annotate pst2ldif.cpp @ 9:8c724896a28a

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