#include #include #include #include #include "espik_global.h" #include "espik_common_handler.h" #include "espik_error.h" #include "espik_irc.h" #include "espik.h" #include "espik_net.h" #include #include typedef int (*Handler_Func) (void* data, int ev_type, void* ev); Ecore_Con_Server* con_sock; Ecore_Event_Handler* ret; int connected = 0; void espik_con_init (t_info serv_info) { int nb_launch; nb_launch = ecore_con_init (); /* printff ("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) { printf ("ecore_con_server_connect failed " "(ECORE_CON_REMOTE_SYSTEM)"); exit (-1); } espik_free (con_sock); if (! (ret = ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DATA, (Handler_Func) server_data, NULL))) { printf ("ecore_event_handler_add " "(ECORE_CON_EVENT_SERVER_DATA)"); exit (-1); } espik_free (ret); if (! (ret = ecore_event_handler_add (ECORE_CON_EVENT_SERVER_ADD, (Handler_Func) espik_con_up, NULL))) { printf ("ecore_event_handler_add " "(ECORE_CON_EVENT_SERVER_ADD)"); exit (-1); } espik_free (ret); if (! (ret = ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DEL, (Handler_Func) espik_con_shutdown, NULL))) { printf ("ecore_event_handler_add " "(ECORE_CON_EVENT_SERVER_DEL)"); exit (-1); } espik_free (ret); } void send_login (void) { /* printf ("<<<<<<<< DUMMMMY CODE >>>>>>>"); */ char *tmp, *tmp2; tmp = malloc ( strlen("NICK ") + strlen (a_infos.client->nickname)); tmp2 = malloc ( strlen("USER :") + strlen(a_infos.client->nickname)*2 + strlen (a_infos.client->realname) + strlen (a_infos.server->host)); sprintf (tmp, "NICK %s", a_infos.client->nickname); sprintf (tmp2, "USER %s %s %s: %s", a_infos.client->nickname, a_infos.client->nickname, a_infos.server->host, a_infos.client->realname); printf("tmp: %s", tmp); espik_raw_send (tmp); printf("tmp2: %s", tmp2); espik_raw_send (tmp2); espik_raw_send ("JOIN #e.fr"); /* printf ("<<<<<<<< DUMMMMY CODE >>>>>>>"); */ free (tmp); free (tmp2); connected++; } void espik_con_up(void) { printf ("Connected\n"); } void espik_con_shutdown (void) { if (!connected) printf ("Unable to connect to server"); printf ("ecore_con_server_del: %p", ecore_con_server_del (con_sock)); ecore_con_shutdown (); /* ecore_event_handler_del (handler_list.data); ecore_event_handler_del (handler_list.up); ecore_event_handler_del (handler_list.down); */ ecore_main_loop_quit (); } void espik_raw_send (const char *msg) { buf_t buf; int i; buf = make_buffer (strlen(msg) + 1); /* \r\n\0" */ snprintf (buf.buf, buf.len, "%s\r\n", msg); /* Override trailing \0 */ buf.buf[buf.len-1] = '\n'; /* buf.buf[buf.len] = '\0'; */ /* 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]); */ ecore_con_server_send (con_sock, buf.buf, buf.len); free (buf.buf); /* free (msg); */ }