Increase version to 0.10.2
[libisds.git] / client / changepassword.c
blob611540b04a5f2fd9c978bf8421e8e55659a58084
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"
10 void change_password(struct isds_ctx *ctx,
11 const char *old_password, const char *new_password) {
12 printf("Changing password to: `%s'\n", new_password);
13 if (old_password && new_password && !strcmp(old_password, new_password))
14 printf("(Same as old password)\n");
15 if (!old_password)
16 printf("(Old password omitted)\n");
17 isds_error err = isds_change_password(ctx, old_password, new_password,
18 NULL, NULL);
19 if (err) {
20 printf("isds_change_password() failed: %s: %s\n",
21 isds_strerror(err), isds_long_message(ctx));
22 } else {
23 printf("isds_change_password() succeeded.\n"
24 "This should not happen");
26 printf("\n");
29 int main(void) {
30 struct isds_ctx *ctx = NULL;
31 isds_error err;
33 setlocale(LC_ALL, "");
35 err = isds_init();
36 if (err) {
37 printf("isds_init() failed: %s\n", isds_strerror(err));
38 exit(EXIT_FAILURE);
41 isds_set_logging(ILF_ALL & ~ILF_HTTP, ILL_ALL);
43 ctx = isds_ctx_create();
44 if (!ctx) {
45 printf("isds_ctx_create() failed");
48 err = isds_set_timeout(ctx, 10000);
49 if (err) {
50 printf("isds_set_timeout() failed: %s\n", isds_strerror(err));
53 err = isds_login(ctx, url, username(), password(), NULL, NULL);
54 if (err) {
55 printf("isds_login() failed: %s: %s\n", isds_strerror(err),
56 isds_long_message(ctx));
57 } else {
58 printf("Logged in :)\n");
62 /* Try some invalid invocations that should fail */
63 change_password(ctx, password(), NULL);
64 change_password(ctx, password(), "");
65 change_password(ctx, password(), password());
69 err = isds_logout(ctx);
70 if (err) {
71 printf("isds_logout() failed: %s\n", isds_strerror(err));
75 err = isds_ctx_free(&ctx);
76 if (err) {
77 printf("isds_ctx_free() failed: %s\n", isds_strerror(err));
81 err = isds_cleanup();
82 if (err) {
83 printf("isds_cleanup() failed: %s\n", isds_strerror(err));
86 exit (EXIT_SUCCESS);