test: Try cs_CZ.ISO8859-2 in offline/utf82locale test
[libisds.git] / client / addbox.c
blobeb144263b58d18c61372fb28acfc978334a818a2
1 #include "../config.h"
2 #define _XOPEN_SOURCE XOPEN_SOURCE_LEVEL_FOR_STRDUP
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <locale.h>
6 #include <time.h>
7 #include <string.h>
8 #include <isds.h>
9 #include "common.h"
11 /* Pass e-mail address where to deliver credentials as first argument. */
12 int main(int argc, char **argv) {
13 struct isds_ctx *ctx = NULL;
14 isds_error err;
15 struct isds_DbOwnerInfo *db_owner_info = NULL;
16 struct isds_list *users = NULL;
18 setlocale(LC_ALL, "");
20 err = isds_init();
21 if (err) {
22 printf("isds_init() failed: %s\n", isds_strerror(err));
23 exit(EXIT_FAILURE);
26 isds_set_logging(ILF_ALL & ~ILF_HTTP, ILL_ALL);
28 ctx = isds_ctx_create();
29 if (!ctx) {
30 printf("isds_ctx_create() failed");
33 err = isds_set_timeout(ctx, 10000);
34 if (err) {
35 printf("isds_set_timeout() failed: %s\n", isds_strerror(err));
38 err = isds_login(ctx, url, username(), password(), NULL, NULL);
39 if (err) {
40 printf("isds_login() failed: %s: %s\n", isds_strerror(err),
41 isds_long_message(ctx));
42 } else {
43 printf("Logged in :)\n");
48 printf("Getting info about my box:\n");
49 err = isds_GetOwnerInfoFromLogin(ctx, &db_owner_info);
50 if (err) {
51 printf("isds_GetOwnerInfoFromLogin() failed: %s: %s\n",
52 isds_strerror(err), isds_long_message(ctx));
53 } else {
54 printf("isds_GetOwnerInfoFromLogin() succeeded\n");
56 print_DbOwnerInfo(db_owner_info);
60 /* Get info all users of this box */
61 if (db_owner_info) {
62 struct isds_list *item;
63 printf("Getting users of my box with ID `%s':\n", db_owner_info->dbID);
64 err = isds_GetDataBoxUsers(ctx, db_owner_info->dbID, &users);
65 if (err) {
66 printf("isds_GetDataBoxUsers() failed: %s: %s\n",
67 isds_strerror(err), isds_long_message(ctx));
68 } else {
69 printf("isds_GetDataBoxUsers() succeeded\n");
70 for(item = users; item; item = item->next) {
71 printf("List item:\n");
72 print_DbUserInfo(item->data);
78 /* Create the same box */
79 if (db_owner_info) {
80 char *refnumber = NULL;
81 struct isds_credentials_delivery *credentials_delivery = NULL;
82 const struct isds_approval approval = {
83 .approved = 1, .refference = "Me"
86 credentials_delivery = calloc(1, sizeof(*credentials_delivery));
87 if (credentials_delivery && argc >= 2 && argv[1])
88 credentials_delivery->email = strdup(argv[1]);
90 if (!credentials_delivery ||
91 (argc >= 2 && argv[1] && !credentials_delivery->email)) {
92 printf("Not enough memory\n");
93 } else {
94 printf("Creating already existing box\n");
95 err = isds_add_box(ctx, db_owner_info, users, "Former Names",
96 NULL, "CEO", credentials_delivery, &approval, &refnumber);
97 if (err) {
98 printf("isds_add_box() failed: %s: %s\n",
99 isds_strerror(err), isds_long_message(ctx));
100 } else {
101 printf("isds_add_box() succeeded:\n"
102 "\trequest #: %s\n"
103 "\tnew box ID: %s\n"
104 "\tcredentials e-mail: %s\n"
105 "\ttoken value: %s\n",
106 refnumber, db_owner_info->dbID,
107 credentials_delivery->email, credentials_delivery->token);
110 isds_credentials_delivery_free(&credentials_delivery);
113 isds_DbOwnerInfo_free(&db_owner_info);
114 isds_list_free(&users);
117 err = isds_logout(ctx);
118 if (err) {
119 printf("isds_logout() failed: %s\n", isds_strerror(err));
123 err = isds_ctx_free(&ctx);
124 if (err) {
125 printf("isds_ctx_free() failed: %s\n", isds_strerror(err));
129 err = isds_cleanup();
130 if (err) {
131 printf("isds_cleanup() failed: %s\n", isds_strerror(err));
134 exit (EXIT_SUCCESS);