aboutsummaryrefslogtreecommitdiffstats
path: root/camel/camel-folder-summary.c
diff options
context:
space:
mode:
authorDan Winship <danw@src.gnome.org>2001-04-27 03:44:50 +0800
committerDan Winship <danw@src.gnome.org>2001-04-27 03:44:50 +0800
commit84e075645b9013f6c0f8200ebddee10b1904936a (patch)
tree74f643de637d9d67844a018ac34354a6872184a0 /camel/camel-folder-summary.c
parent8605f534604aea28d0ebe6385f0f04c7df2a34c7 (diff)
downloadgsoc2013-evolution-84e075645b9013f6c0f8200ebddee10b1904936a.tar.gz
gsoc2013-evolution-84e075645b9013f6c0f8200ebddee10b1904936a.tar.zst
gsoc2013-evolution-84e075645b9013f6c0f8200ebddee10b1904936a.zip
New file, with the int, string, time_t, and off_t encode/decode routines
* camel-file-utils.c: New file, with the int, string, time_t, and off_t encode/decode routines from camel-folder-summary.c moved here and renamed, for the enjoyment of non-CamelFolderSummary subclasses. * Makefile.am (libcamel_la_SOURCES): Add camel-file-utils.c (libcamelinclude_HEADERS): and camel-file-utils.h * camel-folder-summary.c: Remove functions that were moved to camel-file-utils.c, update uses of them for the new names. (camel_folder_summary_{en,de}code_token are still here.) * providers/local/camel-mbox-summary.c: Use camel_file_util_* names * providers/imap/camel-imap-summary.c: Use camel_file_util_* names * providers/imap/camel-imap-store.c (imap_store_setup_online, imap_store_setup_offline): Use camel_file_util_* names, which makes much more sense since this isn't folder summary stuff. svn path=/trunk/; revision=9590
Diffstat (limited to 'camel/camel-folder-summary.c')
-rw-r--r--camel/camel-folder-summary.c395
1 files changed, 64 insertions, 331 deletions
diff --git a/camel/camel-folder-summary.c b/camel/camel-folder-summary.c
index 2627007294..e9b60cebc2 100644
--- a/camel/camel-folder-summary.c
+++ b/camel/camel-folder-summary.c
@@ -24,7 +24,6 @@
#endif
#include <unistd.h>
-#include <netinet/in.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
@@ -32,9 +31,7 @@
#include "camel-folder-summary.h"
-#include <camel/camel-mime-message.h>
-#include <camel/camel-multipart.h>
-
+#include <camel/camel-file-utils.h>
#include <camel/camel-mime-filter.h>
#include <camel/camel-mime-filter-index.h>
#include <camel/camel-mime-filter-charset.h>
@@ -42,6 +39,7 @@
#include <camel/camel-mime-filter-basic.h>
#include <camel/camel-mime-filter-html.h>
#include <camel/camel-mime-message.h>
+#include <camel/camel-multipart.h>
#include <camel/camel-stream-mem.h>
#include "hash-table-utils.h"
@@ -508,7 +506,7 @@ perform_content_info_load(CamelFolderSummary *s, FILE *in)
if (ci == NULL)
return NULL;
- if (camel_folder_summary_decode_uint32(in, &count) == -1 || count > 500) {
+ if (camel_file_util_decode_uint32(in, &count) == -1 || count > 500) {
camel_folder_summary_content_info_free(s, ci);
return NULL;
}
@@ -587,7 +585,7 @@ perform_content_info_save(CamelFolderSummary *s, FILE *out, CamelMessageContentI
CamelMessageContentInfo *part;
((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->content_info_save(s, out, ci);
- camel_folder_summary_encode_uint32(out, my_list_size((struct _node **)&ci->childs));
+ camel_file_util_encode_uint32(out, my_list_size((struct _node **)&ci->childs));
part = ci->childs;
while (part) {
perform_content_info_save(s, out, part);
@@ -1067,200 +1065,6 @@ void camel_folder_summary_remove_index(CamelFolderSummary *s, int index)
}
}
-/**
- * camel_folder_summary_encode_uint32:
- * @out:
- * @value:
- *
- * Utility function to save an uint32 to a file.
- *
- * Return value: -1 on error.
- **/
-int
-camel_folder_summary_encode_uint32(FILE *out, guint32 value)
-{
- int i;
-
- io(printf("Encoding int %u\n", value));
-
- for (i=28;i>0;i-=7) {
- if (value >= (1<<i)) {
- unsigned int c = (value>>i) & 0x7f;
- if (fputc(c, out) == -1)
- return -1;
- }
- }
- return fputc(value | 0x80, out);
-}
-
-/**
- * camel_folder_summary_decode_uint32:
- * @in:
- * @dest:
- *
- * Retrieve an encoded uint32 from a file.
- *
- * Return value: -1 on error. @*dest will contain the
- * decoded value.
- **/
-int
-camel_folder_summary_decode_uint32(FILE *in, guint32 *dest)
-{
- guint32 value=0, v;
-
- /* until we get the last byte, keep decoding 7 bits at a time */
- while ( ((v = fgetc(in)) & 0x80) == 0 && v!=EOF) {
- value |= v;
- value <<= 7;
- }
- if (v == EOF) {
- *dest = value>>7;
- return -1;
- }
- *dest = value | (v&0x7f);
-
- io(printf("Decoding int %u\n", *dest));
-
- return 0;
-}
-
-/**
- * camel_folder_summary_encode_fixed_int32:
- * @out:
- * @value:
- *
- * Encode a gint32, performing no compression, but converting
- * to network order.
- *
- * Return value: -1 on error.
- **/
-int
-camel_folder_summary_encode_fixed_int32(FILE *out, gint32 value)
-{
- guint32 save;
-
- save = htonl(value);
- if (fwrite(&save, sizeof(save), 1, out) != 1)
- return -1;
- return 0;
-}
-
-/**
- * camel_folder_summary_decode_fixed_int32:
- * @in:
- * @dest:
- *
- * Retrieve a gint32.
- *
- * Return value: -1 on error.
- **/
-int
-camel_folder_summary_decode_fixed_int32(FILE *in, gint32 *dest)
-{
- guint32 save;
-
- if (fread(&save, sizeof(save), 1, in) == 1) {
- *dest = ntohl(save);
- return 0;
- } else {
- return -1;
- }
-}
-
-/**
- * camel_folder_summary_encode_time_t:
- * @out:
- * @value:
- *
- * Encode a time_t value to the file.
- *
- * Return value: -1 on error.
- **/
-int
-camel_folder_summary_encode_time_t(FILE *out, time_t value)
-{
- int i;
-
- for (i=sizeof(time_t)-1;i>=0;i--) {
- if (fputc((value >> (i*8)) & 0xff, out) == -1)
- return -1;
- }
- return 0;
-}
-
-/**
- * camel_folder_summary_decode_time_t:
- * @in:
- * @dest:
- *
- * Decode a time_t value.
- *
- * Return value: -1 on error.
- **/
-int
-camel_folder_summary_decode_time_t(FILE *in, time_t *dest)
-{
- time_t save = 0;
- unsigned int v;
- int i = sizeof(time_t) - 1;
-
- while ( i>=0 && (v = fgetc(in)) != EOF) {
- save |= v << (i*8);
- i--;
- }
- *dest = save;
- if (v == EOF)
- return -1;
- return 0;
-}
-
-/**
- * camel_folder_summary_encode_off_t:
- * @out:
- * @value:
- *
- * Encode an off_t type.
- *
- * Return value:
- **/
-int
-camel_folder_summary_encode_off_t(FILE *out, off_t value)
-{
- int i;
-
- for (i=sizeof(off_t)-1;i>=0;i--) {
- if (fputc((value >> (i*8)) & 0xff, out) == -1)
- return -1;
- }
- return 0;
-}
-
-/**
- * camel_folder_summary_decode_off_t:
- * @in:
- * @dest:
- *
- * Decode an off_t type.
- *
- * Return value:
- **/
-int
-camel_folder_summary_decode_off_t(FILE *in, off_t *dest)
-{
- off_t save = 0;
- unsigned int v;
- int i = sizeof(off_t) - 1;
-
- while ( i>=0 && (v = fgetc(in)) != EOF) {
- save |= v << (i*8);
- i--;
- }
- *dest = save;
- if (v == EOF)
- return -1;
- return 0;
-}
-
/* should be sorted, for binary search */
/* This is a tokenisation mechanism for strings written to the
summary - to save space.
@@ -1327,7 +1131,7 @@ camel_folder_summary_encode_token(FILE *out, const char *str)
io(printf("Encoding token: '%s'\n", str));
if (str == NULL) {
- return camel_folder_summary_encode_uint32(out, 0);
+ return camel_file_util_encode_uint32(out, 0);
} else {
int len = strlen(str);
int i, token=-1;
@@ -1353,9 +1157,9 @@ camel_folder_summary_encode_token(FILE *out, const char *str)
#endif
}
if (token != -1) {
- return camel_folder_summary_encode_uint32(out, token+1);
+ return camel_file_util_encode_uint32(out, token+1);
} else {
- if (camel_folder_summary_encode_uint32(out, len+32) == -1)
+ if (camel_file_util_encode_uint32(out, len+32) == -1)
return -1;
if (fwrite(str, len, 1, out) != 1)
return -1;
@@ -1381,7 +1185,7 @@ camel_folder_summary_decode_token(FILE *in, char **str)
io(printf("Decode token ...\n"));
- if (camel_folder_summary_decode_uint32(in, &len) == -1) {
+ if (camel_file_util_decode_uint32(in, &len) == -1) {
g_warning("Could not decode token from file");
*str = NULL;
return -1;
@@ -1418,77 +1222,6 @@ camel_folder_summary_decode_token(FILE *in, char **str)
return 0;
}
-/**
- * camel_folder_summary_encode_string:
- * @out:
- * @str:
- *
- * Encode a normal string and save it in the output file.
- *
- * Return value: -1 on error.
- **/
-int
-camel_folder_summary_encode_string(FILE *out, const char *str)
-{
- register int len;
-
- io(printf("Encoding string: '%s'\n", str));
-
- if (str == NULL)
- return camel_folder_summary_encode_uint32(out, 0);
-
- len = strlen(str);
- if (camel_folder_summary_encode_uint32(out, len+1) == -1)
- return -1;
- if (fwrite(str, len, 1, out) == 1)
- return 0;
- return -1;
-}
-
-
-/**
- * camel_folder_summary_decode_string:
- * @in:
- * @str:
- *
- * Decode a normal string from the input file.
- *
- * Return value: -1 on error.
- **/
-int
-camel_folder_summary_decode_string(FILE *in, char **str)
-{
- guint32 len;
- register char *ret;
-
- io(printf("Decode string ...\n", str));
-
- if (camel_folder_summary_decode_uint32(in, &len) == -1) {
- *str = NULL;
- return -1;
- }
-
- len--;
- if (len > 65536) {
- *str = NULL;
- io(printf("String = '%s'\n", *str));
- return -1;
- }
-
- ret = g_malloc(len+1);
- if (fread(ret, len, 1, in) != 1) {
- g_free(ret);
- *str = NULL;
- return -1;
- }
-
- io(printf("String = '%s'\n", ret));
-
- ret[len] = 0;
- *str = ret;
- return 0;
-}
-
static struct _node *
my_list_append(struct _node **list, struct _node *n)
{
@@ -1522,11 +1255,11 @@ summary_header_load(CamelFolderSummary *s, FILE *in)
io(printf("Loading header\n"));
- if (camel_folder_summary_decode_fixed_int32(in, &version) == -1
- || camel_folder_summary_decode_fixed_int32(in, &flags) == -1
- || camel_folder_summary_decode_fixed_int32(in, &nextuid) == -1
- || camel_folder_summary_decode_time_t(in, &time) == -1
- || camel_folder_summary_decode_fixed_int32(in, &count) == -1) {
+ if (camel_file_util_decode_fixed_int32(in, &version) == -1
+ || camel_file_util_decode_fixed_int32(in, &flags) == -1
+ || camel_file_util_decode_fixed_int32(in, &nextuid) == -1
+ || camel_file_util_decode_time_t(in, &time) == -1
+ || camel_file_util_decode_fixed_int32(in, &count) == -1) {
return -1;
}
@@ -1548,11 +1281,11 @@ summary_header_save(CamelFolderSummary *s, FILE *out)
io(printf("Savining header\n"));
- camel_folder_summary_encode_fixed_int32(out, s->version);
- camel_folder_summary_encode_fixed_int32(out, s->flags);
- camel_folder_summary_encode_fixed_int32(out, s->nextuid);
- camel_folder_summary_encode_time_t(out, s->time);
- return camel_folder_summary_encode_fixed_int32(out, camel_folder_summary_count(s));
+ camel_file_util_encode_fixed_int32(out, s->version);
+ camel_file_util_encode_fixed_int32(out, s->flags);
+ camel_file_util_encode_fixed_int32(out, s->nextuid);
+ camel_file_util_encode_time_t(out, s->time);
+ return camel_file_util_encode_fixed_int32(out, camel_folder_summary_count(s));
}
/* are these even useful for anything??? */
@@ -1799,16 +1532,16 @@ message_info_load(CamelFolderSummary *s, FILE *in)
io(printf("Loading message info\n"));
- camel_folder_summary_decode_string(in, &uid);
- camel_folder_summary_decode_uint32(in, &mi->flags);
- camel_folder_summary_decode_uint32(in, &mi->size);
- camel_folder_summary_decode_time_t(in, &mi->date_sent);
- camel_folder_summary_decode_time_t(in, &mi->date_received);
- camel_folder_summary_decode_string(in, &subject);
- camel_folder_summary_decode_string(in, &from);
- camel_folder_summary_decode_string(in, &to);
- camel_folder_summary_decode_string(in, &cc);
- camel_folder_summary_decode_string(in, &mlist);
+ camel_file_util_decode_string(in, &uid);
+ camel_file_util_decode_uint32(in, &mi->flags);
+ camel_file_util_decode_uint32(in, &mi->size);
+ camel_file_util_decode_time_t(in, &mi->date_sent);
+ camel_file_util_decode_time_t(in, &mi->date_received);
+ camel_file_util_decode_string(in, &subject);
+ camel_file_util_decode_string(in, &from);
+ camel_file_util_decode_string(in, &to);
+ camel_file_util_decode_string(in, &cc);
+ camel_file_util_decode_string(in, &mlist);
#ifdef DOEPOOLV
e_poolv_set(mi->strings, CAMEL_MESSAGE_INFO_UID, uid, TRUE);
@@ -1835,38 +1568,38 @@ message_info_load(CamelFolderSummary *s, FILE *in)
mi->content = NULL;
- camel_folder_summary_decode_fixed_int32(in, &mi->message_id.id.part.hi);
- camel_folder_summary_decode_fixed_int32(in, &mi->message_id.id.part.lo);
+ camel_file_util_decode_fixed_int32(in, &mi->message_id.id.part.hi);
+ camel_file_util_decode_fixed_int32(in, &mi->message_id.id.part.lo);
- if (camel_folder_summary_decode_uint32(in, &count) == -1 || count > 500)
+ if (camel_file_util_decode_uint32(in, &count) == -1 || count > 500)
goto error;
if (count > 0) {
mi->references = g_malloc(sizeof(*mi->references) + ((count-1) * sizeof(mi->references->references[0])));
mi->references->size = count;
for (i=0;i<count;i++) {
- camel_folder_summary_decode_fixed_int32(in, &mi->references->references[i].id.part.hi);
- camel_folder_summary_decode_fixed_int32(in, &mi->references->references[i].id.part.lo);
+ camel_file_util_decode_fixed_int32(in, &mi->references->references[i].id.part.hi);
+ camel_file_util_decode_fixed_int32(in, &mi->references->references[i].id.part.lo);
}
}
- if (camel_folder_summary_decode_uint32(in, &count) == -1 || count > 500)
+ if (camel_file_util_decode_uint32(in, &count) == -1 || count > 500)
goto error;
for (i=0;i<count;i++) {
char *name;
- camel_folder_summary_decode_string(in, &name);
+ camel_file_util_decode_string(in, &name);
camel_flag_set(&mi->user_flags, name, TRUE);
g_free(name);
}
- if (camel_folder_summary_decode_uint32(in, &count) == -1 || count > 500)
+ if (camel_file_util_decode_uint32(in, &count) == -1 || count > 500)
goto error;
for (i=0;i<count;i++) {
char *name, *value;
- camel_folder_summary_decode_string(in, &name);
- camel_folder_summary_decode_string(in, &value);
+ camel_file_util_decode_string(in, &name);
+ camel_file_util_decode_string(in, &value);
camel_tag_set(&mi->user_tags, name, value);
g_free(name);
g_free(value);
@@ -1891,44 +1624,44 @@ message_info_save(CamelFolderSummary *s, FILE *out, CamelMessageInfo *mi)
io(printf("Saving message info\n"));
- camel_folder_summary_encode_string(out, camel_message_info_uid(mi));
- camel_folder_summary_encode_uint32(out, mi->flags);
- camel_folder_summary_encode_uint32(out, mi->size);
- camel_folder_summary_encode_time_t(out, mi->date_sent);
- camel_folder_summary_encode_time_t(out, mi->date_received);
- camel_folder_summary_encode_string(out, camel_message_info_subject(mi));
- camel_folder_summary_encode_string(out, camel_message_info_from(mi));
- camel_folder_summary_encode_string(out, camel_message_info_to(mi));
- camel_folder_summary_encode_string(out, camel_message_info_cc(mi));
- camel_folder_summary_encode_string(out, camel_message_info_mlist(mi));
+ camel_file_util_encode_string(out, camel_message_info_uid(mi));
+ camel_file_util_encode_uint32(out, mi->flags);
+ camel_file_util_encode_uint32(out, mi->size);
+ camel_file_util_encode_time_t(out, mi->date_sent);
+ camel_file_util_encode_time_t(out, mi->date_received);
+ camel_file_util_encode_string(out, camel_message_info_subject(mi));
+ camel_file_util_encode_string(out, camel_message_info_from(mi));
+ camel_file_util_encode_string(out, camel_message_info_to(mi));
+ camel_file_util_encode_string(out, camel_message_info_cc(mi));
+ camel_file_util_encode_string(out, camel_message_info_mlist(mi));
- camel_folder_summary_encode_fixed_int32(out, mi->message_id.id.part.hi);
- camel_folder_summary_encode_fixed_int32(out, mi->message_id.id.part.lo);
+ camel_file_util_encode_fixed_int32(out, mi->message_id.id.part.hi);
+ camel_file_util_encode_fixed_int32(out, mi->message_id.id.part.lo);
if (mi->references) {
- camel_folder_summary_encode_uint32(out, mi->references->size);
+ camel_file_util_encode_uint32(out, mi->references->size);
for (i=0;i<mi->references->size;i++) {
- camel_folder_summary_encode_fixed_int32(out, mi->references->references[i].id.part.hi);
- camel_folder_summary_encode_fixed_int32(out, mi->references->references[i].id.part.lo);
+ camel_file_util_encode_fixed_int32(out, mi->references->references[i].id.part.hi);
+ camel_file_util_encode_fixed_int32(out, mi->references->references[i].id.part.lo);
}
} else {
- camel_folder_summary_encode_uint32(out, 0);
+ camel_file_util_encode_uint32(out, 0);
}
count = camel_flag_list_size(&mi->user_flags);
- camel_folder_summary_encode_uint32(out, count);
+ camel_file_util_encode_uint32(out, count);
flag = mi->user_flags;
while (flag) {
- camel_folder_summary_encode_string(out, flag->name);
+ camel_file_util_encode_string(out, flag->name);
flag = flag->next;
}
count = camel_tag_list_size(&mi->user_tags);
- camel_folder_summary_encode_uint32(out, count);
+ camel_file_util_encode_uint32(out, count);
tag = mi->user_tags;
while (tag) {
- camel_folder_summary_encode_string(out, tag->name);
- camel_folder_summary_encode_string(out, tag->value);
+ camel_file_util_encode_string(out, tag->name);
+ camel_file_util_encode_string(out, tag->value);
tag = tag->next;
}
@@ -1987,7 +1720,7 @@ content_info_load(CamelFolderSummary *s, FILE *in)
ct = header_content_type_new(type, subtype);
g_free(type); /* can this be removed? */
g_free(subtype);
- if (camel_folder_summary_decode_uint32(in, &count) == -1 || count > 500)
+ if (camel_file_util_decode_uint32(in, &count) == -1 || count > 500)
goto error;
for (i=0;i<count;i++) {
@@ -2005,7 +1738,7 @@ content_info_load(CamelFolderSummary *s, FILE *in)
camel_folder_summary_decode_token(in, &ci->description);
camel_folder_summary_decode_token(in, &ci->encoding);
- camel_folder_summary_decode_uint32(in, &ci->size);
+ camel_file_util_decode_uint32(in, &ci->size);
ci->childs = NULL;
@@ -2029,7 +1762,7 @@ content_info_save(CamelFolderSummary *s, FILE *out, CamelMessageContentInfo *ci)
if (ct) {
camel_folder_summary_encode_token(out, ct->type);
camel_folder_summary_encode_token(out, ct->subtype);
- camel_folder_summary_encode_uint32(out, my_list_size((struct _node **)&ct->params));
+ camel_file_util_encode_uint32(out, my_list_size((struct _node **)&ct->params));
hp = ct->params;
while (hp) {
camel_folder_summary_encode_token(out, hp->name);
@@ -2039,12 +1772,12 @@ content_info_save(CamelFolderSummary *s, FILE *out, CamelMessageContentInfo *ci)
} else {
camel_folder_summary_encode_token(out, NULL);
camel_folder_summary_encode_token(out, NULL);
- camel_folder_summary_encode_uint32(out, 0);
+ camel_file_util_encode_uint32(out, 0);
}
camel_folder_summary_encode_token(out, ci->id);
camel_folder_summary_encode_token(out, ci->description);
camel_folder_summary_encode_token(out, ci->encoding);
- return camel_folder_summary_encode_uint32(out, ci->size);
+ return camel_file_util_encode_uint32(out, ci->size);
}
static void