Subversion Repositories

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

Rev 92 | Rev 107 | 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
101 magnus 47
@@ -8,10 +8,14 @@ endif
87 magnus 48
 
101 magnus 49
 CFLAGS  = $(BASECFLAGS)
50
 LDFLAGS = $(BASELDFLAGS)
51
+LDFLAGS_TEMPLATELIB = \
52
+       -Wl,--defsym=template_map=template_map_$(TYPE) \
53
+       -Wl,--defsym=template_map_count=template_map_$(TYPE)_count
54
+LDFLAGS += $(LDFLAGS_TEMPLATELIB)
55
 
87 magnus 56
 TYPE=cam
57
 
58
-TARGETS=templates.a templates_frontend.a
59
+TARGETS=templates.a templates_frontend.a $(TYPE).so $(TYPE)_frontend.so
60
 
61
 T_FILES_FRONTEND=login.t login_hermes.t \
62
   frontend_login_error.t frontend_security.t frontend_session.t \
101 magnus 63
@@ -111,6 +115,12 @@ templates.a: $(O_FILES)
87 magnus 64
        rm -f templates.a
65
        ar q templates.a $(O_FILES)
66
 
67
+$(TYPE)_frontend.so: $(O_FILES_FRONTEND)
101 magnus 68
+       $(CC) $(LDFLAGS) -shared -o $@ $(O_FILES_FRONTEND)
87 magnus 69
+
70
+$(TYPE).so: $(O_FILES)
101 magnus 71
+       $(CC) $(LDFLAGS) -shared -o $@ $(O_FILES)
87 magnus 72
+
73
 %.o: %.c Makefile
74
        $(CC) $(CFLAGS) -I../../lib -c $<
75
 
101 magnus 76
@@ -129,6 +139,10 @@ install:
87 magnus 77
        cp *.t $(BROOT)$(PREFIX)/templates/$(TYPE)
78
        cp *.vars $(BROOT)$(PREFIX)/templates/$(TYPE)
79
 
80
+       $(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_DIR) -d \
81
+         $(BROOT)$(LIB_PREFIX)/templates
82
+       cp *.so $(BROOT)$(LIB_PREFIX)/templates/
83
+
84
 clean:
101 magnus 85
        rm -f $(TARGETS) *.html *.o *.c \#*\# *~
87 magnus 86
 
87
--- a/templates/old/Makefile
88
+++ b/templates/old/Makefile
101 magnus 89
@@ -8,10 +8,14 @@ endif
87 magnus 90
 
101 magnus 91
 CFLAGS  = $(BASECFLAGS)
92
 LDFLAGS = $(BASELDFLAGS)
93
+LDFLAGS_TEMPLATELIB = \
94
+       -Wl,--defsym=template_map=template_map_$(TYPE) \
95
+       -Wl,--defsym=template_map_count=template_map_$(TYPE)_count
96
+LDFLAGS += $(LDFLAGS_TEMPLATELIB)
97
 
87 magnus 98
 TYPE=old
99
 
100
-TARGETS=templates.a templates_frontend.a
101
+TARGETS=templates.a templates_frontend.a $(TYPE).so $(TYPE)_frontend.so
102
 
103
 T_FILES_FRONTEND=login.t \
104
   frontend_login_error.t frontend_security.t frontend_session.t \
101 magnus 105
@@ -110,6 +114,12 @@ templates.a: $(O_FILES)
87 magnus 106
        rm -f templates.a
107
        ar q templates.a $(O_FILES)
108
 
109
+$(TYPE)_frontend.so: $(O_FILES_FRONTEND)
101 magnus 110
+       $(CC) $(LDFLAGS) -shared -o $@ $(O_FILES_FRONTEND)
87 magnus 111
+
112
+$(TYPE).so: $(O_FILES)
101 magnus 113
+       $(CC) $(LDFLAGS) -shared -o $@ $(O_FILES)
87 magnus 114
+
115
 %.o: %.c Makefile
116
        $(CC) $(CFLAGS) -I../../lib -c $<
117
 
101 magnus 118
@@ -128,6 +138,10 @@ install:
87 magnus 119
        cp *.t $(BROOT)$(PREFIX)/templates/$(TYPE)
120
        cp *.vars $(BROOT)$(PREFIX)/templates/$(TYPE)
121
 
122
+       $(INSTALL) -o $(RO_USER) -g $(RO_GROUP) -m $(PUBLIC_DIR) -d \
123
+         $(BROOT)$(LIB_PREFIX)/templates
124
+       cp *.so $(BROOT)$(LIB_PREFIX)/templates/
125
+
126
 clean:
