aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBertrand Jacquin (Beber) <beber.mailing@gmail.com>2006-04-10 21:01:25 +0200
committerbeber <beber@meathook.melee>2006-04-10 21:01:25 +0200
commit3c6fd19250a0647c1c774d5ee2006f56b13d9ba2 (patch)
treed05a2ef8cf2807b8cfb72f2bea746eb0ba1084ff
parentdel unused m4 macros (diff)
downloadespik-3c6fd19250a0647c1c774d5ee2006f56b13d9ba2.tar.xz
make it rework and build
-rw-r--r--src/Makefile.am6
-rw-r--r--src/espik.c13
-rw-r--r--src/espik_common_handler.c41
-rw-r--r--src/espik_common_handler.h2
-rw-r--r--src/espik_config.c20
-rw-r--r--src/espik_irc.c20
-rw-r--r--src/espik_net.c48
7 files changed, 87 insertions, 63 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 30fcb53..5f648b1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -12,13 +12,17 @@ ESPIKHEADERS = \
espik_common_handler.h \
espik_config.h \
espik_error.h \
- espik_global.h
+ espik_global.h \
+ espik_irc.h \
+ espik_net.h
espik_SOURCES = \
espik.c \
espik_common_handler.c \
espik_config.c \
espik_error.c \
+ espik_irc.c \
+ espik_net.c \
$(ESPIKHEADERS)
espik_LDADD = \
diff --git a/src/espik.c b/src/espik.c
index 026fc64..6b49e7b 100644
--- a/src/espik.c
+++ b/src/espik.c
@@ -14,13 +14,14 @@
#include "espik_global.h"
#include "espik_config.h"
#include "espik_common_handler.h"
+#include "espik_net.h"
#include "espik.h"
typedef int (*Handler_Func) (void *data, int ev_type, void *ev);
/* typedef int (*Handler_Fd_Func) (void *data, Ecore_Fd_Handler * fd_handler); */
-static void espik_destroy_ptr(void *ptr)
+static void espik_destroy_ptr (void *ptr)
{
if (ptr)
{
@@ -30,7 +31,7 @@ static void espik_destroy_ptr(void *ptr)
}
}
-static void espik_init(void)
+static void espik_init (void)
{
printf ("Welcome to %s-%s\n", APPS_NAME, ESPIK_VERSION);
ptr_list = ecore_list_new();
@@ -49,7 +50,7 @@ void espik_free (void *ptr)
ecore_list_append (ptr_list, ptr);
}
-void espik_shutdown(void)
+void espik_shutdown (void)
{
ecore_main_loop_quit();
}
@@ -109,14 +110,14 @@ int main (int argc, char **argv)
exit (-1);
}
+ espik_con_init (a_infos);
ecore_main_loop_begin ();
- espik_shutdown();
-
+ espik_shutdown ();
espik_config_shutdown (a_infos);
ecore_shutdown ();
- ecore_list_destroy(ptr_list);
+ ecore_list_destroy (ptr_list);
return (0);
}
diff --git a/src/espik_common_handler.c b/src/espik_common_handler.c
index 6022344..c53268a 100644
--- a/src/espik_common_handler.c
+++ b/src/espik_common_handler.c
@@ -8,9 +8,50 @@
#include "espik_global.h"
#include "espik.h"
#include "espik_error.h"
+#include "espik_net.h"
#include "espik_common_handler.h"
#define INPUT_LENGHT 200
+
+static int count_num_recv = 0;
+
+int server_data (void* data __UNUSED__, int ev_type __UNUSED__,
+ Ecore_Con_Event_Server_Data* ev)
+{
+ unsigned int i;
+ char* msg;
+
+ 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++;
+
+ printf ("%s", msg);
+
+ for (i = 0 ; i < strlen(msg) ; i++)
+ {
+ if (msg[i] == ' ')
+ msg[i] = '\0';
+ }
+
+ if (count_num_recv >= 1)
+ {
+ //server_dns = strdup (msg+1);
+ send_login ();
+ }
+
+ if (! (strcmp (msg, "PING")))
+ espik_raw_send ("PONG guybrush.melee");
+
+ memset (msg, 0, strlen(msg));
+ free (msg);
+
+ return (0);
+}
int kb_get (void* data __UNUSED__, Ecore_Fd_Handler* fd_handler)
{
diff --git a/src/espik_common_handler.h b/src/espik_common_handler.h
index 7bbf6c6..f07b75b 100644
--- a/src/espik_common_handler.h
+++ b/src/espik_common_handler.h
@@ -7,5 +7,7 @@
#include "espik_global.h"
int kb_get (void *__UNUSED__, Ecore_Fd_Handler *);
+int server_data (void* data __UNUSED__, int ev_type __UNUSED__,
+ Ecore_Con_Event_Server_Data* ev);
#endif /* ESPIK_COMMON_HANDLER_H */
diff --git a/src/espik_config.c b/src/espik_config.c
index bbae1b8..a840e67 100644
--- a/src/espik_config.c
+++ b/src/espik_config.c
@@ -11,8 +11,6 @@
#include "espik_error.h"
#include "espik_config.h"
-static int ret; /* For debug */
-
t_servinfo* espik_server_config_set (char* server, unsigned short port)
{
t_servinfo* s_info;
@@ -76,23 +74,15 @@ void espik_config_default_set (void)
void espik_config_init (void)
{
- if ((ret = ecore_config_init (APPS_NAME)) != ECORE_CONFIG_ERR_SUCC)
- {
- printf ("Init ecore_config failed (%d)", ret);
- //kill_me (2);
- //exit (ret);
- }
+ if (ecore_config_init (APPS_NAME) != ECORE_CONFIG_ERR_SUCC)
+ printf ("Init ecore_config failed\n");
- if ((ret = ecore_config_load ()) != ECORE_CONFIG_ERR_SUCC)
+ if (ecore_config_load () != ECORE_CONFIG_ERR_SUCC)
{
/* If an config option is not present,
* this will force it to a value */
- printf ("Load ecore_config failed (%d)", ret);
+ printf ("Load ecore_config failed\n");
espik_config_default_set ();
- /*
- kill_me (2);
- exit (ret);
- */
}
}
@@ -100,7 +90,7 @@ void espik_config_shutdown (t_info s_info)
{
espik_free (s_info.server);
espik_free (s_info.client);
-// free (s_info);
+/* free (s_info); */
ecore_config_save();
ecore_config_shutdown();
diff --git a/src/espik_irc.c b/src/espik_irc.c
index 21c418f..ff58dea 100644
--- a/src/espik_irc.c
+++ b/src/espik_irc.c
@@ -70,7 +70,7 @@ void string_upper (char *str)
if (str[i] >= 0x61 && str[i] <= 0x7A)
str[i] -= 0x20;
}
- espik_debug_print ("string_upper: %s", str);
+ printf ("string_upper: %s", str);
espik_leave();
}
#endif
@@ -112,8 +112,8 @@ char* irc_join (char* chan __UNUSED__, char* msg)
* have to look on RFC, dev will be done with # only */
if (msg[0] != '#')
{
- espik_debug_print ("%s is not a channel", msg);
- espik_debug_print ("Usage: /JOIN #channel");
+ printf ("%s is not a channel", msg);
+ printf ("Usage: /JOIN #channel");
return (0);
}
@@ -164,7 +164,7 @@ char* irc_quit (char* chan __UNUSED__, char* msg)
snprintf (out.buf, out.len, "QUIT :%s", msg);
- espik_debug_print ("msg : %s\nout: %s", msg, out.buf);
+ printf ("msg : %s\nout: %s", msg, out.buf);
/*
espik_raw_send (out);
@@ -191,7 +191,7 @@ char* irc_nick (char* chan __UNUSED__, char* nick)
snprintf (out.buf, out.len, "NICK %s", nick);
- espik_debug_print ("NICK CHANGED REQUEST: %s", nick);
+ printf ("NICK CHANGED REQUEST: %s", nick);
return (out.buf);
}
@@ -207,9 +207,9 @@ Ecore_Con_Server* irc_connect (char* host __UNUSED__, int port __UNUSED__)
void irc_disconnect (Ecore_Con_Server *sock)
{
espik_enter();
- espik_debug_print ("> irc_disconnect");
+ printf ("> irc_disconnect");
ecore_main_loop_quit ();
- espik_debug_print ("< irc_disconnect");
+ printf ("< irc_disconnect");
espik_leave();
}
#endif
@@ -230,7 +230,7 @@ char* irc_send (char* msg)
cmd_and_message = separate_commandline (msg + 1);
/*
- espik_debug_print ("irc_send: <separate_commandline");
+ printf ("irc_send: <separate_commandline");
*/
/*
@@ -250,7 +250,7 @@ char* irc_send (char* msg)
}
if (!out)
{
- espik_debug_print ("%s is not a know command",
+ printf ("%s is not a know command",
cmd_and_message[0]);
return (0);
}
@@ -264,7 +264,7 @@ char* irc_send (char* msg)
return (0);
}
- espik_debug_print ("%s", out);
+ printf ("%s", out);
return (out);
}
diff --git a/src/espik_net.c b/src/espik_net.c
index 4c0ce1f..ec11430 100644
--- a/src/espik_net.c
+++ b/src/espik_net.c
@@ -15,28 +15,25 @@
typedef int (*Handler_Func) (void* data, int ev_type, void* ev);
-static int ret_int; /* For debug */
-char connected = 0;
-
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 ();
- com_active = 0;
- /* espik_debug_printf ("nb_launch = %d", nb_launch); */
+ /* 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)
{
- espik_debug_print ("ecore_con_server_connect failed "
+ printf ("ecore_con_server_connect failed "
"(ECORE_CON_REMOTE_SYSTEM)");
exit (-1);
}
@@ -45,7 +42,7 @@ void espik_con_init (t_info serv_info)
if (! (ret = ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DATA,
(Handler_Func) server_data, NULL)))
{
- espik_debug_print ("ecore_event_handler_add "
+ printf ("ecore_event_handler_add "
"(ECORE_CON_EVENT_SERVER_DATA)");
exit (-1);
}
@@ -54,7 +51,7 @@ void espik_con_init (t_info serv_info)
if (! (ret = ecore_event_handler_add (ECORE_CON_EVENT_SERVER_ADD,
(Handler_Func) espik_con_up, NULL)))
{
- espik_debug_print ("ecore_event_handler_add "
+ printf ("ecore_event_handler_add "
"(ECORE_CON_EVENT_SERVER_ADD)");
exit (-1);
}
@@ -63,16 +60,16 @@ void espik_con_init (t_info serv_info)
if (! (ret = ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DEL,
(Handler_Func) espik_con_shutdown, NULL)))
{
- espik_debug_print ("ecore_event_handler_add "
+ printf ("ecore_event_handler_add "
"(ECORE_CON_EVENT_SERVER_DEL)");
exit (-1);
}
espik_free (ret);
}
-void send_login()
+void send_login (void)
{
-/* espik_debug_print ("<<<<<<<< DUMMMMY CODE >>>>>>>"); */
+/* printf ("<<<<<<<< DUMMMMY CODE >>>>>>>"); */
char *tmp, *tmp2;
@@ -88,15 +85,13 @@ void send_login()
a_infos.client->nickname, a_infos.server->host,
a_infos.client->realname);
- espik_debug_print("tmp: %s", tmp);
+ printf("tmp: %s", tmp);
espik_raw_send (tmp);
- espik_debug_print("tmp2: %s", tmp2);
+ printf("tmp2: %s", tmp2);
espik_raw_send (tmp2);
espik_raw_send ("JOIN #e.fr");
- com_active = 1;
-
-/* espik_debug_print ("<<<<<<<< DUMMMMY CODE >>>>>>>"); */
+/* printf ("<<<<<<<< DUMMMMY CODE >>>>>>>"); */
free (tmp);
free (tmp2);
@@ -104,17 +99,17 @@ void send_login()
connected++;
}
-void espik_con_up()
+void espik_con_up(void)
{
printf ("Connected\n");
}
-void espik_con_shutdown ()
+void espik_con_shutdown (void)
{
if (!connected)
- espik_debug_print ("Unable to connect to server");
+ printf ("Unable to connect to server");
- espik_debug_print ("ecore_con_server_del: %p",
+ printf ("ecore_con_server_del: %p",
ecore_con_server_del (con_sock));
ecore_con_shutdown ();
@@ -126,7 +121,6 @@ void espik_con_shutdown ()
*/
ecore_main_loop_quit ();
- espik_free (server_dns);
}
void espik_raw_send (const char *msg)
@@ -138,25 +132,17 @@ void espik_raw_send (const char *msg)
snprintf (buf.buf, buf.len, "%s\r\n", msg);
/* Override trailing \0 */
- espik_debug_print("strlen(msg): %d", strlen(msg));
- espik_debug_print("buf.len: %d", buf.len);
buf.buf[buf.len-1] = '\n';
/* buf.buf[buf.len] = '\0'; */
- 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]);
*/
- for (i = 0 ; buf.buf[i] != 0 ; i++)
- espik_debug_print ("buf.buf[%d]: '%d'", i, buf.buf[i]);
-
-
- ret_int = ecore_con_server_send (con_sock, buf.buf, buf.len);
+ ecore_con_server_send (con_sock, buf.buf, buf.len);
- espik_debug_print ("ret_int: %d", ret_int);
free (buf.buf);
/* free (msg); */
}