remove (camel_operation_shutdown): remove. (co_getcc): new helper to get
authorNot Zed <NotZed@Ximian.com>
Mon, 20 Dec 2004 09:00:06 +0000 (09:00 +0000)
committerMichael Zucci <zucchi@src.gnome.org>
Mon, 20 Dec 2004 09:00:06 +0000 (09:00 +0000)
2004-12-20  Not Zed  <NotZed@Ximian.com>

        * camel-operation.c (camel_operation_init): remove
        (camel_operation_shutdown): remove.
        (co_getcc): new helper to get the current thread-specific value &
        init if need be.

        * camel-mime-utils.c (camel_mime_utils_init): removed, taken from
        prebuilt tables now.
        (header_remove_bits, header_init_bits, header_decode_init)
        (base64_init): removed, handled by perl script now.

        * camel.c (camel_shutdown): dont shutdown mime utils anymore.

        * camel-mime-utils.c (mailing_list_init): move the mailing list
        init stuff from camel-mime-utils-init to here.
        (camel_header_raw_check_mailing_list): call mailing_list_once to
        init the regular expression tables.
        (camel_mime_utils_shutdown): removed, it can 'leak' the static
        memory.
        (base64_init): removed, this data never changes, keep table in
        static memory.

camel/ChangeLog
camel/Makefile.am
camel/camel-mime-utils.c
camel/camel-mime-utils.h
camel/camel-operation.c
camel/camel-operation.h
camel/camel.c

index 2a30877..b8c95e5 100644 (file)
@@ -1,3 +1,26 @@
+2004-12-20  Not Zed  <NotZed@Ximian.com>
+
+       * camel-operation.c (camel_operation_init): remove
+       (camel_operation_shutdown): remove.
+       (co_getcc): new helper to get the current thread-specific value &
+       init if need be.
+
+       * camel-mime-utils.c (camel_mime_utils_init): removed, taken from
+       prebuilt tables now.
+       (header_remove_bits, header_init_bits, header_decode_init) 
+       (base64_init): removed, handled by perl script now.
+
+       * camel.c (camel_shutdown): dont shutdown mime utils anymore.
+
+       * camel-mime-utils.c (mailing_list_init): move the mailing list
+       init stuff from camel-mime-utils-init to here.
+       (camel_header_raw_check_mailing_list): call mailing_list_once to
+       init the regular expression tables.
+       (camel_mime_utils_shutdown): removed, it can 'leak' the static
+       memory.
+       (base64_init): removed, this data never changes, keep table in
+       static memory.
+
 2004-12-15  Rodney Dawes  <dobey@novell.com>
 
        * Makefile.am: Move camel-search-private.h to libcamelinclude_HEADERS
index b708dd0..256997d 100644 (file)
@@ -160,6 +160,7 @@ libcamel_1_2_la_SOURCES =                           \
        camel-mime-part-utils.c                 \
        camel-mime-part.c                       \
        camel-mime-utils.c                      \
+       camel-mime-tables.c                     \
        camel-multipart-encrypted.c             \
        camel-multipart-signed.c                \
        camel-multipart.c                       \
@@ -273,6 +274,9 @@ camel_index_control_1_2_LDADD =                     \
        libcamel-1.2.la                         \
        $(libcamel_1_2_la_LIBADD)
 
+camel-mime-tables.c: gentables.pl
+       perl gentables.pl > $@
+
 install-exec-hook:
        @if test -n "$(CAMEL_LOCK_HELPER_USER)"; then \
            if test `whoami` = root ; then \
@@ -313,5 +317,6 @@ noinst_HEADERS =                            \
 
 EXTRA_DIST =                                   \
        $(pkgconfig_in_files)                   \
+       gentables.pl                            \
        ChangeLog.pre-1-4                       \
        README
index 510d07f..9e80429 100644 (file)
@@ -20,8 +20,6 @@
  * Boston, MA 02111-1307, USA.
  */
 
