test: server: authorize client by distinguished name
[libisds.git] / client / getsent.c
blob9eefd2131be4d22ef897a4c190f7bc5f614abbd3
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_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 /* Get list of sent messages */
47 struct tm from_time_tm = {
48 .tm_year = 2000 - 1900,
49 .tm_mon = 1 - 1,
50 .tm_mday = 1,
51 .tm_hour = 1,
52 .tm_min = 2,
53 .tm_sec = 3,
54 .tm_isdst = -1
56 time_t from_time_t = mktime(&from_time_tm);
57 struct timeval from_time = {
58 .tv_sec = from_time_t,
59 .tv_usec = 4000
61 unsigned long int number = 0;
62 struct isds_list *messages = NULL, *item;
64 /* TODO: Try different criteria */
65 printf("Getting list of sent messages\n");
66 err = isds_get_list_of_sent_messages(ctx, &from_time, NULL, NULL,
67 MESSAGESTATE_ANY, 0, &number, &messages);
68 if (err)
69 printf("isds_get_list_of_sent_messages() failed: %s: %s\n",
70 isds_strerror(err), isds_long_message(ctx));
71 else {
72 printf("isds_get_list_of_sent_messages() succeeded: "
73 "number of messages = %lu:\n", number);
74 for(item = messages; item; item = item->next) {
75 printf("List item:\n");
76 print_message(item->data);
80 isds_list_free(&messages);
84 err = isds_logout(ctx);
85 if (err) {
86 printf("isds_logout() failed: %s\n", isds_strerror(err));
90 err = isds_ctx_free(&ctx);
91 if (err) {
92 printf("isds_ctx_free() failed: %s\n", isds_strerror(err));
96 err = isds_cleanup();
97 if (err) {
98 printf("isds_cleanup() failed: %s\n", isds_strerror(err));
101 exit (EXIT_SUCCESS);