Export isds_PersonName_free(), isds_BirthInfo_free(), isds_Address_free()
[libisds.git] / client / changebox.c
blobaa165e453e5ca277d2ce0e7bdd610a54fa34b0cf
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"
10 /* Get info about my account */
11 isds_error get_my_box(struct isds_ctx *ctx,
12 struct isds_DbOwnerInfo **db_owner_info) {
13 isds_error err = IE_SUCCESS;
14 printf("Getting info about my box:\n");
15 err = isds_GetOwnerInfoFromLogin(ctx, db_owner_info);
16 if (err) {
17 printf("isds_GetOwnerInfoFromLogin() failed: %s: %s\n",
18 isds_strerror(err), isds_long_message(ctx));
19 } else {
20 printf("isds_GetOwnerInfoFromLogin() succeeded\n");
22 print_DbOwnerInfo(*db_owner_info);
23 return err;
27 int main(int argc, char **argv) {
28 struct isds_ctx *ctx = NULL;
29 isds_error err;
30 struct isds_DbOwnerInfo *db_owner_info = NULL;
32 setlocale(LC_ALL, "");
34 err = isds_init();
35 if (err) {
36 printf("isds_init() failed: %s\n", isds_strerror(err));
37 exit(EXIT_FAILURE);
40 isds_set_logging(ILF_ALL & ~ILF_HTTP, ILL_ALL);
42 ctx = isds_ctx_create();
43 if (!ctx) {
44 printf("isds_ctx_create() failed");
47 err = isds_set_timeout(ctx, 10000);
48 if (err) {
49 printf("isds_set_timeout() failed: %s\n", isds_strerror(err));
52 err = isds_login(ctx, url, username(), password(), NULL, NULL);
53 if (err) {
54 printf("isds_login() failed: %s: %s\n", isds_strerror(err),
55 isds_long_message(ctx));
56 } else {
57 printf("Logged in :)\n");
62 printf("Get current box info\n");
63 get_my_box(ctx, &db_owner_info);
67 if (db_owner_info) {
68 /* Update box info */
69 struct isds_DbOwnerInfo *old_owner_info = NULL;
70 char *refnumber = NULL;
72 old_owner_info = isds_DbOwnerInfo_duplicate(db_owner_info);
73 if (!old_owner_info) {
74 fprintf(stderr, "No enough memory\n");
75 exit(EXIT_FAILURE);
78 printf("Updating info about my box: with no change\n");
79 err = isds_UpdateDataBoxDescr(ctx, old_owner_info, db_owner_info,
80 NULL, &refnumber);
81 if (err) {
82 printf("isds_UpdateDataBoxDescr() failed: %s: %s\n",
83 isds_strerror(err), isds_long_message(ctx));
84 } else {
85 printf("isds_UpdateDataBoxDescr() succeeded as request #%s\n",
86 refnumber);
87 printf("Get new box info\n");
88 get_my_box(ctx, &db_owner_info);
91 free(refnumber);
92 isds_DbOwnerInfo_free(&old_owner_info);
95 isds_DbOwnerInfo_free(&db_owner_info);
99 err = isds_logout(ctx);
100 if (err) {
101 printf("isds_logout() failed: %s\n", isds_strerror(err));
105 err = isds_ctx_free(&ctx);
106 if (err) {
107 printf("isds_ctx_free() failed: %s\n", isds_strerror(err));
111 err = isds_cleanup();
112 if (err) {
113 printf("isds_cleanup() failed: %s\n", isds_strerror(err));
116 exit (EXIT_SUCCESS);