annotate src/pst2ldif.cpp @ 19:1246d317a05b

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