4 * First parameter is location of LDIF, second location of Gammu backup
5 * how it should be parsed.
7 * Optional third parameter can be used to generate template backup
15 #include "../helper/memory-display.h"
19 #include "../libgammu/service/backup/backldif.h"
21 int main(int argc
, char **argv
)
29 gboolean generate
= FALSE
;
32 GSM_Debug_Info
*debug_info
;
34 /* Configure debugging */
35 debug_info
= GSM_GetGlobalDebug();
36 GSM_SetDebugFileDescriptor(stderr
, FALSE
, debug_info
);
37 GSM_SetDebugLevel("textall", debug_info
);
39 /* Check parameters */
40 if (argc
!= 3 && argc
!= 4) {
41 printf("Not enough parameters!\nUsage: ldif-read file.ldif file.backup\n");
45 /* Check for generating option */
46 if (argc
== 4 && strcmp(argv
[3], "generate") == 0) {
51 f
= fopen(argv
[1], "r");
52 test_result(f
!= NULL
);
55 len
= fread(buffer
, 1, sizeof(buffer
) - 1, f
);
58 /* Zero terminate string */
61 /* We don't need file any more */
65 error
= GSM_DecodeLDIFEntry(buffer
, &pos
, &pbk
);
66 gammu_test_result(error
, "GSM_DecodeLDIFEntry");
68 /* Generate file if we should */
70 GSM_ClearBackup(&backup
);
71 strcpy(backup
.Creator
, "LDIF tester");
73 backup
.PhonePhonebook
[0] = &pbk
;
74 backup
.PhonePhonebook
[1] = NULL
;
75 error
= GSM_SaveBackupFile(argv
[2], &backup
, TRUE
);
76 gammu_test_result(error
, "GSM_SaveBackupFile");
79 /* Read file content */
80 GSM_ClearBackup(&backup
);
81 error
= GSM_ReadBackupFile(argv
[2], &backup
, GSM_Backup_GammuUCS2
);
82 gammu_test_result(error
, "GSM_ReadBackupFile");
85 test_result(pbk
.EntriesNum
== backup
.PhonePhonebook
[0]->EntriesNum
);
88 for (i
= 0; i
< pbk
.EntriesNum
; i
++) {
89 test_result(pbk
.Entries
[i
].EntryType
== backup
.PhonePhonebook
[0]->Entries
[i
].EntryType
);
90 printf("Entry type: %d\n", pbk
.Entries
[i
].EntryType
);
91 switch (pbk
.Entries
[i
].EntryType
) {
92 case PBK_Number_General
:
93 case PBK_Number_Mobile
:
95 case PBK_Number_Pager
:
96 case PBK_Number_Other
:
97 case PBK_Number_Messaging
:
98 case PBK_Number_Video
:
100 case PBK_Text_Postal
:
102 case PBK_Text_Email2
:
106 case PBK_Text_LastName
:
107 case PBK_Text_FirstName
:
108 case PBK_Text_SecondName
:
109 case PBK_Text_FormalName
:
110 case PBK_Text_NamePrefix
:
111 case PBK_Text_NameSuffix
:
112 case PBK_Text_NickName
:
113 case PBK_Text_Company
:
114 case PBK_Text_JobTitle
:
115 case PBK_Text_StreetAddress
:
119 case PBK_Text_Country
:
120 case PBK_Text_Custom1
:
121 case PBK_Text_Custom2
:
122 case PBK_Text_Custom3
:
123 case PBK_Text_Custom4
:
124 case PBK_Text_UserID
:
125 case PBK_Text_PictureName
:
126 case PBK_PushToTalkID
:
132 test_result(mywstrncmp(pbk
.Entries
[i
].Text
, backup
.PhonePhonebook
[0]->Entries
[i
].Text
, 0) == TRUE
);
135 test_result((pbk
.Entries
[i
].Picture
.Length
==
136 backup
.PhonePhonebook
[0]->Entries
[i
].Picture
.Length
) &&
137 memcmp(pbk
.Entries
[i
].Picture
.Buffer
, backup
.PhonePhonebook
[0]->Entries
[i
].Picture
.Buffer
, pbk
.Entries
[i
].Picture
.Length
) == 0);
138 free(pbk
.Entries
[i
].Picture
.Buffer
);
141 case PBK_LastModified
:
148 case PBK_Caller_Group
:
149 test_result(pbk
.Entries
[i
].Number
== backup
.PhonePhonebook
[0]->Entries
[i
].Number
);
154 error
= PrintMemoryEntry(&pbk
, NULL
);
155 gammu_test_result(error
, "PrintMemoryEntry");
158 GSM_FreeBackup(&backup
);
164 /* Editor configuration
165 * vim: noexpandtab sw=8 ts=8 sts=8 tw=72: