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
);
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
);
118 save_data("Saving signed delivery info",
119 message
->raw
, message
->raw_length
);
122 isds_message_free(&message
);
123 free(last_message_id
);
127 /* Download signed delivery info with invalid ID */
129 struct isds_message
*message
= NULL
;
130 char *id
= "123456789112345678921";
132 printf("Getting signed delivery info with invalid ID: %s\n", id
);
133 err
= isds_get_signed_delivery_info(ctx
, id
, &message
);
135 printf("isds_get_signed_delivery_info() failed as assumed: %s: "
136 "%s\n", isds_strerror(err
), isds_long_message(ctx
));
138 printf("isds_get_signed_delivery_info() succeeded. "
139 "This should not happen:\n");
140 print_message(message
);
143 isds_message_free(&message
);
147 /* Download nonexistent signed delivery info */
149 struct isds_message
*message
= NULL
;
150 char *id
= "7777777";
152 printf("Getting nonexistent signed delivery info with ID: %s\n", id
);
153 err
= isds_get_signed_delivery_info(ctx
, id
, &message
);
155 printf("isds_get_signed_delivery_info() failed as assumed: %s: "
156 "%s\n", isds_strerror(err
), isds_long_message(ctx
));
158 printf("isds_get_signed_delivery_info() succeeded. "
159 "This should not happen:\n");
160 print_message(message
);
163 isds_message_free(&message
);
167 err
= isds_logout(ctx
);
169 printf("isds_logout() failed: %s\n", isds_strerror(err
));
173 err
= isds_ctx_free(&ctx
);
175 printf("isds_ctx_free() failed: %s\n", isds_strerror(err
));
179 err
= isds_cleanup();
181 printf("isds_cleanup() failed: %s\n", isds_strerror(err
));