88c2bf4a4fd3c358433f0c13c660e35bcd97ad60
[radsecproxy.git] / lib / examples / server.c
1 /* RADIUS/RadSec server using libradsec. */
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <assert.h>
6 #include <string.h>
7 #include <radsec/radsec.h>
8 #include <event2/event.h>
9 #include "debug.h"              /* For rs_dump_message(). */
10
11 #define CONFIG_FILE "examples/test.conf"
12 #define CONFIG "tls"
13
14 #define SECRET "sikrit"
15 #define USER_NAME "molgan@PROJECT-MOONSHOT.ORG"
16 #define USER_PW "password"
17
18
19 struct rs_error *
20 server (struct rs_context *ctx)
21 {
22   struct rs_error *err = NULL;
23   struct rs_connection *conn = NULL;
24 #if 0
25   struct rs_listener *listener = NULL;
26
27   if (rs_listener_create (ctx, &listener, CONFIG))
28     goto out;
29
30   while (1)
31     {
32       if (rs_listener_dispatch (listener))
33         goto out;
34     }
35
36  out:
37 #endif
38
39   err = rs_err_ctx_pop (ctx);
40   if (err == NULL)
41     err = rs_err_conn_pop (conn);
42
43 #if 0
44   if (listener)
45     rs_listener_destroy (listener);
46   listener = NULL;
47 #endif
48
49   return err;
50 }
51
52 int
53 main (int argc, char *argv[])
54 {
55   struct rs_error *err = NULL;
56   struct rs_context *ctx = NULL;
57
58   if (rs_context_create (&ctx))
59     goto out;
60   if (rs_context_read_config (ctx, CONFIG_FILE))
61     goto out;
62
63   {                             /* DEBUG printouts */
64     char *buf = NULL;
65     int err = rs_context_print_config (ctx, &buf);
66     assert (err == RSE_OK);
67     fputs (buf, stdout);
68     free (buf);
69   }
70
71   err = server (ctx);
72
73  out:
74   if (ctx)
75     rs_context_destroy (ctx);
76
77   if (err)
78     {
79       fprintf (stderr, "error: %s: %d\n", rs_err_msg (err), rs_err_code (err, 0));
80       return rs_err_code (err, 1);
81     }
82   return 0;
83 }