doc: Base URL server locator without suffix
[libisds.git] / client / changebox.c
blob3bebbcf0b4b933b75355a80f686bdc169738534a
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_set_tls(ctx, ITLS_VERIFY_SERVER, 0);
53 if (err) {
54 printf("isds_set_tls(ITLS_VERIFY_SERVER) failed: %s\n",
55 isds_strerror(err));
58 err = isds_set_tls(ctx, ITLS_CA_FILE, "/etc/ssl/certs/ca-certificates.crt");
59 if (err) {
60 printf("isds_set_tls(ITLS_CA_FILE) failed: %s\n",
61 isds_strerror(err));
62 }*/
64 err = isds_login(ctx, url, username, password, NULL, NULL);
65 if (err) {
66 printf("isds_login() failed: %s: %s\n", isds_strerror(err),
67 isds_long_message(ctx));
68 } else {
69 printf("Logged in :)\n");
74 printf("Get current box info\n");
75 get_my_box(ctx, &db_owner_info);
79 if (db_owner_info) {
80 /* Update box info */
81 struct isds_DbOwnerInfo *old_owner_info = NULL;
82 char *refnumber = NULL;
84 old_owner_info = isds_DbOwnerInfo_duplicate(db_owner_info);
85 if (!old_owner_info) {
86 fprintf(stderr, "No enough memory\n");
87 exit(EXIT_FAILURE);
90 printf("Updating info about my box: with no change\n");
91 err = isds_UpdateDataBoxDescr(ctx, old_owner_info, db_owner_info,
92 NULL, &refnumber);
93 if (err) {
94 printf("isds_UpdateDataBoxDescr() failed: %s: %s\n",
95 isds_strerror(err), isds_long_message(ctx));
96 } else {
97 printf("isds_UpdateDataBoxDescr() succeeded as request #%s\n",
98 refnumber);
99 printf("Get new box info\n");
100 get_my_box(ctx, &db_owner_info);
103 free(refnumber);
104 isds_DbOwnerInfo_free(&old_owner_info);
107 isds_DbOwnerInfo_free(&db_owner_info);
111 err = isds_logout(ctx);
112 if (err) {
113 printf("isds_logout() failed: %s\n", isds_strerror(err));
117 err = isds_ctx_free(&ctx);
118 if (err) {
119 printf("isds_ctx_free() failed: %s\n", isds_strerror(err));
123 err = isds_cleanup();
124 if (err) {
125 printf("isds_cleanup() failed: %s\n", isds_strerror(err));
128 exit (EXIT_SUCCESS);