3 #include "proto_detect.h"
6 static void proto_connect (net_hook_t* hook)
10 static void proto_close (net_hook_t* hook)
14 static void proto_write (net_hook_t* hook)
18 static void proto_read (net_hook_t* hook, gchar* buffer, size_t len)
22 str = (GString*) hook->data;
23 g_string_append_len (str, buffer, len);
26 if (!strncmp (str->str, "<stream", 7))
28 /* Connection is a Jabber client */
29 g_debug ("Connection from %s is a Jabber client.",
30 hook->conn->hostname);
31 new_hook = jabber_hook_new (hook->conn);
32 new_hook->read (new_hook, str->str, str->len);
33 proto_detect_destroy (hook);
37 g_debug ("Unrecognized protocol from %s.",
38 hook->conn->hostname);
39 gnet_conn_disconnect (hook->conn);
40 gnet_conn_unref (hook->conn);
41 proto_detect_destroy (hook);
46 net_hook_t* proto_detect_new (GConn* conn)
49 hook = g_slice_new (net_hook_t);
53 hook->connect = proto_connect;
54 hook->close = proto_close;
55 hook->write = proto_write;
56 hook->read = proto_read;
57 hook->data = g_string_sized_new (128);
58 gnet_conn_set_callback (hook->conn, nethook_event, hook);
62 void proto_detect_destroy (net_hook_t* hook)
64 if (hook->data != NULL)
66 g_string_free (hook->data, TRUE);
68 g_slice_free (net_hook_t, hook);