TODO: PDZInfo tested
[libisds.git] / client / loadcmssignedsentmessage.c
bloba78c31440675c307c7125c656a79dc01c870aaa0
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 <libgen.h>
8 #include <isds.h>
9 #include "common.h"
12 int main(int argc, char **argv) {
13 struct isds_ctx *ctx = NULL;
14 isds_error err;
16 setlocale(LC_ALL, "");
18 if (argc != 2 || !argv[1] || !*argv[1]) {
19 printf("Usage: %s FILE_WITH_SIGNED_SEND_MESSAGE\n", basename(argv[0]));
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");
39 /* Load CMS signed sent message */
40 struct isds_message *message = NULL;
41 void *buffer;
42 int fd;
43 size_t length;
45 if (mmap_file(argv[1], &fd, &buffer, &length)) {
46 fprintf(stderr, "Could not map file with message");
47 isds_ctx_free(&ctx);
48 isds_cleanup();
49 exit(EXIT_FAILURE);
52 printf("Loading CMS signed sent message\n");
53 err = isds_load_message(ctx, RAWTYPE_CMS_SIGNED_OUTGOING_MESSAGE,
54 buffer, length, &message, BUFFER_DONT_STORE);
55 if (err)
56 printf("isds_load_message() failed: %s: %s\n",
57 isds_strerror(err), isds_long_message(ctx));
58 else {
59 printf("isds_load_message() succeeded:\n");
60 print_message(message);
63 isds_message_free(&message);
64 munmap_file(fd, buffer, length);
69 err = isds_ctx_free(&ctx);
70 if (err) {
71 printf("isds_ctx_free() failed: %s\n", isds_strerror(err));
75 err = isds_cleanup();
76 if (err) {
77 printf("isds_cleanup() failed: %s\n", isds_strerror(err));
80 exit (EXIT_SUCCESS);