Increase version to 0.10.2
[libisds.git] / client / convertdocument.c
blobd01e130a5b169b64bb22d75bdad7065abeb25fa5
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 struct isds_document document;
15 int fd;
16 char *id = NULL;
17 struct tm *date = NULL;
19 setlocale(LC_ALL, "");
21 if (argc < 3) {
22 fprintf(stderr, "Usage: program FILE DESCRIPTION\n");
23 exit(EXIT_FAILURE);
26 err = isds_init();
27 if (err) {
28 printf("isds_init() failed: %s\n", isds_strerror(err));
29 exit(EXIT_FAILURE);
32 isds_set_logging(ILF_ALL & ~ILF_HTTP, ILL_ALL);
34 ctx = isds_ctx_create();
35 if (!ctx) {
36 printf("isds_ctx_create() failed");
39 err = isds_set_timeout(ctx, 10000);
40 if (err) {
41 printf("isds_set_timeout() failed: %s\n", isds_strerror(err));
45 /* Load document */
46 memset(&document, 0, sizeof(document));
47 if (mmap_file(argv[1], &fd, &document.data, &document.data_length)) {
48 fprintf(stderr, "Could not map file with document");
49 isds_ctx_free(&ctx);
50 isds_cleanup();
51 exit(EXIT_FAILURE);
53 document.dmFileDescr = argv[2];
56 /* Submit document for conversion */
57 printf("Submitting document for authorized conversion: "
58 "content=%s, description=%s\n", argv[1], argv[2]);
59 err = czp_convert_document(ctx, &document, &id, &date);
60 if (err)
61 printf("czp_convert_document() failed: %s: %s\n",
62 isds_strerror(err), isds_long_message(ctx));
63 else {
64 printf("czp_convert_document() succeeded:\n");
65 printf("\tidentifier = %s\n", id);
66 printf("\tsubmit date = ");
67 print_date(date);
70 free(id);
71 free(date);
72 munmap_file(fd, document.data, document.data_length);
76 err = czp_close_connection(ctx);
77 if (err) {
78 printf("czp_close_connetion() failed: %s\n", isds_strerror(err));
82 err = isds_ctx_free(&ctx);
83 if (err) {
84 printf("isds_ctx_free() failed: %s\n", isds_strerror(err));
88 err = isds_cleanup();
89 if (err) {
90 printf("isds_cleanup() failed: %s\n", isds_strerror(err));
93 exit (EXIT_SUCCESS);