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_login(ctx
, url
, username(), password(), NULL
, NULL
);
38 printf("isds_login() failed: %s: %s\n", isds_strerror(err
),
39 isds_long_message(ctx
));
41 printf("Logged in :)\n");
46 /* Get list of received messages */
48 struct tm from_time_tm
= {
49 .tm_year
= 2000 - 1900,
57 time_t from_time_t
= mktime(&from_time_tm
);
58 struct timeval from_time
= {
59 .tv_sec
= from_time_t
,
62 unsigned long int number
= 0;
63 struct isds_list
*messages
= NULL
, *item
;
64 struct isds_message
*last_message
= NULL
;
66 /* TODO: Try different criteria */
67 printf("Getting list of received messages\n");
68 err
= isds_get_list_of_received_messages(ctx
, &from_time
, NULL
, NULL
,
69 MESSAGESTATE_ANY
, 0, &number
, &messages
);
71 printf("isds_get_list_of_received_messages() failed: %s: %s\n",
72 isds_strerror(err
), isds_long_message(ctx
));
74 printf("isds_get_list_of_received_messages() succeeded: "
75 "number of messages = %lu:\n", number
);
76 for(item
= messages
; item
; item
= item
->next
) {
77 last_message
= (struct isds_message
*) (item
->data
);
83 /*Save last message for latter refference */
84 if (last_message
->envelope
&& last_message
->envelope
->dmID
) {
85 last_message_id
= strdup(last_message
->envelope
->dmID
);
89 isds_list_free(&messages
);
93 if (last_message_id
) {
94 /* Download last message */
95 struct isds_message
*message
= NULL
;
97 printf("Getting last received message with ID: %s\n", last_message_id
);
98 err
= isds_get_received_message(ctx
, last_message_id
, &message
);
100 printf("isds_get_received_message() failed: %s: %s\n",
101 isds_strerror(err
), isds_long_message(ctx
));
103 printf("isds_get_received_message() succeeded:\n");
104 print_message(message
);
108 /* Verify message hash */
109 printf("Verifying last received message hash against server\n");
110 err
= isds_verify_message_hash(ctx
, message
);
112 printf("isds_verify_message_hash() succeeded: "
113 "message is genuine\n");
114 printf("Computed hash: ");
115 print_hash(message
->envelope
->hash
);
116 } else if (err
== IE_NOTEQUAL
) {
117 printf("isds_verify_message_hash() failed: message is a fake\n");
118 printf("Computed hash: ");
119 print_hash(message
->envelope
->hash
);
120 printf("This should not happen\n");
122 printf("isds_verify_message_hash() failed: %s: %s\n",
123 isds_strerror(err
), isds_long_message(ctx
));
127 /* Download last signed message */
128 printf("Getting last signed received message with ID: %s\n",
130 err
= isds_get_signed_received_message(ctx
, last_message_id
, &message
);
132 printf("isds_get_signed_received_message() failed: %s: %s\n",
133 isds_strerror(err
), isds_long_message(ctx
));
135 printf("isds_get_signed_received_message() succeeded:\n");
136 printf("\tMessage should have the same content ;)\n");
139 /* Verify signed message hash */
140 printf("Verifying last signed received message hash against server\n");
141 err
= isds_verify_message_hash(ctx
, message
);
143 printf("isds_verify_message_hash() succeeded: "
144 "message is genuine\n");
145 printf("Computed hash: ");
146 print_hash(message
->envelope
->hash
);
147 } else if (err
== IE_NOTEQUAL
) {
148 printf("isds_verify_message_hash() failed: message is a fake\n");
149 printf("Computed hash: ");
150 print_hash(message
->envelope
->hash
);
151 printf("This should not happen\n");
153 printf("isds_verify_message_hash() failed: %s: %s\n",
154 isds_strerror(err
), isds_long_message(ctx
));
158 isds_message_free(&message
);
159 free(last_message_id
);
164 err
= isds_logout(ctx
);
166 printf("isds_logout() failed: %s\n", isds_strerror(err
));
170 err
= isds_ctx_free(&ctx
);
172 printf("isds_ctx_free() failed: %s\n", isds_strerror(err
));
176 err
= isds_cleanup();
178 printf("isds_cleanup() failed: %s\n", isds_strerror(err
));