Mercurial > libpst
annotate src/vbuf.c @ 402:37cd2aea5d4a
update x_python.m4 to detect python 3.9
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Thu, 26 Mar 2020 09:22:43 -0700 |
parents | 4fd5197aacc2 |
children |
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 | 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 | 11 |
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 | 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 | 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 | 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 |
309
4fd5197aacc2
fix charset issue with iconv return value
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
74 DEBUG_ENT("sbcs_conversion"); |
182
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
75 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
|
76 |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
77 do { |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
78 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
|
79 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
|
80 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
|
81 myerrno = errno; |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
82 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
|
83 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
|
84 } 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
|
85 |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
86 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
|
87 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
|
88 pst_unicode_init(); |
309
4fd5197aacc2
fix charset issue with iconv return value
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
89 DEBUG_RET(); |
182
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
90 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
|
91 } |
309
4fd5197aacc2
fix charset issue with iconv return value
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
92 DEBUG_RET(); |
4fd5197aacc2
fix charset issue with iconv return value
Carl Byington <carl@five-ten-sg.com>
parents:
195
diff
changeset
|
93 return 0; |
182
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
94 } |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
95 |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
96 |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
97 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
|
98 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
|
99 { |
116
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
100 iconv_close(i16to8); |
151
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
101 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
|
102 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
|
103 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
|
104 target_charset = NULL; |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
105 target_open_from = 0; |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
106 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
|
107 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
|
108 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
109 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
110 |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
164
diff
changeset
|
111 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
|
112 static int utf16_is_terminated(const char *str, int length) |
43 | 113 { |
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
|
114 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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 } |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
120 } |
43 | 121 |
182
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
122 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
|
123 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
|
124 } |
43 | 125 |
182
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
126 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
|
127 } |
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 |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
130 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
|
131 { |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
132 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
|
133 if (result) { |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
134 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
|
135 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
|
136 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
|
137 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
|
138 } |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
139 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
|
140 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
|
141 } |
43 | 142 |
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
|
143 |
182
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
144 /** 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
|
145 */ |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
146 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
|
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 == len) |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
149 return; |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
150 |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
151 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
|
152 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
|
153 return; |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
154 } |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
155 |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
156 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
|
157 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
|
158 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
|
159 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
|
160 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
|
161 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
|
162 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
|
163 |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
164 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
|
165 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
|
166 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
|
167 } else { |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
168 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
|
169 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
|
170 } |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
171 |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
172 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
|
173 |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
174 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
|
175 } |
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 |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
178 /** 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
|
179 */ |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
180 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
|
181 { |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
182 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
|
183 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
|
184 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
|
185 } |
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 |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
188 /** 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
|
189 */ |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
190 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
|
191 { |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
192 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
|
193 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
|
194 return; |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
195 } |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
196 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
|
197 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
|
198 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
|
199 } |
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 |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
202 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
|
203 { |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
204 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
|
205 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
|
206 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
|
207 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
|
208 } |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
209 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
|
210 } |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
211 |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
212 |
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
213 size_t pst_vb_utf16to8(pst_vbuf *dest, const char *inbuf, int iblen) |
43 | 214 { |
116
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
215 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
|
216 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
|
217 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
|
218 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
|
219 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
|
220 |
195
320cfcba8058
add python module interface to the shared library for easy scripting.
Carl Byington <carl@five-ten-sg.com>
parents:
182
diff
changeset
|
221 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
|
222 pst_vbresize(dest, iblen); |
43 | 223 |
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
|
224 //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
|
225 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
|
226 return (size_t)-1; |
43 | 227 |
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
|
228 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
|
229 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
|
230 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
|
231 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
|
232 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
|
233 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
|
234 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
|
235 } while ((size_t)-1 == icresult && E2BIG == myerrno); |
43 | 236 |
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
|
237 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
|
238 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
|
239 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
|
240 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
|
241 } |
116
ed2a260bbb98
improve handling of content-type charset values in mime parts
Carl Byington <carl@five-ten-sg.com>
parents:
93
diff
changeset
|
242 return (icresult) ? (size_t)-1 : 0; |
43 | 243 } |
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
|
244 |
b12f4e50e2e8
Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
245 |
182
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
246 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
|
247 { |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
248 open_targets(charset); |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
249 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
|
250 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
|
251 } |
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 |
182
b65e8d0a088a
more cleanup on external names in the shared object file
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
254 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
|
255 { |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
256 open_targets(charset); |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
257 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
|
258 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
|
259 } |
cda7c812ec01
track character set individually for each mapi element
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
260 |