Cleanup warnings imapx-utils.c
authorChenthill Palanisamy <pchenthill@novell.com>
Wed, 2 Dec 2009 14:47:48 +0000 (20:17 +0530)
committerChenthill Palanisamy <pchenthill@novell.com>
Wed, 2 Dec 2009 14:47:48 +0000 (20:17 +0530)
camel/providers/imapx/camel-imapx-utils.c

index e471f00..e66dede 100644 (file)
@@ -40,7 +40,7 @@ static void imapx_namespace_clear (CamelIMAPXStoreNamespace **ns);
 
 /* flag table */
 static struct {
-       gchar *name;
+       const gchar *name;
        guint32 flag;
 } flag_table[] = {
        { "\\ANSWERED", CAMEL_MESSAGE_ANSWERED },
@@ -98,36 +98,50 @@ imap_parse_flags(CamelIMAPXStream *stream, guint32 *flagsp, CamelFlag **user_fla
 }
 
 void
-imap_write_flags(CamelStream *stream, guint32 flags, CamelFlag *user_flags)
+imap_write_flags(CamelStream *stream, guint32 flags, CamelFlag *user_flags, CamelException *ex)
 /* throws IO exception */
 {
        gint i;
 
-       /* all this ugly exception throwing goes away once camel streams throw their own? */
-       if (camel_stream_write(stream, "(", 1) == -1)
-               camel_exception_throw(1, "io error: %s", strerror(errno));
+       if (camel_stream_write(stream, "(", 1) == -1) {
+               camel_exception_setv (ex, 1, "io error: %s", strerror(errno));
+               return;
+       }
 
        for (i=0;flags!=0 && i< G_N_ELEMENTS (flag_table);i++) {
                if (flag_table[i].flag & flags) {
-                       if (camel_stream_write(stream, flag_table[i].name, strlen(flag_table[i].name)) == -1)
-                               camel_exception_throw(1, "io error: %s", strerror(errno));
+                       if (camel_stream_write(stream, flag_table[i].name, strlen(flag_table[i].name)) == -1) {
+                               camel_exception_setv (ex,1, "io error: %s", strerror(errno));
+                               return;
+                       }
+
                        flags &= ~flag_table[i].flag;
                        if (flags != 0 && user_flags == NULL)
-                               if (camel_stream_write(stream, " ", 1) == -1)
-                                       camel_exception_throw(1, "io error: %s", strerror(errno));
+                               if (camel_stream_write(stream, " ", 1) == -1) {
+                                       camel_exception_setv (ex, 1, "io error: %s", strerror(errno));
+                                       return;
+                               }
                }
        }
 
        while (user_flags) {
-               if (camel_stream_write(stream, user_flags->name, strlen(user_flags->name)) == -1)
-                       camel_exception_throw(1, "io error: %s", strerror(errno));
-               if (user_flags->next && camel_stream_write(stream, " ", 1) == -1)
-                       camel_exception_throw(1, "io error: %s", strerror(errno));
+               if (camel_stream_write(stream, user_flags->name, strlen(user_flags->name)) == -1) {
+                       camel_exception_setv (ex, 1, "io error: %s", strerror(errno));
+                       return;
+               }
+
+               if (user_flags->next && camel_stream_write(stream, " ", 1) == -1) {
+                       camel_exception_setv (ex, 1, "io error: %s", strerror(errno));
+                       return; 
+               }
+
                user_flags = user_flags->next;
        }
 
-       if (camel_stream_write(stream, ")", 1) == -1)
-               camel_exception_throw(1, "io error: %s", strerror(errno));
+       if (camel_stream_write(stream, ")", 1) == -1) {
+               camel_exception_setv (ex, 1, "io error: %s", strerror(errno));
+               return;
+       }
 }
 
 /*
@@ -139,7 +153,7 @@ capability_data ::= "CAPABILITY" SPACE [1#capability SPACE] "IMAP4rev1"
 */
 
 struct {
-       gchar *name;
+       const gchar *name;
        guint32 flag;
 } capa_table[] = {
        { "IMAP4", IMAP_CAPABILITY_IMAP4 },
@@ -154,8 +168,9 @@ struct {
 struct _capability_info *
 imap_parse_capability(CamelIMAPXStream *stream, CamelException *ex)
 {
-       gint tok, len, i;
-       guchar *token, *p, c, *temp;
+       gint tok, i;
+       guint len;
+       guchar *token, *p, c;
        gboolean free_token = FALSE;
        struct _capability_info * cinfo;
 
@@ -165,7 +180,7 @@ imap_parse_capability(CamelIMAPXStream *stream, CamelException *ex)
        while (!camel_exception_is_set (ex) && (tok = camel_imapx_stream_token(stream, &token, &len, ex)) != '\n') {
                switch (tok) {
                        case 43:
-                               token = g_strconcat (token, "+", NULL);
+                               token = (guchar *) g_strconcat ((gchar *)token, "+", NULL);
                                free_token = TRUE;
                        case IMAP_TOK_TOKEN:
                        case IMAP_TOK_STRING:
@@ -175,7 +190,7 @@ imap_parse_capability(CamelIMAPXStream *stream, CamelException *ex)
                        case IMAP_TOK_INT:
                                printf(" cap: '%s'\n", token);
                                for (i = 0; i < G_N_ELEMENTS (capa_table); i++)
-                                       if (!strcmp(token, capa_table[i].name))
+                                       if (!strcmp((gchar *) token, capa_table[i].name))
                                                cinfo->capa |= capa_table[i].flag;
                                if (free_token) {
                                        g_free (token);
@@ -207,8 +222,9 @@ imap_parse_namespace_list (CamelIMAPXStream *stream, CamelException *ex)
 {
        CamelIMAPXStoreNamespace *namespaces[3], *node, *tail;
        CamelIMAPXNamespaceList *nsl = NULL;
-       gint tok, len, i;
-       guchar *token, *p, c;
+       gint tok, i;
+       guint len;
+       guchar *token;
        gint n = 0;
 
        nsl = g_malloc0(sizeof(CamelIMAPXNamespaceList));
@@ -233,14 +249,14 @@ imap_parse_namespace_list (CamelIMAPXStream *stream, CamelException *ex)
 
                                node = g_new0 (CamelIMAPXStoreNamespace, 1);
                                node->next = NULL;
-                               node->full_name = g_strdup (token);
-                               node->path = g_strdup (token);
+                               node->full_name = g_strdup ((gchar *) token);
+                               node->path = g_strdup ((gchar *) token);
                                g_message ("namespace: Node path is %s \n", node->path);
 
                                tok = camel_imapx_stream_token (stream, &token, &len, ex);
 
                                if (tok == IMAP_TOK_STRING) {
-                                       if (strlen (token) == 1) {
+                                       if (strlen ((gchar *) token) == 1) {
                                                node->sep = *token;
                                        } else {
                                                if (*token)
@@ -281,7 +297,7 @@ imap_parse_namespace_list (CamelIMAPXStream *stream, CamelException *ex)
                                goto exception;
                        }
 
-               } else if (tok == IMAP_TOK_TOKEN && !strcmp (token, "NIL")) {
+               } else if (tok == IMAP_TOK_TOKEN && !strcmp ((gchar *) token, "NIL")) {
                        namespaces [n] = NULL;
                } else {
                        camel_exception_set (ex, 1, "namespace: expected either a '(' or NIL");
@@ -446,8 +462,10 @@ imap_free_body(struct _CamelMessageContentInfo *cinfo)
 void
 imap_parse_param_list(CamelIMAPXStream *is, struct _camel_header_param **plist, CamelException *ex)
 {
-       gint tok, len;
-       guchar *token, *param;
+       gint tok;
+       guint len;
+       guchar *token;
+       gchar *param;
 
        p(printf("body_fld_param\n"));
 
@@ -461,10 +479,10 @@ imap_parse_param_list(CamelIMAPXStream *is, struct _camel_header_param **plist,
                        camel_imapx_stream_ungettoken(is, tok, token, len);
 
                        camel_imapx_stream_astring(is, &token, ex);
-                       param = alloca(strlen(token)+1);
-                       strcpy(param, token);
+                       param = alloca (strlen ((gchar *) token)+1);
+                       strcpy(param, (gchar *) token);
                        camel_imapx_stream_astring(is, &token, ex);
-                       camel_header_set_param(plist, param, token);
+                       camel_header_set_param(plist, param, (gchar *) token);
                }
        } /* else check nil?  no need */
 }
@@ -472,7 +490,8 @@ imap_parse_param_list(CamelIMAPXStream *is, struct _camel_header_param **plist,
 struct _CamelContentDisposition *
 imap_parse_ext_optional(CamelIMAPXStream *is, CamelException *ex)
 {
-       gint tok, len;
+       gint tok;
+       guint len;
        guchar *token;
        struct _CamelContentDisposition *dinfo = NULL;
 
@@ -501,7 +520,7 @@ imap_parse_ext_optional(CamelIMAPXStream *is, CamelException *ex)
                        /* should be string */
                        camel_imapx_stream_astring(is, &token, ex);
 
-                       dinfo->disposition = g_strdup(token);
+                       dinfo->disposition = g_strdup((gchar *) token);
                        imap_parse_param_list(is, &dinfo->params, ex);
                case IMAP_TOK_TOKEN:
                        d(printf("body_fld_dsp: NIL\n"));
@@ -558,7 +577,8 @@ imap_parse_ext_optional(CamelIMAPXStream *is, CamelException *ex)
 struct _CamelMessageContentInfo *
 imap_parse_body_fields(CamelIMAPXStream *is, CamelException *ex)
 {
-       guchar *token, *type;
+       guchar *token;
+       gchar  *type;
        struct _CamelMessageContentInfo *cinfo;
 
        /* body_fields     ::= body_fld_param SPACE body_fld_id SPACE
@@ -573,12 +593,12 @@ imap_parse_body_fields(CamelIMAPXStream *is, CamelException *ex)
        camel_imapx_stream_astring(is, &token, ex);
        if (camel_exception_is_set (ex))
                goto error;
-       type = alloca(strlen(token)+1);
-       strcpy(type, token);
+       type = alloca(strlen( (gchar *) token)+1);
+       strcpy(type, (gchar *) token);
        camel_imapx_stream_astring(is, &token, ex);
        if (camel_exception_is_set (ex))
                goto error;
-       cinfo->type = camel_content_type_new(type, token);
+       cinfo->type = camel_content_type_new(type, (gchar *) token);
        imap_parse_param_list(is, &cinfo->type->params, ex);
        if (camel_exception_is_set (ex))
                goto error;
@@ -587,20 +607,20 @@ imap_parse_body_fields(CamelIMAPXStream *is, CamelException *ex)
        camel_imapx_stream_nstring(is, &token, ex);
        if (camel_exception_is_set (ex))
                goto error;
-       cinfo->id = g_strdup(token);
+       cinfo->id = g_strdup((gchar *) token);
 
        /* body_fld_desc   ::= nstring */
        camel_imapx_stream_nstring(is, &token, ex);
        if (camel_exception_is_set (ex))
                goto error;
-       cinfo->description = g_strdup(token);
+       cinfo->description = g_strdup((gchar *) token);
 
        /* body_fld_enc    ::= (<"> ("7BIT" / "8BIT" / "BINARY" / "BASE64"/
           "QUOTED-PRINTABLE") <">) / string */
        camel_imapx_stream_astring(is, &token, ex);
        if (camel_exception_is_set (ex))
                goto error;
-       cinfo->encoding = g_strdup(token);
+       cinfo->encoding = g_strdup((gchar *) token);
 
        /* body_fld_octets ::= number */
        cinfo->size = camel_imapx_stream_number(is, ex);
@@ -617,8 +637,10 @@ struct _camel_header_address *
 imap_parse_address_list(CamelIMAPXStream *is, CamelException *ex)
 /* throws PARSE,IO exception */
 {
-       gint tok, len;
-       guchar *token, *host, *mbox;
+       gint tok;
+       guint len;
+       guchar *token, *host;
+       gchar *mbox;
        struct _camel_header_address *list = NULL;
 
        /* "(" 1*address ")" / nil */
@@ -642,7 +664,7 @@ imap_parse_address_list(CamelIMAPXStream *is, CamelException *ex)
                        addr = camel_header_address_new();
                        addr->type = CAMEL_HEADER_ADDRESS_NAME;
                        tok = camel_imapx_stream_nstring(is, &token, ex);
-                       addr->name = g_strdup(token);
+                       addr->name = g_strdup((gchar *) token);
                        /* we ignore the route, nobody uses it in the real world */
                        tok = camel_imapx_stream_nstring(is, &token, ex);
 
@@ -654,7 +676,7 @@ imap_parse_address_list(CamelIMAPXStream *is, CamelException *ex)
                           non-NIL, this is a start of group marker, and the
                           mailbox name field holds the group name phrase. */
 
-                       tok = camel_imapx_stream_nstring(is, &mbox, ex);
+                       tok = camel_imapx_stream_nstring(is,(guchar **) &mbox, ex);
                        mbox = g_strdup(mbox);
                        tok = camel_imapx_stream_nstring(is, &host, ex);
                        if (host == NULL) {
@@ -669,7 +691,7 @@ imap_parse_address_list(CamelIMAPXStream *is, CamelException *ex)
                                        group = addr;
                                }
                        } else {
-                               addr->v.addr = g_strdup_printf("%s%s%s", mbox?(gchar *)mbox:"", host?"@":"", host?(gchar *)host:"");
+                               addr->v.addr = g_strdup_printf("%s%s%s", mbox? mbox:"", host?"@":"", host?(gchar *)host:"");
                                g_free(mbox);
                                d(printf("adding address '%s'\n", addr->v.addr));
                                if (group != NULL)
@@ -693,7 +715,8 @@ imap_parse_address_list(CamelIMAPXStream *is, CamelException *ex)
 struct _CamelMessageInfo *
 imap_parse_envelope(CamelIMAPXStream *is, CamelException *ex)
 {
-       gint tok, len;
+       gint tok;
+       guint len;
        guchar *token;
        struct _camel_header_address *addr, *addr_from;
        gchar *addrstr;
@@ -717,11 +740,11 @@ imap_parse_envelope(CamelIMAPXStream *is, CamelException *ex)
 
        /* env_date        ::= nstring */
        camel_imapx_stream_nstring(is, &token, ex);
-       minfo->date_sent = camel_header_decode_date(token, NULL);
+       minfo->date_sent = camel_header_decode_date((gchar *) token, NULL);
 
        /* env_subject     ::= nstring */
        tok = camel_imapx_stream_nstring(is, &token, ex);
-       minfo->subject = camel_pstring_strdup(token);
+       minfo->subject = camel_pstring_strdup((gchar *) token);
 
        /* we merge from/sender into from, append should probably merge more smartly? */
 
@@ -791,7 +814,7 @@ imap_parse_envelope(CamelIMAPXStream *is, CamelException *ex)
        tok = camel_imapx_stream_token(is, &token, &len, ex);
        if (tok != ')') {
                camel_message_info_free(minfo);
-               camel_exception_throw(1, "expecting ')'");
+               camel_exception_set (ex, 1, "expecting ')'");
                return NULL;
        }
 
@@ -803,7 +826,8 @@ imap_parse_envelope(CamelIMAPXStream *is, CamelException *ex)
 struct _CamelMessageContentInfo *
 imap_parse_body(CamelIMAPXStream *is, CamelException *ex)
 {
-       gint tok, len;
+       gint tok;
+       guint len;
        guchar *token;
        struct _CamelMessageContentInfo * volatile cinfo = NULL;
        struct _CamelMessageContentInfo *subinfo, *last;
@@ -841,7 +865,7 @@ imap_parse_body(CamelIMAPXStream *is, CamelException *ex)
                d(printf("media_subtype\n"));
 
                camel_imapx_stream_astring(is, &token, ex);
-               cinfo->type = camel_content_type_new("multipart", token);
+               cinfo->type = camel_content_type_new("multipart", (gchar *) token);
 
                /* body_ext_mpart  ::= body_fld_param
                   [SPACE body_fld_dsp SPACE body_fld_lang
@@ -933,8 +957,9 @@ imap_parse_body(CamelIMAPXStream *is, CamelException *ex)
        /* there should only be simple tokens, no lists */
        do {
                tok = camel_imapx_stream_token(is, &token, &len, ex);
-               if (tok != ')')
+               if (tok != ')') {
                        d(printf("Dropping extension data '%s'\n", token));
+               }
        } while (tok != ')');
 
        /* CHEN TODO handle exceptions better */
@@ -958,7 +983,8 @@ imap_parse_body(CamelIMAPXStream *is, CamelException *ex)
 gchar *
 imap_parse_section(CamelIMAPXStream *is, CamelException *ex)
 {
-       gint tok, len;
+       gint tok;
+       guint len;
        guchar *token;
        gchar * section = NULL;
 
@@ -981,7 +1007,7 @@ imap_parse_section(CamelIMAPXStream *is, CamelException *ex)
 
        tok = camel_imapx_stream_token(is, &token, &len, ex);
        if (tok == IMAP_TOK_INT || tok == IMAP_TOK_TOKEN)
-               section = g_strdup(token);
+               section = g_strdup((gchar *) token);
        else if (tok == ']') {
                section = g_strdup("");
                camel_imapx_stream_ungettoken(is, tok, token, len);
@@ -1041,8 +1067,6 @@ imap_free_fetch(struct _fetch_info *finfo)
        g_free(finfo);
 }
 
-extern void camel_message_info_dump(CamelMessageInfo *mi);
-
 #include <camel/camel-stream-fs.h>
 
 /* debug, dump one out */
@@ -1101,7 +1125,8 @@ imap_dump_fetch(struct _fetch_info *finfo)
 struct _fetch_info *
 imap_parse_fetch(CamelIMAPXStream *is, CamelException *ex)
 {
-       gint tok, len;
+       gint tok;
+       guint len;
        guchar *token, *p, c;
        struct _fetch_info *finfo;
 
@@ -1120,7 +1145,7 @@ imap_parse_fetch(CamelIMAPXStream *is, CamelException *ex)
                while ((c=*p))
                        *p++ = toupper(c);
 
-               switch (imap_tokenise(token, len)) {
+               switch (imap_tokenise((gchar *) token, len)) {
                        case IMAP_ENVELOPE:
                                finfo->minfo = imap_parse_envelope(is, ex);
                                finfo->got |= FETCH_MINFO;
@@ -1132,7 +1157,7 @@ imap_parse_fetch(CamelIMAPXStream *is, CamelException *ex)
                        case IMAP_INTERNALDATE:
                                camel_imapx_stream_nstring(is, &token, ex);
                                /* TODO: convert to camel format? */
-                               finfo->date = g_strdup(token);
+                               finfo->date = g_strdup((gchar *) token);
                                finfo->got |= FETCH_DATE;
                                break;
                        case IMAP_RFC822_HEADER:
@@ -1162,7 +1187,7 @@ imap_parse_fetch(CamelIMAPXStream *is, CamelException *ex)
                                        finfo->got |= FETCH_SECTION;
                                        tok = camel_imapx_stream_token(is, &token, &len, ex);
                                        if (token[0] == '<') {
-                                               finfo->offset = strtoul(token+1, NULL, 10);
+                                               finfo->offset = strtoul((gchar *) token+1, NULL, 10);
                                        } else {
                                                camel_imapx_stream_ungettoken(is, tok, token, len);
                                        }
@@ -1180,7 +1205,7 @@ imap_parse_fetch(CamelIMAPXStream *is, CamelException *ex)
                                        camel_exception_set (ex, 1, "uid not integer");
                                }
 
-                               finfo->uid = g_strdup(token);
+                               finfo->uid = g_strdup((gchar *) token);
                                finfo->got |= FETCH_UID;
                                break;
                        default:
@@ -1204,7 +1229,8 @@ imap_parse_fetch(CamelIMAPXStream *is, CamelException *ex)
 struct _status_info *
 imap_parse_status(CamelIMAPXStream *is, CamelException *ex)
 {
-       gint tok, len;
+       gint tok;
+       guint len;
        guchar *token;
        struct _status_info *sinfo;
 
@@ -1222,7 +1248,7 @@ imap_parse_status(CamelIMAPXStream *is, CamelException *ex)
           ;; Status condition
         */
 
-       sinfo->result = imap_tokenise(token, len);
+       sinfo->result = imap_tokenise((gchar *) token, len);
        switch (sinfo->result) {
                case IMAP_OK:
                case IMAP_NO:
@@ -1239,7 +1265,7 @@ imap_parse_status(CamelIMAPXStream *is, CamelException *ex)
        tok = camel_imapx_stream_token(is, &token, &len, ex);
        if (tok == '[') {
                camel_imapx_stream_atom(is, &token, &len, ex);
-               sinfo->condition = imap_tokenise(token, len);
+               sinfo->condition = imap_tokenise((gchar *) token, len);
 
                /* parse any details */
                switch (sinfo->condition) {
@@ -1256,9 +1282,9 @@ imap_parse_status(CamelIMAPXStream *is, CamelException *ex)
                        case IMAP_NEWNAME:
                                /* the rfc doesn't specify the bnf for this */
                                camel_imapx_stream_astring(is, &token, ex);
-                               sinfo->u.newname.oldname = g_strdup(token);
+                               sinfo->u.newname.oldname = g_strdup((gchar *) token);
                                camel_imapx_stream_astring(is, &token, ex);
-                               sinfo->u.newname.newname = g_strdup(token);
+                               sinfo->u.newname.newname = g_strdup((gchar *) token);
                                break;
                        case IMAP_PERMANENTFLAGS:
                                /* we only care about \* for permanent flags, not user flags */
@@ -1331,7 +1357,7 @@ imap_free_status(struct _status_info *sinfo)
 /* FIXME: use tokeniser? */
 /* FIXME: real flags */
 static struct {
-       gchar *name;
+       const gchar *name;
        guint32 flag;
 } list_flag_table[] = {
        { "\\NOINFERIORS", CAMEL_FOLDER_NOINFERIORS },
@@ -1344,7 +1370,8 @@ struct _list_info *
 imap_parse_list(CamelIMAPXStream *is, CamelException *ex)
 /* throws io, parse */
 {
-       gint tok, len, i;
+       gint tok, i;
+       guint len;
        guchar *token, *p, c;
        struct _list_info * linfo;
 
@@ -1367,7 +1394,7 @@ imap_parse_list(CamelIMAPXStream *is, CamelException *ex)
                        while ((c=*p))
                                *p++ = toupper(c);
                        for (i = 0; i < G_N_ELEMENTS (list_flag_table); i++)
-                               if (!strcmp(token, list_flag_table[i].name))
+                               if (!strcmp((gchar *) token, list_flag_table[i].name))
                                        linfo->flags |= list_flag_table[i].flag;
                } else {
                        imap_free_list(linfo);
@@ -1379,7 +1406,7 @@ imap_parse_list(CamelIMAPXStream *is, CamelException *ex)
        camel_imapx_stream_nstring(is, &token, ex);
        linfo->separator = token?*token:0;
        camel_imapx_stream_astring(is, &token, ex);
-       linfo->name = g_strdup(token);
+       linfo->name = g_strdup((gchar *) token);
 
        return linfo;
 }