annotate src/vbuf.c @ 261:41862bddcf63

adding more debug code
author Carl Byington <carl@five-ten-sg.com>
date Sun, 17 Apr 2011 15:01:18 -0700
parents 320cfcba8058
children 4fd5197aacc2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
1
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
2 #include "define.h"
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
3
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
4 static int unicode_up = 0;
116
ed2a260bbb98 improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents: 93
diff changeset
5 static iconv_t i16to8;
ed2a260bbb98 improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents: 93
diff changeset
6 static const char *target_charset = NULL;
151
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 142
diff changeset
7 static int target_open_from = 0;
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 142
diff changeset
8 static int target_open_to = 0;
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 142
diff changeset
9 static iconv_t i8totarget = (iconv_t)-1;
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 142
diff changeset
10 static iconv_t target2i8 = (iconv_t)-1;
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
11
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
12
182
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
13 #define ASSERT(x,...) { if( !(x) ) DIE(( __VA_ARGS__)); }
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
14
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
15
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
16 /** DESTRUCTIVELY grow or shrink buffer
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
17 */
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
18 static void pst_vbresize(pst_vbuf *vb, size_t len);
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
19 static void pst_vbresize(pst_vbuf *vb, size_t len)
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
20 {
182
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
21 vb->dlen = 0;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
22
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
23 if (vb->blen >= len) {
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
24 vb->b = vb->buf;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
25 return;
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
26 }
182
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
27
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
28 vb->buf = realloc(vb->buf, len);
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
29 vb->b = vb->buf;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
30 vb->blen = len;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
31 }
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
32
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
33
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
34 static size_t pst_vbavail(pst_vbuf * vb);
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
35 static size_t pst_vbavail(pst_vbuf * vb)
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
36 {
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
37 return vb->blen - vb->dlen - (size_t)(vb->b - vb->buf);
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
38 }
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
39
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
40
182
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
41 static void open_targets(const char* charset);
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
42 static void open_targets(const char* charset)
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
43 {
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
44 if (!target_charset || strcasecmp(target_charset, charset)) {
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
45 if (target_open_from) iconv_close(i8totarget);
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
46 if (target_open_to) iconv_close(target2i8);
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
47 if (target_charset) free((char *)target_charset);
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
48 target_charset = strdup(charset);
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
49 target_open_from = 1;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
50 target_open_to = 1;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
51 i8totarget = iconv_open(target_charset, "utf-8");
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
52 if (i8totarget == (iconv_t)-1) {
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
53 target_open_from = 0;
195
320cfcba8058 add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents: 182
diff changeset
54 DEBUG_WARN(("Couldn't open iconv descriptor for utf-8 to %s.\n", target_charset));
182
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
55 }
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
56 target2i8 = iconv_open("utf-8", target_charset);
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
57 if (target2i8 == (iconv_t)-1) {
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
58 target_open_to = 0;
195
320cfcba8058 add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents: 182
diff changeset
59 DEBUG_WARN(("Couldn't open iconv descriptor for %s to utf-8.\n", target_charset));
182
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
60 }
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
61 }
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
62 }
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
63
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
64
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
65 static size_t sbcs_conversion(pst_vbuf *dest, const char *inbuf, int iblen, iconv_t conversion);
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
66 static size_t sbcs_conversion(pst_vbuf *dest, const char *inbuf, int iblen, iconv_t conversion)
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
67 {
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
68 size_t inbytesleft = iblen;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
69 size_t icresult = (size_t)-1;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
70 size_t outbytesleft = 0;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
71 char *outbuf = NULL;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
72 int myerrno;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
73
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
74 pst_vbresize(dest, 2*iblen);
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
75
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
76 do {
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
77 outbytesleft = dest->blen - dest->dlen;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
78 outbuf = dest->b + dest->dlen;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
79 icresult = iconv(conversion, (ICONV_CONST char**)&inbuf, &inbytesleft, &outbuf, &outbytesleft);
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
80 myerrno = errno;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
81 dest->dlen = outbuf - dest->b;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
82 if (inbytesleft) pst_vbgrow(dest, 2*inbytesleft);
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
83 } while ((size_t)-1 == icresult && E2BIG == myerrno);
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
84
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
85 if (icresult == (size_t)-1) {
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
86 DEBUG_WARN(("iconv failure: %s\n", strerror(myerrno)));
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
87 pst_unicode_init();
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
88 return (size_t)-1;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
89 }
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
90 return (icresult) ? (size_t)-1 : 0;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
91 }
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
92
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
93
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
94 static void pst_unicode_close();
176
ac6e22c8a9cf build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents: 172
diff changeset
95 static void pst_unicode_close()
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
96 {
116
ed2a260bbb98 improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents: 93
diff changeset
97 iconv_close(i16to8);
151
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 142
diff changeset
98 if (target_open_from) iconv_close(i8totarget);
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 142
diff changeset
99 if (target_open_to) iconv_close(target2i8);
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 142
diff changeset
100 if (target_charset) free((char *)target_charset);
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 142
diff changeset
101 target_charset = NULL;
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 142
diff changeset
102 target_open_from = 0;
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 142
diff changeset
103 target_open_to = 0;
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
104 unicode_up = 0;
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
105 }
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
106
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
107
172
6954d315aaa8 move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents: 164
diff changeset
108 static int utf16_is_terminated(const char *str, int length);
6954d315aaa8 move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents: 164
diff changeset
109 static int utf16_is_terminated(const char *str, int length)
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
110 {
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
111 int len = -1;
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
112 int i;
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
113 for (i = 0; i < length; i += 2) {
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
114 if (str[i] == 0 && str[i + 1] == 0) {
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
115 len = i;
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
116 }
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
117 }
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
118
182
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
119 if (len == -1) {
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
120 DEBUG_WARN(("utf16 string is not zero terminated\n"));
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
121 }
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
122
182
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
123 return (len == -1) ? 0 : 1;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
124 }
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
125
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
126
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
127 pst_vbuf *pst_vballoc(size_t len)
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
128 {
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
129 pst_vbuf *result = pst_malloc(sizeof(pst_vbuf));
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
130 if (result) {
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
131 result->dlen = 0;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
132 result->blen = 0;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
133 result->buf = NULL;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
134 pst_vbresize(result, len);
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
135 }
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
136 else DIE(("malloc() failure"));
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
137 return result;
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
138 }
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
139
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
140
182
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
141 /** out: vbavail(vb) >= len, data are preserved
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
142 */
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
143 void pst_vbgrow(pst_vbuf *vb, size_t len)
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
144 {
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
145 if (0 == len)
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
146 return;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
147
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
148 if (0 == vb->blen) {
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
149 pst_vbresize(vb, len);
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
150 return;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
151 }
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
152
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
153 if (vb->dlen + len > vb->blen) {
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
154 if (vb->dlen + len < vb->blen * 1.5)
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
155 len = vb->blen * 1.5;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
156 char *nb = pst_malloc(vb->blen + len);
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
157 if (!nb) DIE(("malloc() failure"));
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
158 vb->blen = vb->blen + len;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
159 memcpy(nb, vb->b, vb->dlen);
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
160
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
161 free(vb->buf);
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
162 vb->buf = nb;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
163 vb->b = vb->buf;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
164 } else {
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
165 if (vb->b != vb->buf)
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
166 memcpy(vb->buf, vb->b, vb->dlen);
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
167 }
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
168
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
169 vb->b = vb->buf;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
170
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
171 ASSERT(pst_vbavail(vb) >= len, "vbgrow(): I have failed in my mission.");
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
172 }
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
173
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
174
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
175 /** set vbuf b size=len, resize if necessary, relen = how much to over-allocate
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
176 */
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
177 void pst_vbset(pst_vbuf * vb, void *b, size_t len)
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
178 {
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
179 pst_vbresize(vb, len);
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
180 memcpy(vb->b, b, len);
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
181 vb->dlen = len;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
182 }
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
183
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
184
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
185 /** append len bytes of b to vb, resize if necessary
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
186 */
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
187 void pst_vbappend(pst_vbuf *vb, void *b, size_t len)
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
188 {
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
189 if (0 == vb->dlen) {
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
190 pst_vbset(vb, b, len);
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
191 return;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
192 }
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
193 pst_vbgrow(vb, len);
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
194 memcpy(vb->b + vb->dlen, b, len);
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
195 vb->dlen += len;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
196 }
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
197
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
198
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
199 void pst_unicode_init()
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
200 {
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
201 if (unicode_up) pst_unicode_close();
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
202 i16to8 = iconv_open("utf-8", "utf-16le");
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
203 if (i16to8 == (iconv_t)-1) {
195
320cfcba8058 add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents: 182
diff changeset
204 DEBUG_WARN(("Couldn't open iconv descriptor for utf-16le to utf-8.\n"));
182
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
205 }
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
206 unicode_up = 1;
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
207 }
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
208
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
209
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
210 size_t pst_vb_utf16to8(pst_vbuf *dest, const char *inbuf, int iblen)
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
211 {
116
ed2a260bbb98 improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents: 93
diff changeset
212 size_t inbytesleft = iblen;
ed2a260bbb98 improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents: 93
diff changeset
213 size_t icresult = (size_t)-1;
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
214 size_t outbytesleft = 0;
116
ed2a260bbb98 improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents: 93
diff changeset
215 char *outbuf = NULL;
164
ab384fed78c5 Compensate for iconv conversion to utf-7 that produces strings that are not null terminated.
Carl Byington <carl@five-ten-sg.com>
parents: 151
diff changeset
216 int myerrno;
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
217
195
320cfcba8058 add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents: 182
diff changeset
218 if (!unicode_up) return (size_t)-1; // failure to open iconv
172
6954d315aaa8 move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents: 164
diff changeset
219 pst_vbresize(dest, iblen);
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
220
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
221 //Bad Things can happen if a non-zero-terminated utf16 string comes through here
116
ed2a260bbb98 improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents: 93
diff changeset
222 if (!utf16_is_terminated(inbuf, iblen))
ed2a260bbb98 improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents: 93
diff changeset
223 return (size_t)-1;
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
224
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
225 do {
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
226 outbytesleft = dest->blen - dest->dlen;
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
227 outbuf = dest->b + dest->dlen;
116
ed2a260bbb98 improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents: 93
diff changeset
228 icresult = iconv(i16to8, (ICONV_CONST char**)&inbuf, &inbytesleft, &outbuf, &outbytesleft);
164
ab384fed78c5 Compensate for iconv conversion to utf-7 that produces strings that are not null terminated.
Carl Byington <carl@five-ten-sg.com>
parents: 151
diff changeset
229 myerrno = errno;
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
230 dest->dlen = outbuf - dest->b;
172
6954d315aaa8 move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents: 164
diff changeset
231 if (inbytesleft) pst_vbgrow(dest, inbytesleft);
164
ab384fed78c5 Compensate for iconv conversion to utf-7 that produces strings that are not null terminated.
Carl Byington <carl@five-ten-sg.com>
parents: 151
diff changeset
232 } while ((size_t)-1 == icresult && E2BIG == myerrno);
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
233
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
234 if (icresult == (size_t)-1) {
164
ab384fed78c5 Compensate for iconv conversion to utf-7 that produces strings that are not null terminated.
Carl Byington <carl@five-ten-sg.com>
parents: 151
diff changeset
235 DEBUG_WARN(("iconv failure: %s\n", strerror(myerrno)));
172
6954d315aaa8 move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents: 164
diff changeset
236 pst_unicode_init();
116
ed2a260bbb98 improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents: 93
diff changeset
237 return (size_t)-1;
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
238 }
116
ed2a260bbb98 improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents: 93
diff changeset
239 return (icresult) ? (size_t)-1 : 0;
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents:
diff changeset
240 }
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
241
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 43
diff changeset
242
182
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
243 size_t pst_vb_utf8to8bit(pst_vbuf *dest, const char *inbuf, int iblen, const char* charset)
151
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 142
diff changeset
244 {
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 142
diff changeset
245 open_targets(charset);
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 142
diff changeset
246 if (!target_open_from) return (size_t)-1; // failure to open the target
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 142
diff changeset
247 return sbcs_conversion(dest, inbuf, iblen, i8totarget);
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 142
diff changeset
248 }
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 142
diff changeset
249
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 142
diff changeset
250
182
b65e8d0a088a more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents: 176
diff changeset
251 size_t pst_vb_8bit2utf8(pst_vbuf *dest, const char *inbuf, int iblen, const char* charset)
151
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 142
diff changeset
252 {
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 142
diff changeset
253 open_targets(charset);
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 142
diff changeset
254 if (!target_open_to) return (size_t)-1; // failure to open the target
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 142
diff changeset
255 return sbcs_conversion(dest, inbuf, iblen, target2i8);
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 142
diff changeset
256 }
cda7c812ec01 track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents: 142
diff changeset
257