Adapt to OpenSSL 1.1.0
[libisds.git] / client / requestnewtestingbox.c
blobec39636af0c682e8b5c006489940dda9dab0e102
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"
12 int main(void) {
13 struct isds_ctx *ctx = NULL, *request_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 /* Request for creating the same box */
79 if (db_owner_info) {
80 char *refnumber = NULL;
81 const struct isds_approval approval = {
82 .approved = 1, .refference = "Me"
85 free(db_owner_info->email);
86 db_owner_info->email = strdup("franta@example.com");
88 request_ctx = isds_ctx_create();
89 if (!request_ctx) {
90 printf("isds_ctx_create() failed");
93 printf("Requesting to create already existing box\n");
94 isds_set_logging(ILF_ALL, ILL_ALL);
95 err = isds_request_new_testing_box(request_ctx, db_owner_info, users,
96 "Former Names", &approval, &refnumber);
97 isds_set_logging(ILF_ALL & ~ILF_HTTP, ILL_ALL);
98 if (err) {
99 printf("isds_request_new_testing_box() failed: %s: %s\n",
100 isds_strerror(err), isds_long_message(request_ctx));
101 } else {
102 printf("isds_request_new_testing_box() succeeded as request #%s: "
103 "new box ID: %s\n",
104 refnumber, db_owner_info->dbID);
107 err = isds_ctx_free(&request_ctx);
108 if (err) {
109 printf("isds_ctx_free() failed: %s\n", isds_strerror(err));
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);