TODO: PDZInfo tested
[libisds.git] / client / logger.c
blob6d57710b957e56d4e2ab8cd8b8e37137ac309514
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 logger(isds_log_facility facility, isds_log_level level,
11 const char *message, int length, void *data) {
12 printf("\033[32mLOG(%02d,%02d): ", facility, level);
13 printf("%.*s", length, message);
14 printf("\033[m");
18 int main(int argc, char **argv) {
19 struct isds_ctx *ctx = NULL;
20 isds_error err;
22 setlocale(LC_ALL, "");
24 err = isds_init();
25 if (err) {
26 printf("isds_init() failed: %s\n", isds_strerror(err));
27 exit(EXIT_FAILURE);
28 } else {
29 printf("isds_init() succeeded\n");
32 isds_set_log_callback(logger, NULL);
33 isds_set_logging(ILF_ALL, ILL_ALL);
35 ctx = isds_ctx_create();
36 if (!ctx) {
37 printf("isds_ctx_create() failed");
38 } else {
39 printf("isds_ctx_create() succeeded\n");
43 err = isds_set_timeout(ctx, 10000);
44 if (err) {
45 printf("isds_set_timeout() failed: %s\n", isds_strerror(err));
46 } else {
47 printf("isds_set_timeout() succeeded\n");
51 err = isds_login(ctx, url, username(), password(), NULL, NULL);
52 if (err) {
53 printf("isds_login() failed: %s: %s\n", isds_strerror(err),
54 isds_long_message(ctx));
55 } else {
56 printf("Logged in :)\n");
60 err = isds_logout(ctx);
61 if (err) {
62 printf("isds_logout() failed: %s\n", isds_strerror(err));
63 } else {
64 printf("isds_logout() succeeded\n");
69 err = isds_ctx_free(&ctx);
70 if (err) {
71 printf("isds_ctx_free() failed: %s\n", isds_strerror(err));
72 } else {
73 printf("isds_ctx_free() succeeded\n");
78 err = isds_cleanup();
79 if (err) {
80 printf("isds_cleanup() failed: %s\n", isds_strerror(err));
81 } else {
82 printf("isds_ctx_cleanup() succeeded\n");
86 exit (EXIT_SUCCESS);