-/* dont touch this file without my permission - Michael */
-
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
@@ -84,98 +82,43 @@ static unsigned char tohex[16] = {
        '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
 };
 
+/* generated by gentables.pl and supplied by camel-mime-tables.c */
 unsigned short camel_mime_special_table[256];
-static unsigned char camel_mime_base64_rank[256];
-
-/* Used by table initialisation code for special characters */
-#define CHARS_LWSP " \t\n\r"
-#define CHARS_TSPECIAL "()<>@,;:\\\"/[]?="
-#define CHARS_SPECIAL "()<>@,;:\\\".[]"
-#define CHARS_CSPECIAL "()\\\r"        /* not in comments */
-#define CHARS_DSPECIAL "[]\\\r \t"     /* not in domains */
-#define CHARS_ESPECIAL "()<>@,;:\"/[]?.=_" /* list of characters that must be encoded.
-                                             encoded word in text specials: rfc 2047 5(1)*/
-#define CHARS_PSPECIAL "!*+-/" /* list of additional characters that can be left unencoded.
-                                 encoded word in phrase specials: rfc 2047 5(3) */
-#define CHARS_ATTRCHAR "*\'% " /* extra non-included attribute-chars */
-
-static void
-header_remove_bits(unsigned short bit, unsigned char *vals)
-{
-       int i;
-
-       for (i=0;vals[i];i++)
-               camel_mime_special_table[vals[i]] &= ~ bit;
-}
-
-static void
-header_init_bits(unsigned short bit, unsigned short bitcopy, int remove, unsigned char *vals)
-{
-       int i;
-       int len = strlen(vals);
-
-       if (!remove) {
-               for (i=0;i<len;i++) {
-                       camel_mime_special_table[vals[i]] |= bit;
-               }
-               if (bitcopy) {
-                       for (i=0;i<256;i++) {
-                               if (camel_mime_special_table[i] & bitcopy)
-                                       camel_mime_special_table[i] |= bit;
-                       }
-               }
-       } else {
-               for (i=0;i<256;i++)
-                       camel_mime_special_table[i] |= bit;
-               for (i=0;i<len;i++) {
-                       camel_mime_special_table[vals[i]] &= ~bit;
-               }
-               if (bitcopy) {
-                       for (i=0;i<256;i++) {
-                               if (camel_mime_special_table[i] & bitcopy)
-                                       camel_mime_special_table[i] &= ~bit;
-                       }
-               }
-       }
-}
 
-static void
-header_decode_init(void)
-{
-       int i;
-
-       for (i=0;i<256;i++) {
-               camel_mime_special_table[i] = 0;
-               if (i<32 || i==127)
-                       camel_mime_special_table[i] |= CAMEL_MIME_IS_CTRL;
-               else if (i < 127)
-                       camel_mime_special_table[i] |= CAMEL_MIME_IS_ATTRCHAR;
-               if ((i>=32 && i<=60) || (i>=62 && i<=126) || i==9)
-                       camel_mime_special_table[i] |= (CAMEL_MIME_IS_QPSAFE|CAMEL_MIME_IS_ESAFE);
-               if ((i>='0' && i<='9') || (i>='a' && i<='z') || (i>='A' && i<= 'Z'))
-                       camel_mime_special_table[i] |= CAMEL_MIME_IS_PSAFE;
-       }
-       camel_mime_special_table[' '] |= CAMEL_MIME_IS_SPACE;
-       header_init_bits(CAMEL_MIME_IS_LWSP, 0, 0, CHARS_LWSP);
-       header_init_bits(CAMEL_MIME_IS_TSPECIAL, CAMEL_MIME_IS_CTRL, 0, CHARS_TSPECIAL);
-       header_init_bits(CAMEL_MIME_IS_SPECIAL, 0, 0, CHARS_SPECIAL);
-       header_init_bits(CAMEL_MIME_IS_DSPECIAL, 0, FALSE, CHARS_DSPECIAL);
-       header_remove_bits(CAMEL_MIME_IS_ESAFE, CHARS_ESPECIAL);
-       header_remove_bits(CAMEL_MIME_IS_ATTRCHAR, CHARS_TSPECIAL CHARS_ATTRCHAR);
-       header_init_bits(CAMEL_MIME_IS_PSAFE, 0, 0, CHARS_PSPECIAL);
-}
-
-static void
-base64_init(void)
-{
-       int i;
-
-       memset(camel_mime_base64_rank, 0xff, sizeof(camel_mime_base64_rank));
-       for (i=0;i<64;i++) {
-               camel_mime_base64_rank[(unsigned int)base64_alphabet[i]] = i;
-       }
-       camel_mime_base64_rank['='] = 0;
-}
+static unsigned char camel_mime_base64_rank[256] = {
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0x3e, 0xff, 0xff, 0xff, 0x3f,
+       0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,
+       0x3c, 0x3d, 0xff, 0xff, 0xff, 0x00, 0xff, 0xff,
+       0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
+       0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
+       0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
+       0x17, 0x18, 0x19, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
+       0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
+       0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,
+       0x31, 0x32, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+};
 
 /* call this when finished encoding everything, to
    flush off the last little bit */
