Mercurial > libpst
annotate src/libstrfunc.c @ 389:3f83feface7a
Use plain make when building from Mercurial
The -C/--directory option can be used to change directory.
The make command accepts multiple targets on the command-line.
automake calls the default target 'all'.
author | Paul Wise <pabs3@bonedaddy.net> |
---|---|
date | Sat, 21 Dec 2019 21:25:45 +0800 |
parents | c947b8812120 |
children |
rev | line source |
---|---|
16 | 1 |
2 /* Taken from LibStrfunc v7.3 */ | |
3 | |
123
ab2a11e72250
more cleanup of #include files.
Carl Byington <carl@five-ten-sg.com>
parents:
110
diff
changeset
|
4 #include "define.h" |
ab2a11e72250
more cleanup of #include files.
Carl Byington <carl@five-ten-sg.com>
parents:
110
diff
changeset
|
5 |
16 | 6 |
94
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
7 static char base64_code_chars[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=="; |
16 | 8 |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
151
diff
changeset
|
9 static void base64_append(char **ou, int *line_count, char data); |
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
151
diff
changeset
|
10 static void base64_append(char **ou, int *line_count, char data) |
94
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
11 { |
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
12 if (*line_count == 76) { |
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
13 *(*ou)++ = '\n'; |
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
14 *line_count = 0; |
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
15 } |
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
16 *(*ou)++ = data; |
257
c947b8812120
rfc2047 and rfc2231 encoding for non-ascii headers and attachment filenames
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
17 if (*line_count >= 0) (*line_count)++; |
94
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
18 } |
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
19 |
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
20 |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
151
diff
changeset
|
21 char *pst_base64_encode(void *data, size_t size) |
94
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
22 { |
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
23 int line_count = 0; |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
151
diff
changeset
|
24 return pst_base64_encode_multiple(data, size, &line_count); |
94
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
25 } |
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
26 |
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
27 |
257
c947b8812120
rfc2047 and rfc2231 encoding for non-ascii headers and attachment filenames
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
28 char *pst_base64_encode_single(void *data, size_t size) |
c947b8812120
rfc2047 and rfc2231 encoding for non-ascii headers and attachment filenames
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
29 { |
c947b8812120
rfc2047 and rfc2231 encoding for non-ascii headers and attachment filenames
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
30 int line_count = -1; |
c947b8812120
rfc2047 and rfc2231 encoding for non-ascii headers and attachment filenames
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
31 return pst_base64_encode_multiple(data, size, &line_count); |
c947b8812120
rfc2047 and rfc2231 encoding for non-ascii headers and attachment filenames
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
32 } |
c947b8812120
rfc2047 and rfc2231 encoding for non-ascii headers and attachment filenames
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
33 |
c947b8812120
rfc2047 and rfc2231 encoding for non-ascii headers and attachment filenames
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
34 |
172
6954d315aaa8
move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents:
151
diff
changeset
|
35 char *pst_base64_encode_multiple(void *data, size_t size, int *line_count) |
94
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
36 { |
43 | 37 char *output; |
94
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
38 char *ou; |
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
39 unsigned char *p = (unsigned char *)data; |
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
40 unsigned char *dte = p + size; |
16 | 41 |
94
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
42 if (data == NULL || size == 0) return NULL; |
36 | 43 |
110
7133b39975f7
patch from David Cuadrado to process emails with type PST_TYPE_OTHER
Carl Byington <carl@five-ten-sg.com>
parents:
94
diff
changeset
|
44 ou = output = (char *)malloc(size / 3 * 4 + (size / 57) + 6); |
94
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
45 if (!output) return NULL; |
36 | 46 |
94
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
47 while((dte-p) >= 3) { |
43 | 48 unsigned char x = p[0]; |
49 unsigned char y = p[1]; | |
50 unsigned char z = p[2]; | |
94
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
51 base64_append(&ou, line_count, base64_code_chars[ x >> 2 ]); |
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
52 base64_append(&ou, line_count, base64_code_chars[ ((x & 0x03) << 4) | (y >> 4) ]); |
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
53 base64_append(&ou, line_count, base64_code_chars[ ((y & 0x0F) << 2) | (z >> 6) ]); |
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
54 base64_append(&ou, line_count, base64_code_chars[ z & 0x3F ]); |
43 | 55 p+=3; |
56 }; | |
94
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
57 if ((dte-p) == 2) { |
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
58 base64_append(&ou, line_count, base64_code_chars[ *p >> 2 ]); |
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
59 base64_append(&ou, line_count, base64_code_chars[ ((*p & 0x03) << 4) | (p[1] >> 4) ]); |
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
60 base64_append(&ou, line_count, base64_code_chars[ ((p[1] & 0x0F) << 2) ]); |
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
61 base64_append(&ou, line_count, '='); |
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
62 } else if ((dte-p) == 1) { |
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
63 base64_append(&ou, line_count, base64_code_chars[ *p >> 2 ]); |
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
64 base64_append(&ou, line_count, base64_code_chars[ ((*p & 0x03) << 4) ]); |
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
65 base64_append(&ou, line_count, '='); |
997cf1373f9e
fix base64 encoding that could create long lines
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
66 base64_append(&ou, line_count, '='); |
43 | 67 }; |
36 | 68 |
43 | 69 *ou=0; |
70 return output; | |
16 | 71 }; |
72 | |
43 | 73 |