1 #define _XOPEN_SOURCE 500
11 int main(int argc
, char **argv
) {
12 struct isds_ctx
*ctx
= NULL
;
14 char *last_message_id
= NULL
;
16 setlocale(LC_ALL
, "");
20 printf("isds_init() failed: %s\n", isds_strerror(err
));
24 isds_set_logging(ILF_ALL
& ~ILF_HTTP
, ILL_ALL
);
26 ctx
= isds_ctx_create();
28 printf("isds_ctx_create() failed");
31 err
= isds_set_timeout(ctx
, 10000);
33 printf("isds_set_timeout() failed: %s\n", isds_strerror(err
));
36 /* err = isds_set_tls(ctx, ITLS_VERIFY_SERVER, 0);
38 printf("isds_set_tls(ITLS_VERIFY_SERVER) failed: %s\n",
42 err = isds_set_tls(ctx, ITLS_CA_FILE, "/etc/ssl/certs/ca-certificates.crt");
44 printf("isds_set_tls(ITLS_CA_FILE) failed: %s\n",
48 err
= isds_login(ctx
, url
, username
, password
, NULL
, NULL
);
50 printf("isds_login() failed: %s: %s\n", isds_strerror(err
),
51 isds_long_message(ctx
));
53 printf("Logged in :)\n");
58 /* Get list of received messages */
60 struct tm from_time_tm
= {
61 .tm_year
= 2000 - 1900,
69 time_t from_time_t
= mktime(&from_time_tm
);
70 struct timeval from_time
= {
71 .tv_sec
= from_time_t
,
74 unsigned long int number
= 0;
75 struct isds_list
*messages
= NULL
, *item
;
76 struct isds_message
*last_message
= NULL
;
78 /* TODO: Try different criteria */
79 printf("Getting list of received messages\n");
80 err
= isds_get_list_of_received_messages(ctx
, &from_time
, NULL
, NULL
,
81 MESSAGESTATE_ANY
, 0, &number
, &messages
);
83 printf("isds_get_list_of_received_messages() failed: %s: %s\n",
84 isds_strerror(err
), isds_long_message(ctx
));
86 printf("isds_get_list_of_received_messages() succeeded: "
87 "number of messages = %lu\n", number
);
88 for(item
= messages
; item
; item
= item
->next
) {
89 last_message
= (struct isds_message
*) (item
->data
);
95 /*Save last message for latter refference */
96 if (last_message
->envelope
&& last_message
->envelope
->dmID
) {
97 last_message_id
= strdup(last_message
->envelope
->dmID
);
101 isds_list_free(&messages
);
105 /* Download last message signed delivery info */
106 if (last_message_id
) {
107 struct isds_message
*message
= NULL
;
109 printf("Getting last received message signed delivery info with ID: "
110 "%s\n", last_message_id
);
111 err
= isds_get_signed_delivery_info(ctx
, last_message_id
, &message
);
113 printf("isds_get_signed_delivery_info() failed: %s: %s\n",
114 isds_strerror(err
), isds_long_message(ctx
));
116 printf("isds_get_signed_delivery_info() succeeded:\n");
117 print_message(message
);
120 isds_message_free(&message
);
121 free(last_message_id
);
125 /* Download signed delivery info with invalid ID */
127 struct isds_message
*message
= NULL
;
128 char *id
= "123456789112345678921";
130 printf("Getting signed delivery info with invalid ID: %s\n", id
);
131 err
= isds_get_signed_delivery_info(ctx
, id
, &message
);
133 printf("isds_get_signed_delivery_info() failed as assumed: %s: "
134 "%s\n", isds_strerror(err
), isds_long_message(ctx
));
136 printf("isds_get_signed_delivery_info() succeeded. "
137 "This should not happen:\n");
138 print_message(message
);
141 isds_message_free(&message
);
145 /* Download nonexistent signed delivery info */
147 struct isds_message
*message
= NULL
;
148 char *id
= "7777777";
150 printf("Getting nonexistent signed delivery info with ID: %s\n", id
);
151 err
= isds_get_signed_delivery_info(ctx
, id
, &message
);
153 printf("isds_get_signed_delivery_info() failed as assumed: %s: "
154 "%s\n", isds_strerror(err
), isds_long_message(ctx
));
156 printf("isds_get_signed_delivery_info() succeeded. "
157 "This should not happen:\n");
158 print_message(message
);
161 isds_message_free(&message
);
165 err
= isds_logout(ctx
);
167 printf("isds_logout() failed: %s\n", isds_strerror(err
));
171 err
= isds_ctx_free(&ctx
);
173 printf("isds_ctx_free() failed: %s\n", isds_strerror(err
));
177 err
= isds_cleanup();
179 printf("isds_cleanup() failed: %s\n", isds_strerror(err
));