test: online/login describes returned error code
[libisds.git] / client / sendmultiple.c
blob7508f3d72fe019fb500073e88949a723e8c0943e
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 *recipient1 = NULL, *recipient2 = 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);
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 /* Find some recipients */
59 struct isds_list *boxes = NULL, *item;
60 struct isds_DbOwnerInfo criteria;
61 isds_DbType criteria_db_type = DBTYPE_OVM;
62 memset(&criteria, 0, sizeof(criteria));
63 criteria.firmName = "Místní";
64 criteria.dbType = &criteria_db_type;
66 printf("Searching box with firm name `%s':\n", criteria.firmName);
67 err = isds_FindDataBox(ctx, &criteria, &boxes);
68 if (err == IE_SUCCESS || err == IE_2BIG) {
69 printf("isds_FindDataBox() succeeded:\n");
71 int n;
72 for(item = boxes, n = 1; item; item = item->next, n++) {
73 if (err != IE_2BIG) {
74 printf("List item #%d:\n", n);
75 print_DbOwnerInfo(item->data);
77 if (n == 1) recipient1 = strdup(
78 ((struct isds_DbOwnerInfo *)(item->data))->dbID);
79 if (n == 2) recipient2 = strdup(
80 ((struct isds_DbOwnerInfo *)(item->data))->dbID);
82 if (err == IE_2BIG)
83 printf("isds_FindDataBox() results truncated to %d boxes\n",
84 --n);
85 } else {
86 printf("isds_FindDataBox() failed: %s: %s\n",
87 isds_strerror(err), isds_long_message(ctx));
90 isds_list_free(&boxes);
95 /* Send one message to more recipients */
96 struct isds_message message;
97 memset(&message, 0, sizeof(message));
99 struct isds_envelope envelope;
100 memset(&envelope, 0, sizeof(envelope));
101 message.envelope = &envelope;
102 long int dmSenderOrgUnitNum = 42;
103 envelope.dmSenderOrgUnitNum = &dmSenderOrgUnitNum;
104 envelope.dmAnnotation = "Multiple recipients";
106 struct isds_document minor_document;
107 memset(&minor_document, 0, sizeof(minor_document));
108 minor_document.data = "hello world?";
109 minor_document.data_length = strlen(minor_document.data);
110 minor_document.dmMimeType = "text/plain";
111 minor_document.dmFileMetaType = FILEMETATYPE_ENCLOSURE;
112 minor_document.dmFileDescr = "minor_standard_text.txt";
113 minor_document.dmFileGuid = "2";
114 minor_document.dmUpFileGuid = "1";
116 struct isds_document main_document;
117 memset(&main_document, 0, sizeof(main_document));
118 main_document.data = "Hello World!";
119 main_document.data_length = strlen(main_document.data);
120 main_document.dmMimeType = "text/plain";
121 main_document.dmFileMetaType = FILEMETATYPE_MAIN;
122 main_document.dmFileDescr = "standard_text.txt";
123 main_document.dmFileGuid = "1";
125 struct isds_list documents_main_item = {
126 .data = &main_document,
127 .next = NULL,
128 .destructor = NULL
130 struct isds_list documents_minor_item = {
131 .data = &minor_document,
132 .next = &documents_main_item,
133 .destructor = NULL
135 message.documents = &documents_minor_item;
137 /* Build recipients list */
138 struct isds_list *copies = NULL;
139 copies = calloc(1, sizeof(*copies));
140 copies->destructor = (void (*)(void**)) isds_message_copy_free;
141 copies->data = calloc(1, sizeof(struct isds_message_copy));
142 ((struct isds_message_copy*) copies->data)->dbIDRecipient = recipient1;
144 copies->next = calloc(1, sizeof(*copies->next));
145 copies->next->destructor = (void (*)(void**)) isds_message_copy_free;
146 copies->next->data = calloc(1, sizeof(struct isds_message_copy));
147 ((struct isds_message_copy*)copies->next->data)->dbIDRecipient =
148 recipient2;
151 printf("Sending message to box ID `%s' and box ID `%s'\n",
152 recipient1, recipient2);
153 err = isds_send_message_to_multiple_recipients(ctx, &message, copies);
155 if (err == IE_SUCCESS || err == IE_PARTIAL_SUCCESS) {
156 if (err == IE_SUCCESS){
157 printf("isds_send_message_to_multiple_recipients() succeeded "
158 "cempletely:\n");
160 if (err == IE_PARTIAL_SUCCESS){
161 printf("isds_send_message_to_multiple_recipients() succeeded "
162 "partialy:\n");
164 print_copies(copies);
165 } else
166 printf("isds_send_message_to_multiple_recipients() failed: "
167 "%s: %s\n", isds_strerror(err), isds_long_message(ctx));
169 isds_list_free(&copies);
174 err = isds_logout(ctx);
175 if (err) {
176 printf("isds_logout() failed: %s\n", isds_strerror(err));
180 err = isds_ctx_free(&ctx);
181 if (err) {
182 printf("isds_ctx_free() failed: %s\n", isds_strerror(err));
186 err = isds_cleanup();
187 if (err) {
188 printf("isds_cleanup() failed: %s\n", isds_strerror(err));
191 exit (EXIT_SUCCESS);