annotate src/pst2ldif.cpp @ 52:034641c26ab9

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