annotate nick2ldif.cpp @ 12:3f627519a92d stable-0-5-2

properly ignore (second block zero) errors. that will just drop some unknown attachments, but the rest of the data is still found
author carl
date Sat, 18 Feb 2006 09:56:00 -0800
parents a818f3c2e589
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
1 /*
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
2
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
3 Copyright (c) 2004 Carl Byington - 510 Software Group, released under
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
4 the GPL version 2 or any later version at your choice available at
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
5 http://www.fsf.org/licenses/gpl.txt
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
6
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
7 */
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
8
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
9 #include <stdio.h>
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
10 #include <iostream>
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
11 //#include <fstream>
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
12 #include <unistd.h>
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
13
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
14 char *ldap_base = NULL;
10
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
15 char *ldap_org = NULL;
2
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
16 char *ldap_class = NULL;
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
17
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
18 using namespace std;
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
19
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
20 int main(int argc, char** argv) {
10
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
21 char c;
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
22 char *temp;
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
23 while ((c = getopt(argc, argv, "b:c:"))!= -1) {
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
24 switch (c) {
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
25 case 'b':
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
26 ldap_base = optarg;
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
27 temp = strchr(ldap_base, ',');
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
28 if (temp) {
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
29 *temp = '\0';
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
30 ldap_org = strdup(ldap_base);
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
31 *temp = ',';
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
32 }
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
33 break;
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
34 case 'c':
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
35 ldap_class = optarg;
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
36 break;
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
37 default:
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
38 break;
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
39 }
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
40 }
2
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
41
10
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
42 const int LINE_SIZE = 2000;
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
43 char line[LINE_SIZE];
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
44 while (!cin.eof()) {
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
45 cin.getline(line, LINE_SIZE);
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
46 int n = strlen(line);
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
47 if (!n) continue;
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
48 char *f = line + 6; // skip alias keyword
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
49 char *e;
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
50 if (*f == '"') {
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
51 f++;
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
52 e = strchr(f, '"');
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
53 }
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
54 else {
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
55 e = strchr(f, ' ');
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
56 }
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
57 if (!e) continue;
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
58 *e = '\0';
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
59 char *m = e+1;
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
60 while (*m == ' ') m++;
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
61 if (*m != '\0') {
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
62 char cn[1000];
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
63 snprintf(cn, sizeof(cn), "email %s", f);
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
64 printf("dn: cn=%s, %s\n", cn, ldap_base);
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
65 printf("cn: %s\n", cn);
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
66 printf("sn: %s\n", f);
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
67 printf("mail: %s\n", m);
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
68 printf("objectClass: %s\n\n", ldap_class);
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
69 }
a818f3c2e589 fix tree walk, we now use the item counts in the node blocks
carl
parents: 2
diff changeset
70 }
2
8dd68d722fa8 add ldif converters
carl
parents:
diff changeset
71 }