doc: Update maximum message size
[libisds.git] / client / logger.c
blob3f219ea95483c07a76cea1be7a960880100a57b9
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 /* Silent warning about unused argument.
13 * It's a libisds' protopype isds_log_callback. */
14 (void) data;
16 printf("\033[32mLOG(%02d,%02d): ", facility, level);
17 printf("%.*s", length, message);
18 printf("\033[m");
22 int main(void) {
23 struct isds_ctx *ctx = NULL;
24 isds_error err;
26 setlocale(LC_ALL, "");
28 err = isds_init();
29 if (err) {
30 printf("isds_init() failed: %s\n", isds_strerror(err));
31 exit(EXIT_FAILURE);
32 } else {
33 printf("isds_init() succeeded\n");
36 isds_set_log_callback(logger, NULL);
37 isds_set_logging(ILF_ALL, ILL_ALL);
39 ctx = isds_ctx_create();
40 if (!ctx) {
41 printf("isds_ctx_create() failed");
42 } else {
43 printf("isds_ctx_create() succeeded\n");
47 err = isds_set_timeout(ctx, 10000);
48 if (err) {
49 printf("isds_set_timeout() failed: %s\n", isds_strerror(err));
50 } else {
51 printf("isds_set_timeout() succeeded\n");
55 err = isds_login(ctx, url, username(), password(), NULL, NULL);
56 if (err) {
57 printf("isds_login() failed: %s: %s\n", isds_strerror(err),
58 isds_long_message(ctx));
59 } else {
60 printf("Logged in :)\n");
64 err = isds_logout(ctx);
65 if (err) {
66 printf("isds_logout() failed: %s\n", isds_strerror(err));
67 } else {
68 printf("isds_logout() succeeded\n");
73 err = isds_ctx_free(&ctx);
74 if (err) {
75 printf("isds_ctx_free() failed: %s\n", isds_strerror(err));
76 } else {
77 printf("isds_ctx_free() succeeded\n");
82 err = isds_cleanup();
83 if (err) {
84 printf("isds_cleanup() failed: %s\n", isds_strerror(err));
85 } else {
86 printf("isds_ctx_cleanup() succeeded\n");
90 exit (EXIT_SUCCESS);