101 magnus 127
        rm -f $(TARGETS) *.html *.o *.c \#*\# *~
87 magnus 128
 
129
--- a/servers/prayer_chroot.c
130
+++ b/servers/prayer_chroot.c
92 magnus 131
@@ -255,6 +255,8 @@ int main(int argc, char *argv[])
132
     if (list_length(prayer->http_port_list) == 0L)
133
         prayer_fatal(prayer, "No HTTP or HTTPS ports active");
87 magnus 134
 
88 magnus 135
+    dlopen_templates(config->template_set, "_frontend");
87 magnus 136
+
92 magnus 137
     if (config->prayer_background && !want_foreground) {
138
         pid_t pid = fork();
87 magnus 139
 
140
--- a/shared/Makefile
141
+++ b/shared/Makefile
142
@@ -33,7 +33,7 @@ MYCFLAGS  = $(BASECFLAGS)
143
 
144
 SHARED_OBJS = \
145
  config.o gzip.o html_common.o log.o \
146
- request.o response.o user_agent.o
147
+ request.o response.o user_agent.o dlopen_templates.o
148
 
149
 
150
 all: $(SHARED_OBJS)
151
--- a/servers/prayer_main.c
152
+++ b/servers/prayer_main.c
92 magnus 153
@@ -290,6 +290,8 @@ int main(int argc, char *argv[])
87 magnus 154
 
92 magnus 155
     prayer_log_open(prayer);
156
 
88 magnus 157
+    dlopen_templates(config->template_set, "_frontend");
87 magnus 158
+
92 magnus 159
     if (config->limit_vm)
160
         os_limit_vm(config->limit_vm);
87 magnus 161
 
162
--- a/shared/shared.h
163
+++ b/shared/shared.h
164
@@ -40,3 +40,4 @@ extern int errno;               /* just 
165
 #include "setproctitle.h"
166
 #include "mymutex.h"
167
 #include "log.h"
168
+#include "dlopen_templates.h"
169
--- a/servers/Makefile
170
+++ b/servers/Makefile
171
@@ -73,7 +73,7 @@ ifeq ($(strip $(CCLIENT_KERB_ENABLE)), t
172
 endif
173
 
174
 MYCFLAGS  = $(BASECFLAGS) $(SERVER_SSL_INCLUDE) $(CCLIENT_INCLUDE)
175
-MYLDFLAGS = $(BASELDFLAGS)
176
+MYLDFLAGS = $(BASELDFLAGS) -ldl
177
 
178
 TEMPLATES= ../templates/index.o \
179
  ../templates/old/templates.a \
180
@@ -84,15 +84,13 @@ TEMPLATES_FRONTEND= ../templates/index.o
181
  ../templates/cam/templates_frontend.a
182
 
183
 PRAYER_OBJS= prayer.o prayer_login.o prayer_server.o portlist.o \
184
-  ../shared/shared.a $(LIB) $(TEMPLATES_FRONTEND)
185
+  ../shared/shared.a $(LIB)
186
 
187
 SESSION_OBJS= \
188
    session_config.o session_exchange.o session_unix.o session_server.o \
189
    session_main.o portlist.o ../cmd/cmd.a ../session/session.a \
190
    ../shared/shared.a ../lib/lib_nossl.a
191
 
192
-SESSION_OBJS += $(TEMPLATES)
193
-
194
 #########################################################################
195
 
196
 all:   $(BIN)
197
--- a/Makefile
198
+++ b/Makefile
199
@@ -28,7 +28,7 @@ install-cert:
200
 install:
201
        $(MAKE) -C files install
202
        $(MAKE) -C man   install
203
-#      $(MAKE) -C templates install
204
+       $(MAKE) -C templates install
205
        $(MAKE) -C servers install
206
        $(MAKE) -C utils install
207
 ifeq ($(strip $(ACCOUNTD_ENABLE)), true)
88 magnus 208
--- a/servers/session_exchange.c
209
+++ b/servers/session_exchange.c
210
@@ -212,6 +212,8 @@ BOOL session_exchange(struct session * s
211
     else
212
         template_set = config->template_set;   /* Safe default */
87 magnus 213
 
88 magnus 214
+    dlopen_templates(template_set, "");
215
+
216
     /* Set up template_vars ready for dispatch */
217
     session->template_vals = tvals
218
         = template_vals_create(request->pool,