PDA

Visualizza la versione completa : convertire una rubrica .csv in .ldif


ky
03-09-2003, 14:31
Ciao a tutti!
Non so se ho postato nel forum + appropriato, ma volevo sapere se qualcuno di voi sa creare un programmino che mi converta una rubrica di Outlook (formato .csv) in una di Netscape (formato .ldi o .ldif).
Mi sarebbe molto utile perché la webmail a cui mi appoggio non carica il formato csv e io volevo importare la rubrica che ho su Outlook... :eek:
Grazie 1000!!! Ciaoooo! :ciauz:

ky
03-09-2003, 15:16
...ma non so come posso utilizzarlo:


/* File: csvDump2ldif.c
Author: Greg Ippolito
Version: 1.0

Useage: csvDump2ldf < inputfile.csv > outfile.ldif

Load into LDAP:
ldapadd -f stooges.ldif -cxv -D "cn=StoogeAdmin,o=stooges" -W

*/

#include <stdio.h>
#include <string.h>

#define MAX_NUMBER_OF_FIELDS 17
#define MAX_FIELD_LENGTH 132
#define TOTAL_SIZE (MAX_FIELD_LENGTH * MAX_NUMBER_OF_FIELDS)
#define SERVER_ROOT "o=stooges"

int main(int argv, char *argc[])
{
int i, c;
int ifield; /* Field count */
int iline=0; /* Line count */
int ignoreCommaFlag = 0;
char field[MAX_NUMBER_OF_FIELDS][MAX_FIELD_LENGTH]; /* 17 fields */
char *server_root = SERVER_ROOT;
int ii, kk, fComma;

for( ii=1910; ii<2100; ii++ )
{
printf("dn: ou=%d,o=stooges\n",ii);
printf("ou: %d\n",ii);
printf("objectclass: top\n");
printf("objectclass: organizationalUnit\n");
printf("\n");
}

bzero((char *)field, (size_t) TOTAL_SIZE);

i = 0;
ifield = 0;
fComma = 0;

while ((c = getchar()) != EOF)
{
if( c == '"' && ignoreCommaFlag ) ignoreCommaFlag = 0;
else if( c == '"' && !ignoreCommaFlag ) ignoreCommaFlag = 1;
else if( c == ',' && ignoreCommaFlag )
{
field[ifield][i] = ' ';
i++;
}
else if( c == ',' && !ignoreCommaFlag )
{
fComma = 1; /* Set comma flag */
field[ifield][i] = '\0'; /* NULL terminate */
i = 0;
ifield++;
/* Found line with bogus number of fields. Keep repeating last field.*/
if( ifield == MAX_NUMBER_OF_FIELDS ) ifield--;
}
else if( c == '\n' )
{ /* First field number begins count at 0 */
iline++;
field[ifield][i] = '\0'; /* NULL terminate */
fComma = 0; /* Set comma flag */

if( field[2][0] == '\0' )
fprintf(stderr,"Error line %d: Blank field 3 - no cn\n", iline);
else
{
printf("dn: cn=%s,ou=%s,%s\n",field[2],field[11],server_root);
printf("cn: %s\n", field[2]);
printf("objectClass: top\n");
printf("objectClass: person\n");
printf("objectClass: organizationalPerson\n");
printf("objectClass: inetOrgPerson\n");
printf("givenname: %s\n", field[1]);
printf("sn: %s\n", field[0]);
if( field[11][0] != '\0')
printf("ou: %s\n", field[11]); /* Department=organizational unit */
if( field[12][0] != '\0' ) printf("mail: %s\n", field[12]) ;
printf("employeetype: A\n");
if( field[3][0] != 0 && field[4][0] != 0)
printf("streetAddress: %s %s\n", field[3], field[4]);
else if( field[3][0] != 0 && field[4][0] == 0)
printf("streetAddress: %s\n", field[3]);
else if( field[3][0] == 0 && field[4][0] != 0)
printf("streetAddress: %s\n", field[4]);
if( field[5][0] != '\0') printf("l: %s\n",field[5]);
if( field[6][0] != '\0') printf("st: %s\n", field[6]);
if( field[7][0] != '\0') printf("postalCode: %s\n", field[7]);
if( field[10][0] != '\0') printf("telephoneNumber: %s\n", field[10]);
if( field[9][0] != '\0') printf("homePhone: %s\n", field[9]);
if( field[13][0] != '\0') printf("mobile: %s\n", field[13]);
if( field[11][0] != '\0')
printf("departmentNumber: %s\n", field[11]);

printf("\n");

/* Clear variables */
bzero((char *)field, (size_t) TOTAL_SIZE);
}

i = 0;
ifield = 0;
}
else
{
//if( i==0 && c==' ' )
field[ifield][i] = c;
i++;
fComma = 0; /* Set comma flag */
}

}

}




Potete darmi una mano x favore? :bhò:

Loading