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