1 #define _XOPEN_SOURCE 500
10 void reset_password(struct isds_ctx
*ctx
,
11 const struct isds_DbOwnerInfo
*box
, const struct isds_DbUserInfo
*user
,
13 struct isds_credentials_delivery
*credentials_delivery
) {
14 char *refnumber
= NULL
;
16 printf("Resetting password\n");
17 isds_error err
= isds_reset_password(ctx
, box
, user
, paid
, NULL
,
18 credentials_delivery
, &refnumber
);
20 printf("isds_reset_password() failed: %s: %s\n",
21 isds_strerror(err
), isds_long_message(ctx
));
23 printf("isds_reset_password() succeeded as request #%s.\n"
24 "This should not happen\n", refnumber
);
25 if (credentials_delivery
) {
26 printf("email = %s\n", credentials_delivery
->email
);
27 printf("token = %s\n", credentials_delivery
->token
);
28 printf("new_user_name = %s\n", credentials_delivery
->new_user_name
);
36 struct isds_ctx
*ctx
= NULL
;
38 struct isds_DbOwnerInfo
*db_owner_info
= NULL
;
39 struct isds_DbUserInfo
*db_user_info
= NULL
;
41 setlocale(LC_ALL
, "");
45 printf("isds_init() failed: %s\n", isds_strerror(err
));
49 isds_set_logging(ILF_ALL
& ~ILF_HTTP
, ILL_ALL
);
51 ctx
= isds_ctx_create();
53 printf("isds_ctx_create() failed");
56 err
= isds_set_timeout(ctx
, 10000);
58 printf("isds_set_timeout() failed: %s\n", isds_strerror(err
));
61 err
= isds_login(ctx
, url
, username(), password(), NULL
, NULL
);
63 printf("isds_login() failed: %s: %s\n", isds_strerror(err
),
64 isds_long_message(ctx
));
66 printf("Logged in :)\n");
71 /* Get info about my box */
72 printf("Getting info about my box:\n");
73 err
= isds_GetOwnerInfoFromLogin(ctx
, &db_owner_info
);
75 printf("isds_GetOwnerInfoFromLogin() failed: %s: %s\n",
76 isds_strerror(err
), isds_long_message(ctx
));
78 printf("isds_GetOwnerInfoFromLogin() succeeded\n");
80 print_DbOwnerInfo(db_owner_info
);
84 /* Get info about my account */
85 printf("Getting info about my account:\n");
86 err
= isds_GetUserInfoFromLogin(ctx
, &db_user_info
);
88 printf("isds_GetUserInfoFromLogin() failed: %s: %s\n",
89 isds_strerror(err
), isds_long_message(ctx
));
91 printf("isds_GetUserInfoFromLogin() succeeded\n");
92 print_DbUserInfo(db_user_info
);
96 if (db_owner_info
&& db_user_info
) {
98 struct isds_credentials_delivery credentials_delivery
;
99 /* Try some invalid invocation that should fail */
100 reset_password(ctx
, db_owner_info
, db_user_info
, 0, NULL
);
101 reset_password(ctx
, db_owner_info
, db_user_info
, 1, NULL
);
103 credentials_delivery
.email
= NULL
;
104 credentials_delivery
.token
= NULL
;
105 credentials_delivery
.new_user_name
= NULL
;
106 reset_password(ctx
, db_owner_info
, db_user_info
, 1,
107 &credentials_delivery
);
108 free(credentials_delivery
.token
);
109 free(credentials_delivery
.new_user_name
);
111 credentials_delivery
.email
= "42";
112 credentials_delivery
.token
= NULL
;
113 credentials_delivery
.new_user_name
= NULL
;
114 reset_password(ctx
, db_owner_info
, db_user_info
, 1,
115 &credentials_delivery
);
116 free(credentials_delivery
.token
);
117 free(credentials_delivery
.new_user_name
);
119 fprintf(stderr
, "This function can lose current user credentials. "
123 isds_DbOwnerInfo_free(&db_owner_info
);
124 isds_DbUserInfo_free(&db_user_info
);
127 err
= isds_logout(ctx
);
129 printf("isds_logout() failed: %s\n", isds_strerror(err
));
133 err
= isds_ctx_free(&ctx
);
135 printf("isds_ctx_free() failed: %s\n", isds_strerror(err
));
139 err
= isds_cleanup();
141 printf("isds_cleanup() failed: %s\n", isds_strerror(err
));