2 #define _XOPEN_SOURCE XOPEN_SOURCE_LEVEL_FOR_STRDUP
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
;
15 struct isds_DbOwnerInfo
*db_owner_info
= NULL
;
16 struct isds_list
*users
= NULL
;
18 setlocale(LC_ALL
, "");
22 printf("isds_init() failed: %s\n", isds_strerror(err
));
26 isds_set_logging(ILF_ALL
& ~ILF_HTTP
, ILL_ALL
);
28 ctx
= isds_ctx_create();
30 printf("isds_ctx_create() failed");
33 err
= isds_set_timeout(ctx
, 10000);
35 printf("isds_set_timeout() failed: %s\n", isds_strerror(err
));
38 err
= isds_login(ctx
, url
, username(), password(), NULL
, NULL
);
40 printf("isds_login() failed: %s: %s\n", isds_strerror(err
),
41 isds_long_message(ctx
));
43 printf("Logged in :)\n");
48 printf("Getting info about my box:\n");
49 err
= isds_GetOwnerInfoFromLogin(ctx
, &db_owner_info
);
51 printf("isds_GetOwnerInfoFromLogin() failed: %s: %s\n",
52 isds_strerror(err
), isds_long_message(ctx
));
54 printf("isds_GetOwnerInfoFromLogin() succeeded\n");
56 print_DbOwnerInfo(db_owner_info
);
60 /* Get info all users of this box */
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
);
66 printf("isds_GetDataBoxUsers() failed: %s: %s\n",
67 isds_strerror(err
), isds_long_message(ctx
));
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 */
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");
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
);
98 printf("isds_add_box() failed: %s: %s\n",
99 isds_strerror(err
), isds_long_message(ctx
));
101 printf("isds_add_box() succeeded:\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
);
119 printf("isds_logout() failed: %s\n", isds_strerror(err
));
123 err
= isds_ctx_free(&ctx
);
125 printf("isds_ctx_free() failed: %s\n", isds_strerror(err
));
129 err
= isds_cleanup();
131 printf("isds_cleanup() failed: %s\n", isds_strerror(err
));