annotate pst2ldif.cpp @ 8:2b58cf15aaf7

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