diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/espik.c | 6 | ||||
-rw-r--r-- | src/espik_common_handler.c | 72 | ||||
-rw-r--r-- | src/espik_common_handler.h | 3 | ||||
-rw-r--r-- | src/espik_config.c | 3 | ||||
-rw-r--r-- | src/espik_debug.c | 4 | ||||
-rw-r--r-- | src/espik_debug.h | 6 | ||||
-rw-r--r-- | src/espik_irc.c | 8 | ||||
-rw-r--r-- | src/espik_net.c | 55 | ||||
-rw-r--r-- | src/espik_net.h | 1 |
9 files changed, 135 insertions, 23 deletions
diff --git a/src/espik.c b/src/espik.c index ac3c4d0..f1d55dd 100644 --- a/src/espik.c +++ b/src/espik.c @@ -139,11 +139,13 @@ int main (int argc, char **argv) espik_debug_print ("end"); ecore_config_shutdown (); + /* - ecore_con_shutdown (); + espik_con_shutdown (); */ + ecore_shutdown (); - espik_leave(); + //espik_leave(); return (0); } diff --git a/src/espik_common_handler.c b/src/espik_common_handler.c index f3d1653..d581dc4 100644 --- a/src/espik_common_handler.c +++ b/src/espik_common_handler.c @@ -6,6 +6,8 @@ #include <Ecore.h> #include <Ecore_Con.h> +#include <wchar.h> + #include "espik_global.h" #include "espik_common_handler.h" #include "espik_irc.h" @@ -14,15 +16,79 @@ #include "espik_error.h" #include "espik_debug.h" +#if 0 +static char* convert_utf_unicode(char* putf) +{ + int len; + wchar_t* punicode; + espik_enter(); + + len = strlen(putf)+ 1; + + punicode = (wchar_t *)malloc(len * sizeof(wchar_t)); + + if (punicode == NULL) + return NULL; + +#ifdef UNICODE + strcpy(punicode,putf); +#else + if (mbstowcs(punicode,putf,len) < 0) + { + free(punicode); + return NULL; + } +#endif + + espik_leave(); + return punicode; +} + + +static char* convert_unicode_utf(const wchar_t *punicode) +{ + int len; + char* putf; + espik_enter(); + + len = wcslen(punicode) + 1; + + putf = (char *)malloc(len * sizeof(wchar_t)); + + if (!putf) + return NULL; +#ifdef UNICODE + strcpy(putf, punicode); +#else + if (wcstombs(putf,punicode,len) < 0) + { + free (putf); + return NULL; + } +#endif + espik_leave(); + return putf; +} +#endif + + int server_data (void* data __UNUSED__, int ev_type __UNUSED__, Ecore_Con_Event_Server_Data* ev) { unsigned int i; char* msg; espik_enter(); + static int count_num_recv = 0; msg = strdup((char*)ev->data); + //msg = convert_unicode_utf((const wchar_t*)ev->data); + //msg = convert_utf_unicode((char*)ev->data); + + if (!msg) + return 0; + count_num_recv++; + espik_debug_print ("%s", msg); for (i=0 ; i < strlen(msg) ; i++) @@ -31,6 +97,12 @@ int server_data (void* data __UNUSED__, int ev_type __UNUSED__, msg[i] = '\0'; } + if (count_num_recv >= 1 && !com_active) + { + server_dns = strdup (msg+1); + send_login(); + } + if (! (strcmp (msg, "PING"))) { espik_raw_send ("PONG guybrush.melee"); diff --git a/src/espik_common_handler.h b/src/espik_common_handler.h index c46ab6c..fddece4 100644 --- a/src/espik_common_handler.h +++ b/src/espik_common_handler.h @@ -6,6 +6,9 @@ #include "espik_global.h" +int com_active; +char* server_dns; + int server_data (void *__UNUSED__, int __UNUSED__, Ecore_Con_Event_Server_Data * __UNUSED__); int kb_get (void *__UNUSED__, Ecore_Fd_Handler *); diff --git a/src/espik_config.c b/src/espik_config.c index f24b32c..168dfbf 100644 --- a/src/espik_config.c +++ b/src/espik_config.c @@ -38,7 +38,8 @@ t_userinfo* espik_user_sysinfo_get () u_info = malloc (sizeof (t_userinfo)); - u_info->nickname = pw->pw_name; + //u_info->nickname = pw->pw_name; + u_info->nickname = strdup ("beber_espik_test"); u_info->username = pw->pw_name; if (! (pw->pw_gecos[0]) ) diff --git a/src/espik_debug.c b/src/espik_debug.c index 424408e..9badbd4 100644 --- a/src/espik_debug.c +++ b/src/espik_debug.c @@ -14,6 +14,7 @@ inline void espik_debug_bt (int num) { +#if 0 #ifdef __GLIBC__ #ifdef _ESPIK_DEBUG_ @@ -37,13 +38,14 @@ inline void espik_debug_bt (int num) free(strings); #endif /* _ESPIK_DEBUG_ */ - num ++; /* Just for avoid warning */ #endif /* __GLIBC__ */ #ifndef __GLIBC__ fprintf(stderr, "Your system doesn't have glibc. Backtraces disabled." "But program receive signal %d.\n", num); #endif /* __GLIBC__ */ +#endif + num ++; /* Just for avoid warning */ } void espik_debug_init() diff --git a/src/espik_debug.h b/src/espik_debug.h index 19f0746..b17a9fd 100644 --- a/src/espik_debug.h +++ b/src/espik_debug.h @@ -23,6 +23,7 @@ #ifdef _ESPIK_DEBUG_ int __indent_level; + #define espik_enter() \ { \ __indent_level++; \ @@ -30,6 +31,9 @@ int __indent_level; __FILE__, __LINE__, __func__); \ } +//#define espik_enter() {} + + #define espik_leave() \ { \ fprintf (DEBUG_ENTLEV_FILENO, "<%*c%s +%i @%s\n", __indent_level, ' ', \ @@ -37,6 +41,8 @@ int __indent_level; __indent_level--; \ } +//#define espik_leave() {} + #else #define espik_enter() \ diff --git a/src/espik_irc.c b/src/espik_irc.c index f0cc195..827a3e4 100644 --- a/src/espik_irc.c +++ b/src/espik_irc.c @@ -184,6 +184,7 @@ char* irc_quit (char* chan __UNUSED__, char* msg) irc_disconnect(sock); */ + free (msg); espik_leave(); return (out.buf); @@ -256,11 +257,11 @@ char* irc_send (char* msg) for (cmd = cmd_tab; cmd->cmd_name != 0; cmd++) { - if ((strcasecmp (cmd_and_message[0], cmd->cmd_name)) == - 0) + if ((strcasecmp (cmd_and_message[0], cmd->cmd_name)) == 0) { out = cmd->format (current_chan, cmd_and_message[1]); + free (msg); /* Why do job after found the good to do ? */ break; } @@ -276,6 +277,7 @@ char* irc_send (char* msg) else { out = irc_privmsg (current_chan, msg); + free (msg); } if (!out) @@ -284,7 +286,7 @@ char* irc_send (char* msg) return (0); } - espik_debug_print ("%sn", out); + espik_debug_print ("%s", out); espik_leave(); return (out); diff --git a/src/espik_net.c b/src/espik_net.c index d682c7e..e638682 100644 --- a/src/espik_net.c +++ b/src/espik_net.c @@ -28,6 +28,8 @@ void espik_con_init (t_info serv_info) nb_launch = ecore_con_init (); + com_active = 0; + /* espik_debug_printf ("nb_launch = %d", nb_launch); */ @@ -68,35 +70,46 @@ void espik_con_init (t_info serv_info) espik_leave(); } -void espik_con_up() +void send_login() { espik_enter(); - printf ("Connected\n"); - - espik_debug_print ("<<<<<<<< DUMMMMY CODE >>>>>>>"); +// espik_debug_print ("<<<<<<<< DUMMMMY CODE >>>>>>>"); char *tmp, *tmp2; - tmp = malloc (strlen("NICK ") - + strlen (a_infos.client->nickname)); - tmp2 = malloc (strlen("USER localhost:") - + strlen(a_infos.client->nickname)*2 - + strlen (a_infos.client->realname)); + 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 localhost: %s", a_infos.client->nickname, - a_infos.client->nickname, a_infos.client->realname); + sprintf (tmp2, "USER %s %s %s: %s", a_infos.client->nickname, + a_infos.client->nickname, a_infos.server->host, + a_infos.client->realname); + espik_debug_print("tmp: %s", tmp); espik_raw_send (tmp); + espik_debug_print("tmp2: %s", tmp2); espik_raw_send (tmp2); espik_raw_send ("JOIN #e.fr"); - espik_debug_print ("<<<<<<<< DUMMMMY CODE >>>>>>>"); + com_active = 1; + +// espik_debug_print ("<<<<<<<< DUMMMMY CODE >>>>>>>"); connected++; espik_leave(); } +void espik_con_up() +{ + espik_enter(); + printf ("Connected\n"); + espik_leave(); +} + void espik_con_shutdown () { espik_enter(); @@ -117,20 +130,30 @@ void espik_raw_send (char *msg) buf_t buf; espik_enter(); - buf = make_buffer (strlen(msg) + 3); + buf = make_buffer (strlen(msg) + 2); - snprintf (buf.buf, buf.len, "%s\r\n", msg); + snprintf (buf.buf, buf.len, "%s\r", msg); + /* Overid trailing \0 */ + buf.buf[strlen(buf.buf)] = '\n'; - espik_debug_print ("msg: %s\nout: %s", msg, buf.buf); + espik_debug_print ("\n\nmsg(%d): %s\n\nout(%d-%d): %s\n", strlen(msg), msg, strlen(buf.buf), buf.len, 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]); */ + /* + int i; + for (i = 0 ; i < buf.len ; i++) + { + espik_debug_print ("buf.buf[%d]: '%c' '%d'", i, buf.buf[i], buf.buf[i]); + } + */ + ret = ecore_con_server_send (con_sock, buf.buf, buf.len); - espik_debug_print ("%d", ret); + espik_debug_print ("ret: %d", ret); free (buf.buf); espik_leave(); } diff --git a/src/espik_net.h b/src/espik_net.h index 3e45c3a..ecfa7d3 100644 --- a/src/espik_net.h +++ b/src/espik_net.h @@ -7,5 +7,6 @@ void espik_raw_send (char*); void espik_con_init (t_info); void espik_con_up(); void espik_con_shutdown (); +void send_login(); #endif /* HAVE_ESPIK_NET_H */ |