Changeset 3024

Show
Ignore:
Timestamp:
11/28/07 19:19:36
Author:
pvanhoof
Message:

Coping with null strings

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • devel/pvanhoof/bs/libtinymail-camel/bs/bodystruct.c

    r3023 r3024  
    1010 
    1111#include "bodystruct.h" 
     12 
     13#define PRINT_NULL(o)   (o?o:"(null)") 
    1214 
    1315#ifdef DEBUG 
     
    316318        while (param) { 
    317319                next = param->next; 
    318                 debug_printf ("%s = ", param->name); 
    319                 debug_printf ("%s\n", param->value); 
     320                debug_printf ("%s = ", PRINT_NULL (param->name)); 
     321                debug_printf ("%s\n", PRINT_NULL (param->value)); 
    320322                param = next; 
    321323        } 
     
    420422        inptr = *in; 
    421423        str = decode_qstring (&inptr, inend, err); 
    422         debug_printf ("unknown: %s\n", str); 
     424        debug_printf ("unknown: %s\n", PRINT_NULL (str)); 
    423425        g_free (str); 
    424426        *in = inptr; 
     
    450452 
    451453        node->date = decode_qstring (&inptr, inend, err); 
    452         debug_printf ("env date: %s\n", node->date); 
     454        debug_printf ("env date: %s\n", PRINT_NULL (node->date)); 
    453455        node->subject = decode_qstring (&inptr, inend, err); 
    454         debug_printf ("env subject: %s\n", node->subject); 
     456        debug_printf ("env subject: %s\n", PRINT_NULL (node->subject)); 
    455457 
    456458        node->from = decode_estring (&inptr, inend, err); 
    457         debug_printf ("env from: %s\n", node->from); 
     459        debug_printf ("env from: %s\n", PRINT_NULL (node->from)); 
    458460 
    459461        node->sender = decode_estring (&inptr, inend, err); 
    460         debug_printf ("env sender: %s\n", node->sender); 
     462        debug_printf ("env sender: %s\n", PRINT_NULL (node->sender)); 
    461463 
    462464        node->reply_to = decode_estring (&inptr, inend, err); 
    463         debug_printf ("env reply_to: %s\n", node->reply_to); 
     465        debug_printf ("env reply_to: %s\n", PRINT_NULL (node->reply_to)); 
    464466 
    465467        node->to = decode_estring (&inptr, inend, err); 
    466         debug_printf ("env to: %s\n", node->to); 
     468        debug_printf ("env to: %s\n", PRINT_NULL (node->to)); 
    467469 
    468470        node->cc = decode_estring (&inptr, inend, err); 
    469         debug_printf ("env cc: %s\n", node->cc); 
     471        debug_printf ("env cc: %s\n", PRINT_NULL (node->cc)); 
    470472 
    471473        node->bcc = decode_estring (&inptr, inend, err); 
    472         debug_printf ("env bcc: %s\n", node->bcc); 
     474        debug_printf ("env bcc: %s\n", PRINT_NULL (node->bcc)); 
    473475 
    474476        node->in_reply_to = decode_estring (&inptr, inend, err); 
    475         debug_printf ("env in_reply_to: %s\n", node->in_reply_to); 
     477        debug_printf ("env in_reply_to: %s\n", PRINT_NULL (node->in_reply_to)); 
    476478 
    477479        node->message_id = decode_qstring (&inptr, inend, err); 
    478         debug_printf ("env message_id: %s\n", node->message_id); 
     480        debug_printf ("env message_id: %s\n", PRINT_NULL (node->message_id)); 
    479481 
    480482        while (inptr < inend && *inptr == ' ') 
     
    517519                /* case b */ 
    518520                part->content.lang = decode_qstring (&inptr, inend, err); 
    519                 debug_printf ("lang: %s\n", part->content.lang); 
     521                debug_printf ("lang: %s\n", PRINT_NULL (part->content.lang)); 
    520522 
    521523                while (inptr < inend && *inptr == ' ') 
     
    536538                        /* case c */ 
    537539                        part->content.lang = decode_qstring (&inptr, inend, err); 
    538                         debug_printf ("lang: %s\n", part->content.lang); 
     540                        debug_printf ("lang: %s\n", PRINT_NULL (part->content.lang)); 
    539541                } else /* case a */ 
    540542                        inptr += 3; 
     
    564566                /* cases c & b */ 
    565567                disposition->type = decode_qstring (&inptr, inend, err); 
    566                 debug_printf ("disposition.type: %s\n", disposition->type); 
     568                debug_printf ("disposition.type: %s\n", PRINT_NULL (disposition->type)); 
    567569                disposition->params = decode_params (&inptr, inend, err); 
    568570                print_params (disposition->params); 
     
    586588                        /* case d */ 
    587589                        disposition->type = decode_qstring (&inptr, inend, err); 
    588                         debug_printf ("disposition.type: %s\n", disposition->type); 
     590                        debug_printf ("disposition.type: %s\n", PRINT_NULL (disposition->type)); 
    589591                        disposition->params = decode_params (&inptr, inend, err); 
    590592                        print_params (disposition->params); 
     
    599601 
    600602 
    601 static void  
    602 parse_something_unknown (unsigned char **in, unsigned char *inend, GError **err) 
    603 { 
    604         unsigned char *inptr = *in; 
    605  
    606         /* a) NIL  
    607          * b) ("INLINE" NIL)  
    608          * c) "INLINE" NIL (never seen this one)*/ 
    609  
    610         while (inptr < inend && *inptr == ' ') 
    611                 inptr++; 
    612  
    613         if (*inptr == '(') { 
    614                 struct _mimeparam *unknown_param; 
    615                 inptr++; /* My '(' */ 
    616  
    617                 /* case b */ 
    618                 read_unknown_qstring (&inptr, inend, err); 
    619                 unknown_param = decode_params (&inptr, inend, err); 
    620                 print_params (unknown_param); 
    621                 mimeparam_destroy (unknown_param); 
    622  
    623                 while (inptr < inend && *inptr == ' ') 
    624                         inptr++; 
    625  
    626                 if (*inptr != ')') { 
    627                         *in = inptr; 
    628                         set_error (err, in); 
    629                         return; 
    630                 } 
    631  
    632                 inptr++; /* My ')' */ 
    633         } else { 
    634                 if (strncmp ((const char *) inptr, "NIL", 3) != 0) { 
    635                         struct _mimeparam *unknown_param; 
    636                         /* case c */ 
    637                         read_unknown_qstring (&inptr, inend, err); 
    638                         unknown_param = decode_params (&inptr, inend, err); 
    639                         print_params (unknown_param); 
    640                         mimeparam_destroy (unknown_param); 
    641                 } else /* case a */ 
    642                         inptr += 3; 
    643         } 
    644  
    645         *in = inptr; 
    646  
    647         return; 
    648 } 
    649603 
    650604static void 
     
    736690                if (*inptr != ')') { 
    737691                        part->content.subtype = decode_qstring (&inptr, inend, err); 
    738                         debug_printf ("contensubtype: %s\n", part->content.subtype); 
     692                        debug_printf ("contensubtype: %s\n", PRINT_NULL (part->content.subtype)); 
    739693                } 
    740694 
     
    765719                if (!part->content.type) 
    766720                        part->content.type = g_strdup ("TEXT"); 
    767                 debug_printf ("contentype: %s\n", part->content.type); 
     721                debug_printf ("contentype: %s\n", PRINT_NULL (part->content.type)); 
    768722 
    769723                part->content.subtype = decode_qstring (&inptr, inend, err); 
    770724                if (!part->content.subtype) 
    771725                        part->content.subtype = g_strdup ("PLAIN"); 
    772                 debug_printf ("contensubtype: %s\n", part->content.subtype); 
     726                debug_printf ("contensubtype: %s\n", PRINT_NULL (part->content.subtype)); 
    773727 
    774728                part->disposition.type = NULL; 
     
    788742                        if (*inptr != ')') { 
    789743                                part->content.cid = decode_qstring (&inptr, inend, err); 
    790                                 debug_printf ("content.cid: %s\n", part->content.cid); 
     744                                debug_printf ("content.cid: %s\n", PRINT_NULL (part->content.cid)); 
    791745                        } 
    792746 
    793747                        if (*inptr != ')') { 
    794748                                part->description = decode_qstring (&inptr, inend, err); 
    795                                 debug_printf ("description: %s\n", part->description); 
     749                                debug_printf ("description: %s\n", PRINT_NULL (part->description)); 
    796750                        } 
    797751 
     
    800754                                if (!part->encoding) 
    801755                                        part->encoding = g_strdup ("7BIT"); 
    802                                 debug_printf ("encoding: %s\n", part->encoding); 
     756                                debug_printf ("encoding: %s\n", PRINT_NULL (part->encoding)); 
    803757                        } 
    804758 
     
    846800                        if (*inptr != ')') { 
    847801                                part->content.cid = decode_qstring (&inptr, inend, err); 
    848                                 debug_printf ("content.cid: %s\n", part->content.cid); 
     802                                debug_printf ("content.cid: %s\n", PRINT_NULL (part->content.cid)); 
    849803                        } 
    850804 
    851805                        if (*inptr != ')') { 
    852806                                part->description = decode_qstring (&inptr, inend, err); 
    853                                 debug_printf ("description: %s\n", part->description); 
     807                                debug_printf ("description: %s\n", PRINT_NULL (part->description)); 
    854808                        } 
    855809 
    856810                        if (*inptr != ')') { 
    857811                                part->encoding = decode_qstring (&inptr, inend, err); 
    858                                 debug_printf ("encoding: %s\n", part->encoding); 
     812                                debug_printf ("encoding: %s\n", PRINT_NULL (part->encoding)); 
    859813                        } 
    860814 
     
    885839                        } 
    886840 
    887                 } else if (!strcasecmp (part->content.type, "application")|| 
    888                                 !strcasecmp (part->content.type, "image") || 
    889                                 !strcasecmp (part->content.type, "audio")) 
     841                } else if (!strcasecmp (part->content.type, "APPLICATION")|| 
     842                                !strcasecmp (part->content.type, "IMAGE") || 
     843                                !strcasecmp (part->content.type, "AUDIO")) 
    890844                { 
    891845 
     
    897851                        if (*inptr != ')') { 
    898852                                part->content.cid = decode_qstring (&inptr, inend, err); 
    899                                 debug_printf ("content.cid: %s\n", part->content.cid); 
     853                                debug_printf ("content.cid: %s\n", PRINT_NULL (part->content.cid)); 
    900854                        } 
    901855 
    902856                        if (*inptr != ')') { 
    903857                                part->description = decode_qstring (&inptr, inend, err); 
    904                                 debug_printf ("description: %s\n", part->description); 
     858                                debug_printf ("description: %s\n", PRINT_NULL (part->description)); 
    905859                        } 
    906860 
    907861                        if (*inptr != ')') { 
    908862                                part->encoding = decode_qstring (&inptr, inend, err); 
    909                                 debug_printf ("encoding: %s\n", part->encoding); 
     863                                debug_printf ("encoding: %s\n", PRINT_NULL (part->encoding)); 
    910864                        } 
    911865 
     
    984938                printf ("  "); 
    985939 
    986         printf ("IMAP part specification: %s\n", part->part_spec); 
     940        printf ("IMAP part specification: %s\n", PRINT_NULL (part->part_spec)); 
    987941 
    988942        for (i = 0; i < depth; i++) 
    989943                printf ("  "); 
    990944 
    991         printf ("Content-Type: %s/%s", part->content.type
     945        printf ("Content-Type: %s/%s", PRINT_NULL (part->content.type)
    992946                 part->content.subtype); 
    993947 
     
    995949                param = part->content.params; 
    996950                while (param) { 
    997                         printf ("; %s=%s", param->name, param->value); 
     951                        printf ("; %s=%s", PRINT_NULL (param->name),  
     952                                PRINT_NULL (param->value)); 
    998953                        param = param->next; 
    999954                } 
     
    1013968                for (i = 0; i < depth; i++) 
    1014969                        printf ("  "); 
    1015                 printf ( "Date: %s\n", part->envelope->date); 
     970                printf ( "Date: %s\n", PRINT_NULL (part->envelope->date)); 
    1016971                for (i = 0; i < depth; i++) 
    1017972                        printf ("  "); 
    1018                 printf ("Subject: %s\n", part->envelope->subject); 
     973                printf ("Subject: %s\n", PRINT_NULL (part->envelope->subject)); 
    1019974                for (i = 0; i < depth; i++) 
    1020975                        printf ("  "); 
    1021                 printf ("From: %s\n", part->envelope->from); 
     976                printf ("From: %s\n", PRINT_NULL (part->envelope->from)); 
    1022977                for (i = 0; i < depth; i++) 
    1023978                        printf ("  "); 
    1024                 printf ("Sender: %s\n", part->envelope->sender); 
     979                printf ("Sender: %s\n", PRINT_NULL (part->envelope->sender)); 
    1025980                for (i = 0; i < depth; i++) 
    1026981                        printf ("  "); 
    1027                 printf ("Reply-To: %s\n", part->envelope->reply_to); 
     982                printf ("Reply-To: %s\n", PRINT_NULL (part->envelope->reply_to)); 
    1028983                for (i = 0; i < depth; i++) 
    1029984                        printf ("  "); 
    1030                 printf ("To: %s\n", part->envelope->to); 
     985                printf ("To: %s\n", PRINT_NULL (part->envelope->to)); 
    1031986                for (i = 0; i < depth; i++) 
    1032987                        printf ("  "); 
    1033                 printf ("Cc: %s\n", part->envelope->cc); 
     988                printf ("Cc: %s\n", PRINT_NULL (part->envelope->cc)); 
    1034989                for (i = 0; i < depth; i++) 
    1035990                        printf ("  "); 
    1036                 printf ("Bcc: %s\n", part->envelope->bcc); 
     991                printf ("Bcc: %s\n", PRINT_NULL (part->envelope->bcc)); 
    1037992                for (i = 0; i < depth; i++) 
    1038993                        printf ("  "); 
    1039                 printf ("In-Reply-To: %s\n", part->envelope->in_reply_to); 
     994                printf ("In-Reply-To: %s\n", PRINT_NULL (part->envelope->in_reply_to)); 
    1040995                for (i = 0; i < depth; i++) 
    1041996                        printf ("  "); 
    1042                 printf ("Message-Id: %s\n", part->envelope->message_id); 
     997                printf ("Message-Id: %s\n", PRINT_NULL (part->envelope->message_id)); 
    1043998                bodystruct_dump_r (part->subparts, depth); 
    1044999                depth--; 
     
    10471002                        for (i = 0; i < depth; i++) 
    10481003                                printf ("  "); 
    1049                         printf ("Content-Disposition: %s", part->disposition.type); 
     1004                        printf ("Content-Disposition: %s", PRINT_NULL (part->disposition.type)); 
    10501005                        if (part->disposition.params) { 
    10511006                                param = part->disposition.params; 
    10521007                                while (param) { 
    1053                                         printf ("; %s=%s", param->name, param->value); 
     1008                                        printf ("; %s=%s", PRINT_NULL (param->name),  
     1009                                                PRINT_NULL (param->value)); 
    10541010                                        param = param->next; 
    10551011                                } 
     
    10621018                        for (i = 0; i < depth; i++) 
    10631019                                printf ("  "); 
    1064                         printf ("Content-Transfer-Encoding: %s\n", part->encoding); 
     1020                        printf ("Content-Transfer-Encoding: %s\n", PRINT_NULL (part->encoding)); 
    10651021                } 
    10661022 
     
    10681024                        for (i = 0; i < depth; i++) 
    10691025                                printf ("  "); 
    1070                         printf ("Description: %s\n", part->description); 
     1026                        printf ("Description: %s\n", PRINT_NULL (part->description)); 
    10711027                } 
    10721028 
     
    10781034                        for (i = 0; i < depth; i++) 
    10791035                                printf ("  "); 
    1080                         printf ("Language: %s\n", part->content.lang); 
     1036                        printf ("Language: %s\n", PRINT_NULL (part->content.lang)); 
    10811037                } 
    10821038 
     
    10841040                        for (i = 0; i < depth; i++) 
    10851041                                printf ("  "); 
    1086                         printf ("Location: %s\n", part->content.loc); 
     1042                        printf ("Location: %s\n", PRINT_NULL (part->content.loc)); 
    10871043                } 
    10881044 
     
    10901046                        for (i = 0; i < depth; i++) 
    10911047                                printf ("  "); 
    1092                         printf ("Cid: %s\n", part->content.cid); 
     1048                        printf ("Cid: %s\n", PRINT_NULL (part->content.cid)); 
    10931049                } 
    10941050 
     
    10961052                        for (i = 0; i < depth; i++) 
    10971053                                printf ("  "); 
    1098                         printf ("MD5: %s\n", part->content.md5); 
    1099                 } 
    1100         } 
     1054                        printf ("MD5: %s\n", PRINT_NULL (part->content.md5)); 
     1055                } 
     1056        } 
     1057 
    11011058 
    11021059        printf ("\n");