annotate pst2ldif.c @ 7:3e3d8b576630

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