]> git.meshlink.io Git - catta/blob - main.c
0479f14b56c3ffbe7d59aae5080a7d66c0564e29
[catta] / main.c
1 #include <sys/socket.h>
2 #include <netinet/in.h>
3 #include <arpa/inet.h>
4
5 #include "flx.h"
6 #include "server.h"
7 #include "subscribe.h"
8
9 static gboolean quit_timeout(gpointer data) {
10     g_main_loop_quit(data);
11     return FALSE;
12 }
13
14 static gboolean send_timeout(gpointer data) {
15     flxServer *flx = data;
16     flxKey *k;
17
18     k = flx_key_new("ecstasy.local.", FLX_DNS_CLASS_IN, FLX_DNS_TYPE_TXT);
19     flx_server_post_query(flx, 0, AF_UNSPEC, k);
20     flx_key_unref(k);
21
22     k = flx_key_new("ecstasy.local.", FLX_DNS_CLASS_IN, FLX_DNS_TYPE_A);
23     flx_server_post_query(flx, 0, AF_INET, k);
24     flx_key_unref(k);
25
26     return FALSE;
27 }
28
29 static gboolean dump_timeout(gpointer data) {
30     flxServer *flx = data;
31     flx_server_dump(flx, stdout);
32     return TRUE;
33 }
34
35 static void subscription(flxSubscription *s, flxRecord *r, gint interface, guchar protocol, flxSubscriptionEvent event, gpointer userdata) {
36     gchar *t;
37     
38     g_assert(s);
39     g_assert(r);
40     g_assert(interface > 0);
41     g_assert(protocol != AF_UNSPEC);
42
43     g_message("SUBSCRIPTION: record [%s] on %i.%i is %s", t = flx_record_to_string(r), interface, protocol,
44               event == FLX_SUBSCRIPTION_NEW ? "new" : (event == FLX_SUBSCRIPTION_CHANGE ? "changed" : "removed"));
45
46     g_free(t);
47 }
48
49
50 int main(int argc, char *argv[]) {
51     flxServer *flx;
52     gchar *r;
53     GMainLoop *loop = NULL;
54     flxSubscription *s;
55     flxKey *k;
56
57     flx = flx_server_new(NULL);
58
59     flx_server_add_text(flx, 0, 0, AF_UNSPEC, FALSE, NULL, "hallo", NULL);
60
61 /*     k = flx_key_new("ecstasy.local.", FLX_DNS_CLASS_IN, FLX_DNS_TYPE_ANY); */
62 /*     s = flx_subscription_new(flx, k, 0, AF_UNSPEC, subscription, NULL); */
63 /*     flx_key_unref(k); */
64
65     loop = g_main_loop_new(NULL, FALSE);
66     
67     g_timeout_add(1000*30, quit_timeout, loop);
68     g_timeout_add(1000, send_timeout, flx);
69     g_timeout_add(1000*20, dump_timeout, flx);
70     
71     g_main_loop_run(loop);
72
73     g_main_loop_unref(loop);
74
75 /*     flx_subscription_free(s); */
76     flx_server_free(flx);
77     
78     return 0;
79 }