annotate src/pst2ldif.cpp @ 69:63c02a242ca9

minor code cleanup
author Carl Byington <carl@five-ten-sg.com>
date Sat, 10 May 2008 12:45:23 -0700
parents 7d5c637aaafb
children 3cb02cb1e6cd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1 /*
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
2
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
3 Copyright (c) 2004 Carl Byington - 510 Software Group, released under
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
4 the GPL version 2 or any later version at your choice available at
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
5 http://www.fsf.org/licenses/gpl.txt
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
6
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
7 Based on readpst.c by David Smith
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
8
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
9 */
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
10
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
11 using namespace std;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
12
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
13 // needed for std c++ collections
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
14 #include <set>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
15
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
16 extern "C" {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
17 #include "define.h"
59
7d5c637aaafb General cleanup and code fixes.
Carl Byington <carl@five-ten-sg.com>
parents: 52
diff changeset
18 #include "libstrfunc.h"
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
19 #include "libpst.h"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
20 #include "common.h"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
21 #include "timeconv.h"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
22 #include "lzfu.h"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
23 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
24
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
25 int32_t usage();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
26 int32_t version();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
27 char *my_stristr(char *haystack, char *needle);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
28 char *check_filename(char *fname);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
29 char *single(char *str);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
30 char *folded(char *str);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
31 void multi(char *fmt, char *str);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
32 char *rfc2426_escape(char *str);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
33 int32_t chr_count(char *str, char x);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
34
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
35 char *prog_name;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
36 pst_file pstfile;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
37 char *ldap_base = NULL; // 'o=some.domain.tld, c=US'
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
38 char *ldap_class = NULL; // 'newPerson'
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
39 char *ldap_org = NULL; // 'o=some.domain.tld', computed from ldap_base
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
40
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
41
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
42 ////////////////////////////////////////////////
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
43 // define our ordering
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
44 struct ltstr {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
45 bool operator()(char* s1, char* s2) const {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
46 return strcasecmp(s1, s2) < 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
47 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
48 };
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
49 // define our set
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
50 typedef set<char *, ltstr> string_set;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
51 // make a static set to hold the cn values
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
52 static string_set all_strings;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
53
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
54
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
55 ////////////////////////////////////////////////
41
183ae993b9ad security fix for potential buffer overrun in lz decompress
carl
parents: 38
diff changeset
56 // helper to free all the strings in a set
183ae993b9ad security fix for potential buffer overrun in lz decompress
carl
parents: 38
diff changeset
57 //
183ae993b9ad security fix for potential buffer overrun in lz decompress
carl
parents: 38
diff changeset
58 static void free_strings(string_set &s);
183ae993b9ad security fix for potential buffer overrun in lz decompress
carl
parents: 38
diff changeset
59 static void free_strings(string_set &s)
183ae993b9ad security fix for potential buffer overrun in lz decompress
carl
parents: 38
diff changeset
60 {
183ae993b9ad security fix for potential buffer overrun in lz decompress
carl
parents: 38
diff changeset
61 for (string_set::iterator i=s.begin(); i!=s.end(); i++) {
183ae993b9ad security fix for potential buffer overrun in lz decompress
carl
parents: 38
diff changeset
62 free(*i);
183ae993b9ad security fix for potential buffer overrun in lz decompress
carl
parents: 38
diff changeset
63 }
183ae993b9ad security fix for potential buffer overrun in lz decompress
carl
parents: 38
diff changeset
64 s.clear();
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
183ae993b9ad security fix for potential buffer overrun in lz decompress
carl
parents: 38
diff changeset
67
183ae993b9ad security fix for potential buffer overrun in lz decompress
carl
parents: 38
diff changeset
68 ////////////////////////////////////////////////
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
69 // helper to register a string in a string set
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
70 //
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
71 static char* register_string(string_set &s, char *name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
72 static char* register_string(string_set &s, char *name) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
73 string_set::iterator i = s.find(name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
74 if (i != s.end()) return *i;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
75 char *x = strdup(name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
76 s.insert(x);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
77 return x;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
78 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
79
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
80 ////////////////////////////////////////////////
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
81 // register a global string
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
82 //
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
83 static char* register_string(char *name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
84 static char* register_string(char *name) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
85 return register_string(all_strings, name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
86 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
87
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
88
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
89 ////////////////////////////////////////////////
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
90 // make a unique string
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
91 //
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
92 static char* unique_string(char *name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
93 static char* unique_string(char *name) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
94 int unique = 2;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
95 string_set::iterator i = all_strings.find(name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
96 if (i == all_strings.end()) return register_string(name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
97 while (true) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
98 char n[strlen(name)+10];
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
99 snprintf(n, sizeof(n), "%s %d", name, unique++);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
100 string_set::iterator i = all_strings.find(n);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
101 if (i == all_strings.end()) return register_string(n);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
102 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
103 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
104
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
105
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
106 ////////////////////////////////////////////////
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
107 // remove leading and trailing blanks
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
108 //
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
109 static char *trim(char *name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
110 static char *trim(char *name) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
111 char *p;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
112 while (*name == ' ') name++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
113 p = name + strlen(name) - 1;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
114 while ((p >= name) && (*p == ' ')) *p-- = '\0';
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
115 return name;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
116 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
117
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
118
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
119 static void process(pst_desc_ll *d_ptr);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
120 static void process(pst_desc_ll *d_ptr) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
121 pst_item *item = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
122 while (d_ptr) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
123 if (d_ptr->desc) {
52
034641c26ab9 code cleanup
carl
parents: 46
diff changeset
124 item = pst_parse_item(&pstfile, d_ptr);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
125 DEBUG_INFO(("item pointer is %p\n", item));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
126 if (item) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
127 if (item->message_store) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
128 // there should only be one message_store, and we have already done it
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
129 DIE(("main: A second message_store has been found. Sorry, this must be an error.\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
130 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
131
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
132 if (item->folder && d_ptr->child && strcasecmp(item->file_as, "Deleted Items")) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
133 //if this is a non-empty folder other than deleted items, we want to recurse into it
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
134 fprintf(stderr, "entering folder %s\n", item->file_as);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
135 process(d_ptr->child);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
136 } else if (item->contact) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
137 // deal with a contact
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
138 if (item->type != PST_TYPE_CONTACT) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
139 DIE(("type should be contact\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
140 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
141 else if (item->contact == NULL) { // this is an incorrect situation. Inform user
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
142 DIE(("null item contact\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
143 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
144 char cn[1000];
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
145 snprintf(cn, sizeof(cn), "%s %s %s %s",
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
146 single(item->contact->display_name_prefix),
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
147 single(item->contact->first_name),
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
148 single(item->contact->surname),
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
149 single(item->contact->suffix));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
150 if (strcmp(cn, " ")) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
151 // fprintf(stderr, "\n\n\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
152 // fprintf(stderr, "access_method %s\n", item->contact->access_method);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
153 // fprintf(stderr, "account_name %s\n", item->contact->account_name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
154 // fprintf(stderr, "address1 %s\n", item->contact->address1);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
155 // fprintf(stderr, "address1_desc %s\n", item->contact->address1_desc);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
156 // fprintf(stderr, "address1_transport %s\n", item->contact->address1_transport);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
157 // fprintf(stderr, "address2 %s\n", item->contact->address2);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
158 // fprintf(stderr, "address2_desc %s\n", item->contact->address2_desc);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
159 // fprintf(stderr, "address2_transport %s\n", item->contact->address2_transport);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
160 // fprintf(stderr, "address3 %s\n", item->contact->address3);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
161 // fprintf(stderr, "address3_desc %s\n", item->contact->address3_desc);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
162 // fprintf(stderr, "address3_transport %s\n", item->contact->address3_transport);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
163 // fprintf(stderr, "assistant_name %s\n", item->contact->assistant_name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
164 // fprintf(stderr, "assistant_phone %s\n", item->contact->assistant_phone);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
165 // fprintf(stderr, "billing_information %s\n", item->contact->billing_information);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
166 // fprintf(stderr, "business_address %s\n", item->contact->business_address);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
167 // fprintf(stderr, "business_city %s\n", item->contact->business_city);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
168 // fprintf(stderr, "business_country %s\n", item->contact->business_country);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
169 // fprintf(stderr, "business_fax %s\n", item->contact->business_fax);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
170 // fprintf(stderr, "business_homepage %s\n", item->contact->business_homepage);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
171 // fprintf(stderr, "business_phone %s\n", item->contact->business_phone);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
172 // fprintf(stderr, "business_phone2 %s\n", item->contact->business_phone2);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
173 // fprintf(stderr, "business_po_box %s\n", item->contact->business_po_box);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
174 // fprintf(stderr, "business_postal_code %s\n", item->contact->business_postal_code);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
175 // fprintf(stderr, "business_state %s\n", item->contact->business_state);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
176 // fprintf(stderr, "business_street %s\n", item->contact->business_street);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
177 // fprintf(stderr, "callback_phone %s\n", item->contact->callback_phone);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
178 // fprintf(stderr, "car_phone %s\n", item->contact->car_phone);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
179 // fprintf(stderr, "company_main_phone %s\n", item->contact->company_main_phone);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
180 // fprintf(stderr, "company_name %s\n", item->contact->company_name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
181 // fprintf(stderr, "computer_name %s\n", item->contact->computer_name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
182 // fprintf(stderr, "customer_id %s\n", item->contact->customer_id);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
183 // fprintf(stderr, "def_postal_address %s\n", item->contact->def_postal_address);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
184 // fprintf(stderr, "department %s\n", item->contact->department);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
185 // fprintf(stderr, "display_name_prefix %s\n", item->contact->display_name_prefix);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
186 // fprintf(stderr, "first_name %s\n", item->contact->first_name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
187 // fprintf(stderr, "followup %s\n", item->contact->followup);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
188 // fprintf(stderr, "free_busy_address %s\n", item->contact->free_busy_address);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
189 // fprintf(stderr, "ftp_site %s\n", item->contact->ftp_site);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
190 // fprintf(stderr, "fullname %s\n", item->contact->fullname);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
191 // fprintf(stderr, "gov_id %s\n", item->contact->gov_id);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
192 // fprintf(stderr, "hobbies %s\n", item->contact->hobbies);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
193 // fprintf(stderr, "home_address %s\n", item->contact->home_address);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
194 // fprintf(stderr, "home_city %s\n", item->contact->home_city);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
195 // fprintf(stderr, "home_country %s\n", item->contact->home_country);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
196 // fprintf(stderr, "home_fax %s\n", item->contact->home_fax);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
197 // fprintf(stderr, "home_phone %s\n", item->contact->home_phone);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
198 // fprintf(stderr, "home_phone2 %s\n", item->contact->home_phone2);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
199 // fprintf(stderr, "home_po_box %s\n", item->contact->home_po_box);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
200 // fprintf(stderr, "home_postal_code %s\n", item->contact->home_postal_code);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
201 // fprintf(stderr, "home_state %s\n", item->contact->home_state);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
202 // fprintf(stderr, "home_street %s\n", item->contact->home_street);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
203 // fprintf(stderr, "initials %s\n", item->contact->initials);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
204 // fprintf(stderr, "isdn_phone %s\n", item->contact->isdn_phone);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
205 // fprintf(stderr, "job_title %s\n", item->contact->job_title);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
206 // fprintf(stderr, "keyword %s\n", item->contact->keyword);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
207 // fprintf(stderr, "language %s\n", item->contact->language);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
208 // fprintf(stderr, "location %s\n", item->contact->location);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
209 // fprintf(stderr, "manager_name %s\n", item->contact->manager_name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
210 // fprintf(stderr, "middle_name %s\n", item->contact->middle_name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
211 // fprintf(stderr, "mileage %s\n", item->contact->mileage);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
212 // fprintf(stderr, "mobile_phone %s\n", item->contact->mobile_phone);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
213 // fprintf(stderr, "nickname %s\n", item->contact->nickname);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
214 // fprintf(stderr, "office_loc %s\n", item->contact->office_loc);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
215 // fprintf(stderr, "org_id %s\n", item->contact->org_id);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
216 // fprintf(stderr, "other_address %s\n", item->contact->other_address);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
217 // fprintf(stderr, "other_city %s\n", item->contact->other_city);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
218 // fprintf(stderr, "other_country %s\n", item->contact->other_country);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
219 // fprintf(stderr, "other_phone %s\n", item->contact->other_phone);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
220 // fprintf(stderr, "other_po_box %s\n", item->contact->other_po_box);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
221 // fprintf(stderr, "other_postal_code %s\n", item->contact->other_postal_code);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
222 // fprintf(stderr, "other_state %s\n", item->contact->other_state);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
223 // fprintf(stderr, "other_street %s\n", item->contact->other_street);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
224 // fprintf(stderr, "pager_phone %s\n", item->contact->pager_phone);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
225 // fprintf(stderr, "personal_homepage %s\n", item->contact->personal_homepage);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
226 // fprintf(stderr, "pref_name %s\n", item->contact->pref_name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
227 // fprintf(stderr, "primary_fax %s\n", item->contact->primary_fax);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
228 // fprintf(stderr, "primary_phone %s\n", item->contact->primary_phone);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
229 // fprintf(stderr, "profession %s\n", item->contact->profession);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
230 // fprintf(stderr, "radio_phone %s\n", item->contact->radio_phone);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
231 // fprintf(stderr, "spouse_name %s\n", item->contact->spouse_name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
232 // fprintf(stderr, "suffix %s\n", item->contact->suffix);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
233 // fprintf(stderr, "surname %s\n", item->contact->surname);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
234 // fprintf(stderr, "telex %s\n", item->contact->telex);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
235 // fprintf(stderr, "transmittable_display_name %s\n", item->contact->transmittable_display_name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
236 // fprintf(stderr, "ttytdd_phone %s\n", item->contact->ttytdd_phone);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
237 // have a valid cn
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
238 char *ucn = unique_string(folded(trim(cn)));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
239 printf("dn: cn=%s, %s\n", ucn, ldap_base);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
240 printf("cn: %s\n", ucn);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
241 if (item->contact->first_name) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
242 snprintf(cn, sizeof(cn), "%s %s",
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
243 single(item->contact->display_name_prefix),
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
244 single(item->contact->first_name));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
245 printf("givenName: %s\n", trim(cn));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
246 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
247 if (item->contact->surname) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
248 snprintf(cn, sizeof(cn), "%s %s",
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
249 single(item->contact->surname),
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
250 single(item->contact->suffix));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
251 printf("sn: %s\n", trim(cn));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
252 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
253 else if (item->contact->company_name) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
254 printf("sn: %s\n", single(item->contact->company_name));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
255 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
256 else
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
257 printf("sn: %s\n", ucn); // use cn as sn if we cannot find something better
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
258
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
259 if (item->contact->job_title)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
260 printf("personalTitle: %s\n", single(item->contact->job_title));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
261 if (item->contact->company_name)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
262 printf("company: %s\n", single(item->contact->company_name));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
263 if (item->contact->address1 && *item->contact->address1)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
264 printf("mail: %s\n", single(item->contact->address1));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
265 if (item->contact->address2 && *item->contact->address2)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
266 printf("mail: %s\n", single(item->contact->address2));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
267 if (item->contact->address3 && *item->contact->address3)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
268 printf("mail: %s\n", single(item->contact->address3));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
269 if (item->contact->address1a && *item->contact->address1a)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
270 printf("mail: %s\n", single(item->contact->address1a));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
271 if (item->contact->address2a && *item->contact->address2a)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
272 printf("mail: %s\n", single(item->contact->address2a));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
273 if (item->contact->address3a && *item->contact->address3a)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
274 printf("mail: %s\n", single(item->contact->address3a));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
275 if (item->contact->business_address) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
276 if (item->contact->business_po_box)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
277 printf("postalAddress: %s\n", single(item->contact->business_po_box));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
278 if (item->contact->business_street)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
279 multi("postalAddress: %s\n", item->contact->business_street);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
280 if (item->contact->business_city)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
281 printf("l: %s\n", single(item->contact->business_city));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
282 if (item->contact->business_state)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
283 printf("st: %s\n", single(item->contact->business_state));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
284 if (item->contact->business_postal_code)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
285 printf("postalCode: %s\n", single(item->contact->business_postal_code));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
286 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
287 else if (item->contact->home_address) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
288 if (item->contact->home_po_box)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
289 printf("postalAddress: %s\n", single(item->contact->home_po_box));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
290 if (item->contact->home_street)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
291 multi("postalAddress: %s\n", item->contact->home_street);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
292 if (item->contact->home_city)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
293 printf("l: %s\n", single(item->contact->home_city));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
294 if (item->contact->home_state)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
295 printf("st: %s\n", single(item->contact->home_state));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
296 if (item->contact->home_postal_code)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
297 printf("postalCode: %s\n", single(item->contact->home_postal_code));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
298 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
299 else if (item->contact->other_address) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
300 if (item->contact->other_po_box)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
301 printf("postalAddress: %s\n", single(item->contact->other_po_box));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
302 if (item->contact->other_street)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
303 multi("postalAddress: %s\n", item->contact->other_street);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
304 if (item->contact->other_city)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
305 printf("l: %s\n", single(item->contact->other_city));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
306 if (item->contact->other_state)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
307 printf("st: %s\n", single(item->contact->other_state));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
308 if (item->contact->other_postal_code)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
309 printf("postalCode: %s\n", single(item->contact->other_postal_code));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
310 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
311 if (item->contact->business_fax)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
312 printf("facsimileTelephoneNumber: %s\n", single(item->contact->business_fax));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
313 else if (item->contact->home_fax)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
314 printf("facsimileTelephoneNumber: %s\n", single(item->contact->home_fax));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
315
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
316 if (item->contact->business_phone)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
317 printf("telephoneNumber: %s\n", single(item->contact->business_phone));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
318 if (item->contact->home_phone)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
319 printf("homePhone: %s\n", single(item->contact->home_phone));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
320
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
321 if (item->contact->car_phone)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
322 printf("mobile: %s\n", single(item->contact->car_phone));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
323 else if (item->contact->mobile_phone)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
324 printf("mobile: %s\n", single(item->contact->mobile_phone));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
325 else if (item->contact->other_phone)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
326 printf("mobile: %s\n", single(item->contact->other_phone));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
327
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
328
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
329 if (item->comment)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
330 printf("description: %s\n", single(item->comment));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
331
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
332 printf("objectClass: %s\n\n", ldap_class);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
333 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
334 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
335 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
336 else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
337 DEBUG_INFO(("item is not a contact\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
338 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
339 }
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 41
diff changeset
340 pst_freeItem(item);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
341 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
342 d_ptr = d_ptr->next;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
343 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
344 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
345
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
346
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
347 int main(int argc, char** argv) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
348 pst_desc_ll *d_ptr;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
349 char *fname = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
350 char *temp = NULL; //temporary char pointer
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
351 char c;
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 22
diff changeset
352 char *d_log = NULL;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
353 prog_name = argv[0];
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
354 pst_item *item = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
355
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 22
diff changeset
356 while ((c = getopt(argc, argv, "b:c:d:Vh"))!= -1) {
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
357 switch (c) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
358 case 'b':
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
359 ldap_base = optarg;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
360 temp = strchr(ldap_base, ',');
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
361 if (temp) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
362 *temp = '\0';
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
363 ldap_org = strdup(ldap_base+2); // assume first 2 chars are o=
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
364 *temp = ',';
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
365 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
366 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
367 case 'c':
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
368 ldap_class = optarg;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
369 break;
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 22
diff changeset
370 case 'd':
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 22
diff changeset
371 d_log = optarg;
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 22
diff changeset
372 break;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
373 case 'h':
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
374 usage();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
375 exit(0);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
376 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
377 case 'V':
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
378 version();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
379 exit(0);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
380 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
381 default:
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
382 usage();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
383 exit(1);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
384 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
385 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
386 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
387
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
388 if ((argc > optind) && (ldap_base) && (ldap_class) && (ldap_org)) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
389 fname = argv[optind];
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
390 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
391 usage();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
392 exit(2);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
393 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
394
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
395 #ifdef DEBUG_ALL
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 22
diff changeset
396 // force a log file
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 22
diff changeset
397 if (!d_log) d_log = "pst2ldif.log";
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
398 #endif
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 22
diff changeset
399 DEBUG_INIT(d_log);
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 22
diff changeset
400 DEBUG_REGISTER_CLOSE();
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
401 DEBUG_ENT("main");
59
7d5c637aaafb General cleanup and code fixes.
Carl Byington <carl@five-ten-sg.com>
parents: 52
diff changeset
402 RET_DERROR(pst_open(&pstfile, fname), 1, ("Error opening File\n"));
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
403 RET_DERROR(pst_load_index(&pstfile), 2, ("Index Error\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
404
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
405 pst_load_extended_attributes(&pstfile);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
406
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
407 d_ptr = pstfile.d_head; // first record is main record
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 41
diff changeset
408 item = (pst_item*)pst_parse_item(&pstfile, d_ptr);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
409 if (!item || !item->message_store) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
410 DEBUG_RET();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
411 DIE(("main: Could not get root record\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
412 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
413
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
414 d_ptr = pst_getTopOfFolders(&pstfile, item);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
415 if (!d_ptr) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
416 DEBUG_RET();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
417 DIE(("Top of folders record not found. Cannot continue\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
418 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
419
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 41
diff changeset
420 pst_freeItem(item);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
421
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
422 // write the ldap header
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
423 printf("dn: %s\n", ldap_base);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
424 printf("o: %s\n", ldap_org);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
425 printf("objectClass: organization\n\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
426 printf("dn: cn=root, %s\n", ldap_base);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
427 printf("cn: root\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
428 printf("objectClass: %s\n\n", ldap_class);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
429
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
430 process(d_ptr->child); // do the children of TOPF
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
431 pst_close(&pstfile);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
432 DEBUG_RET();
41
183ae993b9ad security fix for potential buffer overrun in lz decompress
carl
parents: 38
diff changeset
433 free_strings(all_strings);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
434 return 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
435 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
436
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
437
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
438 int usage() {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
439 version();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
440 printf("Usage: %s [OPTIONS] {PST FILENAME}\n", prog_name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
441 printf("OPTIONS:\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
442 printf("\t-h\t- Help. This screen\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
443 printf("\t-V\t- Version. Display program version\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
444 printf("\t-b ldapbase\t- set the ldap base value\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
445 printf("\t-c class \t- set the class of the ldap objects\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
446 return 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
447 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
448
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
449
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
450 int version() {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
451 printf("pst2ldif v%s\n", VERSION);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
452 #if BYTE_ORDER == BIG_ENDIAN
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
453 printf("Big Endian implementation being used.\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
454 #elif BYTE_ORDER == LITTLE_ENDIAN
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
455 printf("Little Endian implementation being used.\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
456 #else
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
457 # error "Byte order not supported by this library"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
458 #endif
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
459 #ifdef __GNUC__
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
460 printf("GCC %d.%d : %s %s\n", __GNUC__, __GNUC_MINOR__, __DATE__, __TIME__);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
461 #endif
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
462 return 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
463 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
464
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
465
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
466 // my_stristr varies from strstr in that its searches are case-insensitive
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
467 char * my_stristr(char *haystack, char *needle) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
468 char *x=haystack, *y=needle, *z = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
469 if (haystack == NULL || needle == NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
470 return NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
471 while (*y != '\0' && *x != '\0') {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
472 if (tolower(*y) == tolower(*x)) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
473 // move y on one
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
474 y++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
475 if (z == NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
476 z = x; // store first position in haystack where a match is made
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
477 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
478 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
479 y = needle; // reset y to the beginning of the needle
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
480 z = NULL; // reset the haystack storage point
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
481 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
482 x++; // advance the search in the haystack
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
483 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
484 return z;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
485 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
486
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
487
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
488 char *check_filename(char *fname) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
489 char *t = fname;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
490 if (t == NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
491 return fname;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
492 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
493 while ((t = strpbrk(t, "/\\:"))) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
494 // while there are characters in the second string that we don't want
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
495 *t = '_'; //replace them with an underscore
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
496 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
497 return fname;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
498 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
499
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
500
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
501 char *single(char *str) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
502 if (!str) return "";
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
503 char *ret = rfc2426_escape(str);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
504 char *n = strchr(ret, '\n');
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
505 if (n) *n = '\0';
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
506 return ret;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
507 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
508
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
509
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
510 char *folded(char *str) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
511 if (!str) return "";
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
512 char *ret = rfc2426_escape(str);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
513 char *n = ret;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
514 while (n = strchr(n, '\n')) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
515 *n = ' ';
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
516 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
517 n = ret;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
518 while (n = strchr(n, ',')) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
519 *n = ' ';
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
520 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
521 return ret;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
522 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
523
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
524
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
525 void multi(char *fmt, char *str) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
526 if (!str) return;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
527 char *ret = rfc2426_escape(str);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
528 char *n = ret;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
529 while (n = strchr(ret, '\n')) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
530 *n = '\0';
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
531 printf(fmt, ret);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
532 ret = n+1;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
533 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
534 if (*ret) printf(fmt, ret);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
535 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
536
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
537
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
538 char *rfc2426_escape(char *str) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
539 static char* buf = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
540 char *ret, *a, *b;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
541 int x = 0, y, z;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
542 if (str == NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
543 ret = str;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
544 else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
545
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
546 // calculate space required to escape all the following characters
38
f5c024aa1dc5 more valgrind fixes
carl
parents: 33
diff changeset
547 y = chr_count(str, '\\')
f5c024aa1dc5 more valgrind fixes
carl
parents: 33
diff changeset
548 + chr_count(str, ';');
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
549 z = chr_count(str, '\r');
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
550 if (y == 0 && z == 0)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
551 // there isn't any extra space required
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
552 ret = str;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
553 else {
38
f5c024aa1dc5 more valgrind fixes
carl
parents: 33
diff changeset
554 x = strlen(str) + y - z + 1; // don't forget room for the NUL
f5c024aa1dc5 more valgrind fixes
carl
parents: 33
diff changeset
555 buf = (char*) realloc(buf, x);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
556 a = str;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
557 b = buf;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
558 while (*a != '\0') {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
559 switch(*a) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
560 case '\\':
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
561 case ';' :
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
562 *(b++)='\\';
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
563 *b=*a;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
564 break;
38
f5c024aa1dc5 more valgrind fixes
carl
parents: 33
diff changeset
565 case '\r': // skip cr
f5c024aa1dc5 more valgrind fixes
carl
parents: 33
diff changeset
566 b--;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
567 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
568 default:
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
569 *b=*a;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
570 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
571 b++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
572 a++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
573 }
38
f5c024aa1dc5 more valgrind fixes
carl
parents: 33
diff changeset
574 *b = '\0'; // NUL-terminate the string (buf)
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
575 ret = buf;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
576 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
577 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
578 return ret;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
579 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
580
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
581
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
582 int chr_count(char *str, char x) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
583 int r = 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
584 while (*str != '\0') {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
585 if (*str == x)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
586 r++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
587 str++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
588 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
589 return r;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
590 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
591