2 #define _XOPEN_SOURCE XOPEN_SOURCE_LEVEL_FOR_STRDUP
13 struct isds_ctx
*ctx
= NULL
;
15 char *last_message_id
= NULL
;
17 setlocale(LC_ALL
, "");
21 printf("isds_init() failed: %s\n", isds_strerror(err
));
25 isds_set_logging(ILF_ALL
& ~ILF_HTTP
, ILL_ALL
);
27 ctx
= isds_ctx_create();
29 printf("isds_ctx_create() failed");
32 err
= isds_set_timeout(ctx
, 10000);
34 printf("isds_set_timeout() failed: %s\n", isds_strerror(err
));
37 err
= isds_login(ctx
, url
, username(), password(), NULL
, NULL
);
39 printf("isds_login() failed: %s: %s\n", isds_strerror(err
),
40 isds_long_message(ctx
));
42 printf("Logged in :)\n");
47 /* Get list of received messages */
49 struct tm from_time_tm
= {
50 .tm_year
= 2000 - 1900,
58 time_t from_time_t
= mktime(&from_time_tm
);
59 struct timeval from_time
= {
60 .tv_sec
= from_time_t
,
63 unsigned long int number
= 0;
64 struct isds_list
*messages
= NULL
, *item
;
65 struct isds_message
*last_message
= NULL
;
67 /* TODO: Try different criteria */
68 printf("Getting list of received messages\n");
69 err
= isds_get_list_of_received_messages(ctx
, &from_time
, NULL
, NULL
,
70 MESSAGESTATE_ANY
, 0, &number
, &messages
);
72 printf("isds_get_list_of_received_messages() failed: %s: %s\n",
73 isds_strerror(err
), isds_long_message(ctx
));
75 printf("isds_get_list_of_received_messages() succeeded: "
76 "number of messages = %lu\n", number
);
77 for(item
= messages
; item
; item
= item
->next
) {
78 last_message
= (struct isds_message
*) (item
->data
);
84 /*Save last message for latter refference */
85 if (last_message
->envelope
&& last_message
->envelope
->dmID
) {
86 last_message_id
= strdup(last_message
->envelope
->dmID
);
90 isds_list_free(&messages
);
94 /* Download last message envelope*/
95 if (last_message_id
) {
96 struct isds_message
*message
= NULL
;
98 printf("Getting last received envelope with ID: %s\n", last_message_id
);
99 err
= isds_get_received_envelope(ctx
, last_message_id
, &message
);
101 printf("isds_get_received_envelope() failed: %s: %s\n",
102 isds_strerror(err
), isds_long_message(ctx
));
104 printf("isds_get_received_envelope() succeeded:\n");
105 print_message(message
);
108 isds_message_free(&message
);
109 free(last_message_id
);
113 /* Download envelope with invalid ID*/
115 struct isds_message
*message
= NULL
;
116 char *id
= "123456789112345678921";
118 printf("Getting received envelope with invalid ID: %s\n", id
);
119 err
= isds_get_received_envelope(ctx
, id
, &message
);
121 printf("isds_get_received_envelope() failed as assumed: %s: %s\n",
122 isds_strerror(err
), isds_long_message(ctx
));
124 printf("isds_get_received_envelope() succeeded. "
125 "This should not happen:\n");
126 print_message(message
);
129 isds_message_free(&message
);
133 /* Download nonexistent envelope */
135 struct isds_message
*message
= NULL
;
136 char *id
= "7777777";
138 printf("Getting nonexistent received envelope with ID: %s\n", id
);
139 err
= isds_get_received_envelope(ctx
, id
, &message
);
141 printf("isds_get_received_envelope() failed as assumed: %s: %s\n",
142 isds_strerror(err
), isds_long_message(ctx
));
144 printf("isds_get_received_envelope() succeeded. "
145 "This should not happen:\n");
146 print_message(message
);
149 isds_message_free(&message
);
153 err
= isds_logout(ctx
);
155 printf("isds_logout() failed: %s\n", isds_strerror(err
));
159 err
= isds_ctx_free(&ctx
);
161 printf("isds_ctx_free() failed: %s\n", isds_strerror(err
));
165 err
= isds_cleanup();
167 printf("isds_cleanup() failed: %s\n", isds_strerror(err
));