tests: Adapt utf8locale to musl
[libisds.git] / client / getsignedsentbyid.c
blob5f0d2f24faa96505eeeb0077ff36556f37a9f937
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 if (argc < 2) {
19 fprintf(stderr, "Usage: program SENT_MESSAGE_ID\n");
20 exit(EXIT_FAILURE);
23 err = isds_init();
24 if (err) {
25 printf("isds_init() failed: %s\n", isds_strerror(err));
26 exit(EXIT_FAILURE);
29 isds_set_logging(ILF_ALL & ~ILF_HTTP, ILL_ALL);
31 ctx = isds_ctx_create();
32 if (!ctx) {
33 printf("isds_ctx_create() failed");
36 err = isds_set_timeout(ctx, 10000);
37 if (err) {
38 printf("isds_set_timeout() failed: %s\n", isds_strerror(err));
41 err = isds_login(ctx, url, username(), password(), NULL, NULL);
42 if (err) {
43 printf("isds_login() failed: %s: %s\n", isds_strerror(err),
44 isds_long_message(ctx));
45 } else {
46 printf("Logged in :)\n");
52 /* Download signed message selected by message ID */
53 if (argv[1]) {
54 struct isds_message *message = NULL;
56 printf("Getting signed sent message with ID: %s\n",
57 argv[1]);
58 err = isds_get_signed_sent_message(ctx, argv[1], &message);
59 if (err)
60 printf("isds_get_signed_sent_message() failed: %s: %s\n",
61 isds_strerror(err), isds_long_message(ctx));
62 else {
63 printf("isds_get_signed_sent_message() succeeded:\n");
64 print_message(message);
65 save_data("Saving signed message",
66 message->raw, message->raw_length);
69 isds_message_free(&message);
70 free(last_message_id);
75 err = isds_logout(ctx);
76 if (err) {
77 printf("isds_logout() failed: %s\n", isds_strerror(err));
81 err = isds_ctx_free(&ctx);
82 if (err) {
83 printf("isds_ctx_free() failed: %s\n", isds_strerror(err));
87 err = isds_cleanup();
88 if (err) {
89 printf("isds_cleanup() failed: %s\n", isds_strerror(err));
92 exit (EXIT_SUCCESS);