annotate src/pst2ldif.cpp @ 33:12cac756bc05 stable-0-5-5

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