Increase version to 0.10.2
[libisds.git] / client / getuserboxinfo.c
blob99ee5d577e0753df7f3a5b7f703c8a2be903e617
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(void) {
12 struct isds_ctx *ctx = NULL;
13 isds_error err;
14 struct isds_DbOwnerInfo *db_owner_info = NULL;
16 setlocale(LC_ALL, "");
18 err = isds_init();
19 if (err) {
20 printf("isds_init() failed: %s\n", isds_strerror(err));
21 exit(EXIT_FAILURE);
24 isds_set_logging(ILF_ALL & ~ILF_HTTP, ILL_ALL);
26 ctx = isds_ctx_create();
27 if (!ctx) {
28 printf("isds_ctx_create() failed");
31 err = isds_set_timeout(ctx, 10000);
32 if (err) {
33 printf("isds_set_timeout() failed: %s\n", isds_strerror(err));
36 err = isds_login(ctx, url, username(), password(), NULL, NULL);
37 if (err) {
38 printf("isds_login() failed: %s: %s\n", isds_strerror(err),
39 isds_long_message(ctx));
40 } else {
41 printf("Logged in :)\n");
46 printf("Getting info about my box:\n");
47 err = isds_GetOwnerInfoFromLogin(ctx, &db_owner_info);
48 if (err) {
49 printf("isds_GetOwnerInfoFromLogin() failed: %s: %s\n",
50 isds_strerror(err), isds_long_message(ctx));
51 } else {
52 printf("isds_GetOwnerInfoFromLogin() succeeded\n");
54 print_DbOwnerInfo(db_owner_info);
59 /* Current server implementation (2009-11-17) does not allow to find
60 * myself. Previous version allowed it. */
61 struct isds_list *boxes = NULL, *item;
63 printf("Searching for my own box:\n");
64 err = isds_FindDataBox(ctx, db_owner_info, &boxes);
65 if (err == IE_SUCCESS || err == IE_2BIG) {
66 if (err == IE_2BIG)
67 printf("isds_FindDataBox() results truncated\n");
68 printf("isds_FindDataBox() succeeded:\n");
70 for(item = boxes; item; item = item->next) {
71 printf("List item:\n");
72 print_DbOwnerInfo(item->data);
74 } else {
75 printf("isds_FindDataBox() failed: %s: %s\n",
76 isds_strerror(err), isds_long_message(ctx));
79 isds_list_free(&boxes);
83 /* Get box delivery info */
84 if (db_owner_info) {
85 long int box_status = 0;
86 printf("Getting status of my box with ID `%s'\n", db_owner_info->dbID);
87 err = isds_CheckDataBox(ctx, db_owner_info->dbID, &box_status);
88 if (err)
89 printf("isds_CheckDataBox() failed: %s: %s\n",
90 isds_strerror(err), isds_long_message(ctx));
91 else {
92 printf("isds_CheckDataBox() succeeded: status = ");
93 print_DbState(box_status);
97 /* Get info all users of this box */
98 if (db_owner_info) {
99 struct isds_list *users = NULL, *item;
100 printf("Getting users of my box with ID `%s':\n", db_owner_info->dbID);
101 err = isds_GetDataBoxUsers(ctx, db_owner_info->dbID, &users);
102 if (err) {
103 printf("isds_GetDataBoxUsers() failed: %s: %s\n",
104 isds_strerror(err), isds_long_message(ctx));
105 } else {
106 printf("isds_GetDataBoxUsers() succeeded\n");
107 for(item = users; item; item = item->next) {
108 printf("List item:\n");
109 print_DbUserInfo(item->data);
112 isds_list_free(&users);
115 isds_DbOwnerInfo_free(&db_owner_info);
118 /* Get info about my account */
119 struct isds_DbUserInfo *db_user_info = NULL;
120 printf("Getting info about my account:\n");
121 err = isds_GetUserInfoFromLogin(ctx, &db_user_info);
122 if (err) {
123 printf("isds_GetUserInfoFromLogin() failed: %s: %s\n",
124 isds_strerror(err), isds_long_message(ctx));
125 } else {
126 printf("isds_GetUserInfoFromLogin() succeeded\n");
127 print_DbUserInfo(db_user_info);
129 isds_DbUserInfo_free(&db_user_info);
133 /* Get password expiration time */
134 struct timeval *expiration = NULL;
135 printf("Getting password expiration time\n");
136 err = isds_get_password_expiration(ctx, &expiration);
137 if (err)
138 printf("isds_get_password_expiration() failed: %s: %s\n",
139 isds_strerror(err), isds_long_message(ctx));
140 else {
141 printf("isds_get_password_expiration() succeeded: "
142 "Password expires at: ");
143 if (expiration)
144 print_timeval(expiration);
145 else
146 printf("<Never>\n");
148 free(expiration);
152 err = isds_logout(ctx);
153 if (err) {
154 printf("isds_logout() failed: %s\n", isds_strerror(err));
158 err = isds_ctx_free(&ctx);
159 if (err) {
160 printf("isds_ctx_free() failed: %s\n", isds_strerror(err));
164 err = isds_cleanup();
165 if (err) {
166 printf("isds_cleanup() failed: %s\n", isds_strerror(err));
169 exit (EXIT_SUCCESS);