Subversion Repositories

?revision_form?Rev ?revision_input??revision_submit??revision_endform?

Rev 129 | Rev 153 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
90 magnus 1
Experimental support for dynamically loading templates. Low-level template handling is unchanged;
2
main programs call dlopen_templates() at appropriate times. If template set has changed, the old
3
one is unloaded first.
87 magnus 4
--- /dev/null
5
+++ b/shared/dlopen_templates.c
101 magnus 6
@@ -0,0 +1,34 @@
87 magnus 7
+#include <dlfcn.h>
8
+#include "shared.h"
9
+
88 magnus 10
+struct template_map_index template_map_index[] = {
11
+    {NIL, NIL, NIL},
12
+    {NIL, NIL, NIL}
13
+};
87 magnus 14
+
88 magnus 15
+struct template_map_index *
16
+dlopen_templates(const char *set, const char *suffix)
87 magnus 17
+{
88 magnus 18
+    struct template_map_index *tmi = &template_map_index[0];
19
+    static void *handle = 0;
87 magnus 20
+
88 magnus 21
+    if (!handle || strcmp(tmi->name, set)) {
22
+        char *filename = pool_printf(NIL, "/usr/lib/prayer/templates/%s%s.so",
23
+                                     set, suffix);
87 magnus 24
+
88 magnus 25
+        if (handle) {
26
+            dlclose(handle);
27
+            free(tmi->name);
87 magnus 28
+        }
88 magnus 29
+        tmi->name = pool_strdup(NIL, set);
30
+        if (!(handle = dlopen(filename, RTLD_NOW))
101 magnus 31
+            || !(tmi->template_map = dlsym(handle, "template_map"))
32
+            || !(tmi->count = dlsym(handle, "template_map_count"))) {
92 magnus 33
+            log_fatal("Failed to load template library: %s",
34
+                      dlerror());
87 magnus 35
+        }
88 magnus 36
+        log_debug("Loaded library %s with %d templates", filename, *tmi->count);
37
+        free(filename);
87 magnus 38
+    }
88 magnus 39
+    return tmi;
87 magnus 40
+}
41
--- /dev/null
42
+++ b/shared/dlopen_templates.h
88 magnus 43
@@ -0,0 +1 @@
44
+struct template_map_index *dlopen_templates(const char *set, const char *suffix);
87 magnus 45
--- a/templates/cam/Makefile
46
+++ b/templates/cam/Makefile
107 magnus 47
@@ -6,12 +6,16 @@ else
48
 include ../../Config
49
 endif
87 magnus 50
 
107 magnus 51
-CFLAGS  = $(BASECFLAGS)
52
-LDFLAGS = $(BASELDFLAGS)
53
+CFLAGS  = $(BASECFLAGS) -fPIC
54
+LDFLAGS = $(BASELDFLAGS) -fPIC
101 magnus 55
+LDFLAGS_TEMPLATELIB = \
56
+       -Wl,--defsym=template_map=template_map_$(TYPE) \
57
+       -Wl,--defsym=template_map_count=template_map_$(TYPE)_count
58
+LDFLAGS += $(LDFLAGS_TEMPLATELIB)
59
 
87 magnus 60
 TYPE=cam
61
 
62
-TARGETS=templates.a templates_frontend.a
63
+TARGETS=templates.a templates_frontend.a $(TYPE).so $(TYPE)_frontend.so
64
 
65
 T_FILES_FRONTEND=login.t login_hermes.t \
66
   frontend_login_error.t frontend_security.t frontend_session.t \
101 magnus 67
@@ -111,6 +115,12 @@ templates.a: $(O_FILES)
87 magnus 68
        rm -f templates.a
69
        ar q templates.a $(O_FILES)
70
 
71
+$(TYPE)_frontend.so: $(O_FILES_FRONTEND)
101 magnus 72
+       $(CC) $(LDFLAGS) -shared -o $@ $(O_FILES_FRONTEND)
87 magnus 73
+
74
+$(TYPE).so: $(O_FILES)
101 magnus 75
+       $(CC) $(LDFLAGS) -shared -o $@ $(O_FILES)
87 magnus 76
+
77
 %.o: %.c Makefile
