Remove executable flag from getreceived*delivery.c
[libisds.git] / client / getreceivedsigneddelivery.c
blob47eab699231b5fef837264abc15eedd830a1b898
1 #define _XOPEN_SOURCE 500
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <locale.h>
5 #include <time.h>
6 #include <string.h>
7 #include <isds.h>
8 #include "common.h"
11 int main(int argc, char **argv) {
12 struct isds_ctx *ctx = NULL;
13 isds_error err;
14 char *last_message_id = NULL;
16 setlocale(LC_ALL, "");
18 err = isds_init();
19 if (err) {
20 printf("isds_init() failed: %s\n", isds_strerror(err));
21 exit(EXIT_FAILURE);
24 isds_set_logging(ILF_ALL & ~ILF_HTTP, ILL_ALL);
26 ctx = isds_ctx_create();
27 if (!ctx) {
28 printf("isds_ctx_create() failed");
31 err = isds_set_timeout(ctx, 10000);
32 if (err) {
33 printf("isds_set_timeout() failed: %s\n", isds_strerror(err));
36 /* err = isds_set_tls(ctx, ITLS_VERIFY_SERVER, 0);
37 if (err) {
38 printf("isds_set_tls(ITLS_VERIFY_SERVER) failed: %s\n",
39 isds_strerror(err));
42 err = isds_set_tls(ctx, ITLS_CA_FILE, "/etc/ssl/certs/ca-certificates.crt");
43 if (err) {
44 printf("isds_set_tls(ITLS_CA_FILE) failed: %s\n",
45 isds_strerror(err));
46 }*/
48 err = isds_login(ctx, url, username, password, NULL, NULL);
49 if (err) {
50 printf("isds_login() failed: %s: %s\n", isds_strerror(err),
51 isds_long_message(ctx));
52 } else {
53 printf("Logged in :)\n");
58 /* Get list of received messages */
60 struct tm from_time_tm = {
61 .tm_year = 2000 - 1900,
62 .tm_mon = 1 - 1,
63 .tm_mday = 1,
64 .tm_hour = 1,
65 .tm_min = 2,
66 .tm_sec = 3,
67 .tm_isdst = -1
69 time_t from_time_t = mktime(&from_time_tm);
70 struct timeval from_time = {
71 .tv_sec = from_time_t,
72 .tv_usec = 4000
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);
82 if (err)
83 printf("isds_get_list_of_received_messages() failed: %s: %s\n",
84 isds_strerror(err), isds_long_message(ctx));
85 else {
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);
94 if (last_message) {
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);
112 if (err)
113 printf("isds_get_signed_delivery_info() failed: %s: %s\n",
114 isds_strerror(err), isds_long_message(ctx));
115 else {
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);
132 if (err)
133 printf("isds_get_signed_delivery_info() failed as assumed: %s: "
134 "%s\n", isds_strerror(err), isds_long_message(ctx));
135 else {
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);
152 if (err)
153 printf("isds_get_signed_delivery_info() failed as assumed: %s: "
154 "%s\n", isds_strerror(err), isds_long_message(ctx));
155 else {
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);
166 if (err) {
167 printf("isds_logout() failed: %s\n", isds_strerror(err));
171 err = isds_ctx_free(&ctx);
172 if (err) {
173 printf("isds_ctx_free() failed: %s\n", isds_strerror(err));
177 err = isds_cleanup();
178 if (err) {
179 printf("isds_cleanup() failed: %s\n", isds_strerror(err));
182 exit (EXIT_SUCCESS);