#include #include #include #include #include "espik_global.h" #include "espik_net.h" #include "espik_common_handler.h" #include "espik_error.h" #include "espik_debug.h" #include "espik_irc.h" #include "espik.h" #include #include typedef int (*Handler_Func) (void* data, int ev_type, void* ev); static int ret; /* For debug */ char connected = 0; Ecore_Con_Server* con_sock; void espik_con_init (t_info serv_info) { int nb_launch; espik_enter(); nb_launch = ecore_con_init (); /* espik_debug_printf ("nb_launch = %d", nb_launch); */ con_sock = ecore_con_server_connect (ECORE_CON_REMOTE_SYSTEM, serv_info.server->host, (int)serv_info.server->port, NULL); if (!con_sock) { espik_debug_print ("ecore_con_server_connect failed " "(ECORE_CON_REMOTE_SYSTEM)"); exit (-1); } if (! (ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DATA, (Handler_Func) server_data, NULL))) { espik_debug_print ("ecore_event_handler_add " "(ECORE_CON_EVENT_SERVER_DATA)"); exit (-1); } if (! (ecore_event_handler_add (ECORE_CON_EVENT_SERVER_ADD, (Handler_Func) espik_con_up, NULL))) { espik_debug_print ("ecore_event_handler_add " "(ECORE_CON_EVENT_SERVER_ADD)"); exit (-1); } if (! (ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DEL, (Handler_Func) espik_con_shutdown, NULL))) { espik_debug_print ("ecore_event_handler_add " "(ECORE_CON_EVENT_SERVER_DEL)"); exit (-1); } espik_leave(); } void espik_con_up() { espik_enter(); printf ("Connected\n"); espik_debug_print ("<<<<<<<< DUMMMMY CODE >>>>>>>"); char *tmp, *tmp2; tmp = malloc (sizeof(char)*(strlen("NICK ") + strlen (a_infos.client->nickname))); tmp2 = malloc (sizeof(char)*(strlen("USER localhost:") + strlen(a_infos.client->nickname)*2 + strlen (a_infos.client->realname))); sprintf (tmp, "NICK %s", a_infos.client->nickname); sprintf (tmp2, "USER %s %s localhost: %s", a_infos.client->nickname, a_infos.client->nickname, a_infos.client->realname); espik_raw_send (tmp); espik_raw_send (tmp2); espik_raw_send ("JOIN #e.fr"); espik_debug_print ("<<<<<<<< DUMMMMY CODE >>>>>>>"); connected++; espik_leave(); } void espik_con_shutdown () { espik_enter(); if (!connected) espik_debug_print ("Unable to connect to server"); espik_debug_print ("ecore_con_server_del: %p", ecore_con_server_del (con_sock)); ecore_con_shutdown (); ecore_main_loop_quit (); espik_leave(); } void espik_raw_send (char *msg) { buf_t buf; espik_enter(); buf = make_buffer (strlen(msg) + 3); snprintf (buf.buf, buf.len, "%s\r\n", msg); espik_debug_print ("msg: %s\nout: %s", msg, buf.buf); /* printf ("out[len-3]: 0x%X\n", out[len - 3]); printf ("out[len-2]: 0x%X\n", out[len - 2]); printf ("out[len-1]: 0x%X\n", out[len - 1]); */ ret = ecore_con_server_send (con_sock, buf.buf, buf.len); espik_debug_print ("%d", ret); free (buf.buf); espik_leave(); }