@@ -3837,13 +3780,42 @@ static struct {
        { "List-Unsubscribe", "<mailto:(.+)-unsubscribe@([^ \n\t\r>]*)" },
 };
 
+static pthread_once_t mailing_list_init_once = PTHREAD_ONCE_INIT;
+
+static void
+mailing_list_init(void)
+{
+       int i, errcode, failed=0;
+
+       /* precompile regex's for speed at runtime */
+       for (i = 0; i < G_N_ELEMENTS (mail_list_magic); i++) {
+               errcode = regcomp(&mail_list_magic[i].regex, mail_list_magic[i].pattern, REG_EXTENDED|REG_ICASE);
+               if (errcode != 0) {
+                       char *errstr;
+                       size_t len;
+               
+                       len = regerror(errcode, &mail_list_magic[i].regex, NULL, 0);
+                       errstr = g_malloc0(len + 1);
+                       regerror(errcode, &mail_list_magic[i].regex, errstr, len);
+               
+                       g_warning("Internal error, compiling regex failed: %s: %s", mail_list_magic[i].pattern, errstr);
+                       g_free(errstr);
+                       failed++;
+               }
+       }
+
+       g_assert(failed == 0);
+}
+
 char *
 camel_header_raw_check_mailing_list(struct _camel_header_raw **list)
 {
        const char *v;
        regmatch_t match[3];
        int i, j;
-       
+
+       pthread_once(&mailing_list_init_once, mailing_list_init);
+
        for (i = 0; i < sizeof (mail_list_magic) / sizeof (mail_list_magic[0]); i++) {
                v = camel_header_raw_find (list, mail_list_magic[i].name, NULL);
                for (j=0;j<3;j++) {
@@ -4277,42 +4249,3 @@ camel_header_unfold(const char *in)
 
        return out;
 }
-
-void
-camel_mime_utils_init(void)
-{
-       int i, errcode, regex_compilation_failed=0;
-
-       /* Init tables */
-       header_decode_init();
-       base64_init();
-
-       /* precompile regex's for speed at runtime */
-       for (i = 0; i < G_N_ELEMENTS (mail_list_magic); i++) {
-               errcode = regcomp(&mail_list_magic[i].regex, mail_list_magic[i].pattern, REG_EXTENDED|REG_ICASE);
-               if (errcode != 0) {
-                       char *errstr;
-                       size_t len;
-               
-                       len = regerror(errcode, &mail_list_magic[i].regex, NULL, 0);
-                       errstr = g_malloc0(len + 1);
-                       regerror(errcode, &mail_list_magic[i].regex, errstr, len);
-               
-                       g_warning("Internal error, compiling regex failed: %s: %s", mail_list_magic[i].pattern, errstr);
-                       g_free(errstr);
-                       regex_compilation_failed++;
-               }
-       }
-
-       g_assert(regex_compilation_failed == 0);
-}
-
-
-void
-camel_mime_utils_shutdown (void)
-{
-       int i;
-       
-       for (i = 0; i < G_N_ELEMENTS (mail_list_magic); i++)
-               regfree (&mail_list_magic[i].regex);
-}
index c75b846..eed3289 100644 (file)
@@ -112,10 +112,6 @@ struct _camel_header_newsgroup {
        char *newsgroup;
 };
 
-/* MUST be called before everything else */
-void camel_mime_utils_init(void);
-void camel_mime_utils_shutdown (void);
-
 /* Address lists */
 struct _camel_header_address *camel_header_address_new (void);
 struct _camel_header_address *camel_header_address_new_name (const char *name, const char *addr);
index 1234163..0bf2db3 100644 (file)
@@ -20,7 +20,6 @@
  *
  */
 
-
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
@@ -87,32 +86,24 @@ static pthread_mutex_t operation_lock = PTHREAD_MUTEX_INITIALIZER;
 static unsigned int stamp (void);
 static EDList operation_list = E_DLIST_INITIALISER(operation_list);
 static pthread_key_t operation_key;
+static pthread_once_t operation_once = PTHREAD_ONCE_INIT;
 
 typedef struct _CamelOperationMsg {
        EMsg msg;
 } CamelOperationMsg ;
 
-/**
- * camel_operation_init:
- * @void: 
- * 
- * Init internal variables.  Only call this once.
- **/
-void
-camel_operation_init(void)
+static void
+co_createspecific(void)
 {
        pthread_key_create(&operation_key, NULL);
 }
 
-/**
- * camel_operation_shutdown:
- *
- * Cleans up internal variables.
- **/
-void
-camel_operation_shutdown (void)
+static CamelOperation *
+co_getcc(void)
 {
-       pthread_key_delete (operation_key);
+       pthread_once(&operation_once, co_createspecific);
+
+       return (CamelOperation *)pthread_getspecific(operation_key);
 }
 
 /**
@@ -175,7 +166,7 @@ camel_operation_mute(CamelOperation *cc)
 CamelOperation *
 camel_operation_registered (void)
 {
-       CamelOperation *cc = (CamelOperation *)pthread_getspecific(operation_key);
+       CamelOperation *cc = co_getcc();
 
        if (cc)
                camel_operation_ref(cc);
@@ -249,7 +240,7 @@ void
 camel_operation_cancel_block (CamelOperation *cc)
 {
        if (cc == NULL)
-               cc = (CamelOperation *)pthread_getspecific(operation_key);
+               cc = co_getcc();
 
        if (cc) {
                LOCK();
@@ -270,7 +261,7 @@ void
 camel_operation_cancel_unblock (CamelOperation *cc)
 {
        if (cc == NULL)
-               cc = (CamelOperation *)pthread_getspecific(operation_key);
+               cc = co_getcc();
 
        if (cc) {
                LOCK();
@@ -331,7 +322,7 @@ void
 camel_operation_uncancel(CamelOperation *cc)
 {
        if (cc == NULL)
-               cc = (CamelOperation *)pthread_getspecific(operation_key);
+               cc = co_getcc();
 
        if (cc) {
                CamelOperationMsg *msg;
@@ -362,7 +353,7 @@ camel_operation_uncancel(CamelOperation *cc)
 CamelOperation *
 camel_operation_register (CamelOperation *cc)
 {
-       CamelOperation *oldcc = pthread_getspecific(operation_key);
+       CamelOperation *oldcc = co_getcc();
 
        pthread_setspecific(operation_key, cc);
 
@@ -378,6 +369,7 @@ camel_operation_register (CamelOperation *cc)
 void
 camel_operation_unregister (CamelOperation *cc)
 {
+       pthread_once(&operation_once, co_createspecific);
        pthread_setspecific(operation_key, NULL);
 }
 
@@ -399,7 +391,7 @@ camel_operation_cancel_check (CamelOperation *cc)
        d(printf("checking for cancel in thread %d\n", pthread_self()));
 
        if (cc == NULL)
-               cc = (CamelOperation *)pthread_getspecific(operation_key);
+               cc = co_getcc();
 
        LOCK();
 
@@ -438,7 +430,7 @@ int
 camel_operation_cancel_fd (CamelOperation *cc)
 {
        if (cc == NULL)
-               cc = (CamelOperation *)pthread_getspecific(operation_key);
+               cc = co_getcc();
 
        if (cc == NULL || cc->blocked)
                return -1;
@@ -468,7 +460,7 @@ PRFileDesc *
 camel_operation_cancel_prfd (CamelOperation *cc)
 {
        if (cc == NULL)
-               cc = (CamelOperation *)pthread_getspecific(operation_key);
+               cc = co_getcc();
 
        if (cc == NULL || cc->blocked)
                return NULL;
@@ -501,7 +493,7 @@ camel_operation_start (CamelOperation *cc, char *what, ...)
        struct _status_stack *s;
 
        if (cc == NULL)
-               cc = (CamelOperation *)pthread_getspecific(operation_key);
+               cc = co_getcc();
 
        if (cc == NULL)
                return;
@@ -548,7 +540,7 @@ camel_operation_start_transient (CamelOperation *cc, char *what, ...)
        struct _status_stack *s;
 
        if (cc == NULL)
-               cc = (CamelOperation *)pthread_getspecific(operation_key);
+               cc = co_getcc();
 
        if (cc == NULL || cc->status == NULL)
                return;
@@ -601,7 +593,7 @@ camel_operation_progress (CamelOperation *cc, int pc)
        char *msg = NULL;
 
        if (cc == NULL)
-               cc = (CamelOperation *)pthread_getspecific(operation_key);
+               cc = co_getcc();
 
        if (cc == NULL)
                return;
@@ -673,7 +665,7 @@ camel_operation_end (CamelOperation *cc)
        int pc = 0;
 
        if (cc == NULL)
-               cc = (CamelOperation *)pthread_getspecific(operation_key);
+               cc = co_getcc();
 
        if (cc == NULL)
                return;
index a190940..a8758f2 100644 (file)
@@ -39,8 +39,6 @@ enum _camel_operation_status_t {
 };
 
 /* main thread functions */
-void camel_operation_init(void);
-
 CamelOperation *camel_operation_new(CamelOperationStatusFunc status, void *status_data);
 void camel_operation_mute(CamelOperation *cc);
 void camel_operation_ref(CamelOperation *cc);
index 6545be2..ef040c2 100644 (file)
@@ -46,7 +46,6 @@ static int initialised = FALSE;
 static void
 camel_shutdown (void)
 {
-       void camel_operation_shutdown (void);
        CamelCertDB *certdb;
        
        if (!initialised)
@@ -64,9 +63,6 @@ camel_shutdown (void)
                camel_object_unref (certdb);
        }
        
-       camel_operation_shutdown ();
-       camel_mime_utils_shutdown ();
-       
        initialised = FALSE;
 }
 
@@ -75,7 +71,6 @@ camel_init (const char *configdir, gboolean nss_init)
 {
        CamelCertDB *certdb;
        char *path;
-       void camel_operation_init(void);
        
        if (initialised)
                return 0;
@@ -85,9 +80,6 @@ camel_init (const char *configdir, gboolean nss_init)
        /* initialise global camel_object_type */
        camel_object_get_type();
 
-       camel_mime_utils_init();
-       camel_operation_init();
-
 #ifdef HAVE_NSS
        if (nss_init) {
                PR_Init (PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 10);