test: online/login describes returned error code
[libisds.git] / client / switchcommercial.c
blob151508308ad5af306214a696af7ce486e83587c2
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;
13 isds_error err;
14 struct isds_DbOwnerInfo *db_owner_info = NULL;
16 setlocale(LC_ALL, "");
18 err = isds_init();
19 if (err) {
20 printf("isds_init() failed: %s\n", isds_strerror(err));
21 exit(EXIT_FAILURE);
24 isds_set_logging(ILF_ALL & ~ILF_HTTP, ILL_ALL);
26 ctx = isds_ctx_create();
27 if (!ctx) {
28 printf("isds_ctx_create() failed");
31 err = isds_set_timeout(ctx, 10000);
32 if (err) {
33 printf("isds_set_timeout() failed: %s\n", isds_strerror(err));
36 /* err = isds_set_tls(ctx, ITLS_VERIFY_SERVER, 0);
37 if (err) {
38 printf("isds_set_tls(ITLS_VERIFY_SERVER) failed: %s\n",
39 isds_strerror(err));
42 err = isds_set_tls(ctx, ITLS_CA_FILE, "/etc/ssl/certs/ca-certificates.crt");
43 if (err) {
44 printf("isds_set_tls(ITLS_CA_FILE) failed: %s\n",
45 isds_strerror(err));
46 }*/
48 err = isds_login(ctx, url, username, password, NULL);
49 if (err) {
50 printf("isds_login() failed: %s: %s\n", isds_strerror(err),
51 isds_long_message(ctx));
52 } else {
53 printf("Logged in :)\n");
58 printf("Getting info about my box:\n");
59 err = isds_GetOwnerInfoFromLogin(ctx, &db_owner_info);
60 if (err) {
61 printf("isds_GetOwnerInfoFromLogin() failed: %s: %s\n",
62 isds_strerror(err), isds_long_message(ctx));
63 } else {
64 printf("isds_GetOwnerInfoFromLogin() succeeded\n");
66 print_DbOwnerInfo(db_owner_info);
70 /* Switch commecrial message receiving status */
71 if (db_owner_info) {
72 _Bool allow;
73 struct isds_DbOwnerInfo *new_db_owner_info = NULL;
74 char *refnumber = NULL;
76 if (db_owner_info->dbOpenAddressing)
77 allow = !*db_owner_info->dbOpenAddressing;
78 else
79 allow = 1;
81 printf("Switching commerical receiving status to: %s\n",
82 (allow) ? "true" : "false");
83 err = isds_switch_commercial_receiving(ctx, db_owner_info->dbID, allow,
84 NULL, &refnumber);
85 if (err)
86 printf("isds_switch_commercial_receiving() failed: %s: %s\n",
87 isds_strerror(err), isds_long_message(ctx));
88 else {
89 printf("isds_switch_commercial_receiving() succeeded "
90 "as request #%s\n", refnumber);
92 free(refnumber);
94 printf("Verifying info about my box:\n");
95 err = isds_GetOwnerInfoFromLogin(ctx, &new_db_owner_info);
96 if (err) {
97 printf("isds_GetOwnerInfoFromLogin() failed: %s: %s\n",
98 isds_strerror(err), isds_long_message(ctx));
99 } else {
100 printf("isds_GetOwnerInfoFromLogin() succeeded\n");
101 printf("New status is: ");
102 print_bool(new_db_owner_info->dbOpenAddressing);
104 isds_DbOwnerInfo_free(&new_db_owner_info);
107 isds_DbOwnerInfo_free(&db_owner_info);
110 err = isds_logout(ctx);
111 if (err) {
112 printf("isds_logout() failed: %s\n", isds_strerror(err));
116 err = isds_ctx_free(&ctx);
117 if (err) {
118 printf("isds_ctx_free() failed: %s\n", isds_strerror(err));
122 err = isds_cleanup();
123 if (err) {
124 printf("isds_cleanup() failed: %s\n", isds_strerror(err));
127 exit (EXIT_SUCCESS);