]> git.mikk.net Git - liburl/commitdiff
Make module initiation cascade to modules which may be used. Guard
authorchris mikkelson <chris@mikk.net>
Thu, 11 Mar 2010 22:03:29 +0000 (16:03 -0600)
committerchris mikkelson <chris@mikk.net>
Thu, 11 Mar 2010 22:03:29 +0000 (16:03 -0600)
initialization from multiple invocations.

base64.c
message.c
multipart.c
text.c

index 117dc39070024b3700b716501e6e85220bd600ff..6f16f5f69c3f87807e9ed5ee2abe7643dadca1fa 100644 (file)
--- a/base64.c
+++ b/base64.c
@@ -18,6 +18,10 @@ base64_init(void)
 {
        int i;
        const char *p;
+       static int initialized = 0;
+
+       if (initialized++) return;
+
        for (i = 0; i < 256; i++) 
                i64[i] = -1;
        for (p = b64c, i = 0; *p; p++, i++) 
index 7e28acc4ae81bdfde3b86d0776ca06a3ab5ae80f..4b66878ac432a07af0da0132165faa49b32d0dd0 100644 (file)
--- a/message.c
+++ b/message.c
@@ -20,6 +20,12 @@ static pcre *enc_re;
 static const char *bound_pat = "boundary\\s*=\\s*\"?([\\da-z'()+,-./:=?_ \r\n]+)\"?";
 static pcre *bound_re;
 
+static msgproc_module *text_module = &msgproc_text,
+               *html_module = &msgproc_html,
+               *multipart_module = &msgproc_multipart,
+               *quoted_module = &msgproc_quoted,
+               *base64_module = &msgproc_base64;
+
 static void
 message_init(void)
 {
@@ -37,13 +43,13 @@ message_init(void)
        type_re = pcre_compile(type_pat, options, &etxt, &epos, 0);
        enc_re = pcre_compile(enc_pat, options, &etxt, &epos, 0);
        bound_re = pcre_compile(bound_pat, options, &etxt, &epos, 0);
+       msgproc_module_init(text_module);
+       msgproc_module_init(html_module);
+       msgproc_module_init(multipart_module);
+       msgproc_module_init(quoted_module);
+       msgproc_module_init(base64_module);
 }
 
-static msgproc_module *text_module = &msgproc_text,
-               *html_module = &msgproc_html,
-               *multipart_module = &msgproc_multipart,
-               *quoted_module = &msgproc_quoted,
-               *base64_module = &msgproc_base64;
 
 #define MESSAGE_MODULE_TEXT 0
 #define MESSAGE_MODULE_HTML 1
@@ -54,13 +60,16 @@ static msgproc_module *text_module = &msgproc_text,
 static void
 message_module_set(int type, void *data, size_t size)
 {
+       msgproc_module *mpm;
        switch(type) {
-       case MESSAGE_MODULE_TEXT: text_module = data; break;
-       case MESSAGE_MODULE_HTML: html_module = data; break;
-       case MESSAGE_MODULE_MULTIPART: multipart_module = data; break;
-       case MESSAGE_MODULE_QUOTED: quoted_module = data; break;
-       case MESSAGE_MODULE_BASE64: base64_module = data; break;
+       case MESSAGE_MODULE_TEXT: mpm = text_module = data; break;
+       case MESSAGE_MODULE_HTML: mpm = html_module = data; break;
+       case MESSAGE_MODULE_MULTIPART: mpm = multipart_module = data; break;
+       case MESSAGE_MODULE_QUOTED: mpm = quoted_module = data; break;
+       case MESSAGE_MODULE_BASE64: mpm = base64_module = data; break;
+       default: return;
        }
+       msgproc_module_init(mpm);
 }
 
 #define HDRALLOC 512
index 22e836d1ea1399f0581873b451da86ecd0d8d494..f2e4fefdca4419e433de839ce2dc47bef8985016 100644 (file)
@@ -21,6 +21,14 @@ struct multipart_state {
        int state;
 };
 
+static void
+multipart_init(void)
+{
+       static int initialized = 0;
+       if (initialized++) return;
+       msgproc_module_init(nextmod);
+}
+
 static void 
 multipart_start(msgproc *m)
 {
@@ -36,6 +44,7 @@ setnextmod(int type, void *data, size_t size)
 {
        if (type != MULTIPART_MODULE_NEXTMOD) return;
        nextmod = (msgproc_module *)data;
+       msgproc_module_init(nextmod);
 }
 
 static void
@@ -199,7 +208,7 @@ multipart_finish(msgproc *m)
 
 msgproc_module msgproc_multipart = {
        MSGPROC_MULTIPART,              /* type */
-       NULL,                           /* module init */
+       multipart_init,                 /* module init */
        setnextmod,                     /* set module parameter */
        multipart_start,                /* start module instance */
        setboundary,                    /* set module instance parameter */
diff --git a/text.c b/text.c
index c0b15d403a242d9ddf30f50b0957d739868eb607..f0b1e0a3da542d9f98d294d8b85a1df9655487a0 100644 (file)
--- a/text.c
+++ b/text.c
@@ -24,8 +24,7 @@ text_init(void) {
        const char *etxt; int epos;
        static int initialized = 0;
 
-       if (initialized) return;
-       initialized = 1;
+       if (initialized++) return;
 
        text_url_re = pcre_compile(text_url_pattern, PCRE_CASELESS, &etxt, &epos, 0);
        if (!text_url_re) {