78
        $(CC) $(CFLAGS) -I../../lib -c $<
79
 
101 magnus 80
@@ -129,6 +139,10 @@ install:
87 magnus 81
        cp *.t $(BROOT)$(PREFIX)/templates/$(TYPE)
82
        cp *.vars $(BROOT)$(PREFIX)/templates/$(TYPE)
83
 
84
+       $(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_DIR) -d \
85
+         $(BROOT)$(LIB_PREFIX)/templates
86
+       cp *.so $(BROOT)$(LIB_PREFIX)/templates/
87
+
88
 clean:
101 magnus 89
        rm -f $(TARGETS) *.html *.o *.c \#*\# *~
87 magnus 90
 
91
--- a/templates/old/Makefile
92
+++ b/templates/old/Makefile
107 magnus 93
@@ -6,12 +6,16 @@ else
94
 include ../../Config
95
 endif
87 magnus 96
 
107 magnus 97
-CFLAGS  = $(BASECFLAGS)
98
-LDFLAGS = $(BASELDFLAGS)
99
+CFLAGS  = $(BASECFLAGS) -fPIC
100
+LDFLAGS = $(BASELDFLAGS) -fPIC
101 magnus 101
+LDFLAGS_TEMPLATELIB = \
102
+       -Wl,--defsym=template_map=template_map_$(TYPE) \
103
+       -Wl,--defsym=template_map_count=template_map_$(TYPE)_count
104
+LDFLAGS += $(LDFLAGS_TEMPLATELIB)
105
 
87 magnus 106
 TYPE=old
107
 
108
-TARGETS=templates.a templates_frontend.a
109
+TARGETS=templates.a templates_frontend.a $(TYPE).so $(TYPE)_frontend.so
110
 
111
 T_FILES_FRONTEND=login.t \
112
   frontend_login_error.t frontend_security.t frontend_session.t \
101 magnus 113
@@ -110,6 +114,12 @@ templates.a: $(O_FILES)
87 magnus 114
        rm -f templates.a
115
        ar q templates.a $(O_FILES)
116
 
117
+$(TYPE)_frontend.so: $(O_FILES_FRONTEND)
101 magnus 118
+       $(CC) $(LDFLAGS) -shared -o $@ $(O_FILES_FRONTEND)
87 magnus 119
+
120
+$(TYPE).so: $(O_FILES)
101 magnus 121
+       $(CC) $(LDFLAGS) -shared -o $@ $(O_FILES)
87 magnus 122
+
123
 %.o: %.c Makefile
124
        $(CC) $(CFLAGS) -I../../lib -c $<
125
 
101 magnus 126
@@ -128,6 +138,10 @@ install:
87 magnus 127
        cp *.t $(BROOT)$(PREFIX)/templates/$(TYPE)
128
        cp *.vars $(BROOT)$(PREFIX)/templates/$(TYPE)
129
 
130
+       $(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_DIR) -d \
131
+         $(BROOT)$(LIB_PREFIX)/templates
132
+       cp *.so $(BROOT)$(LIB_PREFIX)/templates/
133
+
134
 clean:
101 magnus 135
        rm -f $(TARGETS) *.html *.o *.c \#*\# *~
87 magnus 136
 
137
--- a/servers/prayer_chroot.c
138
+++ b/servers/prayer_chroot.c
92 magnus 139
@@ -255,6 +255,8 @@ int main(int argc, char *argv[])
140
     if (list_length(prayer->http_port_list) == 0L)
141
         prayer_fatal(prayer, "No HTTP or HTTPS ports active");
87 magnus 142
 
