Adapt to OpenSSL 1.1.0
[libisds.git] / client / getchangedstates.c
blob6383c77591c3718f63d51ec1de1389a9bff5b087
1 #define _XOPEN_SOURCE 500
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <locale.h>
5 #include <string.h>
6 #include <sys/time.h>
7 #include <isds.h>
8 #include "common.h"
11 int main(void) {
12 struct isds_ctx *ctx = NULL;
13 isds_error err;
15 setlocale(LC_ALL, "");
17 err = isds_init();
18 if (err) {
19 printf("isds_init() failed: %s\n", isds_strerror(err));
20 exit(EXIT_FAILURE);
23 isds_set_logging(ILF_ALL & ~ILF_HTTP, ILL_ALL);
25 ctx = isds_ctx_create();
26 if (!ctx) {
27 printf("isds_ctx_create() failed");
30 err = isds_set_timeout(ctx, 10000);
31 if (err) {
32 printf("isds_set_timeout() failed: %s\n", isds_strerror(err));
35 err = isds_login(ctx, url, username(), password(), NULL, NULL);
36 if (err) {
37 printf("isds_login() failed: %s: %s\n", isds_strerror(err),
38 isds_long_message(ctx));
39 } else {
40 printf("Logged in :)\n");
45 struct isds_list *changed_states = NULL, *item;
46 struct timeval not_before = { .tv_sec = 0, .tv_usec = 0 };
47 struct timeval not_after;
49 if (!gettimeofday(&not_after, NULL)) {
50 /* Changes older than 15 days are not reported currently. */
51 not_before.tv_sec = not_after.tv_sec - 10 * 24 * 3600;
53 err = isds_get_list_of_sent_message_state_changes(ctx,
54 &not_before, &not_after, &changed_states);
55 if (err) {
56 printf("isds_get_list_of_sent_message_state_changes() failed: "
57 "%s: %s\n", isds_strerror(err), isds_long_message(ctx));
58 } else {
59 printf("isds_get_list_of_sent_message_state_changes() "
60 "succeeded:\n");
61 if (!changed_states)
62 printf("No message status changes available\n");
63 else
64 for(item = changed_states; item; item = item->next) {
65 printf("List item:\n");
66 print_message_status_change(item->data);
69 printf("\n");
71 isds_list_free(&changed_states);
72 } else {
73 perror("Could not get current time");
78 err = isds_logout(ctx);
79 if (err) {
80 printf("isds_logout() failed: %s\n", isds_strerror(err));
84 err = isds_ctx_free(&ctx);
85 if (err) {
86 printf("isds_ctx_free() failed: %s\n", isds_strerror(err));
90 err = isds_cleanup();
91 if (err) {
92 printf("isds_cleanup() failed: %s\n", isds_strerror(err));
95 exit (EXIT_SUCCESS);