8 #include "../../misc/coding/coding.h" 9 #include "../../debug.h" 10 #include "../gsmlogo.h" 11 #include "../gsmmisc.h" 14 #ifdef GSM_ENABLE_BACKUP 16 static void SaveLDIFText(FILE *file,
const char *Name,
const unsigned char *Value)
18 unsigned char Buffer[1000],Buffer2[1000];
22 fprintf(file,
"%s:: %s%c%c",Name,Buffer2,13,10);
28 GSM_Error SaveLDIF(
const char *FileName, GSM_Backup *backup)
33 int firstname = -1, lastname = -1;
37 file = fopen(FileName,
"wb");
41 while (backup->PhonePhonebook[i]!=NULL) {
42 for (j=0;j<backup->PhonePhonebook[i]->EntriesNum;j++) {
43 switch (backup->PhonePhonebook[i]->Entries[j].EntryType) {
45 SaveLDIFText(file,
"dn", backup->PhonePhonebook[i]->Entries[j].Text);
59 if (!had_dn && (firstname != -1 || lastname != -1)) {
62 if (firstname != -1) {
63 CopyUnicodeString(Text + 2 * pos, backup->PhonePhonebook[i]->Entries[firstname].Text);
64 pos +=
UnicodeLength(backup->PhonePhonebook[i]->Entries[firstname].Text);
71 if (firstname != -1) {
72 Text[2*(pos - 1) + 1] =
' ';
74 CopyUnicodeString(Text + 2 * pos, backup->PhonePhonebook[i]->Entries[lastname].Text);
75 pos +=
UnicodeLength(backup->PhonePhonebook[i]->Entries[lastname].Text);
80 SaveLDIFText(file,
"dn", Text);
82 fprintf(file,
"objectclass: top%c%c",13,10);
83 fprintf(file,
"objectclass: person%c%c",13,10);
84 fprintf(file,
"objectclass: organizationalPerson%c%c",13,10);
85 fprintf(file,
"objectclass: inetOrgPerson%c%c",13,10);
86 fprintf(file,
"objectclass: mozillaAbPersonObsolete%c%c",13,10);
87 for (j=0;j<backup->PhonePhonebook[i]->EntriesNum;j++) {
88 switch (backup->PhonePhonebook[i]->Entries[j].EntryType) {
91 SaveLDIFText(file,
"homePostalAddress", backup->PhonePhonebook[i]->Entries[j].Text);
94 SaveLDIFText(file,
"workPostalAddress", backup->PhonePhonebook[i]->Entries[j].Text);
96 SaveLDIFText(file,
"postalAddress", backup->PhonePhonebook[i]->Entries[j].Text);
100 SaveLDIFText(file,
"homeurl", backup->PhonePhonebook[i]->Entries[j].Text);
106 SaveLDIFText(file,
"Description", backup->PhonePhonebook[i]->Entries[j].Text);
109 SaveLDIFText(file,
"mobile", backup->PhonePhonebook[i]->Entries[j].Text);
112 SaveLDIFText(file,
"pager", backup->PhonePhonebook[i]->Entries[j].Text);
115 SaveLDIFText(file,
"messaging", backup->PhonePhonebook[i]->Entries[j].Text);
119 SaveLDIFText(file,
"fax", backup->PhonePhonebook[i]->Entries[j].Text);
123 SaveLDIFText(file,
"homePhone", backup->PhonePhonebook[i]->Entries[j].Text);
124 }
else if (backup->PhonePhonebook[i]->Entries[j].Location ==
PBK_Location_Work) {
126 SaveLDIFText(file,
"workPhone", backup->PhonePhonebook[i]->Entries[j].Text);
129 SaveLDIFText(file,
"telephoneNumber", backup->PhonePhonebook[i]->Entries[j].Text);
133 SaveLDIFText(file,
"mail", backup->PhonePhonebook[i]->Entries[j].Text);
136 SaveLDIFText(file,
"mozillaSecondEmail", backup->PhonePhonebook[i]->Entries[j].Text);
139 SaveLDIFText(file,
"custom1", backup->PhonePhonebook[i]->Entries[j].Text);
142 SaveLDIFText(file,
"custom2", backup->PhonePhonebook[i]->Entries[j].Text);
145 SaveLDIFText(file,
"custom3", backup->PhonePhonebook[i]->Entries[j].Text);
148 SaveLDIFText(file,
"custom4", backup->PhonePhonebook[i]->Entries[j].Text);
151 SaveLDIFText(file,
"luid", backup->PhonePhonebook[i]->Entries[j].Text);
154 SaveLDIFText(file,
"o", backup->PhonePhonebook[i]->Entries[j].Text);
157 SaveLDIFText(file,
"title", backup->PhonePhonebook[i]->Entries[j].Text);
161 SaveLDIFText(file,
"workPostalAddress", backup->PhonePhonebook[i]->Entries[j].Text);
163 SaveLDIFText(file,
"homePostalAddress", backup->PhonePhonebook[i]->Entries[j].Text);
168 SaveLDIFText(file,
"workLocalityName", backup->PhonePhonebook[i]->Entries[j].Text);
170 SaveLDIFText(file,
"mozillaHomeLocalityName", backup->PhonePhonebook[i]->Entries[j].Text);
175 SaveLDIFText(file,
"workState", backup->PhonePhonebook[i]->Entries[j].Text);
177 SaveLDIFText(file,
"mozillaHomeState", backup->PhonePhonebook[i]->Entries[j].Text);
182 SaveLDIFText(file,
"workPostalCode", backup->PhonePhonebook[i]->Entries[j].Text);
184 SaveLDIFText(file,
"mozillaHomePostalCode", backup->PhonePhonebook[i]->Entries[j].Text);
189 SaveLDIFText(file,
"workCountryName", backup->PhonePhonebook[i]->Entries[j].Text);
191 SaveLDIFText(file,
"mozillaHomeCountryName", backup->PhonePhonebook[i]->Entries[j].Text);
195 SaveLDIFText(file,
"sn", backup->PhonePhonebook[i]->Entries[j].Text);
198 SaveLDIFText(file,
"givenName", backup->PhonePhonebook[i]->Entries[j].Text);
201 SaveLDIFText(file,
"nickname", backup->PhonePhonebook[i]->Entries[j].Text);
204 SaveLDIFText(file,
"nickname", backup->PhonePhonebook[i]->Entries[j].Text);
207 SaveLDIFText(file,
"cn", backup->PhonePhonebook[i]->Entries[j].Text);
234 fprintf(file,
"%c%c",13,10);
241 static gboolean ReadLDIFText(
const char *Buffer,
const char *Start,
char *Value)
243 unsigned char Buffer2[1000],buff[200];
250 if (!strncmp(Buffer,buff,strlen(buff))) {
251 i =
DecodeBASE64(Buffer+strlen(Start)+3, Buffer2, strlen(Buffer)-(strlen(Start)+3));
252 dbgprintf(NULL,
"Text after DecodeBASE64 is \"%s\"\n",Buffer2);
259 if (!strncmp(Buffer,buff,strlen(buff))) {
260 EncodeUnicode(Value,Buffer+strlen(Start)+2,strlen(Buffer)-(strlen(Start)+2));
269 unsigned char Line[2000],Buff[2000],Buff2[2000];
277 error =
MyGetLine(Buffer, Pos, Line, strlen(Buffer),
sizeof(Line),
FALSE);
278 if (error !=
ERR_NONE)
return error;
279 if (strlen(Line) == 0)
break;
285 if (ReadLDIFText(Line,
"objectclass", Buff)) {
287 if (!strcmp(
"mozillaAbPersonObsolete",Buff2)) {
294 if (ReadLDIFText(Line,
"dn", Buff)) {
299 if (ReadLDIFText(Line,
"givenName", Buff)) {
305 if (ReadLDIFText(Line,
"sn", Buff)) {
311 if (ReadLDIFText(Line,
"telephoneNumber", Buff)) {
317 if (ReadLDIFText(Line,
"mobile", Buff)) {
323 if (ReadLDIFText(Line,
"pager", Buff)) {
329 if (ReadLDIFText(Line,
"messaging", Buff)) {
335 if (ReadLDIFText(Line,
"workPhone", Buff)) {
341 if (ReadLDIFText(Line,
"fax", Buff)) {
347 if (ReadLDIFText(Line,
"homePhone",Buff)) {
353 if (ReadLDIFText(Line,
"Description", Buff)) {
359 if (ReadLDIFText(Line,
"homePostalAddress", Buff)) {
365 if (ReadLDIFText(Line,
"mozillaHomeLocalityName", Buff)) {
371 if (ReadLDIFText(Line,
"mozillaHomeState", Buff)) {
377 if (ReadLDIFText(Line,
"mozillaHomePostalCode", Buff)) {
383 if (ReadLDIFText(Line,
"mozillaHomeCountryName", Buff)) {
389 if (ReadLDIFText(Line,
"workPostalAddress", Buff)) {
395 if (ReadLDIFText(Line,
"workLocalityName", Buff)) {
401 if (ReadLDIFText(Line,
"workState", Buff)) {
407 if (ReadLDIFText(Line,
"workPostalCode", Buff)) {
413 if (ReadLDIFText(Line,
"workCountryName", Buff)) {
419 if (ReadLDIFText(Line,
"mail", Buff)) {
425 if (ReadLDIFText(Line,
"mozillaSecondEmail", Buff)) {
431 if (ReadLDIFText(Line,
"homeurl", Buff)) {
437 if (ReadLDIFText(Line,
"luid", Buff)) {
443 if (ReadLDIFText(Line,
"custom1", Buff)) {
449 if (ReadLDIFText(Line,
"custom2", Buff)) {
455 if (ReadLDIFText(Line,
"custom3", Buff)) {
461 if (ReadLDIFText(Line,
"custom4", Buff)) {
467 if (ReadLDIFText(Line,
"o", Buff)) {
473 if (ReadLDIFText(Line,
"title", Buff)) {
479 if (ReadLDIFText(Line,
"nickname", Buff)) {
497 GSM_Error LoadLDIF(
const char *FileName, GSM_Backup *backup)
507 if (error !=
ERR_NONE)
return error;
510 error = GSM_DecodeLDIFEntry(File.
Buffer, &Pos, &Pbk);
516 if (numPbk < GSM_BACKUP_MAX_PHONEPHONEBOOK) {
518 if (backup->PhonePhonebook[numPbk] == NULL) {
522 backup->PhonePhonebook[numPbk + 1] = NULL;
524 dbgprintf(NULL,
"Increase GSM_BACKUP_MAX_PHONEPHONEBOOK\n");
529 backup->PhonePhonebook[numPbk]->Location = numPbk + 1;
530 backup->PhonePhonebook[numPbk]->MemoryType =
MEM_ME;
char * DecodeUnicodeString(const unsigned char *src)
void CopyUnicodeString(unsigned char *Dest, const unsigned char *Source)
#define GSM_PHONEBOOK_TEXT_LENGTH
#define GSM_PHONEBOOK_ENTRIES
void EncodeBASE64(const unsigned char *Input, char *Output, const size_t Length)
size_t UnicodeLength(const unsigned char *str)
unsigned char Text[(GSM_PHONEBOOK_TEXT_LENGTH+1) *2]
void EncodeUnicode(unsigned char *dest, const char *src, size_t len)
void DecodeUTF8(unsigned char *dest, const char *src, size_t len)
GSM_Error GSM_ReadFile(const char *FileName, GSM_File *File)
GSM_EntryLocation Location
gboolean EncodeUTF8(char *dest, const unsigned char *src)
GSM_Error MyGetLine(char *Buffer, size_t *Pos, char *OutBuffer, size_t MaxLen, size_t MaxOutLen, gboolean MergeLines)
int DecodeBASE64(const char *Input, unsigned char *Output, const size_t Length)
GSM_SubMemoryEntry Entries[GSM_PHONEBOOK_ENTRIES]