Mercurial > libpst
annotate src/pst2ldif.cpp @ 110:7133b39975f7 stable-0-6-22
patch from David Cuadrado to process emails with type PST_TYPE_OTHER
base64_encode_multiple() may insert newline, needs larger malloc
subject lines shorter than 2 bytes could segfault
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 28 Nov 2008 11:36:53 -0800 |
parents | 1b2a4fac1303 |
children | e213bfcf9aa7 |
rev | line source |
---|---|
16 | 1 /* |
2 | |
3 Copyright (c) 2004 Carl Byington - 510 Software Group, released under | |
4 the GPL version 2 or any later version at your choice available at | |
5 http://www.fsf.org/licenses/gpl.txt | |
6 | |
7 Based on readpst.c by David Smith | |
8 | |
9 */ | |
10 | |
11 using namespace std; | |
12 | |
13 // needed for std c++ collections | |
14 #include <set> | |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
15 #include <vector> |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
16 #include <string> |
16 | 17 |
18 extern "C" { | |
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:
59
diff
changeset
|
19 #include "define.h" |
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:
59
diff
changeset
|
20 #include "libstrfunc.h" |
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:
59
diff
changeset
|
21 #include "libpst.h" |
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:
59
diff
changeset
|
22 #include "common.h" |
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:
59
diff
changeset
|
23 #include "timeconv.h" |
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:
59
diff
changeset
|
24 #include "lzfu.h" |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
25 #include "stdarg.h" |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
26 #include "iconv.h" |
16 | 27 } |
28 | |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
29 int32_t usage(); |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
30 int32_t version(); |
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:
59
diff
changeset
|
31 char *check_filename(char *fname); |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
32 void print_ldif_single(const char *attr, const char *value); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
33 void print_ldif_address(const char *attr, int nvalues, char *value, ...); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
34 void print_ldif_dn(const char *attr, const char *value, const char *base); |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
35 void print_ldif_multi(const char *dn, const char *value); |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
36 void print_ldif_two(const char *attr, const char *value1, const char *value2); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
37 void print_escaped_dn(const char *value); |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
38 void build_cn(char *cn, size_t len, int nvalues, char *value, ...); |
16 | 39 |
40 char *prog_name; | |
41 pst_file pstfile; | |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
42 bool old_schema = false; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
43 char *ldap_base = NULL; // 'o=some.domain.tld,c=US' |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
44 int ldif_extra_line_count = 0; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
45 iconv_t cd = 0; // Character set conversion descriptor |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
46 vector<string> ldap_class; // 'newPerson' or 'inetOrgPerson' |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
47 vector<string> ldif_extra_line; // 'o: myorg' |
16 | 48 |
49 | |
50 //////////////////////////////////////////////// | |
51 // define our ordering | |
52 struct ltstr { | |
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:
59
diff
changeset
|
53 bool operator()(const char* s1, const char* s2) const { |
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:
59
diff
changeset
|
54 return strcasecmp(s1, s2) < 0; |
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:
59
diff
changeset
|
55 } |
16 | 56 }; |
57 // define our set | |
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:
59
diff
changeset
|
58 typedef set<const char *, ltstr> string_set; |
16 | 59 // make a static set to hold the cn values |
60 static string_set all_strings; | |
61 | |
62 | |
63 //////////////////////////////////////////////// | |
41
183ae993b9ad
security fix for potential buffer overrun in lz decompress
carl
parents:
38
diff
changeset
|
64 // helper to free all the strings in a set |
183ae993b9ad
security fix for potential buffer overrun in lz decompress
carl
parents:
38
diff
changeset
|
65 // |
183ae993b9ad
security fix for potential buffer overrun in lz decompress
carl
parents:
38
diff
changeset
|
66 static void free_strings(string_set &s); |
183ae993b9ad
security fix for potential buffer overrun in lz decompress
carl
parents:
38
diff
changeset
|
67 static void free_strings(string_set &s) |
183ae993b9ad
security fix for potential buffer overrun in lz decompress
carl
parents:
38
diff
changeset
|
68 { |
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:
59
diff
changeset
|
69 for (string_set::iterator i=s.begin(); i!=s.end(); i++) { |
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:
59
diff
changeset
|
70 free((void*)*i); |
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:
59
diff
changeset
|
71 } |
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:
59
diff
changeset
|
72 s.clear(); |
41
183ae993b9ad
security fix for potential buffer overrun in lz decompress
carl
parents:
38
diff
changeset
|
73 } |
183ae993b9ad
security fix for potential buffer overrun in lz decompress
carl
parents:
38
diff
changeset
|
74 |
183ae993b9ad
security fix for potential buffer overrun in lz decompress
carl
parents:
38
diff
changeset
|
75 |
183ae993b9ad
security fix for potential buffer overrun in lz decompress
carl
parents:
38
diff
changeset
|
76 //////////////////////////////////////////////// |
16 | 77 // helper to register a string in a string set |
78 // | |
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:
59
diff
changeset
|
79 static const char* register_string(string_set &s, const char *name); |
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:
59
diff
changeset
|
80 static const char* register_string(string_set &s, const char *name) { |
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:
59
diff
changeset
|
81 string_set::const_iterator i = s.find(name); |
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:
59
diff
changeset
|
82 if (i != s.end()) return *i; |
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:
59
diff
changeset
|
83 char *x = strdup(name); |
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:
59
diff
changeset
|
84 s.insert(x); |
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:
59
diff
changeset
|
85 return x; |
16 | 86 } |
87 | |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
88 |
16 | 89 //////////////////////////////////////////////// |
90 // register a global string | |
91 // | |
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:
59
diff
changeset
|
92 static const char* register_string(const char *name); |
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:
59
diff
changeset
|
93 static const char* register_string(const char *name) { |
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:
59
diff
changeset
|
94 return register_string(all_strings, name); |
16 | 95 } |
96 | |
97 | |
98 //////////////////////////////////////////////// | |
99 // make a unique string | |
100 // | |
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:
59
diff
changeset
|
101 static const char* unique_string(const char *name); |
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:
59
diff
changeset
|
102 static const char* unique_string(const char *name) { |
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:
59
diff
changeset
|
103 int unique = 2; |
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:
59
diff
changeset
|
104 string_set::iterator i = all_strings.find(name); |
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:
59
diff
changeset
|
105 if (i == all_strings.end()) return register_string(name); |
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:
59
diff
changeset
|
106 while (true) { |
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:
59
diff
changeset
|
107 char n[strlen(name)+10]; |
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:
59
diff
changeset
|
108 snprintf(n, sizeof(n), "%s %d", name, unique++); |
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:
59
diff
changeset
|
109 string_set::iterator i = all_strings.find(n); |
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:
59
diff
changeset
|
110 if (i == all_strings.end()) return register_string(n); |
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:
59
diff
changeset
|
111 } |
16 | 112 } |
113 | |
114 | |
115 static void process(pst_desc_ll *d_ptr); | |
116 static void process(pst_desc_ll *d_ptr) { | |
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:
59
diff
changeset
|
117 pst_item *item = NULL; |
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:
59
diff
changeset
|
118 while (d_ptr) { |
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:
59
diff
changeset
|
119 if (d_ptr->desc) { |
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:
59
diff
changeset
|
120 item = pst_parse_item(&pstfile, d_ptr); |
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:
59
diff
changeset
|
121 DEBUG_INFO(("item pointer is %p\n", item)); |
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:
59
diff
changeset
|
122 if (item) { |
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:
59
diff
changeset
|
123 if (item->folder && d_ptr->child && strcasecmp(item->file_as, "Deleted Items")) { |
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:
59
diff
changeset
|
124 //if this is a non-empty folder other than deleted items, we want to recurse into it |
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:
59
diff
changeset
|
125 fprintf(stderr, "entering folder %s\n", item->file_as); |
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:
59
diff
changeset
|
126 process(d_ptr->child); |
79
56fa05fd5271
Patch from Robert Simpson for encryption type 2.
Carl Byington <carl@five-ten-sg.com>
parents:
73
diff
changeset
|
127 |
56fa05fd5271
Patch from Robert Simpson for encryption type 2.
Carl Byington <carl@five-ten-sg.com>
parents:
73
diff
changeset
|
128 } else if (item->contact && (item->type == PST_TYPE_CONTACT)) { |
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:
59
diff
changeset
|
129 // deal with a contact |
79
56fa05fd5271
Patch from Robert Simpson for encryption type 2.
Carl Byington <carl@five-ten-sg.com>
parents:
73
diff
changeset
|
130 char cn[1000]; |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
131 |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
132 build_cn(cn, sizeof(cn), 4, |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
133 item->contact->display_name_prefix, |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
134 item->contact->first_name, |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
135 item->contact->surname, |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
136 item->contact->suffix); |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
137 if (cn[0] != 0) { |
79
56fa05fd5271
Patch from Robert Simpson for encryption type 2.
Carl Byington <carl@five-ten-sg.com>
parents:
73
diff
changeset
|
138 // have a valid cn |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
139 const char *ucn = unique_string(cn); |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
140 |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
141 print_ldif_dn("dn", ucn, ldap_base); |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
142 print_ldif_single("cn", ucn); |
79
56fa05fd5271
Patch from Robert Simpson for encryption type 2.
Carl Byington <carl@five-ten-sg.com>
parents:
73
diff
changeset
|
143 if (item->contact->first_name) { |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
144 print_ldif_two("givenName", |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
145 item->contact->display_name_prefix, |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
146 item->contact->first_name); |
79
56fa05fd5271
Patch from Robert Simpson for encryption type 2.
Carl Byington <carl@five-ten-sg.com>
parents:
73
diff
changeset
|
147 } |
56fa05fd5271
Patch from Robert Simpson for encryption type 2.
Carl Byington <carl@five-ten-sg.com>
parents:
73
diff
changeset
|
148 if (item->contact->surname) { |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
149 print_ldif_two("sn", |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
150 item->contact->surname, |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
151 item->contact->suffix); |
79
56fa05fd5271
Patch from Robert Simpson for encryption type 2.
Carl Byington <carl@five-ten-sg.com>
parents:
73
diff
changeset
|
152 } |
56fa05fd5271
Patch from Robert Simpson for encryption type 2.
Carl Byington <carl@five-ten-sg.com>
parents:
73
diff
changeset
|
153 else if (item->contact->company_name) { |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
154 print_ldif_single("sn", item->contact->company_name); |
79
56fa05fd5271
Patch from Robert Simpson for encryption type 2.
Carl Byington <carl@five-ten-sg.com>
parents:
73
diff
changeset
|
155 } |
56fa05fd5271
Patch from Robert Simpson for encryption type 2.
Carl Byington <carl@five-ten-sg.com>
parents:
73
diff
changeset
|
156 else |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
157 print_ldif_single("sn", ucn); // use cn as sn if we cannot find something better |
16 | 158 |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
159 if (old_schema) { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
160 if (item->contact->job_title) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
161 print_ldif_single("personalTitle", item->contact->job_title); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
162 if (item->contact->company_name) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
163 print_ldif_single("company", item->contact->company_name); |
108
1b2a4fac1303
fix title bug with old schema in pst2ldif, also escape commas in distinguished names per rfc4514.
Carl Byington <carl@five-ten-sg.com>
parents:
106
diff
changeset
|
164 } |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
165 else { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
166 // new schema |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
167 if (item->contact->job_title) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
168 print_ldif_single("title", item->contact->job_title); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
169 if (item->contact->company_name) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
170 print_ldif_single("o", item->contact->company_name); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
171 } |
79
56fa05fd5271
Patch from Robert Simpson for encryption type 2.
Carl Byington <carl@five-ten-sg.com>
parents:
73
diff
changeset
|
172 if (item->contact->address1 && *item->contact->address1) |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
173 print_ldif_single("mail", item->contact->address1); |
79
56fa05fd5271
Patch from Robert Simpson for encryption type 2.
Carl Byington <carl@five-ten-sg.com>
parents:
73
diff
changeset
|
174 if (item->contact->address2 && *item->contact->address2) |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
175 print_ldif_single("mail", item->contact->address2); |
79
56fa05fd5271
Patch from Robert Simpson for encryption type 2.
Carl Byington <carl@five-ten-sg.com>
parents:
73
diff
changeset
|
176 if (item->contact->address3 && *item->contact->address3) |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
177 print_ldif_single("mail", item->contact->address3); |
79
56fa05fd5271
Patch from Robert Simpson for encryption type 2.
Carl Byington <carl@five-ten-sg.com>
parents:
73
diff
changeset
|
178 if (item->contact->address1a && *item->contact->address1a) |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
179 print_ldif_single("mail", item->contact->address1a); |
79
56fa05fd5271
Patch from Robert Simpson for encryption type 2.
Carl Byington <carl@five-ten-sg.com>
parents:
73
diff
changeset
|
180 if (item->contact->address2a && *item->contact->address2a) |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
181 print_ldif_single("mail", item->contact->address2a); |
79
56fa05fd5271
Patch from Robert Simpson for encryption type 2.
Carl Byington <carl@five-ten-sg.com>
parents:
73
diff
changeset
|
182 if (item->contact->address3a && *item->contact->address3a) |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
183 print_ldif_single("mail", item->contact->address3a); |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
184 |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
185 if (old_schema) { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
186 if (item->contact->business_address) { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
187 if (item->contact->business_po_box) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
188 print_ldif_single("postalAddress", item->contact->business_po_box); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
189 if (item->contact->business_street) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
190 print_ldif_multi("postalAddress", item->contact->business_street); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
191 if (item->contact->business_city) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
192 print_ldif_single("l", item->contact->business_city); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
193 if (item->contact->business_state) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
194 print_ldif_single("st", item->contact->business_state); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
195 if (item->contact->business_postal_code) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
196 print_ldif_single("postalCode", item->contact->business_postal_code); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
197 } |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
198 else if (item->contact->home_address) { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
199 if (item->contact->home_po_box) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
200 print_ldif_single("postalAddress", item->contact->home_po_box); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
201 if (item->contact->home_street) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
202 print_ldif_multi("postalAddress", item->contact->home_street); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
203 if (item->contact->home_city) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
204 print_ldif_single("l", item->contact->home_city); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
205 if (item->contact->home_state) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
206 print_ldif_single("st", item->contact->home_state); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
207 if (item->contact->home_postal_code) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
208 print_ldif_single("postalCode", item->contact->home_postal_code); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
209 } |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
210 else if (item->contact->other_address) { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
211 if (item->contact->other_po_box) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
212 print_ldif_single("postalAddress", item->contact->other_po_box); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
213 if (item->contact->other_street) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
214 print_ldif_multi("postalAddress", item->contact->other_street); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
215 if (item->contact->other_city) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
216 print_ldif_single("l", item->contact->other_city); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
217 if (item->contact->other_state) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
218 print_ldif_single("st", item->contact->other_state); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
219 if (item->contact->other_postal_code) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
220 print_ldif_single("postalCode", item->contact->other_postal_code); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
221 } |
79
56fa05fd5271
Patch from Robert Simpson for encryption type 2.
Carl Byington <carl@five-ten-sg.com>
parents:
73
diff
changeset
|
222 } |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
223 else { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
224 // new schema, with proper RFC4517 postal addresses |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
225 if (item->contact->business_address) { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
226 print_ldif_address("postalAddress", 6, |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
227 item->contact->business_po_box, |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
228 item->contact->business_street, |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
229 item->contact->business_city, |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
230 item->contact->business_state, |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
231 item->contact->business_postal_code, |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
232 item->contact->business_country); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
233 if (item->contact->business_city) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
234 print_ldif_single("l", item->contact->business_city); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
235 if (item->contact->business_state) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
236 print_ldif_single("st", item->contact->business_state); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
237 if (item->contact->business_postal_code) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
238 print_ldif_single("postalCode", item->contact->business_postal_code); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
239 } |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
240 else if (item->contact->home_address) { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
241 if (item->contact->home_city) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
242 print_ldif_single("l", item->contact->home_city); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
243 if (item->contact->home_state) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
244 print_ldif_single("st", item->contact->home_state); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
245 if (item->contact->home_postal_code) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
246 print_ldif_single("postalCode", item->contact->home_postal_code); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
247 } |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
248 else if (item->contact->other_address) { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
249 print_ldif_address("postalAddress", 6, |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
250 item->contact->other_po_box, |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
251 item->contact->other_street, |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
252 item->contact->other_city, |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
253 item->contact->other_state, |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
254 item->contact->other_postal_code, |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
255 item->contact->other_country); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
256 if (item->contact->other_city) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
257 print_ldif_single("l", item->contact->other_city); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
258 if (item->contact->other_state) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
259 print_ldif_single("st", item->contact->other_state); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
260 if (item->contact->other_postal_code) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
261 print_ldif_single("postalCode", item->contact->other_postal_code); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
262 } |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
263 if (item->contact->home_address) { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
264 print_ldif_address("homePostalAddress", 6, |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
265 item->contact->home_po_box, |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
266 item->contact->home_street, |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
267 item->contact->home_city, |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
268 item->contact->home_state, |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
269 item->contact->home_postal_code, |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
270 item->contact->home_country); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
271 } |
79
56fa05fd5271
Patch from Robert Simpson for encryption type 2.
Carl Byington <carl@five-ten-sg.com>
parents:
73
diff
changeset
|
272 } |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
273 |
79
56fa05fd5271
Patch from Robert Simpson for encryption type 2.
Carl Byington <carl@five-ten-sg.com>
parents:
73
diff
changeset
|
274 if (item->contact->business_fax) |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
275 print_ldif_single("facsimileTelephoneNumber", item->contact->business_fax); |
79
56fa05fd5271
Patch from Robert Simpson for encryption type 2.
Carl Byington <carl@five-ten-sg.com>
parents:
73
diff
changeset
|
276 else if (item->contact->home_fax) |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
277 print_ldif_single("facsimileTelephoneNumber", item->contact->home_fax); |
16 | 278 |
79
56fa05fd5271
Patch from Robert Simpson for encryption type 2.
Carl Byington <carl@five-ten-sg.com>
parents:
73
diff
changeset
|
279 if (item->contact->business_phone) |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
280 print_ldif_single("telephoneNumber", item->contact->business_phone); |
79
56fa05fd5271
Patch from Robert Simpson for encryption type 2.
Carl Byington <carl@five-ten-sg.com>
parents:
73
diff
changeset
|
281 if (item->contact->home_phone) |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
282 print_ldif_single("homePhone", item->contact->home_phone); |
16 | 283 |
79
56fa05fd5271
Patch from Robert Simpson for encryption type 2.
Carl Byington <carl@five-ten-sg.com>
parents:
73
diff
changeset
|
284 if (item->contact->car_phone) |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
285 print_ldif_single("mobile", item->contact->car_phone); |
79
56fa05fd5271
Patch from Robert Simpson for encryption type 2.
Carl Byington <carl@five-ten-sg.com>
parents:
73
diff
changeset
|
286 else if (item->contact->mobile_phone) |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
287 print_ldif_single("mobile", item->contact->mobile_phone); |
79
56fa05fd5271
Patch from Robert Simpson for encryption type 2.
Carl Byington <carl@five-ten-sg.com>
parents:
73
diff
changeset
|
288 else if (item->contact->other_phone) |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
289 print_ldif_single("mobile", item->contact->other_phone); |
16 | 290 |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
291 if (!old_schema) { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
292 if (item->contact->business_homepage) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
293 print_ldif_single("labeledURI", item->contact->business_homepage); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
294 if (item->contact->personal_homepage) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
295 print_ldif_single("labeledURI", item->contact->personal_homepage); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
296 } |
16 | 297 |
79
56fa05fd5271
Patch from Robert Simpson for encryption type 2.
Carl Byington <carl@five-ten-sg.com>
parents:
73
diff
changeset
|
298 if (item->comment) |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
299 print_ldif_single("description", item->comment); |
16 | 300 |
106
07d090676ce9
cleanup fedora9 compile warnings
Carl Byington <carl@five-ten-sg.com>
parents:
105
diff
changeset
|
301 for (vector<string>::size_type i=0; i<ldap_class.size(); i++) |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
302 print_ldif_single("objectClass", ldap_class[i].c_str()); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
303 printf("\n"); |
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:
59
diff
changeset
|
304 } |
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:
59
diff
changeset
|
305 } |
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:
59
diff
changeset
|
306 else { |
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:
59
diff
changeset
|
307 DEBUG_INFO(("item is not a contact\n")); |
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:
59
diff
changeset
|
308 } |
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:
59
diff
changeset
|
309 } |
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:
59
diff
changeset
|
310 pst_freeItem(item); |
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:
59
diff
changeset
|
311 } |
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:
59
diff
changeset
|
312 d_ptr = d_ptr->next; |
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:
59
diff
changeset
|
313 } |
16 | 314 } |
315 | |
316 | |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
317 // Prints an attribute together with its value. |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
318 // If the value isn't a "SAFE STRING" (as defined in RFC2849), |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
319 // then it is output as a BASE-64 encoded value |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
320 void print_ldif_single(const char *attr, const char *value) |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
321 { |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
322 size_t len; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
323 bool is_safe_string = true; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
324 bool needs_code_conversion = false; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
325 bool space_flag = false; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
326 |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
327 // Strip leading spaces |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
328 while (*value == ' ') value++; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
329 len = strlen(value) + 1; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
330 char buffer[len]; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
331 char *p = buffer; |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
332 |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
333 // See if "value" is a "SAFE STRING" |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
334 // First check characters that are safe but not safe as initial characters |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
335 if (*value == ':' || *value == '<') |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
336 is_safe_string = false; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
337 for (;;) { |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
338 char ch = *value++; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
339 |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
340 if (ch == 0 || ch == '\n') |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
341 break; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
342 else if (ch == '\r') |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
343 continue; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
344 else if (ch == ' ') { |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
345 space_flag = true; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
346 continue; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
347 } |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
348 else { |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
349 if ((ch & 0x80) == 0x80) { |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
350 needs_code_conversion = true; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
351 is_safe_string = false; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
352 } |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
353 if (space_flag) { |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
354 *p++ = ' '; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
355 space_flag = false; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
356 } |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
357 *p++ = ch; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
358 } |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
359 } |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
360 *p = 0; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
361 if (is_safe_string) { |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
362 printf("%s: %s\n", attr, buffer); |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
363 return; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
364 } |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
365 |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
366 if (needs_code_conversion && cd != 0) { |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
367 size_t inlen = p - buffer; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
368 size_t utf8_len = 2 * inlen + 1; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
369 char utf8_buffer[utf8_len]; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
370 char *utf8_p = utf8_buffer; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
371 |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
372 iconv(cd, NULL, NULL, NULL, NULL); |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
373 p = buffer; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
374 int ret = iconv(cd, &p, &inlen, &utf8_p, &utf8_len); |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
375 |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
376 if (ret >= 0) { |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
377 *utf8_p = 0; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
378 p = base64_encode(utf8_buffer, utf8_p - utf8_buffer); |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
379 } |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
380 else |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
381 p = base64_encode(buffer, strlen(buffer)); |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
382 } |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
383 else |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
384 p = base64_encode(buffer, strlen(buffer)); |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
385 printf("%s:: %s\n", attr, p); |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
386 free(p); |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
387 } |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
388 |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
389 |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
390 // Combines values representing address lines into an address,i |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
391 // lines separated with "$" as per PostalAddress syntax in RFC4517 |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
392 void print_ldif_address(const char *attr, int nvalues, char *value, ...) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
393 { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
394 bool space_flag = false; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
395 bool newline_flag = false; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
396 char *address = NULL; // Buffer where address is built up |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
397 int len = 0; // Length of buffer |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
398 int i = 0; // Index of next character position in buffer |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
399 va_list ap; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
400 |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
401 va_start(ap, value); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
402 |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
403 while (!value) { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
404 nvalues--; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
405 if (nvalues == 0) { // Nothing at all to do! |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
406 va_end(ap); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
407 return; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
408 } |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
409 value = va_arg(ap, char *); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
410 } |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
411 for (;;) { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
412 char ch = *value++; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
413 |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
414 if (ch == 0 || ch == '\n') { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
415 do { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
416 value = NULL; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
417 nvalues--; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
418 if (nvalues == 0) break; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
419 value = va_arg(ap, char *); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
420 } while (!value); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
421 if (!value) break; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
422 space_flag = true; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
423 newline_flag = true; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
424 } |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
425 else if (ch == '\r') |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
426 continue; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
427 else if (ch == '\n') { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
428 newline_flag = true; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
429 continue; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
430 } |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
431 else if (ch == ' ') { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
432 space_flag = true; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
433 continue; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
434 } |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
435 else { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
436 if (i > (len-5)) { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
437 len += 256; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
438 address = (char *)realloc(address, len); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
439 } |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
440 if (newline_flag) { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
441 address[i++] = '$'; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
442 newline_flag = false; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
443 space_flag = false; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
444 } |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
445 else if (space_flag) { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
446 address[i++] = ' '; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
447 space_flag = false; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
448 } |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
449 if (ch == '$' || ch == '\\') address[i++] = '\\'; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
450 address[i++] = ch; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
451 } |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
452 } |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
453 va_end(ap); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
454 if (i == 0) return; // Nothing to do |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
455 address[i] = 0; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
456 print_ldif_single(attr, address); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
457 free(address); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
458 } |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
459 |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
460 |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
461 void print_ldif_multi(const char *dn, const char *value) |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
462 { |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
463 const char *n; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
464 while ((n = strchr(value, '\n'))) { |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
465 print_ldif_single(dn, value); |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
466 value = n + 1; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
467 } |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
468 print_ldif_single(dn, value); |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
469 } |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
470 |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
471 |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
472 void print_ldif_two(const char *attr, const char *value1, const char *value2) |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
473 { |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
474 size_t len1, len2; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
475 if (value1 && *value1) |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
476 len1 = strlen(value1); |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
477 else { |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
478 print_ldif_single(attr, value2); |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
479 return; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
480 } |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
481 |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
482 if (value2 && *value2) |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
483 len2 = strlen(value2); |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
484 else { |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
485 print_ldif_single(attr, value1); |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
486 return; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
487 } |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
488 |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
489 char value[len1 + len2 + 2]; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
490 memcpy(value, value1, len1); |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
491 value[len1] = ' '; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
492 memcpy(value + len1 + 1, value2, len2 + 1); |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
493 print_ldif_single(attr, value); |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
494 } |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
495 |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
496 |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
497 void build_cn(char *cn, size_t len, int nvalues, char *value, ...) |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
498 { |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
499 bool space_flag = false; |
105
4703d622e95b
cleanup fedora9 compile warnings
Carl Byington <carl@five-ten-sg.com>
parents:
104
diff
changeset
|
500 size_t i = 0; |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
501 va_list ap; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
502 |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
503 va_start(ap, value); |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
504 |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
505 while (!value) { |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
506 nvalues--; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
507 if (nvalues == 0) { |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
508 cn[0] = 0; // Just a terminating NUL |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
509 va_end(ap); |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
510 return; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
511 } |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
512 value = va_arg(ap, char *); |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
513 } |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
514 for (;;) { |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
515 char ch = *value++; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
516 |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
517 if (ch == 0 || ch == '\n') { |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
518 do { |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
519 value = NULL; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
520 nvalues--; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
521 if (nvalues == 0) break; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
522 value = va_arg(ap, char *); |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
523 } while (!value); |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
524 if (!value) break; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
525 space_flag = true; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
526 } |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
527 else if (ch == '\r') |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
528 continue; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
529 else if (ch == ' ') { |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
530 space_flag = true; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
531 continue; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
532 } |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
533 else { |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
534 if (space_flag) { |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
535 if (i > 0) { |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
536 if (i < (len - 2)) cn[i++] = ' '; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
537 else break; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
538 } |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
539 space_flag = false; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
540 } |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
541 if (i < (len - 1)) cn[i++] = ch; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
542 else break; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
543 } |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
544 } |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
545 cn[i] = 0; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
546 va_end(ap); |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
547 } |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
548 |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
549 |
16 | 550 int main(int argc, char** argv) { |
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:
59
diff
changeset
|
551 pst_desc_ll *d_ptr; |
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:
59
diff
changeset
|
552 char *fname = NULL; |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
553 int c; |
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:
59
diff
changeset
|
554 char *d_log = NULL; |
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:
59
diff
changeset
|
555 prog_name = argv[0]; |
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:
59
diff
changeset
|
556 pst_item *item = NULL; |
16 | 557 |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
558 while ((c = getopt(argc, argv, "b:c:C:d:l:oVh"))!= -1) { |
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:
59
diff
changeset
|
559 switch (c) { |
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:
59
diff
changeset
|
560 case 'b': |
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:
59
diff
changeset
|
561 ldap_base = optarg; |
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:
59
diff
changeset
|
562 break; |
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:
59
diff
changeset
|
563 case 'c': |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
564 ldap_class.push_back(string(optarg)); |
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:
59
diff
changeset
|
565 break; |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
566 case 'C': |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
567 cd = iconv_open("UTF-8", optarg); |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
568 if (cd == (iconv_t)(-1)) { |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
569 fprintf(stderr, "I don't know character set \"%s\"!\n\n", optarg); |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
570 fprintf(stderr, "Type: \"iconv --list\" to get list of known character sets\n"); |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
571 return 1; |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
572 } |
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
573 break; |
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:
59
diff
changeset
|
574 case 'd': |
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:
59
diff
changeset
|
575 d_log = optarg; |
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:
59
diff
changeset
|
576 break; |
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:
59
diff
changeset
|
577 case 'h': |
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:
59
diff
changeset
|
578 usage(); |
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:
59
diff
changeset
|
579 exit(0); |
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:
59
diff
changeset
|
580 break; |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
581 case 'l': |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
582 ldif_extra_line.push_back(string(optarg)); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
583 break; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
584 case 'o': |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
585 old_schema = true; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
586 break; |
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:
59
diff
changeset
|
587 case 'V': |
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:
59
diff
changeset
|
588 version(); |
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:
59
diff
changeset
|
589 exit(0); |
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:
59
diff
changeset
|
590 break; |
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:
59
diff
changeset
|
591 default: |
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:
59
diff
changeset
|
592 usage(); |
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:
59
diff
changeset
|
593 exit(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:
59
diff
changeset
|
594 break; |
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:
59
diff
changeset
|
595 } |
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:
59
diff
changeset
|
596 } |
16 | 597 |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
598 if ((argc > optind) && (ldap_base)) { |
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:
59
diff
changeset
|
599 fname = argv[optind]; |
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:
59
diff
changeset
|
600 } else { |
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:
59
diff
changeset
|
601 usage(); |
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:
59
diff
changeset
|
602 exit(2); |
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:
59
diff
changeset
|
603 } |
16 | 604 |
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:
59
diff
changeset
|
605 #ifdef DEBUG_ALL |
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:
59
diff
changeset
|
606 // force a log file |
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:
59
diff
changeset
|
607 if (!d_log) d_log = "pst2ldif.log"; |
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:
59
diff
changeset
|
608 #endif |
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:
59
diff
changeset
|
609 DEBUG_INIT(d_log); |
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:
59
diff
changeset
|
610 DEBUG_REGISTER_CLOSE(); |
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:
59
diff
changeset
|
611 DEBUG_ENT("main"); |
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:
59
diff
changeset
|
612 RET_DERROR(pst_open(&pstfile, fname), 1, ("Error opening File\n")); |
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:
59
diff
changeset
|
613 RET_DERROR(pst_load_index(&pstfile), 2, ("Index Error\n")); |
16 | 614 |
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:
59
diff
changeset
|
615 pst_load_extended_attributes(&pstfile); |
16 | 616 |
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:
59
diff
changeset
|
617 d_ptr = pstfile.d_head; // first record is main record |
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:
59
diff
changeset
|
618 item = (pst_item*)pst_parse_item(&pstfile, d_ptr); |
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:
59
diff
changeset
|
619 if (!item || !item->message_store) { |
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:
59
diff
changeset
|
620 DEBUG_RET(); |
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:
59
diff
changeset
|
621 DIE(("main: Could not get root record\n")); |
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:
59
diff
changeset
|
622 } |
16 | 623 |
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:
59
diff
changeset
|
624 d_ptr = pst_getTopOfFolders(&pstfile, item); |
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:
59
diff
changeset
|
625 if (!d_ptr) { |
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:
59
diff
changeset
|
626 DEBUG_RET(); |
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:
59
diff
changeset
|
627 DIE(("Top of folders record not found. Cannot continue\n")); |
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:
59
diff
changeset
|
628 } |
16 | 629 |
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:
59
diff
changeset
|
630 pst_freeItem(item); |
16 | 631 |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
632 if (old_schema && (strlen(ldap_base) > 2)) { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
633 char *ldap_org = strdup(ldap_base+2); // assume first 2 chars are o= |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
634 char *temp = strchr(ldap_org, ','); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
635 if (temp) { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
636 *temp = '\0'; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
637 // write the ldap header |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
638 printf("dn: %s\n", ldap_base); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
639 printf("o: %s\n", ldap_org); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
640 printf("objectClass: organization\n\n"); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
641 printf("dn: cn=root, %s\n", ldap_base); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
642 printf("cn: root\n"); |
108
1b2a4fac1303
fix title bug with old schema in pst2ldif, also escape commas in distinguished names per rfc4514.
Carl Byington <carl@five-ten-sg.com>
parents:
106
diff
changeset
|
643 printf("sn: root\n"); |
106
07d090676ce9
cleanup fedora9 compile warnings
Carl Byington <carl@five-ten-sg.com>
parents:
105
diff
changeset
|
644 for (vector<string>::size_type i=0; i<ldap_class.size(); i++) |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
645 print_ldif_single("objectClass", ldap_class[i].c_str()); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
646 printf("\n"); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
647 } |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
648 } |
16 | 649 |
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:
59
diff
changeset
|
650 process(d_ptr->child); // do the children of TOPF |
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:
59
diff
changeset
|
651 pst_close(&pstfile); |
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:
59
diff
changeset
|
652 DEBUG_RET(); |
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:
59
diff
changeset
|
653 free_strings(all_strings); |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
654 if (cd) iconv_close(cd); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
655 |
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:
59
diff
changeset
|
656 return 0; |
16 | 657 } |
658 | |
659 | |
660 int usage() { | |
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:
59
diff
changeset
|
661 version(); |
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:
59
diff
changeset
|
662 printf("Usage: %s [OPTIONS] {PST FILENAME}\n", prog_name); |
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:
59
diff
changeset
|
663 printf("OPTIONS:\n"); |
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:
59
diff
changeset
|
664 printf("\t-V\t- Version. Display program version\n"); |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
665 printf("\t-C charset\t- assumed character set of non-ASCII characters\n"); |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
666 printf("\t-b ldapbase\t- set the LDAP base value\n"); |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
667 printf("\t-c class\t- set the class of the LDAP objects (may contain more than one)\n"); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
668 printf("\t-d <filename>\t- Debug to file. This is a binary log. Use readpstlog to print it\n"); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
669 printf("\t-h\t- Help. This screen\n"); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
670 printf("\t-l line\t- extra line to insert in the LDIF file for each contact\n"); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
671 printf("\t-o\t- use old schema, default is new schema\n"); |
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:
59
diff
changeset
|
672 return 0; |
16 | 673 } |
674 | |
675 | |
676 int version() { | |
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:
59
diff
changeset
|
677 printf("pst2ldif v%s\n", VERSION); |
16 | 678 #if BYTE_ORDER == BIG_ENDIAN |
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:
59
diff
changeset
|
679 printf("Big Endian implementation being used.\n"); |
16 | 680 #elif BYTE_ORDER == LITTLE_ENDIAN |
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:
59
diff
changeset
|
681 printf("Little Endian implementation being used.\n"); |
16 | 682 #else |
683 # error "Byte order not supported by this library" | |
684 #endif | |
685 #ifdef __GNUC__ | |
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:
59
diff
changeset
|
686 printf("GCC %d.%d : %s %s\n", __GNUC__, __GNUC_MINOR__, __DATE__, __TIME__); |
16 | 687 #endif |
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:
59
diff
changeset
|
688 return 0; |
16 | 689 } |
690 | |
691 | |
692 char *check_filename(char *fname) { | |
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:
59
diff
changeset
|
693 char *t = fname; |
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:
59
diff
changeset
|
694 if (t == NULL) { |
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:
59
diff
changeset
|
695 return fname; |
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:
59
diff
changeset
|
696 } |
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:
59
diff
changeset
|
697 while ((t = strpbrk(t, "/\\:"))) { |
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:
59
diff
changeset
|
698 // while there are characters in the second string that we don't want |
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:
59
diff
changeset
|
699 *t = '_'; //replace them with an underscore |
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:
59
diff
changeset
|
700 } |
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:
59
diff
changeset
|
701 return fname; |
16 | 702 } |
703 | |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
704 |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
705 // This function escapes Distinguished Names (as per RFC4514) |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
706 void print_ldif_dn(const char *attr, const char *value, const char *base) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
707 { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
708 printf("dn: cn="); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
709 // remove leading spaces (RFC says escape them) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
710 while (*value == ' ') |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
711 value++; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
712 |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
713 print_escaped_dn(value); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
714 if (base && base[0]) { |
108
1b2a4fac1303
fix title bug with old schema in pst2ldif, also escape commas in distinguished names per rfc4514.
Carl Byington <carl@five-ten-sg.com>
parents:
106
diff
changeset
|
715 printf(", %s", base); |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
716 } |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
717 printf("\n"); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
718 return; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
719 } |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
720 |
16 | 721 |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
722 void print_escaped_dn(const char *value) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
723 { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
724 char ch; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
725 bool needs_code_conversion = false; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
726 char *utf8_buffer = NULL; |
16 | 727 |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
728 // First do a quick scan to see if any code conversion is required |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
729 if (cd) { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
730 const char *p = value; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
731 while (*p) { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
732 if (*p++ & 0x80) { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
733 needs_code_conversion = true; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
734 break; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
735 } |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
736 } |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
737 } |
16 | 738 |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
739 if (needs_code_conversion) { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
740 size_t inlen = strlen(value); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
741 size_t utf8_len = 2 * inlen + 1; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
742 char *p = (char *)value; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
743 char *utf8_p = utf8_buffer; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
744 |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
745 utf8_buffer = (char *)malloc(utf8_len); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
746 utf8_p = utf8_buffer; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
747 iconv(cd, NULL, NULL, NULL, NULL); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
748 if (iconv(cd, &p, &inlen, &utf8_p, &utf8_len) >= 0) { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
749 *utf8_p = 0; |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
750 value = utf8_buffer; |
99
b7f456946c5b
add configure option --enable-dii=no to remove dependency on libgd.
Carl Byington <carl@five-ten-sg.com>
parents:
79
diff
changeset
|
751 } |
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:
59
diff
changeset
|
752 } |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
753 |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
754 // escape initial '#' and space |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
755 if (*value == '#' || *value == ' ') |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
756 putchar('\\'); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
757 |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
758 while ((ch = *value++) != 0) { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
759 if (((ch & 0x80) != 0) || (ch <= 0x1F)) |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
760 // Print as escaped hex digits |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
761 printf("\\%2.2X", ch & 0xFF); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
762 else switch (ch) { |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
763 case '\\': |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
764 case '"' : |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
765 case '+' : |
108
1b2a4fac1303
fix title bug with old schema in pst2ldif, also escape commas in distinguished names per rfc4514.
Carl Byington <carl@five-ten-sg.com>
parents:
106
diff
changeset
|
766 case ',' : |
104
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
767 case ';' : |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
768 case '<' : |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
769 case '>' : |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
770 putchar('\\'); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
771 // Fall through |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
772 default: |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
773 putchar(ch); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
774 } |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
775 } |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
776 if (utf8_buffer) free((void *)utf8_buffer); |
39ba19372732
many fixes in pst2ldif by Robert Harris
Carl Byington <carl@five-ten-sg.com>
parents:
99
diff
changeset
|
777 return; |
16 | 778 } |