Increase version to 0.10.2
[libisds.git] / client / changeuser.c
blob2fa0466d20479908f9b59e1bdeb60bde8f3ed919
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_account(struct isds_ctx *ctx,
12 struct isds_DbUserInfo **db_user_info) {
13 isds_error err = IE_SUCCESS;
14 printf("Getting info about my account:\n");
15 err = isds_GetUserInfoFromLogin(ctx, db_user_info);
16 if (err) {
17 printf("isds_GetUserInfoFromLogin() failed: %s: %s\n",
18 isds_strerror(err), isds_long_message(ctx));
19 } else {
20 printf("isds_GetUserInfoFromLogin() succeeded\n");
21 print_DbUserInfo(*db_user_info);
23 return err;
27 int main(void) {
28 struct isds_ctx *ctx = NULL;
29 isds_error err;
30 struct isds_DbOwnerInfo *db_owner_info = NULL;
31 struct isds_DbUserInfo *db_user_info = NULL;
33 setlocale(LC_ALL, "");
35 err = isds_init();
36 if (err) {
37 printf("isds_init() failed: %s\n", isds_strerror(err));
38 exit(EXIT_FAILURE);
41 isds_set_logging(ILF_ALL & ~ILF_HTTP, ILL_ALL);
43 ctx = isds_ctx_create();
44 if (!ctx) {
45 printf("isds_ctx_create() failed");
48 err = isds_set_timeout(ctx, 10000);
49 if (err) {
50 printf("isds_set_timeout() failed: %s\n", isds_strerror(err));
53 err = isds_login(ctx, url, username(), password(), NULL, NULL);
54 if (err) {
55 printf("isds_login() failed: %s: %s\n", isds_strerror(err),
56 isds_long_message(ctx));
57 } else {
58 printf("Logged in :)\n");
63 printf("Getting info about my box:\n");
64 err = isds_GetOwnerInfoFromLogin(ctx, &db_owner_info);
65 if (err) {
66 printf("isds_GetOwnerInfoFromLogin() failed: %s: %s\n",
67 isds_strerror(err), isds_long_message(ctx));
68 } else {
69 printf("isds_GetOwnerInfoFromLogin() succeeded\n");
71 print_DbOwnerInfo(db_owner_info);
77 /* Get info about my account */
78 err = get_my_account(ctx, &db_user_info);
81 if (db_user_info && db_owner_info) {
82 /* Update user info */
83 struct isds_DbUserInfo *old_user_info = NULL;
84 char *refnumber = NULL;
86 old_user_info = isds_DbUserInfo_duplicate(db_user_info);
87 if (!old_user_info) {
88 fprintf(stderr, "No enough memory\n");
89 exit(EXIT_FAILURE);
92 printf("Updating info about my account: with no change\n");
93 err = isds_UpdateDataBoxUser(ctx, db_owner_info,
94 old_user_info, db_user_info, &refnumber);
95 if (err) {
96 printf("isds_UpdateDataBoxUser() failed: %s: %s\n",
97 isds_strerror(err), isds_long_message(ctx));
98 } else {
99 printf("isds_UpdateDataBoxUser() succeeded as request #%s\n",
100 refnumber);
102 /* Verify info about my account */
103 get_my_account(ctx, &db_user_info);
106 free(refnumber);
107 isds_DbUserInfo_free(&old_user_info);
110 isds_DbUserInfo_free(&db_user_info);
111 isds_DbOwnerInfo_free(&db_owner_info);
115 err = isds_logout(ctx);
116 if (err) {
117 printf("isds_logout() failed: %s\n", isds_strerror(err));
121 err = isds_ctx_free(&ctx);
122 if (err) {
123 printf("isds_ctx_free() failed: %s\n", isds_strerror(err));
127 err = isds_cleanup();
128 if (err) {
129 printf("isds_cleanup() failed: %s\n", isds_strerror(err));
132 exit (EXIT_SUCCESS);