client: Add getreceivedsigneddelivery
[libisds.git] / client / getsent.c
blobc56ffcd72b7010ead911e7378dd3331e9cc8a6cd
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;
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_set_tls(ctx, ITLS_VERIFY_SERVER, 0);
36 if (err) {
37 printf("isds_set_tls(ITLS_VERIFY_SERVER) failed: %s\n",
38 isds_strerror(err));
41 err = isds_set_tls(ctx, ITLS_CA_FILE, "/etc/ssl/certs/ca-certificates.crt");
42 if (err) {
43 printf("isds_set_tls(ITLS_CA_FILE) failed: %s\n",
44 isds_strerror(err));
45 }*/
47 err = isds_login(ctx, url, username, password, NULL, NULL);
48 if (err) {
49 printf("isds_login() failed: %s: %s\n", isds_strerror(err),
50 isds_long_message(ctx));
51 } else {
52 printf("Logged in :)\n");
57 /* Get list of sent messages */
59 struct tm from_time_tm = {
60 .tm_year = 2000 - 1900,
61 .tm_mon = 1 - 1,
62 .tm_mday = 1,
63 .tm_hour = 1,
64 .tm_min = 2,
65 .tm_sec = 3,
66 .tm_isdst = -1
68 time_t from_time_t = mktime(&from_time_tm);
69 struct timeval from_time = {
70 .tv_sec = from_time_t,
71 .tv_usec = 4000
73 unsigned long int number = 0;
74 struct isds_list *messages = NULL, *item;
76 /* TODO: Try different criteria */
77 printf("Getting list of sent messages\n");
78 err = isds_get_list_of_sent_messages(ctx, &from_time, NULL, NULL,
79 MESSAGESTATE_ANY, 0, &number, &messages);
80 if (err)
81 printf("isds_get_list_of_sent_messages() failed: %s: %s\n",
82 isds_strerror(err), isds_long_message(ctx));
83 else {
84 printf("isds_get_list_of_sent_messages() succeeded: "
85 "number of messages = %lu:\n", number);
86 for(item = messages; item; item = item->next) {
87 printf("List item:\n");
88 print_message(item->data);
92 isds_list_free(&messages);
96 err = isds_logout(ctx);
97 if (err) {
98 printf("isds_logout() failed: %s\n", isds_strerror(err));
102 err = isds_ctx_free(&ctx);
103 if (err) {
104 printf("isds_ctx_free() failed: %s\n", isds_strerror(err));
108 err = isds_cleanup();
109 if (err) {
110 printf("isds_cleanup() failed: %s\n", isds_strerror(err));
113 exit (EXIT_SUCCESS);