1 #define _XOPEN_SOURCE 500
10 /* Pass e-mail address where to deliver credentials as first argument. */
11 int main(int argc
, char **argv
) {
12 struct isds_ctx
*ctx
= NULL
;
14 struct isds_DbOwnerInfo
*db_owner_info
= NULL
;
15 struct isds_list
*users
= NULL
;
17 setlocale(LC_ALL
, "");
21 printf("isds_init() failed: %s\n", isds_strerror(err
));
25 isds_set_logging(ILF_ALL
& ~ILF_HTTP
, ILL_ALL
);
27 ctx
= isds_ctx_create();
29 printf("isds_ctx_create() failed");
32 err
= isds_set_timeout(ctx
, 10000);
34 printf("isds_set_timeout() failed: %s\n", isds_strerror(err
));
37 err
= isds_login(ctx
, url
, username(), password(), NULL
, NULL
);
39 printf("isds_login() failed: %s: %s\n", isds_strerror(err
),
40 isds_long_message(ctx
));
42 printf("Logged in :)\n");
47 printf("Getting info about my box:\n");
48 err
= isds_GetOwnerInfoFromLogin(ctx
, &db_owner_info
);
50 printf("isds_GetOwnerInfoFromLogin() failed: %s: %s\n",
51 isds_strerror(err
), isds_long_message(ctx
));
53 printf("isds_GetOwnerInfoFromLogin() succeeded\n");
55 print_DbOwnerInfo(db_owner_info
);
59 /* Get info all users of this box */
61 struct isds_list
*item
;
62 printf("Getting users of my box with ID `%s':\n", db_owner_info
->dbID
);
63 err
= isds_GetDataBoxUsers(ctx
, db_owner_info
->dbID
, &users
);
65 printf("isds_GetDataBoxUsers() failed: %s: %s\n",
66 isds_strerror(err
), isds_long_message(ctx
));
68 printf("isds_GetDataBoxUsers() succeeded\n");
69 for(item
= users
; item
; item
= item
->next
) {
70 printf("List item:\n");
71 print_DbUserInfo(item
->data
);
77 /* Create the same box */
79 char *refnumber
= NULL
;
80 struct isds_credentials_delivery
*credentials_delivery
= NULL
;
81 const struct isds_approval approval
= {
82 .approved
= 1, .refference
= "Me"
85 credentials_delivery
= calloc(1, sizeof(*credentials_delivery
));
86 if (credentials_delivery
&& argv
[1])
87 credentials_delivery
->email
= strdup(argv
[1]);
89 if (!credentials_delivery
|| (argv
[1] && !credentials_delivery
->email
))
91 printf("Not enough memory\n");
93 printf("Creating already existing box\n");
94 err
= isds_add_box(ctx
, db_owner_info
, users
, "Former Names",
95 NULL
, "CEO", credentials_delivery
, &approval
, &refnumber
);
97 printf("isds_add_box() failed: %s: %s\n",
98 isds_strerror(err
), isds_long_message(ctx
));
100 printf("isds_add_box() succeeded:\n"
103 "\tcredentials e-mail: %s\n"
104 "\ttoken value: %s\n",
105 refnumber
, db_owner_info
->dbID
,
106 credentials_delivery
->email
, credentials_delivery
->token
);
109 isds_credentials_delivery_free(&credentials_delivery
);
112 isds_DbOwnerInfo_free(&db_owner_info
);
113 isds_list_free(&users
);
116 err
= isds_logout(ctx
);
118 printf("isds_logout() failed: %s\n", isds_strerror(err
));
122 err
= isds_ctx_free(&ctx
);
124 printf("isds_ctx_free() failed: %s\n", isds_strerror(err
));
128 err
= isds_cleanup();
130 printf("isds_cleanup() failed: %s\n", isds_strerror(err
));