test: server_cli tool added
[libisds.git] / client / requestnewtestingbox.c
blobffc0df66c8d78d38e3dfe5cc3fb8e2992a083dba
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, *request_ctx = NULL;
13 isds_error err;
14 struct isds_DbOwnerInfo *db_owner_info = NULL;
15 struct isds_list *users = NULL;
17 setlocale(LC_ALL, "");
19 err = isds_init();
20 if (err) {
21 printf("isds_init() failed: %s\n", isds_strerror(err));
22 exit(EXIT_FAILURE);
25 isds_set_logging(ILF_ALL & ~ILF_HTTP, ILL_ALL);
27 ctx = isds_ctx_create();
28 if (!ctx) {
29 printf("isds_ctx_create() failed");
32 err = isds_set_timeout(ctx, 10000);
33 if (err) {
34 printf("isds_set_timeout() failed: %s\n", isds_strerror(err));
37 err = isds_login(ctx, url, username(), password(), NULL, NULL);
38 if (err) {
39 printf("isds_login() failed: %s: %s\n", isds_strerror(err),
40 isds_long_message(ctx));
41 } else {
42 printf("Logged in :)\n");
47 printf("Getting info about my box:\n");
48 err = isds_GetOwnerInfoFromLogin(ctx, &db_owner_info);
49 if (err) {
50 printf("isds_GetOwnerInfoFromLogin() failed: %s: %s\n",
51 isds_strerror(err), isds_long_message(ctx));
52 } else {
53 printf("isds_GetOwnerInfoFromLogin() succeeded\n");
55 print_DbOwnerInfo(db_owner_info);
59 /* Get info all users of this box */
60 if (db_owner_info) {
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);
64 if (err) {
65 printf("isds_GetDataBoxUsers() failed: %s: %s\n",
66 isds_strerror(err), isds_long_message(ctx));
67 } else {
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 /* Request for creating the same box */
78 if (db_owner_info) {
79 char *refnumber = NULL;
80 const struct isds_approval approval = {
81 .approved = 1, .refference = "Me"
84 free(db_owner_info->email);
85 db_owner_info->email = strdup("franta@example.com");
87 request_ctx = isds_ctx_create();
88 if (!request_ctx) {
89 printf("isds_ctx_create() failed");
92 printf("Requesting to create already existing box\n");
93 isds_set_logging(ILF_ALL, ILL_ALL);
94 err = isds_request_new_testing_box(request_ctx, db_owner_info, users,
95 "Former Names", &approval, &refnumber);
96 isds_set_logging(ILF_ALL & ~ILF_HTTP, ILL_ALL);
97 if (err) {
98 printf("isds_request_new_testing_box() failed: %s: %s\n",
99 isds_strerror(err), isds_long_message(request_ctx));
100 } else {
101 printf("isds_request_new_testing_box() succeeded as request #%s: "
102 "new box ID: %s\n",
103 refnumber, db_owner_info->dbID);
106 err = isds_ctx_free(&request_ctx);
107 if (err) {
108 printf("isds_ctx_free() failed: %s\n", isds_strerror(err));
112 isds_DbOwnerInfo_free(&db_owner_info);
113 isds_list_free(&users);
116 err = isds_logout(ctx);
117 if (err) {
118 printf("isds_logout() failed: %s\n", isds_strerror(err));
122 err = isds_ctx_free(&ctx);
123 if (err) {
124 printf("isds_ctx_free() failed: %s\n", isds_strerror(err));
128 err = isds_cleanup();
129 if (err) {
130 printf("isds_cleanup() failed: %s\n", isds_strerror(err));
133 exit (EXIT_SUCCESS);