Subversion Repositories

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

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