88 magnus 143
+    dlopen_templates(config->template_set, "_frontend");
87 magnus 144
+
92 magnus 145
     if (config->prayer_background && !want_foreground) {
146
         pid_t pid = fork();
87 magnus 147
 
148
--- a/shared/Makefile
149
+++ b/shared/Makefile
150
@@ -33,7 +33,7 @@ MYCFLAGS  = $(BASECFLAGS)
151
 
152
 SHARED_OBJS = \
153
  config.o gzip.o html_common.o log.o \
154
- request.o response.o user_agent.o
155
+ request.o response.o user_agent.o dlopen_templates.o
156
 
157
 
158
 all: $(SHARED_OBJS)
159
--- a/servers/prayer_main.c
160
+++ b/servers/prayer_main.c
92 magnus 161
@@ -290,6 +290,8 @@ int main(int argc, char *argv[])
87 magnus 162
 
92 magnus 163
     prayer_log_open(prayer);
164
 
88 magnus 165
+    dlopen_templates(config->template_set, "_frontend");
87 magnus 166
+
92 magnus 167
     if (config->limit_vm)
168
         os_limit_vm(config->limit_vm);
87 magnus 169
 
170
--- a/shared/shared.h
171
+++ b/shared/shared.h
127 magnus 172
@@ -40,3 +40,4 @@ extern int errno;               /* just
87 magnus 173
 #include "setproctitle.h"
174
 #include "mymutex.h"
175
 #include "log.h"
176
+#include "dlopen_templates.h"
177
--- a/servers/Makefile
178
+++ b/servers/Makefile
127 magnus 179
@@ -60,8 +60,8 @@ ifeq ($(strip $(ACCOUNTD_ENABLE)), true)
180
   endif
87 magnus 181
 endif
182
 
127 magnus 183
-PRAYER_LIBS   = $(BASE_LIBS) $(SERVER_SSL_LIBS)
145 magnus 184
-SESSION_LIBS  = $(CCLIENT_LIBS) $(BASE_LIBS) 
127 magnus 185
+PRAYER_LIBS   = $(BASE_LIBS) $(SERVER_SSL_LIBS) -ldl
145 magnus 186
+SESSION_LIBS  = $(CCLIENT_LIBS) $(BASE_LIBS) -ldl
87 magnus 187
 
127 magnus 188
 # Add SSL if c-client needs SSL
189
 ifeq ($(strip $(CCLIENT_SSL_ENABLE)), true)
190
@@ -90,15 +90,13 @@ TEMPLATES_FRONTEND= ../templates/index.o
87 magnus 191
  ../templates/cam/templates_frontend.a
192
 
193
 PRAYER_OBJS= prayer.o prayer_login.o prayer_server.o portlist.o \
194
-  ../shared/shared.a $(LIB) $(TEMPLATES_FRONTEND)
195
+  ../shared/shared.a $(LIB)
196
 
197
 SESSION_OBJS= \
198
    session_config.o session_exchange.o session_unix.o session_server.o \
199
    session_main.o portlist.o ../cmd/cmd.a ../session/session.a \
200
    ../shared/shared.a ../lib/lib_nossl.a
201
 
202
-SESSION_OBJS += $(TEMPLATES)
203
-
204
 #########################################################################
205
 
206
 all:   $(BIN)
207
--- a/Makefile
208
+++ b/Makefile
209
@@ -28,7 +28,7 @@ install-cert:
210
 install:
211
        $(MAKE) -C files install
212
        $(MAKE) -C man   install
213
-#      $(MAKE) -C templates install
214
+       $(MAKE) -C templates install
215
        $(MAKE) -C servers install
216
        $(MAKE) -C utils install
217
 ifeq ($(strip $(ACCOUNTD_ENABLE)), true)
88 magnus 218
--- a/servers/session_exchange.c
219
+++ b/servers/session_exchange.c
145 magnus 220
@@ -146,6 +146,8 @@ BOOL session_exchange(struct session * s
88 magnus 221
     else
222
         template_set = config->template_set;   /* Safe default */
87 magnus 223
 
88 magnus 224
+    dlopen_templates(template_set, "");
225
+
226
     /* Set up template_vars ready for dispatch */
227
     session->template_vals = tvals
228
         = template_vals_create(request->pool,
129 magnus 229
--- a/servers/prayer_shared.h
230
+++ b/servers/prayer_shared.h
231
@@ -44,3 +44,4 @@ extern int errno;               /* just
232
 #include "mymutex.h"
233
 #include "log.h"
234
 #include "utf8.h"
235
+#include "dlopen_templates.h"