]> git.meshlink.io Git - catta/blob - main.c
3bf4360bc9cad3168437d6bbc7c58058f6a7cf0e
[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     flx_server_add_service(flx, 0, 0, AF_UNSPEC, "_http._tcp", "gurke", NULL, NULL, 80, "foo", NULL);
61
62 /*     k = flx_key_new("ecstasy.local.", FLX_DNS_CLASS_IN, FLX_DNS_TYPE_ANY); */
63 /*     s = flx_subscription_new(flx, k, 0, AF_UNSPEC, subscription, NULL); */
64 /*     flx_key_unref(k); */
65
66     loop = g_main_loop_new(NULL, FALSE);
67     
68     g_timeout_add(1000*30, quit_timeout, loop);
69     g_timeout_add(1000, send_timeout, flx);
70     g_timeout_add(1000*20, dump_timeout, flx);
71     
72     g_main_loop_run(loop);
73
74     g_main_loop_unref(loop);
75
76 /*     flx_subscription_free(s); */
77     flx_server_free(flx);
78     
79     return 0;
80 }