diff options
author | Youngjae Shin <yj99.shin@samsung.com> | 2018-05-10 17:57:02 +0900 |
---|---|---|
committer | Youngjae Shin <yj99.shin@samsung.com> | 2018-05-11 11:20:56 +0900 |
commit | 59094ba7ecd29056e5cf2f823ef643439dc587bc (patch) | |
tree | 0c88e7a5a84f524a1c094d01a66426a8613b5927 | |
parent | 6c55b0e1953153366ca1c1fd3dea4b29f8e6ff3c (diff) | |
download | email-service-59094ba7ecd29056e5cf2f823ef643439dc587bc.tar.gz email-service-59094ba7ecd29056e5cf2f823ef643439dc587bc.tar.bz2 email-service-59094ba7ecd29056e5cf2f823ef643439dc587bc.zip |
fix wrong memory release and remove warningssubmit/tizen/20180511.040931submit/tizen/20180511.040502accepted/tizen/unified/20180511.074020
Change-Id: I11dd32be52492421a30016671126019d11ed0ecf
-rw-r--r-- | email-common-use/tpl.c | 4241 | ||||
-rwxr-xr-x | email-core/email-core-cert.c | 5 | ||||
-rwxr-xr-x | email-core/email-core-mailbox-sync.c | 902 | ||||
-rwxr-xr-x | email-core/email-core-mm-callbacks.c | 145 | ||||
-rwxr-xr-x | email-core/email-core-smtp.c | 1109 | ||||
-rwxr-xr-x | email-core/email-storage/email-storage.c | 4775 | ||||
-rw-r--r-- | test/testapp-account.c | 684 | ||||
-rw-r--r-- | test/testapp-rule.c | 90 |
8 files changed, 5978 insertions, 5973 deletions
diff --git a/email-common-use/tpl.c b/email-common-use/tpl.c index 627e33c..6a76561 100644 --- a/email-common-use/tpl.c +++ b/email-common-use/tpl.c @@ -1,29 +1,29 @@ /* -Copyright (c) 2005-2010, Troy D. Hanson http:://tpl.sourceforge.net -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS -IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER -OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ + Copyright (c) 2005-2010, Troy D. Hanson http:://tpl.sourceforge.net + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ #define TPL_VERSION 1.5 -static const char id[] = "$Id : tpl.c 192 2009-04-24 10:35:30Z thanson $"; +//static const char id[] = "$Id : tpl.c 192 2009-04-24 10:35:30Z thanson $"; #include <stdlib.h> /* malloc */ @@ -69,18 +69,18 @@ typedef unsigned __int64 uint64_t; /* macro to add a structure to a doubly-linked list */ #define DL_ADD(head, add) \ - do { \ - if (head) { \ - (add)->prev = (head)->prev; \ - (head)->prev->next = (add); \ - (head)->prev = (add); \ - (add)->next = NULL; \ - } else { \ - (head) = (add); \ - (head)->prev = (head); \ - (head)->next = NULL; \ - } \ - } while (0); + do { \ + if (head) { \ + (add)->prev = (head)->prev; \ + (head)->prev->next = (add); \ + (head)->prev = (add); \ + (add)->next = NULL; \ + } else { \ + (head) = (add); \ + (head)->prev = (head); \ + (head)->next = NULL; \ + } \ + } while (0); #define fatal_oom() tpl_hook.fatal("out of memory\n") @@ -125,50 +125,50 @@ typedef unsigned __int64 uint64_t; /* access to A(...) nodes by index */ typedef struct tpl_pidx { - struct tpl_node *node; - struct tpl_pidx *next, *prev; + struct tpl_node *node; + struct tpl_pidx *next, *prev; } tpl_pidx; /* A(...) node datum */ typedef struct tpl_atyp { - uint32_t num; /* num elements */ - size_t sz; /* size of each backbone's datum */ - struct tpl_backbone *bb, *bbtail; - void *cur; + uint32_t num; /* num elements */ + size_t sz; /* size of each backbone's datum */ + struct tpl_backbone *bb, *bbtail; + void *cur; } tpl_atyp; /* backbone to extend A(...) lists dynamically */ typedef struct tpl_backbone { - struct tpl_backbone *next; - /* when this structure is malloc'd, extra space is alloc'd at the - * end to store the backbone "datum", and data points to it. */ + struct tpl_backbone *next; + /* when this structure is malloc'd, extra space is alloc'd at the + * end to store the backbone "datum", and data points to it. */ #if __STDC_VERSION__ < 199901 - char *data; + char *data; #else - char data[]; + char data[]; #endif } tpl_backbone; /* mmap record */ typedef struct tpl_mmap_rec { - int fd; - void *text; - size_t text_sz; + int fd; + void *text; + size_t text_sz; } tpl_mmap_rec; /* root node datum */ typedef struct tpl_root_data { - int flags; - tpl_pidx *pidx; - tpl_mmap_rec mmap; - char *fmt; - int *fxlens, num_fxlens; + int flags; + tpl_pidx *pidx; + tpl_mmap_rec mmap; + char *fmt; + int *fxlens, num_fxlens; } tpl_root_data; /* node type to size mapping */ struct tpl_type_t { - char c; - int sz; + char c; + int sz; }; @@ -203,80 +203,80 @@ static tpl_node *tpl_map_va(char *fmt, va_list ap); * Also SPARC and x86_64 seem to align always on +8. */ struct tpl_double_alignment_detector { - char a; - double d; /* some platforms align this on +4, others on +8 */ + char a; + double d; /* some platforms align this on +4, others on +8 */ }; /* this is another case where alignment varies. mac os x/gcc was observed * to align the int64_t at +4 under -m32 and at +8 under -m64 */ struct tpl_int64_alignment_detector { - int i; - int64_t j; /* some platforms align this on +4, others on +8 */ + int i; + int64_t j; /* some platforms align this on +4, others on +8 */ }; typedef struct { - size_t inter_elt_len; /* padded inter-element len; i.e. &a[1].field - &a[0].field */ - tpl_node *iter_start_node; /* node to jump back to, as we start each new iteration */ - size_t iternum; /* current iteration number (total req'd. iter's in n->num) */ + size_t inter_elt_len; /* padded inter-element len; i.e. &a[1].field - &a[0].field */ + tpl_node *iter_start_node; /* node to jump back to, as we start each new iteration */ + size_t iternum; /* current iteration number (total req'd. iter's in n->num) */ } tpl_pound_data; /* Hooks for customizing tpl mem alloc, error handling, etc. Set defaults. */ tpl_hook_t tpl_hook = { - /* .oops = */ tpl_oops, - /* .malloc = */ malloc, - /* .realloc = */ realloc, - /* .free = */ free, - /* .fatal = */ tpl_fatal, - /* .gather_max = */ 0 /* max tpl size (bytes) for tpl_gather */ + /* .oops = */ tpl_oops, + /* .malloc = */ malloc, + /* .realloc = */ realloc, + /* .free = */ free, + /* .fatal = */ tpl_fatal, + /* .gather_max = */ 0 /* max tpl size (bytes) for tpl_gather */ }; static const char tpl_fmt_chars[] = "AS($)BiucsfIUjv#"; /* valid format chars */ -static const char tpl_S_fmt_chars[] = "iucsfIUjv#$()"; /* valid within S(...) */ +//static const char tpl_S_fmt_chars[] = "iucsfIUjv#$()"; /* valid within S(...) */ static const char tpl_datapeek_ok_chars[] = "iucsfIUjv"; /* valid in datapeek */ static const struct tpl_type_t tpl_types[] = { - /* [TPL_TYPE_ROOT] = */ {'r', 0}, - /* [TPL_TYPE_INT32] = */ {'i', sizeof(int32_t)}, - /* [TPL_TYPE_UINT32] = */ {'u', sizeof(uint32_t)}, - /* [TPL_TYPE_BYTE] = */ {'c', sizeof(char)}, - /* [TPL_TYPE_STR] = */ {'s', sizeof(char*)}, - /* [TPL_TYPE_ARY] = */ {'A', 0}, - /* [TPL_TYPE_BIN] = */ {'B', 0}, - /* [TPL_TYPE_DOUBLE] = */ {'f', 8}, /* not sizeof(double) as that varies */ - /* [TPL_TYPE_INT64] = */ {'I', sizeof(int64_t)}, - /* [TPL_TYPE_UINT64] = */ {'U', sizeof(uint64_t)}, - /* [TPL_TYPE_INT16] = */ {'j', sizeof(int16_t)}, - /* [TPL_TYPE_UINT16] = */ {'v', sizeof(uint16_t)}, - /* [TPL_TYPE_POUND] = */ {'#', 0}, + /* [TPL_TYPE_ROOT] = */ {'r', 0}, + /* [TPL_TYPE_INT32] = */ {'i', sizeof(int32_t)}, + /* [TPL_TYPE_UINT32] = */ {'u', sizeof(uint32_t)}, + /* [TPL_TYPE_BYTE] = */ {'c', sizeof(char)}, + /* [TPL_TYPE_STR] = */ {'s', sizeof(char*)}, + /* [TPL_TYPE_ARY] = */ {'A', 0}, + /* [TPL_TYPE_BIN] = */ {'B', 0}, + /* [TPL_TYPE_DOUBLE] = */ {'f', 8}, /* not sizeof(double) as that varies */ + /* [TPL_TYPE_INT64] = */ {'I', sizeof(int64_t)}, + /* [TPL_TYPE_UINT64] = */ {'U', sizeof(uint64_t)}, + /* [TPL_TYPE_INT16] = */ {'j', sizeof(int16_t)}, + /* [TPL_TYPE_UINT16] = */ {'v', sizeof(uint16_t)}, + /* [TPL_TYPE_POUND] = */ {'#', 0}, }; /* default error-reporting function. Just writes to stderr. */ static int tpl_oops(const char *fmt, ...) { char buf[256]; - va_list ap; - va_start(ap, fmt); -/* vfprintf(stderr, fmt, ap); */ + va_list ap; + va_start(ap, fmt); + /* vfprintf(stderr, fmt, ap); */ snprintf(buf, sizeof(buf)-1, fmt, ap); EM_DEBUG_EXCEPTION("%s", buf); - va_end(ap); - return 0; + va_end(ap); + return 0; } static tpl_node *tpl_node_new(tpl_node *parent) { - tpl_node *n; - if ((n = tpl_hook.malloc(sizeof(tpl_node))) == NULL) { - fatal_oom(); - } - n->addr = NULL; - n->data = NULL; - n->num = 1; - n->ser_osz = 0; - n->children = NULL; - n->next = NULL; - n->parent = parent; - return n; + tpl_node *n; + if ((n = tpl_hook.malloc(sizeof(tpl_node))) == NULL) + fatal_oom(); + + n->addr = NULL; + n->data = NULL; + n->num = 1; + n->ser_osz = 0; + n->children = NULL; + n->next = NULL; + n->parent = parent; + return n; } /* Used in S(..) formats to pack several fields from a structure based on @@ -289,555 +289,554 @@ static tpl_node *tpl_node_new(tpl_node *parent) */ char *calc_field_addr(tpl_node *parent, int type, char *struct_addr, int ordinal) { - tpl_node *prev; - int offset; - int align_sz; - - if (ordinal == 1) return struct_addr; /* first field starts on structure address */ - - /* generate enough padding so field addr is divisible by it's align_sz. 4, 8, etc */ - prev = parent->children->prev; - switch (type) { - case TPL_TYPE_DOUBLE: - align_sz = sizeof(struct tpl_double_alignment_detector) > 12 ? 8 : 4; - break; - case TPL_TYPE_INT64: - case TPL_TYPE_UINT64: - align_sz = sizeof(struct tpl_int64_alignment_detector) > 12 ? 8 : 4; - break; - default: - align_sz = tpl_types[type].sz; - break; - } - offset = ((uintptr_t)prev->addr - (uintptr_t)struct_addr) - + (tpl_types[prev->type].sz * prev->num); - offset = (offset + align_sz - 1) / align_sz * align_sz; - return struct_addr + offset; + tpl_node *prev; + int offset; + int align_sz; + + if (ordinal == 1) return struct_addr; /* first field starts on structure address */ + + /* generate enough padding so field addr is divisible by it's align_sz. 4, 8, etc */ + prev = parent->children->prev; + switch (type) { + case TPL_TYPE_DOUBLE: + align_sz = sizeof(struct tpl_double_alignment_detector) > 12 ? 8 : 4; + break; + case TPL_TYPE_INT64: + case TPL_TYPE_UINT64: + align_sz = sizeof(struct tpl_int64_alignment_detector) > 12 ? 8 : 4; + break; + default: + align_sz = tpl_types[type].sz; + break; + } + offset = ((uintptr_t)prev->addr - (uintptr_t)struct_addr) + + (tpl_types[prev->type].sz * prev->num); + offset = (offset + align_sz - 1) / align_sz * align_sz; + return struct_addr + offset; } TPL_API tpl_node *tpl_map(char *fmt, ...) { - va_list ap; - tpl_node *tn; + va_list ap; + tpl_node *tn; - va_start(ap, fmt); - tn = tpl_map_va(fmt, ap); - va_end(ap); - return tn; + va_start(ap, fmt); + tn = tpl_map_va(fmt, ap); + va_end(ap); + return tn; } static tpl_node *tpl_map_va(char *fmt, va_list ap) { - int lparen_level = 0, expect_lparen = 0, t = 0, in_structure = 0, ordinal = 0; - int in_nested_structure = 0; - char *c, *peek, *struct_addr = NULL, *struct_next; - tpl_node *root, *parent, *n = NULL, *preceding, *iter_start_node = NULL, - *struct_widest_node = NULL, *np; tpl_pidx *pidx; - tpl_pound_data *pd; - int *fxlens, num_fxlens, pound_num, pound_prod, applies_to_struct; - int contig_fxlens[10]; /* temp space for contiguous fxlens */ - int num_contig_fxlens, i, j; - ptrdiff_t inter_elt_len = 0; /* padded element length of contiguous structs in array */ - - - root = tpl_node_new(NULL); - root->type = TPL_TYPE_ROOT; - root->data = (tpl_root_data*)tpl_hook.malloc(sizeof(tpl_root_data)); - if (!root->data) fatal_oom(); - memset((tpl_root_data*)root->data, 0, sizeof(tpl_root_data)); - - /* set up root nodes special ser_osz to reflect overhead of preamble */ - root->ser_osz = sizeof(uint32_t); /* tpl leading length */ - root->ser_osz += EM_SAFE_STRLEN(fmt) + 1; /* fmt + NUL-terminator */ - root->ser_osz += 4; /* 'tpl' magic prefix + flags byte */ - - parent = root; - - c = fmt; - while (*c != '\0') { - switch (*c) { - case 'c': - case 'i': - case 'u': - case 'j': - case 'v': - case 'I': - case 'U': - case 'f': - if (*c == 'c') t = TPL_TYPE_BYTE; - else if (*c == 'i') t = TPL_TYPE_INT32; - else if (*c == 'u') t = TPL_TYPE_UINT32; - else if (*c == 'j') t = TPL_TYPE_INT16; - else if (*c == 'v') t = TPL_TYPE_UINT16; - else if (*c == 'I') t = TPL_TYPE_INT64; - else if (*c == 'U') t = TPL_TYPE_UINT64; - else if (*c == 'f') t = TPL_TYPE_DOUBLE; - - if (expect_lparen) goto fail; - n = tpl_node_new(parent); - n->type = t; - if (in_structure) { - if (ordinal == 1) { - /* for S(...)# iteration. Apply any changes to case 's' too!!! */ - iter_start_node = n; - struct_widest_node = n; - } - if (tpl_types[n->type].sz > tpl_types[struct_widest_node->type].sz) { - struct_widest_node = n; - } - n->addr = calc_field_addr(parent, n->type, struct_addr, ordinal++); - } else n->addr = (void*)va_arg(ap, void*); - n->data = tpl_hook.malloc(tpl_types[t].sz); - if (!n->data) fatal_oom(); - if (n->parent->type == TPL_TYPE_ARY) - ((tpl_atyp*)(n->parent->data))->sz += tpl_types[t].sz; - DL_ADD(parent->children, n); - break; - case 's': - if (expect_lparen) goto fail; - n = tpl_node_new(parent); - n->type = TPL_TYPE_STR; - if (in_structure) { - if (ordinal == 1) { - iter_start_node = n; /* for S(...)# iteration */ - struct_widest_node = n; - } - if (tpl_types[n->type].sz > tpl_types[struct_widest_node->type].sz) { - struct_widest_node = n; - } - n->addr = calc_field_addr(parent, n->type, struct_addr, ordinal++); - } else n->addr = (void*)va_arg(ap, void*); - n->data = tpl_hook.malloc(sizeof(char*)); - if (!n->data) fatal_oom(); - *(char**)(n->data) = NULL; - if (n->parent->type == TPL_TYPE_ARY) - ((tpl_atyp*)(n->parent->data))->sz += sizeof(void*); - DL_ADD(parent->children, n); - break; - case '#': - /* apply a 'num' to preceding atom */ - if (!parent->children) goto fail; - preceding = parent->children->prev; /* first child's prev is 'last child'*/ - t = preceding->type; - applies_to_struct = (*(c-1) == ')') ? 1 : 0; - if (!applies_to_struct) { - if (!(t == TPL_TYPE_BYTE || t == TPL_TYPE_INT32 || - t == TPL_TYPE_UINT32 || t == TPL_TYPE_DOUBLE || - t == TPL_TYPE_UINT64 || t == TPL_TYPE_INT64 || - t == TPL_TYPE_UINT16 || t == TPL_TYPE_INT16 || - t == TPL_TYPE_STR)) goto fail; - } - /* count up how many contiguous # and form their product */ - pound_prod = 1; - num_contig_fxlens = 0; - for (peek = c; *peek == '#'; peek++) { - pound_num = va_arg(ap, int); - if (pound_num < 1) { - tpl_hook.fatal("non-positive iteration count %d\n", pound_num); - } - if (num_contig_fxlens >= (sizeof(contig_fxlens)/sizeof(contig_fxlens[0]))) { - tpl_hook.fatal("contiguous # exceeds hardcoded limit\n"); - } - contig_fxlens[num_contig_fxlens++] = pound_num; - pound_prod *= pound_num; - } - /* increment c to skip contiguous # so its points to last one */ - c = peek-1; - /* differentiate atom-# from struct-# by noting preceding rparen */ - if (applies_to_struct) { /* insert # node to induce looping */ - n = tpl_node_new(parent); - n->type = TPL_TYPE_POUND; - n->num = pound_prod; - n->data = tpl_hook.malloc(sizeof(tpl_pound_data)); - if (!n->data) fatal_oom(); - pd = (tpl_pound_data*)n->data; - pd->inter_elt_len = inter_elt_len; - pd->iter_start_node = iter_start_node; - pd->iternum = 0; - DL_ADD(parent->children, n); - /* multiply the 'num' and data space on each atom in the structure */ - for (np = iter_start_node; np != n; np = np->next) { - if (n->parent->type == TPL_TYPE_ARY) { - ((tpl_atyp*)(n->parent->data))->sz += - tpl_types[np->type].sz * (np->num * (n->num - 1)); - } - np->data = tpl_hook.realloc(np->data, tpl_types[np->type].sz * - np->num * n->num); - if (!np->data) fatal_oom(); - memset(np->data, 0, tpl_types[np->type].sz * np->num * n->num); - } - } else { /* simple atom-# form does not require a loop */ - preceding->num = pound_prod; - preceding->data = tpl_hook.realloc(preceding->data, - tpl_types[t].sz * preceding->num); - if (!preceding->data) fatal_oom(); - memset(preceding->data, 0, tpl_types[t].sz * preceding->num); - if (n->parent->type == TPL_TYPE_ARY) { - ((tpl_atyp*)(n->parent->data))->sz += tpl_types[t].sz * - (preceding->num-1); - } - } - root->ser_osz += (sizeof(uint32_t) * num_contig_fxlens); - - j = ((tpl_root_data*)root->data)->num_fxlens; /* before incrementing */ - (((tpl_root_data*)root->data)->num_fxlens) += num_contig_fxlens; - num_fxlens = ((tpl_root_data*)root->data)->num_fxlens; /* new value */ - fxlens = ((tpl_root_data*)root->data)->fxlens; - fxlens = tpl_hook.realloc(fxlens, sizeof(int) * num_fxlens); - if (!fxlens) fatal_oom(); - ((tpl_root_data*)root->data)->fxlens = fxlens; - for (i = 0; i < num_contig_fxlens; i++) fxlens[j++] = contig_fxlens[i]; - - break; - case 'B': - if (expect_lparen) goto fail; - if (in_structure) goto fail; - n = tpl_node_new(parent); - n->type = TPL_TYPE_BIN; - n->addr = (tpl_bin*)va_arg(ap, void*); - n->data = tpl_hook.malloc(sizeof(tpl_bin*)); - if (!n->data) fatal_oom(); - *((tpl_bin**)n->data) = NULL; - if (n->parent->type == TPL_TYPE_ARY) - ((tpl_atyp*)(n->parent->data))->sz += sizeof(tpl_bin); - DL_ADD(parent->children, n); - break; - case 'A': - if (in_structure) goto fail; - n = tpl_node_new(parent); - n->type = TPL_TYPE_ARY; - DL_ADD(parent->children, n); - parent = n; - expect_lparen = 1; - pidx = (tpl_pidx*)tpl_hook.malloc(sizeof(tpl_pidx)); - if (!pidx) fatal_oom(); - pidx->node = n; - pidx->next = NULL; - DL_ADD(((tpl_root_data*)(root->data))->pidx, pidx); - /* set up the A's tpl_atyp */ - n->data = (tpl_atyp*)tpl_hook.malloc(sizeof(tpl_atyp)); - if (!n->data) fatal_oom(); - ((tpl_atyp*)(n->data))->num = 0; - ((tpl_atyp*)(n->data))->sz = 0; - ((tpl_atyp*)(n->data))->bb = NULL; - ((tpl_atyp*)(n->data))->bbtail = NULL; - ((tpl_atyp*)(n->data))->cur = NULL; - if (n->parent->type == TPL_TYPE_ARY) - ((tpl_atyp*)(n->parent->data))->sz += sizeof(void*); - break; - case 'S': - if (in_structure) goto fail; - expect_lparen = 1; - ordinal = 1; /* index upcoming atoms in S(..) */ - in_structure = 1+lparen_level; /* so we can tell where S fmt ends */ - struct_addr = (char*)va_arg(ap, void*); - break; - case '$': /* nested structure */ - if (!in_structure) goto fail; - expect_lparen = 1; - in_nested_structure++; - break; - case ')': - lparen_level--; - if (lparen_level < 0) goto fail; - if (*(c-1) == '(') goto fail; - if (in_nested_structure) in_nested_structure--; - else if (in_structure && (in_structure-1 == lparen_level)) { - /* calculate delta between contiguous structures in array */ - struct_next = calc_field_addr(parent, struct_widest_node->type, - struct_addr, ordinal++); - inter_elt_len = struct_next - struct_addr; - in_structure = 0; - } else parent = parent->parent; /* rparen ends A() type, not S() type */ - break; - case '(': - if (!expect_lparen) goto fail; - expect_lparen = 0; - lparen_level++; - break; - default: - tpl_hook.oops("unsupported option %c\n", *c); - goto fail; - } - c++; - } - if (lparen_level != 0) goto fail; - - /* copy the format string, save for convenience */ - ((tpl_root_data*)(root->data))->fmt = tpl_hook.malloc(EM_SAFE_STRLEN(fmt)+1); - if (((tpl_root_data*)(root->data))->fmt == NULL) - fatal_oom(); - memcpy(((tpl_root_data*)(root->data))->fmt, fmt, EM_SAFE_STRLEN(fmt)+1); - - return root; + int lparen_level = 0, expect_lparen = 0, t = 0, in_structure = 0, ordinal = 0; + int in_nested_structure = 0; + char *c, *peek, *struct_addr = NULL, *struct_next; + tpl_node *root, *parent, *n = NULL, *preceding, *iter_start_node = NULL, + *struct_widest_node = NULL, *np; tpl_pidx *pidx; + tpl_pound_data *pd; + int *fxlens, num_fxlens, pound_num, pound_prod, applies_to_struct; + int contig_fxlens[10]; /* temp space for contiguous fxlens */ + int num_contig_fxlens, i, j; + ptrdiff_t inter_elt_len = 0; /* padded element length of contiguous structs in array */ + + + root = tpl_node_new(NULL); + root->type = TPL_TYPE_ROOT; + root->data = (tpl_root_data*)tpl_hook.malloc(sizeof(tpl_root_data)); + if (!root->data) fatal_oom(); + memset((tpl_root_data*)root->data, 0, sizeof(tpl_root_data)); + + /* set up root nodes special ser_osz to reflect overhead of preamble */ + root->ser_osz = sizeof(uint32_t); /* tpl leading length */ + root->ser_osz += EM_SAFE_STRLEN(fmt) + 1; /* fmt + NUL-terminator */ + root->ser_osz += 4; /* 'tpl' magic prefix + flags byte */ + + parent = root; + + c = fmt; + while (*c != '\0') { + switch (*c) { + case 'c': + case 'i': + case 'u': + case 'j': + case 'v': + case 'I': + case 'U': + case 'f': + if (*c == 'c') t = TPL_TYPE_BYTE; + else if (*c == 'i') t = TPL_TYPE_INT32; + else if (*c == 'u') t = TPL_TYPE_UINT32; + else if (*c == 'j') t = TPL_TYPE_INT16; + else if (*c == 'v') t = TPL_TYPE_UINT16; + else if (*c == 'I') t = TPL_TYPE_INT64; + else if (*c == 'U') t = TPL_TYPE_UINT64; + else if (*c == 'f') t = TPL_TYPE_DOUBLE; + + if (expect_lparen) goto fail; + n = tpl_node_new(parent); + n->type = t; + if (in_structure) { + if (ordinal == 1) { + /* for S(...)# iteration. Apply any changes to case 's' too!!! */ + iter_start_node = n; + struct_widest_node = n; + } + if (tpl_types[n->type].sz > tpl_types[struct_widest_node->type].sz) + struct_widest_node = n; + + n->addr = calc_field_addr(parent, n->type, struct_addr, ordinal++); + } else n->addr = (void*)va_arg(ap, void*); + n->data = tpl_hook.malloc(tpl_types[t].sz); + if (!n->data) fatal_oom(); + if (n->parent->type == TPL_TYPE_ARY) + ((tpl_atyp*)(n->parent->data))->sz += tpl_types[t].sz; + DL_ADD(parent->children, n); + break; + case 's': + if (expect_lparen) goto fail; + n = tpl_node_new(parent); + n->type = TPL_TYPE_STR; + if (in_structure) { + if (ordinal == 1) { + iter_start_node = n; /* for S(...)# iteration */ + struct_widest_node = n; + } + if (tpl_types[n->type].sz > tpl_types[struct_widest_node->type].sz) + struct_widest_node = n; + + n->addr = calc_field_addr(parent, n->type, struct_addr, ordinal++); + } else n->addr = (void*)va_arg(ap, void*); + n->data = tpl_hook.malloc(sizeof(char*)); + if (!n->data) fatal_oom(); + *(char**)(n->data) = NULL; + if (n->parent->type == TPL_TYPE_ARY) + ((tpl_atyp*)(n->parent->data))->sz += sizeof(void*); + DL_ADD(parent->children, n); + break; + case '#': + /* apply a 'num' to preceding atom */ + if (!parent->children) goto fail; + preceding = parent->children->prev; /* first child's prev is 'last child'*/ + t = preceding->type; + applies_to_struct = (*(c-1) == ')') ? 1 : 0; + if (!applies_to_struct) { + if (!(t == TPL_TYPE_BYTE || t == TPL_TYPE_INT32 || + t == TPL_TYPE_UINT32 || t == TPL_TYPE_DOUBLE || + t == TPL_TYPE_UINT64 || t == TPL_TYPE_INT64 || + t == TPL_TYPE_UINT16 || t == TPL_TYPE_INT16 || + t == TPL_TYPE_STR)) goto fail; + } + /* count up how many contiguous # and form their product */ + pound_prod = 1; + num_contig_fxlens = 0; + for (peek = c; *peek == '#'; peek++) { + pound_num = va_arg(ap, int); + if (pound_num < 1) + tpl_hook.fatal("non-positive iteration count %d\n", pound_num); + + if (num_contig_fxlens >= (sizeof(contig_fxlens)/sizeof(contig_fxlens[0]))) + tpl_hook.fatal("contiguous # exceeds hardcoded limit\n"); + + contig_fxlens[num_contig_fxlens++] = pound_num; + pound_prod *= pound_num; + } + /* increment c to skip contiguous # so its points to last one */ + c = peek-1; + /* differentiate atom-# from struct-# by noting preceding rparen */ + if (applies_to_struct) { /* insert # node to induce looping */ + n = tpl_node_new(parent); + n->type = TPL_TYPE_POUND; + n->num = pound_prod; + n->data = tpl_hook.malloc(sizeof(tpl_pound_data)); + if (!n->data) fatal_oom(); + pd = (tpl_pound_data*)n->data; + pd->inter_elt_len = inter_elt_len; + pd->iter_start_node = iter_start_node; + pd->iternum = 0; + DL_ADD(parent->children, n); + /* multiply the 'num' and data space on each atom in the structure */ + for (np = iter_start_node; np != n; np = np->next) { + if (n->parent->type == TPL_TYPE_ARY) { + ((tpl_atyp*)(n->parent->data))->sz += + tpl_types[np->type].sz * (np->num * (n->num - 1)); + } + np->data = tpl_hook.realloc(np->data, tpl_types[np->type].sz * + np->num * n->num); + if (!np->data) fatal_oom(); + memset(np->data, 0, tpl_types[np->type].sz * np->num * n->num); + } + } else { /* simple atom-# form does not require a loop */ + preceding->num = pound_prod; + preceding->data = tpl_hook.realloc(preceding->data, + tpl_types[t].sz * preceding->num); + if (!preceding->data) fatal_oom(); + memset(preceding->data, 0, tpl_types[t].sz * preceding->num); + if (n->parent->type == TPL_TYPE_ARY) { + ((tpl_atyp*)(n->parent->data))->sz += tpl_types[t].sz * + (preceding->num-1); + } + } + root->ser_osz += (sizeof(uint32_t) * num_contig_fxlens); + + j = ((tpl_root_data*)root->data)->num_fxlens; /* before incrementing */ + (((tpl_root_data*)root->data)->num_fxlens) += num_contig_fxlens; + num_fxlens = ((tpl_root_data*)root->data)->num_fxlens; /* new value */ + fxlens = ((tpl_root_data*)root->data)->fxlens; + fxlens = tpl_hook.realloc(fxlens, sizeof(int) * num_fxlens); + if (!fxlens) fatal_oom(); + ((tpl_root_data*)root->data)->fxlens = fxlens; + for (i = 0; i < num_contig_fxlens; i++) fxlens[j++] = contig_fxlens[i]; + + break; + case 'B': + if (expect_lparen) goto fail; + if (in_structure) goto fail; + n = tpl_node_new(parent); + n->type = TPL_TYPE_BIN; + n->addr = (tpl_bin*)va_arg(ap, void*); + n->data = tpl_hook.malloc(sizeof(tpl_bin*)); + if (!n->data) fatal_oom(); + *((tpl_bin**)n->data) = NULL; + if (n->parent->type == TPL_TYPE_ARY) + ((tpl_atyp*)(n->parent->data))->sz += sizeof(tpl_bin); + DL_ADD(parent->children, n); + break; + case 'A': + if (in_structure) goto fail; + n = tpl_node_new(parent); + n->type = TPL_TYPE_ARY; + DL_ADD(parent->children, n); + parent = n; + expect_lparen = 1; + pidx = (tpl_pidx*)tpl_hook.malloc(sizeof(tpl_pidx)); + if (!pidx) fatal_oom(); + pidx->node = n; + pidx->next = NULL; + DL_ADD(((tpl_root_data*)(root->data))->pidx, pidx); + /* set up the A's tpl_atyp */ + n->data = (tpl_atyp*)tpl_hook.malloc(sizeof(tpl_atyp)); + if (!n->data) fatal_oom(); + ((tpl_atyp*)(n->data))->num = 0; + ((tpl_atyp*)(n->data))->sz = 0; + ((tpl_atyp*)(n->data))->bb = NULL; + ((tpl_atyp*)(n->data))->bbtail = NULL; + ((tpl_atyp*)(n->data))->cur = NULL; + if (n->parent->type == TPL_TYPE_ARY) + ((tpl_atyp*)(n->parent->data))->sz += sizeof(void*); + break; + case 'S': + if (in_structure) goto fail; + expect_lparen = 1; + ordinal = 1; /* index upcoming atoms in S(..) */ + in_structure = 1+lparen_level; /* so we can tell where S fmt ends */ + struct_addr = (char*)va_arg(ap, void*); + break; + case '$': /* nested structure */ + if (!in_structure) goto fail; + expect_lparen = 1; + in_nested_structure++; + break; + case ')': + lparen_level--; + if (lparen_level < 0) goto fail; + if (*(c-1) == '(') goto fail; + if (in_nested_structure) in_nested_structure--; + else if (in_structure && (in_structure-1 == lparen_level)) { + /* calculate delta between contiguous structures in array */ + struct_next = calc_field_addr(parent, struct_widest_node->type, + struct_addr, ordinal++); + inter_elt_len = struct_next - struct_addr; + in_structure = 0; + } else parent = parent->parent; /* rparen ends A() type, not S() type */ + break; + case '(': + if (!expect_lparen) goto fail; + expect_lparen = 0; + lparen_level++; + break; + default: + tpl_hook.oops("unsupported option %c\n", *c); + goto fail; + } + c++; + } + if (lparen_level != 0) goto fail; + + /* copy the format string, save for convenience */ + ((tpl_root_data*)(root->data))->fmt = tpl_hook.malloc(EM_SAFE_STRLEN(fmt)+1); + if (((tpl_root_data*)(root->data))->fmt == NULL) + fatal_oom(); + memcpy(((tpl_root_data*)(root->data))->fmt, fmt, EM_SAFE_STRLEN(fmt)+1); + + return root; fail: - tpl_hook.oops("failed to parse %s\n", fmt); - tpl_free(root); - return NULL; + tpl_hook.oops("failed to parse %s\n", fmt); + tpl_free(root); + return NULL; } static int tpl_unmap_file(tpl_mmap_rec *mr) { - if (munmap(mr->text, mr->text_sz) == -1) { - tpl_hook.oops("Failed to munmap: %s\n", strerror(errno)); - } - close(mr->fd); - mr->text = NULL; - mr->text_sz = 0; - return 0; + if (munmap(mr->text, mr->text_sz) == -1) + tpl_hook.oops("Failed to munmap: %s\n", strerror(errno)); + + close(mr->fd); + mr->text = NULL; + mr->text_sz = 0; + return 0; } static void tpl_free_keep_map(tpl_node *r) { - int mmap_bits = (TPL_RDONLY|TPL_FILE); - int ufree_bits = (TPL_MEM|TPL_UFREE); - tpl_node *nxtc, *c; - int find_next_node = 0, looking, i; - size_t sz; - - /* For mmap'd files, or for 'ufree' memory images , do appropriate release */ - if ((((tpl_root_data*)(r->data))->flags & mmap_bits) == mmap_bits) { - tpl_unmap_file(&((tpl_root_data*)(r->data))->mmap); - } else if ((((tpl_root_data*)(r->data))->flags & ufree_bits) == ufree_bits) { - tpl_hook.free(((tpl_root_data*)(r->data))->mmap.text); - } - - c = r->children; - if (c) { - while (c->type != TPL_TYPE_ROOT) { /* loop until we come back to root node */ - switch (c->type) { - case TPL_TYPE_BIN: - /* free any binary buffer hanging from tpl_bin */ - if (*((tpl_bin**)(c->data))) { - if ((*((tpl_bin**)(c->data)))->addr) { - tpl_hook.free((*((tpl_bin**)(c->data)))->addr); - } - *((tpl_bin**)c->data) = NULL; /* reset tpl_bin */ - } - find_next_node = 1; - break; - case TPL_TYPE_STR: - /* free any packed (copied) string */ - for (i = 0; i < c->num; i++) { - char *str = ((char**)c->data)[i]; - if (str) { - tpl_hook.free(str); - ((char**)c->data)[i] = NULL; - } - } - find_next_node = 1; - break; - case TPL_TYPE_INT32: - case TPL_TYPE_UINT32: - case TPL_TYPE_INT64: - case TPL_TYPE_UINT64: - case TPL_TYPE_BYTE: - case TPL_TYPE_DOUBLE: - case TPL_TYPE_INT16: - case TPL_TYPE_UINT16: - case TPL_TYPE_POUND: - find_next_node = 1; - break; - case TPL_TYPE_ARY: - c->ser_osz = 0; /* zero out the serialization output size */ - - sz = ((tpl_atyp*)(c->data))->sz; /* save sz to use below */ - tpl_free_atyp(c, c->data); - - /* make new atyp */ - c->data = (tpl_atyp*)tpl_hook.malloc(sizeof(tpl_atyp)); - if (!c->data) fatal_oom(); - ((tpl_atyp*)(c->data))->num = 0; - ((tpl_atyp*)(c->data))->sz = sz; /* restore bb datum sz */ - ((tpl_atyp*)(c->data))->bb = NULL; - ((tpl_atyp*)(c->data))->bbtail = NULL; - ((tpl_atyp*)(c->data))->cur = NULL; - - c = c->children; - break; - default: - tpl_hook.fatal("unsupported format character\n"); - break; - } - - if (find_next_node) { - find_next_node = 0; - looking = 1; - while (looking) { - if (c->next) { - nxtc = c->next; - c = nxtc; - looking = 0; - } else { - if (c->type == TPL_TYPE_ROOT) break; /* root node */ - else { - nxtc = c->parent; - c = nxtc; - } - } - } - } - } - } - - ((tpl_root_data*)(r->data))->flags = 0; /* reset flags */ + int mmap_bits = (TPL_RDONLY|TPL_FILE); + int ufree_bits = (TPL_MEM|TPL_UFREE); + tpl_node *nxtc, *c; + int find_next_node = 0, looking, i; + size_t sz; + + /* For mmap'd files, or for 'ufree' memory images , do appropriate release */ + if ((((tpl_root_data*)(r->data))->flags & mmap_bits) == mmap_bits) + tpl_unmap_file(&((tpl_root_data*)(r->data))->mmap); + else if ((((tpl_root_data*)(r->data))->flags & ufree_bits) == ufree_bits) + tpl_hook.free(((tpl_root_data*)(r->data))->mmap.text); + + + c = r->children; + if (c) { + while (c->type != TPL_TYPE_ROOT) { /* loop until we come back to root node */ + switch (c->type) { + case TPL_TYPE_BIN: + /* free any binary buffer hanging from tpl_bin */ + if (*((tpl_bin**)(c->data))) { + if ((*((tpl_bin**)(c->data)))->addr) + tpl_hook.free((*((tpl_bin**)(c->data)))->addr); + + *((tpl_bin**)c->data) = NULL; /* reset tpl_bin */ + } + find_next_node = 1; + break; + case TPL_TYPE_STR: + /* free any packed (copied) string */ + for (i = 0; i < c->num; i++) { + char *str = ((char**)c->data)[i]; + if (str) { + tpl_hook.free(str); + ((char**)c->data)[i] = NULL; + } + } + find_next_node = 1; + break; + case TPL_TYPE_INT32: + case TPL_TYPE_UINT32: + case TPL_TYPE_INT64: + case TPL_TYPE_UINT64: + case TPL_TYPE_BYTE: + case TPL_TYPE_DOUBLE: + case TPL_TYPE_INT16: + case TPL_TYPE_UINT16: + case TPL_TYPE_POUND: + find_next_node = 1; + break; + case TPL_TYPE_ARY: + c->ser_osz = 0; /* zero out the serialization output size */ + + sz = ((tpl_atyp*)(c->data))->sz; /* save sz to use below */ + tpl_free_atyp(c, c->data); + + /* make new atyp */ + c->data = (tpl_atyp*)tpl_hook.malloc(sizeof(tpl_atyp)); + if (!c->data) fatal_oom(); + ((tpl_atyp*)(c->data))->num = 0; + ((tpl_atyp*)(c->data))->sz = sz; /* restore bb datum sz */ + ((tpl_atyp*)(c->data))->bb = NULL; + ((tpl_atyp*)(c->data))->bbtail = NULL; + ((tpl_atyp*)(c->data))->cur = NULL; + + c = c->children; + break; + default: + tpl_hook.fatal("unsupported format character\n"); + break; + } + + if (find_next_node) { + find_next_node = 0; + looking = 1; + while (looking) { + if (c->next) { + nxtc = c->next; + c = nxtc; + looking = 0; + } else { + if (c->type == TPL_TYPE_ROOT) break; /* root node */ + else { + nxtc = c->parent; + c = nxtc; + } + } + } + } + } + } + + ((tpl_root_data*)(r->data))->flags = 0; /* reset flags */ } TPL_API void tpl_free(tpl_node *r) { - int mmap_bits = (TPL_RDONLY|TPL_FILE); - int ufree_bits = (TPL_MEM|TPL_UFREE); - tpl_node *nxtc, *c; - int find_next_node = 0, looking, i; - tpl_pidx *pidx, *pidx_nxt; - - /* For mmap'd files, or for 'ufree' memory images , do appropriate release */ - if ((((tpl_root_data*)(r->data))->flags & mmap_bits) == mmap_bits) { - tpl_unmap_file(&((tpl_root_data*)(r->data))->mmap); - } else if ((((tpl_root_data*)(r->data))->flags & ufree_bits) == ufree_bits) { - tpl_hook.free(((tpl_root_data*)(r->data))->mmap.text); - } - - c = r->children; - if (c) { - while (c->type != TPL_TYPE_ROOT) { /* loop until we come back to root node */ - switch (c->type) { - case TPL_TYPE_BIN: - /* free any binary buffer hanging from tpl_bin */ - if (*((tpl_bin**)(c->data))) { - if ((*((tpl_bin**)(c->data)))->sz != 0) { - tpl_hook.free((*((tpl_bin**)(c->data)))->addr); - } - tpl_hook.free(*((tpl_bin**)c->data)); /* free tpl_bin */ - } - tpl_hook.free(c->data); /* free tpl_bin* */ - find_next_node = 1; - break; - case TPL_TYPE_STR: - /* free any packed (copied) string */ - for (i = 0; i < c->num; i++) { - char *str = ((char**)c->data)[i]; - if (str) { - tpl_hook.free(str); - ((char**)c->data)[i] = NULL; - } - } - tpl_hook.free(c->data); - find_next_node = 1; - break; - case TPL_TYPE_INT32: - case TPL_TYPE_UINT32: - case TPL_TYPE_INT64: - case TPL_TYPE_UINT64: - case TPL_TYPE_BYTE: - case TPL_TYPE_DOUBLE: - case TPL_TYPE_INT16: - case TPL_TYPE_UINT16: - case TPL_TYPE_POUND: - tpl_hook.free(c->data); - find_next_node = 1; - break; - case TPL_TYPE_ARY: - tpl_free_atyp(c, c->data); - if (c->children) c = c->children; /* normal case */ - else find_next_node = 1; /* edge case, handle bad format A() */ - break; - default: - tpl_hook.fatal("unsupported format character\n"); - break; - } - - if (find_next_node) { - find_next_node = 0; - looking = 1; - while (looking) { - if (c->next) { - nxtc = c->next; - tpl_hook.free(c); - c = nxtc; - looking = 0; - } else { - if (c->type == TPL_TYPE_ROOT) break; /* root node */ - else { - nxtc = c->parent; - tpl_hook.free(c); - c = nxtc; - } - } - } - } - } - } - - /* free root */ - for (pidx = ((tpl_root_data*)(r->data))->pidx; pidx; pidx = pidx_nxt) { - pidx_nxt = pidx->next; - tpl_hook.free(pidx); - } - tpl_hook.free(((tpl_root_data*)(r->data))->fmt); - if (((tpl_root_data*)(r->data))->num_fxlens > 0) { - tpl_hook.free(((tpl_root_data*)(r->data))->fxlens); - } - tpl_hook.free(r->data); /* tpl_root_data */ - tpl_hook.free(r); + int mmap_bits = (TPL_RDONLY|TPL_FILE); + int ufree_bits = (TPL_MEM|TPL_UFREE); + tpl_node *nxtc, *c; + int find_next_node = 0, looking, i; + tpl_pidx *pidx, *pidx_nxt; + + /* For mmap'd files, or for 'ufree' memory images , do appropriate release */ + if ((((tpl_root_data*)(r->data))->flags & mmap_bits) == mmap_bits) + tpl_unmap_file(&((tpl_root_data*)(r->data))->mmap); + else if ((((tpl_root_data*)(r->data))->flags & ufree_bits) == ufree_bits) + tpl_hook.free(((tpl_root_data*)(r->data))->mmap.text); + + c = r->children; + if (c) { + while (c->type != TPL_TYPE_ROOT) { /* loop until we come back to root node */ + switch (c->type) { + case TPL_TYPE_BIN: + /* free any binary buffer hanging from tpl_bin */ + if (*((tpl_bin**)(c->data))) { + if ((*((tpl_bin**)(c->data)))->sz != 0) + tpl_hook.free((*((tpl_bin**)(c->data)))->addr); + + tpl_hook.free(*((tpl_bin**)c->data)); /* free tpl_bin */ + } + tpl_hook.free(c->data); /* free tpl_bin* */ + find_next_node = 1; + break; + case TPL_TYPE_STR: + /* free any packed (copied) string */ + for (i = 0; i < c->num; i++) { + char *str = ((char**)c->data)[i]; + if (str) { + tpl_hook.free(str); + ((char**)c->data)[i] = NULL; + } + } + tpl_hook.free(c->data); + find_next_node = 1; + break; + case TPL_TYPE_INT32: + case TPL_TYPE_UINT32: + case TPL_TYPE_INT64: + case TPL_TYPE_UINT64: + case TPL_TYPE_BYTE: + case TPL_TYPE_DOUBLE: + case TPL_TYPE_INT16: + case TPL_TYPE_UINT16: + case TPL_TYPE_POUND: + tpl_hook.free(c->data); + find_next_node = 1; + break; + case TPL_TYPE_ARY: + tpl_free_atyp(c, c->data); + if (c->children) c = c->children; /* normal case */ + else find_next_node = 1; /* edge case, handle bad format A() */ + break; + default: + tpl_hook.fatal("unsupported format character\n"); + break; + } + + if (find_next_node) { + find_next_node = 0; + looking = 1; + while (looking) { + if (c->next) { + nxtc = c->next; + tpl_hook.free(c); + c = nxtc; + looking = 0; + } else { + if (c->type == TPL_TYPE_ROOT) break; /* root node */ + else { + nxtc = c->parent; + tpl_hook.free(c); + c = nxtc; + } + } + } + } + } + } + + /* free root */ + for (pidx = ((tpl_root_data*)(r->data))->pidx; pidx; pidx = pidx_nxt) { + pidx_nxt = pidx->next; + tpl_hook.free(pidx); + } + tpl_hook.free(((tpl_root_data*)(r->data))->fmt); + if (((tpl_root_data*)(r->data))->num_fxlens > 0) + tpl_hook.free(((tpl_root_data*)(r->data))->fxlens); + + tpl_hook.free(r->data); /* tpl_root_data */ + tpl_hook.free(r); } /* Find the i'th packable ('A' node) */ static tpl_node *tpl_find_i(tpl_node *n, int i) { - int j = 0; - tpl_pidx *pidx; - if (n->type != TPL_TYPE_ROOT) return NULL; - if (i == 0) return n; /* packable 0 is root */ - for (pidx = ((tpl_root_data*)(n->data))->pidx; pidx; pidx = pidx->next) { - if (++j == i) return pidx->node; - } - return NULL; + int j = 0; + tpl_pidx *pidx; + if (n->type != TPL_TYPE_ROOT) return NULL; + if (i == 0) return n; /* packable 0 is root */ + for (pidx = ((tpl_root_data*)(n->data))->pidx; pidx; pidx = pidx->next) { + if (++j == i) return pidx->node; + } + return NULL; } static void *tpl_cpv(void *datav, void *data, size_t sz) { - if (sz > 0) memcpy(datav, data, sz); - return (void*)((uintptr_t)datav + sz); + if (sz > 0) memcpy(datav, data, sz); + return (void*)((uintptr_t)datav + sz); } static void *tpl_extend_backbone(tpl_node *n) { - tpl_backbone *bb; - bb = (tpl_backbone*)tpl_hook.malloc(sizeof(tpl_backbone) + - ((tpl_atyp*)(n->data))->sz); /* datum hangs on coattails of bb */ - if (!bb) fatal_oom(); + tpl_backbone *bb; + bb = (tpl_backbone*)tpl_hook.malloc(sizeof(tpl_backbone) + + ((tpl_atyp*)(n->data))->sz); /* datum hangs on coattails of bb */ + if (!bb) fatal_oom(); #if __STDC_VERSION__ < 199901 - bb->data = (char*)((uintptr_t)bb + sizeof(tpl_backbone)); + bb->data = (char*)((uintptr_t)bb + sizeof(tpl_backbone)); #endif - memset(bb->data, 0, ((tpl_atyp*)(n->data))->sz); - bb->next = NULL; - /* Add the new backbone to the tail, also setting head if necessary */ - if (((tpl_atyp*)(n->data))->bb == NULL) { - ((tpl_atyp*)(n->data))->bb = bb; - ((tpl_atyp*)(n->data))->bbtail = bb; - } else { - ((tpl_atyp*)(n->data))->bbtail->next = bb; - ((tpl_atyp*)(n->data))->bbtail = bb; - } - - ((tpl_atyp*)(n->data))->num++; - return bb->data; + memset(bb->data, 0, ((tpl_atyp*)(n->data))->sz); + bb->next = NULL; + /* Add the new backbone to the tail, also setting head if necessary */ + if (((tpl_atyp*)(n->data))->bb == NULL) { + ((tpl_atyp*)(n->data))->bb = bb; + ((tpl_atyp*)(n->data))->bbtail = bb; + } else { + ((tpl_atyp*)(n->data))->bbtail->next = bb; + ((tpl_atyp*)(n->data))->bbtail = bb; + } + + ((tpl_atyp*)(n->data))->num++; + return bb->data; } /* Get the format string corresponding to a given tpl (root node) */ static char *tpl_fmt(tpl_node *r) { - return ((tpl_root_data*)(r->data))->fmt; + return ((tpl_root_data*)(r->data))->fmt; } /* Get the fmt # lengths as a contiguous buffer of ints (length num_fxlens) */ static int *tpl_fxlens(tpl_node *r, int *num_fxlens) { - *num_fxlens = ((tpl_root_data*)(r->data))->num_fxlens; - return ((tpl_root_data*)(r->data))->fxlens; + *num_fxlens = ((tpl_root_data*)(r->data))->num_fxlens; + return ((tpl_root_data*)(r->data))->fxlens; } /* called when serializing an 'A' type node into a buffer which has @@ -846,231 +845,230 @@ static int *tpl_fxlens(tpl_node *r, int *num_fxlens) */ static void *tpl_dump_atyp(tpl_node *n, tpl_atyp* at, void *dv) { - tpl_backbone *bb; - tpl_node *c; - void *datav; - uint32_t slen; - tpl_bin *binp; - char *strp; - tpl_atyp *atypp; - tpl_pound_data *pd; - int i; - size_t itermax; - - /* handle 'A' nodes */ - dv = tpl_cpv(dv, &at->num, sizeof(uint32_t)); /* array len */ - for (bb = at->bb; bb; bb = bb->next) { - datav = bb->data; - c = n->children; - while (c) { - switch (c->type) { - case TPL_TYPE_BYTE: - case TPL_TYPE_DOUBLE: - case TPL_TYPE_INT32: - case TPL_TYPE_UINT32: - case TPL_TYPE_INT64: - case TPL_TYPE_UINT64: - case TPL_TYPE_INT16: - case TPL_TYPE_UINT16: - dv = tpl_cpv(dv, datav, tpl_types[c->type].sz * c->num); - datav = (void*)((uintptr_t)datav + tpl_types[c->type].sz * c->num); - break; - case TPL_TYPE_BIN: - /* dump the buffer length followed by the buffer */ - memcpy(&binp, datav, sizeof(tpl_bin*)); /* cp to aligned */ - slen = binp->sz; - dv = tpl_cpv(dv, &slen, sizeof(uint32_t)); - dv = tpl_cpv(dv, binp->addr, slen); - datav = (void*)((uintptr_t)datav + sizeof(tpl_bin*)); - break; - case TPL_TYPE_STR: - /* dump the string length followed by the string */ - for (i = 0; i < c->num; i++) { - memcpy(&strp, datav, sizeof(char*)); /* cp to aligned */ - slen = strp ? (EM_SAFE_STRLEN(strp)+1) : 0; - dv = tpl_cpv(dv, &slen, sizeof(uint32_t)); - if (slen > 1) dv = tpl_cpv(dv, strp, slen-1); - datav = (void*)((uintptr_t)datav + sizeof(char*)); - } - break; - case TPL_TYPE_ARY: - memcpy(&atypp, datav, sizeof(tpl_atyp*)); /* cp to aligned */ - dv = tpl_dump_atyp(c, atypp, dv); - datav = (void*)((uintptr_t)datav + sizeof(void*)); - break; - case TPL_TYPE_POUND: - /* iterate over the preceding nodes */ - pd = (tpl_pound_data*)c->data; - itermax = c->num; - if (++(pd->iternum) < itermax) { - c = pd->iter_start_node; - continue; - } else { /* loop complete. */ - pd->iternum = 0; - } - break; - default: - tpl_hook.fatal("unsupported format character\n"); - break; - } - c = c->next; - } - } - return dv; + tpl_backbone *bb; + tpl_node *c; + void *datav; + uint32_t slen; + tpl_bin *binp; + char *strp; + tpl_atyp *atypp; + tpl_pound_data *pd; + int i; + size_t itermax; + + /* handle 'A' nodes */ + dv = tpl_cpv(dv, &at->num, sizeof(uint32_t)); /* array len */ + for (bb = at->bb; bb; bb = bb->next) { + datav = bb->data; + c = n->children; + while (c) { + switch (c->type) { + case TPL_TYPE_BYTE: + case TPL_TYPE_DOUBLE: + case TPL_TYPE_INT32: + case TPL_TYPE_UINT32: + case TPL_TYPE_INT64: + case TPL_TYPE_UINT64: + case TPL_TYPE_INT16: + case TPL_TYPE_UINT16: + dv = tpl_cpv(dv, datav, tpl_types[c->type].sz * c->num); + datav = (void*)((uintptr_t)datav + tpl_types[c->type].sz * c->num); + break; + case TPL_TYPE_BIN: + /* dump the buffer length followed by the buffer */ + memcpy(&binp, datav, sizeof(tpl_bin*)); /* cp to aligned */ + slen = binp->sz; + dv = tpl_cpv(dv, &slen, sizeof(uint32_t)); + dv = tpl_cpv(dv, binp->addr, slen); + datav = (void*)((uintptr_t)datav + sizeof(tpl_bin*)); + break; + case TPL_TYPE_STR: + /* dump the string length followed by the string */ + for (i = 0; i < c->num; i++) { + memcpy(&strp, datav, sizeof(char*)); /* cp to aligned */ + slen = strp ? (EM_SAFE_STRLEN(strp)+1) : 0; + dv = tpl_cpv(dv, &slen, sizeof(uint32_t)); + if (slen > 1) dv = tpl_cpv(dv, strp, slen-1); + datav = (void*)((uintptr_t)datav + sizeof(char*)); + } + break; + case TPL_TYPE_ARY: + memcpy(&atypp, datav, sizeof(tpl_atyp*)); /* cp to aligned */ + dv = tpl_dump_atyp(c, atypp, dv); + datav = (void*)((uintptr_t)datav + sizeof(void*)); + break; + case TPL_TYPE_POUND: + /* iterate over the preceding nodes */ + pd = (tpl_pound_data*)c->data; + itermax = c->num; + if (++(pd->iternum) < itermax) { + c = pd->iter_start_node; + continue; + } else { /* loop complete. */ + pd->iternum = 0; + } + break; + default: + tpl_hook.fatal("unsupported format character\n"); + break; + } + c = c->next; + } + } + return dv; } /* figure the serialization output size needed for tpl whose root is n*/ static size_t tpl_ser_osz(tpl_node *n) { - tpl_node *c, *np; - size_t sz, itermax; - tpl_bin *binp; - char *strp; - tpl_pound_data *pd; - int i; - - /* handle the root node ONLY (subtree's ser_osz have been bubbled-up) */ - if (n->type != TPL_TYPE_ROOT) { - tpl_hook.fatal("internal error: tpl_ser_osz on non-root node\n"); - } - - sz = n->ser_osz; /* start with fixed overhead, already stored */ - c = n->children; - while (c) { - switch (c->type) { - case TPL_TYPE_BYTE: - case TPL_TYPE_DOUBLE: - case TPL_TYPE_INT32: - case TPL_TYPE_UINT32: - case TPL_TYPE_INT64: - case TPL_TYPE_UINT64: - case TPL_TYPE_INT16: - case TPL_TYPE_UINT16: - sz += tpl_types[c->type].sz * c->num; - break; - case TPL_TYPE_BIN: - sz += sizeof(uint32_t); /* binary buf len */ - memcpy(&binp, c->data, sizeof(tpl_bin*)); /* cp to aligned */ - sz += binp->sz; - break; - case TPL_TYPE_STR: - for (i = 0; i < c->num; i++) { - sz += sizeof(uint32_t); /* string len */ - memcpy(&strp, &((char**)c->data)[i], sizeof(char*)); /* cp to aligned */ - sz += strp ? EM_SAFE_STRLEN(strp) : 0; - } - break; - case TPL_TYPE_ARY: - sz += sizeof(uint32_t); /* array len */ - sz += c->ser_osz; /* bubbled-up child array ser_osz */ - break; - case TPL_TYPE_POUND: - /* iterate over the preceding nodes */ - itermax = c->num; - pd = (tpl_pound_data*)c->data; - if (++(pd->iternum) < itermax) { - for (np = pd->iter_start_node; np != c; np = np->next) { - np->data = (char*)(np->data) + - (tpl_types[np->type].sz * np->num); - } - c = pd->iter_start_node; - continue; - } else { /* loop complete. */ - pd->iternum = 0; - for (np = pd->iter_start_node; np != c; np = np->next) { - np->data = (char*)(np->data) - ((itermax-1) * - tpl_types[np->type].sz * - np->num); - } - } - break; - default: - tpl_hook.fatal("unsupported format character\n"); - break; - } - c = c->next; - } - return sz; + tpl_node *c, *np; + size_t sz, itermax; + tpl_bin *binp; + char *strp; + tpl_pound_data *pd; + int i; + + /* handle the root node ONLY (subtree's ser_osz have been bubbled-up) */ + if (n->type != TPL_TYPE_ROOT) + tpl_hook.fatal("internal error: tpl_ser_osz on non-root node\n"); + + sz = n->ser_osz; /* start with fixed overhead, already stored */ + c = n->children; + while (c) { + switch (c->type) { + case TPL_TYPE_BYTE: + case TPL_TYPE_DOUBLE: + case TPL_TYPE_INT32: + case TPL_TYPE_UINT32: + case TPL_TYPE_INT64: + case TPL_TYPE_UINT64: + case TPL_TYPE_INT16: + case TPL_TYPE_UINT16: + sz += tpl_types[c->type].sz * c->num; + break; + case TPL_TYPE_BIN: + sz += sizeof(uint32_t); /* binary buf len */ + memcpy(&binp, c->data, sizeof(tpl_bin*)); /* cp to aligned */ + sz += binp->sz; + break; + case TPL_TYPE_STR: + for (i = 0; i < c->num; i++) { + sz += sizeof(uint32_t); /* string len */ + memcpy(&strp, &((char**)c->data)[i], sizeof(char*)); /* cp to aligned */ + sz += strp ? EM_SAFE_STRLEN(strp) : 0; + } + break; + case TPL_TYPE_ARY: + sz += sizeof(uint32_t); /* array len */ + sz += c->ser_osz; /* bubbled-up child array ser_osz */ + break; + case TPL_TYPE_POUND: + /* iterate over the preceding nodes */ + itermax = c->num; + pd = (tpl_pound_data*)c->data; + if (++(pd->iternum) < itermax) { + for (np = pd->iter_start_node; np != c; np = np->next) { + np->data = (char*)(np->data) + + (tpl_types[np->type].sz * np->num); + } + c = pd->iter_start_node; + continue; + } else { /* loop complete. */ + pd->iternum = 0; + for (np = pd->iter_start_node; np != c; np = np->next) { + np->data = (char*)(np->data) - ((itermax-1) * + tpl_types[np->type].sz * + np->num); + } + } + break; + default: + tpl_hook.fatal("unsupported format character\n"); + break; + } + c = c->next; + } + return sz; } TPL_API int tpl_dump(tpl_node *r, int mode, ...) { - va_list ap; - char *filename, *bufv; - void **addr_out, *buf, *pa_addr; - int fd, rc = 0; - size_t sz, *sz_out, pa_sz; - - if (((tpl_root_data*)(r->data))->flags & TPL_RDONLY) { /* unusual */ - tpl_hook.oops("error: tpl_dump called for a loaded tpl\n"); - return -1; - } - - sz = tpl_ser_osz(r); /* compute the size needed to serialize */ - - va_start(ap, mode); - if (mode & TPL_FILE) { - filename = va_arg(ap, char*); - fd = tpl_mmap_output_file(filename, sz, &buf); - if (fd == -1) rc = -1; - else { - rc = tpl_dump_to_mem(r, buf, sz); - if (msync(buf, sz, MS_SYNC) == -1) { - tpl_hook.oops("msync failed on fd %d: %s\n", fd, strerror(errno)); - } - if (munmap(buf, sz) == -1) { - tpl_hook.oops("munmap failed on fd %d: %s\n", fd, strerror(errno)); - } - close(fd); - } - } else if (mode & TPL_FD) { - fd = va_arg(ap, int); - if ((buf = tpl_hook.malloc(sz)) == NULL) fatal_oom(); - tpl_dump_to_mem(r, buf, sz); - bufv = buf; - do { - rc = write(fd, bufv, sz); - if (rc > 0) { - sz -= rc; - bufv += rc; - } else if (rc == -1) { - if (errno == EINTR || errno == EAGAIN) continue; - tpl_hook.oops("error writing to fd %d: %s\n", fd, strerror(errno)); - free(buf); - va_end(ap); - return -1; - } - } while (sz > 0); - free(buf); - rc = 0; - } else if (mode & TPL_MEM) { - if (mode & TPL_PREALLOCD) { /* caller allocated */ - pa_addr = (void*)va_arg(ap, void*); - pa_sz = va_arg(ap, size_t); - if (pa_sz < sz) { - tpl_hook.oops("tpl_dump: buffer too small, need %d bytes\n", sz); - va_end(ap); - return -1; - } - rc = tpl_dump_to_mem(r, pa_addr, sz); - } else { /* we allocate */ - addr_out = (void**)va_arg(ap, void*); - sz_out = va_arg(ap, size_t*); - if ((buf = tpl_hook.malloc(sz)) == NULL) fatal_oom(); - *sz_out = sz; - *addr_out = buf; - rc = tpl_dump_to_mem(r, buf, sz); - } - } else if (mode & TPL_GETSIZE) { - sz_out = va_arg(ap, size_t*); - *sz_out = sz; - } else { - tpl_hook.oops("unsupported tpl_dump mode %d\n", mode); - rc = -1; - } - va_end(ap); - return rc; + va_list ap; + char *filename, *bufv; + void **addr_out, *buf, *pa_addr; + int fd, rc = 0; + size_t sz, *sz_out, pa_sz; + + if (((tpl_root_data*)(r->data))->flags & TPL_RDONLY) { /* unusual */ + tpl_hook.oops("error: tpl_dump called for a loaded tpl\n"); + return -1; + } + + sz = tpl_ser_osz(r); /* compute the size needed to serialize */ + + va_start(ap, mode); + if (mode & TPL_FILE) { + filename = va_arg(ap, char*); + fd = tpl_mmap_output_file(filename, sz, &buf); + if (fd == -1) rc = -1; + else { + rc = tpl_dump_to_mem(r, buf, sz); + if (msync(buf, sz, MS_SYNC) == -1) + tpl_hook.oops("msync failed on fd %d: %s\n", fd, strerror(errno)); + + if (munmap(buf, sz) == -1) + tpl_hook.oops("munmap failed on fd %d: %s\n", fd, strerror(errno)); + + close(fd); + } + } else if (mode & TPL_FD) { + fd = va_arg(ap, int); + if ((buf = tpl_hook.malloc(sz)) == NULL) fatal_oom(); + tpl_dump_to_mem(r, buf, sz); + bufv = buf; + do { + rc = write(fd, bufv, sz); + if (rc > 0) { + sz -= rc; + bufv += rc; + } else if (rc == -1) { + if (errno == EINTR || errno == EAGAIN) continue; + tpl_hook.oops("error writing to fd %d: %s\n", fd, strerror(errno)); + free(buf); + va_end(ap); + return -1; + } + } while (sz > 0); + free(buf); + rc = 0; + } else if (mode & TPL_MEM) { + if (mode & TPL_PREALLOCD) { /* caller allocated */ + pa_addr = (void*)va_arg(ap, void*); + pa_sz = va_arg(ap, size_t); + if (pa_sz < sz) { + tpl_hook.oops("tpl_dump: buffer too small, need %d bytes\n", sz); + va_end(ap); + return -1; + } + rc = tpl_dump_to_mem(r, pa_addr, sz); + } else { /* we allocate */ + addr_out = (void**)va_arg(ap, void*); + sz_out = va_arg(ap, size_t*); + if ((buf = tpl_hook.malloc(sz)) == NULL) fatal_oom(); + *sz_out = sz; + *addr_out = buf; + rc = tpl_dump_to_mem(r, buf, sz); + } + } else if (mode & TPL_GETSIZE) { + sz_out = va_arg(ap, size_t*); + *sz_out = sz; + } else { + tpl_hook.oops("unsupported tpl_dump mode %d\n", mode); + rc = -1; + } + va_end(ap); + return rc; } /* This function expects the caller to have set up a memory buffer of @@ -1079,100 +1077,100 @@ TPL_API int tpl_dump(tpl_node *r, int mode, ...) */ static int tpl_dump_to_mem(tpl_node *r, void *addr, size_t sz) { - uint32_t slen, sz32; - int *fxlens, num_fxlens, i; - void *dv; - char *fmt, flags; - tpl_node *c, *np; - tpl_pound_data *pd; - size_t itermax; - - fmt = tpl_fmt(r); - flags = 0; - if (tpl_cpu_bigendian()) flags |= TPL_FL_BIGENDIAN; - if (strchr(fmt, 's')) flags |= TPL_FL_NULLSTRINGS; - sz32 = sz; - - dv = addr; - dv = tpl_cpv(dv, TPL_MAGIC, 3); /* copy tpl magic prefix */ - dv = tpl_cpv(dv, &flags, 1); /* copy flags byte */ - dv = tpl_cpv(dv, &sz32, sizeof(uint32_t));/* overall length (inclusive) */ - dv = tpl_cpv(dv, fmt, EM_SAFE_STRLEN(fmt)+1); /* copy format with NUL-term */ - fxlens = tpl_fxlens(r, &num_fxlens); - dv = tpl_cpv(dv, fxlens, num_fxlens*sizeof(uint32_t));/* fmt # lengths */ - - /* serialize the tpl content, iterating over direct children of root */ - c = r->children; - while (c) { - switch (c->type) { - case TPL_TYPE_BYTE: - case TPL_TYPE_DOUBLE: - case TPL_TYPE_INT32: - case TPL_TYPE_UINT32: - case TPL_TYPE_INT64: - case TPL_TYPE_UINT64: - case TPL_TYPE_INT16: - case TPL_TYPE_UINT16: - dv = tpl_cpv(dv, c->data, tpl_types[c->type].sz * c->num); - break; - case TPL_TYPE_BIN: - slen = (*(tpl_bin**)(c->data))->sz; - dv = tpl_cpv(dv, &slen, sizeof(uint32_t)); /* buffer len */ - dv = tpl_cpv(dv, (*(tpl_bin**)(c->data))->addr, slen); /* buf */ - break; - case TPL_TYPE_STR: - for (i = 0; i < c->num; i++) { - char *str = ((char**)c->data)[i]; - slen = str ? EM_SAFE_STRLEN(str)+1 : 0; - dv = tpl_cpv(dv, &slen, sizeof(uint32_t)); /* string len */ - if (slen > 1) dv = tpl_cpv(dv, str, slen-1); /*string*/ - } - break; - case TPL_TYPE_ARY: - dv = tpl_dump_atyp(c, (tpl_atyp*)c->data, dv); - break; - case TPL_TYPE_POUND: - pd = (tpl_pound_data*)c->data; - itermax = c->num; - if (++(pd->iternum) < itermax) { - - /* in start or midst of loop. advance data pointers. */ - for (np = pd->iter_start_node; np != c; np = np->next) { - np->data = (char*)(np->data) + - (tpl_types[np->type].sz * np->num); - } - /* do next iteration */ - c = pd->iter_start_node; - continue; - - } else { /* loop complete. */ - - /* reset iteration index and addr/data pointers. */ - pd->iternum = 0; - for (np = pd->iter_start_node; np != c; np = np->next) { - np->data = (char*)(np->data) - ((itermax-1) * - tpl_types[np->type].sz * - np->num); - } - - } - break; - default: - tpl_hook.fatal("unsupported format character\n"); - break; - } - c = c->next; - } - - return 0; + uint32_t slen, sz32; + int *fxlens, num_fxlens, i; + void *dv; + char *fmt, flags; + tpl_node *c, *np; + tpl_pound_data *pd; + size_t itermax; + + fmt = tpl_fmt(r); + flags = 0; + if (tpl_cpu_bigendian()) flags |= TPL_FL_BIGENDIAN; + if (strchr(fmt, 's')) flags |= TPL_FL_NULLSTRINGS; + sz32 = sz; + + dv = addr; + dv = tpl_cpv(dv, TPL_MAGIC, 3); /* copy tpl magic prefix */ + dv = tpl_cpv(dv, &flags, 1); /* copy flags byte */ + dv = tpl_cpv(dv, &sz32, sizeof(uint32_t));/* overall length (inclusive) */ + dv = tpl_cpv(dv, fmt, EM_SAFE_STRLEN(fmt)+1); /* copy format with NUL-term */ + fxlens = tpl_fxlens(r, &num_fxlens); + dv = tpl_cpv(dv, fxlens, num_fxlens*sizeof(uint32_t));/* fmt # lengths */ + + /* serialize the tpl content, iterating over direct children of root */ + c = r->children; + while (c) { + switch (c->type) { + case TPL_TYPE_BYTE: + case TPL_TYPE_DOUBLE: + case TPL_TYPE_INT32: + case TPL_TYPE_UINT32: + case TPL_TYPE_INT64: + case TPL_TYPE_UINT64: + case TPL_TYPE_INT16: + case TPL_TYPE_UINT16: + dv = tpl_cpv(dv, c->data, tpl_types[c->type].sz * c->num); + break; + case TPL_TYPE_BIN: + slen = (*(tpl_bin**)(c->data))->sz; + dv = tpl_cpv(dv, &slen, sizeof(uint32_t)); /* buffer len */ + dv = tpl_cpv(dv, (*(tpl_bin**)(c->data))->addr, slen); /* buf */ + break; + case TPL_TYPE_STR: + for (i = 0; i < c->num; i++) { + char *str = ((char**)c->data)[i]; + slen = str ? EM_SAFE_STRLEN(str)+1 : 0; + dv = tpl_cpv(dv, &slen, sizeof(uint32_t)); /* string len */ + if (slen > 1) dv = tpl_cpv(dv, str, slen-1); /*string*/ + } + break; + case TPL_TYPE_ARY: + dv = tpl_dump_atyp(c, (tpl_atyp*)c->data, dv); + break; + case TPL_TYPE_POUND: + pd = (tpl_pound_data*)c->data; + itermax = c->num; + if (++(pd->iternum) < itermax) { + + /* in start or midst of loop. advance data pointers. */ + for (np = pd->iter_start_node; np != c; np = np->next) { + np->data = (char*)(np->data) + + (tpl_types[np->type].sz * np->num); + } + /* do next iteration */ + c = pd->iter_start_node; + continue; + + } else { /* loop complete. */ + + /* reset iteration index and addr/data pointers. */ + pd->iternum = 0; + for (np = pd->iter_start_node; np != c; np = np->next) { + np->data = (char*)(np->data) - ((itermax-1) * + tpl_types[np->type].sz * + np->num); + } + + } + break; + default: + tpl_hook.fatal("unsupported format character\n"); + break; + } + c = c->next; + } + + return 0; } static int tpl_cpu_bigendian() { - unsigned i = 1; - char *c; - c = (char*)&i; - return (c[0] == 1 ? 0 : 1); + unsigned i = 1; + char *c; + c = (char*)&i; + return (c[0] == 1 ? 0 : 1); } @@ -1186,259 +1184,258 @@ static int tpl_cpu_bigendian() */ static int tpl_sanity(tpl_node *r, int excess_ok) { - uint32_t intlsz; - int found_nul = 0, rc, octothorpes = 0, num_fxlens, *fxlens, flen; - void *d, *dv; - char intlflags, *fmt, c, *mapfmt; - size_t bufsz, serlen; - - d = ((tpl_root_data*)(r->data))->mmap.text; - bufsz = ((tpl_root_data*)(r->data))->mmap.text_sz; - - dv = d; - if (bufsz < (4 + sizeof(uint32_t) + 1)) return ERR_NOT_MINSIZE; /* min sz : magic+flags+len+nul */ - if (memcmp(dv, TPL_MAGIC, 3) != 0) return ERR_MAGIC_MISMATCH; /* missing tpl magic prefix */ - if (tpl_needs_endian_swap(dv)) ((tpl_root_data*)(r->data))->flags |= TPL_XENDIAN; - dv = (void*)((uintptr_t)dv + 3); - memcpy(&intlflags, dv, sizeof(char)); /* extract flags */ - if (intlflags & ~TPL_SUPPORTED_BITFLAGS) return ERR_UNSUPPORTED_FLAGS; - /* TPL1.3 stores strings with a "length+1" prefix to discern NULL strings from - empty strings from non-empty strings; TPL1.2 only handled the latter two. - So we need to be mindful of which string format we're reading from. */ - if (!(intlflags & TPL_FL_NULLSTRINGS)) { - ((tpl_root_data*)(r->data))->flags |= TPL_OLD_STRING_FMT; - } - dv = (void*)((uintptr_t)dv + 1); - memcpy(&intlsz, dv, sizeof(uint32_t)); /* extract internal size */ - if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN) tpl_byteswap(&intlsz, sizeof(uint32_t)); - if (!excess_ok && (intlsz != bufsz)) return ERR_INCONSISTENT_SZ; /* inconsisent buffer/internal size */ - dv = (void*)((uintptr_t)dv + sizeof(uint32_t)); - - /* dv points to the start of the format string. Look for nul w/in buf sz */ - fmt = (char*)dv; - while ((uintptr_t)dv-(uintptr_t)d < bufsz && !found_nul) { - if ((c = *(char*)dv) != '\0') { - if (strchr(tpl_fmt_chars, c) == NULL) - return ERR_FMT_INVALID; /* invalid char in format string */ - if ((c = *(char*)dv) == '#') octothorpes++; - dv = (void*)((uintptr_t)dv + 1); - } else found_nul = 1; - } - if (!found_nul) return ERR_FMT_MISSING_NUL; /* runaway format string */ - dv = (void*)((uintptr_t)dv + 1); /* advance to octothorpe lengths buffer */ - - /* compare the map format to the format of this tpl image */ - mapfmt = tpl_fmt(r); - rc = strcmp(mapfmt, fmt); - if (rc != 0) return ERR_FMT_MISMATCH; - - /* compare octothorpe lengths in image to the mapped values */ - if ((((uintptr_t)dv + (octothorpes * 4)) - (uintptr_t)d) > bufsz) return ERR_INCONSISTENT_SZ4; - fxlens = tpl_fxlens(r, &num_fxlens); /* mapped fxlens */ - while (num_fxlens--) { - memcpy(&flen, dv, sizeof(uint32_t)); /* stored flen */ - if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN) tpl_byteswap(&flen, sizeof(uint32_t)); - if (flen != *fxlens) return ERR_FLEN_MISMATCH; - dv = (void*)((uintptr_t)dv + sizeof(uint32_t)); - fxlens++; - } - - /* dv now points to beginning of data */ - rc = tpl_serlen(r, r, dv, &serlen); /* get computed serlen of data part */ - if (rc == -1) return ERR_INCONSISTENT_SZ2; /* internal inconsistency in tpl image */ - serlen += ((uintptr_t)dv - (uintptr_t)d); /* add back serlen of preamble part */ - if (excess_ok && (bufsz < serlen)) return ERR_INCONSISTENT_SZ3; - if (!excess_ok && (serlen != bufsz)) return ERR_INCONSISTENT_SZ3; /* buffer/internal sz exceeds serlen */ - return 0; + uint32_t intlsz; + int found_nul = 0, rc, octothorpes = 0, num_fxlens, *fxlens, flen; + void *d, *dv; + char intlflags, *fmt, c, *mapfmt; + size_t bufsz, serlen; + + d = ((tpl_root_data*)(r->data))->mmap.text; + bufsz = ((tpl_root_data*)(r->data))->mmap.text_sz; + + dv = d; + if (bufsz < (4 + sizeof(uint32_t) + 1)) return ERR_NOT_MINSIZE; /* min sz : magic+flags+len+nul */ + if (memcmp(dv, TPL_MAGIC, 3) != 0) return ERR_MAGIC_MISMATCH; /* missing tpl magic prefix */ + if (tpl_needs_endian_swap(dv)) ((tpl_root_data*)(r->data))->flags |= TPL_XENDIAN; + dv = (void*)((uintptr_t)dv + 3); + memcpy(&intlflags, dv, sizeof(char)); /* extract flags */ + if (intlflags & ~TPL_SUPPORTED_BITFLAGS) return ERR_UNSUPPORTED_FLAGS; + /* TPL1.3 stores strings with a "length+1" prefix to discern NULL strings from + empty strings from non-empty strings; TPL1.2 only handled the latter two. + So we need to be mindful of which string format we're reading from. */ + if (!(intlflags & TPL_FL_NULLSTRINGS)) + ((tpl_root_data*)(r->data))->flags |= TPL_OLD_STRING_FMT; + + dv = (void*)((uintptr_t)dv + 1); + memcpy(&intlsz, dv, sizeof(uint32_t)); /* extract internal size */ + if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN) tpl_byteswap(&intlsz, sizeof(uint32_t)); + if (!excess_ok && (intlsz != bufsz)) return ERR_INCONSISTENT_SZ; /* inconsisent buffer/internal size */ + dv = (void*)((uintptr_t)dv + sizeof(uint32_t)); + + /* dv points to the start of the format string. Look for nul w/in buf sz */ + fmt = (char*)dv; + while ((uintptr_t)dv-(uintptr_t)d < bufsz && !found_nul) { + if ((c = *(char*)dv) != '\0') { + if (strchr(tpl_fmt_chars, c) == NULL) + return ERR_FMT_INVALID; /* invalid char in format string */ + if ((c = *(char*)dv) == '#') octothorpes++; + dv = (void*)((uintptr_t)dv + 1); + } else found_nul = 1; + } + if (!found_nul) return ERR_FMT_MISSING_NUL; /* runaway format string */ + dv = (void*)((uintptr_t)dv + 1); /* advance to octothorpe lengths buffer */ + + /* compare the map format to the format of this tpl image */ + mapfmt = tpl_fmt(r); + rc = strcmp(mapfmt, fmt); + if (rc != 0) return ERR_FMT_MISMATCH; + + /* compare octothorpe lengths in image to the mapped values */ + if ((((uintptr_t)dv + (octothorpes * 4)) - (uintptr_t)d) > bufsz) return ERR_INCONSISTENT_SZ4; + fxlens = tpl_fxlens(r, &num_fxlens); /* mapped fxlens */ + while (num_fxlens--) { + memcpy(&flen, dv, sizeof(uint32_t)); /* stored flen */ + if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN) tpl_byteswap(&flen, sizeof(uint32_t)); + if (flen != *fxlens) return ERR_FLEN_MISMATCH; + dv = (void*)((uintptr_t)dv + sizeof(uint32_t)); + fxlens++; + } + + /* dv now points to beginning of data */ + rc = tpl_serlen(r, r, dv, &serlen); /* get computed serlen of data part */ + if (rc == -1) return ERR_INCONSISTENT_SZ2; /* internal inconsistency in tpl image */ + serlen += ((uintptr_t)dv - (uintptr_t)d); /* add back serlen of preamble part */ + if (excess_ok && (bufsz < serlen)) return ERR_INCONSISTENT_SZ3; + if (!excess_ok && (serlen != bufsz)) return ERR_INCONSISTENT_SZ3; /* buffer/internal sz exceeds serlen */ + return 0; } static void *tpl_find_data_start(void *d) { - int octothorpes = 0; - d = (void*)((uintptr_t)d + 4); /* skip TPL_MAGIC and flags byte */ - d = (void*)((uintptr_t)d + 4); /* skip int32 overall len */ - while (*(char*)d != '\0') { - if (*(char*)d == '#') octothorpes++; - d = (void*)((uintptr_t)d + 1); - } - d = (void*)((uintptr_t)d + 1); /* skip NUL */ - d = (void*)((uintptr_t)d + (octothorpes * sizeof(uint32_t))); /* skip # array lens */ - return d; + int octothorpes = 0; + d = (void*)((uintptr_t)d + 4); /* skip TPL_MAGIC and flags byte */ + d = (void*)((uintptr_t)d + 4); /* skip int32 overall len */ + while (*(char*)d != '\0') { + if (*(char*)d == '#') octothorpes++; + d = (void*)((uintptr_t)d + 1); + } + d = (void*)((uintptr_t)d + 1); /* skip NUL */ + d = (void*)((uintptr_t)d + (octothorpes * sizeof(uint32_t))); /* skip # array lens */ + return d; } static int tpl_needs_endian_swap(void *d) { - char *c; - int cpu_is_bigendian; - c = (char*)d; - cpu_is_bigendian = tpl_cpu_bigendian(); - return ((c[3] & TPL_FL_BIGENDIAN) == cpu_is_bigendian) ? 0 : 1; + char *c; + int cpu_is_bigendian; + c = (char*)d; + cpu_is_bigendian = tpl_cpu_bigendian(); + return ((c[3] & TPL_FL_BIGENDIAN) == cpu_is_bigendian) ? 0 : 1; } static size_t tpl_size_for(char c) { - int i; - for (i = 0; i < sizeof(tpl_types)/sizeof(tpl_types[0]); i++) { - if (tpl_types[i].c == c) return tpl_types[i].sz; - } - return 0; + int i; + for (i = 0; i < sizeof(tpl_types)/sizeof(tpl_types[0]); i++) { + if (tpl_types[i].c == c) return tpl_types[i].sz; + } + return 0; } TPL_API char* tpl_peek(int mode, ...) { - va_list ap; - int xendian = 0, found_nul = 0, old_string_format = 0; - char *filename = NULL, *datapeek_f = NULL, *datapeek_c, *datapeek_s; - void *addr = NULL, *dv, *datapeek_p = NULL; - size_t sz = 0, fmt_len, first_atom, num_fxlens = 0; - uint32_t datapeek_ssz, datapeek_csz, datapeek_flen; - tpl_mmap_rec mr = {0, NULL, 0}; - char *fmt, *fmt_cpy = NULL, c; - uint32_t intlsz, **fxlens = NULL, *num_fxlens_out = NULL, *fxlensv; - - va_start(ap, mode); - if ((mode & TPL_FXLENS) && (mode & TPL_DATAPEEK)) { - tpl_hook.oops("TPL_FXLENS and TPL_DATAPEEK mutually exclusive\n"); - goto fail; - } - if (mode & TPL_FILE) filename = va_arg(ap, char *); - else if (mode & TPL_MEM) { - addr = va_arg(ap, void *); - sz = va_arg(ap, size_t); - } else { - tpl_hook.oops("unsupported tpl_peek mode %d\n", mode); - goto fail; - } - if (mode & TPL_DATAPEEK) { - datapeek_f = va_arg(ap, char*); - } - if (mode & TPL_FXLENS) { - num_fxlens_out = va_arg(ap, uint32_t *); - fxlens = va_arg(ap, uint32_t **); - *num_fxlens_out = 0; - *fxlens = NULL; - } - - if (mode & TPL_FILE) { - if (tpl_mmap_file(filename, &mr) != 0) { - tpl_hook.oops("tpl_peek failed for file %s\n", filename); - goto fail; - } - addr = mr.text; - sz = mr.text_sz; - } - - dv = addr; - if (sz < (4 + sizeof(uint32_t) + 1)) goto fail; /* min sz */ - if (memcmp(dv, TPL_MAGIC, 3) != 0) goto fail; /* missing tpl magic prefix */ - if (tpl_needs_endian_swap(dv)) xendian = 1; - if ((((char*)dv)[3] & TPL_FL_NULLSTRINGS) == 0) old_string_format = 1; - dv = (void*)((uintptr_t)dv + 4); - memcpy(&intlsz, dv, sizeof(uint32_t)); /* extract internal size */ - if (xendian) tpl_byteswap(&intlsz, sizeof(uint32_t)); - if (intlsz != sz) goto fail; /* inconsisent buffer/internal size */ - dv = (void*)((uintptr_t)dv + sizeof(uint32_t)); - - /* dv points to the start of the format string. Look for nul w/in buf sz */ - fmt = (char*)dv; - while ((uintptr_t)dv-(uintptr_t)addr < sz && !found_nul) { - if ((c = *(char*)dv) == '\0') { - found_nul = 1; - } else if (c == '#') { - num_fxlens++; - } - dv = (void*)((uintptr_t)dv + 1); - } - if (!found_nul) goto fail; /* runaway format string */ - fmt_len = (char*)dv - fmt; /* include space for \0 */ - fmt_cpy = tpl_hook.malloc(fmt_len); - if (fmt_cpy == NULL) { - fatal_oom(); - } - memcpy(fmt_cpy, fmt, fmt_len); - - /* retrieve the octothorpic lengths if requested */ - if (num_fxlens > 0) { - if (sz < ((uintptr_t)dv + (num_fxlens * sizeof(uint32_t)) - (uintptr_t)addr)) { - goto fail; - } - } - if ((mode & TPL_FXLENS) && (num_fxlens > 0)) { - *fxlens = tpl_hook.malloc(num_fxlens * sizeof(uint32_t)); - if (*fxlens == NULL) tpl_hook.fatal("out of memory"); - *num_fxlens_out = num_fxlens; - fxlensv = *fxlens; - while (num_fxlens--) { - memcpy(fxlensv, dv, sizeof(uint32_t)); - if (xendian) tpl_byteswap(fxlensv, sizeof(uint32_t)); - dv = (void*)((uintptr_t)dv + sizeof(uint32_t)); - fxlensv++; - } - } - /* if caller requested, peek into the specified data elements */ - if (mode & TPL_DATAPEEK) { - - first_atom = strspn(fmt, "S()"); /* skip any leading S() */ - - datapeek_flen = EM_SAFE_STRLEN(datapeek_f); - if (strspn(datapeek_f, tpl_datapeek_ok_chars) < datapeek_flen) { - tpl_hook.oops("invalid TPL_DATAPEEK format: %s\n", datapeek_f); - tpl_hook.free(fmt_cpy); fmt_cpy = NULL; /* fail */ - goto fail; - } - - if (strncmp(&fmt[first_atom], datapeek_f, datapeek_flen) != 0) { - tpl_hook.oops("TPL_DATAPEEK format mismatches tpl iamge\n"); - tpl_hook.free(fmt_cpy); fmt_cpy = NULL; /* fail */ - goto fail; - } - - /* advance to data start, then copy out requested elements */ - dv = (void*)((uintptr_t)dv + (num_fxlens * sizeof(uint32_t))); - for (datapeek_c = datapeek_f; *datapeek_c != '\0'; datapeek_c++) { - datapeek_p = va_arg(ap, void*); - if (*datapeek_c == 's') { /* special handling for strings */ - if ((uintptr_t)dv-(uintptr_t)addr + sizeof(uint32_t) > sz) { - tpl_hook.oops("tpl_peek: tpl has insufficient length\n"); - tpl_hook.free(fmt_cpy); fmt_cpy = NULL; /* fail */ - goto fail; - } - memcpy(&datapeek_ssz, dv, sizeof(uint32_t)); /* get slen */ - if (xendian) tpl_byteswap(&datapeek_ssz, sizeof(uint32_t)); - if (old_string_format) datapeek_ssz++; - dv = (void*)((uintptr_t)dv + sizeof(uint32_t)); /* adv. to str */ - if (datapeek_ssz == 0) datapeek_s = NULL; - else { - if ((uintptr_t)dv-(uintptr_t)addr + datapeek_ssz-1 > sz) { - tpl_hook.oops("tpl_peek: tpl has insufficient length\n"); - tpl_hook.free(fmt_cpy); fmt_cpy = NULL; /* fail */ - goto fail; - } - datapeek_s = tpl_hook.malloc(datapeek_ssz); - if (datapeek_s == NULL) fatal_oom(); - memcpy(datapeek_s, dv, datapeek_ssz-1); - datapeek_s[datapeek_ssz-1] = '\0'; - dv = (void*)((uintptr_t)dv + datapeek_ssz-1); - } - *(char**)datapeek_p = datapeek_s; - } else { - datapeek_csz = tpl_size_for(*datapeek_c); - if ((uintptr_t)dv-(uintptr_t)addr + datapeek_csz > sz) { - tpl_hook.oops("tpl_peek: tpl has insufficient length\n"); - tpl_hook.free(fmt_cpy); fmt_cpy = NULL; /* fail */ - goto fail; - } - memcpy(datapeek_p, dv, datapeek_csz); - if (xendian) tpl_byteswap(datapeek_p, datapeek_csz); - dv = (void*)((uintptr_t)dv + datapeek_csz); - } - } - } + va_list ap; + int xendian = 0, found_nul = 0, old_string_format = 0; + char *filename = NULL, *datapeek_f = NULL, *datapeek_c, *datapeek_s; + void *addr = NULL, *dv, *datapeek_p = NULL; + size_t sz = 0, fmt_len, first_atom, num_fxlens = 0; + uint32_t datapeek_ssz, datapeek_csz, datapeek_flen; + tpl_mmap_rec mr = {0, NULL, 0}; + char *fmt, *fmt_cpy = NULL, c; + uint32_t intlsz, **fxlens = NULL, *num_fxlens_out = NULL, *fxlensv; + + va_start(ap, mode); + if ((mode & TPL_FXLENS) && (mode & TPL_DATAPEEK)) { + tpl_hook.oops("TPL_FXLENS and TPL_DATAPEEK mutually exclusive\n"); + goto fail; + } + if (mode & TPL_FILE) filename = va_arg(ap, char *); + else if (mode & TPL_MEM) { + addr = va_arg(ap, void *); + sz = va_arg(ap, size_t); + } else { + tpl_hook.oops("unsupported tpl_peek mode %d\n", mode); + goto fail; + } + if (mode & TPL_DATAPEEK) + datapeek_f = va_arg(ap, char*); + + if (mode & TPL_FXLENS) { + num_fxlens_out = va_arg(ap, uint32_t *); + fxlens = va_arg(ap, uint32_t **); + *num_fxlens_out = 0; + *fxlens = NULL; + } + + if (mode & TPL_FILE) { + if (tpl_mmap_file(filename, &mr) != 0) { + tpl_hook.oops("tpl_peek failed for file %s\n", filename); + goto fail; + } + addr = mr.text; + sz = mr.text_sz; + } + + dv = addr; + if (sz < (4 + sizeof(uint32_t) + 1)) goto fail; /* min sz */ + if (memcmp(dv, TPL_MAGIC, 3) != 0) goto fail; /* missing tpl magic prefix */ + if (tpl_needs_endian_swap(dv)) xendian = 1; + if ((((char*)dv)[3] & TPL_FL_NULLSTRINGS) == 0) old_string_format = 1; + dv = (void*)((uintptr_t)dv + 4); + memcpy(&intlsz, dv, sizeof(uint32_t)); /* extract internal size */ + if (xendian) tpl_byteswap(&intlsz, sizeof(uint32_t)); + if (intlsz != sz) goto fail; /* inconsisent buffer/internal size */ + dv = (void*)((uintptr_t)dv + sizeof(uint32_t)); + + /* dv points to the start of the format string. Look for nul w/in buf sz */ + fmt = (char*)dv; + while ((uintptr_t)dv-(uintptr_t)addr < sz && !found_nul) { + if ((c = *(char*)dv) == '\0') + found_nul = 1; + else if (c == '#') + num_fxlens++; + + dv = (void*)((uintptr_t)dv + 1); + } + if (!found_nul) goto fail; /* runaway format string */ + fmt_len = (char*)dv - fmt; /* include space for \0 */ + fmt_cpy = tpl_hook.malloc(fmt_len); + if (fmt_cpy == NULL) + fatal_oom(); + + memcpy(fmt_cpy, fmt, fmt_len); + + /* retrieve the octothorpic lengths if requested */ + if (num_fxlens > 0) { + if (sz < ((uintptr_t)dv + (num_fxlens * sizeof(uint32_t)) - (uintptr_t)addr)) + goto fail; + } + if ((mode & TPL_FXLENS) && (num_fxlens > 0)) { + *fxlens = tpl_hook.malloc(num_fxlens * sizeof(uint32_t)); + if (*fxlens == NULL) tpl_hook.fatal("out of memory"); + *num_fxlens_out = num_fxlens; + fxlensv = *fxlens; + while (num_fxlens--) { + memcpy(fxlensv, dv, sizeof(uint32_t)); + if (xendian) tpl_byteswap(fxlensv, sizeof(uint32_t)); + dv = (void*)((uintptr_t)dv + sizeof(uint32_t)); + fxlensv++; + } + } + /* if caller requested, peek into the specified data elements */ + if (mode & TPL_DATAPEEK) { + + first_atom = strspn(fmt, "S()"); /* skip any leading S() */ + + datapeek_flen = EM_SAFE_STRLEN(datapeek_f); + if (strspn(datapeek_f, tpl_datapeek_ok_chars) < datapeek_flen) { + tpl_hook.oops("invalid TPL_DATAPEEK format: %s\n", datapeek_f); + tpl_hook.free(fmt_cpy); fmt_cpy = NULL; /* fail */ + goto fail; + } + + if (strncmp(&fmt[first_atom], datapeek_f, datapeek_flen) != 0) { + tpl_hook.oops("TPL_DATAPEEK format mismatches tpl iamge\n"); + tpl_hook.free(fmt_cpy); fmt_cpy = NULL; /* fail */ + goto fail; + } + + /* advance to data start, then copy out requested elements */ + dv = (void*)((uintptr_t)dv + (num_fxlens * sizeof(uint32_t))); + for (datapeek_c = datapeek_f; *datapeek_c != '\0'; datapeek_c++) { + datapeek_p = va_arg(ap, void*); + if (*datapeek_c == 's') { /* special handling for strings */ + if ((uintptr_t)dv-(uintptr_t)addr + sizeof(uint32_t) > sz) { + tpl_hook.oops("tpl_peek: tpl has insufficient length\n"); + tpl_hook.free(fmt_cpy); fmt_cpy = NULL; /* fail */ + goto fail; + } + memcpy(&datapeek_ssz, dv, sizeof(uint32_t)); /* get slen */ + if (xendian) tpl_byteswap(&datapeek_ssz, sizeof(uint32_t)); + if (old_string_format) datapeek_ssz++; + dv = (void*)((uintptr_t)dv + sizeof(uint32_t)); /* adv. to str */ + if (datapeek_ssz == 0) datapeek_s = NULL; + else { + if ((uintptr_t)dv-(uintptr_t)addr + datapeek_ssz-1 > sz) { + tpl_hook.oops("tpl_peek: tpl has insufficient length\n"); + tpl_hook.free(fmt_cpy); fmt_cpy = NULL; /* fail */ + goto fail; + } + datapeek_s = tpl_hook.malloc(datapeek_ssz); + if (datapeek_s == NULL) fatal_oom(); + memcpy(datapeek_s, dv, datapeek_ssz-1); + datapeek_s[datapeek_ssz-1] = '\0'; + dv = (void*)((uintptr_t)dv + datapeek_ssz-1); + } + *(char**)datapeek_p = datapeek_s; + } else { + datapeek_csz = tpl_size_for(*datapeek_c); + if ((uintptr_t)dv-(uintptr_t)addr + datapeek_csz > sz) { + tpl_hook.oops("tpl_peek: tpl has insufficient length\n"); + tpl_hook.free(fmt_cpy); fmt_cpy = NULL; /* fail */ + goto fail; + } + memcpy(datapeek_p, dv, datapeek_csz); + if (xendian) tpl_byteswap(datapeek_p, datapeek_csz); + dv = (void*)((uintptr_t)dv + datapeek_csz); + } + } + } fail: - va_end(ap); - if ((mode & TPL_FILE) && mr.text != NULL) tpl_unmap_file(&mr); - return fmt_cpy; + va_end(ap); + if ((mode & TPL_FILE) && mr.text != NULL) tpl_unmap_file(&mr); + return fmt_cpy; } /* tpl_jot(TPL_FILE, "file.tpl", "si", &s, &i); */ @@ -1446,205 +1443,206 @@ fail: /* tpl_jot(TPL_FD, fd, "si", &s, &i); */ TPL_API int tpl_jot(int mode, ...) { - va_list ap; - char *filename, *fmt; - size_t *sz; - int fd, rc = 0; - void **buf; - tpl_node *tn; - - va_start(ap, mode); - if (mode & TPL_FILE) { - filename = va_arg(ap, char*); - fmt = va_arg(ap, char*); - tn = tpl_map_va(fmt, ap); - if (tn == NULL) {rc = -1; goto fail; } - tpl_pack(tn, 0); - rc = tpl_dump(tn, TPL_FILE, filename); - tpl_free(tn); - } else if (mode & TPL_MEM) { - buf = va_arg(ap, void*); - sz = va_arg(ap, size_t*); - fmt = va_arg(ap, char*); - tn = tpl_map_va(fmt, ap); - if (tn == NULL) {rc = -1; goto fail; } - tpl_pack(tn, 0); - rc = tpl_dump(tn, TPL_MEM, buf, sz); - tpl_free(tn); - } else if (mode & TPL_FD) { - fd = va_arg(ap, int); - fmt = va_arg(ap, char*); - tn = tpl_map_va(fmt, ap); - if (tn == NULL) {rc = -1; goto fail; } - tpl_pack(tn, 0); - rc = tpl_dump(tn, TPL_FD, fd); - tpl_free(tn); - } else { - tpl_hook.fatal("invalid tpl_jot mode\n"); - } + va_list ap; + char *filename, *fmt; + size_t *sz; + int fd, rc = 0; + void **buf; + tpl_node *tn; + + va_start(ap, mode); + if (mode & TPL_FILE) { + filename = va_arg(ap, char*); + fmt = va_arg(ap, char*); + tn = tpl_map_va(fmt, ap); + if (tn == NULL) {rc = -1; goto fail; } + tpl_pack(tn, 0); + rc = tpl_dump(tn, TPL_FILE, filename); + tpl_free(tn); + } else if (mode & TPL_MEM) { + buf = va_arg(ap, void*); + sz = va_arg(ap, size_t*); + fmt = va_arg(ap, char*); + tn = tpl_map_va(fmt, ap); + if (tn == NULL) {rc = -1; goto fail; } + tpl_pack(tn, 0); + rc = tpl_dump(tn, TPL_MEM, buf, sz); + tpl_free(tn); + } else if (mode & TPL_FD) { + fd = va_arg(ap, int); + fmt = va_arg(ap, char*); + tn = tpl_map_va(fmt, ap); + if (tn == NULL) {rc = -1; goto fail; } + tpl_pack(tn, 0); + rc = tpl_dump(tn, TPL_FD, fd); + tpl_free(tn); + } else { + tpl_hook.fatal("invalid tpl_jot mode\n"); + } fail: - va_end(ap); - return rc; + va_end(ap); + return rc; } TPL_API int tpl_load(tpl_node *r, int mode, ...) { - va_list ap; - int rc = 0, fd = 0; - char *filename = NULL; - void *addr; - size_t sz; - - va_start(ap, mode); - if (mode & TPL_FILE) filename = va_arg(ap, char *); - else if (mode & TPL_MEM) { - addr = va_arg(ap, void *); - sz = va_arg(ap, size_t); - } else if (mode & TPL_FD) { - fd = va_arg(ap, int); - } else { - tpl_hook.oops("unsupported tpl_load mode %d\n", mode); - va_end(ap); - return -1; - } - va_end(ap); - - if (r->type != TPL_TYPE_ROOT) { - tpl_hook.oops("error: tpl_load to non-root node\n"); - return -1; - } - if (((tpl_root_data*)(r->data))->flags & (TPL_WRONLY|TPL_RDONLY)) { - /* already packed or loaded, so reset it as if newly mapped */ - tpl_free_keep_map(r); - } - if (mode & TPL_FILE) { - if (tpl_mmap_file(filename, &((tpl_root_data*)(r->data))->mmap) != 0) { - tpl_hook.oops("tpl_load failed for file %s\n", filename); - return -1; - } - if ((rc = tpl_sanity(r, (mode & TPL_EXCESS_OK))) != 0) { - if (rc == ERR_FMT_MISMATCH) { - tpl_hook.oops("%s: format signature mismatch\n", filename); - } else if (rc == ERR_FLEN_MISMATCH) { - tpl_hook.oops("%s: array lengths mismatch\n", filename); - } else { - tpl_hook.oops("%s: not a valid tpl file\n", filename); - } - tpl_unmap_file(&((tpl_root_data*)(r->data))->mmap); - return -1; - } - ((tpl_root_data*)(r->data))->flags = (TPL_FILE | TPL_RDONLY); - } else if (mode & TPL_MEM) { - ((tpl_root_data*)(r->data))->mmap.text = addr; - ((tpl_root_data*)(r->data))->mmap.text_sz = sz; - if ((rc = tpl_sanity(r, (mode & TPL_EXCESS_OK))) != 0) { - if (rc == ERR_FMT_MISMATCH) { - tpl_hook.oops("format signature mismatch\n"); - } else { - tpl_hook.oops("not a valid tpl file\n"); - } - return -1; - } - ((tpl_root_data*)(r->data))->flags = (TPL_MEM | TPL_RDONLY); - if (mode & TPL_UFREE) ((tpl_root_data*)(r->data))->flags |= TPL_UFREE; - } else if (mode & TPL_FD) { - /* if fd read succeeds, resulting mem img is used for load */ - if (tpl_gather(TPL_GATHER_BLOCKING, fd, &addr, &sz) > 0) { - return tpl_load(r, TPL_MEM|TPL_UFREE, addr, sz); - } else return -1; - } else { - tpl_hook.oops("invalid tpl_load mode %d\n", mode); - return -1; - } - /* this applies to TPL_MEM or TPL_FILE */ - if (tpl_needs_endian_swap(((tpl_root_data*)(r->data))->mmap.text)) - ((tpl_root_data*)(r->data))->flags |= TPL_XENDIAN; - tpl_unpackA0(r); /* prepare root A nodes for use */ - return 0; + va_list ap; + int rc = 0, fd = 0; + char *filename = NULL; + void *addr; + size_t sz; + + va_start(ap, mode); + if (mode & TPL_FILE) filename = va_arg(ap, char *); + else if (mode & TPL_MEM) { + addr = va_arg(ap, void *); + sz = va_arg(ap, size_t); + } else if (mode & TPL_FD) { + fd = va_arg(ap, int); + } else { + tpl_hook.oops("unsupported tpl_load mode %d\n", mode); + va_end(ap); + return -1; + } + va_end(ap); + + if (r->type != TPL_TYPE_ROOT) { + tpl_hook.oops("error: tpl_load to non-root node\n"); + return -1; + } + if (((tpl_root_data*)(r->data))->flags & (TPL_WRONLY|TPL_RDONLY)) { + /* already packed or loaded, so reset it as if newly mapped */ + tpl_free_keep_map(r); + } + if (mode & TPL_FILE) { + if (tpl_mmap_file(filename, &((tpl_root_data*)(r->data))->mmap) != 0) { + tpl_hook.oops("tpl_load failed for file %s\n", filename); + return -1; + } + if ((rc = tpl_sanity(r, (mode & TPL_EXCESS_OK))) != 0) { + if (rc == ERR_FMT_MISMATCH) + tpl_hook.oops("%s: format signature mismatch\n", filename); + else if (rc == ERR_FLEN_MISMATCH) + tpl_hook.oops("%s: array lengths mismatch\n", filename); + else + tpl_hook.oops("%s: not a valid tpl file\n", filename); + + tpl_unmap_file(&((tpl_root_data*)(r->data))->mmap); + return -1; + } + ((tpl_root_data*)(r->data))->flags = (TPL_FILE | TPL_RDONLY); + } else if (mode & TPL_MEM) { + ((tpl_root_data*)(r->data))->mmap.text = addr; + ((tpl_root_data*)(r->data))->mmap.text_sz = sz; + if ((rc = tpl_sanity(r, (mode & TPL_EXCESS_OK))) != 0) { + if (rc == ERR_FMT_MISMATCH) + tpl_hook.oops("format signature mismatch\n"); + else + tpl_hook.oops("not a valid tpl file\n"); + + return -1; + } + ((tpl_root_data*)(r->data))->flags = (TPL_MEM | TPL_RDONLY); + if (mode & TPL_UFREE) ((tpl_root_data*)(r->data))->flags |= TPL_UFREE; + } else if (mode & TPL_FD) { + /* if fd read succeeds, resulting mem img is used for load */ + if (tpl_gather(TPL_GATHER_BLOCKING, fd, &addr, &sz) > 0) + return tpl_load(r, TPL_MEM|TPL_UFREE, addr, sz); + else + return -1; + } else { + tpl_hook.oops("invalid tpl_load mode %d\n", mode); + return -1; + } + /* this applies to TPL_MEM or TPL_FILE */ + if (tpl_needs_endian_swap(((tpl_root_data*)(r->data))->mmap.text)) + ((tpl_root_data*)(r->data))->flags |= TPL_XENDIAN; + tpl_unpackA0(r); /* prepare root A nodes for use */ + return 0; } TPL_API int tpl_Alen(tpl_node *r, int i) { - tpl_node *n; - - n = tpl_find_i(r, i); - if (n == NULL) { - tpl_hook.oops("invalid index %d to tpl_unpack\n", i); - return -1; - } - if (n->type != TPL_TYPE_ARY) return -1; - return ((tpl_atyp*)(n->data))->num; + tpl_node *n; + + n = tpl_find_i(r, i); + if (n == NULL) { + tpl_hook.oops("invalid index %d to tpl_unpack\n", i); + return -1; + } + if (n->type != TPL_TYPE_ARY) return -1; + return ((tpl_atyp*)(n->data))->num; } static void tpl_free_atyp(tpl_node *n, tpl_atyp *atyp) { - tpl_backbone *bb, *bbnxt; - tpl_node *c; - void *dv; - tpl_bin *binp; - tpl_atyp *atypp; - char *strp; - size_t itermax; - tpl_pound_data *pd; - int i; - - bb = atyp->bb; - while (bb) { - bbnxt = bb->next; - dv = bb->data; - c = n->children; - while (c) { - switch (c->type) { - case TPL_TYPE_BYTE: - case TPL_TYPE_DOUBLE: - case TPL_TYPE_INT32: - case TPL_TYPE_UINT32: - case TPL_TYPE_INT64: - case TPL_TYPE_UINT64: - case TPL_TYPE_INT16: - case TPL_TYPE_UINT16: - dv = (void*)((uintptr_t)dv + tpl_types[c->type].sz*c->num); - break; - case TPL_TYPE_BIN: - memcpy(&binp, dv, sizeof(tpl_bin*)); /* cp to aligned */ - if (binp->addr) tpl_hook.free(binp->addr); /* free buf */ - tpl_hook.free(binp); /* free tpl_bin */ - dv = (void*)((uintptr_t)dv + sizeof(tpl_bin*)); - break; - case TPL_TYPE_STR: - for (i = 0; i < c->num; i++) { - memcpy(&strp, dv, sizeof(char*)); /* cp to aligned */ - if (strp) tpl_hook.free(strp); /* free string */ - dv = (void*)((uintptr_t)dv + sizeof(char*)); - } - break; - case TPL_TYPE_POUND: - /* iterate over the preceding nodes */ - itermax = c->num; - pd = (tpl_pound_data*)c->data; - if (++(pd->iternum) < itermax) { - c = pd->iter_start_node; - continue; - } else { /* loop complete. */ - pd->iternum = 0; - } - break; - case TPL_TYPE_ARY: - memcpy(&atypp, dv, sizeof(tpl_atyp*)); /* cp to aligned */ - tpl_free_atyp(c, atypp); /* free atyp */ - dv = (void*)((uintptr_t)dv + sizeof(void*)); - break; - default: - tpl_hook.fatal("unsupported format character\n"); - break; - } - c = c->next; - } - tpl_hook.free(bb); - bb = bbnxt; - } - tpl_hook.free(atyp); + tpl_backbone *bb, *bbnxt; + tpl_node *c; + void *dv; + tpl_bin *binp; + tpl_atyp *atypp; + char *strp; + size_t itermax; + tpl_pound_data *pd; + int i; + + bb = atyp->bb; + while (bb) { + bbnxt = bb->next; + dv = bb->data; + c = n->children; + while (c) { + switch (c->type) { + case TPL_TYPE_BYTE: + case TPL_TYPE_DOUBLE: + case TPL_TYPE_INT32: + case TPL_TYPE_UINT32: + case TPL_TYPE_INT64: + case TPL_TYPE_UINT64: + case TPL_TYPE_INT16: + case TPL_TYPE_UINT16: + dv = (void*)((uintptr_t)dv + tpl_types[c->type].sz*c->num); + break; + case TPL_TYPE_BIN: + memcpy(&binp, dv, sizeof(tpl_bin*)); /* cp to aligned */ + if (binp->addr) tpl_hook.free(binp->addr); /* free buf */ + tpl_hook.free(binp); /* free tpl_bin */ + dv = (void*)((uintptr_t)dv + sizeof(tpl_bin*)); + break; + case TPL_TYPE_STR: + for (i = 0; i < c->num; i++) { + memcpy(&strp, dv, sizeof(char*)); /* cp to aligned */ + if (strp) tpl_hook.free(strp); /* free string */ + dv = (void*)((uintptr_t)dv + sizeof(char*)); + } + break; + case TPL_TYPE_POUND: + /* iterate over the preceding nodes */ + itermax = c->num; + pd = (tpl_pound_data*)c->data; + if (++(pd->iternum) < itermax) { + c = pd->iter_start_node; + continue; + } else { /* loop complete. */ + pd->iternum = 0; + } + break; + case TPL_TYPE_ARY: + memcpy(&atypp, dv, sizeof(tpl_atyp*)); /* cp to aligned */ + tpl_free_atyp(c, atypp); /* free atyp */ + dv = (void*)((uintptr_t)dv + sizeof(void*)); + break; + default: + tpl_hook.fatal("unsupported format character\n"); + break; + } + c = c->next; + } + tpl_hook.free(bb); + bb = bbnxt; + } + tpl_hook.free(atyp); } /* determine (by walking) byte length of serialized r/A node at address dv @@ -1652,599 +1650,597 @@ static void tpl_free_atyp(tpl_node *n, tpl_atyp *atyp) */ static int tpl_serlen(tpl_node *r, tpl_node *n, void *dv, size_t *serlen) { - uint32_t slen; - int num = 0, fidx; - tpl_node *c; - size_t len = 0, alen, buf_past, itermax; - tpl_pound_data *pd; - - buf_past = ((uintptr_t)((tpl_root_data*)(r->data))->mmap.text + - ((tpl_root_data*)(r->data))->mmap.text_sz); - - if (n->type == TPL_TYPE_ROOT) num = 1; - else if (n->type == TPL_TYPE_ARY) { - if ((uintptr_t)dv + sizeof(uint32_t) > buf_past) return -1; - memcpy(&num, dv, sizeof(uint32_t)); - if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN) - tpl_byteswap(&num, sizeof(uint32_t)); - dv = (void*)((uintptr_t)dv + sizeof(uint32_t)); - len += sizeof(uint32_t); - } else tpl_hook.fatal("internal error in tpl_serlen\n"); - - while (num-- > 0) { - c = n->children; - while (c) { - switch (c->type) { - case TPL_TYPE_BYTE: - case TPL_TYPE_DOUBLE: - case TPL_TYPE_INT32: - case TPL_TYPE_UINT32: - case TPL_TYPE_INT64: - case TPL_TYPE_UINT64: - case TPL_TYPE_INT16: - case TPL_TYPE_UINT16: - for (fidx = 0; fidx < c->num; fidx++) { /* octothorpe support */ - if ((uintptr_t)dv + tpl_types[c->type].sz > buf_past) return -1; - dv = (void*)((uintptr_t)dv + tpl_types[c->type].sz); - len += tpl_types[c->type].sz; - } - break; - case TPL_TYPE_BIN: - len += sizeof(uint32_t); - if ((uintptr_t)dv + sizeof(uint32_t) > buf_past) return -1; - memcpy(&slen, dv, sizeof(uint32_t)); - if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN) - tpl_byteswap(&slen, sizeof(uint32_t)); - len += slen; - dv = (void*)((uintptr_t)dv + sizeof(uint32_t)); - if ((uintptr_t)dv + slen > buf_past) return -1; - dv = (void*)((uintptr_t)dv + slen); - break; - case TPL_TYPE_STR: - for (fidx = 0; fidx < c->num; fidx++) { /* octothorpe support */ - len += sizeof(uint32_t); - if ((uintptr_t)dv + sizeof(uint32_t) > buf_past) return -1; - memcpy(&slen, dv, sizeof(uint32_t)); - if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN) - tpl_byteswap(&slen, sizeof(uint32_t)); - if (!(((tpl_root_data*)(r->data))->flags & TPL_OLD_STRING_FMT)) - slen = (slen > 1) ? (slen-1) : 0; - len += slen; - dv = (void*)((uintptr_t)dv + sizeof(uint32_t)); - if ((uintptr_t)dv + slen > buf_past) return -1; - dv = (void*)((uintptr_t)dv + slen); - } - break; - case TPL_TYPE_ARY: - if (tpl_serlen(r, c, dv, &alen) == -1) return -1; - dv = (void*)((uintptr_t)dv + alen); - len += alen; - break; - case TPL_TYPE_POUND: - /* iterate over the preceding nodes */ - itermax = c->num; - pd = (tpl_pound_data*)c->data; - if (++(pd->iternum) < itermax) { - c = pd->iter_start_node; - continue; - } else { /* loop complete. */ - pd->iternum = 0; - } - break; - default: - tpl_hook.fatal("unsupported format character\n"); - break; - } - c = c->next; - } - } - *serlen = len; - return 0; + uint32_t slen; + int num = 0, fidx; + tpl_node *c; + size_t len = 0, alen, buf_past, itermax; + tpl_pound_data *pd; + + buf_past = ((uintptr_t)((tpl_root_data*)(r->data))->mmap.text + + ((tpl_root_data*)(r->data))->mmap.text_sz); + + if (n->type == TPL_TYPE_ROOT) num = 1; + else if (n->type == TPL_TYPE_ARY) { + if ((uintptr_t)dv + sizeof(uint32_t) > buf_past) return -1; + memcpy(&num, dv, sizeof(uint32_t)); + if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN) + tpl_byteswap(&num, sizeof(uint32_t)); + dv = (void*)((uintptr_t)dv + sizeof(uint32_t)); + len += sizeof(uint32_t); + } else tpl_hook.fatal("internal error in tpl_serlen\n"); + + while (num-- > 0) { + c = n->children; + while (c) { + switch (c->type) { + case TPL_TYPE_BYTE: + case TPL_TYPE_DOUBLE: + case TPL_TYPE_INT32: + case TPL_TYPE_UINT32: + case TPL_TYPE_INT64: + case TPL_TYPE_UINT64: + case TPL_TYPE_INT16: + case TPL_TYPE_UINT16: + for (fidx = 0; fidx < c->num; fidx++) { /* octothorpe support */ + if ((uintptr_t)dv + tpl_types[c->type].sz > buf_past) return -1; + dv = (void*)((uintptr_t)dv + tpl_types[c->type].sz); + len += tpl_types[c->type].sz; + } + break; + case TPL_TYPE_BIN: + len += sizeof(uint32_t); + if ((uintptr_t)dv + sizeof(uint32_t) > buf_past) return -1; + memcpy(&slen, dv, sizeof(uint32_t)); + if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN) + tpl_byteswap(&slen, sizeof(uint32_t)); + len += slen; + dv = (void*)((uintptr_t)dv + sizeof(uint32_t)); + if ((uintptr_t)dv + slen > buf_past) return -1; + dv = (void*)((uintptr_t)dv + slen); + break; + case TPL_TYPE_STR: + for (fidx = 0; fidx < c->num; fidx++) { /* octothorpe support */ + len += sizeof(uint32_t); + if ((uintptr_t)dv + sizeof(uint32_t) > buf_past) return -1; + memcpy(&slen, dv, sizeof(uint32_t)); + if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN) + tpl_byteswap(&slen, sizeof(uint32_t)); + if (!(((tpl_root_data*)(r->data))->flags & TPL_OLD_STRING_FMT)) + slen = (slen > 1) ? (slen-1) : 0; + len += slen; + dv = (void*)((uintptr_t)dv + sizeof(uint32_t)); + if ((uintptr_t)dv + slen > buf_past) return -1; + dv = (void*)((uintptr_t)dv + slen); + } + break; + case TPL_TYPE_ARY: + if (tpl_serlen(r, c, dv, &alen) == -1) return -1; + dv = (void*)((uintptr_t)dv + alen); + len += alen; + break; + case TPL_TYPE_POUND: + /* iterate over the preceding nodes */ + itermax = c->num; + pd = (tpl_pound_data*)c->data; + if (++(pd->iternum) < itermax) { + c = pd->iter_start_node; + continue; + } else { /* loop complete. */ + pd->iternum = 0; + } + break; + default: + tpl_hook.fatal("unsupported format character\n"); + break; + } + c = c->next; + } + } + *serlen = len; + return 0; } static int tpl_mmap_output_file(char *filename, size_t sz, void **text_out) { - void *text; - int fd, perms; + void *text; + int fd, perms; #ifndef _WIN32 - perms = S_IRUSR|S_IWUSR|S_IWGRP|S_IRGRP|S_IROTH; /* ug+w o+r */ - fd = open(filename, O_CREAT|O_TRUNC|O_RDWR, perms); + perms = S_IRUSR|S_IWUSR|S_IWGRP|S_IRGRP|S_IROTH; /* ug+w o+r */ + fd = open(filename, O_CREAT|O_TRUNC|O_RDWR, perms); #else perms = _S_IWRITE; - fd = _open(filename, _O_CREAT|_O_TRUNC|_O_RDWR, perms); + fd = _open(filename, _O_CREAT|_O_TRUNC|_O_RDWR, perms); #endif - if (fd == -1) { - tpl_hook.oops("Couldn't open file %s: %s\n", filename, strerror(errno)); - return -1; - } - - text = mmap(0, sz, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); - if (text == MAP_FAILED) { - tpl_hook.oops("Failed to mmap %s: %s\n", filename, strerror(errno)); - close(fd); - return -1; - } - if (ftruncate(fd, sz) == -1) { - tpl_hook.oops("ftruncate failed: %s\n", strerror(errno)); - munmap(text, sz); - close(fd); - return -1; - } - *text_out = text; - return fd; + if (fd == -1) { + tpl_hook.oops("Couldn't open file %s: %s\n", filename, strerror(errno)); + return -1; + } + + text = mmap(0, sz, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); + if (text == MAP_FAILED) { + tpl_hook.oops("Failed to mmap %s: %s\n", filename, strerror(errno)); + close(fd); + return -1; + } + if (ftruncate(fd, sz) == -1) { + tpl_hook.oops("ftruncate failed: %s\n", strerror(errno)); + munmap(text, sz); + close(fd); + return -1; + } + *text_out = text; + return fd; } static int tpl_mmap_file(char *filename, tpl_mmap_rec *mr) { - struct stat stat_buf; - - if ((mr->fd = open(filename, O_RDONLY)) == -1) { - tpl_hook.oops("Couldn't open file %s: %s\n", filename, strerror(errno)); - return -1; - } - - if (fstat(mr->fd, &stat_buf) == -1) { - close(mr->fd); - tpl_hook.oops("Couldn't stat file %s: %s\n", filename, strerror(errno)); - return -1; - } - - mr->text_sz = (size_t)stat_buf.st_size; - mr->text = mmap(0, stat_buf.st_size, PROT_READ, MAP_PRIVATE, mr->fd, 0); - if (mr->text == MAP_FAILED) { - close(mr->fd); - tpl_hook.oops("Failed to mmap %s: %s\n", filename, strerror(errno)); - return -1; - } - - return 0; + struct stat stat_buf; + + if ((mr->fd = open(filename, O_RDONLY)) == -1) { + tpl_hook.oops("Couldn't open file %s: %s\n", filename, strerror(errno)); + return -1; + } + + if (fstat(mr->fd, &stat_buf) == -1) { + close(mr->fd); + tpl_hook.oops("Couldn't stat file %s: %s\n", filename, strerror(errno)); + return -1; + } + + mr->text_sz = (size_t)stat_buf.st_size; + mr->text = mmap(0, stat_buf.st_size, PROT_READ, MAP_PRIVATE, mr->fd, 0); + if (mr->text == MAP_FAILED) { + close(mr->fd); + tpl_hook.oops("Failed to mmap %s: %s\n", filename, strerror(errno)); + return -1; + } + + return 0; } TPL_API int tpl_pack(tpl_node *r, int i) { - tpl_node *n, *child, *np; - void *datav = NULL; - size_t sz, itermax; - uint32_t slen; - char *str; - tpl_bin *bin; - tpl_pound_data *pd; - int fidx; - - n = tpl_find_i(r, i); - if (n == NULL) { - tpl_hook.oops("invalid index %d to tpl_pack\n", i); - return -1; - } - - if (((tpl_root_data*)(r->data))->flags & TPL_RDONLY) { - /* convert to an writeable tpl, initially empty */ - tpl_free_keep_map(r); - } - - ((tpl_root_data*)(r->data))->flags |= TPL_WRONLY; - - if (n->type == TPL_TYPE_ARY) datav = tpl_extend_backbone(n); - child = n->children; - while (child) { - switch (child->type) { - case TPL_TYPE_BYTE: - case TPL_TYPE_DOUBLE: - case TPL_TYPE_INT32: - case TPL_TYPE_UINT32: - case TPL_TYPE_INT64: - case TPL_TYPE_UINT64: - case TPL_TYPE_INT16: - case TPL_TYPE_UINT16: - /* no need to use fidx iteration here; we can copy multiple values in one memcpy */ - memcpy(child->data, child->addr, tpl_types[child->type].sz * child->num); - if (datav) datav = tpl_cpv(datav, child->data, tpl_types[child->type].sz * child->num); - if (n->type == TPL_TYPE_ARY) n->ser_osz += tpl_types[child->type].sz * child->num; - break; - case TPL_TYPE_BIN: - /* copy the buffer to be packed */ - slen = ((tpl_bin*)child->addr)->sz; - if (slen > 0) { - str = tpl_hook.malloc(slen); - if (!str) fatal_oom(); - memcpy(str, ((tpl_bin*)child->addr)->addr, slen); - } else str = NULL; - /* and make a tpl_bin to point to it */ - bin = tpl_hook.malloc(sizeof(tpl_bin)); - if (!bin) fatal_oom(); - bin->addr = str; - bin->sz = slen; - /* now pack its pointer, first deep freeing any pre-existing bin */ - if (*(tpl_bin**)(child->data) != NULL) { - if ((*(tpl_bin**)(child->data))->sz != 0) { - tpl_hook.free((*(tpl_bin**)(child->data))->addr); - } - tpl_hook.free(*(tpl_bin**)(child->data)); - } - memcpy(child->data, &bin, sizeof(tpl_bin*)); - if (datav) { - datav = tpl_cpv(datav, &bin, sizeof(tpl_bin*)); - *(tpl_bin**)(child->data) = NULL; - } - if (n->type == TPL_TYPE_ARY) { - n->ser_osz += sizeof(uint32_t); /* binary buf len word */ - n->ser_osz += bin->sz; /* binary buf */ - } - break; - case TPL_TYPE_STR: - for (fidx = 0; fidx < child->num; fidx++) { - /* copy the string to be packed. slen includes \0. this - block also works if the string pointer is NULL. */ - char *caddr = ((char**)child->addr)[fidx]; - char **cdata = &((char**)child->data)[fidx]; - slen = caddr ? (EM_SAFE_STRLEN(caddr) + 1) : 0; - if (slen) { - str = tpl_hook.malloc(slen); - if (!str) fatal_oom(); - memcpy(str, caddr, slen); /* include \0 */ - } else { - str = NULL; - } - /* now pack its pointer, first freeing any pre-existing string */ - if (*cdata != NULL) { - tpl_hook.free(*cdata); - } - memcpy(cdata, &str, sizeof(char*)); - if (datav) { - datav = tpl_cpv(datav, &str, sizeof(char*)); - *cdata = NULL; - } - if (n->type == TPL_TYPE_ARY) { - n->ser_osz += sizeof(uint32_t); /* string len word */ - if (slen > 1) n->ser_osz += slen-1;/* string (without nul) */ - } - } - break; - case TPL_TYPE_ARY: - /* copy the child's tpl_atype* and reset it to empty */ - if (datav) { - sz = ((tpl_atyp*)(child->data))->sz; - datav = tpl_cpv(datav, &child->data, sizeof(void*)); - child->data = tpl_hook.malloc(sizeof(tpl_atyp)); - if (!child->data) fatal_oom(); - ((tpl_atyp*)(child->data))->num = 0; - ((tpl_atyp*)(child->data))->sz = sz; - ((tpl_atyp*)(child->data))->bb = NULL; - ((tpl_atyp*)(child->data))->bbtail = NULL; - } - /* parent is array? then bubble up child array's ser_osz */ - if (n->type == TPL_TYPE_ARY) { - n->ser_osz += sizeof(uint32_t); /* array len word */ - n->ser_osz += child->ser_osz; /* child array ser_osz */ - child->ser_osz = 0; /* reset child array ser_osz */ - } - break; - - case TPL_TYPE_POUND: - /* we need to iterate n times over preceding nodes in S(...). - * we may be in the midst of an iteration each time or starting. */ - pd = (tpl_pound_data*)child->data; - itermax = child->num; - - /* itermax is total num of iterations needed */ - /* pd->iternum is current iteration index */ - /* pd->inter_elt_len is element-to-element len of contiguous structs */ - /* pd->iter_start_node is where we jump to at each iteration. */ - - if (++(pd->iternum) < itermax) { - - /* in start or midst of loop. advance addr/data pointers. */ - for (np = pd->iter_start_node; np != child; np = np->next) { - np->data = (char*)(np->data) + - (tpl_types[np->type].sz * np->num); - np->addr = (char*)(np->addr) + pd->inter_elt_len; - } - /* do next iteration */ - child = pd->iter_start_node; - continue; - - } else { /* loop complete. */ - - /* reset iteration index and addr/data pointers. */ - pd->iternum = 0; - for (np = pd->iter_start_node; np != child; np = np->next) { - np->data = (char*)(np->data) - ((itermax-1) * - tpl_types[np->type].sz * - np->num); - np->addr = (char*)(np->addr) - ((itermax-1) * pd->inter_elt_len); - } - - } - break; - default: - tpl_hook.fatal("unsupported format character\n"); - break; - } - child = child->next; - } - return 0; + tpl_node *n, *child, *np; + void *datav = NULL; + size_t sz, itermax; + uint32_t slen; + char *str; + tpl_bin *bin; + tpl_pound_data *pd; + int fidx; + + n = tpl_find_i(r, i); + if (n == NULL) { + tpl_hook.oops("invalid index %d to tpl_pack\n", i); + return -1; + } + + if (((tpl_root_data*)(r->data))->flags & TPL_RDONLY) { + /* convert to an writeable tpl, initially empty */ + tpl_free_keep_map(r); + } + + ((tpl_root_data*)(r->data))->flags |= TPL_WRONLY; + + if (n->type == TPL_TYPE_ARY) datav = tpl_extend_backbone(n); + child = n->children; + while (child) { + switch (child->type) { + case TPL_TYPE_BYTE: + case TPL_TYPE_DOUBLE: + case TPL_TYPE_INT32: + case TPL_TYPE_UINT32: + case TPL_TYPE_INT64: + case TPL_TYPE_UINT64: + case TPL_TYPE_INT16: + case TPL_TYPE_UINT16: + /* no need to use fidx iteration here; we can copy multiple values in one memcpy */ + memcpy(child->data, child->addr, tpl_types[child->type].sz * child->num); + if (datav) datav = tpl_cpv(datav, child->data, tpl_types[child->type].sz * child->num); + if (n->type == TPL_TYPE_ARY) n->ser_osz += tpl_types[child->type].sz * child->num; + break; + case TPL_TYPE_BIN: + /* copy the buffer to be packed */ + slen = ((tpl_bin*)child->addr)->sz; + if (slen > 0) { + str = tpl_hook.malloc(slen); + if (!str) fatal_oom(); + memcpy(str, ((tpl_bin*)child->addr)->addr, slen); + } else str = NULL; + /* and make a tpl_bin to point to it */ + bin = tpl_hook.malloc(sizeof(tpl_bin)); + if (!bin) fatal_oom(); + bin->addr = str; + bin->sz = slen; + /* now pack its pointer, first deep freeing any pre-existing bin */ + if (*(tpl_bin**)(child->data) != NULL) { + if ((*(tpl_bin**)(child->data))->sz != 0) + tpl_hook.free((*(tpl_bin**)(child->data))->addr); + + tpl_hook.free(*(tpl_bin**)(child->data)); + } + memcpy(child->data, &bin, sizeof(tpl_bin*)); + if (datav) { + datav = tpl_cpv(datav, &bin, sizeof(tpl_bin*)); + *(tpl_bin**)(child->data) = NULL; + } + if (n->type == TPL_TYPE_ARY) { + n->ser_osz += sizeof(uint32_t); /* binary buf len word */ + n->ser_osz += bin->sz; /* binary buf */ + } + break; + case TPL_TYPE_STR: + for (fidx = 0; fidx < child->num; fidx++) { + /* copy the string to be packed. slen includes \0. this + block also works if the string pointer is NULL. */ + char *caddr = ((char**)child->addr)[fidx]; + char **cdata = &((char**)child->data)[fidx]; + slen = caddr ? (EM_SAFE_STRLEN(caddr) + 1) : 0; + if (slen) { + str = tpl_hook.malloc(slen); + if (!str) fatal_oom(); + memcpy(str, caddr, slen); /* include \0 */ + } else { + str = NULL; + } + /* now pack its pointer, first freeing any pre-existing string */ + if (*cdata != NULL) + tpl_hook.free(*cdata); + + memcpy(cdata, &str, sizeof(char*)); + if (datav) { + datav = tpl_cpv(datav, &str, sizeof(char*)); + *cdata = NULL; + } + if (n->type == TPL_TYPE_ARY) { + n->ser_osz += sizeof(uint32_t); /* string len word */ + if (slen > 1) n->ser_osz += slen-1;/* string (without nul) */ + } + } + break; + case TPL_TYPE_ARY: + /* copy the child's tpl_atype* and reset it to empty */ + if (datav) { + sz = ((tpl_atyp*)(child->data))->sz; + datav = tpl_cpv(datav, &child->data, sizeof(void*)); + child->data = tpl_hook.malloc(sizeof(tpl_atyp)); + if (!child->data) fatal_oom(); + ((tpl_atyp*)(child->data))->num = 0; + ((tpl_atyp*)(child->data))->sz = sz; + ((tpl_atyp*)(child->data))->bb = NULL; + ((tpl_atyp*)(child->data))->bbtail = NULL; + } + /* parent is array? then bubble up child array's ser_osz */ + if (n->type == TPL_TYPE_ARY) { + n->ser_osz += sizeof(uint32_t); /* array len word */ + n->ser_osz += child->ser_osz; /* child array ser_osz */ + child->ser_osz = 0; /* reset child array ser_osz */ + } + break; + + case TPL_TYPE_POUND: + /* we need to iterate n times over preceding nodes in S(...). + * we may be in the midst of an iteration each time or starting. */ + pd = (tpl_pound_data*)child->data; + itermax = child->num; + + /* itermax is total num of iterations needed */ + /* pd->iternum is current iteration index */ + /* pd->inter_elt_len is element-to-element len of contiguous structs */ + /* pd->iter_start_node is where we jump to at each iteration. */ + + if (++(pd->iternum) < itermax) { + + /* in start or midst of loop. advance addr/data pointers. */ + for (np = pd->iter_start_node; np != child; np = np->next) { + np->data = (char*)(np->data) + + (tpl_types[np->type].sz * np->num); + np->addr = (char*)(np->addr) + pd->inter_elt_len; + } + /* do next iteration */ + child = pd->iter_start_node; + continue; + + } else { /* loop complete. */ + + /* reset iteration index and addr/data pointers. */ + pd->iternum = 0; + for (np = pd->iter_start_node; np != child; np = np->next) { + np->data = (char*)(np->data) - ((itermax-1) * + tpl_types[np->type].sz * + np->num); + np->addr = (char*)(np->addr) - ((itermax-1) * pd->inter_elt_len); + } + + } + break; + default: + tpl_hook.fatal("unsupported format character\n"); + break; + } + child = child->next; + } + return 0; } TPL_API int tpl_unpack(tpl_node *r, int i) { - tpl_node *n, *c, *np; - uint32_t slen; - int rc = 1, fidx; - char *str; - void *dv = NULL, *caddr; - size_t A_bytes, itermax; - tpl_pound_data *pd; - void *img; - size_t sz; - - - /* handle unusual case of tpl_pack, tpl_unpack without an - * intervening tpl_dump. do a dump/load implicitly. */ - if (((tpl_root_data*)(r->data))->flags & TPL_WRONLY) { - if (tpl_dump(r, TPL_MEM, &img, &sz) != 0) return -1; - if (tpl_load(r, TPL_MEM|TPL_UFREE, img, sz) != 0) { - tpl_hook.free(img); - return -1; - }; - } - - n = tpl_find_i(r, i); - if (n == NULL) { - tpl_hook.oops("invalid index %d to tpl_unpack\n", i); - return -1; - } - - /* either root node or an A node */ - if (n->type == TPL_TYPE_ROOT) { - dv = tpl_find_data_start(((tpl_root_data*)(n->data))->mmap.text); - } else if (n->type == TPL_TYPE_ARY) { - if (((tpl_atyp*)(n->data))->num <= 0) return 0; /* array consumed */ - else rc = ((tpl_atyp*)(n->data))->num--; - dv = ((tpl_atyp*)(n->data))->cur; - if (!dv) tpl_hook.fatal("must unpack parent of node before node itself\n"); - } - - c = n->children; - while (c) { - switch (c->type) { - case TPL_TYPE_BYTE: - case TPL_TYPE_DOUBLE: - case TPL_TYPE_INT32: - case TPL_TYPE_UINT32: - case TPL_TYPE_INT64: - case TPL_TYPE_UINT64: - case TPL_TYPE_INT16: - case TPL_TYPE_UINT16: - /* unpack elements of cross-endian octothorpic array individually */ - if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN) { - for (fidx = 0; fidx < c->num; fidx++) { - caddr = (void*)((uintptr_t)c->addr + (fidx * tpl_types[c->type].sz)); - memcpy(caddr, dv, tpl_types[c->type].sz); - tpl_byteswap(caddr, tpl_types[c->type].sz); - dv = (void*)((uintptr_t)dv + tpl_types[c->type].sz); - } - } else { - /* bulk unpack ok if not cross-endian */ - memcpy(c->addr, dv, tpl_types[c->type].sz * c->num); - dv = (void*)((uintptr_t)dv + tpl_types[c->type].sz * c->num); - } - break; - case TPL_TYPE_BIN: - memcpy(&slen, dv, sizeof(uint32_t)); - if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN) - tpl_byteswap(&slen, sizeof(uint32_t)); - if (slen > 0) { - str = (char*)tpl_hook.malloc(slen); - if (!str) fatal_oom(); - } else str = NULL; - dv = (void*)((uintptr_t)dv + sizeof(uint32_t)); - if (slen > 0) memcpy(str, dv, slen); - memcpy(&(((tpl_bin*)c->addr)->addr), &str, sizeof(void*)); - memcpy(&(((tpl_bin*)c->addr)->sz), &slen, sizeof(uint32_t)); - dv = (void*)((uintptr_t)dv + slen); - break; - case TPL_TYPE_STR: - for (fidx = 0; fidx < c->num; fidx++) { - memcpy(&slen, dv, sizeof(uint32_t)); - if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN) - tpl_byteswap(&slen, sizeof(uint32_t)); - if (((tpl_root_data*)(r->data))->flags & TPL_OLD_STRING_FMT) - slen += 1; - dv = (void*)((uintptr_t)dv + sizeof(uint32_t)); - if (slen) { /* slen includes \0 */ - str = (char*)tpl_hook.malloc(slen); - if (!str) fatal_oom(); - if (slen > 1) memcpy(str, dv, slen-1); - str[slen-1] = '\0'; /* nul terminate */ - dv = (void*)((uintptr_t)dv + slen-1); - } else str = NULL; - memcpy(&((char**)c->addr)[fidx], &str, sizeof(char*)); - } - break; - case TPL_TYPE_POUND: - /* iterate over preceding nodes */ - pd = (tpl_pound_data*)c->data; - itermax = c->num; - if (++(pd->iternum) < itermax) { - /* in start or midst of loop. advance addr/data pointers. */ - for (np = pd->iter_start_node; np != c; np = np->next) { - np->addr = (char*)(np->addr) + pd->inter_elt_len; - } - /* do next iteration */ - c = pd->iter_start_node; - continue; - - } else { /* loop complete. */ - - /* reset iteration index and addr/data pointers. */ - pd->iternum = 0; - for (np = pd->iter_start_node; np != c; np = np->next) { - np->addr = (char*)(np->addr) - ((itermax-1) * pd->inter_elt_len); - } - - } - break; - case TPL_TYPE_ARY: - if (tpl_serlen(r, c, dv, &A_bytes) == -1) - tpl_hook.fatal("internal error in unpack\n"); - memcpy(&((tpl_atyp*)(c->data))->num, dv, sizeof(uint32_t)); - if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN) - tpl_byteswap(&((tpl_atyp*)(c->data))->num, sizeof(uint32_t)); - ((tpl_atyp*)(c->data))->cur = (void*)((uintptr_t)dv+sizeof(uint32_t)); - dv = (void*)((uintptr_t)dv + A_bytes); - break; - default: - tpl_hook.fatal("unsupported format character\n"); - break; - } - - c = c->next; - } - if (n->type == TPL_TYPE_ARY) ((tpl_atyp*)(n->data))->cur = dv; /* next element */ - return rc; + tpl_node *n, *c, *np; + uint32_t slen; + int rc = 1, fidx; + char *str; + void *dv = NULL, *caddr; + size_t A_bytes, itermax; + tpl_pound_data *pd; + void *img; + size_t sz; + + + /* handle unusual case of tpl_pack, tpl_unpack without an + * intervening tpl_dump. do a dump/load implicitly. */ + if (((tpl_root_data*)(r->data))->flags & TPL_WRONLY) { + if (tpl_dump(r, TPL_MEM, &img, &sz) != 0) return -1; + if (tpl_load(r, TPL_MEM|TPL_UFREE, img, sz) != 0) { + tpl_hook.free(img); + return -1; + }; + } + + n = tpl_find_i(r, i); + if (n == NULL) { + tpl_hook.oops("invalid index %d to tpl_unpack\n", i); + return -1; + } + + /* either root node or an A node */ + if (n->type == TPL_TYPE_ROOT) { + dv = tpl_find_data_start(((tpl_root_data*)(n->data))->mmap.text); + } else if (n->type == TPL_TYPE_ARY) { + if (((tpl_atyp*)(n->data))->num <= 0) return 0; /* array consumed */ + else rc = ((tpl_atyp*)(n->data))->num--; + dv = ((tpl_atyp*)(n->data))->cur; + if (!dv) tpl_hook.fatal("must unpack parent of node before node itself\n"); + } + + c = n->children; + while (c) { + switch (c->type) { + case TPL_TYPE_BYTE: + case TPL_TYPE_DOUBLE: + case TPL_TYPE_INT32: + case TPL_TYPE_UINT32: + case TPL_TYPE_INT64: + case TPL_TYPE_UINT64: + case TPL_TYPE_INT16: + case TPL_TYPE_UINT16: + /* unpack elements of cross-endian octothorpic array individually */ + if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN) { + for (fidx = 0; fidx < c->num; fidx++) { + caddr = (void*)((uintptr_t)c->addr + (fidx * tpl_types[c->type].sz)); + memcpy(caddr, dv, tpl_types[c->type].sz); + tpl_byteswap(caddr, tpl_types[c->type].sz); + dv = (void*)((uintptr_t)dv + tpl_types[c->type].sz); + } + } else { + /* bulk unpack ok if not cross-endian */ + memcpy(c->addr, dv, tpl_types[c->type].sz * c->num); + dv = (void*)((uintptr_t)dv + tpl_types[c->type].sz * c->num); + } + break; + case TPL_TYPE_BIN: + memcpy(&slen, dv, sizeof(uint32_t)); + if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN) + tpl_byteswap(&slen, sizeof(uint32_t)); + if (slen > 0) { + str = (char*)tpl_hook.malloc(slen); + if (!str) fatal_oom(); + } else str = NULL; + dv = (void*)((uintptr_t)dv + sizeof(uint32_t)); + if (slen > 0) memcpy(str, dv, slen); + memcpy(&(((tpl_bin*)c->addr)->addr), &str, sizeof(void*)); + memcpy(&(((tpl_bin*)c->addr)->sz), &slen, sizeof(uint32_t)); + dv = (void*)((uintptr_t)dv + slen); + break; + case TPL_TYPE_STR: + for (fidx = 0; fidx < c->num; fidx++) { + memcpy(&slen, dv, sizeof(uint32_t)); + if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN) + tpl_byteswap(&slen, sizeof(uint32_t)); + if (((tpl_root_data*)(r->data))->flags & TPL_OLD_STRING_FMT) + slen += 1; + dv = (void*)((uintptr_t)dv + sizeof(uint32_t)); + if (slen) { /* slen includes \0 */ + str = (char*)tpl_hook.malloc(slen); + if (!str) fatal_oom(); + if (slen > 1) memcpy(str, dv, slen-1); + str[slen-1] = '\0'; /* nul terminate */ + dv = (void*)((uintptr_t)dv + slen-1); + } else str = NULL; + memcpy(&((char**)c->addr)[fidx], &str, sizeof(char*)); + } + break; + case TPL_TYPE_POUND: + /* iterate over preceding nodes */ + pd = (tpl_pound_data*)c->data; + itermax = c->num; + if (++(pd->iternum) < itermax) { + /* in start or midst of loop. advance addr/data pointers. */ + for (np = pd->iter_start_node; np != c; np = np->next) + np->addr = (char*)(np->addr) + pd->inter_elt_len; + + /* do next iteration */ + c = pd->iter_start_node; + continue; + + } else { /* loop complete. */ + + /* reset iteration index and addr/data pointers. */ + pd->iternum = 0; + for (np = pd->iter_start_node; np != c; np = np->next) + np->addr = (char*)(np->addr) - ((itermax-1) * pd->inter_elt_len); + } + break; + case TPL_TYPE_ARY: + if (tpl_serlen(r, c, dv, &A_bytes) == -1) + tpl_hook.fatal("internal error in unpack\n"); + memcpy(&((tpl_atyp*)(c->data))->num, dv, sizeof(uint32_t)); + if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN) + tpl_byteswap(&((tpl_atyp*)(c->data))->num, sizeof(uint32_t)); + ((tpl_atyp*)(c->data))->cur = (void*)((uintptr_t)dv+sizeof(uint32_t)); + dv = (void*)((uintptr_t)dv + A_bytes); + break; + default: + tpl_hook.fatal("unsupported format character\n"); + break; + } + + c = c->next; + } + if (n->type == TPL_TYPE_ARY) ((tpl_atyp*)(n->data))->cur = dv; /* next element */ + return rc; } /* Specialized function that unpacks only the root's A nodes, after tpl_load */ static int tpl_unpackA0(tpl_node *r) { - tpl_node *n, *c; - uint32_t slen; - int rc = 1, fidx, i; - void *dv; - size_t A_bytes, itermax; - tpl_pound_data *pd; - - n = r; - dv = tpl_find_data_start(((tpl_root_data*)(r->data))->mmap.text); - - c = n->children; - while (c) { - switch (c->type) { - case TPL_TYPE_BYTE: - case TPL_TYPE_DOUBLE: - case TPL_TYPE_INT32: - case TPL_TYPE_UINT32: - case TPL_TYPE_INT64: - case TPL_TYPE_UINT64: - case TPL_TYPE_INT16: - case TPL_TYPE_UINT16: - for (fidx = 0; fidx < c->num; fidx++) { - dv = (void*)((uintptr_t)dv + tpl_types[c->type].sz); - } - break; - case TPL_TYPE_BIN: - memcpy(&slen, dv, sizeof(uint32_t)); - if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN) - tpl_byteswap(&slen, sizeof(uint32_t)); - dv = (void*)((uintptr_t)dv + sizeof(uint32_t)); - dv = (void*)((uintptr_t)dv + slen); - break; - case TPL_TYPE_STR: - for (i = 0; i < c->num; i++) { - memcpy(&slen, dv, sizeof(uint32_t)); - if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN) - tpl_byteswap(&slen, sizeof(uint32_t)); - if (((tpl_root_data*)(r->data))->flags & TPL_OLD_STRING_FMT) - slen += 1; - dv = (void*)((uintptr_t)dv + sizeof(uint32_t)); - if (slen > 1) dv = (void*)((uintptr_t)dv + slen-1); - } - break; - case TPL_TYPE_POUND: - /* iterate over the preceding nodes */ - itermax = c->num; - pd = (tpl_pound_data*)c->data; - if (++(pd->iternum) < itermax) { - c = pd->iter_start_node; - continue; - } else { /* loop complete. */ - pd->iternum = 0; - } - break; - case TPL_TYPE_ARY: - if (tpl_serlen(r, c, dv, &A_bytes) == -1) - tpl_hook.fatal("internal error in unpackA0\n"); - memcpy(&((tpl_atyp*)(c->data))->num, dv, sizeof(uint32_t)); - if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN) - tpl_byteswap(&((tpl_atyp*)(c->data))->num, sizeof(uint32_t)); - ((tpl_atyp*)(c->data))->cur = (void*)((uintptr_t)dv+sizeof(uint32_t)); - dv = (void*)((uintptr_t)dv + A_bytes); - break; - default: - tpl_hook.fatal("unsupported format character\n"); - break; - } - c = c->next; - } - return rc; + tpl_node *n, *c; + uint32_t slen; + int rc = 1, fidx, i; + void *dv; + size_t A_bytes, itermax; + tpl_pound_data *pd; + + n = r; + dv = tpl_find_data_start(((tpl_root_data*)(r->data))->mmap.text); + + c = n->children; + while (c) { + switch (c->type) { + case TPL_TYPE_BYTE: + case TPL_TYPE_DOUBLE: + case TPL_TYPE_INT32: + case TPL_TYPE_UINT32: + case TPL_TYPE_INT64: + case TPL_TYPE_UINT64: + case TPL_TYPE_INT16: + case TPL_TYPE_UINT16: + for (fidx = 0; fidx < c->num; fidx++) + dv = (void*)((uintptr_t)dv + tpl_types[c->type].sz); + + break; + case TPL_TYPE_BIN: + memcpy(&slen, dv, sizeof(uint32_t)); + if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN) + tpl_byteswap(&slen, sizeof(uint32_t)); + dv = (void*)((uintptr_t)dv + sizeof(uint32_t)); + dv = (void*)((uintptr_t)dv + slen); + break; + case TPL_TYPE_STR: + for (i = 0; i < c->num; i++) { + memcpy(&slen, dv, sizeof(uint32_t)); + if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN) + tpl_byteswap(&slen, sizeof(uint32_t)); + if (((tpl_root_data*)(r->data))->flags & TPL_OLD_STRING_FMT) + slen += 1; + dv = (void*)((uintptr_t)dv + sizeof(uint32_t)); + if (slen > 1) dv = (void*)((uintptr_t)dv + slen-1); + } + break; + case TPL_TYPE_POUND: + /* iterate over the preceding nodes */ + itermax = c->num; + pd = (tpl_pound_data*)c->data; + if (++(pd->iternum) < itermax) { + c = pd->iter_start_node; + continue; + } else { /* loop complete. */ + pd->iternum = 0; + } + break; + case TPL_TYPE_ARY: + if (tpl_serlen(r, c, dv, &A_bytes) == -1) + tpl_hook.fatal("internal error in unpackA0\n"); + memcpy(&((tpl_atyp*)(c->data))->num, dv, sizeof(uint32_t)); + if (((tpl_root_data*)(r->data))->flags & TPL_XENDIAN) + tpl_byteswap(&((tpl_atyp*)(c->data))->num, sizeof(uint32_t)); + ((tpl_atyp*)(c->data))->cur = (void*)((uintptr_t)dv+sizeof(uint32_t)); + dv = (void*)((uintptr_t)dv + A_bytes); + break; + default: + tpl_hook.fatal("unsupported format character\n"); + break; + } + c = c->next; + } + return rc; } /* In-place byte order swapping of a word of length "len" bytes */ static void tpl_byteswap(void *word, int len) { - int i; - char c, *w; - w = (char*)word; - for (i = 0; i < len/2; i++) { - c = w[i]; - w[i] = w[len-1-i]; - w[len-1-i] = c; - } + int i; + char c, *w; + w = (char*)word; + for (i = 0; i < len/2; i++) { + c = w[i]; + w[i] = w[len-1-i]; + w[len-1-i] = c; + } } static void tpl_fatal(char *fmt, ...) { - va_list ap; - char exit_msg[100]; + va_list ap; + char exit_msg[100]; - va_start(ap, fmt); - vsnprintf(exit_msg, 100, fmt, ap); - va_end(ap); + va_start(ap, fmt); + vsnprintf(exit_msg, 100, fmt, ap); + va_end(ap); - tpl_hook.oops("%s", exit_msg); - exit(-1); + tpl_hook.oops("%s", exit_msg); + exit(-1); } TPL_API int tpl_gather(int mode, ...) { - va_list ap; - int fd, rc = 0; - size_t *szp, sz; - void **img, *addr, *data; - tpl_gather_t **gs; - tpl_gather_cb *cb; - - va_start(ap, mode); - switch (mode) { - case TPL_GATHER_BLOCKING: - fd = va_arg(ap, int); - img = va_arg(ap, void*); - szp = va_arg(ap, size_t*); - rc = tpl_gather_blocking(fd, img, szp); - break; - case TPL_GATHER_NONBLOCKING: - fd = va_arg(ap, int); - gs = (tpl_gather_t**)va_arg(ap, void*); - cb = (tpl_gather_cb*)va_arg(ap, tpl_gather_cb*); - data = va_arg(ap, void*); - rc = tpl_gather_nonblocking(fd, gs, cb, data); - break; - case TPL_GATHER_MEM: - addr = va_arg(ap, void*); - sz = va_arg(ap, size_t); - gs = (tpl_gather_t**)va_arg(ap, void*); - cb = (tpl_gather_cb*)va_arg(ap, tpl_gather_cb*); - data = va_arg(ap, void*); - rc = tpl_gather_mem(addr, sz, gs, cb, data); - break; - default: - tpl_hook.fatal("unsupported tpl_gather mode %d\n", mode); - break; - } - va_end(ap); - return rc; + va_list ap; + int fd, rc = 0; + size_t *szp, sz; + void **img, *addr, *data; + tpl_gather_t **gs; + tpl_gather_cb *cb; + + va_start(ap, mode); + switch (mode) { + case TPL_GATHER_BLOCKING: + fd = va_arg(ap, int); + img = va_arg(ap, void*); + szp = va_arg(ap, size_t*); + rc = tpl_gather_blocking(fd, img, szp); + break; + case TPL_GATHER_NONBLOCKING: + fd = va_arg(ap, int); + gs = (tpl_gather_t**)va_arg(ap, void*); + cb = (tpl_gather_cb*)va_arg(ap, tpl_gather_cb*); + data = va_arg(ap, void*); + rc = tpl_gather_nonblocking(fd, gs, cb, data); + break; + case TPL_GATHER_MEM: + addr = va_arg(ap, void*); + sz = va_arg(ap, size_t); + gs = (tpl_gather_t**)va_arg(ap, void*); + cb = (tpl_gather_cb*)va_arg(ap, tpl_gather_cb*); + data = va_arg(ap, void*); + rc = tpl_gather_mem(addr, sz, gs, cb, data); + break; + default: + tpl_hook.fatal("unsupported tpl_gather mode %d\n", mode); + break; + } + va_end(ap); + return rc; } /* dequeue a tpl by reading until one full tpl image is obtained. @@ -2254,263 +2250,262 @@ TPL_API int tpl_gather(int mode, ...) */ static int tpl_gather_blocking(int fd, void **img, size_t *sz) { - char preamble[8]; - int i = 0, rc; - uint32_t tpllen; - - do { - rc = read(fd, &preamble[i], 8-i); - i += (rc > 0) ? rc : 0; - } while ((rc == -1 && (errno == EINTR || errno == EAGAIN)) || (rc > 0 && i < 8)); - - if (rc < 0) { - tpl_hook.oops("tpl_gather_fd_blocking failed: %s\n", strerror(errno)); - return -1; - } else if (rc == 0) { - /* tpl_hook.oops("tpl_gather_fd_blocking: eof\n"); */ - return 0; - } else if (i != 8) { - tpl_hook.oops("internal error\n"); - return -1; - } - - if (preamble[0] == 't' && preamble[1] == 'p' && preamble[2] == 'l') { - memcpy(&tpllen, &preamble[4], 4); - if (tpl_needs_endian_swap(preamble)) tpl_byteswap(&tpllen, 4); - } else { - tpl_hook.oops("tpl_gather_fd_blocking: non-tpl input\n"); - return -1; - } - - /* malloc space for remainder of tpl image (overall length tpllen) - * and read it in - */ - if (tpl_hook.gather_max > 0 && - tpllen > tpl_hook.gather_max) { - tpl_hook.oops("tpl exceeds max length %d\n", - tpl_hook.gather_max); - return -2; - } - *sz = tpllen; - if ((*img = tpl_hook.malloc(tpllen)) == NULL) { - fatal_oom(); - } - - memcpy(*img, preamble, 8); /* copy preamble to output buffer */ - i = 8; - do { - rc = read(fd, &((*(char**)img)[i]), tpllen-i); - i += (rc > 0) ? rc : 0; - } while ((rc == -1 && (errno == EINTR || errno == EAGAIN)) || (rc > 0 && i < tpllen)); - - if (rc < 0) { - tpl_hook.oops("tpl_gather_fd_blocking failed: %s\n", strerror(errno)); - tpl_hook.free(*img); - return -1; - } else if (rc == 0) { - /* tpl_hook.oops("tpl_gather_fd_blocking: eof\n"); */ - tpl_hook.free(*img); - return 0; - } else if (i != tpllen) { - tpl_hook.oops("internal error\n"); - tpl_hook.free(*img); - return -1; - } - - return 1; + char preamble[8]; + int i = 0, rc; + uint32_t tpllen; + + do { + rc = read(fd, &preamble[i], 8-i); + i += (rc > 0) ? rc : 0; + } while ((rc == -1 && (errno == EINTR || errno == EAGAIN)) || (rc > 0 && i < 8)); + + if (rc < 0) { + tpl_hook.oops("tpl_gather_fd_blocking failed: %s\n", strerror(errno)); + return -1; + } else if (rc == 0) { + /* tpl_hook.oops("tpl_gather_fd_blocking: eof\n"); */ + return 0; + } else if (i != 8) { + tpl_hook.oops("internal error\n"); + return -1; + } + + if (preamble[0] == 't' && preamble[1] == 'p' && preamble[2] == 'l') { + memcpy(&tpllen, &preamble[4], 4); + if (tpl_needs_endian_swap(preamble)) tpl_byteswap(&tpllen, 4); + } else { + tpl_hook.oops("tpl_gather_fd_blocking: non-tpl input\n"); + return -1; + } + + /* malloc space for remainder of tpl image (overall length tpllen) + * and read it in + */ + if (tpl_hook.gather_max > 0 && + tpllen > tpl_hook.gather_max) { + tpl_hook.oops("tpl exceeds max length %d\n", + tpl_hook.gather_max); + return -2; + } + *sz = tpllen; + if ((*img = tpl_hook.malloc(tpllen)) == NULL) + fatal_oom(); + + memcpy(*img, preamble, 8); /* copy preamble to output buffer */ + i = 8; + do { + rc = read(fd, &((*(char**)img)[i]), tpllen-i); + i += (rc > 0) ? rc : 0; + } while ((rc == -1 && (errno == EINTR || errno == EAGAIN)) || (rc > 0 && i < tpllen)); + + if (rc < 0) { + tpl_hook.oops("tpl_gather_fd_blocking failed: %s\n", strerror(errno)); + tpl_hook.free(*img); + return -1; + } else if (rc == 0) { + /* tpl_hook.oops("tpl_gather_fd_blocking: eof\n"); */ + tpl_hook.free(*img); + return 0; + } else if (i != tpllen) { + tpl_hook.oops("internal error\n"); + tpl_hook.free(*img); + return -1; + } + + return 1; } /* Used by select()-driven apps which want to gather tpl images piecemeal */ /* the file descriptor must be non-blocking for this functino to work. */ static int tpl_gather_nonblocking(int fd, tpl_gather_t **gs, tpl_gather_cb *cb, void *data) { - char buf[TPL_GATHER_BUFLEN], *img, *tpl; - int rc, keep_looping, cbrc = 0; - size_t catlen; - uint32_t tpllen; - - while (1) { - rc = read(fd, buf, TPL_GATHER_BUFLEN); - if (rc == -1) { - if (errno == EINTR) continue; /* got signal during read, ignore */ - if (errno == EAGAIN) return 1; /* nothing to read right now */ - else { - tpl_hook.oops("tpl_gather failed: %s\n", strerror(errno)); - if (*gs) { - tpl_hook.free((*gs)->img); - tpl_hook.free(*gs); - *gs = NULL; - } - return -1; /* error, caller should close fd */ - } - } else if (rc == 0) { - if (*gs) { - tpl_hook.oops("tpl_gather: partial tpl image precedes EOF\n"); - tpl_hook.free((*gs)->img); - tpl_hook.free(*gs); - *gs = NULL; - } - return 0; /* EOF, caller should close fd */ - } else { - /* concatenate any partial tpl from last read with new buffer */ - if (*gs) { - catlen = (*gs)->len + rc; - if (tpl_hook.gather_max > 0 && - catlen > tpl_hook.gather_max) { - tpl_hook.free((*gs)->img); - tpl_hook.free((*gs)); - *gs = NULL; - tpl_hook.oops("tpl exceeds max length %d\n", - tpl_hook.gather_max); - return -2; /* error, caller should close fd */ - } - if ((img = tpl_hook.realloc((*gs)->img, catlen)) == NULL) { - fatal_oom(); - } - memcpy(img + (*gs)->len, buf, rc); - tpl_hook.free(*gs); - *gs = NULL; - } else { - img = buf; - catlen = rc; - } - /* isolate any full tpl(s) in img and invoke cb for each */ - tpl = img; - keep_looping = (tpl+8 < img+catlen) ? 1 : 0; - while (keep_looping) { - if (strncmp("tpl", tpl, 3) != 0) { - tpl_hook.oops("tpl prefix invalid\n"); - if (img != buf) tpl_hook.free(img); - tpl_hook.free(*gs); - *gs = NULL; - return -3; /* error, caller should close fd */ - } - memcpy(&tpllen, &tpl[4], 4); - if (tpl_needs_endian_swap(tpl)) tpl_byteswap(&tpllen, 4); - if (tpl+tpllen <= img+catlen) { - cbrc = (cb)(tpl, tpllen, data); /* invoke cb for tpl image */ - tpl += tpllen; /* point to next tpl image */ - if (cbrc < 0) keep_looping = 0; - else keep_looping = (tpl+8 < img+catlen) ? 1 : 0; - } else keep_looping = 0; - } - /* check if app callback requested closure of tpl source */ - if (cbrc < 0) { - tpl_hook.oops("tpl_fd_gather aborted by app callback\n"); - if (img != buf) tpl_hook.free(img); - if (*gs) tpl_hook.free(*gs); - *gs = NULL; - return -4; - } - /* store any leftover, partial tpl fragment for next read */ - if (tpl == img && img != buf) { - /* consumed nothing from img!= buf */ - if ((*gs = tpl_hook.malloc(sizeof(tpl_gather_t))) == NULL) { - fatal_oom(); - } - (*gs)->img = tpl; - (*gs)->len = catlen; - } else if (tpl < img+catlen) { - /* consumed 1+ tpl(s) from img!= buf or 0 from img == buf */ - if ((*gs = tpl_hook.malloc(sizeof(tpl_gather_t))) == NULL) { - fatal_oom(); - } - if (((*gs)->img = tpl_hook.malloc(img+catlen - tpl)) == NULL) { - fatal_oom(); - } - (*gs)->len = img+catlen - tpl; - memcpy((*gs)->img, tpl, img+catlen - tpl); - /* free partially consumed concat buffer if used */ - if (img != buf) tpl_hook.free(img); - } else { /* tpl(s) fully consumed */ - /* free consumed concat buffer if used */ - if (img != buf) tpl_hook.free(img); - } - } - } + char buf[TPL_GATHER_BUFLEN], *img, *tpl; + int rc, keep_looping, cbrc = 0; + size_t catlen; + uint32_t tpllen; + + while (1) { + rc = read(fd, buf, TPL_GATHER_BUFLEN); + if (rc == -1) { + if (errno == EINTR) continue; /* got signal during read, ignore */ + if (errno == EAGAIN) return 1; /* nothing to read right now */ + else { + tpl_hook.oops("tpl_gather failed: %s\n", strerror(errno)); + if (*gs) { + tpl_hook.free((*gs)->img); + tpl_hook.free(*gs); + *gs = NULL; + } + return -1; /* error, caller should close fd */ + } + } else if (rc == 0) { + if (*gs) { + tpl_hook.oops("tpl_gather: partial tpl image precedes EOF\n"); + tpl_hook.free((*gs)->img); + tpl_hook.free(*gs); + *gs = NULL; + } + return 0; /* EOF, caller should close fd */ + } else { + /* concatenate any partial tpl from last read with new buffer */ + if (*gs) { + catlen = (*gs)->len + rc; + if (tpl_hook.gather_max > 0 && + catlen > tpl_hook.gather_max) { + tpl_hook.free((*gs)->img); + tpl_hook.free((*gs)); + *gs = NULL; + tpl_hook.oops("tpl exceeds max length %d\n", + tpl_hook.gather_max); + return -2; /* error, caller should close fd */ + } + if ((img = tpl_hook.realloc((*gs)->img, catlen)) == NULL) + fatal_oom(); + + memcpy(img + (*gs)->len, buf, rc); + tpl_hook.free(*gs); + *gs = NULL; + } else { + img = buf; + catlen = rc; + } + /* isolate any full tpl(s) in img and invoke cb for each */ + tpl = img; + keep_looping = (tpl+8 < img+catlen) ? 1 : 0; + while (keep_looping) { + if (strncmp("tpl", tpl, 3) != 0) { + tpl_hook.oops("tpl prefix invalid\n"); + if (img != buf) tpl_hook.free(img); + tpl_hook.free(*gs); + *gs = NULL; + return -3; /* error, caller should close fd */ + } + memcpy(&tpllen, &tpl[4], 4); + if (tpl_needs_endian_swap(tpl)) tpl_byteswap(&tpllen, 4); + if (tpl+tpllen <= img+catlen) { + cbrc = (cb)(tpl, tpllen, data); /* invoke cb for tpl image */ + tpl += tpllen; /* point to next tpl image */ + if (cbrc < 0) keep_looping = 0; + else keep_looping = (tpl+8 < img+catlen) ? 1 : 0; + } else keep_looping = 0; + } + /* check if app callback requested closure of tpl source */ + if (cbrc < 0) { + tpl_hook.oops("tpl_fd_gather aborted by app callback\n"); + if (img != buf) tpl_hook.free(img); + if (*gs) tpl_hook.free(*gs); + *gs = NULL; + return -4; + } + /* store any leftover, partial tpl fragment for next read */ + if (tpl == img && img != buf) { + /* consumed nothing from img!= buf */ + if ((*gs = tpl_hook.malloc(sizeof(tpl_gather_t))) == NULL) + fatal_oom(); + + (*gs)->img = tpl; + (*gs)->len = catlen; + } else if (tpl < img+catlen) { + /* consumed 1+ tpl(s) from img!= buf or 0 from img == buf */ + if ((*gs = tpl_hook.malloc(sizeof(tpl_gather_t))) == NULL) + fatal_oom(); + + if (((*gs)->img = tpl_hook.malloc(img+catlen - tpl)) == NULL) + fatal_oom(); + + (*gs)->len = img+catlen - tpl; + memcpy((*gs)->img, tpl, img+catlen - tpl); + /* free partially consumed concat buffer if used */ + if (img != buf) tpl_hook.free(img); + } else { /* tpl(s) fully consumed */ + /* free consumed concat buffer if used */ + if (img != buf) tpl_hook.free(img); + } + } + } } /* gather tpl piecemeal from memory buffer (not fd) e.g., from a lower-level api */ static int tpl_gather_mem(char *buf, size_t len, tpl_gather_t **gs, tpl_gather_cb *cb, void *data) { - char *img, *tpl; - int keep_looping, cbrc = 0; - size_t catlen; - uint32_t tpllen; - - /* concatenate any partial tpl from last read with new buffer */ - if (*gs) { - catlen = (*gs)->len + len; - if (tpl_hook.gather_max > 0 && - catlen > tpl_hook.gather_max) { - tpl_hook.free((*gs)->img); - tpl_hook.free((*gs)); - *gs = NULL; - tpl_hook.oops("tpl exceeds max length %d\n", - tpl_hook.gather_max); - return -2; /* error, caller should stop accepting input from source*/ - } - if ((img = tpl_hook.realloc((*gs)->img, catlen)) == NULL) { - fatal_oom(); - } - memcpy(img + (*gs)->len, buf, len); - tpl_hook.free(*gs); - *gs = NULL; - } else { - img = buf; - catlen = len; - } - /* isolate any full tpl(s) in img and invoke cb for each */ - tpl = img; - keep_looping = (tpl+8 < img+catlen) ? 1 : 0; - while (keep_looping) { - if (strncmp("tpl", tpl, 3) != 0) { - tpl_hook.oops("tpl prefix invalid\n"); - if (img != buf) tpl_hook.free(img); - tpl_hook.free(*gs); - *gs = NULL; - return -3; /* error, caller should stop accepting input from source*/ - } - memcpy(&tpllen, &tpl[4], 4); - if (tpl_needs_endian_swap(tpl)) tpl_byteswap(&tpllen, 4); - if (tpl+tpllen <= img+catlen) { - cbrc = (cb)(tpl, tpllen, data); /* invoke cb for tpl image */ - tpl += tpllen; /* point to next tpl image */ - if (cbrc < 0) keep_looping = 0; - else keep_looping = (tpl+8 < img+catlen) ? 1 : 0; - } else keep_looping = 0; - } - /* check if app callback requested closure of tpl source */ - if (cbrc < 0) { - tpl_hook.oops("tpl_mem_gather aborted by app callback\n"); - if (img != buf) tpl_hook.free(img); - if (*gs) tpl_hook.free(*gs); - *gs = NULL; - return -4; - } - /* store any leftover, partial tpl fragment for next read */ - if (tpl == img && img != buf) { - /* consumed nothing from img!= buf */ - if ((*gs = tpl_hook.malloc(sizeof(tpl_gather_t))) == NULL) { - fatal_oom(); - } - (*gs)->img = tpl; - (*gs)->len = catlen; - } else if (tpl < img+catlen) { - /* consumed 1+ tpl(s) from img!= buf or 0 from img == buf */ - if ((*gs = tpl_hook.malloc(sizeof(tpl_gather_t))) == NULL) { - fatal_oom(); - } - if (((*gs)->img = tpl_hook.malloc(img+catlen - tpl)) == NULL) { - fatal_oom(); - } - (*gs)->len = img+catlen - tpl; - memcpy((*gs)->img, tpl, img+catlen - tpl); - /* free partially consumed concat buffer if used */ - if (img != buf) tpl_hook.free(img); - } else { /* tpl(s) fully consumed */ - /* free consumed concat buffer if used */ - if (img != buf) tpl_hook.free(img); - } - return 1; + char *img, *tpl; + int keep_looping, cbrc = 0; + size_t catlen; + uint32_t tpllen; + + /* concatenate any partial tpl from last read with new buffer */ + if (*gs) { + catlen = (*gs)->len + len; + if (tpl_hook.gather_max > 0 && + catlen > tpl_hook.gather_max) { + tpl_hook.free((*gs)->img); + tpl_hook.free((*gs)); + *gs = NULL; + tpl_hook.oops("tpl exceeds max length %d\n", + tpl_hook.gather_max); + return -2; /* error, caller should stop accepting input from source*/ + } + if ((img = tpl_hook.realloc((*gs)->img, catlen)) == NULL) + fatal_oom(); + + memcpy(img + (*gs)->len, buf, len); + tpl_hook.free(*gs); + *gs = NULL; + } else { + img = buf; + catlen = len; + } + /* isolate any full tpl(s) in img and invoke cb for each */ + tpl = img; + keep_looping = (tpl+8 < img+catlen) ? 1 : 0; + while (keep_looping) { + if (strncmp("tpl", tpl, 3) != 0) { + tpl_hook.oops("tpl prefix invalid\n"); + if (img != buf) tpl_hook.free(img); + tpl_hook.free(*gs); + *gs = NULL; + return -3; /* error, caller should stop accepting input from source*/ + } + memcpy(&tpllen, &tpl[4], 4); + if (tpl_needs_endian_swap(tpl)) tpl_byteswap(&tpllen, 4); + if (tpl+tpllen <= img+catlen) { + cbrc = (cb)(tpl, tpllen, data); /* invoke cb for tpl image */ + tpl += tpllen; /* point to next tpl image */ + if (cbrc < 0) keep_looping = 0; + else keep_looping = (tpl+8 < img+catlen) ? 1 : 0; + } else keep_looping = 0; + } + /* check if app callback requested closure of tpl source */ + if (cbrc < 0) { + tpl_hook.oops("tpl_mem_gather aborted by app callback\n"); + if (img != buf) tpl_hook.free(img); + if (*gs) tpl_hook.free(*gs); + *gs = NULL; + return -4; + } + /* store any leftover, partial tpl fragment for next read */ + if (tpl == img && img != buf) { + /* consumed nothing from img!= buf */ + if ((*gs = tpl_hook.malloc(sizeof(tpl_gather_t))) == NULL) + fatal_oom(); + + (*gs)->img = tpl; + (*gs)->len = catlen; + } else if (tpl < img+catlen) { + /* consumed 1+ tpl(s) from img!= buf or 0 from img == buf */ + if ((*gs = tpl_hook.malloc(sizeof(tpl_gather_t))) == NULL) + fatal_oom(); + + if (((*gs)->img = tpl_hook.malloc(img+catlen - tpl)) == NULL) + fatal_oom(); + + (*gs)->len = img+catlen - tpl; + memcpy((*gs)->img, tpl, img+catlen - tpl); + /* free partially consumed concat buffer if used */ + if (img != buf) tpl_hook.free(img); + } else { /* tpl(s) fully consumed */ + /* free consumed concat buffer if used */ + if (img != buf) tpl_hook.free(img); + } + return 1; } diff --git a/email-core/email-core-cert.c b/email-core/email-core-cert.c index 137b0bb..df32dc1 100755 --- a/email-core/email-core-cert.c +++ b/email-core/email-core-cert.c @@ -57,7 +57,7 @@ typedef enum { CERT_TYPE_P7S } cert_type; -INTERNAL_FUNC int emcore_load_PFX_file(char *certificate, EVP_PKEY **pri_key, X509 **cert, +INTERNAL_FUNC int emcore_load_PFX_file(char *certificate, EVP_PKEY **pri_key, X509 **cert, STACK_OF(X509) **ca, int *err_code) { EM_DEBUG_FUNC_BEGIN_SEC("certificate : [%s]", certificate); @@ -114,6 +114,8 @@ INTERNAL_FUNC int emcore_load_PFX_file(char *certificate, EVP_PKEY **pri_key, X5 &length) != CERTSVC_SUCCESS) { EM_DEBUG_EXCEPTION("certsvc_string_new failed : [%d]", err); err = EMAIL_ERROR_LOAD_CERTIFICATE_FAILURE; + if (certList) + certsvc_pkcs12_free_certificate_list_loaded_from_store(cert_instance, &certList); goto FINISH_OFF; } @@ -238,7 +240,6 @@ FINISH_OFF: free(alias); certsvc_instance_free(cert_instance); - free(certList); return ret; } diff --git a/email-core/email-core-mailbox-sync.c b/email-core/email-core-mailbox-sync.c index 0aaf05c..2aa22d6 100755 --- a/email-core/email-core-mailbox-sync.c +++ b/email-core/email-core-mailbox-sync.c @@ -1,23 +1,23 @@ /* -* email-service -* -* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. -* -* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* -*/ + * email-service + * + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ /****************************************************************************** @@ -82,22 +82,22 @@ static struct { const char *tm_zone; } known_zone_charset[] = { {"euc-kr", "kst"}, - {"euc-jp", "jst"} + {"euc-jp", "jst"} #if 0 - {"Big5", "zh" }, - {"BIG5HKSCS", "zh" }, - {"gb2312", "zh" }, - {"gb18030", "zh" }, - {"gbk", "zh" }, - {"euc-tw", "zh" }, - {"iso-2022-jp", "ja" }, - {"Shift-JIS", "ja" }, - {"sjis", "ja" }, - {"ujis", "ja" }, - {"eucJP", "ja" }, - {"euc-kr", "ko" }, - {"koi8-r", "ru" }, - {"koi8-u", "uk" } + {"Big5", "zh" }, + {"BIG5HKSCS", "zh" }, + {"gb2312", "zh" }, + {"gb18030", "zh" }, + {"gbk", "zh" }, + {"euc-tw", "zh" }, + {"iso-2022-jp", "ja" }, + {"Shift-JIS", "ja" }, + {"sjis", "ja" }, + {"ujis", "ja" }, + {"eucJP", "ja" }, + {"euc-kr", "ko" }, + {"koi8-r", "ru" }, + {"koi8-u", "uk" } #endif }; @@ -689,7 +689,7 @@ FINISH_OFF: emcore_free_uids(uid_list_for_listing, NULL); EM_SAFE_FREE(response); - EM_SAFE_FREE(uid_range_string); + EM_SAFE_FREE(uid_range_string); EM_PROFILE_END(emcore_get_uids_order_by_datetime_from_imap_server); EM_DEBUG_FUNC_END("err [%d]", err); @@ -732,7 +732,7 @@ int imap4_mailbox_get_uids_by_timestamp(MAILSTREAM *stream, emcore_uid_list** ui } /* Fetch the System time and Retrieve the a Week before time */ - /* tzset(); */ + /* tzset(); */ time(&RawTime); EM_DEBUG_LOG("RawTime Info [%lu]", RawTime); @@ -812,11 +812,11 @@ int imap4_mailbox_get_uids_by_timestamp(MAILSTREAM *stream, emcore_uid_list** ui } if ((p = strstr(response, " SEARCH "))) { - *p = '\0'; p += strlen(" SEARCH "); + *p = '\0'; p += strlen(" SEARCH "); - result = strtok_r(p, delims, &ptr); + result = strtok_r(p, delims, &ptr); - while (result != NULL) { + while (result != NULL) { EM_DEBUG_LOG("UID VALUE DEEP is [%s]", result); if (!(uid_elem = em_malloc(sizeof(emcore_uid_list)))) { @@ -831,10 +831,10 @@ int imap4_mailbox_get_uids_by_timestamp(MAILSTREAM *stream, emcore_uid_list** ui uid_elem->next = *uid_list; *uid_list = uid_elem; result = strtok_r(NULL, delims, &ptr); - } + } EM_SAFE_FREE(response); - return 1; + return 1; } else { err = EMAIL_ERROR_INVALID_RESPONSE; goto FINISH_OFF; @@ -1157,18 +1157,18 @@ static gint emcore_compare_uid_elem(gconstpointer a, gconstpointer b) } static int emcore_get_uids_to_download(char *multi_user_name, - MAILSTREAM *stream, - email_account_t *account, - emstorage_mailbox_tbl_t *input_mailbox_tbl, - int limit_count, - emcore_uid_list** uid_list, - int *uids, - int retrieve_mode, - int *err_code) + MAILSTREAM *stream, + email_account_t *account, + emstorage_mailbox_tbl_t *input_mailbox_tbl, + int limit_count, + emcore_uid_list** uid_list, + int *uids, + int retrieve_mode, + int *err_code) { EM_PROFILE_BEGIN(emCoreGetUidsDownload); EM_DEBUG_FUNC_BEGIN("account[%p], input_mailbox_tbl[%p], limit_count[%d], uid_list[%p], err_code[%p]", - account, input_mailbox_tbl, limit_count, uid_list, err_code); + account, input_mailbox_tbl, limit_count, uid_list, err_code); int ret = false; int err = EMAIL_ERROR_NONE; @@ -1202,8 +1202,8 @@ static int emcore_get_uids_to_download(char *multi_user_name, EM_DEBUG_LOG("nmsgs[%d]", ((MAILSTREAM *)stream)->nmsgs); if ((limit_count < ((MAILSTREAM *)stream)->nmsgs)) { if ((err = emcore_get_uids_order_by_datetime_from_imap_server(stream, - limit_count, - uid_list)) != EMAIL_ERROR_NONE) { + limit_count, + uid_list)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_get_uids_order_by_datetime_from_imap_server failed [%d]", err); if (err != EMAIL_ERROR_MAIL_NOT_FOUND_ON_SERVER) goto FINISH_OFF; @@ -1220,13 +1220,13 @@ static int emcore_get_uids_to_download(char *multi_user_name, /* After syncing, if there is moving request, inbox syncing do */ /* So checking all downloaded mail */ if (!emstorage_get_downloaded_list(multi_user_name, - input_mailbox_tbl->account_id, - (account->incoming_server_type == EMAIL_SERVER_TYPE_POP3) ? - 0 : input_mailbox_tbl->mailbox_id, - &downloaded_uids, - &downloaded_uid_count, - true, - &err)) { + input_mailbox_tbl->account_id, + (account->incoming_server_type == EMAIL_SERVER_TYPE_POP3) ? + 0 : input_mailbox_tbl->mailbox_id, + &downloaded_uids, + &downloaded_uid_count, + true, + &err)) { EM_DEBUG_EXCEPTION("emstorage_get_downloaded_list failed [%d]", err); goto FINISH_OFF; } @@ -1317,34 +1317,34 @@ static int emcore_get_uids_to_download(char *multi_user_name, } if (!emstorage_get_mail_by_id(multi_user_name, - downloaded_uids[i-1].local_uid, - &mail, - false, - &err)) { + downloaded_uids[i-1].local_uid, + &mail, + false, + &err)) { EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed : [%d]", err); continue; } if (mail->flags_answered_field != uid_elem->flag.answered) { if (!emcore_set_flags_field(multi_user_name, - downloaded_uids[i-1].account_id, - &(downloaded_uids[i-1].local_uid), - 1, - EMAIL_FLAGS_ANSWERED_FIELD, - uid_elem->flag.answered, - &err)) { + downloaded_uids[i-1].account_id, + &(downloaded_uids[i-1].local_uid), + 1, + EMAIL_FLAGS_ANSWERED_FIELD, + uid_elem->flag.answered, + &err)) { EM_DEBUG_EXCEPTION("emcore_set_flags_field failed : [%d]", err); } } if (mail->flags_forwarded_field != uid_elem->flag.forwarded) { if (!emcore_set_flags_field(multi_user_name, - downloaded_uids[i-1].account_id, - &(downloaded_uids[i-1].local_uid), - 1, - EMAIL_FLAGS_FORWARDED_FIELD, - uid_elem->flag.forwarded, - &err)) { + downloaded_uids[i-1].account_id, + &(downloaded_uids[i-1].local_uid), + 1, + EMAIL_FLAGS_FORWARDED_FIELD, + uid_elem->flag.forwarded, + &err)) { EM_DEBUG_EXCEPTION("emcore_set_flags_field failed : [%d]", err); } } @@ -1372,7 +1372,7 @@ static int emcore_get_uids_to_download(char *multi_user_name, head_uid_elem = uid_elem; end = head_uid_elem; } else { - end->next = uid_elem; + end->next = uid_elem; uid_elem->next = NULL; end = uid_elem; } @@ -1392,28 +1392,28 @@ static int emcore_get_uids_to_download(char *multi_user_name, for (i = 0; i < downloaded_uid_count; i++) { if ((downloaded_uids[i].sync_status == EMAIL_SYNC_STATUS_NOT_EXIST_ON_SERVER) && - (EM_SAFE_STRCMP(downloaded_uids[i].mailbox_name, EMAIL_SEARCH_RESULT_MAILBOX_NAME) != 0)) { + (EM_SAFE_STRCMP(downloaded_uids[i].mailbox_name, EMAIL_SEARCH_RESULT_MAILBOX_NAME) != 0)) { /* deleted on server */ if (!emstorage_get_maildata_by_servermailid(multi_user_name, - downloaded_uids[i].server_uid, - input_mailbox_tbl->mailbox_id, - &mail, - true, - &err)) { + downloaded_uids[i].server_uid, + input_mailbox_tbl->mailbox_id, + &mail, + true, + &err)) { EM_DEBUG_EXCEPTION("emstorage_get_maildata_by_servermailid for uid[%s] Failed [%d] \n ", - downloaded_uids[i].server_uid, err); + downloaded_uids[i].server_uid, err); if (err == EMAIL_ERROR_MAIL_NOT_FOUND) { continue; } } ret = emcore_delete_mails_from_local_storage(multi_user_name, - input_mailbox_tbl->account_id, - &(mail->mail_id), - 1, - EMAIL_DELETED_FROM_SERVER, - false, - &err); + input_mailbox_tbl->account_id, + &(mail->mail_id), + 1, + EMAIL_DELETED_FROM_SERVER, + false, + &err); if (!ret) { EM_DEBUG_EXCEPTION("emcore_delete_mails_from_local_storage falied - %d", err); goto FINISH_OFF; @@ -1425,22 +1425,22 @@ static int emcore_get_uids_to_download(char *multi_user_name, /* set seen flag of downloaded mail */ if (downloaded_uids[i].sync_status == EMAIL_SYNC_STATUS_FLAG_CHANGED) { if (!emcore_set_flags_field(multi_user_name, - downloaded_uids[i].account_id, - &(downloaded_uids[i].local_uid), - 1, - EMAIL_FLAGS_FLAGGED_FIELD, - downloaded_uids[i].flags_flagged_field, - &err)) { + downloaded_uids[i].account_id, + &(downloaded_uids[i].local_uid), + 1, + EMAIL_FLAGS_FLAGGED_FIELD, + downloaded_uids[i].flags_flagged_field, + &err)) { EM_DEBUG_EXCEPTION("emcore_set_flags_field failed [%d]", err); } if (!emcore_set_flags_field(multi_user_name, - downloaded_uids[i].account_id, - &(downloaded_uids[i].local_uid), - 1, - EMAIL_FLAGS_SEEN_FIELD, - downloaded_uids[i].flags_seen_field, - &err)) { + downloaded_uids[i].account_id, + &(downloaded_uids[i].local_uid), + 1, + EMAIL_FLAGS_SEEN_FIELD, + downloaded_uids[i].flags_seen_field, + &err)) { EM_DEBUG_EXCEPTION("emcore_set_flags_field failed [%d]", err); } else emcore_display_unread_in_badge(multi_user_name); @@ -1480,13 +1480,13 @@ FINISH_OFF: /* insert received mail UID to read mail uid table */ static int emcore_add_read_mail_uid(char *multi_user_name, - emstorage_mailbox_tbl_t *input_maibox_data, - char *server_mailbox_name, - int mail_id, - char *uid, - int rfc822_size, - int rule_id, - int *err_code) + emstorage_mailbox_tbl_t *input_maibox_data, + char *server_mailbox_name, + int mail_id, + char *uid, + int rfc822_size, + int rule_id, + int *err_code) { EM_DEBUG_FUNC_BEGIN_SEC("input_maibox_data[%p], server_mailbox_name[%s], uid[%s], rfc822_size[%d], rule_id[%d], err_code[%p]", input_maibox_data, server_mailbox_name, uid, rfc822_size, rule_id, err_code); @@ -1505,11 +1505,11 @@ static int emcore_add_read_mail_uid(char *multi_user_name, read_mail_uid.account_id = input_maibox_data->account_id; if (!(input_maibox_data->mailbox_id) || !(server_mailbox_name)) { if (!emstorage_get_mailbox_by_mailbox_type(multi_user_name, - input_maibox_data->account_id, - EMAIL_MAILBOX_TYPE_INBOX, - &mailbox_tbl, - false, - &err)) { + input_maibox_data->account_id, + EMAIL_MAILBOX_TYPE_INBOX, + &mailbox_tbl, + false, + &err)) { EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_mailbox_type failed [%d]", err); goto FINISH_OFF; } @@ -1594,14 +1594,14 @@ FINISH_OFF: #endif INTERNAL_FUNC int emcore_add_mail_to_mailbox(char *multi_user_name, - emstorage_mailbox_tbl_t *input_maibox_data, - emstorage_mail_tbl_t *input_new_mail_tbl_data, - int *output_mail_id, - int *output_thread_id) + emstorage_mailbox_tbl_t *input_maibox_data, + emstorage_mail_tbl_t *input_new_mail_tbl_data, + int *output_mail_id, + int *output_thread_id) { EM_DEBUG_FUNC_BEGIN("input_maibox_data[%p], input_new_mail_tbl_data[%p], " - "uid_elem[%p], output_mail_id[%p], output_thread_id[%p]", mail_stream, input_maibox_data, - input_new_mail_tbl_data, output_mail_id, output_thread_id); + "uid_elem[%p], output_mail_id[%p], output_thread_id[%p]", mail_stream, input_maibox_data, + input_new_mail_tbl_data, output_mail_id, output_thread_id); int err = EMAIL_ERROR_NONE; int thread_id = -1; @@ -1633,10 +1633,10 @@ INTERNAL_FUNC int emcore_add_mail_to_mailbox(char *multi_user_name, } err = emstorage_get_thread_id_of_thread_mails(multi_user_name, - input_new_mail_tbl_data, - &thread_id, - &latest_mail_id_in_thread, - &thread_item_count); + input_new_mail_tbl_data, + &thread_id, + &latest_mail_id_in_thread, + &thread_item_count); if (err != EMAIL_ERROR_NONE) EM_DEBUG_LOG(" emstorage_get_thread_id_of_thread_mails is failed."); @@ -1659,32 +1659,32 @@ INTERNAL_FUNC int emcore_add_mail_to_mailbox(char *multi_user_name, if (thread_item_count > 1) { if (!emstorage_update_latest_thread_mail(multi_user_name, - input_new_mail_tbl_data->account_id, - input_new_mail_tbl_data->mailbox_id, - input_new_mail_tbl_data->mailbox_type, - input_new_mail_tbl_data->thread_id, - NULL, - -1, - -1, - NOTI_THREAD_ID_CHANGED_BY_ADD, - false, - &err)) { + input_new_mail_tbl_data->account_id, + input_new_mail_tbl_data->mailbox_id, + input_new_mail_tbl_data->mailbox_type, + input_new_mail_tbl_data->thread_id, + NULL, + -1, + -1, + NOTI_THREAD_ID_CHANGED_BY_ADD, + false, + &err)) { EM_DEBUG_EXCEPTION("emstorage_update_latest_thread_mail failed [%d]", err); emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL); goto FINISH_OFF; } if (!emstorage_update_latest_thread_mail(multi_user_name, - input_new_mail_tbl_data->account_id, - input_new_mail_tbl_data->mailbox_id, - input_new_mail_tbl_data->mailbox_type, - input_new_mail_tbl_data->thread_id, - NULL, - 0, - 0, - NOTI_THREAD_ID_CHANGED_BY_ADD, - false, - &err)) { + input_new_mail_tbl_data->account_id, + input_new_mail_tbl_data->mailbox_id, + input_new_mail_tbl_data->mailbox_type, + input_new_mail_tbl_data->thread_id, + NULL, + 0, + 0, + NOTI_THREAD_ID_CHANGED_BY_ADD, + false, + &err)) { EM_DEBUG_EXCEPTION("emstorage_update_latest_thread_mail failed [%d]", err); emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL); goto FINISH_OFF; @@ -1692,10 +1692,10 @@ INTERNAL_FUNC int emcore_add_mail_to_mailbox(char *multi_user_name, } if (emstorage_get_thread_id_of_thread_mails(multi_user_name, - input_new_mail_tbl_data, - &thread_id, - &latest_mail_id_in_thread, - &thread_item_count) != EMAIL_ERROR_NONE) + input_new_mail_tbl_data, + &thread_id, + &latest_mail_id_in_thread, + &thread_item_count) != EMAIL_ERROR_NONE) EM_DEBUG_LOG(" emstorage_get_thread_id_of_thread_mails is failed."); if (output_thread_id) @@ -1705,13 +1705,13 @@ INTERNAL_FUNC int emcore_add_mail_to_mailbox(char *multi_user_name, *output_mail_id = input_new_mail_tbl_data->mail_id; if (!emcore_add_read_mail_uid(multi_user_name, - input_maibox_data, - input_maibox_data->mailbox_name, - input_new_mail_tbl_data->mail_id, - input_new_mail_tbl_data->server_mail_id, - input_new_mail_tbl_data->mail_size, - 0, - &err)) { + input_maibox_data, + input_maibox_data->mailbox_name, + input_new_mail_tbl_data->mail_id, + input_new_mail_tbl_data->server_mail_id, + input_new_mail_tbl_data->mail_size, + 0, + &err)) { EM_DEBUG_EXCEPTION("emcore_add_read_mail_uid failed [%d]", err); emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL); goto FINISH_OFF; @@ -1766,7 +1766,7 @@ int emcore_check_rule(const char *input_full_address_from, const char *input_sub len = EM_SAFE_STRLEN(addr->mailbox); if (addr->host) len += EM_SAFE_STRLEN(addr->host); - len += 2; + len += 2; if (!(from_address = em_malloc(len))) { EM_DEBUG_EXCEPTION("em_mallocfailed..."); @@ -1864,16 +1864,16 @@ FINISH_OFF: } INTERNAL_FUNC int emcore_make_mail_tbl_data_from_envelope(char *multi_user_name, - int account_id, - MAILSTREAM *mail_stream, - ENVELOPE *input_envelope, - emcore_uid_list *input_uid_elem, - emstorage_mail_tbl_t **output_mail_tbl_data, - int *err_code) + int account_id, + MAILSTREAM *mail_stream, + ENVELOPE *input_envelope, + emcore_uid_list *input_uid_elem, + emstorage_mail_tbl_t **output_mail_tbl_data, + int *err_code) { EM_PROFILE_BEGIN(emCoreParseEnvelope); EM_DEBUG_FUNC_BEGIN("input_envelope[%p], input_uid_elem [%p], output_mail_tbl_data[%p], err_code[%p]", - input_envelope, input_uid_elem, output_mail_tbl_data, err_code); + input_envelope, input_uid_elem, output_mail_tbl_data, err_code); int zone_hour = 0; int ret = false; @@ -2085,20 +2085,20 @@ FINISH_OFF: } INTERNAL_FUNC int emcore_sync_header(char *multi_user_name, - emstorage_mailbox_tbl_t *input_mailbox_tbl, - void **stream, - emcore_uid_list **input_uid_list, - int *mail_count, - int *unread_mail, - int *vip_mail_count, - int *vip_unread_mail, - int cancellable, /*0: excluding event thd*/ - int event_handle, - int *err_code) + emstorage_mailbox_tbl_t *input_mailbox_tbl, + void **stream, + emcore_uid_list **input_uid_list, + int *mail_count, + int *unread_mail, + int *vip_mail_count, + int *vip_unread_mail, + int cancellable, /*0: excluding event thd*/ + int event_handle, + int *err_code) { EM_PROFILE_BEGIN(emCoreSyncHeader); EM_DEBUG_FUNC_BEGIN("input_mailbox_tbl[%p], input_uid_list [%p], err_code[%p]", - input_mailbox_tbl, input_uid_list, err_code); + input_mailbox_tbl, input_uid_list, err_code); if (!stream) { EM_DEBUG_EXCEPTION("NULL stream"); @@ -2154,8 +2154,8 @@ INTERNAL_FUNC int emcore_sync_header(char *multi_user_name, } } else { EM_DEBUG_EXCEPTION("because mailbox_name[%s] mailbox_type[%d] of account[%d] is " - "a local box, it cant be synced", - input_mailbox_tbl->mailbox_name, input_mailbox_tbl->mailbox_type, account_id); + "a local box, it cant be synced", + input_mailbox_tbl->mailbox_name, input_mailbox_tbl->mailbox_type, account_id); err = EMAIL_ERROR_INVALID_MAILBOX; goto FINISH_OFF; } @@ -2173,11 +2173,11 @@ INTERNAL_FUNC int emcore_sync_header(char *multi_user_name, #endif /* __FEATURE_SUPPORT_SYNC_STATE_ON_NOTI_BAR__ */ if (!emcore_connect_to_remote_mailbox(multi_user_name, - account_id, - input_mailbox_tbl->mailbox_id, - true, - (void **)stream, - &err) || !*stream) { + account_id, + input_mailbox_tbl->mailbox_id, + true, + (void **)stream, + &err) || !*stream) { EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed - %d", err); goto FINISH_OFF; } @@ -2207,11 +2207,11 @@ INTERNAL_FUNC int emcore_sync_header(char *multi_user_name, /* save total mail count on server to DB */ if (!emstorage_update_mailbox_total_count(multi_user_name, - account_id, - input_mailbox_tbl->mailbox_id, - ((MAILSTREAM *)*stream)->nmsgs, - 1, - &err)) { + account_id, + input_mailbox_tbl->mailbox_id, + ((MAILSTREAM *)*stream)->nmsgs, + 1, + &err)) { EM_DEBUG_EXCEPTION("emstorage_update_mailbox_total_count failed [%d]", err); goto FINISH_OFF; } @@ -2229,14 +2229,14 @@ INTERNAL_FUNC int emcore_sync_header(char *multi_user_name, type = EMAIL_FILTER_FROM; if (!emstorage_get_rule(multi_user_name, - ALL_ACCOUNT, - type, - 0, - &rule_count, - &is_completed, - &rule, - true, - &err) || !rule) { + ALL_ACCOUNT, + type, + 0, + &rule_count, + &is_completed, + &rule, + true, + &err) || !rule) { if (err != EMAIL_ERROR_FILTER_NOT_FOUND) EM_DEBUG_EXCEPTION("emstorage_get_rule error [%d]", err); } @@ -2244,14 +2244,14 @@ INTERNAL_FUNC int emcore_sync_header(char *multi_user_name, download_limit_count = input_mailbox_tbl->mail_slot_size; if (!emcore_get_uids_to_download(multi_user_name, - *stream, - account_ref, - input_mailbox_tbl, - download_limit_count, - &uid_list, - &total, - EMAIL_SYNC_LATEST_MAILS_FIRST, - &err)) { + *stream, + account_ref, + input_mailbox_tbl, + download_limit_count, + &uid_list, + &total, + EMAIL_SYNC_LATEST_MAILS_FIRST, + &err)) { EM_DEBUG_EXCEPTION("emcore_get_uids_to_download failed [%d]", err); goto FINISH_OFF; } @@ -2333,7 +2333,7 @@ INTERNAL_FUNC int emcore_sync_header(char *multi_user_name, int priority_sender = false; if (!emcore_make_mail_tbl_data_from_envelope(multi_user_name, account_id, *stream, env, uid_elem, - &new_mail_tbl_data, &err) || !new_mail_tbl_data) { + &new_mail_tbl_data, &err) || !new_mail_tbl_data) { EM_DEBUG_EXCEPTION("emcore_make_mail_tbl_data_from_envelope failed [%d]", err); goto CONTINUE_NEXT; } @@ -2349,15 +2349,15 @@ INTERNAL_FUNC int emcore_sync_header(char *multi_user_name, EM_DEBUG_LOG("Existed the duplicated mail : message_id[%s]", new_mail_tbl_data->message_id); if (!emcore_add_read_mail_uid(multi_user_name, input_mailbox_tbl, - input_mailbox_tbl->mailbox_name, searched_mail_id, - new_mail_tbl_data->server_mail_id, new_mail_tbl_data->mail_size, - 0, &err)) { + input_mailbox_tbl->mailbox_name, searched_mail_id, + new_mail_tbl_data->server_mail_id, new_mail_tbl_data->mail_size, + 0, &err)) { EM_DEBUG_EXCEPTION("emcore_add_read_mail_uid failed : [%d]", err); goto CONTINUE_NEXT; } if (!emstorage_change_mail_field(multi_user_name, searched_mail_id, UPDATE_DATETIME, - new_mail_tbl_data, true, &err)) { + new_mail_tbl_data, true, &err)) { EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed : [%d]", err); goto CONTINUE_NEXT; } @@ -2366,12 +2366,12 @@ INTERNAL_FUNC int emcore_sync_header(char *multi_user_name, } if (rule && !emcore_check_rule(new_mail_tbl_data->full_address_from, - new_mail_tbl_data->subject, - rule, - rule_count, - &priority_sender, - &blocked, - &err)) { + new_mail_tbl_data->subject, + rule, + rule_count, + &priority_sender, + &blocked, + &err)) { EM_DEBUG_EXCEPTION("emcore_check_rule failed [%d]", err); } @@ -2387,11 +2387,11 @@ INTERNAL_FUNC int emcore_sync_header(char *multi_user_name, if (input_mailbox_tbl->mailbox_type != EMAIL_MAILBOX_TYPE_SPAMBOX) { EM_DEBUG_LOG("This mail would be added to spambox"); if (!emstorage_get_mailbox_by_mailbox_type(multi_user_name, - account_id, - EMAIL_MAILBOX_TYPE_SPAMBOX, - &destination_mailbox, - false, - &err)) { + account_id, + EMAIL_MAILBOX_TYPE_SPAMBOX, + &destination_mailbox, + false, + &err)) { EM_DEBUG_LOG("emstorage_get_mailbox_by_mailbox_type failed [%d]", err); } } else @@ -2403,20 +2403,20 @@ INTERNAL_FUNC int emcore_sync_header(char *multi_user_name, if (destination_mailbox) { if (destination_mailbox->local_yn == 0 || - account_ref->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) { + account_ref->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) { err = emcore_move_mail_on_server_by_server_mail_id((void*)*stream, - new_mail_tbl_data->server_mail_id, - destination_mailbox->mailbox_name); + new_mail_tbl_data->server_mail_id, + destination_mailbox->mailbox_name); if (err != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_move_mail_on_server_by_server_mail_id falied [%d]", err); goto CONTINUE_NEXT; } } else { /* local mailbox */ if ((err = emcore_add_mail_to_mailbox(multi_user_name, - destination_mailbox, - new_mail_tbl_data, - &mail_id, - &thread_id)) != EMAIL_ERROR_NONE) { + destination_mailbox, + new_mail_tbl_data, + &mail_id, + &thread_id)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_add_mail_to_mailbox falied [%d]", err); goto CONTINUE_NEXT; } @@ -2427,10 +2427,10 @@ INTERNAL_FUNC int emcore_sync_header(char *multi_user_name, /* add mails to specified mail box */ EM_DEBUG_LOG_SEC("mail[%d] moved to input_mailbox_tbl [%s]", mail_id, input_mailbox_tbl->mailbox_name); if ((err = emcore_add_mail_to_mailbox(multi_user_name, - input_mailbox_tbl, - new_mail_tbl_data, - &mail_id, - &thread_id)) != EMAIL_ERROR_NONE) { + input_mailbox_tbl, + new_mail_tbl_data, + &mail_id, + &thread_id)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_add_mail_to_mailbox falied [%d]", err); goto CONTINUE_NEXT; } @@ -2439,13 +2439,13 @@ INTERNAL_FUNC int emcore_sync_header(char *multi_user_name, if (account_ref->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) { #endif /* __FEATURE_PARTIAL_BODY_FOR_POP3__ */ if (false == emcore_initiate_pbd(multi_user_name, - *stream, - account_id, - mail_id, - uid_elem->uid, - input_mailbox_tbl->mailbox_id, - input_mailbox_tbl->mailbox_name, - &err)) + *stream, + account_id, + mail_id, + uid_elem->uid, + input_mailbox_tbl->mailbox_id, + input_mailbox_tbl->mailbox_name, + &err)) EM_DEBUG_LOG("Partial body download initiation failed [%d]", err); #ifndef __FEATURE_PARTIAL_BODY_FOR_POP3__ } @@ -2454,19 +2454,19 @@ INTERNAL_FUNC int emcore_sync_header(char *multi_user_name, #ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ if (input_mailbox_tbl->mailbox_type == EMAIL_MAILBOX_TYPE_INBOX) { if (!emcore_insert_auto_download_job(multi_user_name, - account_id, - input_mailbox_tbl->mailbox_id, - mail_id, - /*account_ref->wifi_auto_download*/ 1, - uid_elem->uid, - &err)) + account_id, + input_mailbox_tbl->mailbox_id, + mail_id, + /*account_ref->wifi_auto_download*/ 1, + uid_elem->uid, + &err)) EM_DEBUG_LOG("emcore_insert_auto_download_job failed [%d]", err); } #endif -/* - if (!uid_elem->flag.seen && input_mailbox_tbl->mailbox_type != EMAIL_MAILBOX_TYPE_SPAMBOX) - emcore_add_notification_for_unread_mail(new_mail_tbl_data); -*/ + /* + if (!uid_elem->flag.seen && input_mailbox_tbl->mailbox_type != EMAIL_MAILBOX_TYPE_SPAMBOX) + emcore_add_notification_for_unread_mail(new_mail_tbl_data); + */ if (cancellable) FINISH_OFF_IF_EVENT_CANCELED(err, event_handle); @@ -2479,7 +2479,7 @@ INTERNAL_FUNC int emcore_sync_header(char *multi_user_name, percentage = ((i+1) * 100) / total ; EM_DEBUG_LOG("Header Percentage Completed [%d] : [%d/%d] mail_id [%d]", percentage, i+1, - total, mail_id); + total, mail_id); SNPRINTF(mailbox_id_param_string, 10, "%d", input_mailbox_tbl->mailbox_id); } @@ -2493,7 +2493,7 @@ INTERNAL_FUNC int emcore_sync_header(char *multi_user_name, blocking_mode = emcore_get_blocking_mode_status(); if (!blocking_mode) { if ((err = emcore_check_blocking_mode(multi_user_name, new_mail_tbl_data->email_address_sender, - &blocking_mode)) != EMAIL_ERROR_NONE) { + &blocking_mode)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_check_blocking_mode failed : [%d]", err); } @@ -2650,11 +2650,11 @@ int emcore_download_uid_all(char *multi_user_name, MAILSTREAM *mail_stream, emai if (!mail_stream) { if (!emcore_connect_to_remote_mailbox(multi_user_name, - mailbox->account_id, - mailbox->mailbox_id, - true, - (void **)&tmp_stream, - &err)) { + mailbox->account_id, + mailbox->mailbox_id, + true, + (void **)&tmp_stream, + &err)) { EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed..."); goto FINISH_OFF; @@ -2950,11 +2950,11 @@ int emcore_download_imap_msgno(char *multi_user_name, email_internal_mailbox_t * if (!mailbox->mail_stream) { if (!emcore_connect_to_remote_mailbox(multi_user_name, - mailbox->account_id, - mailbox->mailbox_id, - true, - (void **)&tmp_stream, - &err)) { + mailbox->account_id, + mailbox->mailbox_id, + true, + (void **)&tmp_stream, + &err)) { EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed - %d", err); goto FINISH_OFF; @@ -3245,9 +3245,9 @@ INTERNAL_FUNC char *emcore_guess_charset(char *multi_user_name, char *source_str #ifdef __FEATURE_SYNC_CLIENT_TO_SERVER__ INTERNAL_FUNC int emcore_sync_mail_by_message_id(char *multi_user_name, - int mail_id, - int mailbox_id, - char **output_server_uid) + int mail_id, + int mailbox_id, + char **output_server_uid) { EM_DEBUG_FUNC_BEGIN("mail_id : [%d], mailbox_id : [%d]", mail_id, mailbox_id); @@ -3273,13 +3273,13 @@ INTERNAL_FUNC int emcore_sync_mail_by_message_id(char *multi_user_name, } if (!emcore_connect_to_remote_mailbox(multi_user_name, - mail_data_t->account_id, - mailbox_id, - false, - (void **)&stream, - &err)) { - EM_DEBUG_EXCEPTION("emcore_move_mail_on_server failed : Mailbox open[%d]", err); - goto FINISH_OFF; + mail_data_t->account_id, + mailbox_id, + false, + (void **)&stream, + &err)) { + EM_DEBUG_EXCEPTION("emcore_move_mail_on_server failed : Mailbox open[%d]", err); + goto FINISH_OFF; } EM_DEBUG_LOG("nmsgs : [%lu]", stream->nmsgs); @@ -3376,12 +3376,12 @@ FINISH_OFF: void mail_appenduid(char *mailbox, unsigned long uidvalidity, SEARCHSET *set) { EM_DEBUG_FUNC_BEGIN("mailbox - %s", mailbox); - EM_DEBUG_LOG("UID - %ld", set->first); + EM_DEBUG_LOG("UID - %ld", set->first); - memset(g_append_uid_rsp, 0x00, 129); + memset(g_append_uid_rsp, 0x00, 129); - snprintf(g_append_uid_rsp, sizeof(g_append_uid_rsp), "%ld", set->first); - EM_DEBUG_LOG("append uid - %s", g_append_uid_rsp); + snprintf(g_append_uid_rsp, sizeof(g_append_uid_rsp), "%ld", set->first); + EM_DEBUG_LOG("append uid - %s", g_append_uid_rsp); } INTERNAL_FUNC int emcore_sync_mail_from_client_to_server(char *multi_user_name, int mail_id) @@ -3399,8 +3399,8 @@ INTERNAL_FUNC int emcore_sync_mail_from_client_to_server(char *multi_user_name, char message_size[100] = {0,}; ENVELOPE *envelope = NULL; FILE *fp = NULL; - STRING str; - STRING str_data; + STRING str; + STRING str_data; MAILSTREAM *stream = NULL; email_account_t *account_ref = NULL; emstorage_mail_tbl_t *mail_table_data = NULL; @@ -3446,27 +3446,27 @@ INTERNAL_FUNC int emcore_sync_mail_from_client_to_server(char *multi_user_name, } if (!long_enc_path) { - EM_DEBUG_EXCEPTION(">>long_enc_path : NULL "); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION(">>long_enc_path : NULL "); + goto FINISH_OFF; } if (!emcore_make_rfc822_file_from_mail(multi_user_name, mail_table_data, attachment_tbl_data, attachment_tbl_count, &envelope, &fname, NULL, &err)) { - EM_DEBUG_EXCEPTION(" emcore_make_rfc822_file_from_mail failed [%d]", err); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION(" emcore_make_rfc822_file_from_mail failed [%d]", err); + goto FINISH_OFF; } if (fname) { - err = em_fopen(fname, "a+", &fp); - if (err != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("em_fopen failed - %s", fname); - goto FINISH_OFF; - } + err = em_fopen(fname, "a+", &fp); + if (err != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("em_fopen failed - %s", fname); + goto FINISH_OFF; + } } if (!fp) { - EM_DEBUG_EXCEPTION("fp is NULL..!"); + EM_DEBUG_EXCEPTION("fp is NULL..!"); err = EMAIL_ERROR_SYSTEM_FAILURE; - goto FINISH_OFF; + goto FINISH_OFF; } rewind(fp); @@ -3484,13 +3484,13 @@ INTERNAL_FUNC int emcore_sync_mail_from_client_to_server(char *multi_user_name, rewind(fp); if (!emcore_connect_to_remote_mailbox(multi_user_name, - mail_table_data->account_id, - 0, - true, - (void **)&stream, - &err)) { - EM_DEBUG_EXCEPTION("emcore_move_mail_on_server failed : Mailbox open[%d]", err); - goto FINISH_OFF; + mail_table_data->account_id, + 0, + true, + (void **)&stream, + &err)) { + EM_DEBUG_EXCEPTION("emcore_move_mail_on_server failed : Mailbox open[%d]", err); + goto FINISH_OFF; } /* added for copying server UID to DB */ @@ -3597,13 +3597,13 @@ INTERNAL_FUNC int emcore_sync_mail_from_client_to_server(char *multi_user_name, /* Update read_mail_uid tbl */ if (!emcore_add_read_mail_uid(multi_user_name, - mailbox_tbl, - mailbox_tbl->mailbox_name, - mail_table_data->mail_id, - g_append_uid_rsp, - mail_table_data->mail_size, - 0, - &err)) { + mailbox_tbl, + mailbox_tbl->mailbox_name, + mail_table_data->mail_id, + g_append_uid_rsp, + mail_table_data->mail_size, + 0, + &err)) { EM_DEBUG_EXCEPTION(" emcore_add_read_mail_uid failed [%d]", err); emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL); goto FINISH_OFF; @@ -3611,10 +3611,10 @@ INTERNAL_FUNC int emcore_sync_mail_from_client_to_server(char *multi_user_name, /* Update mail_data tbl */ if (!emstorage_update_server_uid(multi_user_name, - mail_table_data->mail_id, - mail_table_data->server_mail_id, - g_append_uid_rsp, - &err)) { + mail_table_data->mail_id, + mail_table_data->server_mail_id, + g_append_uid_rsp, + &err)) { EM_DEBUG_EXCEPTION("emstorage_update_server_uid failed : [%d]", err); emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL); goto FINISH_OFF; @@ -3679,11 +3679,11 @@ FINISH_OFF: #ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__ INTERNAL_FUNC int emcore_initiate_pbd(char *multi_user_name, MAILSTREAM *stream, int account_id, - int mail_id, char *uid, int input_maibox_id, - char *input_mailbox_name, int *err_code) + int mail_id, char *uid, int input_maibox_id, + char *input_mailbox_name, int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id [%d], mail_id[%d], uid[%p], input_maibox_id[%d], input_mailbox_name[%s]", - account_id, mail_id, uid, input_maibox_id, input_mailbox_name); + account_id, mail_id, uid, input_maibox_id, input_mailbox_name); int ret = false; int err = EMAIL_ERROR_NONE; @@ -3720,7 +3720,7 @@ INTERNAL_FUNC int emcore_initiate_pbd(char *multi_user_name, MAILSTREAM *stream, EM_DEBUG_LOG("input_mailbox_name name [%d]", pbd_event.mailbox_id); EM_DEBUG_LOG("uid [%s]", uid); EM_DEBUG_LOG("pbd_event.account_id[%d], pbd_event.mail_id[%d], pbd_event.server_mail_id [%d]", - pbd_event.account_id, pbd_event.mail_id , pbd_event.server_mail_id); + pbd_event.account_id, pbd_event.mail_id , pbd_event.server_mail_id); if (!emcore_insert_pbd_activity(&pbd_event, &pbd_event.activity_id, &err)) { EM_DEBUG_EXCEPTION("Inserting Partial Body Download activity failed with error[%d]", err); @@ -3728,8 +3728,8 @@ INTERNAL_FUNC int emcore_initiate_pbd(char *multi_user_name, MAILSTREAM *stream, } else { if (false == emcore_is_partial_body_thd_que_full()) { /* h.gahaut : Before inserting the event into event queue activity_type should be made 0 - Because partial body thread differentiates events coming from DB and event queue - on the basis of activity_type and event_type fields */ + Because partial body thread differentiates events coming from DB and event queue + on the basis of activity_type and event_type fields */ pbd_event.activity_type = 0; pbd_event.event_type = EMAIL_EVENT_BULK_PARTIAL_BODY_DOWNLOAD; @@ -3766,16 +3766,16 @@ FINISH_OFF: } INTERNAL_FUNC int emcore_update_attachment_except_inline(char *multi_user_name, - struct _m_content_info *cnt_info, - int account_id, - int mail_id, - int mailbox_id, - int *output_total_attachment_size, - int *output_attachment_count, - int *output_inline_attachment_count) + struct _m_content_info *cnt_info, + int account_id, + int mail_id, + int mailbox_id, + int *output_total_attachment_size, + int *output_attachment_count, + int *output_inline_attachment_count) { EM_DEBUG_FUNC_BEGIN("cnt_info : [%p], account_id : [%d], mail_id : [%d], mailbox_id : [%d]", - cnt_info, account_id, mail_id, mailbox_id); + cnt_info, account_id, mail_id, mailbox_id); int err = EMAIL_ERROR_NONE; if (!cnt_info || !account_id || !mail_id || !mailbox_id) { @@ -3964,11 +3964,11 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int /* Check the body download status and body size */ SNPRINTF(uid_string, sizeof(uid_string), "%ld", imap_response[i].uid_no); if (!emstorage_get_maildata_by_servermailid(pbd_event[temp_count].multi_user_name, - uid_string, - pbd_event[temp_count].mailbox_id, - &mail, - false, - &err) || !mail) { + uid_string, + pbd_event[temp_count].mailbox_id, + &mail, + false, + &err) || !mail) { EM_DEBUG_EXCEPTION("emstorage_get_mail_data_by_servermailid failed : [%d]", err); if (err == EMAIL_ERROR_MAIL_NOT_FOUND || !mail) { if (false == emcore_delete_pbd_activity(pbd_event[temp_count].multi_user_name, @@ -4121,18 +4121,18 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int } /*part_idx = g_mime_multipart_index_of(GMIME_MULTIPART(message1->mime_part), part_tmp1); - replaced = g_mime_multipart_replace(GMIME_MULTIPART(message1->mime_part), part_idx, part_tmp2); - if (!replaced) { - EM_DEBUG_EXCEPTION("g_mime_multipart_replace failed"); - } - if (replaced) g_object_unref(replaced);*/ + replaced = g_mime_multipart_replace(GMIME_MULTIPART(message1->mime_part), part_idx, part_tmp2); + if (!replaced) { + EM_DEBUG_EXCEPTION("g_mime_multipart_replace failed"); + } + if (replaced) g_object_unref(replaced);*/ /*content_tmp2 = g_mime_part_get_content_object(GMIME_PART(part_tmp2)); - part_tmp1 = g_mime_part_iter_get_current(iter1); - if (content_tmp2 && part_tmp1 && GMIME_IS_PART(part_tmp1)) { - g_mime_part_set_content_object(GMIME_PART(part_tmp1), content_tmp2); - g_object_unref(content_tmp2); - }*/ + part_tmp1 = g_mime_part_iter_get_current(iter1); + if (content_tmp2 && part_tmp1 && GMIME_IS_PART(part_tmp1)) { + g_mime_part_set_content_object(GMIME_PART(part_tmp1), content_tmp2); + g_object_unref(content_tmp2); + }*/ } @@ -4166,7 +4166,7 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int if (g_strrstr(g_mime_message_get_sender(message1), "mmsc.plusnet.pl") != NULL || - g_strrstr(g_mime_message_get_sender(message1), "mms.t-mobile.pl") != NULL) { + g_strrstr(g_mime_message_get_sender(message1), "mms.t-mobile.pl") != NULL) { cnt_info->attachment_only = 1; } @@ -4192,7 +4192,7 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int if (sender) { if (g_strrstr(sender, "mmsc.plusnet.pl") != NULL || - g_strrstr(sender, "mms.t-mobile.pl") != NULL) { + g_strrstr(sender, "mms.t-mobile.pl") != NULL) { cnt_info->attachment_only = 1; } } @@ -4202,11 +4202,11 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int if (!strcasecmp(body->subtype, "pkcs7-mime")) { if (emcore_get_attribute_value_of_body_part(body->parameter, - "PROTOCOL", - rfc822_protocol, - TEMP_STRING_LENGTH, - false, - &err)) { + "PROTOCOL", + rfc822_protocol, + TEMP_STRING_LENGTH, + false, + &err)) { if (strcasestr(rfc822_protocol, "enveloped-data")) mail->smime_type = EMAIL_SMIME_ENCRYPTED; else @@ -4216,20 +4216,20 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int mail->smime_type = EMAIL_PGP_ENCRYPTED; } else if (!strcasecmp(body->subtype, "signed")) { if (emcore_get_attribute_value_of_body_part(body->parameter, - "MICALG", - rfc822_micalg, - TEMP_STRING_LENGTH, - false, - &err)) { + "MICALG", + rfc822_micalg, + TEMP_STRING_LENGTH, + false, + &err)) { mail->digest_type = emcore_get_digest_type(rfc822_micalg); } if (emcore_get_attribute_value_of_body_part(body->parameter, - "PROTOCOL", - rfc822_protocol, - TEMP_STRING_LENGTH, - false, - &err)) { + "PROTOCOL", + rfc822_protocol, + TEMP_STRING_LENGTH, + false, + &err)) { if (strcasestr(rfc822_protocol, "pkcs7-signature")) mail->smime_type = EMAIL_SMIME_SIGNED; else @@ -4251,13 +4251,13 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int /* Update the attachment info except inline attachment */ if ((err = emcore_update_attachment_except_inline(pbd_event[temp_count].multi_user_name, - cnt_info, - pbd_event[temp_count].account_id, - mail->mail_id, - pbd_event[temp_count].mailbox_id, - &total_attachment_size, - &attachment_num, - &inline_attachment_num)) != EMAIL_ERROR_NONE) { + cnt_info, + pbd_event[temp_count].account_id, + mail->mail_id, + pbd_event[temp_count].mailbox_id, + &total_attachment_size, + &attachment_num, + &inline_attachment_num)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_update_attachment_except_inline failed : [%d]", err); goto FINISH_OFF; } @@ -4288,21 +4288,21 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int } if (!emstorage_create_dir(pbd_event[temp_count].multi_user_name, - pbd_event[temp_count].account_id, - mail->mail_id, - 0, - &err)) + pbd_event[temp_count].account_id, + mail->mail_id, + 0, + &err)) EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err); if (!emstorage_get_save_name(pbd_event[temp_count].multi_user_name, - pbd_event[temp_count].account_id, - mail->mail_id, - 0, - charset_plain_text, - move_buf, - path_buf, - sizeof(path_buf), - &err)) + pbd_event[temp_count].account_id, + mail->mail_id, + 0, + charset_plain_text, + move_buf, + path_buf, + sizeof(path_buf), + &err)) EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); if (!emstorage_move_file(cnt_info->text.plain, move_buf, false, &err)) { @@ -4332,21 +4332,21 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int charset_html_text = g_strconcat(charset_html_text, HTML_EXTENSION_STRING, NULL); if (!emstorage_create_dir(pbd_event[temp_count].multi_user_name, - pbd_event[temp_count].account_id, - mail->mail_id, - 0, - &err)) + pbd_event[temp_count].account_id, + mail->mail_id, + 0, + &err)) EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err); if (!emstorage_get_save_name(pbd_event[temp_count].multi_user_name, - pbd_event[temp_count].account_id, - mail->mail_id, - 0, - charset_html_text, - move_buf, - path_buf, - sizeof(path_buf), - &err)) + pbd_event[temp_count].account_id, + mail->mail_id, + 0, + charset_html_text, + move_buf, + path_buf, + sizeof(path_buf), + &err)) EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); if (!emstorage_move_file(cnt_info->text.html, move_buf, false, &err)) { @@ -4363,21 +4363,21 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int memset(move_buf, 0x00, sizeof(move_buf)); if (!emstorage_create_dir(pbd_event[temp_count].multi_user_name, - pbd_event[temp_count].account_id, - mail->mail_id, - 0, - &err)) + pbd_event[temp_count].account_id, + mail->mail_id, + 0, + &err)) EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err); if (!emstorage_get_save_name(pbd_event[temp_count].multi_user_name, - pbd_event[temp_count].account_id, - mail->mail_id, - 0, - "mime_entity", - move_buf, - path_buf, - sizeof(path_buf), - &err)) + pbd_event[temp_count].account_id, + mail->mail_id, + 0, + "mime_entity", + move_buf, + path_buf, + sizeof(path_buf), + &err)) EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); if (!emstorage_move_file(cnt_info->text.mime_entity, move_buf, false, &err)) { @@ -4402,21 +4402,21 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int memset(move_buf, 0x00, sizeof(move_buf)); if (!emstorage_create_dir(pbd_event[temp_count].multi_user_name, - pbd_event[temp_count].account_id, - mail->mail_id, - 0, - &err)) + pbd_event[temp_count].account_id, + mail->mail_id, + 0, + &err)) EM_DEBUG_EXCEPTION("emstorage_create_dir failed [%d]", err); if (!emstorage_get_save_name(pbd_event[temp_count].multi_user_name, - pbd_event[temp_count].account_id, - mail->mail_id, - 0, - temp_file->name, - move_buf, - path_buf, - sizeof(path_buf), - &err)) + pbd_event[temp_count].account_id, + mail->mail_id, + 0, + temp_file->name, + move_buf, + path_buf, + sizeof(path_buf), + &err)) EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); if (!emstorage_move_file(temp_file->save, move_buf, false, &err)) { @@ -4439,10 +4439,10 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int EM_DEBUG_LOG("mime_type : [%s]", temp_file->attachment_mime_type); if (!emstorage_add_attachment(pbd_event[temp_count].multi_user_name, - &attachment_tbl, - false, - false, - &err)) + &attachment_tbl, + false, + false, + &err)) EM_DEBUG_EXCEPTION("emstorage_add_attachment failed - %d", err); } } else { @@ -4455,32 +4455,32 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int } mail->body_download_status = (mail->body_download_status & ~0x00000003) | - (((total_mail_size - total_attachment_size <= input_download_size) && - (inline_download_count == inline_attachment_num)) ? - EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED : - EMAIL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED); + (((total_mail_size - total_attachment_size <= input_download_size) && + (inline_download_count == inline_attachment_num)) ? + EMAIL_BODY_DOWNLOAD_STATUS_FULLY_DOWNLOADED : + EMAIL_BODY_DOWNLOAD_STATUS_PARTIALLY_DOWNLOADED); EM_DEBUG_LOG("inline_download_count[%d] inline_attachment_num[%d]", - inline_download_count, inline_attachment_num); + inline_download_count, inline_attachment_num); EM_DEBUG_LOG("total_mail_size[%d] total_attachment_size[%d] input_download_size[%d]", - total_mail_size, total_attachment_size, input_download_size); + total_mail_size, total_attachment_size, input_download_size); EM_DEBUG_LOG("mail_id [%d] body_download_status [%d]", mail->mail_id, mail->body_download_status); /* Get preview text */ if ((err = emcore_get_preview_text_from_file(pbd_event[temp_count].multi_user_name, - mail->file_path_plain, - mail->file_path_html, - MAX_PREVIEW_TEXT_LENGTH, - &(mail->preview_text))) != EMAIL_ERROR_NONE) + mail->file_path_plain, + mail->file_path_html, + MAX_PREVIEW_TEXT_LENGTH, + &(mail->preview_text))) != EMAIL_ERROR_NONE) EM_DEBUG_EXCEPTION("emcore_get_preview_text_from_file() failed[%d]", err); /* Update body contents */ if (!emstorage_change_mail_field(pbd_event[temp_count].multi_user_name, - mail->mail_id, - UPDATE_PARTIAL_BODY_DOWNLOAD, - mail, - true, - &err)) { + mail->mail_id, + UPDATE_PARTIAL_BODY_DOWNLOAD, + mail, + true, + &err)) { EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed - %d", err); goto FINISH_OFF; } @@ -4489,17 +4489,17 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int /* strip html content and save into mail_text_tbl */ char *stripped_text = NULL; if (!emcore_strip_mail_body_from_file(pbd_event[temp_count].multi_user_name, - mail, - &stripped_text, - &err) || stripped_text == NULL) { + mail, + &stripped_text, + &err) || stripped_text == NULL) { EM_DEBUG_EXCEPTION("emcore_strip_mail_body_from_file failed [%d]", err); } if (!emstorage_get_mail_text_by_id(pbd_event[temp_count].multi_user_name, - mail->mail_id, - &mail_text, - true, - &err) || !mail_text) { + mail->mail_id, + &mail_text, + true, + &err) || !mail_text) { EM_DEBUG_EXCEPTION("emstorage_get_mail_text_by_id failed [%d]", err); goto FINISH_OFF; } @@ -4508,10 +4508,10 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int mail_text->body_text = stripped_text; if (!emstorage_change_mail_text_field(pbd_event[temp_count].multi_user_name, - mail->mail_id, - mail_text, - false, - &err)) { + mail->mail_id, + mail_text, + false, + &err)) { EM_DEBUG_EXCEPTION("emstorage_change_mail_text_field failed [%d]", err); goto FINISH_OFF; } @@ -4524,10 +4524,10 @@ static int emcore_gmime_download_imap_partial_mail_body(MAILSTREAM *stream, int emstorage_free_mail(&mail, 1, NULL); if (false == emcore_delete_pbd_activity(pbd_event[temp_count].multi_user_name, - pbd_event[temp_count].account_id, - pbd_event[temp_count].mail_id, - pbd_event[temp_count].activity_id, - &err)) { + pbd_event[temp_count].account_id, + pbd_event[temp_count].mail_id, + pbd_event[temp_count].activity_id, + &err)) { EM_DEBUG_EXCEPTION("emcore_delete_pbd_activity failed [%d]", err); goto FINISH_OFF; } @@ -4612,11 +4612,11 @@ INTERNAL_FUNC int emcore_download_bulk_partial_mail_body_for_pop3(MAILSTREAM *st } for (i = 0; i < item_count; i++) { - EM_DEBUG_LOG_SEC("pbd_event[%d].account_id [%d], mail_id [%d], server_mail_id [%d], activity_id [%d]", \ - i, pbd_event[i].account_id, pbd_event[i].mail_id, pbd_event[i].server_mail_id, pbd_event[i].activity_id); + EM_DEBUG_LOG_SEC("pbd_event[%d].account_id [%d], mail_id [%d], server_mail_id [%d], activity_id [%d]", \ + i, pbd_event[i].account_id, pbd_event[i].mail_id, pbd_event[i].server_mail_id, pbd_event[i].activity_id); if (!emcore_gmime_download_body_sections(pbd_event[i].multi_user_name, stream, pbd_event[i].account_id, - pbd_event[i].mail_id, 0, input_download_size, -1, 0, 0, &err)) { + pbd_event[i].mail_id, 0, input_download_size, -1, 0, 0, &err)) { EM_DEBUG_EXCEPTION("emcore_gmime_download_body_sections failed - %d", err); goto FINISH_OFF; } @@ -4663,18 +4663,18 @@ INTERNAL_FUNC int emcore_download_bulk_partial_mail_body(MAILSTREAM *stream, ema } switch (pbd_account_tbl->incoming_server_type) { - case EMAIL_SERVER_TYPE_IMAP4: - ret = emcore_gmime_download_imap_partial_mail_body(stream, auto_download_size, pbd_event, item_count, &err); - break; + case EMAIL_SERVER_TYPE_IMAP4: + ret = emcore_gmime_download_imap_partial_mail_body(stream, auto_download_size, pbd_event, item_count, &err); + break; - case EMAIL_SERVER_TYPE_POP3: - ret = emcore_download_bulk_partial_mail_body_for_pop3(stream, auto_download_size, pbd_event, item_count, &err); - break; + case EMAIL_SERVER_TYPE_POP3: + ret = emcore_download_bulk_partial_mail_body_for_pop3(stream, auto_download_size, pbd_event, item_count, &err); + break; - default: - err = EMAIL_ERROR_NOT_SUPPORTED; - ret = false; - break; + default: + err = EMAIL_ERROR_NOT_SUPPORTED; + ret = false; + break; } ret = true; @@ -4772,7 +4772,7 @@ static email_partial_buffer *emcore_get_response_from_server(NETSTREAM *nstream, } if (net_getbuffer(nstream, server_response[count].rfc822header_len, - server_response[count].rfc822header) <= 0) { + server_response[count].rfc822header) <= 0) { EM_DEBUG_EXCEPTION("net_getbuffer failed"); goto FINISH_OFF; } diff --git a/email-core/email-core-mm-callbacks.c b/email-core/email-core-mm-callbacks.c index eb61708..fa1dc4e 100755 --- a/email-core/email-core-mm-callbacks.c +++ b/email-core/email-core-mm-callbacks.c @@ -1,23 +1,23 @@ /* -* email-service -* -* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. -* -* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* -*/ + * email-service + * + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ /****************************************************************************** @@ -71,9 +71,8 @@ INTERNAL_FUNC void mm_lsub(MAILSTREAM *stream, int delimiter, char *mailbox, lon /* convert directory delimiter to '/' */ for (s = enc_path; *s; s++) { - if (*s == (char)delimiter) { + if (*s == (char)delimiter) *s = '/'; - } } /* coyp string */ @@ -87,10 +86,10 @@ INTERNAL_FUNC void mm_lsub(MAILSTREAM *stream, int delimiter, char *mailbox, lon p_holder->num++; /* ignore attributes */ -/* if (attributes & latt_noinferiors) fputs (", no inferiors", fp_log); */ -/* if (attributes & latt_noselect) fputs (", no select", fp_log); */ -/* if (attributes & latt_marked) fputs (", marked", fp_log); */ -/* if (attributes & latt_unmarked) fputs (", unmarked", fp_log); */ + /* if (attributes & latt_noinferiors) fputs (", no inferiors", fp_log); */ + /* if (attributes & latt_noselect) fputs (", no select", fp_log); */ + /* if (attributes & latt_marked) fputs (", marked", fp_log); */ + /* if (attributes & latt_unmarked) fputs (", unmarked", fp_log); */ EM_DEBUG_FUNC_END(); } @@ -140,7 +139,7 @@ INTERNAL_FUNC void mm_list(MAILSTREAM *stream, int delimiter, char *mailbox, lon else if (attributes & LATT_XLIST_JUNK) p[count].mailbox_type = EMAIL_MAILBOX_TYPE_SPAMBOX; else if (attributes & LATT_XLIST_FLAGGED) - p[count].mailbox_type = EMAIL_MAILBOX_TYPE_USER_DEFINED; //EMAIL_MAILBOX_TYPE_FLAGGED; P141122-00523 sync starred folder as Inbox sync + p[count].mailbox_type = EMAIL_MAILBOX_TYPE_USER_DEFINED; //EMAIL_MAILBOX_TYPE_FLAGGED; P141122-00523 sync starred folder as Inbox sync else if (attributes & LATT_XLIST_TRASH) p[count].mailbox_type = EMAIL_MAILBOX_TYPE_TRASH; #endif /* __FEATURE_XLIST_SUPPORT__ */ @@ -211,7 +210,7 @@ INTERNAL_FUNC void mm_login(NETMBX *mb, char *user, char *pwd, long trial) char *token = NULL; char *save_ptr = NULL; char *user_info = NULL; - char *temp = NULL; + char *temp = NULL; char *multi_user_name = NULL; if (!mb->user[0]) { @@ -226,8 +225,8 @@ INTERNAL_FUNC void mm_login(NETMBX *mb, char *user, char *pwd, long trial) account_id = atoi(token); token = NULL; - if (temp != NULL && EM_SAFE_STRLEN(temp) > 0) - multi_user_name = EM_SAFE_STRDUP(temp); + if (temp != NULL && EM_SAFE_STRLEN(temp) > 0) + multi_user_name = EM_SAFE_STRDUP(temp); ref_account = emcore_get_account_reference(multi_user_name, account_id, true); if (!ref_account) { @@ -258,8 +257,8 @@ INTERNAL_FUNC void mm_login(NETMBX *mb, char *user, char *pwd, long trial) } if (EM_SAFE_STRLEN(username) > 0 && EM_SAFE_STRLEN(password) > 0) { - EM_SAFE_STRNCPY(user, username, NETMAXUSER- EM_SAFE_STRLEN(user) -1); - EM_SAFE_STRNCPY(pwd, password, MAILTMPLEN - EM_SAFE_STRLEN(pwd) -1); + EM_SAFE_STRNCPY(user, username, NETMAXUSER - EM_SAFE_STRLEN(user) - 1); + EM_SAFE_STRNCPY(pwd, password, MAILTMPLEN - EM_SAFE_STRLEN(pwd) - 1); } else EM_DEBUG_EXCEPTION("User Information is NULL || EM_SAFE_STRLEN is 0 "); @@ -273,7 +272,7 @@ FINISH_OFF: EM_SAFE_FREE(user_info); EM_SAFE_FREE(username); EM_SAFE_FREE(password); - EM_SAFE_FREE(multi_user_name); + EM_SAFE_FREE(multi_user_name); EM_DEBUG_FUNC_END(); } @@ -290,44 +289,44 @@ INTERNAL_FUNC void mm_log(char *string, long errflg) { switch (errflg) { - case NIL: - EM_DEBUG_LOG_SEC("IMAP_TOOLKIT_LOG [%s]", string); - break; + case NIL: + EM_DEBUG_LOG_SEC("IMAP_TOOLKIT_LOG [%s]", string); + break; - case WARN: - EM_DEBUG_EXCEPTION("IMAP_TOOLKIT_LOG WARN [%s]", string); - break; + case WARN: + EM_DEBUG_EXCEPTION("IMAP_TOOLKIT_LOG WARN [%s]", string); + break; - case PARSE: - EM_DEBUG_LOG("IMAP_TOOLKIT_LOG PARSE [%s]", string); - break; + case PARSE: + EM_DEBUG_LOG("IMAP_TOOLKIT_LOG PARSE [%s]", string); + break; - case BYE: - EM_DEBUG_LOG("IMAP_TOOLKIT_LOG BYE [%s]", string); - break; + case BYE: + EM_DEBUG_LOG("IMAP_TOOLKIT_LOG BYE [%s]", string); + break; - case TCPDEBUG: - EM_DEBUG_LOG_SEC("IMAP_TOOLKIT_LOG TCPDEBUG [%s]", string); - break; + case TCPDEBUG: + EM_DEBUG_LOG_SEC("IMAP_TOOLKIT_LOG TCPDEBUG [%s]", string); + break; - case ERROR: { - email_session_t *session = NULL; + case ERROR: { + email_session_t *session = NULL; - EM_DEBUG_EXCEPTION("IMAP_TOOLKIT_LOG ERROR [%s]", string); + EM_DEBUG_EXCEPTION("IMAP_TOOLKIT_LOG ERROR [%s]", string); - emcore_get_current_session(&session); + emcore_get_current_session(&session); - if (session) { - mm_get_error(string, &session->error); - EM_DEBUG_EXCEPTION("IMAP_TOOLKIT_LOG ERROR [%d]", session->error); - if (session->error == EMAIL_ERROR_XOAUTH_BAD_REQUEST || - session->error == EMAIL_ERROR_XOAUTH_INVALID_UNAUTHORIZED) { - session->network = session->error; - } - } + if (session) { + mm_get_error(string, &session->error); + EM_DEBUG_EXCEPTION("IMAP_TOOLKIT_LOG ERROR [%d]", session->error); + if (session->error == EMAIL_ERROR_XOAUTH_BAD_REQUEST || + session->error == EMAIL_ERROR_XOAUTH_INVALID_UNAUTHORIZED) { + session->network = session->error; + } + } - break; - } + break; + } } } @@ -462,10 +461,10 @@ INTERNAL_FUNC void mm_imap_id(char **id_string) EM_DEBUG_FUNC_BEGIN("id_string [%p]", id_string); /* - char *result_string = NULL; - char *tag_string = "ID (\"os\" \"" IMAP_ID_OS "\" \"os-version\" \"" IMAP_ID_OS_VERSION "\" \"vendor\" \"" IMAP_ID_VENDOR "\" \"device\" \"" IMAP_ID_DEVICE_NAME "\" \"AGUID\" \"" IMAP_ID_AGUID "\" \"ACLID\" \"" IMAP_ID_ACLID "\""; - int tag_length = 0; - */ + char *result_string = NULL; + char *tag_string = "ID (\"os\" \"" IMAP_ID_OS "\" \"os-version\" \"" IMAP_ID_OS_VERSION "\" \"vendor\" \"" IMAP_ID_VENDOR "\" \"device\" \"" IMAP_ID_DEVICE_NAME "\" \"AGUID\" \"" IMAP_ID_AGUID "\" \"ACLID\" \"" IMAP_ID_ACLID "\""; + int tag_length = 0; + */ if (id_string == NULL) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); @@ -475,16 +474,16 @@ INTERNAL_FUNC void mm_imap_id(char **id_string) *id_string = NULL; /* - tag_length = EM_SAFE_STRLEN(tag_string); - result_string = EM_SAFE_STRDUP(tag_string); + tag_length = EM_SAFE_STRLEN(tag_string); + result_string = EM_SAFE_STRDUP(tag_string); - if (result_string == NULL) { - EM_DEBUG_EXCEPTION("malloc failed"); - goto FINISH_OFF; - } + if (result_string == NULL) { + EM_DEBUG_EXCEPTION("malloc failed"); + goto FINISH_OFF; + } - *id_string = result_string; - */ + *id_string = result_string; + */ FINISH_OFF: return ; } diff --git a/email-core/email-core-smtp.c b/email-core/email-core-smtp.c index 48efd29..29bc680 100755 --- a/email-core/email-core-smtp.c +++ b/email-core/email-core-smtp.c @@ -1,23 +1,23 @@ /* -* email-service -* -* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. -* -* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* -*/ + * email-service + * + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ #include <stdio.h> #include <string.h> @@ -91,14 +91,14 @@ void mail_send_notify(email_send_status_t status, int total, int sent, int accou EM_DEBUG_FUNC_BEGIN("status[%d], total[%d], sent[%d], account_id[%d], mail_id[%d], err_code[%d]", status, total, sent, account_id, mail_id, err_code); switch (status) { - case EMAIL_SEND_CONNECTION_FAIL: - case EMAIL_SEND_FINISH: - case EMAIL_SEND_FAIL: - break; + case EMAIL_SEND_CONNECTION_FAIL: + case EMAIL_SEND_FINISH: + case EMAIL_SEND_FAIL: + break; - case EMAIL_SEND_PROGRESS: - default: - break; + case EMAIL_SEND_PROGRESS: + default: + break; } emcore_execute_event_callback(EMAIL_ACTION_SEND_MAIL, total, sent, status, account_id, mail_id, -1, err_code); EM_DEBUG_FUNC_END(); @@ -179,14 +179,16 @@ static char *emcore_replace_inline_image_path_with_content_id(char *source_strin while (cur_part) { cur_body = &(cur_part->body); - if (cur_body->disposition.type && cur_body->disposition.type[0] == 'i') { /* Is inline content? */ + /* Is inline content? */ + if (cur_body->disposition.type && cur_body->disposition.type[0] == 'i') { EM_DEBUG_LOG("Has inline content"); memset(content_id_buffer, 0, CONTENT_ID_BUFFER_SIZE); if (cur_body->id) { EM_SAFE_STRNCPY(content_id_buffer, cur_body->id + 1, CONTENT_ID_BUFFER_SIZE - 1); /* Removing <, > */ /* prevent 34413 */ char *last_bracket = rindex(content_id_buffer, '>'); - if (last_bracket) *last_bracket = NULL_CHAR; + if (last_bracket) + *last_bracket = NULL_CHAR; /* if (emcore_get_attribute_value_of_body_part(cur_body->parameter, "name", file_name_buffer, CONTENT_ID_BUFFER_SIZE, false, &err)) { */ if (emcore_get_attribute_value_of_body_part(cur_body->parameter, "name", file_name_buffer, CONTENT_ID_BUFFER_SIZE, true, &err)) { @@ -250,11 +252,11 @@ static int emcore_write_body(BODY *body, BODY *root_body, FILE *fp) if (!file_path || EM_SAFE_STRLEN(file_path) == 0) { EM_DEBUG_LOG("There is no file path"); switch (body->encoding) { - case 0: - default: - p = cpystr((const char *)body->contents.text.data); - len = body->contents.text.size; - break; + case 0: + default: + p = cpystr((const char *)body->contents.text.data); + len = body->contents.text.size; + break; } if (p) { @@ -381,15 +383,15 @@ static int emcore_write_body(BODY *body, BODY *root_body, FILE *fp) /* EM_DEBUG_LOG("body->encoding[%d]", body->encoding); */ switch (body->encoding) { - case ENCQUOTEDPRINTABLE: - p = (char *)rfc822_8bit((unsigned char *)buf, (unsigned long)nread, (unsigned long *)&len); - break; - case ENCBASE64: - tmp_p = g_base64_encode((guchar *)buf, (gsize)nread); - p = g_strconcat(tmp_p, "\r\n", NULL); - EM_SAFE_FREE(tmp_p); - len = EM_SAFE_STRLEN(p); - break; + case ENCQUOTEDPRINTABLE: + p = (char *)rfc822_8bit((unsigned char *)buf, (unsigned long)nread, (unsigned long *)&len); + break; + case ENCBASE64: + tmp_p = g_base64_encode((guchar *)buf, (gsize)nread); + p = g_strconcat(tmp_p, "\r\n", NULL); + EM_SAFE_FREE(tmp_p); + len = EM_SAFE_STRLEN(p); + break; } //prepend additional dot to the string start with dot @@ -400,9 +402,8 @@ static int emcore_write_body(BODY *body, BODY *root_body, FILE *fp) EM_SAFE_FREE(tmp_p); } - if (!p && buf[0] == '.') { + if (!p && buf[0] == '.') p = g_strconcat(".", buf, NULL); - } len = EM_SAFE_STRLEN((p ? p : buf)); EM_DEBUG_LOG_DEV("line[%s]", (p ? p : buf)); @@ -447,57 +448,57 @@ static int emcore_write_rfc822_body(BODY *body, BODY *root_body, FILE *fp, int * int error = EMAIL_ERROR_NONE; switch (body->type) { - case TYPEMULTIPART: - EM_DEBUG_LOG_DEV("body->type = TYPEMULTIPART"); + case TYPEMULTIPART: + EM_DEBUG_LOG_DEV("body->type = TYPEMULTIPART"); - part = body->nested.part; + part = body->nested.part; - for (param = body->parameter; param; param = param->next) { - if (strcasecmp(param->attribute, "BOUNDARY") == 0) { - bndry = param->value; - break; - } + for (param = body->parameter; param; param = param->next) { + if (strcasecmp(param->attribute, "BOUNDARY") == 0) { + bndry = param->value; + break; } + } - do { - p = buf; p[0] = '\0'; + do { + p = buf; p[0] = '\0'; - rfc822_write_body_header(&p, &part->body); + rfc822_write_body_header(&p, &part->body); - fprintf(fp, CRLF_STRING"--%s"CRLF_STRING, bndry); - if (body->subtype && (body->subtype[0] == 'S' || body->subtype[0] == 's')) { - if ((error = emcore_write_body(body, root_body, fp)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emcore_write_body failed : [%d]", error); - return false; - } - fprintf(fp, CRLF_STRING"--%s"CRLF_STRING, bndry); + fprintf(fp, CRLF_STRING"--%s"CRLF_STRING, bndry); + if (body->subtype && (body->subtype[0] == 'S' || body->subtype[0] == 's')) { + if ((error = emcore_write_body(body, root_body, fp)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_write_body failed : [%d]", error); + return false; } + fprintf(fp, CRLF_STRING"--%s"CRLF_STRING, bndry); + } - fprintf(fp, "%s", buf); - emcore_write_rfc822_body(&part->body, root_body, fp, err_code); + fprintf(fp, "%s", buf); + emcore_write_rfc822_body(&part->body, root_body, fp, err_code); - } while ((part = part->next)); + } while ((part = part->next)); - fprintf(fp, CRLF_STRING"--%s--"CRLF_STRING, bndry); - break; + fprintf(fp, CRLF_STRING"--%s--"CRLF_STRING, bndry); + break; - default: - EM_DEBUG_LOG_DEV("body->type is not TYPEMULTIPART"); + default: + EM_DEBUG_LOG_DEV("body->type is not TYPEMULTIPART"); - fprintf(fp, CRLF_STRING); - if ((error = emcore_write_body(body, root_body, fp)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emcore_write_body failed : [%d]", error); - return false; - } + fprintf(fp, CRLF_STRING); + if ((error = emcore_write_body(body, root_body, fp)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_write_body failed : [%d]", error); + return false; + } - break; + break; } EM_DEBUG_FUNC_END(); return true; } static int emcore_write_rfc822(ENVELOPE *env, BODY *body, email_mail_priority_t input_priority, - email_mail_report_t input_report_flag, char **data) + email_mail_report_t input_report_flag, char **data) { EM_DEBUG_FUNC_BEGIN("env[%p], body[%p], data[%p]", env, body, data); @@ -586,8 +587,8 @@ static int emcore_write_rfc822(ENVELOPE *env, BODY *body, email_mail_priority_t } EM_DEBUG_LOG_DEV(" =============================================================================== " - LF_STRING"%s"LF_STRING - " =============================================================================== ", header_buffer); + LF_STRING"%s"LF_STRING + " =============================================================================== ", header_buffer); if (EM_SAFE_STRLEN(header_buffer) > 2) *(header_buffer + EM_SAFE_STRLEN(header_buffer) - 2) = '\0'; @@ -599,15 +600,15 @@ static int emcore_write_rfc822(ENVELOPE *env, BODY *body, email_mail_priority_t /* DSN (delivery status) */ /* change content-type */ /* Content-Type: multipart/report; */ - /* report-type= delivery-status; */ - /* boundary="----=_NextPart_000_004F_01C76EFF.54275C50" */ + /* report-type= delivery-status; */ + /* boundary="----=_NextPart_000_004F_01C76EFF.54275C50" */ } if (input_report_flag & EMAIL_MAIL_REPORT_MDN) { /* MDN (read receipt) */ /* Content-Type: multipart/report; */ - /* report-type= disposition-notification; */ - /* boundary="----=_NextPart_000_004F_01C76EFF.54275C50" */ + /* report-type= disposition-notification; */ + /* boundary="----=_NextPart_000_004F_01C76EFF.54275C50" */ } if (input_report_flag & EMAIL_MAIL_REQUEST_MDN) { @@ -622,19 +623,19 @@ static int emcore_write_rfc822(ENVELOPE *env, BODY *body, email_mail_priority_t SNPRINTF(header_buffer + EM_SAFE_STRLEN(header_buffer), header_buffer_lenth-(EM_SAFE_STRLEN(header_buffer)), "X-Priority: %d"CRLF_STRING, input_priority); switch (input_priority) { - case EMAIL_MAIL_PRIORITY_HIGH: - SNPRINTF(header_buffer + EM_SAFE_STRLEN(header_buffer), header_buffer_lenth-(EM_SAFE_STRLEN(header_buffer)), "X-MSMail-Priority: High"CRLF_STRING); - break; - case EMAIL_MAIL_PRIORITY_NORMAL: - SNPRINTF(header_buffer + EM_SAFE_STRLEN(header_buffer), header_buffer_lenth-(EM_SAFE_STRLEN(header_buffer)), "X-MSMail-Priority: Normal"CRLF_STRING); - break; - case EMAIL_MAIL_PRIORITY_LOW: - SNPRINTF(header_buffer + EM_SAFE_STRLEN(header_buffer), header_buffer_lenth-(EM_SAFE_STRLEN(header_buffer)), "X-MSMail-Priority: Low"CRLF_STRING); - break; + case EMAIL_MAIL_PRIORITY_HIGH: + SNPRINTF(header_buffer + EM_SAFE_STRLEN(header_buffer), header_buffer_lenth-(EM_SAFE_STRLEN(header_buffer)), "X-MSMail-Priority: High"CRLF_STRING); + break; + case EMAIL_MAIL_PRIORITY_NORMAL: + SNPRINTF(header_buffer + EM_SAFE_STRLEN(header_buffer), header_buffer_lenth-(EM_SAFE_STRLEN(header_buffer)), "X-MSMail-Priority: Normal"CRLF_STRING); + break; + case EMAIL_MAIL_PRIORITY_LOW: + SNPRINTF(header_buffer + EM_SAFE_STRLEN(header_buffer), header_buffer_lenth-(EM_SAFE_STRLEN(header_buffer)), "X-MSMail-Priority: Low"CRLF_STRING); + break; } } -// SNPRINTF(header_buffer + EM_SAFE_STRLEN(header_buffer), header_buffer_lenth-(EM_SAFE_STRLEN(header_buffer)), CRLF_STRING); + // SNPRINTF(header_buffer + EM_SAFE_STRLEN(header_buffer), header_buffer_lenth-(EM_SAFE_STRLEN(header_buffer)), CRLF_STRING); if (data && EM_SAFE_STRLEN(*data) > 0) { fname = EM_SAFE_STRDUP(*data); file_exist = 1; @@ -712,7 +713,7 @@ INTERNAL_FUNC int emcore_add_mail(char *multi_user_name, email_mail_data_t *inpu int mailbox_id_spam = 0, mailbox_id_target = 0; int mail_smime_flag = 0; char name_buf[MAX_PATH] = {0x00, }; - char path_buf[MAX_PATH] = {0, }; + char path_buf[MAX_PATH] = {0, }; char *body_text_file_name = NULL; char *dl_error = NULL; void *dl_handle = NULL; @@ -730,8 +731,8 @@ INTERNAL_FUNC int emcore_add_mail(char *multi_user_name, email_mail_data_t *inpu char mailbox_id_param_string[10] = {0,}; char errno_buf[ERRNO_BUF_SIZE] = {0}; int updated_thread_id = 0; - char *prefix_path = NULL; - char real_file_path[MAX_PATH] = {0}; + char *prefix_path = NULL; + char real_file_path[MAX_PATH] = {0}; #ifdef __FEATURE_BODY_SEARCH__ char *stripped_text = NULL; @@ -785,7 +786,7 @@ INTERNAL_FUNC int emcore_add_mail(char *multi_user_name, email_mail_data_t *inpu mailbox_id_target = mail_data->mailbox_id; - if (EM_SAFE_STRLEN(multi_user_name) > 0) { + if (EM_SAFE_STRLEN(multi_user_name) > 0) { err = emcore_get_container_path(multi_user_name, &prefix_path); if (err != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_get_container_path failed : [%d]", err); @@ -799,8 +800,8 @@ INTERNAL_FUNC int emcore_add_mail(char *multi_user_name, email_mail_data_t *inpu !(input_mail_data->message_class & EMAIL_MESSAGE_CLASS_SMART_REPLY) && !(input_mail_data->message_class & EMAIL_MESSAGE_CLASS_SMART_FORWARD)) { if (mail_data->file_path_plain) { - memset(real_file_path, 0x00, sizeof(real_file_path)); - SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, mail_data->file_path_plain); + memset(real_file_path, 0x00, sizeof(real_file_path)); + SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, mail_data->file_path_plain); if (stat(real_file_path, &st_buf) < 0) { EM_DEBUG_EXCEPTION_SEC("mail_data->file_path_plain, stat(\"%s\") failed...", mail_data->file_path_plain); @@ -811,8 +812,8 @@ INTERNAL_FUNC int emcore_add_mail(char *multi_user_name, email_mail_data_t *inpu } if (mail_data->file_path_html) { - memset(real_file_path, 0x00, sizeof(real_file_path)); - SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, mail_data->file_path_html); + memset(real_file_path, 0x00, sizeof(real_file_path)); + SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, mail_data->file_path_html); if (stat(real_file_path, &st_buf) < 0) { EM_DEBUG_EXCEPTION_SEC("mail_data->file_path_html, stat(\"%s\") failed...", mail_data->file_path_html); @@ -825,8 +826,8 @@ INTERNAL_FUNC int emcore_add_mail(char *multi_user_name, email_mail_data_t *inpu if (attachment_count && attachment_data_list) { for (i = 0; i < attachment_count; i++) { if (attachment_data_list[i].save_status) { - memset(real_file_path, 0x00, sizeof(real_file_path)); - SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, attachment_data_list[i].attachment_path); + memset(real_file_path, 0x00, sizeof(real_file_path)); + SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, attachment_data_list[i].attachment_path); if (!attachment_data_list[i].attachment_path || stat(real_file_path, &st_buf) < 0) { EM_DEBUG_EXCEPTION("stat(\"%s\") failed...", attachment_data_list[i].attachment_path); @@ -855,49 +856,50 @@ INTERNAL_FUNC int emcore_add_mail(char *multi_user_name, email_mail_data_t *inpu } /* Create report mail body */ /* - if (!emcore_make_rfc822_file_from_mail(multi_user_name, mail_src, NULL, NULL, NULL, &err)) { - EM_DEBUG_EXCEPTION("emcore_make_rfc822_file_from_mail failed [%d]", err); - goto FINISH_OFF; - } - */ + if (!emcore_make_rfc822_file_from_mail(multi_user_name, mail_src, NULL, NULL, NULL, &err)) { + EM_DEBUG_EXCEPTION("emcore_make_rfc822_file_from_mail failed [%d]", err); + goto FINISH_OFF; + } + */ } } else { /* For Spam handling */ email_option_t *opt = &account_tbl_item->options; EM_DEBUG_LOG_SEC("block_address [%d], block_subject [%d]", opt->block_address, opt->block_subject); - /* For eas moving from spambox to other mailbox */ - if (mail_data->save_status != EMAIL_MAIL_STATUS_SAVED) { - if (opt->block_address || opt->block_subject) { - int is_completed = false; - int type = 0; + /* For eas moving from spambox to other mailbox */ + if (mail_data->save_status != EMAIL_MAIL_STATUS_SAVED) { + if (opt->block_address || opt->block_subject) { + int is_completed = false; + int type = 0; - if (!opt->block_address) - type = EMAIL_FILTER_SUBJECT; - else if (!opt->block_subject) - type = EMAIL_FILTER_FROM; + if (!opt->block_address) + type = EMAIL_FILTER_SUBJECT; + else if (!opt->block_subject) + type = EMAIL_FILTER_FROM; - if (!emstorage_get_rule(multi_user_name, ALL_ACCOUNT, type, 0, &rule_len, &is_completed, &rule, true, &err) || !rule) - EM_DEBUG_LOG("No proper rules. emstorage_get_rule returns [%d]", err); + if (!emstorage_get_rule(multi_user_name, ALL_ACCOUNT, type, 0, &rule_len, &is_completed, &rule, true, &err) || !rule) + EM_DEBUG_LOG("No proper rules. emstorage_get_rule returns [%d]", err); - if (rule && !emcore_check_rule(mail_data->full_address_from, mail_data->subject, rule, rule_len, &priority_sender, &blocked, &err)) { - EM_DEBUG_EXCEPTION("emcore_check_rule failed [%d]", err); - } + if (rule + && !emcore_check_rule(mail_data->full_address_from, mail_data->subject, rule, rule_len, &priority_sender, &blocked, &err)) { + EM_DEBUG_EXCEPTION("emcore_check_rule failed [%d]", err); + } - if (priority_sender) - mail_data->tag_id = PRIORITY_SENDER_TAG_ID; + if (priority_sender) + mail_data->tag_id = PRIORITY_SENDER_TAG_ID; - if (blocked && (mail_data->mailbox_type == EMAIL_MAILBOX_TYPE_INBOX)) { - EM_DEBUG_LOG("mail[%d] added to spambox", mail_data->mail_id); - if (!emstorage_get_mailbox_id_by_mailbox_type(multi_user_name, mail_data->account_id, EMAIL_MAILBOX_TYPE_SPAMBOX, &mailbox_id_spam, false, &err)) { - EM_DEBUG_EXCEPTION("emstorage_get_mailbox_name_by_mailbox_type failed [%d]", err); - mailbox_id_spam = 0; - } + if (blocked && (mail_data->mailbox_type == EMAIL_MAILBOX_TYPE_INBOX)) { + EM_DEBUG_LOG("mail[%d] added to spambox", mail_data->mail_id); + if (!emstorage_get_mailbox_id_by_mailbox_type(multi_user_name, mail_data->account_id, EMAIL_MAILBOX_TYPE_SPAMBOX, &mailbox_id_spam, false, &err)) { + EM_DEBUG_EXCEPTION("emstorage_get_mailbox_name_by_mailbox_type failed [%d]", err); + mailbox_id_spam = 0; + } - if (mailbox_id_spam) - mailbox_id_target = mailbox_id_spam; - } - } - } + if (mailbox_id_spam) + mailbox_id_target = mailbox_id_spam; + } + } + } } if ((err = emstorage_get_mailbox_by_id(multi_user_name, mailbox_id_target, (emstorage_mailbox_tbl_t**)&mailbox_tbl)) != EMAIL_ERROR_NONE) { @@ -924,10 +926,10 @@ INTERNAL_FUNC int emcore_add_mail(char *multi_user_name, email_mail_data_t *inpu } if (mail_data->file_path_plain) { - memset(name_buf, 0x00, sizeof(name_buf)); - memset(path_buf, 0x00, sizeof(path_buf)); - memset(real_file_path, 0x00, sizeof(real_file_path)); - SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, mail_data->file_path_plain); + memset(name_buf, 0x00, sizeof(name_buf)); + memset(path_buf, 0x00, sizeof(path_buf)); + memset(real_file_path, 0x00, sizeof(real_file_path)); + SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, mail_data->file_path_plain); EM_DEBUG_LOG_SEC("mail_data->file_path_plain [%s]", mail_data->file_path_plain); /* EM_SAFE_STRNCPY(body_text_file_name, "UTF-8", MAX_PATH); */ @@ -939,15 +941,15 @@ INTERNAL_FUNC int emcore_add_mail(char *multi_user_name, email_mail_data_t *inpu } /* - if (input_from_eas) - EM_SAFE_STRNCPY(body_text_file_name, UNKNOWN_CHARSET_PLAIN_TEXT_FILE, MAX_PATH); - else - EM_SAFE_STRNCPY(body_text_file_name, "UTF-8", MAX_PATH); - */ + if (input_from_eas) + EM_SAFE_STRNCPY(body_text_file_name, UNKNOWN_CHARSET_PLAIN_TEXT_FILE, MAX_PATH); + else + EM_SAFE_STRNCPY(body_text_file_name, "UTF-8", MAX_PATH); + */ if (!emstorage_get_save_name(multi_user_name, mail_data->account_id, mail_data->mail_id, - 0, body_text_file_name, name_buf, path_buf, - sizeof(path_buf), &err)) { + 0, body_text_file_name, name_buf, path_buf, + sizeof(path_buf), &err)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); goto FINISH_OFF; } @@ -964,10 +966,10 @@ INTERNAL_FUNC int emcore_add_mail(char *multi_user_name, email_mail_data_t *inpu } if (mail_data->file_path_html) { - memset(name_buf, 0x00, sizeof(name_buf)); - memset(path_buf, 0x00, sizeof(path_buf)); - memset(real_file_path, 0x00, sizeof(real_file_path)); - SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, mail_data->file_path_html); + memset(name_buf, 0x00, sizeof(name_buf)); + memset(path_buf, 0x00, sizeof(path_buf)); + memset(real_file_path, 0x00, sizeof(real_file_path)); + SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, mail_data->file_path_html); EM_DEBUG_LOG_SEC("mail_data->file_path_html [%s]", mail_data->file_path_html); /* EM_SAFE_STRNCPY(body_text_file_name, "UTF-8.htm", MAX_PATH); */ @@ -980,15 +982,15 @@ INTERNAL_FUNC int emcore_add_mail(char *multi_user_name, email_mail_data_t *inpu goto FINISH_OFF; } /* - if (input_from_eas) - EM_SAFE_STRNCPY(body_text_file_name, UNKNOWN_CHARSET_HTML_TEXT_FILE, MAX_PATH); - else - EM_SAFE_STRNCPY(body_text_file_name, "UTF-8.htm", MAX_PATH); - */ + if (input_from_eas) + EM_SAFE_STRNCPY(body_text_file_name, UNKNOWN_CHARSET_HTML_TEXT_FILE, MAX_PATH); + else + EM_SAFE_STRNCPY(body_text_file_name, "UTF-8.htm", MAX_PATH); + */ if (!emstorage_get_save_name(multi_user_name, mail_data->account_id, mail_data->mail_id, - 0, body_text_file_name, name_buf, path_buf, - sizeof(path_buf), &err)) { + 0, body_text_file_name, name_buf, path_buf, + sizeof(path_buf), &err)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); goto FINISH_OFF; } @@ -1007,16 +1009,16 @@ INTERNAL_FUNC int emcore_add_mail(char *multi_user_name, email_mail_data_t *inpu } if (mail_data->file_path_mime_entity) { - memset(name_buf, 0x00, sizeof(name_buf)); - memset(path_buf, 0x00, sizeof(path_buf)); - memset(real_file_path, 0x00, sizeof(real_file_path)); - SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, mail_data->file_path_mime_entity); + memset(name_buf, 0x00, sizeof(name_buf)); + memset(path_buf, 0x00, sizeof(path_buf)); + memset(real_file_path, 0x00, sizeof(real_file_path)); + SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, mail_data->file_path_mime_entity); EM_DEBUG_LOG_SEC("mail_data->file_path_mime_entity [%s]", mail_data->file_path_mime_entity); if (!emstorage_get_save_name(multi_user_name, mail_data->account_id, mail_data->mail_id, - 0, "mime_entity", name_buf, path_buf, - sizeof(path_buf), &err)) { + 0, "mime_entity", name_buf, path_buf, + sizeof(path_buf), &err)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); goto FINISH_OFF; } @@ -1064,10 +1066,10 @@ INTERNAL_FUNC int emcore_add_mail(char *multi_user_name, email_mail_data_t *inpu EM_DEBUG_LOG("preview_text[%p]", mail_data->preview_text); if (mail_data->preview_text == NULL) { if ((err = emcore_get_preview_text_from_file(multi_user_name, - mail_data->file_path_plain, - mail_data->file_path_html, - MAX_PREVIEW_TEXT_LENGTH, - &(mail_data->preview_text))) != EMAIL_ERROR_NONE) { + mail_data->file_path_plain, + mail_data->file_path_html, + MAX_PREVIEW_TEXT_LENGTH, + &(mail_data->preview_text))) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_get_preview_text_from_file failed[%d]", err); if (err != EMAIL_ERROR_EMPTY_FILE) @@ -1122,16 +1124,16 @@ INTERNAL_FUNC int emcore_add_mail(char *multi_user_name, email_mail_data_t *inpu if (thread_item_count > 1) { if (!emstorage_update_latest_thread_mail(multi_user_name, - mail_data->account_id, - mail_data->mailbox_id, - mail_data->mailbox_type, - converted_mail_tbl->thread_id, - &updated_thread_id, - 0, - 0, - NOTI_THREAD_ID_CHANGED_BY_ADD, - false, - &err)) { + mail_data->account_id, + mail_data->mailbox_id, + mail_data->mailbox_type, + converted_mail_tbl->thread_id, + &updated_thread_id, + 0, + 0, + NOTI_THREAD_ID_CHANGED_BY_ADD, + false, + &err)) { EM_DEBUG_EXCEPTION("emstorage_update_latest_thread_mail failed [%d]", err); emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL); goto FINISH_OFF; @@ -1144,12 +1146,12 @@ INTERNAL_FUNC int emcore_add_mail(char *multi_user_name, email_mail_data_t *inpu /* Insert attachment information to DB */ for (i = 0; i < attachment_count; i++) { - memset(name_buf, 0x00, sizeof(name_buf)); - memset(path_buf, 0x00, sizeof(path_buf)); + memset(name_buf, 0x00, sizeof(name_buf)); + memset(path_buf, 0x00, sizeof(path_buf)); - /* set attachment size */ - memset(real_file_path, 0x00, sizeof(real_file_path)); - SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, attachment_data_list[i].attachment_path); + /* set attachment size */ + memset(real_file_path, 0x00, sizeof(real_file_path)); + SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, attachment_data_list[i].attachment_path); if (attachment_data_list[i].attachment_size == 0) { if (attachment_data_list[i].attachment_path && stat(real_file_path, &st_buf) < 0) @@ -1171,13 +1173,13 @@ INTERNAL_FUNC int emcore_add_mail(char *multi_user_name, email_mail_data_t *inpu } if (!emstorage_get_save_name(multi_user_name, - mail_data->account_id, - mail_data->mail_id, attachment_data_list[i].inline_content_status ? 0 : attachment_id, - attachment_data_list[i].attachment_name, - name_buf, - path_buf, - sizeof(path_buf), - &err)) { + mail_data->account_id, + mail_data->mail_id, attachment_data_list[i].inline_content_status ? 0 : attachment_id, + attachment_data_list[i].attachment_name, + name_buf, + path_buf, + sizeof(path_buf), + &err)) { EM_DEBUG_EXCEPTION("emstorage_get_save_name failed [%d]", err); emstorage_rollback_transaction(multi_user_name, NULL, NULL, NULL); goto FINISH_OFF; @@ -1218,14 +1220,14 @@ INTERNAL_FUNC int emcore_add_mail(char *multi_user_name, email_mail_data_t *inpu goto FINISH_OFF; } - if (!mail_smime_flag) { + if (!mail_smime_flag) attachment_data_list[i].attachment_id = attachment_tbl.attachment_id; - } } #ifdef __FEATURE_BODY_SEARCH__ /* Insert mail_text to DB */ - if (!emcore_strip_mail_body_from_file(multi_user_name, converted_mail_tbl, &stripped_text, &err) || stripped_text == NULL) { + if (!emcore_strip_mail_body_from_file(multi_user_name, converted_mail_tbl, &stripped_text, &err) + || stripped_text == NULL) { EM_DEBUG_EXCEPTION("emcore_strip_mail_body_from_file failed [%d]", err); } @@ -1238,8 +1240,8 @@ INTERNAL_FUNC int emcore_add_mail(char *multi_user_name, email_mail_data_t *inpu /* Insert Meeting request to DB */ if (mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_REQUEST - || mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_RESPONSE - || mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) { + || mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_RESPONSE + || mail_data->meeting_request_status == EMAIL_MAIL_TYPE_MEETING_ORIGINATINGREQUEST) { EM_DEBUG_LOG("This mail has the meeting request"); input_meeting_request->mail_id = mail_data->mail_id; @@ -1269,10 +1271,10 @@ INTERNAL_FUNC int emcore_add_mail(char *multi_user_name, email_mail_data_t *inpu } if (input_from_eas && (mail_data->flags_seen_field == 0)) { -// && mail_data->mailbox_type != EMAIL_MAILBOX_TYPE_TRASH -// && mail_data->mailbox_type != EMAIL_MAILBOX_TYPE_SPAMBOX) { + // && mail_data->mailbox_type != EMAIL_MAILBOX_TYPE_TRASH + // && mail_data->mailbox_type != EMAIL_MAILBOX_TYPE_SPAMBOX) { if ((err = emcore_update_sync_status_of_account(multi_user_name, mail_data->account_id, SET_TYPE_SET, SYNC_STATUS_SYNCING | SYNC_STATUS_HAVE_NEW_MAILS)) != EMAIL_ERROR_NONE) - EM_DEBUG_LOG("emcore_update_sync_status_of_account failed [%d]", err); + EM_DEBUG_LOG("emcore_update_sync_status_of_account failed [%d]", err); } FINISH_OFF: @@ -1379,29 +1381,29 @@ INTERNAL_FUNC int emcore_add_read_receipt(char *multi_user_name, int input_read_ /* Report attachment */ /* Final-Recipient : rfc822;digipop@gmail.com Original-Message-ID: <r97a77ag0jdhkvvxke58u9i5.1345611508570@email.android.com> - Disposition : manual-action/MDN-sent-manually; displayed */ +Disposition : manual-action/MDN-sent-manually; displayed */ /* - receipt_mail_data->attachment_count = 1; - attachment_count = 1; + receipt_mail_data->attachment_count = 1; + attachment_count = 1; - attachment_data = em_malloc(sizeof(email_attachment_data_t)); - if (!attachment_data) { - EM_DEBUG_EXCEPTION("em_mallocfailed..."); - err = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } + attachment_data = em_malloc(sizeof(email_attachment_data_t)); + if (!attachment_data) { + EM_DEBUG_EXCEPTION("em_mallocfailed..."); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } - attachment_data->save_status = 1; - attachment_data->attachment_path = EM_SAFE_STRDUP(root_body->nested.part->next->body.sparep); + attachment_data->save_status = 1; + attachment_data->attachment_path = EM_SAFE_STRDUP(root_body->nested.part->next->body.sparep); - if (!emcore_get_file_name(attachment_data->attachment_path, &p, &err)) { - EM_DEBUG_EXCEPTION("emcore_get_file_name failed [%d]", err); - goto FINISH_OFF; - } + if (!emcore_get_file_name(attachment_data->attachment_path, &p, &err)) { + EM_DEBUG_EXCEPTION("emcore_get_file_name failed [%d]", err); + goto FINISH_OFF; + } - attachment_data->attachment_name = cpystr(p); - */ + attachment_data->attachment_name = cpystr(p); + */ if ((err = emcore_add_mail(multi_user_name, receipt_mail_data, attachment_data, attachment_count, NULL, 0, false)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_add_mail failed [%d]", err); @@ -1430,8 +1432,8 @@ FINISH_OFF: if (receipt_mail_tbl_data) emstorage_free_mail(&receipt_mail_tbl_data, 1, NULL); - if (root_body) - mail_free_body(&root_body); + if (root_body) + mail_free_body(&root_body); EM_DEBUG_FUNC_END("err [%d]", err); return err; @@ -1499,22 +1501,22 @@ INTERNAL_FUNC int emcore_query_mail_size_limit(char *multi_user_name, int accoun if (ref_account->pop_before_smtp != FALSE) { if (!emcore_connect_to_remote_mailbox(multi_user_name, - account_id, - 0, - true, - (void **)&mail_stream, - &err)) { + account_id, + 0, + true, + (void **)&mail_stream, + &err)) { EM_DEBUG_EXCEPTION(" POP before SMTP Authentication failed [%d]", err); goto FINISH_OFF; } } if (!emcore_connect_to_remote_mailbox(multi_user_name, - account_id, - EMAIL_CONNECT_FOR_SENDING, - true, - (void **)&tmp_stream, - &err)) { + account_id, + EMAIL_CONNECT_FOR_SENDING, + true, + (void **)&tmp_stream, + &err)) { EM_DEBUG_EXCEPTION(" emcore_connect_to_remote_mailbox failed [%d]", err); goto FINISH_OFF; } @@ -1571,8 +1573,8 @@ typedef struct { } email_send_stream_list_t; /* -stmp stream should be closed when threads exit, otherwise memory leaks -*/ + stmp stream should be closed when threads exit, otherwise memory leaks + */ INTERNAL_FUNC void emcore_close_smtp_stream_list() { EM_DEBUG_FUNC_BEGIN(); @@ -1591,9 +1593,9 @@ INTERNAL_FUNC void emcore_close_smtp_stream_list() } /* -if threads exit after calling the function, emcore_close_smtp_stream_list should be called. -Otherwise, memory leaks -*/ + if threads exit after calling the function, emcore_close_smtp_stream_list should be called. + Otherwise, memory leaks + */ INTERNAL_FUNC SENDSTREAM **emcore_get_smtp_stream(char *multi_user_name, int account_id, int *error) { EM_DEBUG_FUNC_BEGIN("account_id[%d]", account_id); @@ -1633,11 +1635,11 @@ INTERNAL_FUNC SENDSTREAM **emcore_get_smtp_stream(char *multi_user_name, int acc } if (!emcore_connect_to_remote_mailbox(multi_user_name, - account_id, - EMAIL_CONNECT_FOR_SENDING, - true, - (void **)ret, - &err)) { + account_id, + EMAIL_CONNECT_FOR_SENDING, + true, + (void **)ret, + &err)) { EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err); EM_SAFE_FREE(ret); @@ -1669,12 +1671,12 @@ FINISH_OFF: /* -send a mail -3 threads call this function : -worker_send_event_queue -mainloop (by alarm), -thread_func_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL, -*/ + send a mail + 3 threads call this function : + worker_send_event_queue + mainloop (by alarm), + thread_func_EMAIL_ASYNC_TASK_SEND_MAIL_WITH_DOWNLOADING_ATTACHMENT_OF_ORIGINAL_MAIL, + */ INTERNAL_FUNC int emcore_send_mail(char *multi_user_name, int mail_id, int *err_code) { @@ -1787,11 +1789,11 @@ INTERNAL_FUNC int emcore_send_mail(char *multi_user_name, int mail_id, int *err_ if (ref_account->pop_before_smtp != FALSE) { if (!emcore_connect_to_remote_mailbox(multi_user_name, - account_id, - 0, - true, - (void **)&mail_stream, - &err)) { + account_id, + 0, + true, + (void **)&mail_stream, + &err)) { EM_DEBUG_EXCEPTION(" POP before SMTP Authentication failed [%d]", err); if (err == EMAIL_ERROR_CONNECTION_BROKEN) err = EMAIL_ERROR_CANCELLED; @@ -1821,11 +1823,11 @@ INTERNAL_FUNC int emcore_send_mail(char *multi_user_name, int mail_id, int *err_ #if 0 if (!emcore_connect_to_remote_mailbox(multi_user_name, - account_id, - EMAIL_CONNECT_FOR_SENDING, - true, - (void **)&tmp_stream, - &err)) { + account_id, + EMAIL_CONNECT_FOR_SENDING, + true, + (void **)&tmp_stream, + &err)) { EM_DEBUG_EXCEPTION(" emcore_connect_to_remote_mailbox failed [%d]", err); if (err == EMAIL_ERROR_CONNECTION_BROKEN) @@ -1902,11 +1904,11 @@ INTERNAL_FUNC int emcore_send_mail(char *multi_user_name, int mail_id, int *err_ /* sent mail is moved to 'SENT' box or deleted. */ if (opt->keep_local_copy) { if (!emstorage_get_mailbox_by_mailbox_type(multi_user_name, - account_id, - EMAIL_MAILBOX_TYPE_SENTBOX, - &local_mailbox, - true, - &err)) { + account_id, + EMAIL_MAILBOX_TYPE_SENTBOX, + &local_mailbox, + true, + &err)) { EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_mailbox_type failed [%d]", err); goto FINISH_OFF; } @@ -1920,9 +1922,8 @@ INTERNAL_FUNC int emcore_send_mail(char *multi_user_name, int mail_id, int *err_ emstorage_activity_tbl_t new_activity; int activityid = 0; - if (false == emcore_get_next_activity_id(&activityid, &err)) { + if (false == emcore_get_next_activity_id(&activityid, &err)) EM_DEBUG_EXCEPTION(" emcore_get_next_activity_id Failed [%d] ", err); - } memset(&new_activity, 0x00, sizeof(emstorage_activity_tbl_t)); new_activity.activity_id = activityid; @@ -1933,9 +1934,8 @@ INTERNAL_FUNC int emcore_send_mail(char *multi_user_name, int mail_id, int *err_ new_activity.dest_mbox = NULL; new_activity.src_mbox = NULL; - if (!emcore_add_activity(&new_activity, &err)) { + if (!emcore_add_activity(&new_activity, &err)) EM_DEBUG_EXCEPTION(" emcore_add_activity Failed [%d] ", err); - } if (!emcore_move_mail_on_server(multi_user_name, dest_mbox.account_id, dst_mailbox_id, &mail_id, 1, dest_mbox.name, &err)) { EM_DEBUG_EXCEPTION(" emcore_move_mail_on_server falied [%d]", err); @@ -1949,9 +1949,8 @@ INTERNAL_FUNC int emcore_send_mail(char *multi_user_name, int mail_id, int *err_ new_activity.server_mailid = NULL; new_activity.src_mbox = NULL; - if (!emcore_delete_activity(&new_activity, &err)) { + if (!emcore_delete_activity(&new_activity, &err)) EM_DEBUG_EXCEPTION(">>>>>>Local Activity [ACTIVITY_SAVEMAIL] [%d] ", err); - } } sent_box = 1; } @@ -1959,14 +1958,14 @@ INTERNAL_FUNC int emcore_send_mail(char *multi_user_name, int mail_id, int *err_ #endif if (ref_account->incoming_server_type == EMAIL_SERVER_TYPE_IMAP4) { emstorage_mailbox_tbl_t* src_mailbox = NULL; -// emstorage_mail_tbl_t *temp_mail = NULL; + //emstorage_mail_tbl_t *temp_mail = NULL; if (!emstorage_get_mailbox_by_mailbox_type(multi_user_name, - account_id, - EMAIL_MAILBOX_TYPE_OUTBOX, - &src_mailbox, - true, - &err)) { + account_id, + EMAIL_MAILBOX_TYPE_OUTBOX, + &src_mailbox, + true, + &err)) { EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_mailbox_type failed [%d]", err); goto FINISH_OFF; } @@ -1976,28 +1975,28 @@ INTERNAL_FUNC int emcore_send_mail(char *multi_user_name, int mail_id, int *err_ /* This is syncing operation in sent box but it slowed operation */ /* - void *local_stream = NULL; - if (!emcore_sync_header (multi_user_name, local_mailbox, &local_stream, NULL, NULL, NULL, NULL, NULL, 0, -1, &err)) { - EM_DEBUG_EXCEPTION("emcore_sync_header failed"); - } - mail_close(local_stream); - if (!emstorage_get_maildata_by_servermailid(multi_user_name, - "0", - local_mailbox->mailbox_id, - &temp_mail, - false, - &err)) { - if (err != EMAIL_ERROR_MAIL_NOT_FOUND) { - EM_DEBUG_EXCEPTION("emstorage_get_maildata_by_servermailid failed : [%d]", err); - goto FINISH_OFF; - } - } - - if (temp_mail) { - emcore_sync_mail_from_client_to_server(multi_user_name, mail_id); - emstorage_free_mail(&temp_mail, 1, NULL); - } - */ + void *local_stream = NULL; + if (!emcore_sync_header (multi_user_name, local_mailbox, &local_stream, NULL, NULL, NULL, NULL, NULL, 0, -1, &err)) { + EM_DEBUG_EXCEPTION("emcore_sync_header failed"); + } + mail_close(local_stream); + if (!emstorage_get_maildata_by_servermailid(multi_user_name, + "0", + local_mailbox->mailbox_id, + &temp_mail, + false, + &err)) { + if (err != EMAIL_ERROR_MAIL_NOT_FOUND) { + EM_DEBUG_EXCEPTION("emstorage_get_maildata_by_servermailid failed : [%d]", err); + goto FINISH_OFF; + } + } + + if (temp_mail) { + emcore_sync_mail_from_client_to_server(multi_user_name, mail_id); + emstorage_free_mail(&temp_mail, 1, NULL); + } + */ /* sent box exception list : gmail (After the mail sent, moved the sent box) */ if (ref_account->outgoing_server_address) { @@ -2005,21 +2004,20 @@ INTERNAL_FUNC int emcore_send_mail(char *multi_user_name, int mail_id, int *err_ emcore_sync_mail_from_client_to_server(multi_user_name, mail_id); } else { err = emcore_sync_mail_by_message_id(multi_user_name, - mail_id, - dst_mailbox_id, - &server_uid); - if (err != EMAIL_ERROR_NONE) { + mail_id, + dst_mailbox_id, + &server_uid); + if (err != EMAIL_ERROR_NONE) EM_DEBUG_EXCEPTION("emcore_sync_mail_by_message_id failed : [%d]", err); - } EM_DEBUG_LOG("server_uid : [%s]", server_uid); if (server_uid) { if (!emstorage_update_server_uid(multi_user_name, - mail_id, - NULL, - server_uid, - &err)) { + mail_id, + NULL, + server_uid, + &err)) { EM_DEBUG_EXCEPTION("emstorage_update_server_uid failed : [%d]", err); } @@ -2038,9 +2036,9 @@ INTERNAL_FUNC int emcore_send_mail(char *multi_user_name, int mail_id, int *err_ downloaded_mail->rfc822_size = mail_tbl_data->mail_size; if (!emstorage_add_downloaded_mail(multi_user_name, - downloaded_mail, - true, - &err)) { + downloaded_mail, + true, + &err)) { EM_DEBUG_EXCEPTION("emstorage_add_downloaded_mail failed : [%d]", err); } } @@ -2048,12 +2046,12 @@ INTERNAL_FUNC int emcore_send_mail(char *multi_user_name, int mail_id, int *err_ } } else { if (!emcore_move_mail_on_server(multi_user_name, - account_id, - src_mailbox->mailbox_id, - &mail_id, - 1, - local_mailbox->mailbox_name, - &err)) { + account_id, + src_mailbox->mailbox_id, + &mail_id, + 1, + local_mailbox->mailbox_name, + &err)) { EM_DEBUG_EXCEPTION(" emcore_move_mail_on_server falied [%d]", err); } } @@ -2065,42 +2063,42 @@ INTERNAL_FUNC int emcore_send_mail(char *multi_user_name, int mail_id, int *err_ mail_tbl_data->flags_draft_field = 0; if (!emstorage_set_field_of_mails_with_integer_value(multi_user_name, - account_id, - &mail_id, - 1, - "flags_draft_field", - mail_tbl_data->flags_draft_field, - true, - &err)) + account_id, + &mail_id, + 1, + "flags_draft_field", + mail_tbl_data->flags_draft_field, + true, + &err)) EM_DEBUG_EXCEPTION("Failed to modify extra flag [%d]", err); } else { if (!emcore_delete_mail(multi_user_name, - account_id, - 0, - &mail_id, - 1, - EMAIL_DELETE_LOCALLY, - EMAIL_DELETED_AFTER_SENDING, - false, - &err)) + account_id, + 0, + &mail_id, + 1, + EMAIL_DELETE_LOCALLY, + EMAIL_DELETED_AFTER_SENDING, + false, + &err)) EM_DEBUG_EXCEPTION(" emcore_delete_mail failed [%d]", err); } /* Set the phone log */ - if ((err = emcore_set_sent_contacts_log(multi_user_name, mail_tbl_data)) != EMAIL_ERROR_NONE) { + err = emcore_set_sent_contacts_log(multi_user_name, mail_tbl_data); + if (err != EMAIL_ERROR_NONE) EM_DEBUG_EXCEPTION("emcore_set_sent_contacts_log failed : [%d]", err); - } /*Update save_status */ mail_tbl_data->save_status = EMAIL_MAIL_STATUS_SENT; if (!emstorage_set_field_of_mails_with_integer_value(multi_user_name, - account_id, - &mail_id, - 1, - "save_status", - mail_tbl_data->save_status, - true, - &err)) + account_id, + &mail_id, + 1, + "save_status", + mail_tbl_data->save_status, + true, + &err)) EM_DEBUG_EXCEPTION("emstorage_set_field_of_mails_with_integer_value failed [%d]", err); if (!emcore_delete_transaction_info_by_mailId(mail_id)) @@ -2125,13 +2123,13 @@ FINISH_OFF: else { mail_tbl_data->save_status = EMAIL_MAIL_STATUS_SEND_CANCELED; if (!emstorage_set_field_of_mails_with_integer_value(multi_user_name, - account_id, - &mail_id, - 1, - "save_status", - mail_tbl_data->save_status, - true, - &err2)) + account_id, + &mail_id, + 1, + "save_status", + mail_tbl_data->save_status, + true, + &err2)) EM_DEBUG_EXCEPTION("emstorage_set_field_of_mails_with_integer_value failed [%d]", err2); } } @@ -2246,8 +2244,8 @@ INTERNAL_FUNC int emcore_send_saved_mail(char *multi_user_name, int account_id, goto FINISH_OFF; } -/*don't delete the comment. several threads including event thread call this func */ -/* FINISH_OFF_IF_CANCELED; */ + /*don't delete the comment. several threads including event thread call this func */ + /* FINISH_OFF_IF_CANCELED; */ if (!emnetwork_check_network_status(&err)) { EM_DEBUG_EXCEPTION("emnetwork_check_network_status failed [%d]", err); @@ -2294,8 +2292,8 @@ INTERNAL_FUNC int emcore_send_saved_mail(char *multi_user_name, int account_id, emstorage_free_mailbox(&local_mailbox, 1, NULL); for (i = 0; i < total; i++) { -/*don't delete the comment. several threads including event thread call this func */ -/* FINISH_OFF_IF_CANCELED;*/ + /*don't delete the comment. several threads including event thread call this func */ + /* FINISH_OFF_IF_CANCELED;*/ if (!emstorage_get_mail_by_id(multi_user_name, mail_ids[i], &searched_mail_tbl_data, false, &err)) { EM_DEBUG_EXCEPTION("emstorage_get_mail_by_id failed [%d]", err); @@ -2329,8 +2327,8 @@ INTERNAL_FUNC int emcore_send_saved_mail(char *multi_user_name, int account_id, goto FINISH_OFF; } -/*don't delete the comment. several threads including event thread call this func */ -/* FINISH_OFF_IF_CANCELED;*/ + /*don't delete the comment. several threads including event thread call this func */ + /* FINISH_OFF_IF_CANCELED;*/ /* connect mail server. */ if (!stream) { @@ -2342,11 +2340,11 @@ INTERNAL_FUNC int emcore_send_saved_mail(char *multi_user_name, int account_id, stream = NULL; if (!emcore_connect_to_remote_mailbox(multi_user_name, - account_id, - EMAIL_CONNECT_FOR_SENDING, - true, - &tmp_stream, - &err) || !tmp_stream) { + account_id, + EMAIL_CONNECT_FOR_SENDING, + true, + &tmp_stream, + &err) || !tmp_stream) { EM_DEBUG_EXCEPTION("emcore_connect_to_remote_mailbox failed [%d]", err); if (err == EMAIL_ERROR_CONNECTION_BROKEN) @@ -2358,8 +2356,8 @@ INTERNAL_FUNC int emcore_send_saved_mail(char *multi_user_name, int account_id, stream = (SENDSTREAM *)tmp_stream; -/*don't delete the comment. several threads including event thread call this func */ -/* FINISH_OFF_IF_CANCELED;*/ + /*don't delete the comment. several threads including event thread call this func */ + /* FINISH_OFF_IF_CANCELED;*/ mail_send_notify(EMAIL_SEND_CONNECTION_SUCCEED, 0, 0, account_id, mail_ids[i], err); @@ -2394,11 +2392,11 @@ INTERNAL_FUNC int emcore_send_saved_mail(char *multi_user_name, int account_id, EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed [%d]", err); if (!emstorage_get_mailbox_by_mailbox_type(multi_user_name, - account_id, - EMAIL_MAILBOX_TYPE_OUTBOX, - &local_mailbox, - false, - &err)) { + account_id, + EMAIL_MAILBOX_TYPE_OUTBOX, + &local_mailbox, + false, + &err)) { EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_mailbox_type failed [%d]", err); goto FINISH_OFF; } @@ -2416,11 +2414,11 @@ INTERNAL_FUNC int emcore_send_saved_mail(char *multi_user_name, int account_id, /* update mail status to sent mail. */ if (!emstorage_change_mail_field(multi_user_name, - mail_ids[i], - UPDATE_EXTRA_FLAG, - searched_mail_tbl_data, - true, - &err)) { + mail_ids[i], + UPDATE_EXTRA_FLAG, + searched_mail_tbl_data, + true, + &err)) { EM_DEBUG_EXCEPTION("emstorage_change_mail_field failed [%d]", err); goto FINISH_OFF; } @@ -2428,44 +2426,44 @@ INTERNAL_FUNC int emcore_send_saved_mail(char *multi_user_name, int account_id, /* sent mail is moved to 'SENT' box or deleted. */ if (opt->keep_local_copy) { if (!emstorage_get_mailbox_by_mailbox_type(multi_user_name, - account_id, - EMAIL_MAILBOX_TYPE_SENTBOX, - &local_mailbox, - false, - &err)) { + account_id, + EMAIL_MAILBOX_TYPE_SENTBOX, + &local_mailbox, + false, + &err)) { EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_mailbox_type failed [%d]", err); goto FINISH_OFF; } dst_mailbox_id = local_mailbox->mailbox_id; if (!emcore_move_mail(multi_user_name, - &mail_ids[i], - 1, - dst_mailbox_id, - EMAIL_MOVED_AFTER_SENDING, - 0, - &err)) + &mail_ids[i], + 1, + dst_mailbox_id, + EMAIL_MOVED_AFTER_SENDING, + 0, + &err)) EM_DEBUG_EXCEPTION("emcore_mail_move falied [%d]", err); if (local_mailbox) emstorage_free_mailbox(&local_mailbox, 1, NULL); } else { if (!emcore_delete_mail(multi_user_name, - account_id, - 0, - &mail_ids[i], - 1, - EMAIL_DELETE_LOCALLY, - EMAIL_DELETED_AFTER_SENDING, - false, - &err)) + account_id, + 0, + &mail_ids[i], + 1, + EMAIL_DELETE_LOCALLY, + EMAIL_DELETED_AFTER_SENDING, + false, + &err)) EM_DEBUG_EXCEPTION("emcore_delete_mail falied [%d]", err); } /* Set the phone log */ - if ((err = emcore_set_sent_contacts_log(multi_user_name, searched_mail_tbl_data)) != EMAIL_ERROR_NONE) { + err = emcore_set_sent_contacts_log(multi_user_name, searched_mail_tbl_data); + if (err != EMAIL_ERROR_NONE) EM_DEBUG_EXCEPTION("emcore_set_sent_contacts_log failed : [%d]", err); - } if (searched_mail_tbl_data) { emstorage_free_mail(&searched_mail_tbl_data, 1, NULL); @@ -2539,15 +2537,15 @@ FINISH_OFF: } static int emcore_send_mail_smtp(char *multi_user_name, - SENDSTREAM *stream, - ENVELOPE *env, - char *data_file, - int account_id, - int mail_id, - int *err_code) + SENDSTREAM *stream, + ENVELOPE *env, + char *data_file, + int account_id, + int mail_id, + int *err_code) { EM_DEBUG_FUNC_BEGIN_SEC("stream[%p], env[%p], data_file[%s], account_id[%d], mail_id[%d], err_code[%p]", - stream, env, data_file, account_id, mail_id, err_code); + stream, env, data_file, account_id, mail_id, err_code); EM_PROFILE_BEGIN(profile_emcore_send_mail_smtp); int ret = false; @@ -2598,7 +2596,7 @@ static int emcore_send_mail_smtp(char *multi_user_name, if (stream->protocol.esmtp.dsn.envid) SNPRINTF(buf + EM_SAFE_STRLEN(buf), sizeof(buf)-(EM_SAFE_STRLEN(buf)), - " ENVID=%.100s", stream->protocol.esmtp.dsn.envid); + " ENVID=%.100s", stream->protocol.esmtp.dsn.envid); } else EM_DEBUG_LOG("stream->protocol.esmtp.dsn.want is not required or DSN is not supported"); } @@ -2616,27 +2614,27 @@ static int emcore_send_mail_smtp(char *multi_user_name, EM_DEBUG_LOG_SEC("[SMTP] MAIL %s --------> %s", buf, stream->reply); switch (send_ret) { - case SMTP_RESPONSE_OK: - break; + case SMTP_RESPONSE_OK: + break; - case SMTP_RESPONSE_WANT_AUTH: - case SMTP_RESPONSE_WANT_AUTH2: - EM_DEBUG_EXCEPTION("SMTP error : authentication required..."); - err = EMAIL_ERROR_AUTH_REQUIRED; - goto FINISH_OFF; + case SMTP_RESPONSE_WANT_AUTH: + case SMTP_RESPONSE_WANT_AUTH2: + EM_DEBUG_EXCEPTION("SMTP error : authentication required..."); + err = EMAIL_ERROR_AUTH_REQUIRED; + goto FINISH_OFF; - case SMTP_RESPONSE_UNAVAIL: - EM_DEBUG_EXCEPTION("SMTP error : sending unavailable..."); - err = EMAIL_ERROR_SMTP_SEND_FAILURE; - goto FINISH_OFF; - case SMTP_RESPONSE_CONNECTION_BROKEN: - EM_DEBUG_EXCEPTION("SMTP error : SMTP connection broken..."); - err = EMAIL_ERROR_SMTP_SEND_FAILURE; - goto FINISH_OFF; - default: - EM_DEBUG_EXCEPTION("SMTP error : sending unavailable..."); - err = EMAIL_ERROR_SMTP_SEND_FAILURE; - goto FINISH_OFF; + case SMTP_RESPONSE_UNAVAIL: + EM_DEBUG_EXCEPTION("SMTP error : sending unavailable..."); + err = EMAIL_ERROR_SMTP_SEND_FAILURE; + goto FINISH_OFF; + case SMTP_RESPONSE_CONNECTION_BROKEN: + EM_DEBUG_EXCEPTION("SMTP error : SMTP connection broken..."); + err = EMAIL_ERROR_SMTP_SEND_FAILURE; + goto FINISH_OFF; + default: + EM_DEBUG_EXCEPTION("SMTP error : sending unavailable..."); + err = EMAIL_ERROR_SMTP_SEND_FAILURE; + goto FINISH_OFF; } if (env->to) { @@ -2684,15 +2682,15 @@ static int emcore_send_mail_smtp(char *multi_user_name, EM_DEBUG_EXCEPTION("No valid recipients..."); switch (stream->replycode) { - case SMTP_RESPONSE_UNAVAIL: - case SMTP_RESPONSE_WANT_AUTH: - case SMTP_RESPONSE_WANT_AUTH2: - err = EMAIL_ERROR_AUTH_REQUIRED; - break; + case SMTP_RESPONSE_UNAVAIL: + case SMTP_RESPONSE_WANT_AUTH: + case SMTP_RESPONSE_WANT_AUTH2: + err = EMAIL_ERROR_AUTH_REQUIRED; + break; - default: - err = EMAIL_ERROR_INVALID_ADDRESS; - break; + default: + err = EMAIL_ERROR_INVALID_ADDRESS; + break; } goto FINISH_OFF; } @@ -2784,7 +2782,7 @@ static int emcore_send_mail_smtp(char *multi_user_name, emcore_update_notification_for_send(account_id, mail_id, progress); } EM_DEBUG_LOG("Sent data Successfully. sent[%d] total[%d] datasize[%d]", - sent, total, dataSize); + sent, total, dataSize); } total -= dataSize; } @@ -2903,7 +2901,7 @@ char *emcore_generate_content_id_string(const char *hostname, int *err) /* data_len : length of data. if filename not NULL, ignored. */ /* file_name : attahcment name. */ static int attach_part(BODY *body, const unsigned char *data, int data_len, - char *filename, char *content_sub_type, int is_inline, int *err_code) + char *filename, char *content_sub_type, int is_inline, int *err_code) { EM_DEBUG_FUNC_BEGIN_SEC("body[%p], data[%s], data_len[%d], filename[%s], content_sub_type[%s], err_code[%p]", body, data, data_len, filename, content_sub_type, err_code); @@ -3327,7 +3325,7 @@ static int attach_attachment_to_body(char *multi_user_name, BODY **multipart_bod char *name = NULL; struct stat st_buf; - if (EM_SAFE_STRLEN(multi_user_name) > 0) { + if (EM_SAFE_STRLEN(multi_user_name) > 0) { error = emcore_get_container_path(multi_user_name, &prefix_path); if (error != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_get_container_path failed : [%d]", error); @@ -3342,8 +3340,8 @@ static int attach_attachment_to_body(char *multi_user_name, BODY **multipart_bod EM_DEBUG_LOG("insert files - attachment id[%d]", temp_attachment_tbl->attachment_id); - memset(real_file_path, 0x00, sizeof(real_file_path)); - SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, temp_attachment_tbl->attachment_path); + memset(real_file_path, 0x00, sizeof(real_file_path)); + SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, temp_attachment_tbl->attachment_path); if (stat(temp_attachment_tbl->attachment_path, &st_buf) == 0) { if (!temp_attachment_tbl->attachment_name) { @@ -3394,7 +3392,7 @@ static char *emcore_encode_rfc2047_text(char *utf8_text, int *err_code) if (len > 0) { return emcore_gmime_get_encoding_to_utf8(utf8_text); -// return g_strdup(utf8_text); /* emoji handle */ + // return g_strdup(utf8_text); /* emoji handle */ } else return strdup(""); } @@ -3420,12 +3418,12 @@ static int emcore_make_envelope_from_mail(char *multi_user_name, emstorage_mail_ { EM_DEBUG_FUNC_BEGIN("input_mail_tbl_data[%p], output_envelope[%p]", input_mail_tbl_data, output_envelope); - int ret = false; - int error = EMAIL_ERROR_NONE; - int is_incomplete = 0; - char *pAdd = NULL; - ENVELOPE *envelope = NULL; - email_account_t *ref_account = NULL; + int ret = false; + int error = EMAIL_ERROR_NONE; + int is_incomplete = 0; + char *pAdd = NULL; + ENVELOPE *envelope = NULL; + email_account_t *ref_account = NULL; if (!input_mail_tbl_data || !output_envelope) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); @@ -3487,8 +3485,8 @@ static int emcore_make_envelope_from_mail(char *multi_user_name, emstorage_mail_ envelope->from->personal = cpystr(ref_account->options.display_name_from); else envelope->from->personal = - (ref_account->user_display_name && ref_account->user_display_name[0] != '\0') ? - cpystr(ref_account->user_display_name) : NULL; + (ref_account->user_display_name && ref_account->user_display_name[0] != '\0') ? + cpystr(ref_account->user_display_name) : NULL; } } } @@ -3505,13 +3503,13 @@ static int emcore_make_envelope_from_mail(char *multi_user_name, emstorage_mail_ EM_SAFE_FREE(p); } } else { -/* - if (input_mail_tbl_data->full_address_from == NULL) { - EM_DEBUG_EXCEPTION("input_mail_tbl_data->full_address_from[%p]", input_mail_tbl_data->full_address_from); - error = EMAIL_ERROR_INVALID_MAIL; - goto FINISH_OFF; - } -*/ + /* + if (input_mail_tbl_data->full_address_from == NULL) { + EM_DEBUG_EXCEPTION("input_mail_tbl_data->full_address_from[%p]", input_mail_tbl_data->full_address_from); + error = EMAIL_ERROR_INVALID_MAIL; + goto FINISH_OFF; + } + */ int i, j; if (input_mail_tbl_data->full_address_from) { @@ -3588,7 +3586,7 @@ static int emcore_make_envelope_from_mail(char *multi_user_name, emstorage_mail_ em_skip_whitespace(input_mail_tbl_data->full_address_bcc , &pAdd); rfc822_parse_adrlist(&envelope->bcc, pAdd, NULL); EM_SAFE_FREE(pAdd); - pAdd = NULL ; + pAdd = NULL ; emcore_encode_rfc2047_address(envelope->return_path, &error); emcore_encode_rfc2047_address(envelope->from, &error); @@ -3599,7 +3597,8 @@ static int emcore_make_envelope_from_mail(char *multi_user_name, emstorage_mail_ emcore_encode_rfc2047_address(envelope->bcc, &error); if (input_mail_tbl_data->subject) { - envelope->subject = emcore_encode_rfc2047_text(input_mail_tbl_data->subject, &error); + envelope->subject = emcore_encode_rfc2047_text( + input_mail_tbl_data->subject, &error); } char rfc822_date_string[DATE_STR_LENGTH] = { 0, }; @@ -3635,14 +3634,14 @@ static int emcore_make_envelope_from_mail(char *multi_user_name, emstorage_mail_ zone += ((julian < 0) == (abs(julian) == 1)) ? -24 * 60 : 24*60; SNPRINTF(localtime_string, DATE_STR_LENGTH, "%s, %d %s %d %02d:%02d:%02d " - , days[t->tm_wday] - , t->tm_mday - , months[t->tm_mon] - , t->tm_year + 1900 - , t->tm_hour - , t->tm_min - , t->tm_sec - ); + , days[t->tm_wday] + , t->tm_mday + , months[t->tm_mon] + , t->tm_year + 1900 + , t->tm_hour + , t->tm_min + , t->tm_sec + ); EM_DEBUG_LOG("localtime string : [%s]", localtime_string); /* append last 5byes("+0900") */ @@ -3737,9 +3736,9 @@ static char *emcore_get_digest_string(int digest_type, int mime_type) /* Description : Make RFC822 text file from mail_tbl data */ /* Parameters : */ -/* input_mail_tbl_data : */ -/* is_draft : this mail is draft mail. */ -/* file_path : path of file that rfc822 data will be written to. */ +/* input_mail_tbl_data : */ +/* is_draft : this mail is draft mail. */ +/* file_path : path of file that rfc822 data will be written to. */ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(char *multi_user_name, emstorage_mail_tbl_t *input_mail_tbl_data, emstorage_attachment_tbl_t *input_attachment_tbl, int input_attachment_count, ENVELOPE **env, char **file_path, email_option_t *sending_option, int *err_code) { EM_DEBUG_FUNC_BEGIN("input_mail_tbl_data[%p], env[%p], file_path[%p], sending_option[%p], err_code[%p]", input_mail_tbl_data, env, file_path, sending_option, err_code); @@ -3796,7 +3795,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(char *multi_user_name, emsto goto FINISH_OFF; } - if (EM_SAFE_STRLEN(multi_user_name) > 0) { + if (EM_SAFE_STRLEN(multi_user_name) > 0) { error = emcore_get_container_path(multi_user_name, &prefix_path); if (error != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_get_container_path failed : [%d]", error); @@ -3875,7 +3874,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(char *multi_user_name, emsto root_body->parameter = param; if (input_mail_tbl_data->smime_type == EMAIL_SMIME_NONE && - (input_mail_tbl_data->file_path_plain && input_mail_tbl_data->file_path_html)) { + (input_mail_tbl_data->file_path_plain && input_mail_tbl_data->file_path_html)) { /* Multipart/mixed -> multipart/related -> multipart/alternative : has inline content and */ /* Multipart/mixed -> Multipart/alternative */ @@ -3899,8 +3898,8 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(char *multi_user_name, emsto if (strlen(input_mail_tbl_data->file_path_plain) > 0) { EM_DEBUG_LOG_SEC("file_path_plain[%s]", input_mail_tbl_data->file_path_plain); - memset(real_file_path, 0x00, sizeof(real_file_path)); - SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_tbl_data->file_path_plain); + memset(real_file_path, 0x00, sizeof(real_file_path)); + SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_tbl_data->file_path_plain); text_body = &(part_for_alternative->body); if (!attach_part(text_body, (unsigned char *)real_file_path, 0, NULL, "plain", false, &error)) { @@ -3912,8 +3911,8 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(char *multi_user_name, emsto if (strlen(input_mail_tbl_data->file_path_html) > 0) { EM_DEBUG_LOG_SEC("file_path_html[%s]", input_mail_tbl_data->file_path_html); - memset(real_file_path, 0x00, sizeof(real_file_path)); - SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_tbl_data->file_path_html); + memset(real_file_path, 0x00, sizeof(real_file_path)); + SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_tbl_data->file_path_html); html_body = &(part_for_alternative->body); if (!attach_part(html_body, (unsigned char *)real_file_path, 0, NULL, "html", false, &error)) { @@ -3922,12 +3921,12 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(char *multi_user_name, emsto } } } else if (input_mail_tbl_data->smime_type == EMAIL_SMIME_NONE && - (input_mail_tbl_data->file_path_plain || input_mail_tbl_data->file_path_html)) { + (input_mail_tbl_data->file_path_plain || input_mail_tbl_data->file_path_html)) { if (input_mail_tbl_data->file_path_plain && EM_SAFE_STRLEN(input_mail_tbl_data->file_path_plain) > 0) { EM_DEBUG_LOG_SEC("file_path_plain[%s]", input_mail_tbl_data->file_path_plain); - memset(real_file_path, 0x00, sizeof(real_file_path)); - SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_tbl_data->file_path_plain); + memset(real_file_path, 0x00, sizeof(real_file_path)); + SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_tbl_data->file_path_plain); if (!attach_part(root_body, (unsigned char *)real_file_path, 0, NULL, "plain", false, &error)) { EM_DEBUG_EXCEPTION("attach_partfailed [%d]", error); @@ -3946,18 +3945,18 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(char *multi_user_name, emsto } } - memset(real_file_path, 0x00, sizeof(real_file_path)); - SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_tbl_data->file_path_html); + memset(real_file_path, 0x00, sizeof(real_file_path)); + SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_tbl_data->file_path_html); if (part_for_related) { if (!attach_part(&(part_for_related->body), (unsigned char *)real_file_path, 0, - NULL, "html", false, &error)) { + NULL, "html", false, &error)) { EM_DEBUG_EXCEPTION("attach_partfailed [%d]", error); goto FINISH_OFF; } } else { if (!attach_part(root_body, (unsigned char *)real_file_path, 0, - NULL, "html", false, &error)) { + NULL, "html", false, &error)) { EM_DEBUG_EXCEPTION("attach_partfailed [%d]", error); goto FINISH_OFF; } @@ -3967,8 +3966,8 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(char *multi_user_name, emsto if (input_mail_tbl_data->file_path_mime_entity && EM_SAFE_STRLEN(input_mail_tbl_data->file_path_mime_entity) > 0) { EM_DEBUG_LOG_SEC("file_path_mime_entity[%s]", input_mail_tbl_data->file_path_mime_entity); - memset(real_file_path, 0x00, sizeof(real_file_path)); - SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_tbl_data->file_path_mime_entity); + memset(real_file_path, 0x00, sizeof(real_file_path)); + SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_tbl_data->file_path_mime_entity); root_body->sparep = EM_SAFE_STRDUP(input_mail_tbl_data->file_path_mime_entity); } @@ -4009,16 +4008,16 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(char *multi_user_name, emsto else body_to_attach = root_body; - memset(real_file_path, 0x00, sizeof(real_file_path)); - SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, temp_attachment_tbl->attachment_path); + memset(real_file_path, 0x00, sizeof(real_file_path)); + SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, temp_attachment_tbl->attachment_path); if (!attach_part(body_to_attach, - (unsigned char *)real_file_path, - 0, - name, - temp_attachment_tbl->attachment_mime_type, - temp_attachment_tbl->attachment_inline_content_status, - &error)) { + (unsigned char *)real_file_path, + 0, + name, + temp_attachment_tbl->attachment_mime_type, + temp_attachment_tbl->attachment_inline_content_status, + &error)) { EM_DEBUG_EXCEPTION("attach_partfailed [%d]", error); continue; } @@ -4041,8 +4040,8 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(char *multi_user_name, emsto if (strlen(input_mail_tbl_data->file_path_plain) > 0) { EM_DEBUG_LOG_SEC("file_path_plain[%s]", input_mail_tbl_data->file_path_plain); - memset(real_file_path, 0x00, sizeof(real_file_path)); - SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_tbl_data->file_path_plain); + memset(real_file_path, 0x00, sizeof(real_file_path)); + SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_tbl_data->file_path_plain); if (!attach_part(root_body, (unsigned char *)real_file_path, 0, NULL, "plain", false, &error)) { EM_DEBUG_EXCEPTION("attach_partfailed [%d]", error); @@ -4053,8 +4052,8 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(char *multi_user_name, emsto if (strlen(input_mail_tbl_data->file_path_html) > 0) { EM_DEBUG_LOG_SEC("file_path_html[%s]", input_mail_tbl_data->file_path_html); - memset(real_file_path, 0x00, sizeof(real_file_path)); - SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_tbl_data->file_path_html); + memset(real_file_path, 0x00, sizeof(real_file_path)); + SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_tbl_data->file_path_html); if (!attach_part(root_body, (unsigned char *)real_file_path, 0, NULL, "html", false, &error)) { EM_DEBUG_EXCEPTION("attach_partfailed [%d]", error); @@ -4065,18 +4064,18 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(char *multi_user_name, emsto root_body->type = TYPETEXT; root_body->encoding = ENC8BIT; if (input_mail_tbl_data->file_path_plain || input_mail_tbl_data->file_path_html) { - if (input_mail_tbl_data->file_path_plain) { - memset(real_file_path, 0x00, sizeof(real_file_path)); - SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_tbl_data->file_path_plain); - } else { - memset(real_file_path, 0x00, sizeof(real_file_path)); - SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_tbl_data->file_path_html); - } + if (input_mail_tbl_data->file_path_plain) { + memset(real_file_path, 0x00, sizeof(real_file_path)); + SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_tbl_data->file_path_plain); + } else { + memset(real_file_path, 0x00, sizeof(real_file_path)); + SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, input_mail_tbl_data->file_path_html); + } root_body->sparep = EM_SAFE_STRDUP(real_file_path); - } - else + } else { root_body->sparep = NULL; + } if (input_mail_tbl_data->file_path_html != NULL && input_mail_tbl_data->file_path_html[0] != '\0') root_body->subtype = strdup("html"); @@ -4097,7 +4096,7 @@ INTERNAL_FUNC int emcore_make_rfc822_file_from_mail(char *multi_user_name, emsto EM_DEBUG_LOG("write rfc822 : file_path[%p]", file_path); if ((error = emcore_write_rfc822(envelope, root_body, input_mail_tbl_data->priority, - input_mail_tbl_data->report_status, file_path)) != EMAIL_ERROR_NONE) { + input_mail_tbl_data->report_status, file_path)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_write_rfc822 failed [%d]", error); goto FINISH_OFF; } @@ -4256,11 +4255,11 @@ static int emcore_get_report_mail_body(char *multi_user_name, ENVELOPE *envelope } /* - if (envelope->from->personal) - SNPRINTF(buf, sizeof(buf), "%s <%s@%s>", envelope->from->personal, envelope->from->mailbox, envelope->from->host); - else - */ - SNPRINTF(buf, sizeof(buf), "%s@%s", envelope->from->mailbox, envelope->from->host); + if (envelope->from->personal) + SNPRINTF(buf, sizeof(buf), "%s <%s@%s>", envelope->from->personal, envelope->from->mailbox, envelope->from->host); + else + */ + SNPRINTF(buf, sizeof(buf), "%s@%s", envelope->from->mailbox, envelope->from->host); fprintf(fp, "Your message has been read by %s"CRLF_STRING, buf); fprintf(fp, "Date : %s", envelope->date); @@ -4300,12 +4299,12 @@ static int emcore_get_report_mail_body(char *multi_user_name, ENVELOPE *envelope fclose(fp); fp = NULL; - temp_attachment_tbl = (emstorage_attachment_tbl_t *)em_malloc(sizeof(emstorage_attachment_tbl_t)); - if (temp_attachment_tbl == NULL) { - EM_DEBUG_EXCEPTION("em_mallocfailed"); - err = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } + temp_attachment_tbl = (emstorage_attachment_tbl_t *)em_malloc(sizeof(emstorage_attachment_tbl_t)); + if (temp_attachment_tbl == NULL) { + EM_DEBUG_EXCEPTION("em_mallocfailed"); + err = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } temp_attachment_tbl->attachment_path = EM_SAFE_STRDUP(fname); @@ -4376,8 +4375,8 @@ FINISH_OFF: EM_SAFE_FREE(fname); - if (temp_attachment_tbl) - emstorage_free_attachment(&temp_attachment_tbl, 1, NULL); + if (temp_attachment_tbl) + emstorage_free_attachment(&temp_attachment_tbl, 1, NULL); if (err_code != NULL) *err_code = err; @@ -4469,14 +4468,14 @@ static int emcore_copy_attachment_from_original_mail(char *multi_user_name, int EM_DEBUG_LOG("attachment_inline_content_status [%d] attachment_id[%d]", target_attach->attachment_inline_content_status, attachment_id); if (!emcore_save_mail_file(multi_user_name, - target_attach->account_id, - target_attach->mail_id, - attachment_id, - original_mail_attachment_array[i].attachment_path, - original_mail_attachment_array[i].attachment_name, - output_file_path, - virtual_file_path, - &err)) { + target_attach->account_id, + target_attach->mail_id, + attachment_id, + original_mail_attachment_array[i].attachment_path, + original_mail_attachment_array[i].attachment_name, + output_file_path, + virtual_file_path, + &err)) { EM_DEBUG_EXCEPTION("emcore_save_mail_file failed [%d]", err); goto FINISH_OFF; } @@ -4547,7 +4546,7 @@ INTERNAL_FUNC int emcore_send_mail_with_downloading_attachment_of_original_mail( for (i = 0; i < attachment_count; i++) { if (attachment_array[i].save_status != 1) { /* this function is not run by event thread, - so cancellable should be set to 0*/ + so cancellable should be set to 0*/ if (!emcore_gmime_download_attachment(multi_user_name, original_mail->mail_id, i + 1, 0, -1, 0, &err)) { EM_DEBUG_EXCEPTION("emcore_gmime_download_attachment failed [%d]", err); goto FINISH_OFF; @@ -4630,11 +4629,11 @@ static int emcore_sending_alarm_cb(email_alarm_data_t *alarm_data, void *user_pa #ifdef __FEATURE_MOVE_TO_OUTBOX_FIRST__ if (!emstorage_get_mailbox_by_mailbox_type(multi_user_name, - account_id, - EMAIL_MAILBOX_TYPE_OUTBOX, - &outbox_tbl, - false, - &err)) { + account_id, + EMAIL_MAILBOX_TYPE_OUTBOX, + &outbox_tbl, + false, + &err)) { EM_DEBUG_EXCEPTION("emstorage_get_mailbox_by_mailbox_type failed : [%d]", err); goto FINISH_OFF; } @@ -4645,12 +4644,12 @@ static int emcore_sending_alarm_cb(email_alarm_data_t *alarm_data, void *user_pa if (mail_data->mailbox_id != dst_mailbox_id) { if (!emcore_move_mail(multi_user_name, - &input_mail_id, - 1, - dst_mailbox_id, - EMAIL_MOVED_AFTER_SENDING, - 0, - &err)) { + &input_mail_id, + 1, + dst_mailbox_id, + EMAIL_MOVED_AFTER_SENDING, + 0, + &err)) { EM_DEBUG_EXCEPTION("emcore_move_mail failed : [%d]", err); goto FINISH_OFF; } @@ -4658,13 +4657,13 @@ static int emcore_sending_alarm_cb(email_alarm_data_t *alarm_data, void *user_pa #endif /* __FEATURE_MOVE_TO_OUTBOX_FIRST__ */ if (!emstorage_set_field_of_mails_with_integer_value(multi_user_name, - account_id, - &input_mail_id, - 1, - "save_status", - EMAIL_MAIL_STATUS_SEND_WAIT, - true, - &err)) { + account_id, + &input_mail_id, + 1, + "save_status", + EMAIL_MAIL_STATUS_SEND_WAIT, + true, + &err)) { EM_DEBUG_EXCEPTION("emstorage_set_field_of_mails_with_integer_value failed : [%d]", err); goto FINISH_OFF; } @@ -4693,13 +4692,13 @@ FINISH_OFF: if (err != EMAIL_ERROR_NONE) { if (!emstorage_set_field_of_mails_with_integer_value(multi_user_name, - account_id, - &input_mail_id, - 1, - "save_status", - EMAIL_MAIL_STATUS_SAVED, - true, - &err)) + account_id, + &input_mail_id, + 1, + "save_status", + EMAIL_MAIL_STATUS_SAVED, + true, + &err)) EM_DEBUG_EXCEPTION("emstorage_set_field_of_mails_with_integer_value failed : [%d]", err); if (event_data) { @@ -4733,24 +4732,24 @@ INTERNAL_FUNC int emcore_schedule_sending_mail(char *multi_user_name, int input_ } if (!emstorage_set_field_of_mails_with_integer_value(multi_user_name, - mail_data->account_id, - &(mail_data->mail_id), - 1, - "scheduled_sending_time", - input_time_to_send, - true, - &err)) { + mail_data->account_id, + &(mail_data->mail_id), + 1, + "scheduled_sending_time", + input_time_to_send, + true, + &err)) { EM_DEBUG_EXCEPTION("emstorage_set_field_of_mails_with_integer_value failed [%d]", err); goto FINISH_OFF; } /* add alarm */ if ((err = emcore_add_alarm(multi_user_name, - input_time_to_send, - EMAIL_ALARM_CLASS_SCHEDULED_SENDING, - input_mail_id, - emcore_sending_alarm_cb, - NULL)) != EMAIL_ERROR_NONE) { + input_time_to_send, + EMAIL_ALARM_CLASS_SCHEDULED_SENDING, + input_mail_id, + emcore_sending_alarm_cb, + NULL)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_add_alarm failed [%d]", err); goto FINISH_OFF; } @@ -4852,13 +4851,13 @@ static int emcore_auto_resend_cb(email_alarm_data_t *alarm_data, void *user_para if (attribute_field_name) { if (!emstorage_set_field_of_mails_with_integer_value(multi_user_name, - result_mail_list[i].account_id, - &(result_mail_list[i].mail_id), - 1, - attribute_field_name, - result_mail_list[i].remaining_resend_times - 1, - true, - &err)) { + result_mail_list[i].account_id, + &(result_mail_list[i].mail_id), + 1, + attribute_field_name, + result_mail_list[i].remaining_resend_times - 1, + true, + &err)) { EM_DEBUG_EXCEPTION("emstorage_set_field_of_mails_with_integer_value failed [%d]", err); } } diff --git a/email-core/email-storage/email-storage.c b/email-core/email-storage/email-storage.c index 55e411d..96b2bea 100755 --- a/email-core/email-storage/email-storage.c +++ b/email-core/email-storage/email-storage.c @@ -1,23 +1,23 @@ /* -* email-service -* -* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. -* -* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* -*/ + * email-service + * + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ /****************************************************************************** @@ -265,7 +265,7 @@ int emstorage_set_db_handle(char *multi_user_name, sqlite3 *db_handle) if (_db_handle_list[i].thread_id == 0) { _db_handle_list[i].thread_id = current_thread_id; _db_handle_list[i].db_handle = db_handle; - /* Only distinguished container and host */ + /* Only distinguished container and host */ _db_handle_list[i].user_name = EM_SAFE_STRDUP(multi_user_name); EM_DEBUG_LOG("current_thread_id [%d], index [%d]", current_thread_id, i); error_code = EMAIL_ERROR_NONE; @@ -319,7 +319,7 @@ int emstorage_reset_db_handle_list() } LEAVE_CRITICAL_SECTION(_db_handle_lock) - EM_DEBUG_FUNC_END(); + EM_DEBUG_FUNC_END(); return EMAIL_ERROR_NONE; } @@ -366,7 +366,7 @@ int shm_fd_for_generating_mail_id = 0; #else /* __FEATURE_USE_SHARED_MUTEX_FOR_PROTECTED_FUNC_CALL__ */ #define EMSTORAGE_PROTECTED_FUNC_CALL(function_call, return_value) \ - { return_value = function_call; } +{ return_value = function_call; } #endif /* __FEATURE_USE_SHARED_MUTEX_FOR_PROTECTED_FUNC_CALL__ */ static int emstorage_exec_query_by_prepare_v2(sqlite3 *local_db_handle, char *query_string) @@ -378,11 +378,11 @@ static int emstorage_exec_query_by_prepare_v2(sqlite3 *local_db_handle, char *qu EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, query_string, EM_SAFE_STRLEN(query_string), &db_statement, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_prepare failed [%d] [%s]", rc, query_string)); + ("sqlite3_prepare failed [%d] [%s]", rc, query_string)); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(db_statement), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step failed [%d] [%s]", rc, query_string)); + ("sqlite3_step failed [%d] [%s]", rc, query_string)); FINISH_OFF: @@ -480,29 +480,29 @@ int _initialize_shm_mutex(const char *shm_file_name, int *param_shm_fd, mmapped_ } } - fchmod((*param_shm_fd), 0666); - EM_DEBUG_LOG("** Create SHM FILE **"); - if (ftruncate((*param_shm_fd), sizeof(mmapped_t)) != 0) { - EM_DEBUG_EXCEPTION("ftruncate errno [%d]", errno); - return EMAIL_ERROR_SYSTEM_FAILURE; - } + fchmod((*param_shm_fd), 0666); + EM_DEBUG_LOG("** Create SHM FILE **"); + if (ftruncate((*param_shm_fd), sizeof(mmapped_t)) != 0) { + EM_DEBUG_EXCEPTION("ftruncate errno [%d]", errno); + return EMAIL_ERROR_SYSTEM_FAILURE; + } - mmapped_t *tmp = (mmapped_t *)mmap(NULL, sizeof(mmapped_t), PROT_READ|PROT_WRITE, MAP_SHARED, (*param_shm_fd), 0); - if (tmp == MAP_FAILED) { - EM_DEBUG_EXCEPTION("mmap failed: %s", EM_STRERROR(errno_buf)); - return EMAIL_ERROR_SYSTEM_FAILURE; - } + mmapped_t *tmp = (mmapped_t *)mmap(NULL, sizeof(mmapped_t), PROT_READ|PROT_WRITE, MAP_SHARED, (*param_shm_fd), 0); + if (tmp == MAP_FAILED) { + EM_DEBUG_EXCEPTION("mmap failed: %s", EM_STRERROR(errno_buf)); + return EMAIL_ERROR_SYSTEM_FAILURE; + } - tmp->data = 0; + tmp->data = 0; - pthread_mutexattr_t mattr; - pthread_mutexattr_init(&mattr); - pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED); - pthread_mutexattr_setrobust(&mattr, PTHREAD_MUTEX_ROBUST_NP); - pthread_mutex_init(&(tmp->mutex), &mattr); - pthread_mutexattr_destroy(&mattr); + pthread_mutexattr_t mattr; + pthread_mutexattr_init(&mattr); + pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED); + pthread_mutexattr_setrobust(&mattr, PTHREAD_MUTEX_ROBUST_NP); + pthread_mutex_init(&(tmp->mutex), &mattr); + pthread_mutexattr_destroy(&mattr); - *param_mapped = tmp; + *param_mapped = tmp; } EM_DEBUG_FUNC_END(); @@ -810,8 +810,8 @@ typedef struct _em_mail_id_list { } em_mail_id_list; static char *g_test_query[] = { - /* 1. select mail_account_tbl */ - "SELECT" + /* 1. select mail_account_tbl */ + "SELECT" " account_name, " " incoming_server_type, " " incoming_server_address, " @@ -870,8 +870,8 @@ static char *g_test_query[] = { ", cipher_type" ", digest_type" " FROM mail_account_tbl", - /* 2. select mail_box_tbl */ - "SELECT " + /* 2. select mail_box_tbl */ + "SELECT " " mailbox_id, " " account_id, " " local_yn, " @@ -886,8 +886,8 @@ static char *g_test_query[] = { " no_select, " " last_sync_time " " FROM mail_box_tbl ", - /* 3. select mail_read_mail_uid_tbl */ - "SELECT " + /* 3. select mail_read_mail_uid_tbl */ + "SELECT " " account_id, " " mailbox_id, " " mailbox_name, " @@ -898,8 +898,8 @@ static char *g_test_query[] = { " flags_seen_field, " " idx_num " " FROM mail_read_mail_uid_tbl ", - /* 4. select mail_rule_tbl */ - "SELECT " + /* 4. select mail_rule_tbl */ + "SELECT " " account_id, " " rule_id, " " filter_name, " @@ -911,8 +911,8 @@ static char *g_test_query[] = { " flag1, " " flag2 " " FROM mail_rule_tbl ", - /* 5. select mail_tbl */ - "SELECT" + /* 5. select mail_tbl */ + "SELECT" " mail_id, " " account_id, " " mailbox_id, " @@ -962,8 +962,8 @@ static char *g_test_query[] = { " digest_type, " " smime_type " " FROM mail_tbl", - /* 6. select mail_attachment_tbl */ - "SELECT " + /* 6. select mail_attachment_tbl */ + "SELECT " " attachment_id, " " attachment_name, " " attachment_path, " @@ -979,7 +979,7 @@ static char *g_test_query[] = { " FROM mail_attachment_tbl ", #ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__ - "SELECT " + "SELECT " " account_id, " " mail_id, " " server_mail_id, " @@ -991,7 +991,7 @@ static char *g_test_query[] = { " FROM mail_partial_body_activity_tbl ", #endif - "SELECT " + "SELECT " " mail_id, " " account_id, " " mailbox_id, " @@ -1010,7 +1010,7 @@ static char *g_test_query[] = { " FROM mail_meeting_tbl ", #ifdef __FEATURE_LOCAL_ACTIVITY__ - "SELECT " + "SELECT " " activity_id, " " account_id, " " mail_id, " @@ -1020,7 +1020,7 @@ static char *g_test_query[] = { " dest_mbox " " FROM mail_local_activity_tbl ", #endif - "SELECT " + "SELECT " " certificate_id, " " issue_year, " " issue_month, " @@ -1034,7 +1034,7 @@ static char *g_test_query[] = { " filepath, " " password " " FROM mail_certificate_tbl ", - "SELECT " + "SELECT " " task_id, " " task_type, " " task_status, " @@ -1044,7 +1044,7 @@ static char *g_test_query[] = { " date_time " " FROM mail_task_tbl ", #ifdef __FEATURE_BODY_SEARCH__ - "SELECT " + "SELECT " " mail_id, " " account_id, " " mailbox_id, " @@ -1052,7 +1052,7 @@ static char *g_test_query[] = { " FROM mail_text_tbl ", #endif #ifdef __FEATURE_WIFI_AUTO_DOWNLOAD__ - "SELECT " + "SELECT " " activity_id, " " status, " " account_id, " @@ -1062,7 +1062,7 @@ static char *g_test_query[] = { " multi_user_name, " " FROM mail_auto_download_activity_tbl ", #endif - NULL, + NULL, }; int _field_count_of_table[CREATE_TABLE_MAX] = { 0, }; @@ -1163,7 +1163,7 @@ static int _get_table_field_data_string_without_allocation(char **table, char *b { if ((table == NULL) || (buf == NULL) || (index < 0)) { EM_DEBUG_EXCEPTION(" table[%p], buf[%p], index[%d]", table, buf, index); - return false; + return false; } char *pTemp = table[index]; @@ -1224,7 +1224,7 @@ static int _get_stmt_field_data_char(DB_STMT hStmt, char *buf, int index) if (sqlite3_column_text(hStmt, index) != NULL) { *buf = (char)sqlite3_column_int(hStmt, index); #ifdef _PRINT_STORAGE_LOG_ - EM_DEBUG_LOG("_get_stmt_field_data_int [%d]", *buf); + EM_DEBUG_LOG("_get_stmt_field_data_int [%d]", *buf); #endif return true; } @@ -1244,7 +1244,7 @@ static int _get_stmt_field_data_int(DB_STMT hStmt, int *buf, int index) if (sqlite3_column_text(hStmt, index) != NULL) { *buf = sqlite3_column_int(hStmt, index); #ifdef _PRINT_STORAGE_LOG_ - EM_DEBUG_LOG("_get_stmt_field_data_int [%d]", *buf); + EM_DEBUG_LOG("_get_stmt_field_data_int [%d]", *buf); #endif return true; } @@ -1284,7 +1284,7 @@ static int _get_stmt_field_data_string(DB_STMT hStmt, char **buf, int ucs2, int sLen = sqlite3_column_bytes(hStmt, index); #ifdef _PRINT_STORAGE_LOG_ - EM_DEBUG_LOG("_get_stmt_field_data_string sqlite3_column_bytes sLen[%d]", sLen); + EM_DEBUG_LOG("_get_stmt_field_data_string sqlite3_column_bytes sLen[%d]", sLen); #endif if (sLen > 0) { @@ -1526,8 +1526,8 @@ INTERNAL_FUNC int emstorage_close(int *err_code) if (!emstorage_db_close(NULL, &error)) - if (--_open_counter == 0) - _emstorage_close_once(); + if (--_open_counter == 0) + _emstorage_close_once(); ret = true; @@ -1591,8 +1591,8 @@ FINISH_OFF: return NULL; } - /* pData : a parameter which is registered when busy handler is registerd */ - /* count : retry count */ +/* pData : a parameter which is registered when busy handler is registerd */ +/* count : retry count */ static int _callback_sqlite_busy_handler(void *pData, int count) { if (10 - count > 0) { @@ -1610,7 +1610,7 @@ static int _callback_sqlite_busy_handler(void *pData, int count) } static int _callback_collation_utf7_sort(void *data, int length_text_a, const void *text_a, - int length_text_b, const void *text_b) + int length_text_b, const void *text_b) { EM_DEBUG_FUNC_BEGIN(); int result = 0; @@ -1802,9 +1802,15 @@ INTERNAL_FUNC int emstorage_init_db(char *multi_user_name) chmod(EMAIL_SERVICE_DB_JOURNAL_FILE_PATH, 0660); chmod(EMAIL_SQL_PATH, 0660); - chown(EMAIL_SERVICE_DB_FILE_PATH, email_uid, email_gid); - chown(EMAIL_SERVICE_DB_JOURNAL_FILE_PATH, email_uid, email_gid); - chown(EMAIL_SQL_PATH, email_uid, email_gid); + ret = chown(EMAIL_SERVICE_DB_FILE_PATH, email_uid, email_gid); + if (0 != ret) + EM_DEBUG_EXCEPTION("chown() Fail[errno=%d]", errno); + ret = chown(EMAIL_SERVICE_DB_JOURNAL_FILE_PATH, email_uid, email_gid); + if (0 != ret) + EM_DEBUG_EXCEPTION("chown() Fail[errno=%d]", errno); + ret = chown(EMAIL_SQL_PATH, email_uid, email_gid); + if (0 != ret) + EM_DEBUG_EXCEPTION("chown() Fail[errno=%d]", errno); } @@ -1833,17 +1839,17 @@ INTERNAL_FUNC int em_db_open(char *db_file_path, sqlite3 **sqlite_handle, int *e return true; } - EM_DEBUG_LOG("DB file path : [%s]", db_file_path); + EM_DEBUG_LOG("DB file path : [%s]", db_file_path); /* db open */ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_open(db_file_path, sqlite_handle), rc); if (SQLITE_OK != rc) { EM_DEBUG_EXCEPTION("sqlite3_open fail:%d -%s", rc, sqlite3_errmsg(*sqlite_handle)); - if (SQLITE_PERM == rc || SQLITE_CANTOPEN == rc) { + if (SQLITE_PERM == rc || SQLITE_CANTOPEN == rc) error = EMAIL_ERROR_PERMISSION_DENIED; - } else { + else error = EMAIL_ERROR_DB_FAILURE; - } + sqlite3_close(*sqlite_handle); *sqlite_handle = NULL; @@ -1858,11 +1864,11 @@ INTERNAL_FUNC int em_db_open(char *db_file_path, sqlite3 **sqlite_handle, int *e EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_open(db_file_path, sqlite_handle), rc); if (SQLITE_OK != rc) { EM_DEBUG_EXCEPTION("sqlite3_open fail:%d -%s", rc, sqlite3_errmsg(*sqlite_handle)); - if (SQLITE_PERM == rc) { + if (SQLITE_PERM == rc) error = EMAIL_ERROR_PERMISSION_DENIED; - } else { + else error = EMAIL_ERROR_DB_FAILURE; - } + sqlite3_close(*sqlite_handle); *sqlite_handle = NULL; goto FINISH_OFF; /*prevent 33351*/ @@ -1915,17 +1921,17 @@ INTERNAL_FUNC sqlite3* emstorage_db_open(char *multi_user_name, int *err_code) if (_db_handle == NULL) { char *output_file_path = NULL; - char temp_file_path[MAX_PATH] = {0}; + char temp_file_path[MAX_PATH] = {0}; - if (EM_SAFE_STRLEN(multi_user_name) > 0) { - error = emcore_get_container_path(multi_user_name, &prefix_path); - if (error != EMAIL_ERROR_CONTAINER_NOT_INITIALIZATION && error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emcore_get_container_path failed :[%d]", error); - goto FINISH_OFF; - } - } else { - prefix_path = strdup(""); - } + if (EM_SAFE_STRLEN(multi_user_name) > 0) { + error = emcore_get_container_path(multi_user_name, &prefix_path); + if (error != EMAIL_ERROR_CONTAINER_NOT_INITIALIZATION && error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emcore_get_container_path failed :[%d]", error); + goto FINISH_OFF; + } + } else { + prefix_path = strdup(""); + } if (error == EMAIL_ERROR_CONTAINER_NOT_INITIALIZATION) { if ((error = emcore_get_canonicalize_path((char *)EMAIL_SERVICE_DB_FILE_PATH, &output_file_path)) != EMAIL_ERROR_NONE) { @@ -2022,10 +2028,10 @@ INTERNAL_FUNC int emstorage_open(char *multi_user_name, int *err_code) } if (!g_file_test(buf, G_FILE_TEST_EXISTS)) { - retValue = mkdir(buf, DIRECTORY_PERMISSION); + retValue = mkdir(buf, DIRECTORY_PERMISSION); EM_DEBUG_LOG("mkdir return- %d", retValue); - EM_DEBUG_LOG("emstorage_open - before sqlite3_open - pid = %d", getpid()); + EM_DEBUG_LOG("emstorage_open - before sqlite3_open - pid = %d", getpid()); } if (emstorage_db_open(multi_user_name, &error) == NULL) { @@ -2033,9 +2039,8 @@ INTERNAL_FUNC int emstorage_open(char *multi_user_name, int *err_code) goto FINISH_OFF; } - if (_open_counter++ == 0) { + if (_open_counter++ == 0) _emstorage_open_once(multi_user_name, &error); - } ret = true; @@ -2119,9 +2124,8 @@ FINISH_OFF: if (create_table_query) { int i = 0; for (i = 0; i < query_len; i++) { - if (create_table_query[i]) { + if (create_table_query[i]) EM_SAFE_FREE(create_table_query[i]); - } } EM_SAFE_FREE(create_table_query); } @@ -2163,14 +2167,14 @@ INTERNAL_FUNC int emstorage_create_table(char *multi_user_name, emstorage_create sql = "SELECT count(name) FROM sqlite_master WHERE name='mail_account_tbl';"; EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); EM_DEBUG_LOG("emstorage_create_table - result[1] = %s %c", result[1], result[1]); if (atoi(result[1]) < 1) { EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN;", NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, - ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle))); + ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle))); EM_DEBUG_LOG("CREATE TABLE mail_account_tbl"); EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_ACCOUNT_TBL], sizeof(sql_query_string)-1); /*prevent 21984*/ @@ -2203,12 +2207,12 @@ INTERNAL_FUNC int emstorage_create_table(char *multi_user_name, emstorage_create EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); if (atoi(result[1]) < 1) { EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN;", NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, - ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle))); + ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle))); EM_DEBUG_LOG("CREATE TABLE mail_box_tbl"); @@ -2232,7 +2236,7 @@ INTERNAL_FUNC int emstorage_create_table(char *multi_user_name, emstorage_create else if (type == EMAIL_CREATE_DB_CHECK) { rc = sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_BOX_TBL], NULL, NULL, NULL); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_BOX_TBL], rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_BOX_TBL], rc, sqlite3_errmsg(local_db_handle))); } sqlite3_free_table(result); result = NULL; @@ -2241,13 +2245,13 @@ INTERNAL_FUNC int emstorage_create_table(char *multi_user_name, emstorage_create sql = "SELECT count(name) FROM sqlite_master WHERE name='mail_read_mail_uid_tbl';"; EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); if (atoi(result[1]) < 1) { EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN;", NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, - ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle))); + ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle))); EM_DEBUG_LOG("CREATE TABLE mail_read_mail_uid_tbl"); @@ -2271,7 +2275,7 @@ INTERNAL_FUNC int emstorage_create_table(char *multi_user_name, emstorage_create else if (type == EMAIL_CREATE_DB_CHECK) { EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_READ_MAIL_UID_TBL], NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_READ_MAIL_UID_TBL], rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_READ_MAIL_UID_TBL], rc, sqlite3_errmsg(local_db_handle))); } sqlite3_free_table(result); result = NULL; @@ -2281,28 +2285,28 @@ INTERNAL_FUNC int emstorage_create_table(char *multi_user_name, emstorage_create EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); if (atoi(result[1]) < 1) { EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN;", NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, - ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle))); + ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle))); EM_DEBUG_LOG("CREATE TABLE mail_rule_tbl"); EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_RULE_TBL], sizeof(sql_query_string)-1); /*prevent 21984*/ - error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); - if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; - } + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); } /* mail_rule_tbl */ else if (type == EMAIL_CREATE_DB_CHECK) { EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_RULE_TBL], NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_RULE_TBL], rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_RULE_TBL], rc, sqlite3_errmsg(local_db_handle))); } sqlite3_free_table(result); result = NULL; @@ -2311,53 +2315,53 @@ INTERNAL_FUNC int emstorage_create_table(char *multi_user_name, emstorage_create sql = "SELECT count(name) FROM sqlite_master WHERE name='mail_tbl';"; EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); if (atoi(result[1]) < 1) { EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN;", NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, - ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle))); + ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle))); EM_DEBUG_LOG("CREATE TABLE mail_tbl"); EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_TBL], sizeof(sql_query_string)-1); /*prevent 21984*/ - error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); - if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; - } + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } /* create mail_tbl unique index */ SNPRINTF(sql_query_string, sizeof(sql_query_string), "%s", create_table_query[CREATE_TABLE_MAIL_IDX]); - error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); - if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; - } + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } /* create mail_tbl index for date_time */ SNPRINTF(sql_query_string, sizeof(sql_query_string), "%s", create_table_query[CREATE_TABLE_MAIL_DATETIME_IDX]); - error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); - if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; - } + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } /* create mail_tbl index for thread_item_count */ SNPRINTF(sql_query_string, sizeof(sql_query_string), "%s", create_table_query[CREATE_TABLE_MAIL_THREAD_IDX]); - error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); - if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; - } + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); /* just one time call */ -/* EFTSInitFTSIndex(FTS_EMAIL_IDX); */ - } /* mail_tbl */ + /* EFTSInitFTSIndex(FTS_EMAIL_IDX); */ + } /* mail_tbl */ else if (type == EMAIL_CREATE_DB_CHECK) { EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_TBL], NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_TBL], rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_TBL], rc, sqlite3_errmsg(local_db_handle))); } sqlite3_free_table(result); result = NULL; @@ -2366,36 +2370,36 @@ INTERNAL_FUNC int emstorage_create_table(char *multi_user_name, emstorage_create sql = "SELECT count(name) FROM sqlite_master WHERE name='mail_attachment_tbl';"; EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); if (atoi(result[1]) < 1) { EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN;", NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, - ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle))); + ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle))); EM_DEBUG_LOG("CREATE TABLE mail_attachment_tbl"); EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_ATTACHMENT_TBL], sizeof(sql_query_string)-1); /*prevent 21984*/ - error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); - if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; - } + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } /* create mail_attachment_tbl unique index */ SNPRINTF(sql_query_string, sizeof(sql_query_string), "%s", create_table_query[CREATE_TABLE_MAIL_ATTACHMENT_IDX]); - error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); - if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; - } + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); } /* mail_attachment_tbl */ else if (type == EMAIL_CREATE_DB_CHECK) { EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_ATTACHMENT_TBL], NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_ATTACHMENT_TBL], rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_ATTACHMENT_TBL], rc, sqlite3_errmsg(local_db_handle))); } sqlite3_free_table(result); result = NULL; @@ -2405,29 +2409,29 @@ INTERNAL_FUNC int emstorage_create_table(char *multi_user_name, emstorage_create sql = "SELECT count(name) FROM sqlite_master WHERE name='mail_partial_body_activity_tbl';"; EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); if (atoi(result[1]) < 1) { EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN;", NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, - ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle))); + ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle))); EM_DEBUG_LOG("CREATE TABLE mail_partial_body_activity_tbl"); EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_PARTIAL_BODY_ACTIVITY_TBL], sizeof(sql_query_string)-1); /*prevent 21984*/ - error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); - if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; - } + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); } /* mail_rule_tbl */ else if (type == EMAIL_CREATE_DB_CHECK) { EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_PARTIAL_BODY_ACTIVITY_TBL], NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_PARTIAL_BODY_ACTIVITY_TBL], rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_PARTIAL_BODY_ACTIVITY_TBL], rc, sqlite3_errmsg(local_db_handle))); } sqlite3_free_table(result); result = NULL; @@ -2438,71 +2442,71 @@ INTERNAL_FUNC int emstorage_create_table(char *multi_user_name, emstorage_create sql = "SELECT count(name) FROM sqlite_master WHERE name='mail_meeting_tbl';"; EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); if (atoi(result[1]) < 1) { EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN;", NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, - ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle))); + ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle))); EM_DEBUG_LOG("CREATE TABLE mail_meeting_tbl"); EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_MEETING_TBL], sizeof(sql_query_string)-1); /*prevent 21984*/ - error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); - if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; - } + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } SNPRINTF(sql_query_string, sizeof(sql_query_string), "%s", create_table_query[CREATE_TABLE_MAIL_MEETING_IDX]); - error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); - if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; - } + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); } /* mail_contact_sync_tbl */ else if (type == EMAIL_CREATE_DB_CHECK) { EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_MEETING_TBL], NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_MEETING_TBL], rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_MEETING_TBL], rc, sqlite3_errmsg(local_db_handle))); } sqlite3_free_table(result); result = NULL; #ifdef __FEATURE_LOCAL_ACTIVITY__ - sql = "SELECT count(name) FROM sqlite_master WHERE name='mail_local_activity_tbl';"; - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, + sql = "SELECT count(name) FROM sqlite_master WHERE name='mail_local_activity_tbl';"; + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); + EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); - if (atoi(result[1]) < 1) { + if (atoi(result[1]) < 1) { - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN;", NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN;", NULL, NULL, NULL), rc); + EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {goto FINISH_OFF; }, ("SQL(BEGIN EXCLUSIVE) exec fail:%d -%s", rc, sqlite3_errmsg(local_db_handle))); - EM_DEBUG_LOG(" CREATE TABLE mail_local_activity_tbl"); + EM_DEBUG_LOG(" CREATE TABLE mail_local_activity_tbl"); - SNPRINTF(sql_query_string, sizeof(sql_query_string), create_table_query[CREATE_TABLE_MAIL_LOCAL_ACTIVITY_TBL]); - error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); - if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; - } + SNPRINTF(sql_query_string, sizeof(sql_query_string), create_table_query[CREATE_TABLE_MAIL_LOCAL_ACTIVITY_TBL]); + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); - } /* mail_rule_tbl */ - else if (type == EMAIL_CREATE_DB_CHECK) { - rc = sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_LOCAL_ACTIVITY_TBL], NULL, NULL, NULL); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_LOCAL_ACTIVITY_TBL], NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); + } /* mail_rule_tbl */ + else if (type == EMAIL_CREATE_DB_CHECK) { + rc = sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_LOCAL_ACTIVITY_TBL], NULL, NULL, NULL); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, g_test_query[CREATE_TABLE_MAIL_LOCAL_ACTIVITY_TBL], NULL, NULL, NULL), rc); + EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, ("SQL(%s) exec fail:%d -%s", g_test_query[CREATE_TABLE_MAIL_LOCAL_ACTIVITY_TBL], rc, sqlite3_errmsg(local_db_handle))); - } - sqlite3_free_table(result); - result = NULL; + } + sqlite3_free_table(result); + result = NULL; #endif /* __FEATURE_LOCAL_ACTIVITY__ */ /* create mail_certificate_tbl */ sql = "SELECT count(name) FROM sqlite_master WHERE name='mail_certificate_tbl';"; @@ -2517,11 +2521,11 @@ INTERNAL_FUNC int emstorage_create_table(char *multi_user_name, emstorage_create EM_DEBUG_LOG("CREATE TABLE mail_certificate_tbl"); EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_CERTIFICATE_TBL], sizeof(sql_query_string)-1); /*prevent 21984*/ - error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); - if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; - } + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); } /* mail_contact_sync_tbl */ @@ -2545,18 +2549,18 @@ INTERNAL_FUNC int emstorage_create_table(char *multi_user_name, emstorage_create EM_DEBUG_LOG("CREATE TABLE mail_task_tbl"); EM_SAFE_STRNCPY(sql_query_string, create_table_query[CREATE_TABLE_MAIL_TASK_TBL], sizeof(sql_query_string)-1); /*prevent 21984 */ - error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); - if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; - } + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } SNPRINTF(sql_query_string, sizeof(sql_query_string), "%s", create_table_query[CREATE_TABLE_MAIL_TASK_IDX]); - error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); - if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; - } + error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); + if (error != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; + } EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); } /* mail_task_tbl */ @@ -2637,18 +2641,19 @@ FINISH_OFF: if (result) sqlite3_free_table(result); if (ret == true) { - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL( + sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); } else { - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "rollback", NULL, NULL, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL( + sqlite3_exec(local_db_handle, "rollback", NULL, NULL, NULL), rc); } FINISH_OFF2: if (create_table_query) { int i = 0; for (i = 0; i < query_len; i++) { - if (create_table_query[i]) { + if (create_table_query[i]) EM_SAFE_FREE(create_table_query[i]); - } } EM_SAFE_FREE(create_table_query); } @@ -2695,11 +2700,11 @@ INTERNAL_FUNC int emstorage_query_mail_count(char *multi_user_name, const char * if (output_total_mail_count) { EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_prepare failed [%d] [%s]", rc, sql_query_string)); + ("sqlite3_prepare failed [%d] [%s]", rc, sql_query_string)); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step failed [%d] [%s]", rc, sql_query_string)); + ("sqlite3_step failed [%d] [%s]", rc, sql_query_string)); _get_stmt_field_data_int(hStmt, output_total_mail_count, 0); } @@ -2708,7 +2713,7 @@ INTERNAL_FUNC int emstorage_query_mail_count(char *multi_user_name, const char * EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("sqlite3_get_table failed [%d] [%s]", rc, sql_query_string)); + ("sqlite3_get_table failed [%d] [%s]", rc, sql_query_string)); *output_unseen_mail_count = atoi(result[1]); sqlite3_free_table(result); @@ -2771,7 +2776,7 @@ INTERNAL_FUNC int emstorage_query_mail_id_list(char *multi_user_name, const char /* Performing query */ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); col_index = 1; @@ -2868,7 +2873,7 @@ INTERNAL_FUNC int emstorage_query_mail_list(char *multi_user_name, const char *c EM_PROFILE_BEGIN(emstorage_query_mail_list_performing_query); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_get_table failed [%d] [%s]", rc, sql_query_string)); + ("sqlite3_get_table failed [%d] [%s]", rc, sql_query_string)); EM_PROFILE_END(emstorage_query_mail_list_performing_query); if (!base_count) @@ -2974,7 +2979,7 @@ FINISH_OFF: EMSTORAGE_FINISH_READ_TRANSACTION(transaction); -// sqlite3_db_release_memory(local_db_handle); + // sqlite3_db_release_memory(local_db_handle); EM_SAFE_FREE(sql_query_string); EM_SAFE_FREE(date_time_string); @@ -3014,7 +3019,7 @@ INTERNAL_FUNC int emstorage_query_mail_tbl(char *multi_user_name, const char *co EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("sqlite3_get_table failed [%d] [%s]", rc, sql_query_string)); + ("sqlite3_get_table failed [%d] [%s]", rc, sql_query_string)); if (!count) { EM_DEBUG_LOG("No mail found..."); @@ -3106,7 +3111,7 @@ FINISH_OFF: EMSTORAGE_FINISH_READ_TRANSACTION(transaction); -// sqlite3_db_release_memory(local_db_handle); + // sqlite3_db_release_memory(local_db_handle); if (err_code != NULL) *err_code = error; @@ -3146,7 +3151,7 @@ INTERNAL_FUNC int emstorage_query_mail_text_tbl(char *multi_user_name, const cha EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); if (!count) { EM_DEBUG_LOG("No mail found..."); @@ -3184,7 +3189,7 @@ FINISH_OFF: EMSTORAGE_FINISH_READ_TRANSACTION(transaction); -// sqlite3_db_release_memory(local_db_handle); + // sqlite3_db_release_memory(local_db_handle); if (err_code != NULL) *err_code = error; @@ -3225,9 +3230,9 @@ INTERNAL_FUNC int emstorage_query_mailbox_tbl(char *multi_user_name, const char EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("sqlite3_get_table failed [%d] [%s]", rc, sql_query_string)) + ("sqlite3_get_table failed [%d] [%s]", rc, sql_query_string)) - EM_DEBUG_LOG_DEV("result count [%d]", count); + EM_DEBUG_LOG_DEV("result count [%d]", count); if (count == 0) { EM_DEBUG_LOG_SEC("Can't find mailbox query[%s]", sql_query_string); @@ -3279,7 +3284,7 @@ FINISH_OFF: EMSTORAGE_FINISH_READ_TRANSACTION(input_transaction); -// sqlite3_db_release_memory(local_db_handle); + // sqlite3_db_release_memory(local_db_handle); EM_DEBUG_FUNC_END("error [%d]", error); return error; @@ -3297,7 +3302,7 @@ INTERNAL_FUNC int emstorage_check_duplicated_account(char *multi_user_name, emai sqlite3 *local_db_handle = NULL; if (account == NULL || account->user_email_address == NULL || account->incoming_server_user_name == NULL || account->incoming_server_address == NULL || - account->outgoing_server_user_name == NULL || account->outgoing_server_address == NULL) { + account->outgoing_server_user_name == NULL || account->outgoing_server_address == NULL) { if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; @@ -3308,23 +3313,23 @@ INTERNAL_FUNC int emstorage_check_duplicated_account(char *multi_user_name, emai EMSTORAGE_START_READ_TRANSACTION(transaction); SNPRINTF(sql_query_string, sizeof(sql_query_string), - "SELECT COUNT(*) FROM mail_account_tbl " - " WHERE " - " user_email_address = '%s' AND " - " incoming_server_user_name = '%s' AND " - " incoming_server_type = %d AND " - " incoming_server_address = '%s' AND " - " outgoing_server_user_name = '%s' AND " - " outgoing_server_type = %d AND " - " outgoing_server_address = '%s'; ", - account->user_email_address, - account->incoming_server_user_name, account->incoming_server_type, account->incoming_server_address, - account->outgoing_server_user_name, account->outgoing_server_type, account->outgoing_server_address - ); + "SELECT COUNT(*) FROM mail_account_tbl " + " WHERE " + " user_email_address = '%s' AND " + " incoming_server_user_name = '%s' AND " + " incoming_server_type = %d AND " + " incoming_server_address = '%s' AND " + " outgoing_server_user_name = '%s' AND " + " outgoing_server_type = %d AND " + " outgoing_server_address = '%s'; ", + account->user_email_address, + account->incoming_server_user_name, account->incoming_server_type, account->incoming_server_address, + account->outgoing_server_user_name, account->outgoing_server_type, account->outgoing_server_address + ); EM_DEBUG_LOG_SEC("Query[%s]", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); count = atoi(result[1]); sqlite3_free_table(result); @@ -3374,14 +3379,14 @@ INTERNAL_FUNC int emstorage_get_account_count(char *multi_user_name, int *count, SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_account_tbl"); EM_DEBUG_LOG_SEC("SQL STMT [%s]", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, - EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); + EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG("Before sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); *count = sqlite3_column_int(hStmt, 0); @@ -3435,7 +3440,7 @@ INTERNAL_FUNC int emstorage_get_account_list(char *multi_user_name, int *select_ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); count = atoi(result[1]); sqlite3_free_table(result); @@ -3452,73 +3457,73 @@ INTERNAL_FUNC int emstorage_get_account_list(char *multi_user_name, int *select_ sql_len = EM_SAFE_STRLEN(sql_query_string); SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, - "account_id, " - "account_name, " - "logo_icon_path, " - "user_data, " - "user_data_length, " - "account_svc_id, " - "sync_status, " - "sync_disabled, " - "default_mail_slot_size, " - "roaming_option, " - "color_label, " - "user_display_name, " - "user_email_address, " - "reply_to_address, " - "return_address, " - "incoming_server_type, " - "incoming_server_address, " - "incoming_server_port_number, " - "incoming_server_user_name, " - "incoming_server_password, " - "incoming_server_secure_connection, " - "incoming_server_authentication_method, " - "retrieval_mode, " - "keep_mails_on_pop_server_after_download, " - "check_interval, " - "auto_download_size, " - "peak_interval, " - "peak_days, " - "peak_start_time, " - "peak_end_time, " - "outgoing_server_type, " - "outgoing_server_address, " - "outgoing_server_port_number, " - "outgoing_server_user_name, " - "outgoing_server_password, " - "outgoing_server_secure_connection, " - "outgoing_server_need_authentication, " - "outgoing_server_use_same_authenticator, " - "priority, " - "keep_local_copy, " - "req_delivery_receipt, " - "req_read_receipt, " - "download_limit, " - "block_address, " - "block_subject, " - "display_name_from, " - "reply_with_body, " - "forward_with_files, " - "add_myname_card, " - "add_signature, " - "signature, " - "add_my_address_to_bcc, " - "notification_status, " - "vibrate_status, " - "display_content_status, " - "default_ringtone_status, " - "alert_ringtone_path, " - "auto_resend_times, " - "outgoing_server_size_limit, " - "wifi_auto_download, " - "pop_before_smtp, " - "incoming_server_requires_apop, " - "smime_type, " - "certificate_path, " - "cipher_type, " - "digest_type" - ); + "account_id, " + "account_name, " + "logo_icon_path, " + "user_data, " + "user_data_length, " + "account_svc_id, " + "sync_status, " + "sync_disabled, " + "default_mail_slot_size, " + "roaming_option, " + "color_label, " + "user_display_name, " + "user_email_address, " + "reply_to_address, " + "return_address, " + "incoming_server_type, " + "incoming_server_address, " + "incoming_server_port_number, " + "incoming_server_user_name, " + "incoming_server_password, " + "incoming_server_secure_connection, " + "incoming_server_authentication_method, " + "retrieval_mode, " + "keep_mails_on_pop_server_after_download, " + "check_interval, " + "auto_download_size, " + "peak_interval, " + "peak_days, " + "peak_start_time, " + "peak_end_time, " + "outgoing_server_type, " + "outgoing_server_address, " + "outgoing_server_port_number, " + "outgoing_server_user_name, " + "outgoing_server_password, " + "outgoing_server_secure_connection, " + "outgoing_server_need_authentication, " + "outgoing_server_use_same_authenticator, " + "priority, " + "keep_local_copy, " + "req_delivery_receipt, " + "req_read_receipt, " + "download_limit, " + "block_address, " + "block_subject, " + "display_name_from, " + "reply_with_body, " + "forward_with_files, " + "add_myname_card, " + "add_signature, " + "signature, " + "add_my_address_to_bcc, " + "notification_status, " + "vibrate_status, " + "display_content_status, " + "default_ringtone_status, " + "alert_ringtone_path, " + "auto_resend_times, " + "outgoing_server_size_limit, " + "wifi_auto_download, " + "pop_before_smtp, " + "incoming_server_requires_apop, " + "smime_type, " + "certificate_path, " + "cipher_type, " + "digest_type" + ); sql_len = EM_SAFE_STRLEN(sql_query_string); @@ -3528,11 +3533,11 @@ INTERNAL_FUNC int emstorage_get_account_list(char *multi_user_name, int *select_ EM_DEBUG_LOG_DEV("After sqlite3_prepare_v2 hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); if (rc == SQLITE_DONE) { EM_DEBUG_EXCEPTION("no account found..."); @@ -3629,8 +3634,8 @@ INTERNAL_FUNC int emstorage_get_account_list(char *multi_user_name, int *select_ /* get password file name */ error = _get_password_file_name(multi_user_name, p_data_tbl[i].account_id, - recv_password_file_name, - send_password_file_name); + recv_password_file_name, + send_password_file_name); if (error != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("_get_password_file_name error [%d]", error); error = EMAIL_ERROR_SECURED_STORAGE_FAILURE; @@ -3639,18 +3644,18 @@ INTERNAL_FUNC int emstorage_get_account_list(char *multi_user_name, int *select_ /* read password from secure storage */ error = _read_password_from_secure_storage(recv_password_file_name, - &(p_data_tbl[i].incoming_server_password)); + &(p_data_tbl[i].incoming_server_password)); if (error < 0) { EM_DEBUG_EXCEPTION("_read_password_from_secure_storage()[%s] error [%d]", - recv_password_file_name, error); + recv_password_file_name, error); error = EMAIL_ERROR_SECURED_STORAGE_FAILURE; goto FINISH_OFF; } error = _read_password_from_secure_storage(send_password_file_name, - &(p_data_tbl[i].outgoing_server_password)); + &(p_data_tbl[i].outgoing_server_password)); if (error < 0) { EM_DEBUG_EXCEPTION("_read_password_from_secure_storage()[%s] error [%d]", - send_password_file_name, error); + send_password_file_name, error); error = EMAIL_ERROR_SECURED_STORAGE_FAILURE; goto FINISH_OFF; } @@ -3659,7 +3664,7 @@ INTERNAL_FUNC int emstorage_get_account_list(char *multi_user_name, int *select_ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_LOG_DEV("after sqlite3_step(), i = %d, rc = %d.", i, rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); } ret = true; @@ -3691,14 +3696,14 @@ FINISH_OFF: } INTERNAL_FUNC int emstorage_get_maildata_by_servermailid(char *multi_user_name, - char *server_mail_id, - int mailbox_id, - emstorage_mail_tbl_t **mail, - int transaction, - int *err_code) + char *server_mail_id, + int mailbox_id, + emstorage_mail_tbl_t **mail, + int transaction, + int *err_code) { EM_DEBUG_FUNC_BEGIN_SEC("mailbox_id [%d], server_mail_id[%s], mail[%p], transaction[%d], err_code[%p]", - mailbox_id, server_mail_id, mail, transaction, err_code); + mailbox_id, server_mail_id, mail, transaction, err_code); int ret = false, error = EMAIL_ERROR_NONE, result_count; char conditional_clause[QUERY_SIZE] = {0, }; @@ -3714,18 +3719,18 @@ INTERNAL_FUNC int emstorage_get_maildata_by_servermailid(char *multi_user_name, if (mailbox_id > 0) { SNPRINTF(conditional_clause + strlen(conditional_clause), - QUERY_SIZE - strlen(conditional_clause), - " AND mailbox_id = %d", - mailbox_id); + QUERY_SIZE - strlen(conditional_clause), + " AND mailbox_id = %d", + mailbox_id); } EM_DEBUG_LOG("conditional_clause [%s]", conditional_clause); if (!emstorage_query_mail_tbl(multi_user_name, - conditional_clause, - transaction, - &p_data_tbl, - &result_count, - &error)) { + conditional_clause, + transaction, + &p_data_tbl, + &result_count, + &error)) { EM_DEBUG_EXCEPTION("emstorage_query_mail_tbl failed [%d]", error); goto FINISH_OFF; } @@ -3816,59 +3821,59 @@ static int _write_conditional_clause_for_getting_mail_list(int account_id, int m if (search_value) { switch (search_type) { - case EMAIL_SEARCH_FILTER_SUBJECT: - cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, + case EMAIL_SEARCH_FILTER_SUBJECT: + cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " %s (UPPER(subject) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') ", conditional_clause_count++ ? "AND" : "WHERE", search_value); - break; - case EMAIL_SEARCH_FILTER_SENDER: - cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, + break; + case EMAIL_SEARCH_FILTER_SENDER: + cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " %s ((UPPER(full_address_from) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') " ") ", conditional_clause_count++ ? "AND" : "WHERE", search_value); - break; - case EMAIL_SEARCH_FILTER_RECIPIENT: - cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, + break; + case EMAIL_SEARCH_FILTER_RECIPIENT: + cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " %s ((UPPER(full_address_to) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') " " OR (UPPER(full_address_cc) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') " " OR (UPPER(full_address_bcc) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') " ") ", conditional_clause_count++ ? "AND" : "WHERE", search_value, search_value, search_value); - break; - case EMAIL_SEARCH_FILTER_ALL: - cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, + break; + case EMAIL_SEARCH_FILTER_ALL: + cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size - cur_clause, " %s (UPPER(subject) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\' " - " OR (((UPPER(full_address_from) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') " + " OR (((UPPER(full_address_from) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') " " OR (UPPER(full_address_to) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') " " OR (UPPER(full_address_cc) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') " " OR (UPPER(full_address_bcc) LIKE UPPER(\'%%%%%s%%%%\') ESCAPE '\\') " " ) " " )" ")", conditional_clause_count++ ? "AND" : "WHERE", search_value, search_value, search_value, search_value, search_value); - break; + break; } } /* EM_DEBUG_LOG("where clause [%s]", conditional_clause_string); */ static char sorting_str[][50] = { - " ORDER BY date_time DESC", /* case EMAIL_SORT_DATETIME_HIGH: */ - " ORDER BY date_time ASC", /* case EMAIL_SORT_DATETIME_LOW: */ - " ORDER BY full_address_from DESC, date_time DESC", /* case EMAIL_SORT_SENDER_HIGH: */ - " ORDER BY full_address_from ASC, date_time DESC", /* case EMAIL_SORT_SENDER_LOW: */ - " ORDER BY full_address_to DESC, date_time DESC", /* case EMAIL_SORT_RCPT_HIGH: */ - " ORDER BY full_address_to ASC, date_time DESC", /* case EMAIL_SORT_RCPT_LOW: */ - " ORDER BY subject DESC, date_time DESC", /* case EMAIL_SORT_SUBJECT_HIGH: */ - " ORDER BY subject ASC, date_time DESC", /* case EMAIL_SORT_SUBJECT_LOW: */ - " ORDER BY priority DESC, date_time DESC", /* case EMAIL_SORT_PRIORITY_HIGH: */ - " ORDER BY priority ASC, date_time DESC", /* case EMAIL_SORT_PRIORITY_LOW: */ - " ORDER BY attachment_count DESC, date_time DESC", /* case EMAIL_SORT_ATTACHMENT_HIGH: */ - " ORDER BY attachment_count ASC, date_time DESC", /* case EMAIL_SORT_ATTACHMENT_LOW: */ - " ORDER BY lock_status DESC, date_time DESC", /* case EMAIL_SORT_FAVORITE_HIGH: */ - " ORDER BY lock_status ASC, date_time DESC", /* case EMAIL_SORT_FAVORITE_LOW: */ - " ORDER BY mailbox_id DESC, date_time DESC", /* case EMAIL_SORT_MAILBOX_ID_HIGH: */ - " ORDER BY mailbox_id ASC, date_time DESC", /* case EMAIL_SORT_MAILBOX_ID_LOW: */ - " ORDER BY flags_flagged_field DESC, date_time DESC", /* case EMAIL_SORT_FLAGGED_FLAG_HIGH: */ - " ORDER BY flags_flagged_field ASC, date_time DESC", /* case EMAIL_SORT_FLAGGED_FLAG_LOW: */ - " ORDER BY flags_seen_field DESC, date_time DESC", /* case EMAIL_SORT_SEEN_FLAG_HIGH: */ - " ORDER BY flags_seen_field ASC, date_time DESC" /* case EMAIL_SORT_SEEN_FLAG_LOW: */ - }; + " ORDER BY date_time DESC", /* case EMAIL_SORT_DATETIME_HIGH: */ + " ORDER BY date_time ASC", /* case EMAIL_SORT_DATETIME_LOW: */ + " ORDER BY full_address_from DESC, date_time DESC", /* case EMAIL_SORT_SENDER_HIGH: */ + " ORDER BY full_address_from ASC, date_time DESC", /* case EMAIL_SORT_SENDER_LOW: */ + " ORDER BY full_address_to DESC, date_time DESC", /* case EMAIL_SORT_RCPT_HIGH: */ + " ORDER BY full_address_to ASC, date_time DESC", /* case EMAIL_SORT_RCPT_LOW: */ + " ORDER BY subject DESC, date_time DESC", /* case EMAIL_SORT_SUBJECT_HIGH: */ + " ORDER BY subject ASC, date_time DESC", /* case EMAIL_SORT_SUBJECT_LOW: */ + " ORDER BY priority DESC, date_time DESC", /* case EMAIL_SORT_PRIORITY_HIGH: */ + " ORDER BY priority ASC, date_time DESC", /* case EMAIL_SORT_PRIORITY_LOW: */ + " ORDER BY attachment_count DESC, date_time DESC", /* case EMAIL_SORT_ATTACHMENT_HIGH: */ + " ORDER BY attachment_count ASC, date_time DESC", /* case EMAIL_SORT_ATTACHMENT_LOW: */ + " ORDER BY lock_status DESC, date_time DESC", /* case EMAIL_SORT_FAVORITE_HIGH: */ + " ORDER BY lock_status ASC, date_time DESC", /* case EMAIL_SORT_FAVORITE_LOW: */ + " ORDER BY mailbox_id DESC, date_time DESC", /* case EMAIL_SORT_MAILBOX_ID_HIGH: */ + " ORDER BY mailbox_id ASC, date_time DESC", /* case EMAIL_SORT_MAILBOX_ID_LOW: */ + " ORDER BY flags_flagged_field DESC, date_time DESC", /* case EMAIL_SORT_FLAGGED_FLAG_HIGH: */ + " ORDER BY flags_flagged_field ASC, date_time DESC", /* case EMAIL_SORT_FLAGGED_FLAG_LOW: */ + " ORDER BY flags_seen_field DESC, date_time DESC", /* case EMAIL_SORT_SEEN_FLAG_HIGH: */ + " ORDER BY flags_seen_field ASC, date_time DESC" /* case EMAIL_SORT_SEEN_FLAG_LOW: */ + }; if (sorting < EMAIL_SORT_END) cur_clause += SNPRINTF_OFFSET(conditional_clause_string, cur_clause, buffer_size, " %s", sorting_str[sorting]); @@ -3884,10 +3889,10 @@ static int _write_conditional_clause_for_getting_mail_list(int account_id, int m /** - * emstorage_get_mail_list - Get the mail list information. - * - * - */ + * emstorage_get_mail_list - Get the mail list information. + * + * + */ INTERNAL_FUNC int emstorage_get_mail_list(char *multi_user_name, int account_id, int mailbox_id, email_email_address_list_t* addr_list, int thread_id, int start_index, int limit_count, int search_type, const char *search_value, email_sort_type_t sorting, int transaction, email_mail_list_item_t** mail_list, int *result_count, int *err_code) { EM_DEBUG_FUNC_BEGIN(); @@ -3924,10 +3929,10 @@ FINISH_OFF: /** - * emstorage_get_mails - Get the Mail list information based on mailbox_name name - * - * - */ + * emstorage_get_mails - Get the Mail list information based on mailbox_name name + * + * + */ INTERNAL_FUNC int emstorage_get_mails(char *multi_user_name, int account_id, int mailbox_id, email_email_address_list_t* addr_list, int thread_id, int start_index, int limit_count, email_sort_type_t sorting, int transaction, emstorage_mail_tbl_t** mail_list, int *result_count, int *err_code) { EM_DEBUG_FUNC_BEGIN(); @@ -3978,10 +3983,10 @@ FINISH_OFF: /** - * emstorage_get_searched_mail_list - Get the mail list information after filtering - * - * - */ + * emstorage_get_searched_mail_list - Get the mail list information after filtering + * + * + */ INTERNAL_FUNC int emstorage_get_searched_mail_list(char *multi_user_name, int account_id, int mailbox_id, int thread_id, int search_type, const char *search_value, int start_index, int limit_count, email_sort_type_t sorting, int transaction, email_mail_list_item_t **mail_list, int *result_count, int *err_code) { EM_DEBUG_FUNC_BEGIN(); @@ -4037,7 +4042,7 @@ static int _get_password_file_name(char *multi_user_name, int account_id, char * return EMAIL_ERROR_INVALID_PARAM; } - EM_DEBUG_LOG("MULTI_USER_NAME : [%s]", multi_user_name); + EM_DEBUG_LOG("MULTI_USER_NAME : [%s]", multi_user_name); if (EM_SAFE_STRLEN(multi_user_name) > 0) { snprintf(recv_password_file_name, MAX_PW_FILE_NAME_LENGTH, ".email_account_%d_recv_%s", account_id, multi_user_name); @@ -4105,42 +4110,42 @@ INTERNAL_FUNC int emstorage_get_account_by_id(char *multi_user_name, int account if (pulloption & EMAIL_ACC_GET_OPT_DEFAULT) { SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, - "incoming_server_type," - "incoming_server_address," - "user_email_address," - "incoming_server_user_name," - "retrieval_mode," - "incoming_server_port_number," - "incoming_server_secure_connection," - "incoming_server_authentication_method," - "outgoing_server_type," - "outgoing_server_address," - "outgoing_server_port_number," - "outgoing_server_need_authentication," - "outgoing_server_secure_connection," - "outgoing_server_user_name," - "user_display_name," - "reply_to_address," - "return_address," - "account_id," - "keep_mails_on_pop_server_after_download," - "auto_download_size," - "peak_interval," - "peak_days," - "peak_start_time," - "peak_end_time," - "outgoing_server_use_same_authenticator," - "auto_resend_times," - "outgoing_server_size_limit," - "wifi_auto_download," - "pop_before_smtp," - "incoming_server_requires_apop," - "logo_icon_path," - "user_data," - "user_data_length," - "color_label," - "check_interval," - "sync_status,"); + "incoming_server_type," + "incoming_server_address," + "user_email_address," + "incoming_server_user_name," + "retrieval_mode," + "incoming_server_port_number," + "incoming_server_secure_connection," + "incoming_server_authentication_method," + "outgoing_server_type," + "outgoing_server_address," + "outgoing_server_port_number," + "outgoing_server_need_authentication," + "outgoing_server_secure_connection," + "outgoing_server_user_name," + "user_display_name," + "reply_to_address," + "return_address," + "account_id," + "keep_mails_on_pop_server_after_download," + "auto_download_size," + "peak_interval," + "peak_days," + "peak_start_time," + "peak_end_time," + "outgoing_server_use_same_authenticator," + "auto_resend_times," + "outgoing_server_size_limit," + "wifi_auto_download," + "pop_before_smtp," + "incoming_server_requires_apop," + "logo_icon_path," + "user_data," + "user_data_length," + "color_label," + "check_interval," + "sync_status,"); sql_len = EM_SAFE_STRLEN(sql_query_string); } @@ -4152,33 +4157,33 @@ INTERNAL_FUNC int emstorage_get_account_by_id(char *multi_user_name, int account /* get from secure storage, not from db */ if (pulloption & EMAIL_ACC_GET_OPT_OPTIONS) { SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, - "priority," - "keep_local_copy," - "req_delivery_receipt," - "req_read_receipt," - "download_limit," - "block_address," - "block_subject," - "display_name_from," - "reply_with_body," - "forward_with_files," - "add_myname_card," - "add_signature," - "signature," - "add_my_address_to_bcc," - "notification_status," - "vibrate_status," - "display_content_status," - "default_ringtone_status," - "alert_ringtone_path," - "account_svc_id," - "sync_disabled," - "default_mail_slot_size," - "roaming_option," - "smime_type," - "certificate_path," - "cipher_type," - "digest_type,"); + "priority," + "keep_local_copy," + "req_delivery_receipt," + "req_read_receipt," + "download_limit," + "block_address," + "block_subject," + "display_name_from," + "reply_with_body," + "forward_with_files," + "add_myname_card," + "add_signature," + "signature," + "add_my_address_to_bcc," + "notification_status," + "vibrate_status," + "display_content_status," + "default_ringtone_status," + "alert_ringtone_path," + "account_svc_id," + "sync_disabled," + "default_mail_slot_size," + "roaming_option," + "smime_type," + "certificate_path," + "cipher_type," + "digest_type,"); sql_len = EM_SAFE_STRLEN(sql_query_string); } @@ -4192,11 +4197,11 @@ INTERNAL_FUNC int emstorage_get_account_by_id(char *multi_user_name, int account /* execute a sql and count rows */ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); if (rc == SQLITE_DONE) { EM_DEBUG_EXCEPTION("no matched account found..."); @@ -4410,17 +4415,17 @@ INTERNAL_FUNC int emstorage_update_account_password(char *multi_user_name, int i /* get password file name */ if ((err = _get_password_file_name(multi_user_name, - input_account_id, - recv_password_file_name, - send_password_file_name)) != EMAIL_ERROR_NONE) { + input_account_id, + recv_password_file_name, + send_password_file_name)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("_get_password_file_name failed."); goto FINISH_OFF; } EM_DEBUG_LOG_SEC("recv_password_file_name [%s] input_incoming_server_password [%s]", - recv_password_file_name, input_incoming_server_password); + recv_password_file_name, input_incoming_server_password); EM_DEBUG_LOG_SEC("send_password_file_name [%s] input_outgoing_server_password [%s]", - send_password_file_name, input_outgoing_server_password); + send_password_file_name, input_outgoing_server_password); if (input_incoming_server_password) { err = emcore_remove_password_in_key_manager(recv_password_file_name); @@ -4479,78 +4484,78 @@ INTERNAL_FUNC int emstorage_update_account(char *multi_user_name, int account_id EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error); SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_account_tbl SET" - " account_name = ?" - ", logo_icon_path = ?" - ", user_data = ?" - ", user_data_length = ?" - ", account_svc_id = ?" - ", sync_status = ?" - ", sync_disabled = ?" - ", default_mail_slot_size = ?" - ", roaming_option = ?" - ", color_label = ?" - ", user_display_name = ?" - ", user_email_address = ?" - ", reply_to_address = ?" - ", return_address = ?" - ", incoming_server_type = ?" - ", incoming_server_address = ?" - ", incoming_server_port_number = ?" - ", incoming_server_user_name = ?" - ", incoming_server_secure_connection = ?" - ", incoming_server_authentication_method = ?" - ", retrieval_mode = ?" - ", keep_mails_on_pop_server_after_download = ?" - ", check_interval = ?" - ", auto_download_size = ?" - ", peak_interval = ?" - ", peak_days = ?" - ", peak_start_time = ?" - ", peak_end_time = ?" - ", outgoing_server_type = ?" - ", outgoing_server_address = ?" - ", outgoing_server_port_number = ?" - ", outgoing_server_user_name = ?" - ", outgoing_server_secure_connection = ?" - ", outgoing_server_need_authentication = ?" - ", outgoing_server_use_same_authenticator = ?" - ", priority = ?" - ", keep_local_copy = ?" - ", req_delivery_receipt = ?" - ", req_read_receipt = ?" - ", download_limit = ?" - ", block_address = ?" - ", block_subject = ?" - ", display_name_from = ?" - ", reply_with_body = ?" - ", forward_with_files = ?" - ", add_myname_card = ?" - ", add_signature = ?" - ", signature = ?" - ", add_my_address_to_bcc = ?" - ", notification_status = ?" - ", vibrate_status = ?" - ", display_content_status = ?" - ", default_ringtone_status = ?" - ", alert_ringtone_path = ?" - ", auto_resend_times = ?" - ", outgoing_server_size_limit = ?" - ", wifi_auto_download = ?" - ", pop_before_smtp = ?" - ", incoming_server_requires_apop = ?" - ", smime_type = ?" - ", certificate_path = ?" - ", cipher_type = ?" - ", digest_type = ?" - ", user_name = ?" - " WHERE account_id = ?"); + "UPDATE mail_account_tbl SET" + " account_name = ?" + ", logo_icon_path = ?" + ", user_data = ?" + ", user_data_length = ?" + ", account_svc_id = ?" + ", sync_status = ?" + ", sync_disabled = ?" + ", default_mail_slot_size = ?" + ", roaming_option = ?" + ", color_label = ?" + ", user_display_name = ?" + ", user_email_address = ?" + ", reply_to_address = ?" + ", return_address = ?" + ", incoming_server_type = ?" + ", incoming_server_address = ?" + ", incoming_server_port_number = ?" + ", incoming_server_user_name = ?" + ", incoming_server_secure_connection = ?" + ", incoming_server_authentication_method = ?" + ", retrieval_mode = ?" + ", keep_mails_on_pop_server_after_download = ?" + ", check_interval = ?" + ", auto_download_size = ?" + ", peak_interval = ?" + ", peak_days = ?" + ", peak_start_time = ?" + ", peak_end_time = ?" + ", outgoing_server_type = ?" + ", outgoing_server_address = ?" + ", outgoing_server_port_number = ?" + ", outgoing_server_user_name = ?" + ", outgoing_server_secure_connection = ?" + ", outgoing_server_need_authentication = ?" + ", outgoing_server_use_same_authenticator = ?" + ", priority = ?" + ", keep_local_copy = ?" + ", req_delivery_receipt = ?" + ", req_read_receipt = ?" + ", download_limit = ?" + ", block_address = ?" + ", block_subject = ?" + ", display_name_from = ?" + ", reply_with_body = ?" + ", forward_with_files = ?" + ", add_myname_card = ?" + ", add_signature = ?" + ", signature = ?" + ", add_my_address_to_bcc = ?" + ", notification_status = ?" + ", vibrate_status = ?" + ", display_content_status = ?" + ", default_ringtone_status = ?" + ", alert_ringtone_path = ?" + ", auto_resend_times = ?" + ", outgoing_server_size_limit = ?" + ", wifi_auto_download = ?" + ", pop_before_smtp = ?" + ", incoming_server_requires_apop = ?" + ", smime_type = ?" + ", certificate_path = ?" + ", cipher_type = ?" + ", digest_type = ?" + ", user_name = ?" + " WHERE account_id = ?"); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG("After sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_LOG_SEC("SQL[%s]", sql_query_string); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_prepare fail:(%d) %s", rc, sqlite3_errmsg(local_db_handle))); + ("sqlite3_prepare fail:(%d) %s", rc, sqlite3_errmsg(local_db_handle))); int i = 0; @@ -4622,9 +4627,9 @@ INTERNAL_FUNC int emstorage_update_account(char *multi_user_name, int account_id EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMAIL_ERROR_MAIL_MEMORY_FULL; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); /* validate account existence */ rc = sqlite3_changes(local_db_handle); @@ -4734,7 +4739,7 @@ INTERNAL_FUNC int emstorage_get_sync_status_of_account(char *multi_user_name, in EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); if (!count) { EM_DEBUG_EXCEPTION("no matched account found..."); @@ -4782,16 +4787,16 @@ INTERNAL_FUNC int emstorage_update_sync_status_of_account(char *multi_user_name, return false; } switch (set_operator) { - case SET_TYPE_UNION: - set_value = result_sync_status | set_value; - break; - case SET_TYPE_MINUS: - set_value = result_sync_status & (~set_value); - break; - default: - EM_DEBUG_EXCEPTION("EMAIL_ERROR_NOT_SUPPORTED [%d]", set_operator); - error = EMAIL_ERROR_NOT_SUPPORTED; - break; + case SET_TYPE_UNION: + set_value = result_sync_status | set_value; + break; + case SET_TYPE_MINUS: + set_value = result_sync_status & (~set_value); + break; + default: + EM_DEBUG_EXCEPTION("EMAIL_ERROR_NOT_SUPPORTED [%d]", set_operator); + error = EMAIL_ERROR_NOT_SUPPORTED; + break; } EM_DEBUG_LOG("set_value [%d]", set_value); } @@ -4865,14 +4870,13 @@ INTERNAL_FUNC int emstorage_add_account(char *multi_user_name, emstorage_account EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, &row_count, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); if (NULL == result[1]) rc = 1; else { for (i = 1; i <= row_count; i++) { - if (i != atoi(result[i])) { + if (i != atoi(result[i])) break; - } } rc = i; @@ -4895,80 +4899,80 @@ INTERNAL_FUNC int emstorage_add_account(char *multi_user_name, emstorage_account EM_DEBUG_LOG(" >>>> ACCOUNT_ID [ %d ] ", account_tbl->account_id); SNPRINTF(sql_query_string, sizeof(sql_query_string), - "INSERT INTO mail_account_tbl VALUES " - "( " - " ? " /* account_id */ - " , ? " /* account_name */ - " , ? " /* logo_icon_path */ - " , ? " /* user_data */ - " , ? " /* user_data_length */ - " , ? " /* account_svc_id */ - " , ? " /* sync_status */ - " , ? " /* sync_disabled */ - " , ? " /* default_mail_slot_size */ - " , ? " /* roaming_option */ - " , ? " /* color_label */ - " , ? " /* user_display_name */ - " , ? " /* user_email_address */ - " , ? " /* reply_to_address */ - " , ? " /* return_address */ - " , ? " /* incoming_server_type */ - " , ? " /* incoming_server_address */ - " , ? " /* incoming_server_port_number */ - " , ? " /* incoming_server_user_name */ - " , ? " /* incoming_server_password */ - " , ? " /* incoming_server_secure_connection */ - " , ? " /* incoming_server_authentication_method */ - " , ? " /* retrieval_mode */ - " , ? " /* keep_mails_on_pop_server_after_download */ - " , ? " /* check_interval */ - " , ? " /* auto_download_size */ - " , ? " /* peak_interval */ - " , ? " /* peak_days */ - " , ? " /* peak_start_time */ - " , ? " /* peak_end_time */ - " , ? " /* outgoing_server_type */ - " , ? " /* outgoing_server_address */ - " , ? " /* outgoing_server_port_number */ - " , ? " /* outgoing_server_user_name */ - " , ? " /* outgoing_server_password */ - " , ? " /* outgoing_server_secure_connection */ - " , ? " /* outgoing_server_need_authentication */ - " , ? " /* outgoing_server_use_same_authenticator */ - " , ? " /* priority */ - " , ? " /* keep_local_copy */ - " , ? " /* req_delivery_receipt */ - " , ? " /* req_read_receipt */ - " , ? " /* download_limit */ - " , ? " /* block_address */ - " , ? " /* block_subject */ - " , ? " /* display_name_from */ - " , ? " /* reply_with_body */ - " , ? " /* forward_with_files */ - " , ? " /* add_myname_card */ - " , ? " /* add_signature */ - " , ? " /* signature */ - " , ? " /* add_my_address_to_bcc */ - " , ? " /* auto_resend_times */ - " , ? " /* outgoing_server_size_limit */ - " , ? " /* wifi_auto_download */ - " , ? " /* pop_before_smtp */ - " , ? " /* incoming_server_requires_apop */ - " , ? " /* smime_type */ - " , ? " /* certificate_path */ - " , ? " /* cipher_type */ - " , ? " /* digest_type */ - " , ? " /* notification_status */ - " , ? " /* vibrate_status */ - " , ? " /* display_content_status */ - " , ? " /* default_ringtone_status */ - " , ? " /* alert_ringtone_path */ - " , ? " /* user_name */ - ") "); + "INSERT INTO mail_account_tbl VALUES " + "( " + " ? " /* account_id */ + " , ? " /* account_name */ + " , ? " /* logo_icon_path */ + " , ? " /* user_data */ + " , ? " /* user_data_length */ + " , ? " /* account_svc_id */ + " , ? " /* sync_status */ + " , ? " /* sync_disabled */ + " , ? " /* default_mail_slot_size */ + " , ? " /* roaming_option */ + " , ? " /* color_label */ + " , ? " /* user_display_name */ + " , ? " /* user_email_address */ + " , ? " /* reply_to_address */ + " , ? " /* return_address */ + " , ? " /* incoming_server_type */ + " , ? " /* incoming_server_address */ + " , ? " /* incoming_server_port_number */ + " , ? " /* incoming_server_user_name */ + " , ? " /* incoming_server_password */ + " , ? " /* incoming_server_secure_connection */ + " , ? " /* incoming_server_authentication_method */ + " , ? " /* retrieval_mode */ + " , ? " /* keep_mails_on_pop_server_after_download */ + " , ? " /* check_interval */ + " , ? " /* auto_download_size */ + " , ? " /* peak_interval */ + " , ? " /* peak_days */ + " , ? " /* peak_start_time */ + " , ? " /* peak_end_time */ + " , ? " /* outgoing_server_type */ + " , ? " /* outgoing_server_address */ + " , ? " /* outgoing_server_port_number */ + " , ? " /* outgoing_server_user_name */ + " , ? " /* outgoing_server_password */ + " , ? " /* outgoing_server_secure_connection */ + " , ? " /* outgoing_server_need_authentication */ + " , ? " /* outgoing_server_use_same_authenticator */ + " , ? " /* priority */ + " , ? " /* keep_local_copy */ + " , ? " /* req_delivery_receipt */ + " , ? " /* req_read_receipt */ + " , ? " /* download_limit */ + " , ? " /* block_address */ + " , ? " /* block_subject */ + " , ? " /* display_name_from */ + " , ? " /* reply_with_body */ + " , ? " /* forward_with_files */ + " , ? " /* add_myname_card */ + " , ? " /* add_signature */ + " , ? " /* signature */ + " , ? " /* add_my_address_to_bcc */ + " , ? " /* auto_resend_times */ + " , ? " /* outgoing_server_size_limit */ + " , ? " /* wifi_auto_download */ + " , ? " /* pop_before_smtp */ + " , ? " /* incoming_server_requires_apop */ + " , ? " /* smime_type */ + " , ? " /* certificate_path */ + " , ? " /* cipher_type */ + " , ? " /* digest_type */ + " , ? " /* notification_status */ + " , ? " /* vibrate_status */ + " , ? " /* display_content_status */ + " , ? " /* default_ringtone_status */ + " , ? " /* alert_ringtone_path */ + " , ? " /* user_name */ + ") "); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); i = 0; @@ -5043,9 +5047,9 @@ INTERNAL_FUNC int emstorage_add_account(char *multi_user_name, emstorage_account EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d, errmsg = %s.", rc, sqlite3_errmsg(local_db_handle))); + ("sqlite3_step fail:%d, errmsg = %s.", rc, sqlite3_errmsg(local_db_handle))); /* save passwords to the secure storage */ @@ -5122,8 +5126,8 @@ INTERNAL_FUNC int emstorage_delete_account(char *multi_user_name, int account_id SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_account_tbl WHERE account_id = %d", account_id); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } /* validate account existence */ @@ -5134,7 +5138,7 @@ INTERNAL_FUNC int emstorage_delete_account(char *multi_user_name, int account_id goto FINISH_OFF; } - /* delete from secure storage */ + /* delete from secure storage */ error = emcore_remove_password_in_key_manager(recv_password_file_name); if (error != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_remove_password_in_key_manager failed : [%d]", error); @@ -5237,7 +5241,7 @@ INTERNAL_FUNC int emstorage_get_mailbox_count(char *multi_user_name, int account EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); *count = atoi(result[1]); sqlite3_free_table(result); @@ -5286,21 +5290,21 @@ INTERNAL_FUNC int emstorage_get_mailbox_list(char *multi_user_name, int account_ EM_DEBUG_LOG("conditional_clause_string[%s]", conditional_clause_string); switch (sort_type) { - case EMAIL_MAILBOX_SORT_BY_NAME_ASC: - SNPRINTF(ordering_clause_string, QUERY_SIZE, " ORDER BY mailbox_name ASC"); - break; + case EMAIL_MAILBOX_SORT_BY_NAME_ASC: + SNPRINTF(ordering_clause_string, QUERY_SIZE, " ORDER BY mailbox_name ASC"); + break; - case EMAIL_MAILBOX_SORT_BY_NAME_DSC: - SNPRINTF(ordering_clause_string, QUERY_SIZE, " ORDER BY mailbox_name DESC"); - break; + case EMAIL_MAILBOX_SORT_BY_NAME_DSC: + SNPRINTF(ordering_clause_string, QUERY_SIZE, " ORDER BY mailbox_name DESC"); + break; - case EMAIL_MAILBOX_SORT_BY_TYPE_ASC: - SNPRINTF(ordering_clause_string, QUERY_SIZE, " ORDER BY mailbox_type ASC"); - break; + case EMAIL_MAILBOX_SORT_BY_TYPE_ASC: + SNPRINTF(ordering_clause_string, QUERY_SIZE, " ORDER BY mailbox_type ASC"); + break; - case EMAIL_MAILBOX_SORT_BY_TYPE_DSC: - SNPRINTF(ordering_clause_string, QUERY_SIZE, " ORDER BY mailbox_type DEC"); - break; + case EMAIL_MAILBOX_SORT_BY_TYPE_DSC: + SNPRINTF(ordering_clause_string, QUERY_SIZE, " ORDER BY mailbox_type DEC"); + break; } EM_DEBUG_LOG("ordering_clause_string[%s]", ordering_clause_string); @@ -5351,9 +5355,9 @@ INTERNAL_FUNC int emstorage_get_mailbox_list_ex(char *multi_user_name, int accou } SNPRINTF(ordering_clause_string, QUERY_SIZE, " ORDER BY CASE WHEN MBT.mailbox_name" - " GLOB \'[][~`!@#$%%^&*()_-+=|\\{}:;<>,.?/ ]*\'" - " THEN 2 ELSE 1 END ASC," - " MBT.mailbox_name COLLATE CONVERTUTF8 ASC "); + " GLOB \'[][~`!@#$%%^&*()_-+=|\\{}:;<>,.?/ ]*\'" + " THEN 2 ELSE 1 END ASC," + " MBT.mailbox_name COLLATE CONVERTUTF8 ASC "); EM_DEBUG_LOG("conditional_clause_string[%s]", conditional_clause_string); EM_DEBUG_LOG("ordering_clause_string[%s]", ordering_clause_string); @@ -5461,20 +5465,20 @@ INTERNAL_FUNC int emstorage_stamp_last_sync_time_of_mailbox(char *multi_user_nam time(¤t_time); local_db_handle = emstorage_get_db_connection(multi_user_name); - EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, input_transaction, error); + EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, input_transaction, error); - SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_box_tbl SET" - " last_sync_time = %d" - " WHERE mailbox_id = %d" - , (int)current_time - , input_mailbox_id); + SNPRINTF(sql_query_string, sizeof(sql_query_string), + "UPDATE mail_box_tbl SET" + " last_sync_time = %d" + " WHERE mailbox_id = %d" + , (int)current_time + , input_mailbox_id); EM_DEBUG_LOG_SEC("sql_query_string [%s]", sql_query_string); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } FINISH_OFF: @@ -5609,8 +5613,8 @@ INTERNAL_FUNC int emstorage_get_mailbox_by_id(char *multi_user_name, int input_m EM_DEBUG_LOG("conditional_clause_string = [%s]", conditional_clause_string); if ((ret = emstorage_query_mailbox_tbl(multi_user_name, - conditional_clause_string, - "", true, false, output_mailbox, &result_count)) != EMAIL_ERROR_NONE) { + conditional_clause_string, + "", true, false, output_mailbox, &result_count)) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emstorage_query_mailbox_tbl failed [%d]", ret); goto FINISH_OFF; } @@ -5698,12 +5702,12 @@ INTERNAL_FUNC int emstorage_get_mailbox_id_by_mailbox_type(char *multi_user_name EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); if (rc == SQLITE_DONE) { EM_DEBUG_EXCEPTION("no matched mailbox_name found..."); @@ -5768,12 +5772,12 @@ INTERNAL_FUNC int emstorage_get_mailbox_name_by_mailbox_type(char *multi_user_na EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); if (rc == SQLITE_DONE) { EM_DEBUG_EXCEPTION("no matched mailbox_name found..."); @@ -5812,11 +5816,10 @@ INTERNAL_FUNC int emstorage_update_mailbox_modifiable_yn(char *multi_user_name, char *replaced_mailbox_name = NULL; if (mailbox_name) { - if (strstr(mailbox_name, "'")) { + if (strstr(mailbox_name, "'")) replaced_mailbox_name = em_replace_all_string(mailbox_name, "'", "''"); - } else { + else replaced_mailbox_name = strdup(mailbox_name); - } } sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name); @@ -5824,20 +5827,20 @@ INTERNAL_FUNC int emstorage_update_mailbox_modifiable_yn(char *multi_user_name, EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error); SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_box_tbl SET" - " modifiable_yn = %d" - " WHERE account_id = %d" - " AND local_yn = %d" - " AND mailbox_name = '%s'" - , modifiable_yn - , account_id - , local_yn - , replaced_mailbox_name); + "UPDATE mail_box_tbl SET" + " modifiable_yn = %d" + " WHERE account_id = %d" + " AND local_yn = %d" + " AND mailbox_name = '%s'" + , modifiable_yn + , account_id + , local_yn + , replaced_mailbox_name); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } ret = true; @@ -5845,7 +5848,7 @@ INTERNAL_FUNC int emstorage_update_mailbox_modifiable_yn(char *multi_user_name, FINISH_OFF: EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error); - EM_SAFE_FREE(replaced_mailbox_name); + EM_SAFE_FREE(replaced_mailbox_name); if (err_code != NULL) *err_code = error; @@ -5856,15 +5859,15 @@ FINISH_OFF: } INTERNAL_FUNC int emstorage_update_mailbox_total_count(char *multi_user_name, - int account_id, - int input_mailbox_id, - int total_count_on_server, - int transaction, - int *err_code) + int account_id, + int input_mailbox_id, + int total_count_on_server, + int transaction, + int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id[%d], input_mailbox_id[%d], total_count_on_server[%d], " - "transaction[%d], err_code[%p]", - account_id, input_mailbox_id, total_count_on_server, transaction, err_code); + "transaction[%d], err_code[%p]", + account_id, input_mailbox_id, total_count_on_server, transaction, err_code); int ret = false; int error = EMAIL_ERROR_NONE; @@ -5883,19 +5886,19 @@ INTERNAL_FUNC int emstorage_update_mailbox_total_count(char *multi_user_name, EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error); SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_box_tbl SET" - " total_mail_count_on_server = %d" - " WHERE account_id = %d" - " AND mailbox_id = %d" - , total_count_on_server - , account_id - , input_mailbox_id); + "UPDATE mail_box_tbl SET" + " total_mail_count_on_server = %d" + " WHERE account_id = %d" + " AND mailbox_id = %d" + , total_count_on_server + , account_id + , input_mailbox_id); EM_DEBUG_LOG_SEC("query[%s]", sql_query_string); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } ret = true; @@ -5936,43 +5939,43 @@ INTERNAL_FUNC int emstorage_update_mailbox(char *multi_user_name, int account_id if (local_yn != -1) { SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_box_tbl SET" - " mailbox_id = ?" - ", mailbox_name = ?" - ", mailbox_type = ?" - ", alias = ?" - ", deleted_flag = ?" - ", modifiable_yn= ?" - ", mail_slot_size= ?" - ", total_mail_count_on_server = ?" - " WHERE account_id = %d" - " AND local_yn = %d" - " AND mailbox_id = '%d'" - , account_id - , local_yn - , input_mailbox_id); + "UPDATE mail_box_tbl SET" + " mailbox_id = ?" + ", mailbox_name = ?" + ", mailbox_type = ?" + ", alias = ?" + ", deleted_flag = ?" + ", modifiable_yn= ?" + ", mail_slot_size= ?" + ", total_mail_count_on_server = ?" + " WHERE account_id = %d" + " AND local_yn = %d" + " AND mailbox_id = '%d'" + , account_id + , local_yn + , input_mailbox_id); } else { SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_box_tbl SET" - " mailbox_id = ?" - ", mailbox_name = ?" - ", mailbox_type = ?" - ", alias = ?" - ", deleted_flag = ?" - ", modifiable_yn= ?" - ", mail_slot_size= ?" - ", total_mail_count_on_server = ?" - " WHERE account_id = %d" - " AND mailbox_id = '%d'" - , account_id - , input_mailbox_id); + "UPDATE mail_box_tbl SET" + " mailbox_id = ?" + ", mailbox_name = ?" + ", mailbox_type = ?" + ", alias = ?" + ", deleted_flag = ?" + ", modifiable_yn= ?" + ", mail_slot_size= ?" + ", total_mail_count_on_server = ?" + " WHERE account_id = %d" + " AND mailbox_id = '%d'" + , account_id + , input_mailbox_id); } EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); _bind_stmt_field_data_int(hStmt, i++, result_mailbox->mailbox_id); _bind_stmt_field_data_string(hStmt, i++, (char *)result_mailbox->mailbox_name ? result_mailbox->mailbox_name : "", 0, MAILBOX_NAME_LEN_IN_MAIL_READ_MAIL_UID_TBL); @@ -5986,9 +5989,9 @@ INTERNAL_FUNC int emstorage_update_mailbox(char *multi_user_name, int account_id EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); ret = true; @@ -6038,22 +6041,22 @@ INTERNAL_FUNC int emstorage_update_mailbox_type(char *multi_user_name, int accou /* Update mail_box_tbl */ if (local_yn != -1) { SNPRINTF(sql_query_string, sizeof(sql_query_string)-1, - "UPDATE mail_box_tbl SET" - " mailbox_type = ?" - " WHERE account_id = %d" - " AND local_yn = %d" - " AND mailbox_id = '%d'" - , account_id - , local_yn - , input_mailbox_id); + "UPDATE mail_box_tbl SET" + " mailbox_type = ?" + " WHERE account_id = %d" + " AND local_yn = %d" + " AND mailbox_id = '%d'" + , account_id + , local_yn + , input_mailbox_id); } else { SNPRINTF(sql_query_string, sizeof(sql_query_string)-1, - "UPDATE mail_box_tbl SET" - " mailbox_type = ?" - " WHERE account_id = %d" - " AND mailbox_id = '%d'" - , account_id - , input_mailbox_id); + "UPDATE mail_box_tbl SET" + " mailbox_type = ?" + " WHERE account_id = %d" + " AND mailbox_id = '%d'" + , account_id + , input_mailbox_id); } EM_DEBUG_LOG_SEC("SQL(%s)", sql_query_string); @@ -6170,34 +6173,34 @@ INTERNAL_FUNC int emstorage_set_local_mailbox(char *multi_user_name, int input_m /* Update mail_box_tbl */ SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_box_tbl SET" - " local_yn = ?" - " WHERE mailbox_id = %d" - , input_mailbox_id); + "UPDATE mail_box_tbl SET" + " local_yn = ?" + " WHERE mailbox_id = %d" + , input_mailbox_id); EM_DEBUG_LOG_SEC("SQL(%s)", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); _bind_stmt_field_data_int(hStmt, i++, input_is_local_mailbox); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); -/* - if (hStmt != NULL) { - rc = sqlite3_finalize(hStmt); - if (rc != SQLITE_OK) { - EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc); - error = EMAIL_ERROR_DB_FAILURE; - } - hStmt = NULL; - } -*/ + ("sqlite3_step fail:%d", rc)); + /* + if (hStmt != NULL) { + rc = sqlite3_finalize(hStmt); + if (rc != SQLITE_OK) { + EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc); + error = EMAIL_ERROR_DB_FAILURE; + } + hStmt = NULL; + } + */ ret = true; FINISH_OFF: @@ -6272,8 +6275,8 @@ INTERNAL_FUNC int emstorage_set_field_of_mailbox_with_integer_value(char *multi_ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, err); err = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (err != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", err); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", err); + goto FINISH_OFF; } if (sqlite3_changes(local_db_handle) == 0) @@ -6287,7 +6290,7 @@ FINISH_OFF: if (err == EMAIL_ERROR_NONE && parameter_string) { if (!emcore_notify_storage_event(NOTI_MAILBOX_FIELD_UPDATE, input_account_id, 0, parameter_string, input_value)) EM_DEBUG_EXCEPTION_SEC("emcore_notify_storage_eventfailed : NOTI_MAILBOX_FIELD_UPDATE [%s,%d]", - input_field_name, input_value); + input_field_name, input_value); } EM_SAFE_FREE(mailbox_id_string_buffer); @@ -6320,7 +6323,7 @@ INTERNAL_FUNC int emstorage_add_mailbox(char *multi_user_name, emstorage_mailbox EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); time(¤t_time); @@ -6335,29 +6338,29 @@ INTERNAL_FUNC int emstorage_add_mailbox(char *multi_user_name, emstorage_mailbox mailbox_tbl->mailbox_id = rc; SNPRINTF(sql_query_string, sizeof(sql_query_string), - "INSERT INTO mail_box_tbl VALUES " - "(?" /* mailbox_id */ - ", ?" /* account_id */ - ", ?" /* local_yn */ - ", ?" /* mailbox_name */ - ", ?" /* mailbox_type */ - ", ?" /* alias */ - ", ?" /* deleted_flag */ - ", ?" /* modifiable_yn */ - ", ?" /* total_mail_count_on_server */ - ", ?" /* has_archived_mails */ - ", ?" /* mail_slot_size */ - ", ?" /* no_select */ - ", ?" /* last_sync_time */ - ", ?" /* eas_data_length */ - ", ?" /* eas_data */ - ")"); + "INSERT INTO mail_box_tbl VALUES " + "(?" /* mailbox_id */ + ", ?" /* account_id */ + ", ?" /* local_yn */ + ", ?" /* mailbox_name */ + ", ?" /* mailbox_type */ + ", ?" /* alias */ + ", ?" /* deleted_flag */ + ", ?" /* modifiable_yn */ + ", ?" /* total_mail_count_on_server */ + ", ?" /* has_archived_mails */ + ", ?" /* mail_slot_size */ + ", ?" /* no_select */ + ", ?" /* last_sync_time */ + ", ?" /* eas_data_length */ + ", ?" /* eas_data */ + ")"); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG_DEV("After sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); int col_index = 0; @@ -6380,7 +6383,7 @@ INTERNAL_FUNC int emstorage_add_mailbox(char *multi_user_name, emstorage_mailbox EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%dn", rc)); + ("sqlite3_step fail:%dn", rc)); ret = true; @@ -6396,7 +6399,7 @@ FINISH_OFF: if (error == EMAIL_ERROR_NONE) { if (!emcore_notify_storage_event(NOTI_MAILBOX_ADD, mailbox_tbl->account_id, mailbox_tbl->mailbox_id, - mailbox_tbl->mailbox_name, mailbox_tbl->mailbox_type)) + mailbox_tbl->mailbox_name, mailbox_tbl->mailbox_type)) EM_DEBUG_EXCEPTION("emcore_notify_storage_event[ NOTI_MAILBOX_ADD] : Notification Failed"); } @@ -6430,8 +6433,8 @@ INTERNAL_FUNC int emstorage_set_all_mailbox_modifiable_yn(char *multi_user_name, error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } rc = sqlite3_changes(local_db_handle); @@ -6482,8 +6485,8 @@ INTERNAL_FUNC int emstorage_delete_mailbox(char *multi_user_name, int account_id EM_DEBUG_LOG_SEC("mailbox sql_query_string [%s]", sql_query_string); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } rc = sqlite3_changes(local_db_handle); @@ -6492,7 +6495,7 @@ INTERNAL_FUNC int emstorage_delete_mailbox(char *multi_user_name, int account_id error = EMAIL_ERROR_MAILBOX_NOT_FOUND; ret = true; } - ret = true; + ret = true; FINISH_OFF: @@ -6543,7 +6546,7 @@ FINISH_OFF: if (err_code != NULL) *err_code = error; - EM_DEBUG_FUNC_END("ret [%d]", ret); + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } @@ -6564,11 +6567,10 @@ INTERNAL_FUNC int emstorage_get_count_read_mail_uid(char *multi_user_name, int a char sql_query_string[QUERY_SIZE] = {0, }; char *replaced_mailbox_name = NULL; - if (strstr(mailbox_name, "'")) { + if (strstr(mailbox_name, "'")) replaced_mailbox_name = em_replace_all_string(mailbox_name, "'", "''"); - } else { + else replaced_mailbox_name = EM_SAFE_STRDUP(mailbox_name); - } EM_DEBUG_LOG_SEC("replaced_mailbox_name : [%s]", replaced_mailbox_name); @@ -6582,7 +6584,7 @@ INTERNAL_FUNC int emstorage_get_count_read_mail_uid(char *multi_user_name, int a EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); *count = atoi(result[1]); sqlite3_free_table(result); @@ -6624,11 +6626,10 @@ INTERNAL_FUNC int emstorage_check_read_mail_uid(char *multi_user_name, int accou EMSTORAGE_START_READ_TRANSACTION(transaction); if (mailbox_name) { - if (strstr(mailbox_name, "'")) { + if (strstr(mailbox_name, "'")) replaced_mailbox_name = em_replace_all_string(mailbox_name, "'", "''"); - } else { + else replaced_mailbox_name = strdup(mailbox_name); - } SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_read_mail_uid_tbl WHERE account_id = %d AND mailbox_name = '%s' AND server_uid = '%s' ", account_id, replaced_mailbox_name, uid); } else { @@ -6639,7 +6640,7 @@ INTERNAL_FUNC int emstorage_check_read_mail_uid(char *multi_user_name, int accou EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); *exist = atoi(result[1]); sqlite3_free_table(result); @@ -6688,12 +6689,12 @@ INTERNAL_FUNC int emstorage_get_downloaded_mail(char *multi_user_name, int mail_ EM_DEBUG_LOG("sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); *mail = (emstorage_mail_tbl_t*)malloc(sizeof(emstorage_mail_tbl_t)); if (*mail == NULL) { @@ -6771,18 +6772,18 @@ INTERNAL_FUNC int emstorage_get_downloaded_list(char *multi_user_name, int accou EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG("sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); char **result; /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, count, NULL, NULL); */ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, count, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); sqlite3_free_table(result); if (*count == 0) { @@ -6812,7 +6813,7 @@ INTERNAL_FUNC int emstorage_get_downloaded_list(char *multi_user_name, int accou EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); } ret = true; @@ -6863,41 +6864,40 @@ INTERNAL_FUNC int emstorage_get_downloaded_mail_size(char *multi_user_name, int EMSTORAGE_START_READ_TRANSACTION(transaction); if (mailbox_name) { - if (strstr(mailbox_name, "'")) { + if (strstr(mailbox_name, "'")) replaced_mailbox_name = em_replace_all_string(mailbox_name, "'", "''"); - } else { + else replaced_mailbox_name = strdup(mailbox_name); - } EM_DEBUG_LOG_SEC("replaced_mailbox_name : [%s]", replaced_mailbox_name); SNPRINTF(sql_query_string, sizeof(sql_query_string), - "SELECT IFNULL(MAX(data1), 0) FROM mail_read_mail_uid_tbl " - "WHERE account_id = %d " - "AND mailbox_id = '%s' " - "AND local_uid = %d " - "AND mailbox_name = '%s' " - "AND server_uid = '%s'", - account_id, mailbox_id, local_uid, replaced_mailbox_name, uid); + "SELECT IFNULL(MAX(data1), 0) FROM mail_read_mail_uid_tbl " + "WHERE account_id = %d " + "AND mailbox_id = '%s' " + "AND local_uid = %d " + "AND mailbox_name = '%s' " + "AND server_uid = '%s'", + account_id, mailbox_id, local_uid, replaced_mailbox_name, uid); } else { SNPRINTF(sql_query_string, sizeof(sql_query_string), - "SELECT IFNULL(MAX(data1), 0) FROM mail_read_mail_uid_tbl " - "WHERE account_id = %d " - "AND mailbox_id = '%s' " - "AND local_uid = %d " - "AND server_uid = '%s'", - account_id, mailbox_id, local_uid, uid); + "SELECT IFNULL(MAX(data1), 0) FROM mail_read_mail_uid_tbl " + "WHERE account_id = %d " + "AND mailbox_id = '%s' " + "AND local_uid = %d " + "AND server_uid = '%s'", + account_id, mailbox_id, local_uid, uid); } EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); if (rc == SQLITE_DONE) { EM_DEBUG_LOG("no matched mail found...."); @@ -6954,24 +6954,24 @@ INTERNAL_FUNC int emstorage_add_downloaded_mail(char *multi_user_name, emstorage EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); if (NULL == result[1]) rc = 1; else rc = atoi(result[1])+1; sqlite3_free_table(result); SNPRINTF(sql_query_string, sizeof(sql_query_string), - "INSERT INTO mail_read_mail_uid_tbl VALUES " - "(?" /* account_id */ - ", ?" /* mailbox_id */ - ", ?" /* mailbox_name */ - ", ?" /* local_uid */ - ", ?" /* server_uid */ - ", ?" /* rfc822_size */ - ", ?" /* sync_status */ - ", ?" /* flags_seen_field */ - ", ?" /* flags_flagged_field */ - ", ?)"); + "INSERT INTO mail_read_mail_uid_tbl VALUES " + "(?" /* account_id */ + ", ?" /* mailbox_id */ + ", ?" /* mailbox_name */ + ", ?" /* local_uid */ + ", ?" /* server_uid */ + ", ?" /* rfc822_size */ + ", ?" /* sync_status */ + ", ?" /* flags_seen_field */ + ", ?" /* flags_flagged_field */ + ", ?)"); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc2); @@ -6984,9 +6984,9 @@ INTERNAL_FUNC int emstorage_add_downloaded_mail(char *multi_user_name, emstorage } EM_DEBUG_LOG("account_id[%d] mailbox_id[%d] local_uid [%d]" - "server_uid[%s] rfc822_size[%d] rc[%d]", - read_mail_uid->account_id, read_mail_uid->mailbox_id, read_mail_uid->local_uid, - read_mail_uid->server_uid, read_mail_uid->rfc822_size, rc); + "server_uid[%s] rfc822_size[%d] rc[%d]", + read_mail_uid->account_id, read_mail_uid->mailbox_id, read_mail_uid->local_uid, + read_mail_uid->server_uid, read_mail_uid->rfc822_size, rc); _bind_stmt_field_data_int(hStmt, ACCOUNT_ID_IDX_IN_MAIL_READ_MAIL_UID_TBL, read_mail_uid->account_id); _bind_stmt_field_data_int(hStmt, LOCAL_MAILBOX_ID_IDX_IN_MAIL_READ_MAIL_UID_TBL, read_mail_uid->mailbox_id); @@ -7001,9 +7001,9 @@ INTERNAL_FUNC int emstorage_add_downloaded_mail(char *multi_user_name, emstorage EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail[%d] [%s]", rc, sqlite3_errmsg(local_db_handle))); + ("sqlite3_step fail[%d] [%s]", rc, sqlite3_errmsg(local_db_handle))); ret = true; @@ -7050,15 +7050,15 @@ INTERNAL_FUNC int emstorage_add_mail_text(char *multi_user_name, emstorage_mail_ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); sqlite3_free_table(result); SNPRINTF(sql_query_string, sizeof(sql_query_string), - "INSERT INTO mail_text_tbl VALUES " - "(?" - ", ?" - ", ?" - ", ?)"); + "INSERT INTO mail_text_tbl VALUES " + "(?" + ", ?" + ", ?" + ", ?)"); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc2); if (rc2 != SQLITE_OK) { @@ -7070,7 +7070,7 @@ INTERNAL_FUNC int emstorage_add_mail_text(char *multi_user_name, emstorage_mail_ } EM_DEBUG_LOG("mail_id[%d] account_id[%d] mailbox_id[%d]", mail_text->mail_id, - mail_text->account_id, mail_text->mailbox_id); + mail_text->account_id, mail_text->mailbox_id); EM_DEBUG_LOG_DEV("body_text VALUE [%s] ", mail_text->body_text); _bind_stmt_field_data_int(hStmt, MAIL_ID_IDX_IN_MAIL_TEXT_TBL, mail_text->mail_id); @@ -7080,9 +7080,9 @@ INTERNAL_FUNC int emstorage_add_mail_text(char *multi_user_name, emstorage_mail_ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail[%d] [%s]", rc, sqlite3_errmsg(local_db_handle))); + ("sqlite3_step fail[%d] [%s]", rc, sqlite3_errmsg(local_db_handle))); ret = true; @@ -7126,26 +7126,26 @@ INTERNAL_FUNC int emstorage_change_read_mail_uid(char *multi_user_name, int acco EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error); SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_read_mail_uid_tbl SET" - " account_id = ?" - ", mailbox_id = ?" - ", mailbox_name = ?" - ", local_uid = ?" - ", server_uid = ?" - ", rfc822_size = ?" - ", flags_seen_field = ?" - ", flags_flagged_field = ?" - " WHERE account_id = ?" - " AND mailbox_id = ?" - " AND local_uid = ?" - " AND mailbox_name= ?" - " AND server_uid = ?"); + "UPDATE mail_read_mail_uid_tbl SET" + " account_id = ?" + ", mailbox_id = ?" + ", mailbox_name = ?" + ", local_uid = ?" + ", server_uid = ?" + ", rfc822_size = ?" + ", flags_seen_field = ?" + ", flags_flagged_field = ?" + " WHERE account_id = ?" + " AND mailbox_id = ?" + " AND local_uid = ?" + " AND mailbox_name= ?" + " AND server_uid = ?"); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG("sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); int i = 0; @@ -7167,7 +7167,7 @@ INTERNAL_FUNC int emstorage_change_read_mail_uid(char *multi_user_name, int acco EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); ret = true; @@ -7189,16 +7189,16 @@ FINISH_OFF: } INTERNAL_FUNC int emstorage_remove_downloaded_mail(char *multi_user_name, - int account_id, - int mailbox_id, - char *mailbox_name, - char *uid, - int transaction, - int *err_code) + int account_id, + int mailbox_id, + char *mailbox_name, + char *uid, + int transaction, + int *err_code) { EM_DEBUG_FUNC_BEGIN_SEC("account_id[%d], mailbox_id[%d], mailbox_name[%s], " - "uid[%s], transaction[%d], err_code[%p]", - account_id, mailbox_id, mailbox_name, uid, transaction, err_code); + "uid[%s], transaction[%d], err_code[%p]", + account_id, mailbox_id, mailbox_name, uid, transaction, err_code); if (account_id < FIRST_ACCOUNT_ID) { EM_DEBUG_EXCEPTION_SEC(" account_id[%d], mailbox_name[%s], uid[%s]", account_id, mailbox_name, uid); @@ -7210,43 +7210,42 @@ INTERNAL_FUNC int emstorage_remove_downloaded_mail(char *multi_user_name, int ret = false; int error = EMAIL_ERROR_NONE; - char sql_query_string[QUERY_SIZE] = {0, }; + char sql_query_string[QUERY_SIZE] = {0, }; char *replaced_mailbox_name = NULL; sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name); EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error); SNPRINTF(sql_query_string, sizeof(sql_query_string), - "DELETE FROM mail_read_mail_uid_tbl WHERE account_id = %d ", account_id); + "DELETE FROM mail_read_mail_uid_tbl WHERE account_id = %d ", account_id); if (mailbox_id > 0) { SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), - sizeof(sql_query_string) - (1 + EM_SAFE_STRLEN(sql_query_string)), - "AND mailbox_id = %d ", mailbox_id); + sizeof(sql_query_string) - (1 + EM_SAFE_STRLEN(sql_query_string)), + "AND mailbox_id = %d ", mailbox_id); } if (mailbox_name) { /* NULL means all mailbox_name */ - if (strstr(mailbox_name, "'")) { + if (strstr(mailbox_name, "'")) replaced_mailbox_name = em_replace_all_string(mailbox_name, "'", "''"); - } else { + else replaced_mailbox_name = strdup(mailbox_name); - } SNPRINTF(sql_query_string+EM_SAFE_STRLEN(sql_query_string), - sizeof(sql_query_string) - (1 + EM_SAFE_STRLEN(sql_query_string)), - "AND mailbox_name = '%s' ", replaced_mailbox_name); + sizeof(sql_query_string) - (1 + EM_SAFE_STRLEN(sql_query_string)), + "AND mailbox_name = '%s' ", replaced_mailbox_name); } if (uid) { /* NULL means all mail */ sqlite3_snprintf(sizeof(sql_query_string) - (1 + EM_SAFE_STRLEN(sql_query_string)), - sql_query_string + EM_SAFE_STRLEN(sql_query_string), "AND server_uid = '%q' ", - uid); + sql_query_string + EM_SAFE_STRLEN(sql_query_string), "AND server_uid = '%q' ", + uid); } error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } ret = true; @@ -7327,7 +7326,7 @@ INTERNAL_FUNC int emstorage_get_rule_count_by_account_id(char *multi_user_name, EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); *count = atoi(result[1]); sqlite3_free_table(result); @@ -7382,20 +7381,20 @@ INTERNAL_FUNC int emstorage_get_rule(char *multi_user_name, int account_id, int } EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); -/* EM_DEBUG_LOG("sqlite3_prepare hStmt = %p", hStmt); */ + /* EM_DEBUG_LOG("sqlite3_prepare hStmt = %p", hStmt); */ EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); char **result; /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL); */ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); sqlite3_free_table(result); @@ -7430,7 +7429,7 @@ INTERNAL_FUNC int emstorage_get_rule(char *multi_user_name, int account_id, int EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); } ret = true; @@ -7492,12 +7491,12 @@ INTERNAL_FUNC int emstorage_get_rule_by_id(char *multi_user_name, int rule_id, e EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); if (rc == SQLITE_DONE) { EM_DEBUG_EXCEPTION(" no matched rule found..."); @@ -7568,25 +7567,25 @@ INTERNAL_FUNC int emstorage_change_rule(char *multi_user_name, int rule_id, emst EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error); SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_rule_tbl SET" - " filter_name = ?" - ", type = ?" - ", value = ?" - ", value2 = ?" - ", action_type = ?" - ", target_mailbox_id = ?" - ", flag1 = ?" - ", flag2 = ?" - ", account_id = ?" - ", rule_id = ?" - " WHERE rule_id = %d" - , rule_id); + "UPDATE mail_rule_tbl SET" + " filter_name = ?" + ", type = ?" + ", value = ?" + ", value2 = ?" + ", action_type = ?" + ", target_mailbox_id = ?" + ", flag1 = ?" + ", flag2 = ?" + ", account_id = ?" + ", rule_id = ?" + " WHERE rule_id = %d" + , rule_id); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG(" Before sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); int i = 0; @@ -7604,7 +7603,7 @@ INTERNAL_FUNC int emstorage_change_rule(char *multi_user_name, int rule_id, emst EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); ret = true; @@ -7649,26 +7648,26 @@ INTERNAL_FUNC int emstorage_find_rule(char *multi_user_name, emstorage_rule_tbl_ case EMAIL_FILTER_MOVE: if (rule->type == EMAIL_PRIORITY_SENDER) { sqlite3_snprintf(sizeof(sql_query_string), sql_query_string, - "SELECT rule_id FROM mail_rule_tbl WHERE action_type = %d AND type = %d AND UPPER(value2) = UPPER(\'%q\')", - rule->action_type, rule->type, rule->value2); + "SELECT rule_id FROM mail_rule_tbl WHERE action_type = %d AND type = %d AND UPPER(value2) = UPPER(\'%q\')", + rule->action_type, rule->type, rule->value2); } else { - sqlite3_snprintf(sizeof(sql_query_string), sql_query_string, + sqlite3_snprintf(sizeof(sql_query_string), sql_query_string, "SELECT rule_id FROM mail_rule_tbl WHERE action_type = %d AND type = %d AND UPPER(filter_name) = UPPER(\'%q\')", rule->action_type, rule->type, rule->filter_name); } break; case EMAIL_FILTER_BLOCK: if (rule->type == EMAIL_FILTER_FROM) sqlite3_snprintf(sizeof(sql_query_string), sql_query_string, - "SELECT rule_id FROM mail_rule_tbl WHERE action_type = %d AND type = %d AND UPPER(value2) = UPPER(\'%q\')", - rule->action_type, rule->type, rule->value2); + "SELECT rule_id FROM mail_rule_tbl WHERE action_type = %d AND type = %d AND UPPER(value2) = UPPER(\'%q\')", + rule->action_type, rule->type, rule->value2); else if (rule->type == EMAIL_FILTER_SUBJECT) sqlite3_snprintf(sizeof(sql_query_string), sql_query_string, - "SELECT rule_id FROM mail_rule_tbl WHERE action_type = %d AND type = %d AND UPPER(value) = UPPER(\'%q\')", - rule->action_type, rule->type, rule->value); + "SELECT rule_id FROM mail_rule_tbl WHERE action_type = %d AND type = %d AND UPPER(value) = UPPER(\'%q\')", + rule->action_type, rule->type, rule->value); else if (rule->type == (EMAIL_FILTER_SUBJECT | EMAIL_FILTER_FROM)) sqlite3_snprintf(sizeof(sql_query_string), sql_query_string, - "SELECT rule_id FROM mail_rule_tbl WHERE action_type = %d AND (type = %d AND UPPER(value) = UPPER(\'%q\')) OR (type = %d AND UPPER(value2) = UPPER(\'%q\'))", - rule->action_type, EMAIL_FILTER_SUBJECT, rule->value, EMAIL_FILTER_FROM, rule->value2); + "SELECT rule_id FROM mail_rule_tbl WHERE action_type = %d AND (type = %d AND UPPER(value) = UPPER(\'%q\')) OR (type = %d AND UPPER(value2) = UPPER(\'%q\'))", + rule->action_type, EMAIL_FILTER_SUBJECT, rule->value, EMAIL_FILTER_FROM, rule->value2); break; default: @@ -7680,11 +7679,11 @@ INTERNAL_FUNC int emstorage_find_rule(char *multi_user_name, emstorage_rule_tbl_ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); if (rc == SQLITE_DONE) { EM_DEBUG_EXCEPTION(" no matched rule found..."); @@ -7726,7 +7725,7 @@ INTERNAL_FUNC int emstorage_add_rule(char *multi_user_name, emstorage_rule_tbl_t int rc, rc_2, ret = false; int error = EMAIL_ERROR_NONE; DB_STMT hStmt = NULL; - char sql_query_string[QUERY_SIZE] = {0, }; + char sql_query_string[QUERY_SIZE] = {0, }; sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name); @@ -7738,7 +7737,7 @@ INTERNAL_FUNC int emstorage_add_rule(char *multi_user_name, emstorage_rule_tbl_t EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); if (NULL == result[1]) rc = 1; @@ -7750,17 +7749,17 @@ INTERNAL_FUNC int emstorage_add_rule(char *multi_user_name, emstorage_rule_tbl_t rule->rule_id = rc; SNPRINTF(sql_query_string, sizeof(sql_query_string), - "INSERT INTO mail_rule_tbl VALUES " - "(?" /* account id */ - ", ?" /* rule_id */ - ", ?" /* filter_name */ - ", ?" /* type */ - ", ?" /* value */ - ", ?" /* value2 */ - ", ?" /* action_type */ - ", ?" /* target_mailbox_id */ - ", ?" /* flag1 */ - ", ?)"); /* flag2 */ + "INSERT INTO mail_rule_tbl VALUES " + "(?" /* account id */ + ", ?" /* rule_id */ + ", ?" /* filter_name */ + ", ?" /* type */ + ", ?" /* value */ + ", ?" /* value2 */ + ", ?" /* action_type */ + ", ?" /* target_mailbox_id */ + ", ?" /* flag1 */ + ", ?)"); /* flag2 */ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc_2); if (rc_2 != SQLITE_OK) { @@ -7782,7 +7781,7 @@ INTERNAL_FUNC int emstorage_add_rule(char *multi_user_name, emstorage_rule_tbl_t EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); ret = true; @@ -7824,8 +7823,8 @@ INTERNAL_FUNC int emstorage_delete_rule(char *multi_user_name, int rule_id, int SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_rule_tbl WHERE rule_id = %d", rule_id); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } rc = sqlite3_changes(local_db_handle); @@ -7866,9 +7865,8 @@ INTERNAL_FUNC int emstorage_free_rule(emstorage_rule_tbl_t** rule_list, int coun emstorage_rule_tbl_t* p = *rule_list; int i = 0; - for (; i < count; i++) { + for (; i < count; i++) EM_SAFE_FREE(p[i].value); - } EM_SAFE_FREE(p); *rule_list = NULL; } @@ -7913,11 +7911,11 @@ INTERNAL_FUNC int emstorage_get_mail_count(char *multi_user_name, int account_id SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " WHERE mailbox_id = %d", mailbox_id); #ifdef USE_GET_RECORD_COUNT_API - char **result; + char **result; EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF2; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); *total = atoi(result[1]); sqlite3_free_table(result); @@ -7925,11 +7923,11 @@ INTERNAL_FUNC int emstorage_get_mail_count(char *multi_user_name, int account_id EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF2; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF2; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); _get_stmt_field_data_int(hStmt, total, 0); #endif /* USE_GET_RECORD_COUNT_API */ } @@ -7937,18 +7935,23 @@ INTERNAL_FUNC int emstorage_get_mail_count(char *multi_user_name, int account_id if (unseen) { SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_tbl WHERE flags_seen_field = 0"); /* fSEEN = 0x01 */ - if (account_id != ALL_ACCOUNT) - SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " AND account_id = %d", account_id); + if (account_id != ALL_ACCOUNT) { + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), + sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " AND account_id = %d", account_id); + } if (mailbox_id) { - SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " AND mailbox_id = %d", mailbox_id); + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), + sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " AND mailbox_id = %d", mailbox_id); } else - SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " AND mailbox_type NOT IN (3, 5)"); + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), + sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " AND mailbox_type NOT IN (3, 5)"); - char **result; + char **result; EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc); - EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + EM_DEBUG_DB_EXEC(SQLITE_OK != rc, + { error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); *unseen = atoi(result[1]); sqlite3_free_table(result); @@ -8012,8 +8015,8 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_id(char *multi_user_name, int mail EMSTORAGE_START_READ_TRANSACTION(transaction); switch (type) { - case RETRIEVE_SUMMARY: - SNPRINTF(sql_query_string, sizeof(sql_query_string), + case RETRIEVE_SUMMARY: + SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT account_id, " "mail_id, " "mailbox_id, " @@ -8029,49 +8032,49 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_id(char *multi_user_name, int mail "thread_id, " "thread_item_count " "FROM mail_tbl WHERE mail_id = %d", mail_id); - break; + break; - case RETRIEVE_FIELDS_FOR_DELETE: - SNPRINTF(sql_query_string, sizeof(sql_query_string), + case RETRIEVE_FIELDS_FOR_DELETE: + SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT account_id, " "mail_id, " "server_mail_status, " "server_mailbox_name, " "server_mail_id " "FROM mail_tbl WHERE mail_id = %d", mail_id); - break; + break; - case RETRIEVE_ACCOUNT: - SNPRINTF(sql_query_string, sizeof(sql_query_string), + case RETRIEVE_ACCOUNT: + SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT account_id " "FROM mail_tbl WHERE mail_id = %d", mail_id); - break; + break; - case RETRIEVE_FLAG: - SNPRINTF(sql_query_string, sizeof(sql_query_string), + case RETRIEVE_FLAG: + SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT account_id, " "flags_seen_field, " "thread_id, " "mailbox_id " "FROM mail_tbl WHERE mail_id = %d", mail_id); - break; + break; - default: - EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM : type [%d]", type); - error = EMAIL_ERROR_INVALID_PARAM; - goto FINISH_OFF; + default: + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM : type [%d]", type); + error = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; } EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); if (rc == SQLITE_DONE) { EM_DEBUG_LOG("no matched mail found..."); @@ -8079,41 +8082,41 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_id(char *multi_user_name, int mail goto FINISH_OFF; } switch (type) { - case RETRIEVE_SUMMARY: - _get_stmt_field_data_int(hStmt, &(p_data_tbl->account_id), col_index++); - _get_stmt_field_data_int(hStmt, &(p_data_tbl->mail_id), col_index++); - _get_stmt_field_data_int(hStmt, &(p_data_tbl->mailbox_id), col_index++); - _get_stmt_field_data_int(hStmt, &(p_data_tbl->server_mail_status), col_index++); - _get_stmt_field_data_string(hStmt, &(p_data_tbl->server_mailbox_name), 0, col_index++); - _get_stmt_field_data_string(hStmt, &(p_data_tbl->server_mail_id), 0, col_index++); - _get_stmt_field_data_string(hStmt, &(p_data_tbl->file_path_plain), 0, col_index++); - _get_stmt_field_data_string(hStmt, &(p_data_tbl->file_path_html), 0, col_index++); - _get_stmt_field_data_string(hStmt, &(p_data_tbl->file_path_mime_entity), 0, col_index++); - _get_stmt_field_data_char(hStmt, &(p_data_tbl->flags_seen_field), col_index++); - _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->save_status), col_index++); - _get_stmt_field_data_int(hStmt, &(p_data_tbl->lock_status), col_index++); - _get_stmt_field_data_int(hStmt, &(p_data_tbl->thread_id), col_index++); - _get_stmt_field_data_int(hStmt, &(p_data_tbl->thread_item_count), col_index++); - break; + case RETRIEVE_SUMMARY: + _get_stmt_field_data_int(hStmt, &(p_data_tbl->account_id), col_index++); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->mail_id), col_index++); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->mailbox_id), col_index++); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->server_mail_status), col_index++); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->server_mailbox_name), 0, col_index++); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->server_mail_id), 0, col_index++); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->file_path_plain), 0, col_index++); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->file_path_html), 0, col_index++); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->file_path_mime_entity), 0, col_index++); + _get_stmt_field_data_char(hStmt, &(p_data_tbl->flags_seen_field), col_index++); + _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->save_status), col_index++); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->lock_status), col_index++); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->thread_id), col_index++); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->thread_item_count), col_index++); + break; - case RETRIEVE_FIELDS_FOR_DELETE: - _get_stmt_field_data_int(hStmt, &(p_data_tbl->account_id), col_index++); - _get_stmt_field_data_int(hStmt, &(p_data_tbl->mail_id), col_index++); - _get_stmt_field_data_int(hStmt, &(p_data_tbl->server_mail_status), col_index++); - _get_stmt_field_data_string(hStmt, &(p_data_tbl->server_mailbox_name), 0, col_index++); - _get_stmt_field_data_string(hStmt, &(p_data_tbl->server_mail_id), 0, col_index++); - break; + case RETRIEVE_FIELDS_FOR_DELETE: + _get_stmt_field_data_int(hStmt, &(p_data_tbl->account_id), col_index++); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->mail_id), col_index++); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->server_mail_status), col_index++); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->server_mailbox_name), 0, col_index++); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->server_mail_id), 0, col_index++); + break; - case RETRIEVE_ACCOUNT: - _get_stmt_field_data_int(hStmt, &(p_data_tbl->account_id), col_index++); - break; + case RETRIEVE_ACCOUNT: + _get_stmt_field_data_int(hStmt, &(p_data_tbl->account_id), col_index++); + break; - case RETRIEVE_FLAG: - _get_stmt_field_data_int(hStmt, &(p_data_tbl->account_id), col_index++); - _get_stmt_field_data_char(hStmt, &(p_data_tbl->flags_seen_field), col_index++); - _get_stmt_field_data_int(hStmt, &(p_data_tbl->thread_id), col_index++); - _get_stmt_field_data_int(hStmt, &(p_data_tbl->mailbox_id), col_index++); - break; + case RETRIEVE_FLAG: + _get_stmt_field_data_int(hStmt, &(p_data_tbl->account_id), col_index++); + _get_stmt_field_data_char(hStmt, &(p_data_tbl->flags_seen_field), col_index++); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->thread_id), col_index++); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->mailbox_id), col_index++); + break; } ret = true; @@ -8183,8 +8186,8 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(char *multi_user_ EMSTORAGE_START_READ_TRANSACTION(transaction); switch (type) { - case RETRIEVE_SUMMARY: - cur_sql_query_string = SNPRINTF(sql_query_string, query_string_length, + case RETRIEVE_SUMMARY: + cur_sql_query_string = SNPRINTF(sql_query_string, query_string_length, "SELECT account_id, " "mail_id, " "mailbox_id, " @@ -8201,41 +8204,41 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(char *multi_user_ "thread_id, " "thread_item_count " "FROM mail_tbl WHERE mail_id in ("); - field_count = 15; - break; + field_count = 15; + break; - case RETRIEVE_FIELDS_FOR_DELETE: - cur_sql_query_string = SNPRINTF(sql_query_string, query_string_length, + case RETRIEVE_FIELDS_FOR_DELETE: + cur_sql_query_string = SNPRINTF(sql_query_string, query_string_length, "SELECT account_id, " "mail_id, " "server_mail_status, " "server_mailbox_name, " "server_mail_id " "FROM mail_tbl WHERE mail_id in ("); - field_count = 5; - break; + field_count = 5; + break; - case RETRIEVE_ACCOUNT: - cur_sql_query_string = SNPRINTF(sql_query_string, query_string_length, + case RETRIEVE_ACCOUNT: + cur_sql_query_string = SNPRINTF(sql_query_string, query_string_length, "SELECT account_id FROM mail_tbl WHERE mail_id in ("); - field_count = 1; - break; + field_count = 1; + break; - case RETRIEVE_FLAG: - cur_sql_query_string = SNPRINTF(sql_query_string, query_string_length, + case RETRIEVE_FLAG: + cur_sql_query_string = SNPRINTF(sql_query_string, query_string_length, "SELECT account_id, " "mail_id, " "mailbox_id, " "flags_seen_field, " "thread_id " "FROM mail_tbl WHERE mail_id in ("); - field_count = 5; - break; + field_count = 5; + break; - default: - EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM : type [%d]", type); - error = EMAIL_ERROR_INVALID_PARAM; - goto FINISH_OFF; + default: + EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM : type [%d]", type); + error = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; } for (i = 0; i < number_of_mails; i++) @@ -8262,43 +8265,43 @@ INTERNAL_FUNC int emstorage_get_mail_field_by_multiple_mail_id(char *multi_user_ for (i = 0; i < item_count; i++) { switch (type) { - case RETRIEVE_SUMMARY: - _get_table_field_data_int(result, &(p_data_tbl[i].account_id), col_index++); - _get_table_field_data_int(result, &(p_data_tbl[i].mail_id), col_index++); - _get_table_field_data_int(result, &(p_data_tbl[i].mailbox_id), col_index++); - _get_table_field_data_int(result, &(p_data_tbl[i].server_mail_status), col_index++); - _get_table_field_data_string(result, &(p_data_tbl[i].server_mailbox_name), 0, col_index++); - _get_table_field_data_string(result, &(p_data_tbl[i].server_mail_id), 0, col_index++); - _get_table_field_data_string(result, &(p_data_tbl[i].file_path_plain), 0, col_index++); - _get_table_field_data_string(result, &(p_data_tbl[i].file_path_html), 0, col_index++); - _get_table_field_data_string(result, &(p_data_tbl[i].file_path_mime_entity), 0, col_index++); - _get_table_field_data_string(result, &(p_data_tbl[i].subject), 0, col_index++); - _get_table_field_data_char(result, &(p_data_tbl[i].flags_seen_field), col_index++); - _get_table_field_data_int(result, (int*)&(p_data_tbl[i].save_status), col_index++); - _get_table_field_data_int(result, &(p_data_tbl[i].lock_status), col_index++); - _get_table_field_data_int(result, &(p_data_tbl[i].thread_id), col_index++); - _get_table_field_data_int(result, &(p_data_tbl[i].thread_item_count), col_index++); - break; + case RETRIEVE_SUMMARY: + _get_table_field_data_int(result, &(p_data_tbl[i].account_id), col_index++); + _get_table_field_data_int(result, &(p_data_tbl[i].mail_id), col_index++); + _get_table_field_data_int(result, &(p_data_tbl[i].mailbox_id), col_index++); + _get_table_field_data_int(result, &(p_data_tbl[i].server_mail_status), col_index++); + _get_table_field_data_string(result, &(p_data_tbl[i].server_mailbox_name), 0, col_index++); + _get_table_field_data_string(result, &(p_data_tbl[i].server_mail_id), 0, col_index++); + _get_table_field_data_string(result, &(p_data_tbl[i].file_path_plain), 0, col_index++); + _get_table_field_data_string(result, &(p_data_tbl[i].file_path_html), 0, col_index++); + _get_table_field_data_string(result, &(p_data_tbl[i].file_path_mime_entity), 0, col_index++); + _get_table_field_data_string(result, &(p_data_tbl[i].subject), 0, col_index++); + _get_table_field_data_char(result, &(p_data_tbl[i].flags_seen_field), col_index++); + _get_table_field_data_int(result, (int*)&(p_data_tbl[i].save_status), col_index++); + _get_table_field_data_int(result, &(p_data_tbl[i].lock_status), col_index++); + _get_table_field_data_int(result, &(p_data_tbl[i].thread_id), col_index++); + _get_table_field_data_int(result, &(p_data_tbl[i].thread_item_count), col_index++); + break; - case RETRIEVE_FIELDS_FOR_DELETE: - _get_table_field_data_int(result, &(p_data_tbl[i].account_id), col_index++); - _get_table_field_data_int(result, &(p_data_tbl[i].mail_id), col_index++); - _get_table_field_data_int(result, &(p_data_tbl[i].server_mail_status), col_index++); - _get_table_field_data_string(result, &(p_data_tbl[i].server_mailbox_name), 0, col_index++); - _get_table_field_data_string(result, &(p_data_tbl[i].server_mail_id), 0, col_index++); - break; + case RETRIEVE_FIELDS_FOR_DELETE: + _get_table_field_data_int(result, &(p_data_tbl[i].account_id), col_index++); + _get_table_field_data_int(result, &(p_data_tbl[i].mail_id), col_index++); + _get_table_field_data_int(result, &(p_data_tbl[i].server_mail_status), col_index++); + _get_table_field_data_string(result, &(p_data_tbl[i].server_mailbox_name), 0, col_index++); + _get_table_field_data_string(result, &(p_data_tbl[i].server_mail_id), 0, col_index++); + break; - case RETRIEVE_ACCOUNT: - _get_table_field_data_int(result, &(p_data_tbl[i].account_id), col_index++); - break; + case RETRIEVE_ACCOUNT: + _get_table_field_data_int(result, &(p_data_tbl[i].account_id), col_index++); + break; - case RETRIEVE_FLAG: - _get_table_field_data_int(result, &(p_data_tbl[i].account_id), col_index++); - _get_table_field_data_int(result, &(p_data_tbl[i].mail_id), col_index++); - _get_table_field_data_int(result, &(p_data_tbl[i].mailbox_id), col_index++); - _get_table_field_data_char(result, &(p_data_tbl[i].flags_seen_field), col_index++); - _get_table_field_data_int(result, &(p_data_tbl[i].thread_id), col_index++); - break; + case RETRIEVE_FLAG: + _get_table_field_data_int(result, &(p_data_tbl[i].account_id), col_index++); + _get_table_field_data_int(result, &(p_data_tbl[i].mail_id), col_index++); + _get_table_field_data_int(result, &(p_data_tbl[i].mailbox_id), col_index++); + _get_table_field_data_char(result, &(p_data_tbl[i].flags_seen_field), col_index++); + _get_table_field_data_int(result, &(p_data_tbl[i].thread_id), col_index++); + break; } } @@ -8405,19 +8408,19 @@ FINISH_OFF: #endif INTERNAL_FUNC int emstorage_mail_search_start(char *multi_user_name, - emstorage_search_filter_t *search, - int account_id, - int mailbox_id, - int sorting, - DB_STMT *search_handle, - int *searched, - int transaction, - int *err_code) + emstorage_search_filter_t *search, + int account_id, + int mailbox_id, + int sorting, + DB_STMT *search_handle, + int *searched, + int transaction, + int *err_code) { EM_DEBUG_FUNC_BEGIN("search[%p], account_id[%d], mailbox_id[%d], sorting[%d], " - "search_handle[%p], searched[%p], transaction[%d], err_code[%p]", - search, account_id, mailbox_id, sorting, search_handle, - searched, transaction, err_code); + "search_handle[%p], searched[%p], transaction[%d], err_code[%p]", + search, account_id, mailbox_id, sorting, search_handle, + searched, transaction, err_code); if (!search_handle || !searched) { if (err_code != NULL) @@ -8476,18 +8479,18 @@ INTERNAL_FUNC int emstorage_mail_search_start(char *multi_user_name, EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); char **result; EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &mail_count, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); sqlite3_free_table(result); @@ -8535,120 +8538,120 @@ INTERNAL_FUNC int emstorage_mail_search_result(DB_STMT search_handle, emstorage_ int error = EMAIL_ERROR_NONE; switch (type) { - case RETRIEVE_ID: - _get_stmt_field_data_int(hStmt, (int *)data, MAIL_ID_IDX_IN_MAIL_TBL); - break; + case RETRIEVE_ID: + _get_stmt_field_data_int(hStmt, (int *)data, MAIL_ID_IDX_IN_MAIL_TBL); + break; - case RETRIEVE_ENVELOPE: - case RETRIEVE_ALL: - if (!(p_data_tbl = em_malloc(sizeof(emstorage_mail_tbl_t)))) { - EM_DEBUG_EXCEPTION(" em_mallocfailed..."); - error = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } + case RETRIEVE_ENVELOPE: + case RETRIEVE_ALL: + if (!(p_data_tbl = em_malloc(sizeof(emstorage_mail_tbl_t)))) { + EM_DEBUG_EXCEPTION(" em_mallocfailed..."); + error = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } - _get_stmt_field_data_int(hStmt, &(p_data_tbl->mail_id), MAIL_ID_IDX_IN_MAIL_TBL); - _get_stmt_field_data_int(hStmt, &(p_data_tbl->account_id), ACCOUNT_ID_IDX_IN_MAIL_TBL); - _get_stmt_field_data_int(hStmt, &(p_data_tbl->mail_size), MAIL_SIZE_IDX_IN_MAIL_TBL); - _get_stmt_field_data_string(hStmt, &(p_data_tbl->server_mail_id), 0, SERVER_MAIL_ID_IDX_IN_MAIL_TBL); - _get_stmt_field_data_string(hStmt, &(p_data_tbl->full_address_from), 1, FULL_ADDRESS_FROM_IDX_IN_MAIL_TBL); - _get_stmt_field_data_string(hStmt, &(p_data_tbl->full_address_to), 1, FULL_ADDRESS_TO_IDX_IN_MAIL_TBL); - _get_stmt_field_data_string(hStmt, &(p_data_tbl->subject), 1, SUBJECT_IDX_IN_MAIL_TBL); - _get_stmt_field_data_int(hStmt, &(p_data_tbl->body_download_status), BODY_DOWNLOAD_STATUS_IDX_IN_MAIL_TBL); - _get_stmt_field_data_string(hStmt, &(p_data_tbl->file_path_plain), 0, FILE_PATH_PLAIN_IDX_IN_MAIL_TBL); - _get_stmt_field_data_string(hStmt, &(p_data_tbl->file_path_html), 0, FILE_PATH_HTML_IDX_IN_MAIL_TBL); - _get_stmt_field_data_string(hStmt, &(p_data_tbl->file_path_mime_entity), 0, FILE_PATH_HTML_IDX_IN_MAIL_TBL); - _get_stmt_field_data_time_t(hStmt, &(p_data_tbl->date_time), DATETIME_IDX_IN_MAIL_TBL); - _get_stmt_field_data_char(hStmt, &(p_data_tbl->flags_seen_field), FLAGS_SEEN_FIELD_IDX_IN_MAIL_TBL); - _get_stmt_field_data_int(hStmt, &(p_data_tbl->DRM_status), DRM_STATUS_IDX_IN_MAIL_TBL); - _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->priority), PRIORITY_IDX_IN_MAIL_TBL); - _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->save_status), SAVE_STATUS_IDX_IN_MAIL_TBL); - _get_stmt_field_data_int(hStmt, &(p_data_tbl->lock_status), LOCK_STATUS_IDX_IN_MAIL_TBL); - _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->report_status), REPORT_STATUS_IDX_IN_MAIL_TBL); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->mail_id), MAIL_ID_IDX_IN_MAIL_TBL); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->account_id), ACCOUNT_ID_IDX_IN_MAIL_TBL); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->mail_size), MAIL_SIZE_IDX_IN_MAIL_TBL); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->server_mail_id), 0, SERVER_MAIL_ID_IDX_IN_MAIL_TBL); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->full_address_from), 1, FULL_ADDRESS_FROM_IDX_IN_MAIL_TBL); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->full_address_to), 1, FULL_ADDRESS_TO_IDX_IN_MAIL_TBL); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->subject), 1, SUBJECT_IDX_IN_MAIL_TBL); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->body_download_status), BODY_DOWNLOAD_STATUS_IDX_IN_MAIL_TBL); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->file_path_plain), 0, FILE_PATH_PLAIN_IDX_IN_MAIL_TBL); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->file_path_html), 0, FILE_PATH_HTML_IDX_IN_MAIL_TBL); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->file_path_mime_entity), 0, FILE_PATH_HTML_IDX_IN_MAIL_TBL); + _get_stmt_field_data_time_t(hStmt, &(p_data_tbl->date_time), DATETIME_IDX_IN_MAIL_TBL); + _get_stmt_field_data_char(hStmt, &(p_data_tbl->flags_seen_field), FLAGS_SEEN_FIELD_IDX_IN_MAIL_TBL); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->DRM_status), DRM_STATUS_IDX_IN_MAIL_TBL); + _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->priority), PRIORITY_IDX_IN_MAIL_TBL); + _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->save_status), SAVE_STATUS_IDX_IN_MAIL_TBL); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->lock_status), LOCK_STATUS_IDX_IN_MAIL_TBL); + _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->report_status), REPORT_STATUS_IDX_IN_MAIL_TBL); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->preview_text), 1, PREVIEW_TEXT_IDX_IN_MAIL_TBL); + _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->meeting_request_status), MEETING_REQUEST_STATUS_IDX_IN_MAIL_TBL); + _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->message_class), MESSAGE_CLASS_IDX_IN_MAIL_TBL); + _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->digest_type), DIGEST_TYPE_IDX_IN_MAIL_TBL); + _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->smime_type), SMIME_TYPE_IDX_IN_MAIL_TBL); + _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->scheduled_sending_time), SCHEDULED_SENDING_TIME_IDX_IN_MAIL_TBL); + _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->remaining_resend_times), SCHEDULED_SENDING_TIME_IDX_IN_MAIL_TBL); + _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->tag_id), TAG_ID_IDX_IN_MAIL_TBL); + _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->eas_data_length), EAS_DATA_LENGTH_IDX_IN_MAIL_TBL); + _get_stmt_field_data_blob(hStmt, (void**)&(p_data_tbl->eas_data), EAS_DATA_IDX_IN_MAIL_TBL); + + if (type == RETRIEVE_ALL) { + _get_stmt_field_data_int(hStmt, &(p_data_tbl->server_mail_status), SERVER_MAIL_STATUS_IDX_IN_MAIL_TBL); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->server_mailbox_name), 0, SERVER_MAILBOX_NAME_IDX_IN_MAIL_TBL); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->full_address_reply), 1, FULL_ADDRESS_REPLY_IDX_IN_MAIL_TBL); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->full_address_cc), 1, FULL_ADDRESS_CC_IDX_IN_MAIL_TBL); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->full_address_bcc), 1, FULL_ADDRESS_BCC_IDX_IN_MAIL_TBL); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->full_address_return), 1, FULL_ADDRESS_RETURN_IDX_IN_MAIL_TBL); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->message_id), 0, MESSAGE_ID_IDX_IN_MAIL_TBL); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->email_address_sender), 1, EMAIL_ADDRESS_SENDER_IDX_IN_MAIL_TBL); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->email_address_recipient), 1, EMAIL_ADDRESS_RECIPIENT_IDX_IN_MAIL_TBL); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->attachment_count), ATTACHMENT_COUNT_IDX_IN_MAIL_TBL); _get_stmt_field_data_string(hStmt, &(p_data_tbl->preview_text), 1, PREVIEW_TEXT_IDX_IN_MAIL_TBL); - _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->meeting_request_status), MEETING_REQUEST_STATUS_IDX_IN_MAIL_TBL); - _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->message_class), MESSAGE_CLASS_IDX_IN_MAIL_TBL); - _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->digest_type), DIGEST_TYPE_IDX_IN_MAIL_TBL); - _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->smime_type), SMIME_TYPE_IDX_IN_MAIL_TBL); - _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->scheduled_sending_time), SCHEDULED_SENDING_TIME_IDX_IN_MAIL_TBL); - _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->remaining_resend_times), SCHEDULED_SENDING_TIME_IDX_IN_MAIL_TBL); - _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->tag_id), TAG_ID_IDX_IN_MAIL_TBL); - _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->eas_data_length), EAS_DATA_LENGTH_IDX_IN_MAIL_TBL); - _get_stmt_field_data_blob(hStmt, (void**)&(p_data_tbl->eas_data), EAS_DATA_IDX_IN_MAIL_TBL); - - if (type == RETRIEVE_ALL) { - _get_stmt_field_data_int(hStmt, &(p_data_tbl->server_mail_status), SERVER_MAIL_STATUS_IDX_IN_MAIL_TBL); - _get_stmt_field_data_string(hStmt, &(p_data_tbl->server_mailbox_name), 0, SERVER_MAILBOX_NAME_IDX_IN_MAIL_TBL); - _get_stmt_field_data_string(hStmt, &(p_data_tbl->full_address_reply), 1, FULL_ADDRESS_REPLY_IDX_IN_MAIL_TBL); - _get_stmt_field_data_string(hStmt, &(p_data_tbl->full_address_cc), 1, FULL_ADDRESS_CC_IDX_IN_MAIL_TBL); - _get_stmt_field_data_string(hStmt, &(p_data_tbl->full_address_bcc), 1, FULL_ADDRESS_BCC_IDX_IN_MAIL_TBL); - _get_stmt_field_data_string(hStmt, &(p_data_tbl->full_address_return), 1, FULL_ADDRESS_RETURN_IDX_IN_MAIL_TBL); - _get_stmt_field_data_string(hStmt, &(p_data_tbl->message_id), 0, MESSAGE_ID_IDX_IN_MAIL_TBL); - _get_stmt_field_data_string(hStmt, &(p_data_tbl->email_address_sender), 1, EMAIL_ADDRESS_SENDER_IDX_IN_MAIL_TBL); - _get_stmt_field_data_string(hStmt, &(p_data_tbl->email_address_recipient), 1, EMAIL_ADDRESS_RECIPIENT_IDX_IN_MAIL_TBL); - _get_stmt_field_data_int(hStmt, &(p_data_tbl->attachment_count), ATTACHMENT_COUNT_IDX_IN_MAIL_TBL); - _get_stmt_field_data_string(hStmt, &(p_data_tbl->preview_text), 1, PREVIEW_TEXT_IDX_IN_MAIL_TBL); - _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->replied_time), REPLIED_TIME_IDX_IN_MAIL_TBL); - _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->forwarded_time), FORWARDED_TIME_IDX_IN_MAIL_TBL); - _get_stmt_field_data_string(hStmt, &(p_data_tbl->default_charset), 0, DEFAULT_CHARSET_IDX_IN_MAIL_TBL); - } + _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->replied_time), REPLIED_TIME_IDX_IN_MAIL_TBL); + _get_stmt_field_data_int(hStmt, (int*)&(p_data_tbl->forwarded_time), FORWARDED_TIME_IDX_IN_MAIL_TBL); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->default_charset), 0, DEFAULT_CHARSET_IDX_IN_MAIL_TBL); + } - if (p_data_tbl->body_download_status) { - struct stat buf; + if (p_data_tbl->body_download_status) { + struct stat buf; - if (p_data_tbl->file_path_html) { - if (stat(p_data_tbl->file_path_html, &buf) == -1) - p_data_tbl->body_download_status = 0; - } else if (p_data_tbl->file_path_plain) { - if (stat(p_data_tbl->file_path_plain, &buf) == -1) - p_data_tbl->body_download_status = 0; - } else + if (p_data_tbl->file_path_html) { + if (stat(p_data_tbl->file_path_html, &buf) == -1) p_data_tbl->body_download_status = 0; - } + } else if (p_data_tbl->file_path_plain) { + if (stat(p_data_tbl->file_path_plain, &buf) == -1) + p_data_tbl->body_download_status = 0; + } else + p_data_tbl->body_download_status = 0; + } - *((emstorage_mail_tbl_t**)data) = p_data_tbl; - break; + *((emstorage_mail_tbl_t**)data) = p_data_tbl; + break; - case RETRIEVE_SUMMARY: - if (!(p_data_tbl = malloc(sizeof(emstorage_mail_tbl_t)))) { - EM_DEBUG_EXCEPTION(" malloc failed..."); + case RETRIEVE_SUMMARY: + if (!(p_data_tbl = malloc(sizeof(emstorage_mail_tbl_t)))) { + EM_DEBUG_EXCEPTION(" malloc failed..."); - error = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } + error = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } - memset(p_data_tbl, 0x00, sizeof(emstorage_mail_tbl_t)); + memset(p_data_tbl, 0x00, sizeof(emstorage_mail_tbl_t)); - _get_stmt_field_data_int(hStmt, &(p_data_tbl->mail_id), MAIL_ID_IDX_IN_MAIL_TBL); - _get_stmt_field_data_int(hStmt, &(p_data_tbl->account_id), ACCOUNT_ID_IDX_IN_MAIL_TBL); - _get_stmt_field_data_int(hStmt, &(p_data_tbl->server_mail_status), SERVER_MAIL_STATUS_IDX_IN_MAIL_TBL); - _get_stmt_field_data_string(hStmt, &(p_data_tbl->server_mailbox_name), 0, SERVER_MAILBOX_NAME_IDX_IN_MAIL_TBL); - _get_stmt_field_data_string(hStmt, &(p_data_tbl->server_mail_id), 0, SERVER_MAIL_ID_IDX_IN_MAIL_TBL); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->mail_id), MAIL_ID_IDX_IN_MAIL_TBL); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->account_id), ACCOUNT_ID_IDX_IN_MAIL_TBL); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->server_mail_status), SERVER_MAIL_STATUS_IDX_IN_MAIL_TBL); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->server_mailbox_name), 0, SERVER_MAILBOX_NAME_IDX_IN_MAIL_TBL); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->server_mail_id), 0, SERVER_MAIL_ID_IDX_IN_MAIL_TBL); - *((emstorage_mail_tbl_t**)data) = p_data_tbl; - break; + *((emstorage_mail_tbl_t**)data) = p_data_tbl; + break; - case RETRIEVE_ADDRESS: - if (!(p_data_tbl = malloc(sizeof(emstorage_mail_tbl_t)))) { - EM_DEBUG_EXCEPTION(" malloc failed..."); - error = EMAIL_ERROR_OUT_OF_MEMORY; - goto FINISH_OFF; - } + case RETRIEVE_ADDRESS: + if (!(p_data_tbl = malloc(sizeof(emstorage_mail_tbl_t)))) { + EM_DEBUG_EXCEPTION(" malloc failed..."); + error = EMAIL_ERROR_OUT_OF_MEMORY; + goto FINISH_OFF; + } - memset(p_data_tbl, 0x00, sizeof(emstorage_mail_tbl_t)); - _get_stmt_field_data_int(hStmt, &(p_data_tbl->mail_id), MAIL_ID_IDX_IN_MAIL_TBL); - _get_stmt_field_data_string(hStmt, &(p_data_tbl->email_address_sender), 1, EMAIL_ADDRESS_SENDER_IDX_IN_MAIL_TBL); - _get_stmt_field_data_string(hStmt, &(p_data_tbl->email_address_recipient), 1, EMAIL_ADDRESS_RECIPIENT_IDX_IN_MAIL_TBL); - *((emstorage_mail_tbl_t**)data) = p_data_tbl; - break; + memset(p_data_tbl, 0x00, sizeof(emstorage_mail_tbl_t)); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->mail_id), MAIL_ID_IDX_IN_MAIL_TBL); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->email_address_sender), 1, EMAIL_ADDRESS_SENDER_IDX_IN_MAIL_TBL); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->email_address_recipient), 1, EMAIL_ADDRESS_RECIPIENT_IDX_IN_MAIL_TBL); + *((emstorage_mail_tbl_t**)data) = p_data_tbl; + break; - default: - break; + default: + break; } EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); ret = true; @@ -8721,57 +8724,57 @@ INTERNAL_FUNC int emstorage_change_mail(char *multi_user_name, int mail_id, emst EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error); SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_tbl SET" - " mail_id = ?" - ", account_id = ?" - ", mailbox_id = ?" - ", mail_size = ?" - ", server_mail_status = ?" - ", server_mailbox_name = ?" - ", server_mail_id = ?" - ", reference_mail_id = ?" - ", full_address_from = ?" - ", full_address_reply = ?" /* 10 */ - ", full_address_to = ?" - ", full_address_cc = ?" - ", full_address_bcc = ?" - ", full_address_return = ?" - ", subject = ?" - ", body_download_status = ?" - ", file_path_plain = ?" - ", file_path_html = ?" - ", file_path_mime_entity = ?" - ", date_time = ?" - ", flags_seen_field = ?" - ", flags_deleted_field = ?" - ", flags_flagged_field = ?" - ", flags_answered_field = ?" - ", flags_recent_field = ?" - ", flags_draft_field = ?" - ", flags_forwarded_field = ?" - ", DRM_status = ?" - ", priority = ?" - ", save_status = ?" - ", lock_status = ?" - ", message_id = ?" - ", report_status = ?" - ", preview_text = ?" - ", smime_type = ?" - ", scheduled_sending_time = ?" - ", remaining_resend_times = ?" - ", tag_id = ?" - ", replied_time = ?" - ", forwarded_time = ?" - ", default_charset = ?" - ", eas_data_length = ?" - ", eas_data = ?" - " WHERE mail_id = %d AND account_id != 0 " - , mail_id); + "UPDATE mail_tbl SET" + " mail_id = ?" + ", account_id = ?" + ", mailbox_id = ?" + ", mail_size = ?" + ", server_mail_status = ?" + ", server_mailbox_name = ?" + ", server_mail_id = ?" + ", reference_mail_id = ?" + ", full_address_from = ?" + ", full_address_reply = ?" /* 10 */ + ", full_address_to = ?" + ", full_address_cc = ?" + ", full_address_bcc = ?" + ", full_address_return = ?" + ", subject = ?" + ", body_download_status = ?" + ", file_path_plain = ?" + ", file_path_html = ?" + ", file_path_mime_entity = ?" + ", date_time = ?" + ", flags_seen_field = ?" + ", flags_deleted_field = ?" + ", flags_flagged_field = ?" + ", flags_answered_field = ?" + ", flags_recent_field = ?" + ", flags_draft_field = ?" + ", flags_forwarded_field = ?" + ", DRM_status = ?" + ", priority = ?" + ", save_status = ?" + ", lock_status = ?" + ", message_id = ?" + ", report_status = ?" + ", preview_text = ?" + ", smime_type = ?" + ", scheduled_sending_time = ?" + ", remaining_resend_times = ?" + ", tag_id = ?" + ", replied_time = ?" + ", forwarded_time = ?" + ", default_charset = ?" + ", eas_data_length = ?" + ", eas_data = ?" + " WHERE mail_id = %d AND account_id != 0 " + , mail_id); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); _bind_stmt_field_data_int(hStmt, i++, mail->mail_id); _bind_stmt_field_data_int(hStmt, i++, mail->account_id); @@ -8819,7 +8822,7 @@ INTERNAL_FUNC int emstorage_change_mail(char *multi_user_name, int mail_id, emst EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); rc = sqlite3_changes(local_db_handle); if (rc == 0) { @@ -8855,10 +8858,10 @@ FINISH_OFF: } /** - * emstorage_clean_save_status(int save_status, int *err_code) - set the all mail status to the set value - * - * - **/ + * emstorage_clean_save_status(int save_status, int *err_code) - set the all mail status to the set value + * + * + **/ INTERNAL_FUNC int emstorage_clean_save_status(char *multi_user_name, int save_status, int *err_code) { EM_DEBUG_FUNC_BEGIN("save_status[%d], err_code[%p]", save_status, err_code); @@ -8877,8 +8880,8 @@ INTERNAL_FUNC int emstorage_clean_save_status(char *multi_user_name, int save_st EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } rc = sqlite3_changes(local_db_handle); @@ -8976,8 +8979,8 @@ INTERNAL_FUNC int emstorage_set_field_of_mails_with_integer_value(char *multi_us EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } if (sqlite3_changes(local_db_handle) == 0) @@ -9029,15 +9032,15 @@ INTERNAL_FUNC int emstorage_change_mail_text_field(char *multi_user_name, int ma EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error); SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_text_tbl SET" - " body_text = ?" - " WHERE mail_id = %d AND account_id != 0" - , mail_id); + "UPDATE mail_text_tbl SET" + " body_text = ?" + " WHERE mail_id = %d AND account_id != 0" + , mail_id); EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); i = 0; _bind_stmt_field_data_string(hStmt, i++, (char *)mail_text->body_text, 0, -1); @@ -9104,8 +9107,8 @@ INTERNAL_FUNC int emstorage_change_mail_field(char *multi_user_name, int mail_id EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error); switch (type) { - case APPEND_BODY: - SNPRINTF(sql_query_string, sizeof(sql_query_string), + case APPEND_BODY: + SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET" " body_download_status = ?" ", file_path_plain = ?" @@ -9129,361 +9132,361 @@ INTERNAL_FUNC int emstorage_change_mail_field(char *multi_user_name, int mail_id , mail_id); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); - EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); - i = 0; - - _bind_stmt_field_data_int(hStmt, i++, mail->body_download_status); - _bind_stmt_field_data_string(hStmt, i++, (char *)mail->file_path_plain, 0, TEXT_1_LEN_IN_MAIL_TBL); - _bind_stmt_field_data_string(hStmt, i++, (char *)mail->file_path_html, 0, TEXT_2_LEN_IN_MAIL_TBL); - _bind_stmt_field_data_string(hStmt, i++, (char *)mail->file_path_mime_entity, 0, MIME_ENTITY_LEN_IN_MAIL_TBL); - _bind_stmt_field_data_int(hStmt, i++, mail->flags_seen_field); - _bind_stmt_field_data_int(hStmt, i++, mail->flags_deleted_field); - _bind_stmt_field_data_int(hStmt, i++, mail->flags_flagged_field); - _bind_stmt_field_data_int(hStmt, i++, mail->flags_answered_field); - _bind_stmt_field_data_int(hStmt, i++, mail->flags_recent_field); - _bind_stmt_field_data_int(hStmt, i++, mail->flags_draft_field); - _bind_stmt_field_data_int(hStmt, i++, mail->flags_forwarded_field); - _bind_stmt_field_data_int(hStmt, i++, mail->DRM_status); - _bind_stmt_field_data_int(hStmt, i++, mail->attachment_count); - _bind_stmt_field_data_nstring(hStmt, i++, (char *)mail->preview_text, 0, PREVIEWBODY_LEN_IN_MAIL_TBL); - _bind_stmt_field_data_int(hStmt, i++, mail->meeting_request_status); - _bind_stmt_field_data_int(hStmt, i++, mail->message_class); - _bind_stmt_field_data_int(hStmt, i++, mail->digest_type); - _bind_stmt_field_data_int(hStmt, i++, mail->smime_type); - break; - - case UPDATE_MAILBOX: { - int err; - emstorage_mailbox_tbl_t *mailbox_tbl; - - if ((err = emstorage_get_mailbox_by_id(multi_user_name, mail->mailbox_id, &mailbox_tbl)) != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION(" emstorage_get_mailbox_by_id failed [%d]", err); - goto FINISH_OFF; - } - - SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_tbl SET" - " mailbox_id = '%d'" - ",mailbox_type = '%d'" - " WHERE mail_id = %d AND account_id != 0" - , mailbox_tbl->mailbox_id - , mailbox_tbl->mailbox_type - , mail_id); - move_flag = 1; - - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); - EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); - - i = 0; - _bind_stmt_field_data_string(hStmt, i++, (char *)mailbox_tbl->mailbox_name, 0, MAILBOX_NAME_LEN_IN_MAIL_BOX_TBL); - - emstorage_free_mailbox(&mailbox_tbl, 1, NULL); /*prevent 26251*/ - - } - break; - - case UPDATE_FLAG: - SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_tbl SET" - " flags_seen_field = %d" - ",flags_deleted_field = %d" - ",flags_flagged_field = %d" - ",flags_answered_field = %d" - ",flags_recent_field = %d" - ",flags_draft_field = %d" - ",flags_forwarded_field = %d" - " WHERE mail_id = %d AND account_id != 0" - , mail->flags_seen_field - , mail->flags_deleted_field - , mail->flags_flagged_field - , mail->flags_answered_field - , mail->flags_recent_field - , mail->flags_draft_field - , mail->flags_forwarded_field - , mail_id); - EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); - - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); - EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); - - break; - - case UPDATE_EXTRA_FLAG: - SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_tbl SET" - " priority = %d" - ", save_status = %d" - ", lock_status = %d" - ", report_status = %d" - ", DRM_status = %d" - " WHERE mail_id = %d AND account_id != 0" - , mail->priority - , mail->save_status - , mail->lock_status - , mail->report_status - , mail->DRM_status - , mail_id); - EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); - - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); - EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); - break; - - case UPDATE_STICKY_EXTRA_FLAG: - SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_tbl SET" - " lock_status = %d" - " WHERE mail_id = %d AND account_id != 0" - , mail->lock_status - , mail_id); - EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); - - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); - EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); - break; - - case UPDATE_MAIL: - SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_tbl SET" - " full_address_from = ?" - ", full_address_reply = ?" - ", full_address_to = ?" - ", full_address_cc = ?" - ", full_address_bcc = ?" - ", full_address_return = ?" - ", subject = ?" - ", file_path_plain = ?" - ", date_time = ?" - ", flags_seen_field = ?" - ", flags_deleted_field = ?" - ", flags_flagged_field = ?" - ", flags_answered_field = ?" - ", flags_recent_field = ?" - ", flags_draft_field = ?" - ", flags_forwarded_field = ?" - ", priority = ?" - ", save_status = ?" - ", lock_status = ?" - ", report_status = ?" - ", DRM_status = ?" - ", file_path_html = ?" - ", file_path_mime_entity = ?" - ", mail_size = ?" - ", preview_text = ?" - ", body_download_status = ?" - ", attachment_count = ?" - ", inline_content_count = ?" - ", meeting_request_status = ?" - ", message_class = ?" - ", digest_type = ?" - ", smime_type = ?" - ", scheduled_sending_time = ?" - ", remaining_resend_times = ?" - ", tag_id = ?" - ", replied_time = ?" - ", forwarded_time = ?" - ", default_charset = ?" - ", eas_data_length = ?" - ", eas_data = ?" - " WHERE mail_id = %d AND account_id != 0" - , mail_id); - - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); - EM_DEBUG_LOG_DEV(" before sqlite3_prepare hStmt = %p", hStmt); - EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); - i = 0; - _bind_stmt_field_data_string(hStmt, i++, (char*)mail->full_address_from, 1, FROM_LEN_IN_MAIL_TBL); - _bind_stmt_field_data_string(hStmt, i++, (char*)mail->full_address_reply, 1, REPLY_TO_LEN_IN_MAIL_TBL); - _bind_stmt_field_data_string(hStmt, i++, (char*)mail->full_address_to, 1, TO_LEN_IN_MAIL_TBL); - _bind_stmt_field_data_string(hStmt, i++, (char*)mail->full_address_cc, 1, CC_LEN_IN_MAIL_TBL); - _bind_stmt_field_data_string(hStmt, i++, (char*)mail->full_address_bcc, 1, BCC_LEN_IN_MAIL_TBL); - _bind_stmt_field_data_string(hStmt, i++, (char*)mail->full_address_return, 1, RETURN_PATH_LEN_IN_MAIL_TBL); - _bind_stmt_field_data_string(hStmt, i++, (char*)mail->subject, 1, SUBJECT_LEN_IN_MAIL_TBL); - _bind_stmt_field_data_string(hStmt, i++, (char*)mail->file_path_plain, 0, TEXT_1_LEN_IN_MAIL_TBL); - _bind_stmt_field_data_time_t(hStmt, i++, mail->date_time); - _bind_stmt_field_data_char(hStmt, i++, mail->flags_seen_field); - _bind_stmt_field_data_char(hStmt, i++, mail->flags_deleted_field); - _bind_stmt_field_data_char(hStmt, i++, mail->flags_flagged_field); - _bind_stmt_field_data_char(hStmt, i++, mail->flags_answered_field); - _bind_stmt_field_data_char(hStmt, i++, mail->flags_recent_field); - _bind_stmt_field_data_char(hStmt, i++, mail->flags_draft_field); - _bind_stmt_field_data_char(hStmt, i++, mail->flags_forwarded_field); - _bind_stmt_field_data_int(hStmt, i++, mail->priority); - _bind_stmt_field_data_int(hStmt, i++, mail->save_status); - _bind_stmt_field_data_int(hStmt, i++, mail->lock_status); - _bind_stmt_field_data_int(hStmt, i++, mail->report_status); - _bind_stmt_field_data_int(hStmt, i++, mail->DRM_status); - _bind_stmt_field_data_string(hStmt, i++, (char*)mail->file_path_html, 0, TEXT_2_LEN_IN_MAIL_TBL); - _bind_stmt_field_data_string(hStmt, i++, (char*)mail->file_path_mime_entity, 0, MIME_ENTITY_LEN_IN_MAIL_TBL); - _bind_stmt_field_data_int(hStmt, i++, mail->mail_size); - _bind_stmt_field_data_nstring(hStmt, i++, (char*)mail->preview_text, 1, PREVIEWBODY_LEN_IN_MAIL_TBL); - _bind_stmt_field_data_int(hStmt, i++, mail->body_download_status); - _bind_stmt_field_data_int(hStmt, i++, mail->attachment_count); - _bind_stmt_field_data_int(hStmt, i++, mail->inline_content_count); - _bind_stmt_field_data_int(hStmt, i++, mail->meeting_request_status); - _bind_stmt_field_data_int(hStmt, i++, mail->message_class); - _bind_stmt_field_data_int(hStmt, i++, mail->digest_type); - _bind_stmt_field_data_int(hStmt, i++, mail->smime_type); - _bind_stmt_field_data_int(hStmt, i++, mail->scheduled_sending_time); - _bind_stmt_field_data_int(hStmt, i++, mail->remaining_resend_times); - _bind_stmt_field_data_int(hStmt, i++, mail->tag_id); - _bind_stmt_field_data_int(hStmt, i++, mail->replied_time); - _bind_stmt_field_data_int(hStmt, i++, mail->forwarded_time); - _bind_stmt_field_data_string(hStmt, i++, (char*)mail->default_charset, 0, TEXT_2_LEN_IN_MAIL_TBL); - _bind_stmt_field_data_int(hStmt, i++, mail->eas_data_length); - _bind_stmt_field_data_blob(hStmt, i++, (void*)mail->eas_data, mail->eas_data_length); - break; - - case UPDATE_DATETIME: { - SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_tbl SET" - " date_time = '%ld'" - " WHERE mail_id = %d AND account_id != 0" - , mail->date_time - , mail_id); - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); - EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); - break; - } - - case UPDATE_FROM_CONTACT_INFO: - EM_DEBUG_LOG("NVARCHAR : emstorage_change_mail_field - mail change type is UPDATE_FROM_CONTACT_INFO"); - SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_tbl SET" - " email_address_sender = ?," - " WHERE mail_id = %d", - mail_id); - - hStmt = NULL; - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); - EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); - i = 0; - _bind_stmt_field_data_string(hStmt, i++, (char *)mail->email_address_sender, 1, FROM_EMAIL_ADDRESS_LEN_IN_MAIL_TBL); - break; - - case UPDATE_TO_CONTACT_INFO: - EM_DEBUG_LOG("NVARCHAR : emstorage_change_mail_field - mail change type is UPDATE_TO_CONTACT_INFO"); - SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_tbl SET" - " email_address_recipient = ?," - " WHERE mail_id = %d", - mail_id); - - hStmt = NULL; - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); - EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); + EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); - i = 0; - _bind_stmt_field_data_string(hStmt, i++, (char *)mail->email_address_recipient, 1, TO_EMAIL_ADDRESS_LEN_IN_MAIL_TBL); - break; + i = 0; + + _bind_stmt_field_data_int(hStmt, i++, mail->body_download_status); + _bind_stmt_field_data_string(hStmt, i++, (char *)mail->file_path_plain, 0, TEXT_1_LEN_IN_MAIL_TBL); + _bind_stmt_field_data_string(hStmt, i++, (char *)mail->file_path_html, 0, TEXT_2_LEN_IN_MAIL_TBL); + _bind_stmt_field_data_string(hStmt, i++, (char *)mail->file_path_mime_entity, 0, MIME_ENTITY_LEN_IN_MAIL_TBL); + _bind_stmt_field_data_int(hStmt, i++, mail->flags_seen_field); + _bind_stmt_field_data_int(hStmt, i++, mail->flags_deleted_field); + _bind_stmt_field_data_int(hStmt, i++, mail->flags_flagged_field); + _bind_stmt_field_data_int(hStmt, i++, mail->flags_answered_field); + _bind_stmt_field_data_int(hStmt, i++, mail->flags_recent_field); + _bind_stmt_field_data_int(hStmt, i++, mail->flags_draft_field); + _bind_stmt_field_data_int(hStmt, i++, mail->flags_forwarded_field); + _bind_stmt_field_data_int(hStmt, i++, mail->DRM_status); + _bind_stmt_field_data_int(hStmt, i++, mail->attachment_count); + _bind_stmt_field_data_nstring(hStmt, i++, (char *)mail->preview_text, 0, PREVIEWBODY_LEN_IN_MAIL_TBL); + _bind_stmt_field_data_int(hStmt, i++, mail->meeting_request_status); + _bind_stmt_field_data_int(hStmt, i++, mail->message_class); + _bind_stmt_field_data_int(hStmt, i++, mail->digest_type); + _bind_stmt_field_data_int(hStmt, i++, mail->smime_type); + break; - case UPDATE_ALL_CONTACT_INFO: - EM_DEBUG_LOG("emstorage_change_mail_field - mail change type is UPDATE_ALL_CONTACT_INFO"); - SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_tbl SET" - " email_address_sender = ?," - " email_address_recipient = ?," - " WHERE mail_id = %d", - mail_id); - - hStmt = NULL; - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); - EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); - i = 0; - _bind_stmt_field_data_string(hStmt, i++, (char *)mail->email_address_sender, 1, FROM_EMAIL_ADDRESS_LEN_IN_MAIL_TBL); - _bind_stmt_field_data_string(hStmt, i++, (char *)mail->email_address_recipient, 1, TO_EMAIL_ADDRESS_LEN_IN_MAIL_TBL); - break; + case UPDATE_MAILBOX: { + int err; + emstorage_mailbox_tbl_t *mailbox_tbl; + + if ((err = emstorage_get_mailbox_by_id(multi_user_name, mail->mailbox_id, &mailbox_tbl)) != EMAIL_ERROR_NONE) { + EM_DEBUG_EXCEPTION(" emstorage_get_mailbox_by_id failed [%d]", err); + goto FINISH_OFF; + } + + SNPRINTF(sql_query_string, sizeof(sql_query_string), + "UPDATE mail_tbl SET" + " mailbox_id = '%d'" + ",mailbox_type = '%d'" + " WHERE mail_id = %d AND account_id != 0" + , mailbox_tbl->mailbox_id + , mailbox_tbl->mailbox_type + , mail_id); + move_flag = 1; + + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); + EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + + i = 0; + _bind_stmt_field_data_string(hStmt, i++, (char *)mailbox_tbl->mailbox_name, 0, MAILBOX_NAME_LEN_IN_MAIL_BOX_TBL); + + emstorage_free_mailbox(&mailbox_tbl, 1, NULL); /*prevent 26251*/ + + } + break; + + case UPDATE_FLAG: + SNPRINTF(sql_query_string, sizeof(sql_query_string), + "UPDATE mail_tbl SET" + " flags_seen_field = %d" + ",flags_deleted_field = %d" + ",flags_flagged_field = %d" + ",flags_answered_field = %d" + ",flags_recent_field = %d" + ",flags_draft_field = %d" + ",flags_forwarded_field = %d" + " WHERE mail_id = %d AND account_id != 0" + , mail->flags_seen_field + , mail->flags_deleted_field + , mail->flags_flagged_field + , mail->flags_answered_field + , mail->flags_recent_field + , mail->flags_draft_field + , mail->flags_forwarded_field + , mail_id); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); + + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); + EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + + break; + + case UPDATE_EXTRA_FLAG: + SNPRINTF(sql_query_string, sizeof(sql_query_string), + "UPDATE mail_tbl SET" + " priority = %d" + ", save_status = %d" + ", lock_status = %d" + ", report_status = %d" + ", DRM_status = %d" + " WHERE mail_id = %d AND account_id != 0" + , mail->priority + , mail->save_status + , mail->lock_status + , mail->report_status + , mail->DRM_status + , mail_id); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); + + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); + EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + break; + + case UPDATE_STICKY_EXTRA_FLAG: + SNPRINTF(sql_query_string, sizeof(sql_query_string), + "UPDATE mail_tbl SET" + " lock_status = %d" + " WHERE mail_id = %d AND account_id != 0" + , mail->lock_status + , mail_id); + EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); + + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); + EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + break; + + case UPDATE_MAIL: + SNPRINTF(sql_query_string, sizeof(sql_query_string), + "UPDATE mail_tbl SET" + " full_address_from = ?" + ", full_address_reply = ?" + ", full_address_to = ?" + ", full_address_cc = ?" + ", full_address_bcc = ?" + ", full_address_return = ?" + ", subject = ?" + ", file_path_plain = ?" + ", date_time = ?" + ", flags_seen_field = ?" + ", flags_deleted_field = ?" + ", flags_flagged_field = ?" + ", flags_answered_field = ?" + ", flags_recent_field = ?" + ", flags_draft_field = ?" + ", flags_forwarded_field = ?" + ", priority = ?" + ", save_status = ?" + ", lock_status = ?" + ", report_status = ?" + ", DRM_status = ?" + ", file_path_html = ?" + ", file_path_mime_entity = ?" + ", mail_size = ?" + ", preview_text = ?" + ", body_download_status = ?" + ", attachment_count = ?" + ", inline_content_count = ?" + ", meeting_request_status = ?" + ", message_class = ?" + ", digest_type = ?" + ", smime_type = ?" + ", scheduled_sending_time = ?" + ", remaining_resend_times = ?" + ", tag_id = ?" + ", replied_time = ?" + ", forwarded_time = ?" + ", default_charset = ?" + ", eas_data_length = ?" + ", eas_data = ?" + " WHERE mail_id = %d AND account_id != 0" + , mail_id); + + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); + EM_DEBUG_LOG_DEV(" before sqlite3_prepare hStmt = %p", hStmt); + EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + i = 0; + _bind_stmt_field_data_string(hStmt, i++, (char*)mail->full_address_from, 1, FROM_LEN_IN_MAIL_TBL); + _bind_stmt_field_data_string(hStmt, i++, (char*)mail->full_address_reply, 1, REPLY_TO_LEN_IN_MAIL_TBL); + _bind_stmt_field_data_string(hStmt, i++, (char*)mail->full_address_to, 1, TO_LEN_IN_MAIL_TBL); + _bind_stmt_field_data_string(hStmt, i++, (char*)mail->full_address_cc, 1, CC_LEN_IN_MAIL_TBL); + _bind_stmt_field_data_string(hStmt, i++, (char*)mail->full_address_bcc, 1, BCC_LEN_IN_MAIL_TBL); + _bind_stmt_field_data_string(hStmt, i++, (char*)mail->full_address_return, 1, RETURN_PATH_LEN_IN_MAIL_TBL); + _bind_stmt_field_data_string(hStmt, i++, (char*)mail->subject, 1, SUBJECT_LEN_IN_MAIL_TBL); + _bind_stmt_field_data_string(hStmt, i++, (char*)mail->file_path_plain, 0, TEXT_1_LEN_IN_MAIL_TBL); + _bind_stmt_field_data_time_t(hStmt, i++, mail->date_time); + _bind_stmt_field_data_char(hStmt, i++, mail->flags_seen_field); + _bind_stmt_field_data_char(hStmt, i++, mail->flags_deleted_field); + _bind_stmt_field_data_char(hStmt, i++, mail->flags_flagged_field); + _bind_stmt_field_data_char(hStmt, i++, mail->flags_answered_field); + _bind_stmt_field_data_char(hStmt, i++, mail->flags_recent_field); + _bind_stmt_field_data_char(hStmt, i++, mail->flags_draft_field); + _bind_stmt_field_data_char(hStmt, i++, mail->flags_forwarded_field); + _bind_stmt_field_data_int(hStmt, i++, mail->priority); + _bind_stmt_field_data_int(hStmt, i++, mail->save_status); + _bind_stmt_field_data_int(hStmt, i++, mail->lock_status); + _bind_stmt_field_data_int(hStmt, i++, mail->report_status); + _bind_stmt_field_data_int(hStmt, i++, mail->DRM_status); + _bind_stmt_field_data_string(hStmt, i++, (char*)mail->file_path_html, 0, TEXT_2_LEN_IN_MAIL_TBL); + _bind_stmt_field_data_string(hStmt, i++, (char*)mail->file_path_mime_entity, 0, MIME_ENTITY_LEN_IN_MAIL_TBL); + _bind_stmt_field_data_int(hStmt, i++, mail->mail_size); + _bind_stmt_field_data_nstring(hStmt, i++, (char*)mail->preview_text, 1, PREVIEWBODY_LEN_IN_MAIL_TBL); + _bind_stmt_field_data_int(hStmt, i++, mail->body_download_status); + _bind_stmt_field_data_int(hStmt, i++, mail->attachment_count); + _bind_stmt_field_data_int(hStmt, i++, mail->inline_content_count); + _bind_stmt_field_data_int(hStmt, i++, mail->meeting_request_status); + _bind_stmt_field_data_int(hStmt, i++, mail->message_class); + _bind_stmt_field_data_int(hStmt, i++, mail->digest_type); + _bind_stmt_field_data_int(hStmt, i++, mail->smime_type); + _bind_stmt_field_data_int(hStmt, i++, mail->scheduled_sending_time); + _bind_stmt_field_data_int(hStmt, i++, mail->remaining_resend_times); + _bind_stmt_field_data_int(hStmt, i++, mail->tag_id); + _bind_stmt_field_data_int(hStmt, i++, mail->replied_time); + _bind_stmt_field_data_int(hStmt, i++, mail->forwarded_time); + _bind_stmt_field_data_string(hStmt, i++, (char*)mail->default_charset, 0, TEXT_2_LEN_IN_MAIL_TBL); + _bind_stmt_field_data_int(hStmt, i++, mail->eas_data_length); + _bind_stmt_field_data_blob(hStmt, i++, (void*)mail->eas_data, mail->eas_data_length); + break; + + case UPDATE_DATETIME: { + SNPRINTF(sql_query_string, sizeof(sql_query_string), + "UPDATE mail_tbl SET" + " date_time = '%ld'" + " WHERE mail_id = %d AND account_id != 0" + , mail->date_time + , mail_id); + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); + EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + break; + } + + case UPDATE_FROM_CONTACT_INFO: + EM_DEBUG_LOG("NVARCHAR : emstorage_change_mail_field - mail change type is UPDATE_FROM_CONTACT_INFO"); + SNPRINTF(sql_query_string, sizeof(sql_query_string), + "UPDATE mail_tbl SET" + " email_address_sender = ?," + " WHERE mail_id = %d", + mail_id); + + hStmt = NULL; + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); + EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + i = 0; + _bind_stmt_field_data_string(hStmt, i++, (char *)mail->email_address_sender, 1, FROM_EMAIL_ADDRESS_LEN_IN_MAIL_TBL); + break; + + case UPDATE_TO_CONTACT_INFO: + EM_DEBUG_LOG("NVARCHAR : emstorage_change_mail_field - mail change type is UPDATE_TO_CONTACT_INFO"); + SNPRINTF(sql_query_string, sizeof(sql_query_string), + "UPDATE mail_tbl SET" + " email_address_recipient = ?," + " WHERE mail_id = %d", + mail_id); + + hStmt = NULL; + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); + EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + i = 0; + _bind_stmt_field_data_string(hStmt, i++, (char *)mail->email_address_recipient, 1, TO_EMAIL_ADDRESS_LEN_IN_MAIL_TBL); + break; + + case UPDATE_ALL_CONTACT_INFO: + EM_DEBUG_LOG("emstorage_change_mail_field - mail change type is UPDATE_ALL_CONTACT_INFO"); + SNPRINTF(sql_query_string, sizeof(sql_query_string), + "UPDATE mail_tbl SET" + " email_address_sender = ?," + " email_address_recipient = ?," + " WHERE mail_id = %d", + mail_id); + + hStmt = NULL; + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); + EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + i = 0; + _bind_stmt_field_data_string(hStmt, i++, (char *)mail->email_address_sender, 1, FROM_EMAIL_ADDRESS_LEN_IN_MAIL_TBL); + _bind_stmt_field_data_string(hStmt, i++, (char *)mail->email_address_recipient, 1, TO_EMAIL_ADDRESS_LEN_IN_MAIL_TBL); + break; #ifdef __FEATURE_PARTIAL_BODY_DOWNLOAD__ - case UPDATE_PARTIAL_BODY_DOWNLOAD: - - SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_tbl SET" - " body_download_status = ?" - ", file_path_plain = ?" - ", file_path_html = ?" - ", file_path_mime_entity = ?" - ", attachment_count = ?" - ", inline_content_count = ?" - ", preview_text = ?" - ", digest_type = ?" - ", smime_type = ?" - " WHERE mail_id = %d" - , mail_id); - - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); - EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); - i = 0; - - _bind_stmt_field_data_int(hStmt, i++, mail->body_download_status); - _bind_stmt_field_data_string(hStmt, i++, (char *)mail->file_path_plain, 0, TEXT_1_LEN_IN_MAIL_TBL); - _bind_stmt_field_data_string(hStmt, i++, (char *)mail->file_path_html, 0, TEXT_2_LEN_IN_MAIL_TBL); - _bind_stmt_field_data_string(hStmt, i++, (char *)mail->file_path_mime_entity, 0, MIME_ENTITY_LEN_IN_MAIL_TBL); - _bind_stmt_field_data_int(hStmt, i++, mail->attachment_count); - _bind_stmt_field_data_int(hStmt, i++, mail->inline_content_count); - _bind_stmt_field_data_nstring(hStmt, i++, (char *)mail->preview_text, 0, PREVIEWBODY_LEN_IN_MAIL_TBL); - _bind_stmt_field_data_int(hStmt, i++, mail->digest_type); - _bind_stmt_field_data_int(hStmt, i++, mail->smime_type); - - break; + case UPDATE_PARTIAL_BODY_DOWNLOAD: + + SNPRINTF(sql_query_string, sizeof(sql_query_string), + "UPDATE mail_tbl SET" + " body_download_status = ?" + ", file_path_plain = ?" + ", file_path_html = ?" + ", file_path_mime_entity = ?" + ", attachment_count = ?" + ", inline_content_count = ?" + ", preview_text = ?" + ", digest_type = ?" + ", smime_type = ?" + " WHERE mail_id = %d" + , mail_id); + + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); + EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + i = 0; + + _bind_stmt_field_data_int(hStmt, i++, mail->body_download_status); + _bind_stmt_field_data_string(hStmt, i++, (char *)mail->file_path_plain, 0, TEXT_1_LEN_IN_MAIL_TBL); + _bind_stmt_field_data_string(hStmt, i++, (char *)mail->file_path_html, 0, TEXT_2_LEN_IN_MAIL_TBL); + _bind_stmt_field_data_string(hStmt, i++, (char *)mail->file_path_mime_entity, 0, MIME_ENTITY_LEN_IN_MAIL_TBL); + _bind_stmt_field_data_int(hStmt, i++, mail->attachment_count); + _bind_stmt_field_data_int(hStmt, i++, mail->inline_content_count); + _bind_stmt_field_data_nstring(hStmt, i++, (char *)mail->preview_text, 0, PREVIEWBODY_LEN_IN_MAIL_TBL); + _bind_stmt_field_data_int(hStmt, i++, mail->digest_type); + _bind_stmt_field_data_int(hStmt, i++, mail->smime_type); + + break; #endif - case UPDATE_FILE_PATH: - SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_tbl SET" - ", file_path_plain = ?" - ", file_path_html = ?" - ", file_path_mime_entity = ?" - " WHERE mail_id = %d" - , mail_id); - - - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); - EM_DEBUG_LOG(" before sqlite3_prepare hStmt = %p", hStmt); - EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); - i = 0; - _bind_stmt_field_data_string(hStmt, i++, (char*)mail->file_path_plain, 0, TEXT_1_LEN_IN_MAIL_TBL); - _bind_stmt_field_data_string(hStmt, i++, (char*)mail->file_path_html, 0, TEXT_2_LEN_IN_MAIL_TBL); - _bind_stmt_field_data_string(hStmt, i++, (char*)mail->file_path_mime_entity, 0, MIME_ENTITY_LEN_IN_MAIL_TBL); - break; + case UPDATE_FILE_PATH: + SNPRINTF(sql_query_string, sizeof(sql_query_string), + "UPDATE mail_tbl SET" + ", file_path_plain = ?" + ", file_path_html = ?" + ", file_path_mime_entity = ?" + " WHERE mail_id = %d" + , mail_id); + + + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); + EM_DEBUG_LOG(" before sqlite3_prepare hStmt = %p", hStmt); + EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + i = 0; + _bind_stmt_field_data_string(hStmt, i++, (char*)mail->file_path_plain, 0, TEXT_1_LEN_IN_MAIL_TBL); + _bind_stmt_field_data_string(hStmt, i++, (char*)mail->file_path_html, 0, TEXT_2_LEN_IN_MAIL_TBL); + _bind_stmt_field_data_string(hStmt, i++, (char*)mail->file_path_mime_entity, 0, MIME_ENTITY_LEN_IN_MAIL_TBL); + break; - default: - EM_DEBUG_LOG(" type[%d]", type); + default: + EM_DEBUG_LOG(" type[%d]", type); - error = EMAIL_ERROR_INVALID_PARAM; - goto FINISH_OFF; + error = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; } if (hStmt != NULL) { - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); rc = sqlite3_changes(local_db_handle); if (rc == 0) { EM_DEBUG_LOG(" no matched mail found..."); @@ -9554,15 +9557,15 @@ INTERNAL_FUNC int emstorage_increase_mail_id(char *multi_user_name, int *mail_id _timedlock_shm_mutex(mapped_for_generating_mail_id, 2); #endif /* __FEATURE_USE_SHARED_MUTEX_FOR_GENERATING_MAIL_ID__ */ - ret = vconf_get_int(VCONF_KEY_LATEST_MAIL_ID, &latest_mail_id); + ret = vconf_get_int(VCONF_KEY_LATEST_MAIL_ID, &latest_mail_id); if (ret < 0 || latest_mail_id == 0) { EM_DEBUG_LOG("vconf_get_int() failed [%d] or latest_mail_id is zero", ret); - local_db_handle = emstorage_get_db_connection(multi_user_name); + local_db_handle = emstorage_get_db_connection(multi_user_name); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); if (NULL == result[1]) rc = 1; else @@ -9621,8 +9624,8 @@ INTERNAL_FUNC int emstorage_add_mail(char *multi_user_name, emstorage_mail_tbl_t char **result; EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); -/* EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL[%s] sqlite3_get_table fail[%d] [%s]", sql, rc, sqlite3_errmsg(local_db_handle))); */ + /* EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, + ("SQL[%s] sqlite3_get_table fail[%d] [%s]", sql, rc, sqlite3_errmsg(local_db_handle))); */ if (rc != SQLITE_OK) { EM_DEBUG_EXCEPTION("SQL[%s] sqlite3_get_table fail[%d] [%s]", sql, rc, sqlite3_errmsg(local_db_handle)); error = EMAIL_ERROR_DB_FAILURE; @@ -9645,84 +9648,84 @@ INTERNAL_FUNC int emstorage_add_mail(char *multi_user_name, emstorage_mail_tbl_t mail_tbl_data->date_time = time(NULL); SNPRINTF(sql_query_string, sizeof(sql_query_string), - "INSERT INTO mail_tbl VALUES " - "(?" /* mail_id */ - ", ?" /* account_id */ - ", ?" /* mailbox_id */ - ", ?" /* mailbox_type */ - ", ?" /* subject */ - - ", ?" /* date_time */ - ", ?" /* server_mail_status */ - ", ?" /* server_mailbox_name */ - ", ?" /* server_mail_id */ - ", ?" /* message_id */ - - ", ?" /* reference_mail_id */ - ", ?" /* full_address_from */ - ", ?" /* full_address_reply */ - ", ?" /* full_address_to */ - ", ?" /* full_address_cc */ - - ", ?" /* full_address_bcc */ - ", ?" /* full_address_return */ - ", ?" /* email_address_sender */ - ", ?" /* email_address_recipient */ - ", ?" /* alias_sender */ - - ", ?" /* alias_recipient */ - ", ?" /* body_download_status */ - ", ?" /* file_path_plain */ - ", ?" /* file_path_html */ - ", ?" /* file_path_mime_entity */ - - ", ?" /* mail_size */ - ", ?" /* flags_seen_field */ - ", ?" /* flags_deleted_field */ - ", ?" /* flags_flagged_field */ - ", ?" /* flags_answered_field */ - - ", ?" /* flags_recent_field */ - ", ?" /* flags_draft_field */ - ", ?" /* flags_forwarded_field */ - ", ?" /* DRM_status */ - ", ?" /* priority */ - - ", ?" /* save_status */ - ", ?" /* lock_status */ - ", ?" /* report_status */ - ", ?" /* attachment_count */ - ", ?" /* inline_content_count */ - - ", ?" /* thread_id */ - ", ?" /* thread_item_count */ - ", ?" /* preview_text */ - ", ?" /* meeting_request_status */ - ", ?" /* message_class */ - - ", ?" /* digest_type */ - ", ?" /* smime_type */ - ", ?" /* scheduled_sending_time */ - ", ?" /* remaining_resend_times */ - ", ?" /* tag_id */ - - ", ?" /* replied_time */ - ", ?" /* forwarded_time */ - ", ?" /* default charset */ - ", ?" /* eas_data_length */ - ", ?" /* eas_data */ - ", ?" /* user_name */ - ")"); + "INSERT INTO mail_tbl VALUES " + "(?" /* mail_id */ + ", ?" /* account_id */ + ", ?" /* mailbox_id */ + ", ?" /* mailbox_type */ + ", ?" /* subject */ + + ", ?" /* date_time */ + ", ?" /* server_mail_status */ + ", ?" /* server_mailbox_name */ + ", ?" /* server_mail_id */ + ", ?" /* message_id */ + + ", ?" /* reference_mail_id */ + ", ?" /* full_address_from */ + ", ?" /* full_address_reply */ + ", ?" /* full_address_to */ + ", ?" /* full_address_cc */ + + ", ?" /* full_address_bcc */ + ", ?" /* full_address_return */ + ", ?" /* email_address_sender */ + ", ?" /* email_address_recipient */ + ", ?" /* alias_sender */ + + ", ?" /* alias_recipient */ + ", ?" /* body_download_status */ + ", ?" /* file_path_plain */ + ", ?" /* file_path_html */ + ", ?" /* file_path_mime_entity */ + + ", ?" /* mail_size */ + ", ?" /* flags_seen_field */ + ", ?" /* flags_deleted_field */ + ", ?" /* flags_flagged_field */ + ", ?" /* flags_answered_field */ + + ", ?" /* flags_recent_field */ + ", ?" /* flags_draft_field */ + ", ?" /* flags_forwarded_field */ + ", ?" /* DRM_status */ + ", ?" /* priority */ + + ", ?" /* save_status */ + ", ?" /* lock_status */ + ", ?" /* report_status */ + ", ?" /* attachment_count */ + ", ?" /* inline_content_count */ + + ", ?" /* thread_id */ + ", ?" /* thread_item_count */ + ", ?" /* preview_text */ + ", ?" /* meeting_request_status */ + ", ?" /* message_class */ + + ", ?" /* digest_type */ + ", ?" /* smime_type */ + ", ?" /* scheduled_sending_time */ + ", ?" /* remaining_resend_times */ + ", ?" /* tag_id */ + + ", ?" /* replied_time */ + ", ?" /* forwarded_time */ + ", ?" /* default charset */ + ", ?" /* eas_data_length */ + ", ?" /* eas_data */ + ", ?" /* user_name */ + ")"); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, - sql_query_string, - EM_SAFE_STRLEN(sql_query_string), - &hStmt, - NULL), - rc); + sql_query_string, + EM_SAFE_STRLEN(sql_query_string), + &hStmt, + NULL), + rc); if (rc != SQLITE_OK) { EM_DEBUG_EXCEPTION("sqlite3_prepare error [%d] [%s] SQL(%s) ", - rc, sql_query_string, sqlite3_errmsg(local_db_handle)); + rc, sql_query_string, sqlite3_errmsg(local_db_handle)); error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; } @@ -9856,11 +9859,10 @@ INTERNAL_FUNC int emstorage_move_multiple_mails_on_db(char *multi_user_name, int } if (result_mailbox->mailbox_name) { - if (strstr(result_mailbox->mailbox_name, "'")) { + if (strstr(result_mailbox->mailbox_name, "'")) target_mailbox_name = em_replace_all_string(result_mailbox->mailbox_name, "'", "''"); - } else { + else target_mailbox_name = strdup(result_mailbox->mailbox_name); - } } target_mailbox_type = result_mailbox->mailbox_type; @@ -9898,8 +9900,8 @@ INTERNAL_FUNC int emstorage_move_multiple_mails_on_db(char *multi_user_name, int error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } /* Updating a mail_attachment_tbl */ @@ -9908,8 +9910,8 @@ INTERNAL_FUNC int emstorage_move_multiple_mails_on_db(char *multi_user_name, int EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } /* Updating a mail_meeting_tbl */ @@ -9918,8 +9920,8 @@ INTERNAL_FUNC int emstorage_move_multiple_mails_on_db(char *multi_user_name, int EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } #ifdef __FEATURE_BODY_SEARCH__ @@ -9929,8 +9931,8 @@ INTERNAL_FUNC int emstorage_move_multiple_mails_on_db(char *multi_user_name, int EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } #endif @@ -9950,8 +9952,8 @@ INTERNAL_FUNC int emstorage_move_multiple_mails_on_db(char *multi_user_name, int EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } ret = true; @@ -9993,8 +9995,8 @@ INTERNAL_FUNC int emstorage_delete_mail(char *multi_user_name, int mail_id, int EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } ret = true; @@ -10048,8 +10050,8 @@ INTERNAL_FUNC int emstorage_delete_multiple_mails(char *multi_user_name, int mai EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } #ifdef __FEATURE_BODY_SEARCH__ @@ -10065,8 +10067,8 @@ INTERNAL_FUNC int emstorage_delete_multiple_mails(char *multi_user_name, int mai EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } #endif @@ -10106,8 +10108,8 @@ INTERNAL_FUNC int emstorage_delete_mail_by_account(char *multi_user_name, int ac EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } rc = sqlite3_changes(local_db_handle); @@ -10121,8 +10123,8 @@ INTERNAL_FUNC int emstorage_delete_mail_by_account(char *multi_user_name, int ac EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } rc = sqlite3_changes(local_db_handle); @@ -10137,8 +10139,8 @@ INTERNAL_FUNC int emstorage_delete_mail_by_account(char *multi_user_name, int ac EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } rc = sqlite3_changes(local_db_handle); @@ -10309,9 +10311,9 @@ INTERNAL_FUNC void emstorage_free_mail_text(emstorage_mail_text_tbl_t** mail_tex emstorage_mail_text_tbl_t *p = *mail_text_list; int i = 0; - for (; i < count; i++, p++) { + for (; i < count; i++, p++) EM_SAFE_FREE(p->body_text); - } + EM_SAFE_FREE(*mail_text_list); } @@ -10343,7 +10345,7 @@ INTERNAL_FUNC int emstorage_get_attachment_count(char *multi_user_name, int mail EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); *count = atoi(result[1]); sqlite3_free_table(result); @@ -10382,7 +10384,7 @@ INTERNAL_FUNC int emstorage_get_attachment_list(char *multi_user_name, int input SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT COUNT(*) FROM mail_attachment_tbl WHERE mail_id = %d", input_mail_id); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); *output_attachment_count = atoi(result[1]); sqlite3_free_table(result); @@ -10484,12 +10486,12 @@ INTERNAL_FUNC int emstorage_get_attachment(char *multi_user_name, int attachment EM_DEBUG_LOG_DEV(" before sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_prepare failed [%d] [%s]", rc, sql_query_string)); + ("sqlite3_prepare failed [%d] [%s]", rc, sql_query_string)); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step failed [%d] [%s]", rc, sql_query_string)); + ("sqlite3_step failed [%d] [%s]", rc, sql_query_string)); if (rc == SQLITE_DONE) { EM_DEBUG_LOG("no matched attachment found..."); @@ -10518,8 +10520,8 @@ INTERNAL_FUNC int emstorage_get_attachment(char *multi_user_name, int attachment _get_stmt_field_data_string(hStmt, &(p_data_tbl->attachment_mime_type), 0, ATTACHMENT_MIME_TYPE_IDX_IN_MAIL_ATTACHMENT_TBL); #ifdef __ATTACHMENT_OPTI__ - _get_stmt_field_data_int(hStmt, &(p_data_tbl->encoding), ENCODING_IDX_IN_MAIL_ATTACHMENT_TBL); - _get_stmt_field_data_string(hStmt, &(p_data_tbl->section), 0, SECTION_IDX_IN_MAIL_ATTACHMENT_TBL); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->encoding), ENCODING_IDX_IN_MAIL_ATTACHMENT_TBL); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->section), 0, SECTION_IDX_IN_MAIL_ATTACHMENT_TBL); #endif ret = true; @@ -10573,12 +10575,12 @@ INTERNAL_FUNC int emstorage_get_attachment_nth(char *multi_user_name, int mail_i EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); if (rc == SQLITE_DONE) { EM_DEBUG_EXCEPTION("no matched attachment found: mail_id[%d] nth[%d]", mail_id, nth); @@ -10610,11 +10612,11 @@ INTERNAL_FUNC int emstorage_get_attachment_nth(char *multi_user_name, int mail_i if ((p = (char *)sqlite3_column_text(hStmt, ATTACHMENT_MIME_TYPE_IDX_IN_MAIL_ATTACHMENT_TBL)) && (int)EM_SAFE_STRLEN(p)) p_data_tbl->attachment_mime_type = cpy_str(p); #ifdef __ATTACHMENT_OPTI__ - p_data_tbl->encoding = sqlite3_column_int(hStmt, ENCODING_IDX_IN_MAIL_ATTACHMENT_TBL); - if ((p = (char *)sqlite3_column_text(hStmt, SECTION_IDX_IN_MAIL_ATTACHMENT_TBL)) && (int)EM_SAFE_STRLEN(p)) - p_data_tbl->section = cpy_str(p); + p_data_tbl->encoding = sqlite3_column_int(hStmt, ENCODING_IDX_IN_MAIL_ATTACHMENT_TBL); + if ((p = (char *)sqlite3_column_text(hStmt, SECTION_IDX_IN_MAIL_ATTACHMENT_TBL)) && (int)EM_SAFE_STRLEN(p)) + p_data_tbl->section = cpy_str(p); #endif - ret = true; + ret = true; FINISH_OFF: if (ret == true) @@ -10664,12 +10666,12 @@ INTERNAL_FUNC int emstorage_get_attachment_by_attachment_path(char *multi_user_n EM_DEBUG_LOG_DEV("before sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_prepare failed [%d] [%s]", rc, sql_query_string)); + ("sqlite3_prepare failed [%d] [%s]", rc, sql_query_string)); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step failed [%d] [%s]", rc, sql_query_string)); + ("sqlite3_step failed [%d] [%s]", rc, sql_query_string)); if (rc == SQLITE_DONE) { EM_DEBUG_LOG("no matched attachment found..."); @@ -10698,8 +10700,8 @@ INTERNAL_FUNC int emstorage_get_attachment_by_attachment_path(char *multi_user_n _get_stmt_field_data_string(hStmt, &(p_data_tbl->attachment_mime_type), 0, ATTACHMENT_MIME_TYPE_IDX_IN_MAIL_ATTACHMENT_TBL); #ifdef __ATTACHMENT_OPTI__ - _get_stmt_field_data_int(hStmt, &(p_data_tbl->encoding), ENCODING_IDX_IN_MAIL_ATTACHMENT_TBL); - _get_stmt_field_data_string(hStmt, &(p_data_tbl->section), 0, SECTION_IDX_IN_MAIL_ATTACHMENT_TBL); + _get_stmt_field_data_int(hStmt, &(p_data_tbl->encoding), ENCODING_IDX_IN_MAIL_ATTACHMENT_TBL); + _get_stmt_field_data_string(hStmt, &(p_data_tbl->section), 0, SECTION_IDX_IN_MAIL_ATTACHMENT_TBL); #endif ret = true; @@ -10748,33 +10750,33 @@ INTERNAL_FUNC int emstorage_change_attachment_field(char *multi_user_name, int m EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error); switch (type) { - case UPDATE_MAILBOX: - EM_DEBUG_LOG("UPDATE_MAILBOX"); - if (!attachment->mailbox_id) { - EM_DEBUG_EXCEPTION(" attachment->mailbox_id[%d]", attachment->mailbox_id); - error = EMAIL_ERROR_INVALID_PARAM; - goto FINISH_OFF; - } - SNPRINTF(sql_query_string, sizeof(sql_query_string), + case UPDATE_MAILBOX: + EM_DEBUG_LOG("UPDATE_MAILBOX"); + if (!attachment->mailbox_id) { + EM_DEBUG_EXCEPTION(" attachment->mailbox_id[%d]", attachment->mailbox_id); + error = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } + SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_attachment_tbl SET mailbox_id = ? WHERE mail_id = %d", mail_id); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); - EM_DEBUG_LOG(" Before sqlite3_prepare hStmt = %p", hStmt); - EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); + EM_DEBUG_LOG(" Before sqlite3_prepare hStmt = %p", hStmt); + EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); - _bind_stmt_field_data_int(hStmt, i++, attachment->mailbox_id); - break; + _bind_stmt_field_data_int(hStmt, i++, attachment->mailbox_id); + break; - case UPDATE_SAVENAME: - EM_DEBUG_LOG("UPDATE_SAVENAME"); - if (!attachment->attachment_path) { - EM_DEBUG_EXCEPTION(" attachment->attachment_path[%p]", attachment->attachment_path); - error = EMAIL_ERROR_INVALID_PARAM; - goto FINISH_OFF; - } + case UPDATE_SAVENAME: + EM_DEBUG_LOG("UPDATE_SAVENAME"); + if (!attachment->attachment_path) { + EM_DEBUG_EXCEPTION(" attachment->attachment_path[%p]", attachment->attachment_path); + error = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } - SNPRINTF(sql_query_string, sizeof(sql_query_string), + SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_attachment_tbl SET" " attachment_size = ?" ", attachment_save_status = ?" @@ -10785,26 +10787,26 @@ INTERNAL_FUNC int emstorage_change_attachment_field(char *multi_user_name, int m , attachment->attachment_id); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); - EM_DEBUG_LOG(" Before sqlite3_prepare hStmt = %p", hStmt); - EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); + EM_DEBUG_LOG(" Before sqlite3_prepare hStmt = %p", hStmt); + EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); - _bind_stmt_field_data_int(hStmt, i++, attachment->attachment_size); - _bind_stmt_field_data_int(hStmt, i++, attachment->attachment_save_status); - _bind_stmt_field_data_string(hStmt, i++, (char *)attachment->attachment_path, 0, ATTACHMENT_PATH_LEN_IN_MAIL_ATTACHMENT_TBL); - break; + _bind_stmt_field_data_int(hStmt, i++, attachment->attachment_size); + _bind_stmt_field_data_int(hStmt, i++, attachment->attachment_save_status); + _bind_stmt_field_data_string(hStmt, i++, (char *)attachment->attachment_path, 0, ATTACHMENT_PATH_LEN_IN_MAIL_ATTACHMENT_TBL); + break; - default: - EM_DEBUG_LOG("type[%d]", type); - error = EMAIL_ERROR_INVALID_PARAM; - goto FINISH_OFF; + default: + EM_DEBUG_LOG("type[%d]", type); + error = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; } EM_DEBUG_LOG_SEC("query = [%s]", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); ret = true; FINISH_OFF: @@ -10846,17 +10848,15 @@ INTERNAL_FUNC int emstorage_rename_mailbox(char *multi_user_name, int input_mail return EMAIL_ERROR_INVALID_PARAM; } - if (strstr(input_new_mailbox_name, "'")) { + if (strstr(input_new_mailbox_name, "'")) replaced_mailbox_name = em_replace_all_string(input_new_mailbox_name, "'", "''"); - } else { + else replaced_mailbox_name = strdup(input_new_mailbox_name); - } - if (strstr(input_new_mailbox_alias, "'")) { + if (strstr(input_new_mailbox_alias, "'")) replaced_alias = em_replace_all_string(input_new_mailbox_alias, "'", "''"); - } else { + else replaced_alias = strdup(input_new_mailbox_alias); - } local_db_handle = emstorage_get_db_connection(multi_user_name); @@ -10867,11 +10867,11 @@ INTERNAL_FUNC int emstorage_rename_mailbox(char *multi_user_name, int input_mail return error; } - if (old_mailbox_data == NULL) { - EM_DEBUG_LOG("old_mailbox_data is NULL"); - error = EMAIL_ERROR_MAILBOX_NOT_FOUND; - goto FINISH_OFF; - } + if (old_mailbox_data == NULL) { + EM_DEBUG_LOG("old_mailbox_data is NULL"); + error = EMAIL_ERROR_MAILBOX_NOT_FOUND; + goto FINISH_OFF; + } account_id = old_mailbox_data->account_id; @@ -10879,17 +10879,17 @@ INTERNAL_FUNC int emstorage_rename_mailbox(char *multi_user_name, int input_mail if (input_eas_data && input_eas_data_length > 0) { SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_box_tbl SET" - " mailbox_name = ?" - ",alias = ?" - ",eas_data = ?" - ",eas_data_length = ?" - " WHERE mailbox_id = ?"); + "UPDATE mail_box_tbl SET" + " mailbox_name = ?" + ",alias = ?" + ",eas_data = ?" + ",eas_data_length = ?" + " WHERE mailbox_id = ?"); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); _bind_stmt_field_data_string(hStmt, field_idx++, input_new_mailbox_name, 0, ATTACHMENT_NAME_LEN_IN_MAIL_ATTACHMENT_TBL); _bind_stmt_field_data_string(hStmt, field_idx++, input_new_mailbox_alias, 0, ATTACHMENT_PATH_LEN_IN_MAIL_ATTACHMENT_TBL); @@ -10906,7 +10906,7 @@ INTERNAL_FUNC int emstorage_rename_mailbox(char *multi_user_name, int input_mail EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); _bind_stmt_field_data_string(hStmt, field_idx++ , input_new_mailbox_name, 0, ATTACHMENT_NAME_LEN_IN_MAIL_ATTACHMENT_TBL); _bind_stmt_field_data_string(hStmt, field_idx++ , input_new_mailbox_alias, 0, ATTACHMENT_PATH_LEN_IN_MAIL_ATTACHMENT_TBL); @@ -10916,9 +10916,9 @@ INTERNAL_FUNC int emstorage_rename_mailbox(char *multi_user_name, int input_mail EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMAIL_ERROR_MAIL_MEMORY_FULL; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); if (sqlite3_changes(local_db_handle) == 0) EM_DEBUG_LOG("no mail_meeting_tbl matched..."); @@ -10975,7 +10975,7 @@ INTERNAL_FUNC int emstorage_get_new_attachment_no(char *multi_user_name, int *at EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); if (NULL == result[1]) rc = 1; @@ -11023,7 +11023,7 @@ INTERNAL_FUNC int emstorage_add_attachment(char *multi_user_name, emstorage_atta EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); if (NULL == result[1]) rc = 1; else rc = atoi(result[1]) + 1; @@ -11032,30 +11032,30 @@ INTERNAL_FUNC int emstorage_add_attachment(char *multi_user_name, emstorage_atta attachment_tbl->attachment_id = rc; SNPRINTF(sql_query_string, sizeof(sql_query_string), - "INSERT INTO mail_attachment_tbl VALUES " - "(?" /* attachment_id */ - ", ?" /* attachment_name */ - ", ?" /* attachment_path */ - ", ?" /* content_id */ - ", ?" /* attachment_size */ - ", ?" /* mail_id */ - ", ?" /* account_id */ - ", ?" /* mailbox_id */ - ", ?" /* attachment_save_status */ - ", ?" /* attachment_drm_type */ - ", ?" /* attachment_drm_method */ - ", ?" /* attachment_inline_content_status */ - ", ?" /* attachment_mime_type */ + "INSERT INTO mail_attachment_tbl VALUES " + "(?" /* attachment_id */ + ", ?" /* attachment_name */ + ", ?" /* attachment_path */ + ", ?" /* content_id */ + ", ?" /* attachment_size */ + ", ?" /* mail_id */ + ", ?" /* account_id */ + ", ?" /* mailbox_id */ + ", ?" /* attachment_save_status */ + ", ?" /* attachment_drm_type */ + ", ?" /* attachment_drm_method */ + ", ?" /* attachment_inline_content_status */ + ", ?" /* attachment_mime_type */ #ifdef __ATTACHMENT_OPTI__ - ", ?" - ", ?" + ", ?" + ", ?" #endif - ")"); + ")"); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); _bind_stmt_field_data_int(hStmt, ATTACHMENT_ID_IDX_IN_MAIL_ATTACHMENT_TBL, attachment_tbl->attachment_id); _bind_stmt_field_data_string(hStmt, ATTACHMENT_NAME_IDX_IN_MAIL_ATTACHMENT_TBL, (char*)attachment_tbl->attachment_name, 0, ATTACHMENT_NAME_LEN_IN_MAIL_ATTACHMENT_TBL); @@ -11078,9 +11078,9 @@ INTERNAL_FUNC int emstorage_add_attachment(char *multi_user_name, emstorage_atta EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMAIL_ERROR_MAIL_MEMORY_FULL; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); rc = sqlite3_changes(local_db_handle); if (rc == 0) { @@ -11103,7 +11103,7 @@ FINISH_OFF: } if (err_code != NULL) - *err_code = error; + *err_code = error; EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; @@ -11116,7 +11116,7 @@ INTERNAL_FUNC int emstorage_update_attachment(char *multi_user_name, emstorage_a int rc, ret = false, field_idx = 0; int error = EMAIL_ERROR_NONE; DB_STMT hStmt = NULL; - char sql_query_string[QUERY_SIZE] = {0, }; + char sql_query_string[QUERY_SIZE] = {0, }; if (!attachment_tbl) { EM_DEBUG_EXCEPTION(" attachment_tbl[%p] ", attachment_tbl); @@ -11130,26 +11130,26 @@ INTERNAL_FUNC int emstorage_update_attachment(char *multi_user_name, emstorage_a EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error); SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_attachment_tbl SET " - " attachment_name = ?" - ", attachment_path = ?" - ", content_id = ?" - ", attachment_size = ?" - ", mail_id = ?" - ", account_id = ?" - ", mailbox_id = ?" - ", attachment_save_status = ?" - ", attachment_drm_type = ?" - ", attachment_drm_method = ?" - ", attachment_inline_content_status = ? " - ", attachment_mime_type = ? " - " WHERE attachment_id = ?;"); + "UPDATE mail_attachment_tbl SET " + " attachment_name = ?" + ", attachment_path = ?" + ", content_id = ?" + ", attachment_size = ?" + ", mail_id = ?" + ", account_id = ?" + ", mailbox_id = ?" + ", attachment_save_status = ?" + ", attachment_drm_type = ?" + ", attachment_drm_method = ?" + ", attachment_inline_content_status = ? " + ", attachment_mime_type = ? " + " WHERE attachment_id = ?;"); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); _bind_stmt_field_data_string(hStmt, field_idx++ , (char*)attachment_tbl->attachment_name, 0, ATTACHMENT_NAME_LEN_IN_MAIL_ATTACHMENT_TBL); _bind_stmt_field_data_string(hStmt, field_idx++ , (char*)attachment_tbl->attachment_path, 0, ATTACHMENT_PATH_LEN_IN_MAIL_ATTACHMENT_TBL); @@ -11168,9 +11168,9 @@ INTERNAL_FUNC int emstorage_update_attachment(char *multi_user_name, emstorage_a EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMAIL_ERROR_MAIL_MEMORY_FULL; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); rc = sqlite3_changes(local_db_handle); if (rc == 0) { @@ -11192,7 +11192,7 @@ FINISH_OFF: } if (err_code != NULL) - *err_code = error; + *err_code = error; EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; @@ -11220,8 +11220,8 @@ INTERNAL_FUNC int emstorage_delete_attachment_on_db(char *multi_user_name, int a error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } ret = true; @@ -11258,8 +11258,8 @@ INTERNAL_FUNC int emstorage_delete_all_attachments_of_mail(char *multi_user_name SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_attachment_tbl WHERE mail_id = %d", mail_id); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } ret = true; @@ -11291,12 +11291,11 @@ INTERNAL_FUNC int emstorage_delete_attachment_all_on_db(char *multi_user_name, i if (account_id != ALL_ACCOUNT) /* '0' means all account */ SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " WHERE account_id = %d", account_id); - if (mailbox) /* NULL means all mailbox_name */ { - if (strstr(mailbox, "'")) { + if (mailbox) /* NULL means all mailbox_name */ { + if (strstr(mailbox, "'")) replaced_mailbox = em_replace_all_string(mailbox, "'", "''"); - } else { + else replaced_mailbox = strdup(mailbox); - } SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), " %s mailbox_name = '%s'", account_id != ALL_ACCOUNT ? "AND" : "WHERE", replaced_mailbox); EM_SAFE_FREE(replaced_mailbox); /*prevent 49434*/ @@ -11304,8 +11303,8 @@ INTERNAL_FUNC int emstorage_delete_attachment_all_on_db(char *multi_user_name, i error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } ret = true; @@ -11368,7 +11367,7 @@ INTERNAL_FUNC int emstorage_begin_transaction(char *multi_user_name, void *d1, v int rc; EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "BEGIN immediate;", NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {ret = false; }, - ("SQL(BEGIN) exec error:%d -%s", rc, sqlite3_errmsg(local_db_handle))); + ("SQL(BEGIN) exec error:%d -%s", rc, sqlite3_errmsg(local_db_handle))); if (ret == false) { if (err_code != NULL) *err_code = EMAIL_ERROR_DB_FAILURE; @@ -11408,7 +11407,7 @@ INTERNAL_FUNC int emstorage_rollback_transaction(char *multi_user_name, void *d1 EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "ROLLBACK;", NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {ret = false; }, - ("SQL(ROLLBACK) exec error:%d -%s", rc, sqlite3_errmsg(local_db_handle))); + ("SQL(ROLLBACK) exec error:%d -%s", rc, sqlite3_errmsg(local_db_handle))); if (ret == false && err_code != NULL) *err_code = EMAIL_ERROR_DB_FAILURE; @@ -11491,8 +11490,8 @@ INTERNAL_FUNC int emstorage_clear_mail_data(char *multi_user_name, int transacti SNPRINTF(sql_query_string, sizeof(sql_query_string), "DROP index %s", indexes->object_name); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } } indexes++; @@ -11503,8 +11502,8 @@ INTERNAL_FUNC int emstorage_clear_mail_data(char *multi_user_name, int transacti SNPRINTF(sql_query_string, sizeof(sql_query_string), "DROP table %s", tables->object_name); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } } @@ -11547,7 +11546,7 @@ INTERNAL_FUNC char *emstorage_make_directory_path_from_file_path(char *file_name } INTERNAL_FUNC int emstorage_get_save_name(char *multi_user_name, int account_id, int mail_id, int atch_id, - char *fname, char *move_buf, char *path_buf, int maxlen, int *err_code) + char *fname, char *move_buf, char *path_buf, int maxlen, int *err_code) { EM_DEBUG_FUNC_BEGIN_SEC("account_id[%d], mail_id[%d], atch_id[%d], fname[%s], move_buf[%p], path_buf[%p], err_code[%p]", account_id, mail_id, atch_id, fname, move_buf, path_buf, err_code); EM_PROFILE_BEGIN(profile_emstorage_get_save_name); @@ -11577,9 +11576,8 @@ INTERNAL_FUNC int emstorage_get_save_name(char *multi_user_name, int account_id, if (fname) { temp_file = EM_SAFE_STRDUP(fname); - if (temp_file && strstr(temp_file, "/")) { + if (temp_file && strstr(temp_file, "/")) dir_name = emstorage_make_directory_path_from_file_path(temp_file); - } } if (dir_name) { @@ -11608,9 +11606,8 @@ INTERNAL_FUNC int emstorage_get_save_name(char *multi_user_name, int account_id, goto FINISH_OFF; } - if (remain_len > MAX_FILENAME) { + if (remain_len > MAX_FILENAME) remain_len = MAX_FILENAME; - } modified_name = em_shrink_filename(modified_fname, remain_len); @@ -11619,7 +11616,8 @@ INTERNAL_FUNC int emstorage_get_save_name(char *multi_user_name, int account_id, goto FINISH_OFF; } - snprintf(path_buf+EM_SAFE_STRLEN(path_buf), 512 - EM_SAFE_STRLEN(path_buf),"%s%s", DIR_SEPERATOR, modified_name); + snprintf(path_buf+EM_SAFE_STRLEN(path_buf), 512 - EM_SAFE_STRLEN(path_buf), + "%s%s", DIR_SEPERATOR, modified_name); EM_DEBUG_LOG(">>>>> Modified fname [%s]", modified_name); EM_SAFE_FREE(modified_name); } else { @@ -11632,29 +11630,31 @@ INTERNAL_FUNC int emstorage_get_save_name(char *multi_user_name, int account_id, goto FINISH_OFF; } - snprintf(path_buf+EM_SAFE_STRLEN(path_buf), 512 - EM_SAFE_STRLEN(path_buf),"%s%s", DIR_SEPERATOR, modified_name); + snprintf(path_buf+EM_SAFE_STRLEN(path_buf), 512 - EM_SAFE_STRLEN(path_buf), + "%s%s", DIR_SEPERATOR, modified_name); EM_DEBUG_LOG(">>>>> Modified fname [%s]", modified_name); EM_SAFE_FREE(modified_name); } else { - snprintf(path_buf+EM_SAFE_STRLEN(path_buf), 512 - EM_SAFE_STRLEN(path_buf),"%s%s", DIR_SEPERATOR, modified_fname); + snprintf(path_buf+EM_SAFE_STRLEN(path_buf), 512 - EM_SAFE_STRLEN(path_buf), + "%s%s", DIR_SEPERATOR, modified_fname); } } } EM_DEBUG_LOG_SEC(">>>>> path_buf [%s]", path_buf); - if (EM_SAFE_STRLEN(multi_user_name) > 0) { + if (EM_SAFE_STRLEN(multi_user_name) > 0) { error = emcore_get_container_path(multi_user_name, &prefix_path); if (error != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_get_container_path failed : [%d]", error); goto FINISH_OFF; } - snprintf(move_buf, 512, "%s/%s", prefix_path, path_buf); - EM_DEBUG_LOG_SEC("move_buf : [%s]", move_buf); - } else { - snprintf(move_buf, 512, "%s", path_buf); - EM_DEBUG_LOG_SEC("move_buf : [%s]", move_buf); - } + snprintf(move_buf, 512, "%s/%s", prefix_path, path_buf); + EM_DEBUG_LOG_SEC("move_buf : [%s]", move_buf); + } else { + snprintf(move_buf, 512, "%s", path_buf); + EM_DEBUG_LOG_SEC("move_buf : [%s]", move_buf); + } ret = true; @@ -11673,34 +11673,34 @@ FINISH_OFF: } /* -INTERNAL_FUNC int emstorage_get_dele_name(char *multi_user_name, int account_id, int mail_id, int atch_id, char *fname, char *name_buf, int *err_code) -{ - EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], atch_id[%d], fname[%p], name_buf[%p], err_code[%p]", account_id, mail_id, atch_id, fname, name_buf, err_code); + INTERNAL_FUNC int emstorage_get_dele_name(char *multi_user_name, int account_id, int mail_id, int atch_id, char *fname, char *name_buf, int *err_code) + { + EM_DEBUG_FUNC_BEGIN("account_id[%d], mail_id[%d], atch_id[%d], fname[%p], name_buf[%p], err_code[%p]", account_id, mail_id, atch_id, fname, name_buf, err_code); - if (!name_buf || account_id < FIRST_ACCOUNT_ID) { - EM_DEBUG_EXCEPTION(" account_id[%d], mail_id[%d], atch_id[%d], fname[%p], name_buf[%p]", account_id, mail_id, atch_id, fname, name_buf); - if (err_code != NULL) - *err_code = EMAIL_ERROR_INVALID_PARAM; - return false; - } + if (!name_buf || account_id < FIRST_ACCOUNT_ID) { + EM_DEBUG_EXCEPTION(" account_id[%d], mail_id[%d], atch_id[%d], fname[%p], name_buf[%p]", account_id, mail_id, atch_id, fname, name_buf); + if (err_code != NULL) + *err_code = EMAIL_ERROR_INVALID_PARAM; + return false; + } - sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%s%d", MAILHOME, DIR_SEPERATOR, account_id); + sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%s%d", MAILHOME, DIR_SEPERATOR, account_id); - if (mail_id > 0) - sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%d", DIR_SEPERATOR, mail_id); - else - goto FINISH_OFF; + if (mail_id > 0) + sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%d", DIR_SEPERATOR, mail_id); + else + goto FINISH_OFF; - if (atch_id > 0) - sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%d", DIR_SEPERATOR, atch_id); - else - goto FINISH_OFF; + if (atch_id > 0) + sprintf(name_buf+EM_SAFE_STRLEN(name_buf), "%s%d", DIR_SEPERATOR, atch_id); + else + goto FINISH_OFF; FINISH_OFF: - sprintf(name_buf+EM_SAFE_STRLEN(name_buf), ".DELE"); +sprintf(name_buf+EM_SAFE_STRLEN(name_buf), ".DELE"); - EM_DEBUG_FUNC_END(); - return true; +EM_DEBUG_FUNC_END(); +return true; } */ @@ -11717,7 +11717,7 @@ INTERNAL_FUNC int emstorage_create_dir(char *multi_user_name, int account_id, in memset(buf, 0x00, sizeof(buf)); - if (EM_SAFE_STRLEN(multi_user_name) > 0) { + if (EM_SAFE_STRLEN(multi_user_name) > 0) { error = emcore_get_container_path(multi_user_name, &prefix_path); if (error != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("emcore_get_container_path failed : [%d]", error); @@ -11729,10 +11729,10 @@ INTERNAL_FUNC int emstorage_create_dir(char *multi_user_name, int account_id, in if (account_id >= FIRST_ACCOUNT_ID) { SNPRINTF(buf, sizeof(buf), "%s%s%s%s%d", prefix_path, - DIR_SEPERATOR, - MAIL_HOME, - DIR_SEPERATOR, - account_id); + DIR_SEPERATOR, + MAIL_HOME, + DIR_SEPERATOR, + account_id); if (stat(buf, &sbuf) == 0) { if ((sbuf.st_mode & S_IFMT) != S_IFDIR) { @@ -11750,9 +11750,8 @@ INTERNAL_FUNC int emstorage_create_dir(char *multi_user_name, int account_id, in goto FINISH_OFF; } - if (account_id == EML_FOLDER) { + if (account_id == EML_FOLDER) chmod(buf, 0777); - } } } @@ -11789,9 +11788,8 @@ INTERNAL_FUNC int emstorage_create_dir(char *multi_user_name, int account_id, in goto FINISH_OFF; } - if (account_id == EML_FOLDER) { + if (account_id == EML_FOLDER) chmod(buf, 0777); - } } } @@ -11819,9 +11817,8 @@ INTERNAL_FUNC int emstorage_create_dir(char *multi_user_name, int account_id, in goto FINISH_OFF; } - if (account_id == EML_FOLDER) { + if (account_id == EML_FOLDER) chmod(buf, 0777); - } } } @@ -11869,14 +11866,14 @@ INTERNAL_FUNC int emstorage_copy_file(char *src_file, char *dst_file, int sync_s error = em_open(src_file, O_RDONLY, 0, &fp_src); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION(">>>> Source Fail em_open %s Failed: %d", src_file, error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION(">>>> Source Fail em_open %s Failed: %d", src_file, error); + goto FINISH_OFF; } error = em_open(dst_file, O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, &fp_dst); /*prevent 24474*/ if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION(">>>> Destination Fail em_open %s: %d", dst_file, error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION(">>>> Destination Fail em_open %s: %d", dst_file, error); + goto FINISH_OFF; } memset(buf, 0x00, FILE_MAX_BUFFER_SIZE); @@ -12039,9 +12036,9 @@ INTERNAL_FUNC int emstorage_add_content_type(char *file_path, char *char_set, in EM_DEBUG_LOG(">>>> Nread Value [ %d ] ", nread); /** - * 1.Add check for whether content type is there. - * 2. If not based on the character set, Append it in File - **/ + * 1.Add check for whether content type is there. + * 2. If not based on the character set, Append it in File + **/ low_char_set = calloc(1, EM_SAFE_STRLEN(char_set) + strlen(" \" /></head>") +1); /*prevent 34359*/ if (low_char_set == NULL) { @@ -12075,9 +12072,9 @@ INTERNAL_FUNC int emstorage_add_content_type(char *file_path, char *char_set, in /* 1. Create a temporary file name */ if (!_get_temp_file_name(&temp_file_name, &err)) { - EM_DEBUG_EXCEPTION(" emcore_get_temp_file_name failed - %d", err); - if (err_code != NULL) *err_code = err; - goto FINISH_OFF; + EM_DEBUG_EXCEPTION(" emcore_get_temp_file_name failed - %d", err); + if (err_code != NULL) *err_code = err; + goto FINISH_OFF; } EM_DEBUG_LOG_SEC(">>>>>>> TEMP APPEND FILE PATH [ %s ] ", temp_file_name); @@ -12163,24 +12160,24 @@ INTERNAL_FUNC int emstorage_move_file(char *src_file, char *dst_file, int sync_s EM_DEBUG_LOG_SEC("src_file[%s], dst_file[%s]", src_file, dst_file); if (strcmp(src_file, dst_file) != 0) { - EM_DEBUG_LOG("oldpath and newpath are not on the same mounted file system."); - if (!emstorage_copy_file(src_file, dst_file, sync_status, &error)) { - EM_DEBUG_EXCEPTION("emstorage_copy_file failed - %d", error); + EM_DEBUG_LOG("oldpath and newpath are not on the same mounted file system."); + if (!emstorage_copy_file(src_file, dst_file, sync_status, &error)) { + EM_DEBUG_EXCEPTION("emstorage_copy_file failed - %d", error); - struct stat temp_file_stat; - if (stat(src_file, &temp_file_stat) < 0) { - EM_DEBUG_EXCEPTION("no src file found [%s] : %s", src_file, EM_STRERROR(errno_buf)); - } - if (stat(dst_file, &temp_file_stat) < 0) - EM_DEBUG_EXCEPTION("no dst file found [%s] : %s", dst_file, EM_STRERROR(errno_buf)); + struct stat temp_file_stat; + if (stat(src_file, &temp_file_stat) < 0) + EM_DEBUG_EXCEPTION("no src file found [%s] : %s", src_file, EM_STRERROR(errno_buf)); - error = EMAIL_ERROR_FILE_NOT_FOUND; - goto FINISH_OFF; + if (stat(dst_file, &temp_file_stat) < 0) + EM_DEBUG_EXCEPTION("no dst file found [%s] : %s", dst_file, EM_STRERROR(errno_buf)); + + error = EMAIL_ERROR_FILE_NOT_FOUND; + goto FINISH_OFF; - } - remove(src_file); - EM_DEBUG_LOG("src[%s] removed", src_file); + } + remove(src_file); + EM_DEBUG_LOG("src[%s] removed", src_file); } else { EM_DEBUG_LOG("src[%s] = dst[%s]", src_file, dst_file); } @@ -12318,10 +12315,10 @@ INTERNAL_FUNC int emstorage_delete_dir(char *src_dir, int *err_code) /* faizan.h@samsung.com */ INTERNAL_FUNC int emstorage_update_server_uid(char *multi_user_name, - int mail_id, - char *old_server_uid, - char *new_server_uid, - int *err_code) + int mail_id, + char *old_server_uid, + char *new_server_uid, + int *err_code) { EM_DEBUG_FUNC_BEGIN("new_server_uid[%s], old_server_uid[%s]", new_server_uid, old_server_uid); int ret = false; @@ -12347,7 +12344,7 @@ INTERNAL_FUNC int emstorage_update_server_uid(char *multi_user_name, if (mail_id > 0) { temp_strlen = strlen(conditional_clause_string); SNPRINTF(conditional_clause_string + temp_strlen, sizeof(conditional_clause_string) - temp_strlen, - "mail_id = %d ", mail_id); + "mail_id = %d ", mail_id); and_operation = 1; } @@ -12355,15 +12352,15 @@ INTERNAL_FUNC int emstorage_update_server_uid(char *multi_user_name, temp_strlen = strlen(conditional_clause_string); if (!and_operation) { sqlite3_snprintf(sizeof(conditional_clause_string) - temp_strlen, conditional_clause_string + temp_strlen, - "server_mail_id = '%q'", old_server_uid); + "server_mail_id = '%q'", old_server_uid); } else { sqlite3_snprintf(sizeof(conditional_clause_string) - temp_strlen, conditional_clause_string + temp_strlen, - "and server_mail_id = '%q'", old_server_uid); + "and server_mail_id = '%q'", old_server_uid); } } sqlite3_snprintf(sizeof(sql_query_string), sql_query_string, - "UPDATE mail_tbl SET server_mail_id = '%q' %s", new_server_uid, conditional_clause_string); + "UPDATE mail_tbl SET server_mail_id = '%q' %s", new_server_uid, conditional_clause_string); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { @@ -12406,12 +12403,12 @@ INTERNAL_FUNC int emstorage_update_read_mail_uid(char *multi_user_name, int mail SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_read_mail_uid_tbl SET server_uid=\'%s\', mailbox_id=\'%s\', mailbox_name=\'%s\' WHERE local_uid=%d ", new_server_uid, mbox_name, mbox_name, mail_id); + "UPDATE mail_read_mail_uid_tbl SET server_uid=\'%s\', mailbox_id=\'%s\', mailbox_name=\'%s\' WHERE local_uid=%d ", new_server_uid, mbox_name, mbox_name, mail_id); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } ret = true; @@ -12450,8 +12447,8 @@ INTERNAL_FUNC int emstorage_update_save_status(char *multi_user_name, int accoun error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } ret = true; @@ -12496,13 +12493,19 @@ int emstorage_get_unread_mailid(char *multi_user_name, int account_id, int vip_m memset(sql_query_string, 0x00, sizeof(sql_query_string)); - if (account_id == -1) - SNPRINTF(sql_select_query_string, sizeof(sql_select_query_string), "SELECT mail_id FROM mail_tbl WHERE flags_seen_field = 0 AND (save_status = %d or save_status = %d)", EMAIL_MAIL_STATUS_NOTI_WAITED, EMAIL_MAIL_STATUS_RECEIVED); - else - SNPRINTF(sql_select_query_string, sizeof(sql_select_query_string), "SELECT mail_id FROM mail_tbl WHERE account_id = %d AND flags_seen_field = 0 AND (save_status = %d or save_status = %d)", account_id, EMAIL_MAIL_STATUS_NOTI_WAITED, EMAIL_MAIL_STATUS_RECEIVED); + if (account_id == -1) { + SNPRINTF(sql_select_query_string, sizeof(sql_select_query_string), + "SELECT mail_id FROM mail_tbl WHERE flags_seen_field = 0 AND (save_status = %d or save_status = %d)", + EMAIL_MAIL_STATUS_NOTI_WAITED, EMAIL_MAIL_STATUS_RECEIVED); + } else { + SNPRINTF(sql_select_query_string, sizeof(sql_select_query_string), + "SELECT mail_id FROM mail_tbl WHERE account_id = %d AND flags_seen_field = 0 AND (save_status = %d or save_status = %d)", + account_id, EMAIL_MAIL_STATUS_NOTI_WAITED, EMAIL_MAIL_STATUS_RECEIVED); + } if (vip_mode) { - SNPRINTF(temp_query_string, sizeof(temp_query_string), "%s AND tag_id < 0", sql_select_query_string); + SNPRINTF(temp_query_string, sizeof(temp_query_string), + "%s AND tag_id < 0", sql_select_query_string); } else { SNPRINTF(temp_query_string, sizeof(temp_query_string), "%s", sql_select_query_string); } @@ -12513,7 +12516,7 @@ int emstorage_get_unread_mailid(char *multi_user_name, int account_id, int vip_m EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EM_DEBUG_LOG("Count : %d", count); @@ -12533,9 +12536,8 @@ int emstorage_get_unread_mailid(char *multi_user_name, int account_id, int vip_m col_index = 1; - for (i = 0; i < count; i++) { + for (i = 0; i < count; i++) _get_table_field_data_int(result, &(p_mail_ids[i]), col_index++); - } ret = true; @@ -12546,7 +12548,7 @@ FINISH_OFF: EMSTORAGE_FINISH_READ_TRANSACTION(transaction); -// sqlite3_db_release_memory(local_db_handle); + // sqlite3_db_release_memory(local_db_handle); if (ret == true) { if (mail_ids != NULL) @@ -12567,8 +12569,8 @@ FINISH_OFF: int setting_system_command(const char *command) - { - int pid = 0, status = 0; +{ + int pid = 0, status = 0; char *const environ[] = { NULL }; if (command == 0) @@ -12592,7 +12594,7 @@ int setting_system_command(const char *command) } do { - if (waitpid(pid, &status, 0) == -1) { + if (waitpid(pid, &status, 0) == -1) { if (errno != EINTR) return -1; } else { @@ -12647,29 +12649,29 @@ INTERNAL_FUNC int emstorage_mail_get_total_diskspace_usage(unsigned long *total_ goto FINISH_OFF; } - line_from_file = fgets(line, sizeof(line), fp); + line_from_file = fgets(line, sizeof(line), fp); - if (line_from_file == NULL) { - EM_DEBUG_EXCEPTION("fgets failed"); + if (line_from_file == NULL) { + EM_DEBUG_EXCEPTION("fgets failed"); error = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; - } - total_diskusage = strtoul(line, NULL, 10); - - memset(syscmd, 0, sizeof(syscmd)); - SNPRINTF(syscmd, sizeof(syscmd), "rm -f %s", SETTING_MEMORY_TEMP_FILE_PATH); - if (setting_system_command(syscmd) == -1) { - EM_DEBUG_EXCEPTION("emstorage_mail_get_total_diskspace_usage : [Setting > Memory] System Command [%s] is failed", syscmd); - error = EMAIL_ERROR_SYSTEM_FAILURE; + } + total_diskusage = strtoul(line, NULL, 10); + + memset(syscmd, 0, sizeof(syscmd)); + SNPRINTF(syscmd, sizeof(syscmd), "rm -f %s", SETTING_MEMORY_TEMP_FILE_PATH); + if (setting_system_command(syscmd) == -1) { + EM_DEBUG_EXCEPTION("emstorage_mail_get_total_diskspace_usage : [Setting > Memory] System Command [%s] is failed", syscmd); + error = EMAIL_ERROR_SYSTEM_FAILURE; goto FINISH_OFF; - } + } - EM_DEBUG_LOG("[Setting > Memory] @@@@@ Size of Directory [%s] is %ld KB", EMAIL_PATH, total_diskusage); + EM_DEBUG_LOG("[Setting > Memory] @@@@@ Size of Directory [%s] is %ld KB", EMAIL_PATH, total_diskusage); ret = true; FINISH_OFF: - if (err_code != NULL) + if (err_code != NULL) *err_code = error; if (ret) @@ -12677,7 +12679,7 @@ FINISH_OFF: else *total_usage = 0; - if (fp) fclose(fp); /* prevent 32730 */ + if (fp) fclose(fp); /* prevent 32730 */ EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; @@ -12693,61 +12695,61 @@ INTERNAL_FUNC int emstorage_test(char *multi_user_name, int mail_id, int account char sql_query_string[QUERY_SIZE] = {0, }; SNPRINTF(sql_query_string, sizeof(sql_query_string), - "INSERT INTO mail_tbl VALUES " - "(?" /* mail_id */ - ", ?" /* account_id */ - ", ?" /* mail_size */ - ", ?" /* server_mail_status */ - ", ?" /* server_mailbox_name */ - ", ?" /* server_mail_id */ - ", ?" /* reference_mail_id */ - ", ?" /* full_address_from */ - ", ?" /* full_address_reply */ - ", ?" /* full_address_to */ - ", ?" /* full_address_cc */ - ", ?" /* full_address_bcc */ - ", ?" /* full_address_return */ - ", ?" /* subject */ - ", ?" /* body_download_status */ - ", ?" /* file_path_plain */ - ", ?" /* file_path_html */ - ", ?" /* date_time */ - ", ?" /* flags_seen_field */ - ", ?" /* flags_deleted_field */ - ", ?" /* flags_flagged_field */ - ", ?" /* flags_answered_field */ - ", ?" /* flags_recent_field */ - ", ?" /* flags_draft_field */ - ", ?" /* flags_forwarded_field */ - ", ?" /* DRM_status */ - ", ?" /* priority */ - ", ?" /* save_status */ - ", ?" /* lock_status */ - ", ?" /* message_id */ - ", ?" /* report_status */ - ", ?" /* email_address_sender */ - ", ?" /* email_address_recipient */ - ", ?" /* attachment_count */ - ", ?" /* inline_content_count */ - ", ?" /* preview_text */ - ", ?" /* thread_id */ - ", ?" /* mailbox_type */ - ", ?" /* alias_sender */ - ", ?" /* alias_recipient */ - ", ?" /* thread_item_count */ - ", ?" /* meeting_request_status */ - ", ?" /* message_class */ - ", ?" /* digest_type */ - ", ?" /* smime_type */ - ", ?" /* scheduled_sending_time */ - ", ?" /* remaining_resend_times */ - ", ?" /* tag_id */ - ", ?" /* replied_time */ - ", ?" /* forwarded_time */ - ", ?" /* default_charset */ - ", ?" /* eas_data_length */ - ", ?" /* eas_data */ - ")"); + "INSERT INTO mail_tbl VALUES " + "(?" /* mail_id */ + ", ?" /* account_id */ + ", ?" /* mail_size */ + ", ?" /* server_mail_status */ + ", ?" /* server_mailbox_name */ + ", ?" /* server_mail_id */ + ", ?" /* reference_mail_id */ + ", ?" /* full_address_from */ + ", ?" /* full_address_reply */ + ", ?" /* full_address_to */ + ", ?" /* full_address_cc */ + ", ?" /* full_address_bcc */ + ", ?" /* full_address_return */ + ", ?" /* subject */ + ", ?" /* body_download_status */ + ", ?" /* file_path_plain */ + ", ?" /* file_path_html */ + ", ?" /* date_time */ + ", ?" /* flags_seen_field */ + ", ?" /* flags_deleted_field */ + ", ?" /* flags_flagged_field */ + ", ?" /* flags_answered_field */ + ", ?" /* flags_recent_field */ + ", ?" /* flags_draft_field */ + ", ?" /* flags_forwarded_field */ + ", ?" /* DRM_status */ + ", ?" /* priority */ + ", ?" /* save_status */ + ", ?" /* lock_status */ + ", ?" /* message_id */ + ", ?" /* report_status */ + ", ?" /* email_address_sender */ + ", ?" /* email_address_recipient */ + ", ?" /* attachment_count */ + ", ?" /* inline_content_count */ + ", ?" /* preview_text */ + ", ?" /* thread_id */ + ", ?" /* mailbox_type */ + ", ?" /* alias_sender */ + ", ?" /* alias_recipient */ + ", ?" /* thread_item_count */ + ", ?" /* meeting_request_status */ + ", ?" /* message_class */ + ", ?" /* digest_type */ + ", ?" /* smime_type */ + ", ?" /* scheduled_sending_time */ + ", ?" /* remaining_resend_times */ + ", ?" /* tag_id */ + ", ?" /* replied_time */ + ", ?" /* forwarded_time */ + ", ?" /* default_charset */ + ", ?" /* eas_data_length */ + ", ?" /* eas_data */ + ")"); int transaction = true; sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name); @@ -12757,7 +12759,7 @@ INTERNAL_FUNC int emstorage_test(char *multi_user_name, int mail_id, int account EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); _bind_stmt_field_data_int(hStmt, MAIL_ID_IDX_IN_MAIL_TBL, mail_id); _bind_stmt_field_data_int(hStmt, ACCOUNT_ID_IDX_IN_MAIL_TBL, account_id); @@ -12816,9 +12818,9 @@ INTERNAL_FUNC int emstorage_test(char *multi_user_name, int mail_id, int account EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); ret = true; FINISH_OFF: @@ -12847,14 +12849,14 @@ INTERNAL_FUNC int emstorage_get_max_mail_count() #define STRIPPED_SUBJECT_BUFFER_SIZE 4086 INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(char *multi_user_name, - emstorage_mail_tbl_t *mail_tbl, - int *thread_id, - int *result_latest_mail_id_in_thread, - int *thread_item_count) + emstorage_mail_tbl_t *mail_tbl, + int *thread_id, + int *result_latest_mail_id_in_thread, + int *thread_item_count) { EM_DEBUG_FUNC_BEGIN("mail_tbl [%p], thread_id [%p], " - "result_latest_mail_id_in_thread [%p], thread_item_count [%p]", - mail_tbl, thread_id, result_latest_mail_id_in_thread, thread_item_count); + "result_latest_mail_id_in_thread [%p], thread_item_count [%p]", + mail_tbl, thread_id, result_latest_mail_id_in_thread, thread_item_count); EM_PROFILE_BEGIN(profile_emstorage_get_thread_id_of_thread_mails); int rc = 0, query_size = 0, query_size_account = 0; @@ -12870,7 +12872,7 @@ INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(char *multi_user_name, int col_index = 4; int temp_thread_id = -1; char *sql_format = "SELECT mail_id, thread_id, date_time, subject " - "FROM mail_tbl WHERE subject like \'%%%q\' AND mailbox_id = %d"; + "FROM mail_tbl WHERE subject like \'%%%q\' AND mailbox_id = %d"; char *sql_format_account = " AND account_id = %d "; char *sql_format_order_by = " ORDER BY thread_id, date_time DESC "; char **result = NULL; @@ -12898,8 +12900,8 @@ INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(char *multi_user_name, } if (em_find_pos_stripped_subject_for_thread_view(subject, - stripped_subject, - STRIPPED_SUBJECT_BUFFER_SIZE) != EMAIL_ERROR_NONE) { + stripped_subject, + STRIPPED_SUBJECT_BUFFER_SIZE) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("em_find_pos_stripped_subject_for_thread_view is failed"); err_code = EMAIL_ERROR_UNKNOWN; result_thread_id = -1; @@ -12914,9 +12916,9 @@ INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(char *multi_user_name, } EM_DEBUG_LOG_SEC("em_find_pos_stripped_subject_for_thread_view returns[len = %d] = %s", - EM_SAFE_STRLEN(stripped_subject), stripped_subject); + EM_SAFE_STRLEN(stripped_subject), stripped_subject); - if (account_id > 0) { + if (account_id > 0) { query_size_account = 3 + EM_SAFE_STRLEN(sql_format_account); sql_account = malloc(query_size_account); if (sql_account == NULL) { @@ -12948,10 +12950,10 @@ INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(char *multi_user_name, EM_DEBUG_LOG_SEC("Query : %s", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), - rc); + rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err_code = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EM_DEBUG_LOG("Result rows count : %d", count); @@ -12972,8 +12974,8 @@ INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(char *multi_user_name, temp_thread_id = result_thread_id; if (em_find_pos_stripped_subject_for_thread_view(p_subject, - stripped_subject2, - STRIPPED_SUBJECT_BUFFER_SIZE) != EMAIL_ERROR_NONE) { + stripped_subject2, + STRIPPED_SUBJECT_BUFFER_SIZE) != EMAIL_ERROR_NONE) { EM_DEBUG_EXCEPTION("em_find_pos_stripped_subject_for_thread_view is failed"); err_code = EMAIL_ERROR_UNKNOWN; result_thread_id = -1; @@ -12991,7 +12993,7 @@ INTERNAL_FUNC int emstorage_get_thread_id_of_thread_mails(char *multi_user_name, if (search_thread) { EM_DEBUG_LOG("latest_mail_id_in_thread [%d], mail_id [%d]", - latest_mail_id_in_thread, mail_tbl->mail_id); + latest_mail_id_in_thread, mail_tbl->mail_id); break; } else { result_thread_id = -1; @@ -13093,15 +13095,14 @@ INTERNAL_FUNC int emstorage_get_thread_id_from_mailbox(char *multi_user_name, in EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err_code = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EM_DEBUG_LOG("Result rows count : %d", count); if (count == 0) result_thread_id = -1; - else { + else _get_table_field_data_int(result, &result_thread_id, 1); - } FINISH_OFF: *thread_id = result_thread_id; @@ -13161,7 +13162,7 @@ FINISH_OFF: INTERNAL_FUNC int emstorage_get_sender_list(char *multi_user_name, int account_id, int mailbox_id, int search_type, const char *search_value, email_sort_type_t sorting, email_sender_list_t** sender_list, int *sender_count, int *err_code) { EM_DEBUG_FUNC_BEGIN_SEC("account_id [%d], mailbox_id [%d], search_type [%d], search_value [%p], sorting [%d], sender_list[%p], sender_count[%p] err_code[%p]" - , account_id , mailbox_id , search_type , search_value , sorting , sender_list, sender_count, err_code); + , account_id , mailbox_id , search_type , search_value , sorting , sender_list, sender_count, err_code); if ((!sender_list) || (!sender_count)) { EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM"); @@ -13181,8 +13182,8 @@ INTERNAL_FUNC int emstorage_get_sender_list(char *multi_user_name, int account_i sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name); SNPRINTF(sql_query_string, sizeof(sql_query_string), - "SELECT email_address_sender, alias_sender, COUNT(email_address_sender), SUM(flags_seen_field = 1) " - "FROM mail_tbl "); + "SELECT email_address_sender, alias_sender, COUNT(email_address_sender), SUM(flags_seen_field = 1) " + "FROM mail_tbl "); /* mailbox_id */ if (mailbox_id) @@ -13197,47 +13198,47 @@ INTERNAL_FUNC int emstorage_get_sender_list(char *multi_user_name, int account_i if (search_value) { switch (search_type) { - case EMAIL_SEARCH_FILTER_SUBJECT: - SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), QUERY_SIZE-(EM_SAFE_STRLEN(sql_query_string)+1), + case EMAIL_SEARCH_FILTER_SUBJECT: + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), QUERY_SIZE-(EM_SAFE_STRLEN(sql_query_string)+1), " AND (UPPER(subject) LIKE UPPER(\'%%%%%s%%%%\')) ", search_value); - break; - case EMAIL_SEARCH_FILTER_SENDER: - SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), QUERY_SIZE-(EM_SAFE_STRLEN(sql_query_string)+1), + break; + case EMAIL_SEARCH_FILTER_SENDER: + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), QUERY_SIZE-(EM_SAFE_STRLEN(sql_query_string)+1), " AND ((UPPER(full_address_from) LIKE UPPER(\'%%%%%s%%%%\')) " ") ", search_value); - break; - case EMAIL_SEARCH_FILTER_RECIPIENT: - SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), QUERY_SIZE-(EM_SAFE_STRLEN(sql_query_string)+1), + break; + case EMAIL_SEARCH_FILTER_RECIPIENT: + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), QUERY_SIZE-(EM_SAFE_STRLEN(sql_query_string)+1), " AND ((UPPER(full_address_to) LIKE UPPER(\'%%%%%s%%%%\')) " " OR (UPPER(full_address_cc) LIKE UPPER(\'%%%%%s%%%%\')) " " OR (UPPER(full_address_bcc) LIKE UPPER(\'%%%%%s%%%%\')) " ") ", search_value, search_value, search_value); - break; - case EMAIL_SEARCH_FILTER_ALL: - SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), QUERY_SIZE-(EM_SAFE_STRLEN(sql_query_string)+1), + break; + case EMAIL_SEARCH_FILTER_ALL: + SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), QUERY_SIZE-(EM_SAFE_STRLEN(sql_query_string)+1), " AND (UPPER(subject) LIKE UPPER(\'%%%%%s%%%%\') " - " OR (((UPPER(full_address_from) LIKE UPPER(\'%%%%%s%%%%\')) " + " OR (((UPPER(full_address_from) LIKE UPPER(\'%%%%%s%%%%\')) " " OR (UPPER(full_address_to) LIKE UPPER(\'%%%%%s%%%%\')) " " OR (UPPER(full_address_cc) LIKE UPPER(\'%%%%%s%%%%\')) " " OR (UPPER(full_address_bcc) LIKE UPPER(\'%%%%%s%%%%\')) " " ) " " )" ")", search_value, search_value, search_value, search_value, search_value); - break; + break; } } /* sorting option is not available now. The order of sender list is ascending order by display name */ SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), - "GROUP BY email_address_sender " - "ORDER BY UPPER(alias_sender) "); + "GROUP BY email_address_sender " + "ORDER BY UPPER(alias_sender) "); EM_DEBUG_LOG_SEC("query[%s]", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EM_DEBUG_LOG("Count of Sender [%d]", count); @@ -13327,18 +13328,18 @@ INTERNAL_FUNC int emstorage_free_address_info_list(email_address_info_list_t **a /* delete GLists */ for (i = EMAIL_ADDRESS_TYPE_FROM; i <= EMAIL_ADDRESS_TYPE_BCC; i++) { switch (i) { - case EMAIL_ADDRESS_TYPE_FROM: - list = (*address_info_list)->from; - break; - case EMAIL_ADDRESS_TYPE_TO: - list = (*address_info_list)->to; - break; - case EMAIL_ADDRESS_TYPE_CC: - list = (*address_info_list)->cc; - break; - case EMAIL_ADDRESS_TYPE_BCC: - list = (*address_info_list)->bcc; - break; + case EMAIL_ADDRESS_TYPE_FROM: + list = (*address_info_list)->from; + break; + case EMAIL_ADDRESS_TYPE_TO: + list = (*address_info_list)->to; + break; + case EMAIL_ADDRESS_TYPE_CC: + list = (*address_info_list)->cc; + break; + case EMAIL_ADDRESS_TYPE_BCC: + list = (*address_info_list)->bcc; + break; } /* delete dynamic-allocated memory for each item */ @@ -13385,17 +13386,17 @@ INTERNAL_FUNC int emstorage_add_pbd_activity(char *multi_user_name, email_event_ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error); memset(sql_query_string, 0x00, sizeof(sql_query_string)); SNPRINTF(sql_query_string, sizeof(sql_query_string), - "INSERT INTO mail_partial_body_activity_tbl VALUES " - "(" - "? " /* Account ID */ - ",?" /* Local Mail ID */ - ",?" /* Server mail ID */ - ",?" /* Activity ID */ - ",?" /* Activity type*/ - ",?" /* Mailbox ID*/ - ",?" /* Mailbox name*/ - ",?" /* Multi User Name */ - ") "); + "INSERT INTO mail_partial_body_activity_tbl VALUES " + "(" + "? " /* Account ID */ + ",?" /* Local Mail ID */ + ",?" /* Server mail ID */ + ",?" /* Activity ID */ + ",?" /* Activity type*/ + ",?" /* Mailbox ID*/ + ",?" /* Mailbox name*/ + ",?" /* Multi User Name */ + ") "); char *sql = "SELECT max(rowid) FROM mail_partial_body_activity_tbl;"; char **result = NULL; @@ -13404,7 +13405,7 @@ INTERNAL_FUNC int emstorage_add_pbd_activity(char *multi_user_name, email_event_ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); if (NULL == result[1]) rc = 1; else rc = atoi(result[1])+1; @@ -13414,7 +13415,7 @@ INTERNAL_FUNC int emstorage_add_pbd_activity(char *multi_user_name, email_event_ *activity_id = local_activity->activity_id = rc; EM_DEBUG_LOG_SEC(">>>>> ACTIVITY ID [ %d ], MAIL ID [ %d ], ACTIVITY TYPE [ %d ], SERVER MAIL ID [ %lu ]", \ - local_activity->activity_id, local_activity->mail_id, local_activity->activity_type, local_activity->server_mail_id); + local_activity->activity_id, local_activity->mail_id, local_activity->activity_type, local_activity->server_mail_id); if (local_activity->mailbox_id) EM_DEBUG_LOG(" MAILBOX ID [ %d ]", local_activity->mailbox_id); @@ -13422,7 +13423,7 @@ INTERNAL_FUNC int emstorage_add_pbd_activity(char *multi_user_name, email_event_ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); _bind_stmt_field_data_int(hStmt, i++, local_activity->account_id); @@ -13438,9 +13439,9 @@ INTERNAL_FUNC int emstorage_add_pbd_activity(char *multi_user_name, email_event_ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d, errmsg = %s.", rc, sqlite3_errmsg(local_db_handle))); + ("sqlite3_step fail:%d, errmsg = %s.", rc, sqlite3_errmsg(local_db_handle))); ret = true; @@ -13490,7 +13491,7 @@ INTERNAL_FUNC int emstorage_get_pbd_mailbox_list(char *multi_user_name, int acco EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); *count = atoi(result[1]); sqlite3_free_table(result); @@ -13515,12 +13516,12 @@ INTERNAL_FUNC int emstorage_get_pbd_mailbox_list(char *multi_user_name, int acco EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); mbox_list = (int *)em_malloc(sizeof(int) * (*count)); if (NULL == mbox_list) { @@ -13536,7 +13537,7 @@ INTERNAL_FUNC int emstorage_get_pbd_mailbox_list(char *multi_user_name, int acco EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); /* EM_DEBUG_LOG("In emstorage_get_pdb_mailbox_list() loop, After sqlite3_step(), , i = %d, rc = %d.", i, rc); */ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); EM_DEBUG_LOG("mbox_list %d", mbox_list[i]); } @@ -13590,7 +13591,7 @@ INTERNAL_FUNC int emstorage_get_pbd_account_list(char *multi_user_name, int **ac EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); *count = atoi(result[1]); sqlite3_free_table(result); @@ -13615,12 +13616,12 @@ INTERNAL_FUNC int emstorage_get_pbd_account_list(char *multi_user_name, int **ac EM_DEBUG_LOG("Before sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); if (NULL == (result_account_list = (int *)em_malloc(sizeof(int) * (*count)))) { EM_DEBUG_EXCEPTION(" em_mallocfailed..."); @@ -13635,7 +13636,7 @@ INTERNAL_FUNC int emstorage_get_pbd_account_list(char *multi_user_name, int **ac EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); EM_DEBUG_LOG("account id -> %d", result_account_list[i]); } @@ -13694,7 +13695,7 @@ INTERNAL_FUNC int emstorage_get_pbd_activity_data(char *multi_user_name, int acc EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); *count = atoi(result[1]); sqlite3_free_table(result); @@ -13719,12 +13720,12 @@ INTERNAL_FUNC int emstorage_get_pbd_activity_data(char *multi_user_name, int acc EM_DEBUG_LOG(" Bbefore sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); if (!(event_list = (email_event_partial_body_thd*)em_malloc(sizeof(email_event_partial_body_thd) * (*count)))) { EM_DEBUG_EXCEPTION("Malloc failed"); @@ -13747,7 +13748,7 @@ INTERNAL_FUNC int emstorage_get_pbd_activity_data(char *multi_user_name, int acc EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); /* EM_DEBUG_LOG("In emstorage_get_pbd_activity_data() loop, After sqlite3_step(), , i = %d, rc = %d.", i, rc); */ EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); event_list[i].event_type = 0; } @@ -13756,7 +13757,7 @@ INTERNAL_FUNC int emstorage_get_pbd_activity_data(char *multi_user_name, int acc FINISH_OFF: if (true == ret) - *event_start = event_list; + *event_start = event_list; else { for (i = 0; i < (*count); i++) emcore_free_partial_body_thd_event(event_list, NULL); @@ -13812,8 +13813,8 @@ INTERNAL_FUNC int emstorage_delete_pbd_activity(char *multi_user_name, int accou EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } /* validate activity existence */ @@ -13867,12 +13868,12 @@ INTERNAL_FUNC int emstorage_get_mailbox_pbd_activity_count(char *multi_user_name EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG("before sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); _get_stmt_field_data_int(hStmt, activity_count, 0); @@ -13928,11 +13929,11 @@ INTERNAL_FUNC int emstorage_get_pbd_activity_count(char *multi_user_name, int *a EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG_DEV(" before sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); _get_stmt_field_data_int(hStmt, activity_count, 0); @@ -13984,8 +13985,8 @@ INTERNAL_FUNC int emstorage_delete_full_pbd_activity_data(char *multi_user_name, EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } rc = sqlite3_changes(local_db_handle); @@ -14010,7 +14011,7 @@ FINISH_OFF: } /*Himanshu[h.gahlaut]-> Added below API to update mail_partial_body_activity_tbl -if a mail is moved before its partial body is downloaded.Currently not used but should be used if mail move from server is enabled*/ + if a mail is moved before its partial body is downloaded.Currently not used but should be used if mail move from server is enabled*/ INTERNAL_FUNC int emstorage_update_pbd_activity(char *multi_user_name, char *old_server_uid, char *new_server_uid, char *mbox_name, int *err_code) { @@ -14033,19 +14034,18 @@ INTERNAL_FUNC int emstorage_update_pbd_activity(char *multi_user_name, char *old EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error); memset(sql_query_string, 0x00, sizeof(sql_query_string)); SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_partial_body_activity_tbl SET server_mail_id = %s , mailbox_name=\'%s\' WHERE server_mail_id = %s ", new_server_uid, mbox_name, old_server_uid); + "UPDATE mail_partial_body_activity_tbl SET server_mail_id = %s , mailbox_name=\'%s\' WHERE server_mail_id = %s ", new_server_uid, mbox_name, old_server_uid); EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } rc = sqlite3_changes(local_db_handle); - if (rc == 0) { + if (rc == 0) EM_DEBUG_LOG("No matching found in mail_partial_body_activity_tbl"); - } ret = true; @@ -14130,13 +14130,13 @@ INTERNAL_FUNC int emstorage_update_read_mail_uid_by_server_uid(char *multi_user_ SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_read_mail_uid_tbl SET server_uid=\'%s\' , mailbox_name=\'%s\' WHERE server_uid=%s ", new_server_uid, mbox_name, old_server_uid); + "UPDATE mail_read_mail_uid_tbl SET server_uid=\'%s\' , mailbox_name=\'%s\' WHERE server_uid=%s ", new_server_uid, mbox_name, old_server_uid); EM_DEBUG_LOG_SEC(" Query [%s]", sql_query_string); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } rc = sqlite3_changes(local_db_handle); @@ -14149,9 +14149,9 @@ INTERNAL_FUNC int emstorage_update_read_mail_uid_by_server_uid(char *multi_user_ ret = true; FINISH_OFF: - EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error); + EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error); - if (err_code != NULL) + if (err_code != NULL) *err_code = error; EM_DEBUG_FUNC_END("ret [%d]", ret); @@ -14164,21 +14164,21 @@ FINISH_OFF: * @fn emstorage_get_id_set_from_mail_ids(int mail_ids[], int mail_id_count, email_id_set_t** server_uids, int *id_set_count, int *err_code); * Prepare an array of mail_id and corresponding server mail id. * - *@author h.gahlaut@samsung.com + * @author h.gahlaut@samsung.com * @param[in] mail_ids Specifies the comma separated string of mail_ids. Maximaum size of string should be less than or equal to (QUERY_SIZE - 88) * where 88 is the length of fixed keywords including ending null character in the QUERY to be formed * @param[out] idset Returns the array of mail_id and corresponding server_mail_id sorted by server_mail_ids * @param[out] id_set_count Returns the no. of cells in idset array i.e. no. of sets of mail_ids and server_mail_ids * @param[out] err_code Returns the error code. - * @remarks An Example of Query to be exexuted in this API: + * @remarks An Example of Query to be exexuted in this API: * SELECT local_uid, s_uid from mail_read_mail_uid_tbl where local_uid in (12, 13, 56, 78); * @return This function returns true on success or false on failure. */ INTERNAL_FUNC int emstorage_get_id_set_from_mail_ids(char *multi_user_name, - char *mail_ids, - email_id_set_t** idset, - int *id_set_count, - int *err_code) + char *mail_ids, + email_id_set_t** idset, + int *id_set_count, + int *err_code) { EM_DEBUG_FUNC_BEGIN(); EM_PROFILE_BEGIN(EmStorageGetIdSetFromMailIds); @@ -14199,7 +14199,7 @@ INTERNAL_FUNC int emstorage_get_id_set_from_mail_ids(char *multi_user_name, if (NULL == mail_ids || NULL == idset || NULL == id_set_count) { EM_DEBUG_EXCEPTION("Invalid Parameters mail_ids[%p] idset[%p] id_set_count [%p]", - mail_ids, idset, id_set_count); + mail_ids, idset, id_set_count); if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; return false; @@ -14216,8 +14216,8 @@ INTERNAL_FUNC int emstorage_get_id_set_from_mail_ids(char *multi_user_name, /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL); */ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); - goto FINISH_OFF; }, ("SQL(%s) sqlite3_get_table fail:%d -%s", - sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + goto FINISH_OFF; }, ("SQL(%s) sqlite3_get_table fail:%d -%s", + sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EM_DEBUG_LOG(" Count of mails [%d ]", count); @@ -14288,22 +14288,22 @@ INTERNAL_FUNC int emstorage_delete_triggers_from_lucene(char *multi_user_name) SNPRINTF(sql_query_string, sizeof(sql_query_string), "DROP TRIGGER triggerDelete;"); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } SNPRINTF(sql_query_string, sizeof(sql_query_string), "DROP TRIGGER triggerInsert;"); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } SNPRINTF(sql_query_string, sizeof(sql_query_string), "DROP TRIGGER triggerUpdate;"); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } ret = true; @@ -14335,12 +14335,12 @@ INTERNAL_FUNC int emstorage_update_tag_id(char *multi_user_name, int old_filter_ EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error); SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_tbl SET tag_id=%d WHERE tag_id=%d ", new_filter_id, old_filter_id); + "UPDATE mail_tbl SET tag_id=%d WHERE tag_id=%d ", new_filter_id, old_filter_id); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } ret = true; @@ -14424,7 +14424,7 @@ INTERNAL_FUNC int emstorage_filter_mails_by_rule(char *multi_user_name, int acco /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL); */ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EM_DEBUG_LOG("Count of mails [%d]", count); @@ -14473,8 +14473,8 @@ INTERNAL_FUNC int emstorage_filter_mails_by_rule(char *multi_user_name, int acco error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } #ifdef __FEATURE_BODY_SEARCH__ @@ -14580,8 +14580,8 @@ INTERNAL_FUNC int emstorage_set_mail_slot_size(char *multi_user_name, int accoun EM_DEBUG_LOG_SEC("query[%s]", sql_query_string); err = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (err != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", err); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", err); + goto FINISH_OFF; } ret = true; @@ -14604,7 +14604,7 @@ INTERNAL_FUNC int emstorage_add_meeting_request(char *multi_user_name, int accou if (!meeting_req || meeting_req->mail_id <= 0) { if (meeting_req) - EM_DEBUG_EXCEPTION("mail_id[%]d", meeting_req->mail_id); + EM_DEBUG_EXCEPTION("mail_id[%]d", meeting_req->mail_id); if (err_code != NULL) *err_code = EMAIL_ERROR_INVALID_PARAM; @@ -14624,23 +14624,23 @@ INTERNAL_FUNC int emstorage_add_meeting_request(char *multi_user_name, int accou EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error); SNPRINTF(sql_query_string, sizeof(sql_query_string), - "INSERT INTO mail_meeting_tbl VALUES " - "(?" /* mail_id */ - ", ?" /* account_id */ - ", ?" /* mailbox_id */ - ", ?" /* meeting_response */ - ", ?" /* start_time */ - ", ?" /* end_time */ - ", ?" /* location */ - ", ?" /* global_object_id */ - ", ?" /* offset */ - ", ?" /* standard_name */ - ", ?" /* standard_time_start_date */ - ", ?" /* standard_biad */ - ", ?" /* daylight_name */ - ", ?" /* daylight_time_start_date */ - ", ?" /* daylight_bias */ - ")"); + "INSERT INTO mail_meeting_tbl VALUES " + "(?" /* mail_id */ + ", ?" /* account_id */ + ", ?" /* mailbox_id */ + ", ?" /* meeting_response */ + ", ?" /* start_time */ + ", ?" /* end_time */ + ", ?" /* location */ + ", ?" /* global_object_id */ + ", ?" /* offset */ + ", ?" /* standard_name */ + ", ?" /* standard_time_start_date */ + ", ?" /* standard_biad */ + ", ?" /* daylight_name */ + ", ?" /* daylight_time_start_date */ + ", ?" /* daylight_bias */ + ")"); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); if (rc != SQLITE_OK) { @@ -14653,22 +14653,22 @@ INTERNAL_FUNC int emstorage_add_meeting_request(char *multi_user_name, int accou col_index = 0; /* - EM_DEBUG_LOG_SEC(">>>>> meeting_req->mail_id[%d]", meeting_req->mail_id); - EM_DEBUG_LOG_SEC(">>>>> account_id[%d]", account_id); - EM_DEBUG_LOG_SEC(">>>>> mailbox_name[%s]", mailbox_name); - EM_DEBUG_LOG_SEC(">>>>> meeting_req->meeting_response[%d]", meeting_req->meeting_response); - EM_DEBUG_LOG_SEC(">>>>> meeting_req->start_time[%s]", asctime(&(meeting_req->start_time))); - EM_DEBUG_LOG_SEC(">>>>> meeting_req->end_time[%s]", asctime(&(meeting_req->end_time))); - EM_DEBUG_LOG_SEC(">>>>> meeting_req->location[%s]", meeting_req->location); - EM_DEBUG_LOG_SEC(">>>>> meeting_req->global_object_id[%s]", meeting_req->global_object_id); - EM_DEBUG_LOG_SEC(">>>>> meeting_req->time_zone.offset_from_GMT[%d]", meeting_req->time_zone.offset_from_GMT); - EM_DEBUG_LOG_SEC(">>>>> meeting_req->time_zone.standard_name[%s]", meeting_req->time_zone.standard_name); - EM_DEBUG_LOG_SEC(">>>>> meeting_req->time_zone.standard_time_start_date[%s]", asctime(&(meeting_req->time_zone.standard_time_start_date))); - EM_DEBUG_LOG_SEC(">>>>> meeting_req->time_zone.standard_bias[%d]", meeting_req->time_zone.standard_bias); - EM_DEBUG_LOG_SEC(">>>>> meeting_req->time_zone.daylight_name[%s]", meeting_req->time_zone.daylight_name); - EM_DEBUG_LOG_SEC(">>>>> meeting_req->time_zone.daylight_time_start_date[%s]", asctime(&(meeting_req->time_zone.daylight_time_start_date))); - EM_DEBUG_LOG_SEC(">>>>> meeting_req->time_zone.daylight_bias[%d]", meeting_req->time_zone.daylight_bias); - */ + EM_DEBUG_LOG_SEC(">>>>> meeting_req->mail_id[%d]", meeting_req->mail_id); + EM_DEBUG_LOG_SEC(">>>>> account_id[%d]", account_id); + EM_DEBUG_LOG_SEC(">>>>> mailbox_name[%s]", mailbox_name); + EM_DEBUG_LOG_SEC(">>>>> meeting_req->meeting_response[%d]", meeting_req->meeting_response); + EM_DEBUG_LOG_SEC(">>>>> meeting_req->start_time[%s]", asctime(&(meeting_req->start_time))); + EM_DEBUG_LOG_SEC(">>>>> meeting_req->end_time[%s]", asctime(&(meeting_req->end_time))); + EM_DEBUG_LOG_SEC(">>>>> meeting_req->location[%s]", meeting_req->location); + EM_DEBUG_LOG_SEC(">>>>> meeting_req->global_object_id[%s]", meeting_req->global_object_id); + EM_DEBUG_LOG_SEC(">>>>> meeting_req->time_zone.offset_from_GMT[%d]", meeting_req->time_zone.offset_from_GMT); + EM_DEBUG_LOG_SEC(">>>>> meeting_req->time_zone.standard_name[%s]", meeting_req->time_zone.standard_name); + EM_DEBUG_LOG_SEC(">>>>> meeting_req->time_zone.standard_time_start_date[%s]", asctime(&(meeting_req->time_zone.standard_time_start_date))); + EM_DEBUG_LOG_SEC(">>>>> meeting_req->time_zone.standard_bias[%d]", meeting_req->time_zone.standard_bias); + EM_DEBUG_LOG_SEC(">>>>> meeting_req->time_zone.daylight_name[%s]", meeting_req->time_zone.daylight_name); + EM_DEBUG_LOG_SEC(">>>>> meeting_req->time_zone.daylight_time_start_date[%s]", asctime(&(meeting_req->time_zone.daylight_time_start_date))); + EM_DEBUG_LOG_SEC(">>>>> meeting_req->time_zone.daylight_bias[%d]", meeting_req->time_zone.daylight_bias); + */ _bind_stmt_field_data_int(hStmt, col_index++, meeting_req->mail_id); _bind_stmt_field_data_int(hStmt, col_index++, account_id); _bind_stmt_field_data_int(hStmt, col_index++, input_mailbox_id); @@ -14696,9 +14696,9 @@ INTERNAL_FUNC int emstorage_add_meeting_request(char *multi_user_name, int accou EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); ret = true; @@ -14754,7 +14754,7 @@ INTERNAL_FUNC int emstorage_query_meeting_request(char *multi_user_name, const c EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {err = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); if (!count) { EM_DEBUG_EXCEPTION("No meeting_request found..."); @@ -14807,7 +14807,7 @@ FINISH_OFF: EMSTORAGE_FINISH_READ_TRANSACTION(transaction); -// sqlite3_db_release_memory(local_db_handle); + // sqlite3_db_release_memory(local_db_handle); EM_DEBUG_FUNC_END("err [%d]", err); return err; @@ -14880,45 +14880,45 @@ INTERNAL_FUNC int emstorage_update_meeting_request(char *multi_user_name, email_ memset(sql_query_string, 0x00, sizeof(sql_query_string)); SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_meeting_tbl " - "SET " - /* " account_id = ?, " // not update here, this can be changed when move or copy */ - /* " mailbox_name = ?, " // not update here, this can be changed when move or copy */ - " meeting_response = ?, " - " start_time = ?, " - " end_time = ?, " - " location = ?, " - " global_object_id = ?, " - " offset = ?, " - " standard_name = ?, " - " standard_time_start_date = ?, " - " standard_bias = ?, " - " daylight_name = ?, " - " daylight_time_start_date = ?, " - " daylight_bias = ? " - "WHERE mail_id = %d", - meeting_req->mail_id); + "UPDATE mail_meeting_tbl " + "SET " + /* " account_id = ?, " // not update here, this can be changed when move or copy */ + /* " mailbox_name = ?, " // not update here, this can be changed when move or copy */ + " meeting_response = ?, " + " start_time = ?, " + " end_time = ?, " + " location = ?, " + " global_object_id = ?, " + " offset = ?, " + " standard_name = ?, " + " standard_time_start_date = ?, " + " standard_bias = ?, " + " daylight_name = ?, " + " daylight_time_start_date = ?, " + " daylight_bias = ? " + "WHERE mail_id = %d", + meeting_req->mail_id); EM_DEBUG_LOG_SEC("SQL(%s)", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); -/* - EM_DEBUG_LOG_SEC(">>>>> meeting_req->mail_id[%d]", meeting_req->mail_id); - EM_DEBUG_LOG_SEC(">>>>> meeting_req->meeting_response[%d]", meeting_req->meeting_response); - EM_DEBUG_LOG_SEC(">>>>> meeting_req->start_time[%s]", asctime(&(meeting_req->start_time))); - EM_DEBUG_LOG_SEC(">>>>> meeting_req->end_time[%s]", asctime(&(meeting_req->end_time))); - EM_DEBUG_LOG_SEC(">>>>> meeting_req->location[%s]", meeting_req->location); - EM_DEBUG_LOG_SEC(">>>>> meeting_req->global_object_id[%s]", meeting_req->global_object_id); - EM_DEBUG_LOG_SEC(">>>>> meeting_req->time_zone.offset_from_GMT[%d]", meeting_req->time_zone.offset_from_GMT); - EM_DEBUG_LOG_SEC(">>>>> meeting_req->time_zone.standard_name[%s]", meeting_req->time_zone.standard_name); - EM_DEBUG_LOG_SEC(">>>>> meeting_req->time_zone.standard_time_start_date[%s]", asctime(&(meeting_req->time_zone.standard_time_start_date))); - EM_DEBUG_LOG_SEC(">>>>> meeting_req->time_zone.standard_bias[%d]", meeting_req->time_zone.standard_bias); - EM_DEBUG_LOG_SEC(">>>>> meeting_req->time_zone.daylight_name[%s]", meeting_req->time_zone.daylight_name); - EM_DEBUG_LOG_SEC(">>>>> meeting_req->time_zone.daylight_time_start_date[%s]", asctime(&(meeting_req->time_zone.daylight_time_start_date))); - EM_DEBUG_LOG_SEC(">>>>> meeting_req->time_zone.daylight_bias[%d]", meeting_req->time_zone.daylight_bias); -*/ + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + /* + EM_DEBUG_LOG_SEC(">>>>> meeting_req->mail_id[%d]", meeting_req->mail_id); + EM_DEBUG_LOG_SEC(">>>>> meeting_req->meeting_response[%d]", meeting_req->meeting_response); + EM_DEBUG_LOG_SEC(">>>>> meeting_req->start_time[%s]", asctime(&(meeting_req->start_time))); + EM_DEBUG_LOG_SEC(">>>>> meeting_req->end_time[%s]", asctime(&(meeting_req->end_time))); + EM_DEBUG_LOG_SEC(">>>>> meeting_req->location[%s]", meeting_req->location); + EM_DEBUG_LOG_SEC(">>>>> meeting_req->global_object_id[%s]", meeting_req->global_object_id); + EM_DEBUG_LOG_SEC(">>>>> meeting_req->time_zone.offset_from_GMT[%d]", meeting_req->time_zone.offset_from_GMT); + EM_DEBUG_LOG_SEC(">>>>> meeting_req->time_zone.standard_name[%s]", meeting_req->time_zone.standard_name); + EM_DEBUG_LOG_SEC(">>>>> meeting_req->time_zone.standard_time_start_date[%s]", asctime(&(meeting_req->time_zone.standard_time_start_date))); + EM_DEBUG_LOG_SEC(">>>>> meeting_req->time_zone.standard_bias[%d]", meeting_req->time_zone.standard_bias); + EM_DEBUG_LOG_SEC(">>>>> meeting_req->time_zone.daylight_name[%s]", meeting_req->time_zone.daylight_name); + EM_DEBUG_LOG_SEC(">>>>> meeting_req->time_zone.daylight_time_start_date[%s]", asctime(&(meeting_req->time_zone.daylight_time_start_date))); + EM_DEBUG_LOG_SEC(">>>>> meeting_req->time_zone.daylight_bias[%d]", meeting_req->time_zone.daylight_bias); + */ int col_index = 0; _bind_stmt_field_data_int(hStmt, col_index++, meeting_req->meeting_response); @@ -14941,7 +14941,7 @@ INTERNAL_FUNC int emstorage_update_meeting_request(char *multi_user_name, email_ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); ret = true; @@ -14999,8 +14999,8 @@ INTERNAL_FUNC int emstorage_delete_meeting_request(char *multi_user_name, int ac error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } ret = true; @@ -15025,7 +15025,7 @@ INTERNAL_FUNC void emstorage_free_meeting_request(email_meeting_request_t *meeti EM_SAFE_FREE(meeting_req->location); EM_SAFE_FREE(meeting_req->global_object_id); - EM_DEBUG_FUNC_END(); + EM_DEBUG_FUNC_END(); } INTERNAL_FUNC int emstorage_get_overflowed_mail_id_list(char *multi_user_name, int account_id, int input_mailbox_id, int mail_slot_size, int **mail_id_list, int *mail_id_count, int transaction, int *err_code) @@ -15056,7 +15056,7 @@ INTERNAL_FUNC int emstorage_get_overflowed_mail_id_list(char *multi_user_name, i EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &result_mail_id_count, 0, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); if (!result_mail_id_count) { EM_DEBUG_LOG("No mail found..."); @@ -15130,7 +15130,7 @@ INTERNAL_FUNC int emstorage_get_thread_id_by_mail_id(char *multi_user_name, int /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &result_count, 0, NULL); */ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &result_count, 0, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {err = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); if (!result_count) { EM_DEBUG_LOG("No mail found..."); @@ -15156,21 +15156,21 @@ FINISH_OFF: } INTERNAL_FUNC int emstorage_update_latest_thread_mail(char *multi_user_name, - int account_id, - int mailbox_id, - int mailbox_type, - int thread_id, - int *updated_thread_id, - int latest_mail_id, - int thread_item_count, - int noti_type, - int transaction, - int *err_code) + int account_id, + int mailbox_id, + int mailbox_type, + int thread_id, + int *updated_thread_id, + int latest_mail_id, + int thread_item_count, + int noti_type, + int transaction, + int *err_code) { EM_DEBUG_FUNC_BEGIN("account_id [%d], mailbox_id [%d], thread_id[%d], updated_thread_id[%p], " - "latest_mail_id [%d], thread_item_count[%d], err_code[%p]", - account_id, mailbox_id, thread_id, updated_thread_id, - latest_mail_id, thread_item_count, err_code); + "latest_mail_id [%d], thread_item_count[%d], err_code[%p]", + account_id, mailbox_id, thread_id, updated_thread_id, + latest_mail_id, thread_item_count, err_code); int rc = -1, ret = false; int err = EMAIL_ERROR_NONE; @@ -15194,7 +15194,7 @@ INTERNAL_FUNC int emstorage_update_latest_thread_mail(char *multi_user_name, /* rc = sqlite3_get_table(local_db_handle, sql_query_string, &result, &result_count, 0, NULL); */ EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &result_count, 0, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {err = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EM_DEBUG_LOG("result_count[%d]", result_count); if (result_count == 0) { EM_DEBUG_LOG("No mail found..."); @@ -15222,8 +15222,8 @@ INTERNAL_FUNC int emstorage_update_latest_thread_mail(char *multi_user_name, EM_DEBUG_LOG_SEC("query[%s]", sql_query_string); err = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (err != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", err); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", err); + goto FINISH_OFF; } } else if (thread_id != latest_mail_id) { /* Initialize the thread id */ @@ -15231,8 +15231,8 @@ INTERNAL_FUNC int emstorage_update_latest_thread_mail(char *multi_user_name, SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET thread_item_count = 0, thread_id = %d WHERE account_id = %d AND mailbox_id = %d AND thread_id = %d", latest_mail_id, account_id, mailbox_id, thread_id); err = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (err != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", err); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", err); + goto FINISH_OFF; } /* update the thread item count */ @@ -15240,8 +15240,8 @@ INTERNAL_FUNC int emstorage_update_latest_thread_mail(char *multi_user_name, SNPRINTF(sql_query_string, sizeof(sql_query_string), "UPDATE mail_tbl SET thread_item_count = %d WHERE account_id = %d AND mail_id = %d ", thread_item_count, account_id, latest_mail_id); err = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (err != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", err); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", err); + goto FINISH_OFF; } } else { memset(sql_query_string, 0, QUERY_SIZE); @@ -15249,8 +15249,8 @@ INTERNAL_FUNC int emstorage_update_latest_thread_mail(char *multi_user_name, EM_DEBUG_LOG_SEC("query[%s]", sql_query_string); err = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (err != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", err); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", err); + goto FINISH_OFF; } } ret = true; @@ -15328,9 +15328,9 @@ FINISH_OFF: #ifdef __FEATURE_LOCAL_ACTIVITY__ /** - * emstorage_add_activity - Add Email Local activity during OFFLINE mode - * - */ + * emstorage_add_activity - Add Email Local activity during OFFLINE mode + * + */ INTERNAL_FUNC int emstorage_add_activity(emstorage_activity_tbl_t* local_activity, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN(); @@ -15370,7 +15370,7 @@ INTERNAL_FUNC int emstorage_add_activity(emstorage_activity_tbl_t* local_activit EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EM_DEBUG_LOG_SEC(">>>> SQL STMT [ %s ] ", sql_query_string); @@ -15386,9 +15386,9 @@ INTERNAL_FUNC int emstorage_add_activity(emstorage_activity_tbl_t* local_activit EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d, errmsg = %s.", rc, sqlite3_errmsg(local_db_handle))); + ("sqlite3_step fail:%d, errmsg = %s.", rc, sqlite3_errmsg(local_db_handle))); ret = true; @@ -15411,10 +15411,10 @@ FINISH_OFF: } /** - * emstorage_get_activity - Get the Local activity Information - * - * - */ + * emstorage_get_activity - Get the Local activity Information + * + * + */ INTERNAL_FUNC int emstorage_get_activity(int account_id, int activityid, emstorage_activity_tbl_t** activity_list, int *select_num, int transaction, int *err_code) { EM_DEBUG_FUNC_BEGIN(); @@ -15444,9 +15444,11 @@ INTERNAL_FUNC int emstorage_get_activity(int account_id, int activityid, emstora memset(sql_query_string, 0x00, sizeof(sql_query_string)); if (activityid == ALL_ACTIVITIES) { - SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_local_activity_tbl WHERE account_id = %d order by activity_id", account_id); + SNPRINTF(sql_query_string, sizeof(sql_query_string), + "SELECT * FROM mail_local_activity_tbl WHERE account_id = %d order by activity_id", account_id); } else { - SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_local_activity_tbl WHERE account_id = %d AND activity_id = %d ", account_id, activityid); + SNPRINTF(sql_query_string, sizeof(sql_query_string), + "SELECT * FROM mail_local_activity_tbl WHERE account_id = %d AND activity_id = %d ", account_id, activityid); } EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); @@ -15455,7 +15457,7 @@ INTERNAL_FUNC int emstorage_get_activity(int account_id, int activityid, emstora EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); col_index = 7; @@ -15556,7 +15558,7 @@ INTERNAL_FUNC int emstorage_get_next_activity_id(int *activity_id, int *err_code /* rc = sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL); n EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); */ EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); if (NULL == result[1]) rc = 1; @@ -15570,7 +15572,7 @@ INTERNAL_FUNC int emstorage_get_next_activity_id(int *activity_id, int *err_code ret = true; - FINISH_OFF: +FINISH_OFF: if (err_code) *err_code = err; @@ -15612,7 +15614,7 @@ INTERNAL_FUNC int emstorage_get_activity_id_list(char *multi_user_name, int acco EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); col_index = 1; @@ -15643,9 +15645,8 @@ FINISH_OFF: EMSTORAGE_FINISH_READ_TRANSACTION(transaction); - if (err_code != NULL) { + if (err_code != NULL) *err_code = error; - } EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; @@ -15670,11 +15671,10 @@ INTERNAL_FUNC int emstorage_free_activity_id_list(int *activity_id_list, int *er ret = true; - FINISH_OFF: +FINISH_OFF: - if (NULL != error_code) { + if (NULL != error_code) *error_code = error; - } EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; @@ -15715,14 +15715,14 @@ INTERNAL_FUNC int emstorage_delete_local_activity(emstorage_activity_tbl_t* loca if (local_activity->account_id) { SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), - " WHERE account_id = %d ", local_activity->account_id); + " WHERE account_id = %d ", local_activity->account_id); query_and = 1; query_where = 1; } if (local_activity->server_mailid) { SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), - " %s %s server_mailid = '%s' ", query_where ? "" : "WHERE", query_and ? "AND" : "", local_activity->server_mailid); + " %s %s server_mailid = '%s' ", query_where ? "" : "WHERE", query_and ? "AND" : "", local_activity->server_mailid); query_and = 1; query_where = 1; } @@ -15732,7 +15732,7 @@ INTERNAL_FUNC int emstorage_delete_local_activity(emstorage_activity_tbl_t* loca EM_DEBUG_LOG(">>>> MAIL ID [ %d ] , ACTIVITY TYPE [%d ]", local_activity->mail_id, local_activity->activity_type); SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), - " %s %s mail_id = %d ", query_where ? "" : "WHERE", query_and ? "AND" : "", local_activity->mail_id); + " %s %s mail_id = %d ", query_where ? "" : "WHERE", query_and ? "AND" : "", local_activity->mail_id); query_and = 1; query_where = 1; @@ -15741,20 +15741,20 @@ INTERNAL_FUNC int emstorage_delete_local_activity(emstorage_activity_tbl_t* loca if (local_activity->activity_type > 0) { SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), - " %s %s activity_type = %d ", query_where ? "" : "WHERE", query_and ? "AND" : "" , local_activity->activity_type); + " %s %s activity_type = %d ", query_where ? "" : "WHERE", query_and ? "AND" : "" , local_activity->activity_type); } if (local_activity->activity_id > 0) { SNPRINTF(sql_query_string + EM_SAFE_STRLEN(sql_query_string), sizeof(sql_query_string)-(EM_SAFE_STRLEN(sql_query_string)+1), - " %s %s activity_id = %d ", query_where ? "" : "WHERE", query_and ? "AND" : "" , local_activity->activity_id); + " %s %s activity_id = %d ", query_where ? "" : "WHERE", query_and ? "AND" : "" , local_activity->activity_id); } EM_DEBUG_LOG_SEC(">>>>> Query [ %s ] ", sql_query_string); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } rc = sqlite3_changes(local_db_handle); @@ -15783,8 +15783,8 @@ FINISH_OFF: } /** -* emstorage_free_local_activity - Free the Local Activity data -*/ + * emstorage_free_local_activity - Free the Local Activity data + */ INTERNAL_FUNC int emstorage_free_local_activity(emstorage_activity_tbl_t **local_activity_list, int count, int *err_code) { EM_DEBUG_FUNC_BEGIN(); @@ -15823,7 +15823,7 @@ FINISH_OFF: if (err_code != NULL) *err_code = error; - EM_DEBUG_FUNC_END("ret [%d]", ret); + EM_DEBUG_FUNC_END("ret [%d]", ret); return ret; } @@ -15922,9 +15922,8 @@ static int _get_key_value_string_for_list_filter_rule(email_list_filter_rule_t * break; } - if (ret == EMAIL_ERROR_NONE && EM_SAFE_STRLEN(key_value_string) > 0) { + if (ret == EMAIL_ERROR_NONE && EM_SAFE_STRLEN(key_value_string) > 0) *output_key_value_string = strdup(key_value_string); - } FINISH_OFF: @@ -16125,7 +16124,7 @@ static int _make_filter_attach_rule_string(char *multi_user_name, email_list_fil EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); col_index = 1; @@ -16153,7 +16152,7 @@ static int _make_filter_attach_rule_string(char *multi_user_name, email_list_fil sqlite3_free_table(result); EMSTORAGE_FINISH_READ_TRANSACTION(true); -// sqlite3_db_release_memory(local_db_handle); + // sqlite3_db_release_memory(local_db_handle); query_size = (10 * count) + strlen("mail_id IN () "); @@ -16166,9 +16165,9 @@ static int _make_filter_attach_rule_string(char *multi_user_name, email_list_fil } cur_query += SNPRINTF_OFFSET(sql_query_string2, cur_query, query_size, "mail_id IN ("); - for (i = 0; i < count-1; i++) { + for (i = 0; i < count-1; i++) cur_query += SNPRINTF_OFFSET(sql_query_string2, cur_query, query_size, "%d, ", mail_ids[i]); - } + cur_query += SNPRINTF_OFFSET(sql_query_string2, cur_query, query_size, "%d) ", mail_ids[count-1]); *output_string = strdup(sql_query_string2); @@ -16229,7 +16228,7 @@ static int _make_filter_fts_rule_string(char *multi_user_name, email_list_filter EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); col_index = 1; @@ -16258,7 +16257,7 @@ static int _make_filter_fts_rule_string(char *multi_user_name, email_list_filter sqlite3_free_table(result); EMSTORAGE_FINISH_READ_TRANSACTION(true); -// sqlite3_db_release_memory(local_db_handle); + // sqlite3_db_release_memory(local_db_handle); query_size = (10 * count) + strlen("mail_id IN () "); @@ -16270,9 +16269,9 @@ static int _make_filter_fts_rule_string(char *multi_user_name, email_list_filter } int cur_query = 0; cur_query += SNPRINTF_OFFSET(sql_query_string2, cur_query, query_size, "mail_id IN ("); - for (i = 0; i < count-1; i++) { + for (i = 0; i < count-1; i++) cur_query += SNPRINTF_OFFSET(sql_query_string2, cur_query, query_size, "%d, ", mail_ids[i]); - } + cur_query += SNPRINTF_OFFSET(sql_query_string2, cur_query, query_size, "%d) ", mail_ids[count-1]); *output_string = strdup(sql_query_string2); @@ -16301,103 +16300,107 @@ static int _make_order_rule_string(char *multi_user_name, email_list_sorting_rul char query_per_account[QUERY_SIZE] = { 0 , }; if (input_sorting_rule->force_boolean_check) { - SNPRINTF(result_rule_string, QUERY_SIZE, "%s = 0 ", emcore_get_mail_field_name_by_attribute_type(input_sorting_rule->target_attribute)); - } else - EM_SAFE_STRNCPY(result_rule_string, emcore_get_mail_field_name_by_attribute_type(input_sorting_rule->target_attribute), QUERY_SIZE - EM_SAFE_STRLEN(result_rule_string) - 1 ); + SNPRINTF(result_rule_string, QUERY_SIZE, "%s = 0 ", + emcore_get_mail_field_name_by_attribute_type(input_sorting_rule->target_attribute)); + } else { + EM_SAFE_STRNCPY(result_rule_string, + emcore_get_mail_field_name_by_attribute_type(input_sorting_rule->target_attribute), + QUERY_SIZE - EM_SAFE_STRLEN(result_rule_string) - 1); + } switch (input_sorting_rule->sort_order) { - case EMAIL_SORT_ORDER_ASCEND: - EM_SAFE_STRNCAT(result_rule_string, " ASC ", QUERY_SIZE - EM_SAFE_STRLEN(result_rule_string) - 1); - break; - - case EMAIL_SORT_ORDER_DESCEND: - EM_SAFE_STRNCAT(result_rule_string, " DESC ", QUERY_SIZE - EM_SAFE_STRLEN(result_rule_string) - 1); - break; - - case EMAIL_SORT_ORDER_NOCASE_ASCEND: - EM_SAFE_STRNCAT(result_rule_string, " COLLATE NOCASE ASC ", QUERY_SIZE - EM_SAFE_STRLEN(result_rule_string) - 1); - break; + case EMAIL_SORT_ORDER_ASCEND: + EM_SAFE_STRNCAT(result_rule_string, " ASC ", QUERY_SIZE - EM_SAFE_STRLEN(result_rule_string) - 1); + break; - case EMAIL_SORT_ORDER_NOCASE_DESCEND: - EM_SAFE_STRNCAT(result_rule_string, " COLLATE NOCASE DESC ", QUERY_SIZE - EM_SAFE_STRLEN(result_rule_string) - 1); - break; + case EMAIL_SORT_ORDER_DESCEND: + EM_SAFE_STRNCAT(result_rule_string, " DESC ", QUERY_SIZE - EM_SAFE_STRLEN(result_rule_string) - 1); + break; - case EMAIL_SORT_ORDER_TO_CCBCC: - memset(result_rule_string, 0, QUERY_SIZE); - if (input_sorting_rule->key_value.string_type_value) - sqlite3_snprintf(QUERY_SIZE, result_rule_string, - " CASE WHEN full_address_to LIKE \'%%%q%%\' THEN 1 ELSE 2 END ", - input_sorting_rule->key_value.string_type_value); - break; + case EMAIL_SORT_ORDER_NOCASE_ASCEND: + EM_SAFE_STRNCAT(result_rule_string, " COLLATE NOCASE ASC ", QUERY_SIZE - EM_SAFE_STRLEN(result_rule_string) - 1); + break; - case EMAIL_SORT_ORDER_TO_CC_BCC: - memset(result_rule_string, 0, QUERY_SIZE); - if (input_sorting_rule->key_value.string_type_value) - sqlite3_snprintf(QUERY_SIZE, result_rule_string, - " CASE WHEN full_address_to LIKE \'%%%q%%\' THEN 1 WHEN full_address_cc LIKE \'%%%q%%\' THEN 2 ELSE 3 END ", - input_sorting_rule->key_value.string_type_value, input_sorting_rule->key_value.string_type_value); - break; + case EMAIL_SORT_ORDER_NOCASE_DESCEND: + EM_SAFE_STRNCAT(result_rule_string, " COLLATE NOCASE DESC ", QUERY_SIZE - EM_SAFE_STRLEN(result_rule_string) - 1); + break; - case EMAIL_SORT_ORDER_TO_CCBCC_ALL: - if (!emstorage_get_account_list(multi_user_name, &count, &account_tbl_array, true, false, NULL)) { - EM_DEBUG_EXCEPTION("emstorage_get_account_list failed"); - goto FINISH_OFF; - } + case EMAIL_SORT_ORDER_TO_CCBCC: + memset(result_rule_string, 0, QUERY_SIZE); + if (input_sorting_rule->key_value.string_type_value) + sqlite3_snprintf(QUERY_SIZE, result_rule_string, + " CASE WHEN full_address_to LIKE \'%%%q%%\' THEN 1 ELSE 2 END ", + input_sorting_rule->key_value.string_type_value); + break; - if (!count) { - EM_DEBUG_LOG("No account exist"); - ret = EMAIL_ERROR_INVALID_PARAM; - goto FINISH_OFF; - } + case EMAIL_SORT_ORDER_TO_CC_BCC: + memset(result_rule_string, 0, QUERY_SIZE); + if (input_sorting_rule->key_value.string_type_value) + sqlite3_snprintf(QUERY_SIZE, result_rule_string, + " CASE WHEN full_address_to LIKE \'%%%q%%\' THEN 1 WHEN full_address_cc LIKE \'%%%q%%\' THEN 2 ELSE 3 END ", + input_sorting_rule->key_value.string_type_value, input_sorting_rule->key_value.string_type_value); + break; - for (i = 0; i < count; i++) { - if (i > 0 && result_str) { - tmp_str2 = result_str; - result_str = g_strconcat(tmp_str2, " OR ", NULL); - EM_SAFE_FREE(tmp_str2); - } + case EMAIL_SORT_ORDER_TO_CCBCC_ALL: + if (!emstorage_get_account_list(multi_user_name, &count, &account_tbl_array, true, false, NULL)) { + EM_DEBUG_EXCEPTION("emstorage_get_account_list failed"); + goto FINISH_OFF; + } - memset(query_per_account, 0, QUERY_SIZE); - snprintf(query_per_account, QUERY_SIZE, - "(account_id = %d AND full_address_to LIKE \'%%%s%%\')", - account_tbl_array[i].account_id, account_tbl_array[i].user_email_address); + if (!count) { + EM_DEBUG_LOG("No account exist"); + ret = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; + } - tmp_str1 = result_str; - if (tmp_str1) - result_str = g_strconcat(tmp_str1, query_per_account, NULL); - else - result_str = g_strdup(query_per_account); - EM_SAFE_FREE(tmp_str1); + for (i = 0; i < count; i++) { + if (i > 0 && result_str) { + tmp_str2 = result_str; + result_str = g_strconcat(tmp_str2, " OR ", NULL); + EM_SAFE_FREE(tmp_str2); } - snprintf(result_rule_string, QUERY_SIZE, - " CASE WHEN %s THEN 1 ELSE 2 END ", result_str); + memset(query_per_account, 0, QUERY_SIZE); + snprintf(query_per_account, QUERY_SIZE, + "(account_id = %d AND full_address_to LIKE \'%%%s%%\')", + account_tbl_array[i].account_id, account_tbl_array[i].user_email_address); + + tmp_str1 = result_str; + if (tmp_str1) + result_str = g_strconcat(tmp_str1, query_per_account, NULL); + else + result_str = g_strdup(query_per_account); + EM_SAFE_FREE(tmp_str1); + } - EM_SAFE_FREE(result_str); - if (account_tbl_array) - emstorage_free_account(&account_tbl_array, count, NULL); - break; + snprintf(result_rule_string, QUERY_SIZE, + " CASE WHEN %s THEN 1 ELSE 2 END ", result_str); - case EMAIL_SORT_ORDER_LOCALIZE_ASCEND: - memset(result_rule_string, 0, QUERY_SIZE); - sqlite3_snprintf(QUERY_SIZE, result_rule_string, + EM_SAFE_FREE(result_str); + if (account_tbl_array) + emstorage_free_account(&account_tbl_array, count, NULL); + break; + + case EMAIL_SORT_ORDER_LOCALIZE_ASCEND: + memset(result_rule_string, 0, QUERY_SIZE); + sqlite3_snprintf(QUERY_SIZE, result_rule_string, " CASE WHEN %s GLOB \'[][~`!@#$%%^&*()_-+=|\\{}:;<>,.?/ ]*\' THEN 1 ELSE 2 END ASC, %s COLLATE NOCASE ASC ", emcore_get_mail_field_name_by_attribute_type(input_sorting_rule->target_attribute), emcore_get_mail_field_name_by_attribute_type(input_sorting_rule->target_attribute)); - break; + break; - case EMAIL_SORT_ORDER_LOCALIZE_DESCEND: - memset(result_rule_string, 0, QUERY_SIZE); - sqlite3_snprintf(QUERY_SIZE, result_rule_string, + case EMAIL_SORT_ORDER_LOCALIZE_DESCEND: + memset(result_rule_string, 0, QUERY_SIZE); + sqlite3_snprintf(QUERY_SIZE, result_rule_string, " CASE WHEN %s GLOB \'[][~`!@#$%%^&*()_-+=|\\{}:;<>,.?/ ]*\' THEN 1 ELSE 2 END DESC, %s COLLATE NOCASE DESC ", emcore_get_mail_field_name_by_attribute_type(input_sorting_rule->target_attribute), emcore_get_mail_field_name_by_attribute_type(input_sorting_rule->target_attribute)); - break; + break; - default: - EM_DEBUG_EXCEPTION("Invalid sort_order [%d]", input_sorting_rule->sort_order); - ret = EMAIL_ERROR_INVALID_PARAM; - goto FINISH_OFF; + default: + EM_DEBUG_EXCEPTION("Invalid sort_order [%d]", input_sorting_rule->sort_order); + ret = EMAIL_ERROR_INVALID_PARAM; + goto FINISH_OFF; } *output_string = strdup(result_rule_string); @@ -16539,9 +16542,8 @@ INTERNAL_FUNC int emstorage_free_list_filter(email_list_filter_t **input_filter_ for (i = 0; i < input_filter_count; i++) { temp_filter_list = (*input_filter_list) + i; - if (!temp_filter_list) { + if (!temp_filter_list) continue; - } if (temp_filter_list->list_filter_item_type == EMAIL_LIST_FILTER_ITEM_RULE) { switch (temp_filter_list->list_filter_item.rule.target_attribute) { @@ -16563,9 +16565,9 @@ INTERNAL_FUNC int emstorage_free_list_filter(email_list_filter_t **input_filter_ break; } } else if (temp_filter_list->list_filter_item_type == EMAIL_LIST_FILTER_ITEM_RULE_FTS && temp_filter_list->list_filter_item.rule_fts.target_attribute == EMAIL_MAIL_TEXT_ATTRIBUTE_FULL_TEXT) { - EM_SAFE_FREE(temp_filter_list->list_filter_item.rule_fts.key_value.string_type_value); + EM_SAFE_FREE(temp_filter_list->list_filter_item.rule_fts.key_value.string_type_value); } else if (temp_filter_list->list_filter_item_type == EMAIL_LIST_FILTER_ITEM_RULE_ATTACH && temp_filter_list->list_filter_item.rule_attach.target_attribute == EMAIL_MAIL_ATTACH_ATTRIBUTE_ATTACHMENT_NAME) { - EM_SAFE_FREE(temp_filter_list->list_filter_item.rule_attach.key_value.string_type_value); + EM_SAFE_FREE(temp_filter_list->list_filter_item.rule_attach.key_value.string_type_value); } } @@ -16600,7 +16602,7 @@ INTERNAL_FUNC int emstorage_add_task(char *multi_user_name, email_task_type_t in EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); if (NULL == result[1]) task_id = 1; @@ -16613,20 +16615,20 @@ INTERNAL_FUNC int emstorage_add_task(char *multi_user_name, email_task_type_t in result = NULL; SNPRINTF(sql_query_string, sizeof(sql_query_string), - "INSERT INTO mail_task_tbl VALUES " - "( " - " ? " /* task_id */ - " , ? " /* task_type */ - " , ? " /* task_status */ - " , ? " /* task_priority */ - " , ? " /* task_parameter_length */ - " , ? " /* task_parameter */ - " , ? " /* date_time */ - ") "); + "INSERT INTO mail_task_tbl VALUES " + "( " + " ? " /* task_id */ + " , ? " /* task_type */ + " , ? " /* task_status */ + " , ? " /* task_priority */ + " , ? " /* task_parameter_length */ + " , ? " /* task_parameter */ + " , ? " /* date_time */ + ") "); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {err = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EM_DEBUG_LOG_SEC(">>>> SQL STMT [%s] ", sql_query_string); @@ -16642,9 +16644,9 @@ INTERNAL_FUNC int emstorage_add_task(char *multi_user_name, email_task_type_t in EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {err = EMAIL_ERROR_MAIL_MEMORY_FULL; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {err = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d, errmsg = %s.", rc, sqlite3_errmsg(local_db_handle))); + ("sqlite3_step fail:%d, errmsg = %s.", rc, sqlite3_errmsg(local_db_handle))); ret = (err == EMAIL_ERROR_NONE); @@ -16684,8 +16686,8 @@ INTERNAL_FUNC int emstorage_delete_task(char *multi_user_name, int task_id, int SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_task_tbl WHERE task_id = %d", task_id); err = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (err != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", err); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", err); + goto FINISH_OFF; } ret = true; @@ -16708,15 +16710,15 @@ INTERNAL_FUNC int emstorage_update_task_status(char *multi_user_name, int task_i EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, err); SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_task_tbl SET" - " task_status = %d" - " WHERE task_id = %d" - , task_status - , task_id); + "UPDATE mail_task_tbl SET" + " task_status = %d" + " WHERE task_id = %d" + , task_status + , task_id); err = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (err != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", err); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", err); + goto FINISH_OFF; } ret = true; @@ -16729,14 +16731,14 @@ FINISH_OFF: } INTERNAL_FUNC int emstorage_query_task(char *multi_user_name, - const char *input_conditional_clause, - const char *input_ordering_clause, - email_task_t **output_task_list, - int *output_task_count) + const char *input_conditional_clause, + const char *input_ordering_clause, + email_task_t **output_task_list, + int *output_task_count) { EM_DEBUG_FUNC_BEGIN("input_conditional_clause[%p], input_ordering_clause [%p], " - "output_task_list[%p], output_task_count[%d]", - input_conditional_clause, input_ordering_clause, output_task_list, output_task_count); + "output_task_list[%p], output_task_count[%d]", + input_conditional_clause, input_ordering_clause, output_task_list, output_task_count); int i = 0, count = 0, rc = -1; int cur_query = 0; int field_index = 0; @@ -16754,12 +16756,12 @@ INTERNAL_FUNC int emstorage_query_task(char *multi_user_name, local_db_handle = emstorage_get_db_connection(multi_user_name); SNPRINTF_OFFSET(sql_query_string, cur_query, QUERY_SIZE, - "SELECT COUNT(*) FROM mail_task_tbl %s", input_conditional_clause); + "SELECT COUNT(*) FROM mail_task_tbl %s", input_conditional_clause); EM_DEBUG_LOG_SEC("emstorage_query_mail_list : query[%s].", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {err = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); count = atoi(result[1]); sqlite3_free_table(result); @@ -16773,18 +16775,18 @@ INTERNAL_FUNC int emstorage_query_task(char *multi_user_name, } SNPRINTF_OFFSET(sql_query_string, cur_query, QUERY_SIZE, - "SELECT %s FROM mail_task_tbl %s %s", field_list, input_conditional_clause, input_ordering_clause); + "SELECT %s FROM mail_task_tbl %s %s", field_list, input_conditional_clause, input_ordering_clause); EM_DEBUG_LOG_SEC("emstorage_query_mail_list : query[%s].", sql_query_string); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG("After sqlite3_prepare_v2 hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {err = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {err = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); if (rc == SQLITE_DONE) { EM_DEBUG_EXCEPTION("no task found..."); @@ -16813,7 +16815,7 @@ INTERNAL_FUNC int emstorage_query_task(char *multi_user_name, EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_LOG("after sqlite3_step(), i = %d, rc = %d.", i, rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {err = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); } FINISH_OFF: @@ -16884,12 +16886,12 @@ INTERNAL_FUNC int emstorage_check_and_update_server_uid_by_message_id(char *mult EM_DEBUG_LOG_SEC("query[%s]", sql_query_string); - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc); - EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {err = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, &count, 0, NULL), rc); + EM_DEBUG_DB_EXEC((SQLITE_OK != rc && -1 != rc), {err = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); - EM_DEBUG_LOG("Count of mails [%d]", count); + EM_DEBUG_LOG("Count of mails [%d]", count); if (count) { _get_table_field_data_int(result, &temp_mail_id, 1); @@ -16898,8 +16900,10 @@ INTERNAL_FUNC int emstorage_check_and_update_server_uid_by_message_id(char *mult memset(sql_query_string, 0x00, QUERY_SIZE); sqlite3_snprintf(sizeof(sql_query_string), sql_query_string, "UPDATE mail_tbl set server_mail_id = '%q'", server_uid); - if (strlen(sql_query_string) + strlen(where_pararaph) < QUERY_SIZE) - EM_SAFE_STRNCAT(sql_query_string, where_pararaph ,QUERY_SIZE - EM_SAFE_STRLEN(sql_query_string) -1 ); + if (strlen(sql_query_string) + strlen(where_pararaph) < QUERY_SIZE) { + EM_SAFE_STRNCAT(sql_query_string, where_pararaph, + QUERY_SIZE - EM_SAFE_STRLEN(sql_query_string) - 1); + } err = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (err != EMAIL_ERROR_NONE) { @@ -16952,16 +16956,16 @@ INTERNAL_FUNC int emstorage_add_auto_download_activity(char *multi_user_name, em memset(sql_query_string, 0x00, sizeof(sql_query_string)); SNPRINTF(sql_query_string, sizeof(sql_query_string), - "INSERT INTO mail_auto_download_activity_tbl VALUES " - "(" - "? " /* Activity ID */ - ",?" /* Status */ - ",?" /* Account ID */ - ",?" /* Local Mail ID */ - ",?" /* Server mail ID */ - ",?" /* Mailbox ID*/ - ",?" /* Multi USER NAME */ - ") "); + "INSERT INTO mail_auto_download_activity_tbl VALUES " + "(" + "? " /* Activity ID */ + ",?" /* Status */ + ",?" /* Account ID */ + ",?" /* Local Mail ID */ + ",?" /* Server mail ID */ + ",?" /* Mailbox ID*/ + ",?" /* Multi USER NAME */ + ") "); char *sql = "SELECT max(rowid) FROM mail_auto_download_activity_tbl;"; char **result = NULL; @@ -16970,7 +16974,7 @@ INTERNAL_FUNC int emstorage_add_auto_download_activity(char *multi_user_name, em EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); if (NULL == result[1]) rc = 1; else rc = atoi(result[1])+1; @@ -16988,7 +16992,7 @@ INTERNAL_FUNC int emstorage_add_auto_download_activity(char *multi_user_name, em EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); _bind_stmt_field_data_int(hStmt, i++, local_activity->activity_id); @@ -17003,9 +17007,9 @@ INTERNAL_FUNC int emstorage_add_auto_download_activity(char *multi_user_name, em EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d, errmsg = %s.", rc, sqlite3_errmsg(local_db_handle))); + ("sqlite3_step fail:%d, errmsg = %s.", rc, sqlite3_errmsg(local_db_handle))); ret = true; @@ -17107,8 +17111,8 @@ INTERNAL_FUNC int emstorage_delete_all_auto_download_activity(char *multi_user_n EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } rc = sqlite3_changes(local_db_handle); @@ -17157,8 +17161,8 @@ INTERNAL_FUNC int emstorage_delete_auto_download_activity_by_mailbox(char *multi EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } rc = sqlite3_changes(local_db_handle); @@ -17213,7 +17217,7 @@ INTERNAL_FUNC int emstorage_get_auto_download_activity(char *multi_user_name, in EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); *count = atoi(result[1]); sqlite3_free_table(result); @@ -17238,12 +17242,12 @@ INTERNAL_FUNC int emstorage_get_auto_download_activity(char *multi_user_name, in EM_DEBUG_LOG(" Bbefore sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); if (!(event_list = (email_event_auto_download *)em_malloc(sizeof(email_event_auto_download)*(*count)))) { EM_DEBUG_EXCEPTION("Malloc failed"); @@ -17262,7 +17266,7 @@ INTERNAL_FUNC int emstorage_get_auto_download_activity(char *multi_user_name, in EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); } ret = true; @@ -17270,7 +17274,7 @@ INTERNAL_FUNC int emstorage_get_auto_download_activity(char *multi_user_name, in FINISH_OFF: if (true == ret) - *event_start = event_list; + *event_start = event_list; else { EM_SAFE_FREE(event_list); *event_start = NULL; @@ -17325,12 +17329,12 @@ INTERNAL_FUNC int emstorage_get_auto_download_activity_count(char *multi_user_na EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG_DEV("before sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); _get_stmt_field_data_int(hStmt, activity_count, 0); @@ -17383,7 +17387,7 @@ INTERNAL_FUNC int emstorage_get_auto_download_account_list(char *multi_user_name EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle))); *count = atoi(result[1]); sqlite3_free_table(result); @@ -17408,12 +17412,12 @@ INTERNAL_FUNC int emstorage_get_auto_download_account_list(char *multi_user_name EM_DEBUG_LOG("Before sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); if (NULL == (result_account_list = (int *)em_malloc(sizeof(int)*(*count)))) { EM_DEBUG_EXCEPTION(" em_mallocfailed..."); @@ -17426,7 +17430,7 @@ INTERNAL_FUNC int emstorage_get_auto_download_account_list(char *multi_user_name EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); EM_DEBUG_LOG("account id -> %d", result_account_list[i]); } @@ -17485,7 +17489,7 @@ INTERNAL_FUNC int emstorage_get_auto_download_mailbox_list(char *multi_user_name EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql_query_string, &result, NULL, NULL, NULL), rc); EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE; sqlite3_free_table(result); goto FINISH_OFF; }, - ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_get_table fail:%d -%s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); *count = atoi(result[1]); sqlite3_free_table(result); @@ -17509,12 +17513,12 @@ INTERNAL_FUNC int emstorage_get_auto_download_mailbox_list(char *multi_user_name EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); mbox_list = (int *)em_malloc(sizeof(int)*(*count)); /* prevent */ if (mbox_list == NULL) { @@ -17528,7 +17532,7 @@ INTERNAL_FUNC int emstorage_get_auto_download_mailbox_list(char *multi_user_name EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); EM_DEBUG_LOG("mbox_list %d", mbox_list[i]); } @@ -17586,11 +17590,11 @@ INTERNAL_FUNC int emstorage_get_auto_download_activity_count_by_mailbox(char *mu EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc); EM_DEBUG_LOG("before sqlite3_prepare hStmt = %p", hStmt); EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); + ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle))); EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc); EM_DEBUG_DB_EXEC((rc != SQLITE_ROW), {error = EMAIL_ERROR_DB_FAILURE; goto FINISH_OFF; }, - ("sqlite3_step fail:%d", rc)); + ("sqlite3_step fail:%d", rc)); _get_stmt_field_data_int(hStmt, activity_count, 0); @@ -17641,22 +17645,21 @@ INTERNAL_FUNC int emstorage_update_auto_download_activity(char *multi_user_name, if (mailbox_id > 0) SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_auto_download_activity_tbl SET server_mail_id = %s , mailbox_id ='%d' WHERE server_mail_id = %s ", new_server_uid, mailbox_id, old_server_uid); + "UPDATE mail_auto_download_activity_tbl SET server_mail_id = %s , mailbox_id ='%d' WHERE server_mail_id = %s ", new_server_uid, mailbox_id, old_server_uid); else if (mailbox_name) SNPRINTF(sql_query_string, sizeof(sql_query_string), - "UPDATE mail_auto_download_activity_tbl SET server_mail_id = %s WHERE server_mail_id = %s ", new_server_uid, old_server_uid); + "UPDATE mail_auto_download_activity_tbl SET server_mail_id = %s WHERE server_mail_id = %s ", new_server_uid, old_server_uid); EM_DEBUG_LOG_SEC("Query [%s]", sql_query_string); error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string); if (error != EMAIL_ERROR_NONE) { - EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); - goto FINISH_OFF; + EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error); + goto FINISH_OFF; } rc = sqlite3_changes(local_db_handle); - if (rc == 0) { + if (rc == 0) EM_DEBUG_LOG("No matching found in mail_auto_download_activity_tbl"); - } ret = true; @@ -17710,10 +17713,10 @@ static int get_column_information_from_table_callback(void *arg1, int argc, char if (validated) { EM_DEBUG_LOG("column_name[%s] column_type[%s]", column_name, column_type); column_info_item = em_malloc(sizeof(email_column_info_t)); - if (column_info_item == NULL) { - EM_DEBUG_EXCEPTION("em_mallocfailed"); - goto FINISH_OFF; - } + if (column_info_item == NULL) { + EM_DEBUG_EXCEPTION("em_mallocfailed"); + goto FINISH_OFF; + } column_info_item->column_name = EM_SAFE_STRDUP(column_name); column_info_item->column_type = EM_SAFE_STRDUP(column_type); @@ -17723,8 +17726,8 @@ static int get_column_information_from_table_callback(void *arg1, int argc, char FINISH_OFF: - EM_SAFE_FREE(column_name); - EM_SAFE_FREE(column_type); + EM_SAFE_FREE(column_name); + EM_SAFE_FREE(column_type); EM_DEBUG_FUNC_END(); return 0; @@ -17786,9 +17789,11 @@ static int emstorage_create_renamed_table(char *multi_user_name, char **input_f FINISH_OFF: if (error == EMAIL_ERROR_NONE) { - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL( + sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); } else { - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "rollback", NULL, NULL, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL( + sqlite3_exec(local_db_handle, "rollback", NULL, NULL, NULL), rc); } EM_DEBUG_FUNC_END("error [%d]", error); @@ -17818,9 +17823,11 @@ static int emstorage_add_column(char *multi_user_name, char *input_table_name, e FINISH_OFF: if (error == EMAIL_ERROR_NONE) { - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL( + sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); } else { - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "rollback", NULL, NULL, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL( + sqlite3_exec(local_db_handle, "rollback", NULL, NULL, NULL), rc); } EM_DEBUG_FUNC_END("error [%d]", error); @@ -17850,9 +17857,11 @@ static int emstorage_drop_table(char *multi_user_name, char *input_table_name) FINISH_OFF: if (error == EMAIL_ERROR_NONE) { - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL( + sqlite3_exec(local_db_handle, "END;", NULL, NULL, NULL), rc); } else { - EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_exec(local_db_handle, "rollback", NULL, NULL, NULL), rc); + EMSTORAGE_PROTECTED_FUNC_CALL( + sqlite3_exec(local_db_handle, "rollback", NULL, NULL, NULL), rc); } EM_DEBUG_FUNC_END("error [%d]", error); @@ -17955,17 +17964,17 @@ INTERNAL_FUNC int emstorage_update_db_table_schema(char *multi_user_name) } emstorage_drop_table(multi_user_name, table_names[i][1]); - } else + } else { EM_DEBUG_LOG("Skipped"); + } } FINISH_OFF: if (create_table_query) { int i = 0; for (i = 0; i < query_len; i++) { - if (create_table_query[i]) { + if (create_table_query[i]) EM_SAFE_FREE(create_table_query[i]); - } } EM_SAFE_FREE(create_table_query); } diff --git a/test/testapp-account.c b/test/testapp-account.c index 7faa9de..384361f 100644 --- a/test/testapp-account.c +++ b/test/testapp-account.c @@ -1,23 +1,23 @@ /* -* email-service -* -* Copyright(c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. -* -* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> -* -* Licensed under the Apache License, Version 2.0(the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* -*/ + * email-service + * + * Copyright(c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> + * + * Licensed under the Apache License, Version 2.0(the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ /* common header */ #include <stdio.h> @@ -42,8 +42,8 @@ /* internal defines */ -#define GWB_RECV_SERVER_ADDR "pop.gawab.com" -#define GWB_SMTP_SERVER_ADDR "smtp.gawab.com" +#define GWB_RECV_SERVER_ADDR "pop.gawab.com" +#define GWB_SMTP_SERVER_ADDR "smtp.gawab.com" #define VDF_RECV_SERVER_ADDR "imap.email.vodafone.de" #define VDF_SMTP_SERVER_ADDR "smtp.email.vodafone.de" @@ -89,46 +89,46 @@ gboolean testapp_create_account_object(email_account_t **result_account) testapp_print("Invalid input. "); switch (account_type) { - case 4: - case 5: - do { - testapp_print("Enter your account index [1~10] : "); - if (0 >= scanf("%d", &samsung3g_account_index)) - testapp_print("Invalid input. "); - } while (samsung3g_account_index > 10 || samsung3g_account_index < 1); - sprintf(id_string, "test%02d", samsung3g_account_index); - sprintf(address_string, "test%02d@streaming.s3glab.net", samsung3g_account_index); - sprintf(password_string, "test%02d", samsung3g_account_index); - break; - case 14: - testapp_print("Enter email address : "); - if (0 >= scanf("%s", address_string)) - testapp_print("Invalid input. "); - strcpy(id_string, address_string); - - testapp_print("Enter access token : "); - if (0 >= scanf("%s", accesss_token)) - testapp_print("Invalid input. "); - - testapp_print("Enter refresh token : "); - if (0 >= scanf("%s", refresh_token)) - testapp_print("Invalid input. "); - - snprintf(password_string, 100, "%s\001%s\001", accesss_token, refresh_token); - break; - default: - testapp_print("Enter email address : "); - if (0 >= scanf("%s", address_string)) - testapp_print("Invalid input. "); - - testapp_print("Enter id : "); - if (0 >= scanf("%s", id_string)) + case 4: + case 5: + do { + testapp_print("Enter your account index [1~10] : "); + if (0 >= scanf("%d", &samsung3g_account_index)) testapp_print("Invalid input. "); - - testapp_print("Enter password_string : "); - if (0 >= scanf("%s", password_string)) - testapp_print("Invalid input. "); - break; + } while (samsung3g_account_index > 10 || samsung3g_account_index < 1); + sprintf(id_string, "test%02d", samsung3g_account_index); + sprintf(address_string, "test%02d@streaming.s3glab.net", samsung3g_account_index); + sprintf(password_string, "test%02d", samsung3g_account_index); + break; + case 14: + testapp_print("Enter email address : "); + if (0 >= scanf("%s", address_string)) + testapp_print("Invalid input. "); + strcpy(id_string, address_string); + + testapp_print("Enter access token : "); + if (0 >= scanf("%s", accesss_token)) + testapp_print("Invalid input. "); + + testapp_print("Enter refresh token : "); + if (0 >= scanf("%s", refresh_token)) + testapp_print("Invalid input. "); + + snprintf(password_string, 100, "%s\001%s\001", accesss_token, refresh_token); + break; + default: + testapp_print("Enter email address : "); + if (0 >= scanf("%s", address_string)) + testapp_print("Invalid input. "); + + testapp_print("Enter id : "); + if (0 >= scanf("%s", id_string)) + testapp_print("Invalid input. "); + + testapp_print("Enter password_string : "); + if (0 >= scanf("%s", password_string)) + testapp_print("Invalid input. "); + break; } account = malloc(sizeof(email_account_t)); @@ -193,178 +193,179 @@ gboolean testapp_create_account_object(email_account_t **result_account) account->outgoing_server_password = strdup(password_string); switch (account_type) { - case 1:/* gawab */ - account->incoming_server_type = EMAIL_SERVER_TYPE_POP3 ; - account->incoming_server_address = strdup(GWB_RECV_SERVER_ADDR); - account->incoming_server_port_number = EMAIL_POP3S_PORT; - account->outgoing_server_address = strdup(GWB_SMTP_SERVER_ADDR); - account->incoming_server_secure_connection = 1; - account->outgoing_server_need_authentication = 1; - account->outgoing_server_port_number = EMAIL_SMTPS_PORT; - account->outgoing_server_secure_connection = 1; - - break; - - case 2:/* vadofone */ - account->incoming_server_type = EMAIL_SERVER_TYPE_IMAP4; - account->incoming_server_address = strdup(VDF_RECV_SERVER_ADDR); - account->incoming_server_port_number = EMAIL_IMAP_PORT; - account->outgoing_server_address = strdup(VDF_SMTP_SERVER_ADDR); - account->incoming_server_secure_connection = 0; - account->outgoing_server_need_authentication = 0; - break; - - case 4:/* SAMSUNG 3G TEST */ - account->incoming_server_type = EMAIL_SERVER_TYPE_POP3; - account->incoming_server_address = strdup(S3G_RECV_SERVER_ADDR); - account->incoming_server_port_number = S3G_RECV_SERVER_PORT; - account->outgoing_server_address = strdup(S3G_SMTP_SERVER_ADDR); - account->outgoing_server_port_number = S3G_SMTP_SERVER_PORT; - account->incoming_server_secure_connection = S3G_RECV_USE_SECURITY; - account->outgoing_server_secure_connection = S3G_SMTP_USE_SECURITY; - account->outgoing_server_need_authentication = S3G_SMTP_AUTH; - break; - - case 5:/* SAMSUNG 3G TEST */ - account->incoming_server_type = EMAIL_SERVER_TYPE_IMAP4; - account->incoming_server_address = strdup(S3G_RECV_SERVER_ADDR); - account->incoming_server_port_number = EMAIL_IMAPS_PORT; - account->outgoing_server_address = strdup(S3G_SMTP_SERVER_ADDR); - account->outgoing_server_port_number = S3G_SMTP_SERVER_PORT; - account->incoming_server_secure_connection = 1; - account->outgoing_server_secure_connection = S3G_SMTP_USE_SECURITY; - account->outgoing_server_need_authentication = S3G_SMTP_AUTH; - break; - - case 6:/* Gmail POP3 */ - account->incoming_server_type = EMAIL_SERVER_TYPE_POP3; - account->incoming_server_address = strdup("pop.gmail.com"); - account->incoming_server_port_number = 995; - account->incoming_server_secure_connection = 1; - account->outgoing_server_address = strdup("smtp.gmail.com"); - account->outgoing_server_port_number = 465; - account->outgoing_server_secure_connection = 1; - account->outgoing_server_need_authentication = 1; - break; - - case 7: /* Gmail IMAP4 */ - account->incoming_server_type = EMAIL_SERVER_TYPE_IMAP4; - account->incoming_server_address = strdup("imap.gmail.com"); - account->incoming_server_port_number = 993; - account->incoming_server_secure_connection = 1; - account->outgoing_server_address = strdup("smtp.gmail.com"); - account->outgoing_server_port_number = 465; - account->outgoing_server_secure_connection = 1; - account->outgoing_server_need_authentication = EMAIL_AUTHENTICATION_METHOD_DEFAULT; - account->incoming_server_authentication_method = EMAIL_AUTHENTICATION_METHOD_NO_AUTH; - break; - - case 8: /* Active Sync */ - account->incoming_server_type = EMAIL_SERVER_TYPE_ACTIVE_SYNC; - account->incoming_server_address = strdup(""); - account->incoming_server_port_number = 0; - account->incoming_server_secure_connection = 1; - account->outgoing_server_address = strdup(""); - account->outgoing_server_port_number = 0; - account->outgoing_server_secure_connection = 1; - account->outgoing_server_need_authentication = 1; - break; - - case 9: /* AOL */ - account->incoming_server_type = EMAIL_SERVER_TYPE_IMAP4; - account->incoming_server_address = strdup("imap.aol.com"); - account->incoming_server_port_number = 143; - account->incoming_server_secure_connection = 0; - account->outgoing_server_address = strdup("smtp.aol.com"); - account->outgoing_server_port_number = 587; - account->outgoing_server_secure_connection = 0; - account->outgoing_server_need_authentication = 1; - break; - - case 10: /* Hotmail */ - account->incoming_server_type = EMAIL_SERVER_TYPE_POP3; - account->incoming_server_address = strdup("pop3.live.com"); - account->incoming_server_port_number = 995; - account->incoming_server_secure_connection = 1; - account->outgoing_server_address = strdup("smtp.live.com"); - account->outgoing_server_port_number = 587; - account->outgoing_server_secure_connection = 0x02; - account->outgoing_server_need_authentication = 1; - break; - - case 11:/* Daum IMAP4*/ - account->incoming_server_type = EMAIL_SERVER_TYPE_IMAP4; - account->incoming_server_address = strdup("imap.daum.net"); - account->incoming_server_port_number = 993; - account->incoming_server_secure_connection = 1; - account->outgoing_server_address = strdup("smtp.daum.net"); - account->outgoing_server_port_number = 465; - account->outgoing_server_secure_connection = 1; - account->outgoing_server_need_authentication = 1; - break; - - case 12:/* Daum POP3*/ - account->incoming_server_type = EMAIL_SERVER_TYPE_POP3; - account->incoming_server_address = strdup("pop.daum.net"); - account->incoming_server_port_number = 995; - account->incoming_server_secure_connection = 1; - account->outgoing_server_address = strdup("smtp.daum.net"); - account->outgoing_server_port_number = 465; - account->outgoing_server_secure_connection = 1; - account->outgoing_server_need_authentication = 1; - break; - - case 13: /* Yahoo IMAP ID */ - account->incoming_server_type = EMAIL_SERVER_TYPE_IMAP4; - account->incoming_server_address = strdup("samsung.imap.mail.yahoo.com"); - account->incoming_server_port_number = 993; - account->incoming_server_secure_connection = 1; - account->outgoing_server_address = strdup("samsung.smtp.mail.yahoo.com"); - account->outgoing_server_port_number = 465; - account->outgoing_server_secure_connection = 1; - account->outgoing_server_need_authentication = 1; - break; - - case 14: /* XOAUTH */ - account->incoming_server_type = EMAIL_SERVER_TYPE_IMAP4; - account->incoming_server_address = strdup("imap.gmail.com"); - account->incoming_server_port_number = 993; - account->incoming_server_secure_connection = 1; - account->outgoing_server_address = strdup("smtp.gmail.com"); - account->outgoing_server_port_number = 465; - account->outgoing_server_secure_connection = 1; - account->outgoing_server_need_authentication = EMAIL_AUTHENTICATION_METHOD_XOAUTH2; - account->incoming_server_authentication_method = EMAIL_AUTHENTICATION_METHOD_XOAUTH2; - break; - - case 15: /* yandex */ - account->incoming_server_type = EMAIL_SERVER_TYPE_IMAP4; - account->incoming_server_address = strdup("imap.yandex.ru"); - account->incoming_server_port_number = 993; - account->incoming_server_secure_connection = 1; - account->outgoing_server_address = strdup("smtp.yandex.ru"); - account->outgoing_server_port_number = 465; - account->outgoing_server_secure_connection = 1; - account->outgoing_server_need_authentication = EMAIL_AUTHENTICATION_METHOD_DEFAULT; - account->incoming_server_authentication_method = EMAIL_AUTHENTICATION_METHOD_DEFAULT; - break; - - case 16: /* mopera */ - account->incoming_server_type = EMAIL_SERVER_TYPE_POP3; - account->incoming_server_address = strdup("mail.mopera.net"); - account->incoming_server_port_number = 110; - account->incoming_server_secure_connection = 0; - account->incoming_server_authentication_method = EMAIL_AUTHENTICATION_METHOD_NO_AUTH; - account->outgoing_server_address = strdup("mail.mopera.net"); - account->outgoing_server_port_number = 465; - account->outgoing_server_secure_connection = 0; - account->outgoing_server_need_authentication = EMAIL_AUTHENTICATION_METHOD_DEFAULT; - break; - - default: - testapp_print("Invalid Account Number\n"); - return FALSE; - break; + case 1:/* gawab */ + account->incoming_server_type = EMAIL_SERVER_TYPE_POP3 ; + account->incoming_server_address = strdup(GWB_RECV_SERVER_ADDR); + account->incoming_server_port_number = EMAIL_POP3S_PORT; + account->outgoing_server_address = strdup(GWB_SMTP_SERVER_ADDR); + account->incoming_server_secure_connection = 1; + account->outgoing_server_need_authentication = 1; + account->outgoing_server_port_number = EMAIL_SMTPS_PORT; + account->outgoing_server_secure_connection = 1; + + break; + + case 2:/* vadofone */ + account->incoming_server_type = EMAIL_SERVER_TYPE_IMAP4; + account->incoming_server_address = strdup(VDF_RECV_SERVER_ADDR); + account->incoming_server_port_number = EMAIL_IMAP_PORT; + account->outgoing_server_address = strdup(VDF_SMTP_SERVER_ADDR); + account->incoming_server_secure_connection = 0; + account->outgoing_server_need_authentication = 0; + break; + + case 4:/* SAMSUNG 3G TEST */ + account->incoming_server_type = EMAIL_SERVER_TYPE_POP3; + account->incoming_server_address = strdup(S3G_RECV_SERVER_ADDR); + account->incoming_server_port_number = S3G_RECV_SERVER_PORT; + account->outgoing_server_address = strdup(S3G_SMTP_SERVER_ADDR); + account->outgoing_server_port_number = S3G_SMTP_SERVER_PORT; + account->incoming_server_secure_connection = S3G_RECV_USE_SECURITY; + account->outgoing_server_secure_connection = S3G_SMTP_USE_SECURITY; + account->outgoing_server_need_authentication = S3G_SMTP_AUTH; + break; + + case 5:/* SAMSUNG 3G TEST */ + account->incoming_server_type = EMAIL_SERVER_TYPE_IMAP4; + account->incoming_server_address = strdup(S3G_RECV_SERVER_ADDR); + account->incoming_server_port_number = EMAIL_IMAPS_PORT; + account->outgoing_server_address = strdup(S3G_SMTP_SERVER_ADDR); + account->outgoing_server_port_number = S3G_SMTP_SERVER_PORT; + account->incoming_server_secure_connection = 1; + account->outgoing_server_secure_connection = S3G_SMTP_USE_SECURITY; + account->outgoing_server_need_authentication = S3G_SMTP_AUTH; + break; + + case 6:/* Gmail POP3 */ + account->incoming_server_type = EMAIL_SERVER_TYPE_POP3; + account->incoming_server_address = strdup("pop.gmail.com"); + account->incoming_server_port_number = 995; + account->incoming_server_secure_connection = 1; + account->outgoing_server_address = strdup("smtp.gmail.com"); + account->outgoing_server_port_number = 465; + account->outgoing_server_secure_connection = 1; + account->outgoing_server_need_authentication = 1; + break; + + case 7: /* Gmail IMAP4 */ + account->incoming_server_type = EMAIL_SERVER_TYPE_IMAP4; + account->incoming_server_address = strdup("imap.gmail.com"); + account->incoming_server_port_number = 993; + account->incoming_server_secure_connection = 1; + account->outgoing_server_address = strdup("smtp.gmail.com"); + account->outgoing_server_port_number = 465; + account->outgoing_server_secure_connection = 1; + account->outgoing_server_need_authentication = EMAIL_AUTHENTICATION_METHOD_DEFAULT; + account->incoming_server_authentication_method = EMAIL_AUTHENTICATION_METHOD_NO_AUTH; + break; + + case 8: /* Active Sync */ + account->incoming_server_type = EMAIL_SERVER_TYPE_ACTIVE_SYNC; + account->incoming_server_address = strdup(""); + account->incoming_server_port_number = 0; + account->incoming_server_secure_connection = 1; + account->outgoing_server_address = strdup(""); + account->outgoing_server_port_number = 0; + account->outgoing_server_secure_connection = 1; + account->outgoing_server_need_authentication = 1; + break; + + case 9: /* AOL */ + account->incoming_server_type = EMAIL_SERVER_TYPE_IMAP4; + account->incoming_server_address = strdup("imap.aol.com"); + account->incoming_server_port_number = 143; + account->incoming_server_secure_connection = 0; + account->outgoing_server_address = strdup("smtp.aol.com"); + account->outgoing_server_port_number = 587; + account->outgoing_server_secure_connection = 0; + account->outgoing_server_need_authentication = 1; + break; + + case 10: /* Hotmail */ + account->incoming_server_type = EMAIL_SERVER_TYPE_POP3; + account->incoming_server_address = strdup("pop3.live.com"); + account->incoming_server_port_number = 995; + account->incoming_server_secure_connection = 1; + account->outgoing_server_address = strdup("smtp.live.com"); + account->outgoing_server_port_number = 587; + account->outgoing_server_secure_connection = 0x02; + account->outgoing_server_need_authentication = 1; + break; + + case 11:/* Daum IMAP4*/ + account->incoming_server_type = EMAIL_SERVER_TYPE_IMAP4; + account->incoming_server_address = strdup("imap.daum.net"); + account->incoming_server_port_number = 993; + account->incoming_server_secure_connection = 1; + account->outgoing_server_address = strdup("smtp.daum.net"); + account->outgoing_server_port_number = 465; + account->outgoing_server_secure_connection = 1; + account->outgoing_server_need_authentication = 1; + break; + + case 12:/* Daum POP3*/ + account->incoming_server_type = EMAIL_SERVER_TYPE_POP3; + account->incoming_server_address = strdup("pop.daum.net"); + account->incoming_server_port_number = 995; + account->incoming_server_secure_connection = 1; + account->outgoing_server_address = strdup("smtp.daum.net"); + account->outgoing_server_port_number = 465; + account->outgoing_server_secure_connection = 1; + account->outgoing_server_need_authentication = 1; + break; + + case 13: /* Yahoo IMAP ID */ + account->incoming_server_type = EMAIL_SERVER_TYPE_IMAP4; + account->incoming_server_address = strdup("samsung.imap.mail.yahoo.com"); + account->incoming_server_port_number = 993; + account->incoming_server_secure_connection = 1; + account->outgoing_server_address = strdup("samsung.smtp.mail.yahoo.com"); + account->outgoing_server_port_number = 465; + account->outgoing_server_secure_connection = 1; + account->outgoing_server_need_authentication = 1; + break; + + case 14: /* XOAUTH */ + account->incoming_server_type = EMAIL_SERVER_TYPE_IMAP4; + account->incoming_server_address = strdup("imap.gmail.com"); + account->incoming_server_port_number = 993; + account->incoming_server_secure_connection = 1; + account->outgoing_server_address = strdup("smtp.gmail.com"); + account->outgoing_server_port_number = 465; + account->outgoing_server_secure_connection = 1; + account->outgoing_server_need_authentication = EMAIL_AUTHENTICATION_METHOD_XOAUTH2; + account->incoming_server_authentication_method = EMAIL_AUTHENTICATION_METHOD_XOAUTH2; + break; + + case 15: /* yandex */ + account->incoming_server_type = EMAIL_SERVER_TYPE_IMAP4; + account->incoming_server_address = strdup("imap.yandex.ru"); + account->incoming_server_port_number = 993; + account->incoming_server_secure_connection = 1; + account->outgoing_server_address = strdup("smtp.yandex.ru"); + account->outgoing_server_port_number = 465; + account->outgoing_server_secure_connection = 1; + account->outgoing_server_need_authentication = EMAIL_AUTHENTICATION_METHOD_DEFAULT; + account->incoming_server_authentication_method = EMAIL_AUTHENTICATION_METHOD_DEFAULT; + break; + + case 16: /* mopera */ + account->incoming_server_type = EMAIL_SERVER_TYPE_POP3; + account->incoming_server_address = strdup("mail.mopera.net"); + account->incoming_server_port_number = 110; + account->incoming_server_secure_connection = 0; + account->incoming_server_authentication_method = EMAIL_AUTHENTICATION_METHOD_NO_AUTH; + account->outgoing_server_address = strdup("mail.mopera.net"); + account->outgoing_server_port_number = 465; + account->outgoing_server_secure_connection = 0; + account->outgoing_server_need_authentication = EMAIL_AUTHENTICATION_METHOD_DEFAULT; + break; + + default: + testapp_print("Invalid Account Number\n"); + email_free_account(&account, 1); + return FALSE; + break; } account->account_svc_id = 77; @@ -389,7 +390,7 @@ static gboolean testapp_test_add_account_with_validation() return FALSE; } - email_get_account_list (&account_list, &pre_count); + email_get_account_list(&account_list, &pre_count); err = email_add_account_with_validation(account, &handle); if (err < 0) { @@ -401,7 +402,7 @@ static gboolean testapp_test_add_account_with_validation() err = email_free_account(&account, 1); do { - email_get_account_list (&account_list, &count); + email_get_account_list(&account_list, &count); if (count > pre_count) { flag = true; @@ -432,7 +433,8 @@ static gboolean testapp_test_update_account() //char signature[100] = {0}; //char user_email_address[256] = {0,}; //int add_my_address_to_bcc = 0; - int with_validation = 0; //account_svc_id = 0, + //int with_validation = 0; + //int account_svc_id = 0, testapp_print("\n>> Enter Account ID: "); if (0 >= scanf("%d", &account_id)) @@ -451,48 +453,48 @@ static gboolean testapp_test_update_account() testapp_print("\n Enter new check interval(in mins):"); if (0 >= scanf("%d", &(account->check_interval))) testapp_print("Invalid input. "); -/* - testapp_print("\n Enter new peak interval(in mins):"); - if (0 >= scanf("%d", &(account->peak_interval)); + /* + testapp_print("\n Enter new peak interval(in mins):"); + if (0 >= scanf("%d", &(account->peak_interval)); - testapp_print("\n Enter new peak days:"); - if (0 >= scanf("%d", &(account->peak_days)); + testapp_print("\n Enter new peak days:"); + if (0 >= scanf("%d", &(account->peak_days)); - testapp_print("\n Enter new peak start time:"); - if (0 >= scanf("%d", &(account->peak_start_time)); + testapp_print("\n Enter new peak start time:"); + if (0 >= scanf("%d", &(account->peak_start_time)); - testapp_print("\n Enter new peak end time:"); - if (0 >= scanf("%d", &(account->peak_end_time)); -*/ + testapp_print("\n Enter new peak end time:"); + if (0 >= scanf("%d", &(account->peak_end_time)); + */ -/* - testapp_print("\n Enter new Account name:"); - if (0 >= scanf("%s",account_name); + /* + testapp_print("\n Enter new Account name:"); + if (0 >= scanf("%s",account_name); - testapp_print("\n Enter new email addr:"); - if (0 >= scanf("%s",user_email_address); + testapp_print("\n Enter new email addr:"); + if (0 >= scanf("%s",user_email_address); - testapp_print("\n Enter new signature:"); - if (0 >= scanf("%s",signature); + testapp_print("\n Enter new signature:"); + if (0 >= scanf("%s",signature); - testapp_print("\n>> Enter add_my_address_to_bcc:(0:off, 1:on) "); - if (0 >= scanf("%d", &add_my_address_to_bcc); + testapp_print("\n>> Enter add_my_address_to_bcc:(0:off, 1:on) "); + if (0 >= scanf("%d", &add_my_address_to_bcc); - testapp_print("\n>> Enter account_svc_id: "); - if (0 >= scanf("%d", &account_svc_id); + testapp_print("\n>> Enter account_svc_id: "); + if (0 >= scanf("%d", &account_svc_id); - testapp_print("\n>> With validation ?(0: No, 1:Yes) "); - if (0 >= scanf("%d", &with_validation); -*/ + testapp_print("\n>> With validation ?(0: No, 1:Yes) "); + if (0 >= scanf("%d", &with_validation); + */ testapp_print("\n Assigning New Account name:(%s)", account->account_name); testapp_print("\n Assigning New Signature:(%s)\n", account->options.signature); - /* - account->account_name = strdup(account_name); - account->user_email_address = strdup(user_email_address); - account->options.signature = strdup(signature); - account->options.add_my_address_to_bcc = add_my_address_to_bcc; - account->account_svc_id = account_svc_id; - */ + /* + account->account_name = strdup(account_name); + account->user_email_address = strdup(user_email_address); + account->options.signature = strdup(signature); + account->options.add_my_address_to_bcc = add_my_address_to_bcc; + account->account_svc_id = account_svc_id; + */ if ((err = email_update_account(account_id, account)) != EMAIL_ERROR_NONE) { testapp_print("email_update_account failed - %d\n", err); @@ -512,7 +514,7 @@ static gboolean testapp_test_delete_account() if (0 >= scanf("%d", &account_id)) testapp_print("Invalid input. "); -/* sowmya.kr, 281209 Adding signature to options in email_account_t changes */ + /* sowmya.kr, 281209 Adding signature to options in email_account_t changes */ if ((err = email_get_account(account_id, WITHOUT_OPTION, &account)) < 0) { testapp_print("email_get_account failed \n"); testapp_print("testapp_test_delete_account failed\n"); @@ -629,7 +631,7 @@ static gboolean testapp_test_get_account() "display_content_status %d\n" "default_ringtone_status %d\n" "alert_ringtone_path %s\n" - , + , account->account_name, account->user_email_address, account->incoming_server_secure_connection, @@ -658,7 +660,7 @@ static gboolean testapp_test_get_account() account->options.display_content_status, account->options.default_ringtone_status, account->options.alert_ringtone_path - ); + ); err_code = email_free_account(&account, 1); @@ -675,11 +677,11 @@ static gboolean testapp_test_get_account() "user_email_address - %s \n" "incoming_server_secure_connection %d \n" "add_signature : %d \n", - account->account_name, - account->user_email_address, - account->incoming_server_secure_connection, - account->options.add_signature - ); + account->account_name, + account->user_email_address, + account->incoming_server_secure_connection, + account->options.add_signature + ); if (account->options.signature) testapp_print("signature : %s\n", account->options.signature); @@ -701,11 +703,11 @@ static gboolean testapp_test_get_account() "signature %s \n" "add_my_address_to_bcc %d\n" "account_svc_id %d\n", - account->options.add_signature, - account->options.signature, - account->options.add_my_address_to_bcc, - account->account_svc_id - ); + account->options.add_signature, + account->options.signature, + account->options.add_my_address_to_bcc, + account->account_svc_id + ); if (account->account_name) testapp_print("account_name : %s \n", account->account_name); @@ -743,8 +745,8 @@ static gboolean testapp_test_get_account_list() for (i = 0; i < count; i++) { testapp_print(" %2d) %-15s %-30s\n", account_list[i].account_id, - account_list[i].account_name, - account_list[i].user_email_address); + account_list[i].account_name, + account_list[i].user_email_address); } err_code = email_free_account(&account_list, count); @@ -794,7 +796,7 @@ static gboolean testapp_test_backup_account() } static gboolean testapp_test_restore_account() { - const char *file_name = tzplatform_mkpath(TZ_USER_DATA,"email/accounts_file"); + const char *file_name = tzplatform_mkpath(TZ_USER_DATA, "email/accounts_file"); int error_code; error_code = email_restore_accounts_from_secure_storage(file_name); testapp_print("\n email_restore_accounts_from_secure_storage returned [%d]\n", error_code); @@ -976,84 +978,84 @@ static gboolean testapp_test_interpret_command(int selected_number) gboolean go_to_loop = TRUE; switch (selected_number) { - case 1: - testapp_test_add_account_with_validation(); - break; + case 1: + testapp_test_add_account_with_validation(); + break; - case 2: - testapp_test_update_account(); - break; + case 2: + testapp_test_update_account(); + break; - case 3: - testapp_test_delete_account(); - break; + case 3: + testapp_test_delete_account(); + break; - case 4: - testapp_test_get_account(); - break; + case 4: + testapp_test_get_account(); + break; - case 5: - testapp_test_get_account_list(); - break; + case 5: + testapp_test_get_account_list(); + break; - case 6: - testapp_test_update_check_interval(); - break; + case 6: + testapp_test_update_check_interval(); + break; - case 7: - testapp_test_validate_account(); - break; + case 7: + testapp_test_validate_account(); + break; - case 8: - testapp_test_cancel_validate_account(); - break; + case 8: + testapp_test_cancel_validate_account(); + break; - case 9: - testapp_test_backup_account(); - break; + case 9: + testapp_test_backup_account(); + break; - case 10: - testapp_test_restore_account(); - break; + case 10: + testapp_test_restore_account(); + break; - case 11: - testapp_test_get_password_length_of_account(); - break; + case 11: + testapp_test_get_password_length_of_account(); + break; - case 13: - testapp_test_update_notification(); - break; + case 13: + testapp_test_update_notification(); + break; - case 14: - testapp_test_clear_notification(); - break; + case 14: + testapp_test_clear_notification(); + break; - case 15: - testapp_test_clear_all_notification(); - break; + case 15: + testapp_test_clear_all_notification(); + break; - case 16: - testapp_test_save_default_account_id(); - break; + case 16: + testapp_test_save_default_account_id(); + break; - case 17: - testapp_test_load_default_account_id(); - break; + case 17: + testapp_test_load_default_account_id(); + break; - case 18: - testapp_test_add_account(); - break; + case 18: + testapp_test_add_account(); + break; - case 19: - testapp_test_update_peak_schedule(); - break; + case 19: + testapp_test_update_peak_schedule(); + break; - case 0: - go_to_loop = FALSE; - break; + case 0: + go_to_loop = FALSE; + break; - default: - break; + default: + break; } return go_to_loop; diff --git a/test/testapp-rule.c b/test/testapp-rule.c index 54bcc37..4f90497 100644 --- a/test/testapp-rule.c +++ b/test/testapp-rule.c @@ -1,23 +1,23 @@ /* -* email-service -* -* Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. -* -* Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -* -*/ + * email-service + * + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Kyuho Jo <kyuho.jo@samsung.com>, Sunghyun Kwon <sh0701.kwon@samsung.com> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ @@ -168,7 +168,7 @@ static gboolean testapp_test_update_rule() testapp_print("Invalid input. "); rule->flag2 = flag; - if (!email_update_rule(filter_id, rule) < 0) + if (email_update_rule(filter_id, rule) < 0) testapp_print("email_update_rule failed..! "); email_free_rule(&rule, 1); @@ -207,10 +207,10 @@ static gboolean testapp_test_get_rule_list(void) for (i = 0; i < count; i++) { testapp_print(" %2d) Fileter_Id: %d | Account_id: %d | Type: %d | Value %s \n", i + 1, - rule_list[i].filter_id, - rule_list[i].account_id, - rule_list[i].type, - rule_list[i].value); + rule_list[i].filter_id, + rule_list[i].account_id, + rule_list[i].type, + rule_list[i].value); } email_free_rule(&rule_list, count); @@ -225,27 +225,27 @@ static gboolean testapp_test_interpret_command(int menu_number) gboolean go_to_loop = TRUE; switch (menu_number) { - case 1: - testapp_test_add_rule(); - break; - case 2: - testapp_test_delete_rule(); - break; - case 3: - testapp_test_update_rule(); - break; - case 5: - testapp_test_get_rule(); - break; - case 6: - testapp_test_get_rule_list(); - break; - - case 0: - go_to_loop = FALSE; - break; - default: - break; + case 1: + testapp_test_add_rule(); + break; + case 2: + testapp_test_delete_rule(); + break; + case 3: + testapp_test_update_rule(); + break; + case 5: + testapp_test_get_rule(); + break; + case 6: + testapp_test_get_rule_list(); + break; + + case 0: + go_to_loop = FALSE; + break; + default: + break; } return go_to_loop; |