annotate src/nick2ldif.cpp @ 18:69ab1d8b3293

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