client: possibly undefined variable value in certauth
[libisds.git] / client / getuserboxinfo.c
blob5a60b4a55ba5885749267ff8c48bc90d453c1656
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_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_set_tls(ctx, ITLS_VERIFY_SERVER, 0);
37 if (err) {
38 printf("isds_set_tls(ITLS_VERIFY_SERVER) failed: %s\n",
39 isds_strerror(err));
42 err = isds_set_tls(ctx, ITLS_CA_FILE, "/etc/ssl/certs/ca-certificates.crt");
43 if (err) {
44 printf("isds_set_tls(ITLS_CA_FILE) failed: %s\n",
45 isds_strerror(err));
46 }*/
48 err = isds_login(ctx, url, username, password, NULL);
49 if (err) {
50 printf("isds_login() failed: %s: %s\n", isds_strerror(err),
51 isds_long_message(ctx));
52 } else {
53 printf("Logged in :)\n");
58 printf("Getting info about my box:\n");
59 err = isds_GetOwnerInfoFromLogin(ctx, &db_owner_info);
60 if (err) {
61 printf("isds_GetOwnerInfoFromLogin() failed: %s: %s\n",
62 isds_strerror(err), isds_long_message(ctx));
63 } else {
64 printf("isds_GetOwnerInfoFromLogin() succeeded\n");
66 print_DbOwnerInfo(db_owner_info);
71 /* Current server implementation (2009-11-17) does not allow to find
72 * myself. Previous version allowed it. */
73 struct isds_list *boxes = NULL, *item;
75 printf("Searching for my own box:\n");
76 err = isds_FindDataBox(ctx, db_owner_info, &boxes);
77 if (err == IE_SUCCESS || err == IE_2BIG) {
78 if (err == IE_2BIG)
79 printf("isds_FindDataBox() results truncated\n");
80 printf("isds_FindDataBox() succeeded:\n");
82 for(item = boxes; item; item = item->next) {
83 printf("List item:\n");
84 print_DbOwnerInfo(item->data);
86 } else {
87 printf("isds_FindDataBox() failed: %s: %s\n",
88 isds_strerror(err), isds_long_message(ctx));
91 isds_list_free(&boxes);
95 /* Get box delivery info */
96 if (db_owner_info) {
97 long int box_status = 0;
98 printf("Getting status of my box with ID `%s'\n", db_owner_info->dbID);
99 err = isds_CheckDataBox(ctx, db_owner_info->dbID, &box_status);
100 if (err)
101 printf("isds_CheckDataBox() failed: %s: %s\n",
102 isds_strerror(err), isds_long_message(ctx));
103 else {
104 printf("isds_CheckDataBox() succeeded: status = ");
105 print_DbState(box_status);
109 /* Get info all users of this box */
110 if (db_owner_info) {
111 struct isds_list *users = NULL, *item;
112 printf("Getting users of my box with ID `%s':\n", db_owner_info->dbID);
113 err = isds_GetDataBoxUsers(ctx, db_owner_info->dbID, &users);
114 if (err) {
115 printf("isds_GetDataBoxUsers() failed: %s: %s\n",
116 isds_strerror(err), isds_long_message(ctx));
117 } else {
118 printf("isds_GetDataBoxUsers() succeeded\n");
119 for(item = users; item; item = item->next) {
120 printf("List item:\n");
121 print_DbUserInfo(item->data);
124 isds_list_free(&users);
127 isds_DbOwnerInfo_free(&db_owner_info);
130 /* Get info about my account */
131 struct isds_DbUserInfo *db_user_info = NULL;
132 printf("Getting info about my account:\n");
133 err = isds_GetUserInfoFromLogin(ctx, &db_user_info);
134 if (err) {
135 printf("isds_GetUserInfoFromLogin() failed: %s: %s\n",
136 isds_strerror(err), isds_long_message(ctx));
137 } else {
138 printf("isds_GetUserInfoFromLogin() succeeded\n");
139 print_DbUserInfo(db_user_info);
141 isds_DbUserInfo_free(&db_user_info);
145 /* Get password expiration time */
146 struct timeval *expiration = NULL;
147 printf("Getting password expiration time\n");
148 err = isds_get_password_expiration(ctx, &expiration);
149 if (err)
150 printf("isds_get_password_expiration() failed: %s: %s\n",
151 isds_strerror(err), isds_long_message(ctx));
152 else {
153 printf("isds_get_password_expiration() succeeded: "
154 "Password expires at: ");
155 print_timeval(expiration);
157 free(expiration);
161 err = isds_logout(ctx);
162 if (err) {
163 printf("isds_logout() failed: %s\n", isds_strerror(err));
167 err = isds_ctx_free(&ctx);
168 if (err) {
169 printf("isds_ctx_free() failed: %s\n", isds_strerror(err));
173 err = isds_cleanup();
174 if (err) {
175 printf("isds_cleanup() failed: %s\n", isds_strerror(err));
178 exit (EXIT_SUCCESS);