2 #define _XOPEN_SOURCE XOPEN_SOURCE_LEVEL_FOR_STRDUP
13 struct isds_ctx
*ctx
= NULL
;
15 struct isds_DbOwnerInfo
*db_owner_info
= NULL
;
16 char *recipient
= NULL
;
18 setlocale(LC_ALL
, "");
22 printf("isds_init() failed: %s\n", isds_strerror(err
));
26 isds_set_logging(ILF_ALL
& ~ILF_HTTP
, ILL_ALL
);
28 ctx
= isds_ctx_create();
30 printf("isds_ctx_create() failed");
33 err
= isds_set_timeout(ctx
, 10000);
35 printf("isds_set_timeout() failed: %s\n", isds_strerror(err
));
38 err
= isds_login(ctx
, url
, username(), password(), NULL
, NULL
);
40 printf("isds_login() failed: %s: %s\n", isds_strerror(err
),
41 isds_long_message(ctx
));
43 printf("Logged in :)\n");
48 printf("isds_ping() failed: %s\n", isds_strerror(err
));
50 printf("isds_ping() succeeded\n");
53 printf("Sending bogus request\n");
54 err
= isds_bogus_request(ctx
);
56 printf("isds_bogus_request() failed: %s: %s\n", isds_strerror(err
),
57 isds_long_message(ctx
));
59 printf("isds_bogus_request() succeeded\n");
63 printf("Getting info about my box:\n");
64 err
= isds_GetOwnerInfoFromLogin(ctx
, &db_owner_info
);
66 printf("isds_GetOwnerInfoFromLogin() failed: %s: %s\n",
67 isds_strerror(err
), isds_long_message(ctx
));
69 printf("isds_GetOwnerInfoFromLogin() succeeded\n");
71 print_DbOwnerInfo(db_owner_info
);
76 /* Current server implementation (2009-11-17) does not allow to find
77 * myself. Previous version allowed it. */
78 struct isds_list
*boxes
= NULL
, *item
;
80 printf("Searching for my own box:\n");
81 err
= isds_FindDataBox(ctx
, db_owner_info
, &boxes
);
82 if (err
== IE_SUCCESS
|| err
== IE_2BIG
) {
84 printf("isds_FindDataBox() results truncated\n");
85 printf("isds_FindDataBox() succeeded:\n");
87 for(item
= boxes
; item
; item
= item
->next
) {
88 printf("List item:\n");
89 print_DbOwnerInfo(item
->data
);
92 printf("isds_FindDataBox() failed: %s: %s\n",
93 isds_strerror(err
), isds_long_message(ctx
));
96 isds_list_free(&boxes
);
100 struct isds_list
*boxes
= NULL
, *item
;
101 struct isds_DbOwnerInfo
*criteria
= calloc(1, sizeof(*criteria
));
103 printf("Not enough memory for struct isds_DbOwnerInfo criteria\n");
106 criteria
->firmName
= strdup("Obec");
107 if (!criteria
->firmName
) {
108 printf("Not enough memory for criteria->firmName\n");
111 criteria
->dbType
= malloc(sizeof(*(criteria
->dbType
)));
112 if (!criteria
->dbType
) {
113 printf("Not enough memory for criteria->dbType\n");
116 *(criteria
->dbType
) = DBTYPE_OVM
;
118 printf("Searching box with firm name `%s':\n", criteria
->firmName
);
119 err
= isds_FindDataBox(ctx
, criteria
, &boxes
);
120 if (err
== IE_SUCCESS
|| err
== IE_2BIG
) {
121 printf("isds_FindDataBox() succeeded:\n");
124 for(item
= boxes
, n
= 1; item
; item
= item
->next
, n
++) {
125 if (err
!= IE_2BIG
) {
126 printf("List item #%d:\n", n
);
127 print_DbOwnerInfo(item
->data
);
131 printf("isds_FindDataBox() results truncated to %d boxes\n",
134 printf("isds_FindDataBox() failed: %s: %s\n",
135 isds_strerror(err
), isds_long_message(ctx
));
138 isds_list_free(&boxes
);
139 isds_DbOwnerInfo_free(&criteria
);
143 struct isds_list
*boxes
= NULL
, *item
;
144 struct isds_DbOwnerInfo criteria
;
145 isds_DbType criteria_db_type
= DBTYPE_OVM
;
146 memset(&criteria
, 0, sizeof(criteria
));
147 criteria
.dbType
= &criteria_db_type
;
148 criteria
.dbID
= "vqbab52";
150 printf("Searching for exact box by ID `%s' and type:\n", criteria
.dbID
);
151 err
= isds_FindDataBox(ctx
, &criteria
, &boxes
);
152 if (err
== IE_SUCCESS
|| err
== IE_2BIG
) {
153 printf("isds_FindDataBox() succeeded:\n");
156 for(item
= boxes
, n
= 1; item
; item
= item
->next
, n
++) {
157 if (err
!= IE_2BIG
) {
158 printf("List item #%d:\n", n
);
159 print_DbOwnerInfo(item
->data
);
161 if (n
== 1) recipient
= strdup(
162 ((struct isds_DbOwnerInfo
*)(item
->data
))->dbID
);
165 printf("isds_FindDataBox() results truncated to %d boxes\n",
168 printf("isds_FindDataBox() failed: %s: %s\n",
169 isds_strerror(err
), isds_long_message(ctx
));
172 isds_list_free(&boxes
);
177 struct isds_list
*boxes
= NULL
, *item
;
178 struct isds_DbOwnerInfo criteria
;
179 isds_DbType criteria_db_type
= DBTYPE_OVM
;
180 memset(&criteria
, 0, sizeof(criteria
));
181 criteria
.firmName
= "Místní";
182 criteria
.dbType
= &criteria_db_type
;
184 printf("Searching box with firm name `%s':\n", criteria
.firmName
);
185 err
= isds_FindDataBox(ctx
, &criteria
, &boxes
);
186 if (err
== IE_SUCCESS
|| err
== IE_2BIG
) {
187 printf("isds_FindDataBox() succeeded:\n");
190 for(item
= boxes
, n
= 1; item
; item
= item
->next
, n
++) {
191 if (err
!= IE_2BIG
) {
192 printf("List item #%d:\n", n
);
193 print_DbOwnerInfo(item
->data
);
195 if (n
== 1) recipient
= strdup(
196 ((struct isds_DbOwnerInfo
*)(item
->data
))->dbID
);
199 printf("isds_FindDataBox() results truncated to %d boxes\n",
202 printf("isds_FindDataBox() failed: %s: %s\n",
203 isds_strerror(err
), isds_long_message(ctx
));
206 isds_list_free(&boxes
);
211 long int box_status
= 0;
212 printf("Getting status of my box with ID `%s'\n", db_owner_info
->dbID
);
213 err
= isds_CheckDataBox(ctx
, db_owner_info
->dbID
, &box_status
);
215 printf("isds_CheckDataBox() failed: %s: %s\n",
216 isds_strerror(err
), isds_long_message(ctx
));
218 printf("isds_CheckDataBox() succeeded: status = ");
219 print_DbState(box_status
);
223 isds_DbOwnerInfo_free(&db_owner_info
);
226 char *box_id
= "7777777";
227 long int box_status
= 0;
228 printf("Getting status of non existing box with ID `%s'\n", box_id
);
229 err
= isds_CheckDataBox(ctx
, box_id
, &box_status
);
231 printf("isds_CheckDataBox() failed: %s: %s\n",
232 isds_strerror(err
), isds_long_message(ctx
));
234 printf("isds_CheckDataBox() succeeded: status = ");
235 print_DbState(box_status
);
242 struct isds_message message
;
243 memset(&message
, 0, sizeof(message
));
245 struct isds_envelope envelope
;
246 memset(&envelope
, 0, sizeof(envelope
));
247 message
.envelope
= &envelope
;
248 envelope
.dbIDRecipient
= recipient
;
249 long int dmSenderOrgUnitNum
= 42;
250 envelope
.dmSenderOrgUnitNum
= &dmSenderOrgUnitNum
;
251 envelope
.dmAnnotation
= "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
252 /* "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
253 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
254 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
255 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
256 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
257 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
258 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
259 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
260 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
261 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
262 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
263 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
264 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
265 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
266 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
267 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
268 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
269 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
270 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"*/
271 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
273 struct isds_document minor_document
;
274 memset(&minor_document
, 0, sizeof(minor_document
));
275 minor_document
.data
= "hello world?";
276 minor_document
.data_length
= strlen(minor_document
.data
);
277 minor_document
.dmMimeType
= "text/plain";
278 /* XXX: This should fail
279 minor_document.dmFileMetaType = FILEMETATYPE_MAIN; */
280 minor_document
.dmFileMetaType
= FILEMETATYPE_ENCLOSURE
;
281 /* Server implementation demands dmFileDescr to be valid file name */
282 /*minor_document.dmFileDescr = "Standard text.txt";*/
283 minor_document
.dmFileDescr
= "minor_standard_text.txt";
284 minor_document
.dmFileGuid
= "2";
285 minor_document
.dmUpFileGuid
= "1";
287 struct isds_document main_document
;
288 memset(&main_document
, 0, sizeof(main_document
));
289 main_document
.data
= "Hello World!";
290 main_document
.data_length
= strlen(main_document
.data
);
291 /* Server implementation sais text is not text file
292 * See <http://www.abclinuxu.cz/forum/show/284940> */
293 main_document
.dmMimeType
= "text/plain";
294 /* XXX: This should fail */
295 /*main_document.dmFileMetaType = FILEMETATYPE_ENCLOSURE;*/
296 main_document
.dmFileMetaType
= FILEMETATYPE_MAIN
;
297 /* Server implementation demands dmFileDescr to be valid file name */
298 /*main_document.dmFileDescr = "Standard text.txt";*/
299 main_document
.dmFileDescr
= "standard_text.txt";
300 main_document
.dmFileGuid
= "1";
302 struct isds_list documents_main_item
= {
303 .data
= &main_document
,
307 struct isds_list documents_minor_item
= {
308 .data
= &minor_document
,
309 .next
= &documents_main_item
,
312 message
.documents
= &documents_minor_item
;
315 printf("Sending message to box ID `%s'\n",
316 message
.envelope
->dbIDRecipient
);
317 err
= isds_send_message(ctx
, &message
);
319 printf("isds_send_message() failed: %s: %s\n",
320 isds_strerror(err
), isds_long_message(ctx
));
322 printf("isds_send_message() succeeded: assigned message ID = %s\n",
323 message
.envelope
->dmID
);
326 free(message
.envelope
->dmID
);
331 err
= isds_logout(ctx
);
333 printf("isds_logout() failed: %s\n", isds_strerror(err
));
336 printf("Ping after logout should fail\n");
337 err
= isds_ping(ctx
);
339 printf("isds_ping() failed: %s\n", isds_strerror(err
));
341 printf("isds_ping() succeeded\n");
344 printf("Sending bogus request after logout\n");
345 err
= isds_bogus_request(ctx
);
347 printf("isds_bogus_request() failed: %s: %s\n", isds_strerror(err
),
348 isds_long_message(ctx
));
350 printf("isds_bogus_request() succeeded\n");
353 err
= isds_ctx_free(&ctx
);
355 printf("isds_ctx_free() failed: %s\n", isds_strerror(err
));
359 err
= isds_cleanup();
361 printf("isds_cleanup() failed: %s\n", isds_strerror(err
));