aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Ghigonis <laurent@p1sec.com>2012-12-04 16:58:58 +0100
committerLaurent Ghigonis <laurent@p1sec.com>2012-12-04 16:58:58 +0100
commitb05a57a5bae18cb5909b4ec587436a5487b1cff9 (patch)
tree80c5b486b5ab91822dc696c69f8e1c25ac264044
parentlink to libevent and libglouglou (diff)
downloadglouglou-b05a57a5bae18cb5909b4ec587436a5487b1cff9.tar.xz
glouglou-b05a57a5bae18cb5909b4ec587436a5487b1cff9.zip
basic version that opens an elementary window, connects to glougloud server
and prints received connection packets
-rw-r--r--gg_map/gg_map.c256
1 files changed, 51 insertions, 205 deletions
diff --git a/gg_map/gg_map.c b/gg_map/gg_map.c
index 646cfac..04e2aca 100644
--- a/gg_map/gg_map.c
+++ b/gg_map/gg_map.c
@@ -3,237 +3,76 @@
#include <Elementary.h>
#include <libglouglou.h>
-
-struct conn {
- int id;
- struct node *nsrc;
- struct node *ndst;
- int proto;
- int size;
- char name[DNSNAME_MAX];
- Evas_Object *line;
-};
-
-struct node {
- char name[DNSNAME_MAX];
- u_int ip;
- char fqdn[DNSNAME_MAX];
- Evas_Object *btn;
-};
+#include <libggnet.h>
Evas_Object *_mainwin, *_connbox;
Eina_List *_conns = NULL;
Eina_List *_nodes = NULL;
+struct event_base *_ev_base;
-static struct conn *conn_add(u_int, struct node *, struct node *, u_int, u_int);
-static void conn_del(struct conn *);
-static struct conn *conn_find(u_int);
-static struct conn *conn_find_or_create(u_int, struct node *, struct node *, u_int, u_int);
-static struct node *node_add(u_int);
-static void node_del(struct node *);
-static struct node *node_find(u_int);
-static struct node *node_find_or_create(u_int);
-static void node_update_name(struct node *, char *, int);
-
-static struct conn *
-conn_add(u_int id, struct node *nsrc, struct node *ndst, u_int proto, u_int size)
-{
- struct conn *c;
-
- c = calloc(sizeof(struct conn), 1);
- if (!c)
- err(1, "calloc failed in conn_add\n");
- c->id = id;
- c->nsrc = nsrc;
- c->ndst = ndst;
- c->proto = proto;
- c->size = size;
- snprintf(c->name, sizeof(c->name), "%d: %x -> %x - %d",
- id, nsrc->ip, ndst->ip, proto);
-
- _conns = eina_list_append(_conns, c);
-
- // XXX c->line evas
-
- return c;
-}
-
-static void
-conn_del(struct conn *c)
-{
- if (c->line)
- evas_object_del(c->line);
- _conns = eina_list_prepend(_conns, c);
- free(c);
-}
-
-static struct conn *
-conn_find(u_int id)
-{
- struct conn *c;
- Eina_List *l;
-
- EINA_LIST_FOREACH(_conns, l, c)
- if (c->id == id)
- return c;
- return NULL;
-}
-
-static struct conn *
-conn_find_or_create(u_int id, struct node *nsrc, struct node *ndst, u_int proto, u_int size)
-{
- struct conn *c;
-
- c = conn_find(id);
- if (!c)
- c = conn_add(id, nsrc, ndst, proto, size);
- return c;
-}
-
-static struct node *
-node_add(u_int ip)
-{
- struct node *n;
-
- n = calloc(sizeof(struct node), 1);
- if (!n)
- err(1, "calloc failed in node_add\n");
- n->ip = ip;
-
- _nodes = eina_list_append(_nodes, n);
-
- n->btn = elm_button_add(_mainwin);
- node_update_name(n, NULL, 0);
- elm_box_pack_end(_connbox, n->btn);
- evas_object_show(n->btn);
-
- return n;
-}
-
-static void
-node_del(struct node *n)
-{
- if (n->btn)
- evas_object_del(n->btn);
- _nodes = eina_list_prepend(_nodes, n);
- free(n);
-}
-
-static struct node *
-node_find(u_int ip)
-{
- struct node *n;
- Eina_List *l;
-
- EINA_LIST_FOREACH(_nodes, l, n)
- if (n->ip == ip)
- return n;
- return NULL;
-}
-
-static struct node *
-node_find_or_create(u_int ip)
-{
- struct node *n;
-
- n = node_find(ip);
- if (!n)
- n = node_add(ip);
- return n;
-}
-
-static void
-node_update_name(struct node *n, char *name, int len)
-{
- if (!name) {
- snprintf(n->name, sizeof(n->name), "%x", n->ip);
- } else {
- if (len > sizeof(n->name))
- len = sizeof(n->name);
- strncpy(n->name, name, len);
- }
- elm_object_text_set(n->btn, n->name);
+static Eina_Bool
+_cb_ecore_libevent(void *data) {
+ if (event_base_got_exit(_ev_base))
+ return EINA_FALSE;
+ else
+ event_base_loop(_ev_base, EVLOOP_NONBLOCK);
+ return EINA_TRUE;
}
-static Eina_Bool
-_cb_conn_data(void *data, int type, Ecore_Con_Event_Server_Data *ev)
+int
+_cb_packet(struct gg_client *cli, struct gg_packet *pkt)
{
- u_int id, ip, src, dst, proto, size, len;
- struct node *n, *nsrc, *ndst;
- struct conn *c;
- struct packet *p;
+ struct ggnet_node *n, *nsrc, *ndst;
+ struct ggnet_conn *c;
char *fqdn;
int i;
- printf("data received:\n");
- for (i=0; i < ev->size; i++){
- printf("%2.2x ", ((u_char *)ev->data)[i]);
- if( (i%15 == 0 && i!=0) || i==ev->size-1 )
- printf("\n");
- }
-
- p = ev->data;
- switch(p->type) {
+ switch(pkt->type) {
case PACKET_NEWCONN:
- id = p->newconn_id;
- src = ntohl(p->newconn_src);
- dst = ntohl(p->newconn_dst);
- proto = p->newconn_proto;
- size = ntohs(p->newconn_size);
-
printf(" type PACKET_NEWCONN\n");
- printf(" newconn_id %d\n", id);
- printf(" newconn_src %4x\n", src);
- printf(" newconn_dst %4x\n", dst);
- printf(" newconn_proto %d\n", proto);
- printf(" newconn_size %d\n", size);
+ printf(" newconn_id %d\n", pkt->newconn_id);
+ printf(" newconn_src %4x\n", pkt->newconn_src);
+ printf(" newconn_dst %4x\n", pkt->newconn_dst);
+ printf(" newconn_proto %d\n", pkt->newconn_proto);
+ printf(" newconn_size %d\n", pkt->newconn_size);
- nsrc = node_find_or_create(src);
- ndst = node_find_or_create(dst);
- conn_find_or_create(id, nsrc, ndst, proto, size);
+ //nsrc = node_find_or_create(pkt->newconn_src);
+ //ndst = node_find_or_create(pkt->newconn_dst);
+ //conn_find_or_create(pkt->newconn_id, pkt->newconn_nsrc, pkt->newconn_ndst, pkt->newconn_proto, pkt->newconn_size);
break;
case PACKET_DELCONN:
- id = p->delconn_id;
-
printf(" type PACKET_DELCONN\n");
- printf(" delconn_id %d\n", id);
+ printf(" delconn_id %d\n", pkt->delconn_id);
- n = node_find(id);
- if (n)
- node_del(n);
+ //n = node_find(id);
+ //if (n)
+ // node_del(n);
break;
case PACKET_DATA:
- id = p->data_connid;
- size = ntohs(p->data_size);
-
printf(" type PACKET_DATA\n");
- printf(" data_connid %d\n", id);
- printf(" data_size %d\n", size);
+ printf(" data_connid %d\n", pkt->data_connid);
+ printf(" data_size %d\n", pkt->data_size);
- c = conn_find(id);
+ //c = conn_find(id);
// XXX evas_point on conn line
break;
case PACKET_NAME:
- ip = ntohl(p->name_addr);
- len = p->name_len;
- fqdn = (char *)p->name_fqdn;
-
printf(" type PACKET_NAME\n");
- printf(" name_addr %4x\n", ip);
- printf(" name_len %d\n", len);
- printf(" name_name_fqdn %s\n", fqdn);
+ printf(" name_addr %4x\n", pkt->name_addr);
+ printf(" name_len %d\n", pkt->name_len);
+ printf(" name_name_fqdn %s\n", pkt->name_fqdn);
- n = node_find(ip);
- if (n)
- node_update_name(n, fqdn, len);
+ //n = node_find(ip);
+ //if (n)
+ // node_update_name(n, fqdn, len);
break;
}
- return ECORE_CALLBACK_RENEW;
+ return 0;
}
static void
@@ -246,7 +85,9 @@ EAPI_MAIN int
elm_main(int argc, char **argv)
{
Evas_Object *box, *lab, *btn, *bg;
- Ecore_Con_Server *conn;
+ Ecore_Timer *timer_libevent;
+ struct gg_client *ggcli;
+ int retval = -1;
_mainwin = elm_win_util_standard_add("hello", "Hello");
evas_object_smart_callback_add(_mainwin, "delete,request", _cb_on_done, NULL);
@@ -262,7 +103,7 @@ elm_main(int argc, char **argv)
evas_object_show(box);
lab = elm_label_add(_mainwin);
- elm_object_text_set(lab, "Welcome to glouglou_efl");
+ elm_object_text_set(lab, "Welcome to Glouglou Map");
elm_box_pack_end(box, lab);
evas_object_show(lab);
@@ -277,14 +118,19 @@ elm_main(int argc, char **argv)
evas_object_show(_mainwin);
- ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA,
- (Ecore_Event_Handler_Cb)_cb_conn_data, NULL);
- conn = ecore_con_server_connect(ECORE_CON_REMOTE_UDP, "127.0.0.1", 4430, NULL);
- ecore_con_server_send(conn, "hello", 5);
- ecore_con_server_flush(conn);
+ _ev_base = event_base_new();
+ ggcli = gg_client_connect(_ev_base, "127.0.0.1", GLOUGLOU_ANALY_DEFAULT_PORT,
+ NULL, _cb_packet, NULL);
+ if (!ggcli)
+ goto quit;
+
+ timer_libevent = ecore_timer_add(0.1, _cb_ecore_libevent, NULL);
elm_run();
+ retval = 0;
+
+quit:
elm_shutdown();
- return 0;
+ return retval;
}
ELM_MAIN()