aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.svnignore1
-rw-r--r--src/.svnignore2
-rw-r--r--src/espik.c29
-rw-r--r--src/espik.h2
-rw-r--r--src/espik_common_handler.c13
-rw-r--r--src/espik_common_handler.h3
-rw-r--r--src/espik_config.c10
-rw-r--r--src/espik_config.h4
-rw-r--r--src/espik_debug.c12
-rw-r--r--src/espik_debug.h18
-rw-r--r--src/espik_irc.c57
-rw-r--r--src/espik_irc.h6
-rw-r--r--src/espik_net.c54
-rw-r--r--tst/.svnignore1
-rw-r--r--tst/cut.c16
-rw-r--r--tst/strlen.c9
16 files changed, 126 insertions, 111 deletions
diff --git a/.svnignore b/.svnignore
index a120787..034c22c 100644
--- a/.svnignore
+++ b/.svnignore
@@ -11,6 +11,7 @@ config.guess
stamp-h1
autom4te.cache
aclocal.m4
+libtool
ltmain.sh
svn-commit*.tmp
espik
diff --git a/src/.svnignore b/src/.svnignore
index af9108c..a0cbd98 100644
--- a/src/.svnignore
+++ b/src/.svnignore
@@ -5,3 +5,5 @@ Makefile
Makefile.in
espik.log
*.o
+*.S
+.*.swp
diff --git a/src/espik.c b/src/espik.c
index d092a71..598077f 100644
--- a/src/espik.c
+++ b/src/espik.c
@@ -9,16 +9,14 @@
#include <Ecore_Config.h> /* Configuration lib */
/*#include <Ecore_Con.h> */ /* Socket lib */
-/* Ebic Stuff */
+/* Espik Stuff */
#include "espik_global.h"
#include "espik_config.h"
#include "espik_irc.h"
#include "espik_common_handler.h"
#include "espik_net.h"
#include "espik.h"
-#if _ESPIK_DEBUG_
-# include "espik_debug.h"
-#endif
+#include "espik_debug.h"
typedef int (*Handler_Func) (void *data, int ev_type, void *ev);
@@ -49,7 +47,7 @@ int main (int argc, char **argv)
printf ("Welcome to %s %s\n", APPS_NAME, ESPIK_VERSION);
-#if _ESPIK_DEBUG_
+#ifdef _ESPIK_DEBUG_
espik_debug_init();
#endif
@@ -77,7 +75,7 @@ int main (int argc, char **argv)
if (!ecore_init ())
{
- fprintf (stderr, "main: Cannot init ecore\n");
+ espik_debug_print ("Cannot init ecore; %d", 1);
exit (-1);
}
espik_con_init (a_infos);
@@ -85,7 +83,7 @@ int main (int argc, char **argv)
/*
* con_sock =
* ecore_con_server_connect (ECORE_CON_REMOTE_SYSTEM, a_infos.server->host,
- * (int)a_infos.server->port, NULL);
+ * (int)a_infos.server->port, NULL);
* if (!con_sock)
* {
* fprintf (stderr, "Baaa\n");
@@ -97,14 +95,14 @@ int main (int argc, char **argv)
fd_kb = ecore_main_fd_handler_add (STDIN_FILENO, ECORE_FD_READ, kb_get, NULL, NULL, NULL);
if (!fd_kb)
{
- fprintf (stderr, "main: Cannot ecore_main_fd_handler_add\n");
+ espik_debug_print ("Cannot ecore_main_fd_handler_add");
exit (-1);
}
/* ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DATA, (Handler_Func) server_data, NULL); */
/* Init IRC connection */
- printf ("<<<<<<<< DUMMMMY CODE >>>>>>>\n");
+ espik_debug_print ("<<<<<<<< DUMMMMY CODE >>>>>>>");
char *tmp, *tmp2;
@@ -118,7 +116,7 @@ int main (int argc, char **argv)
espik_raw_send (tmp2);
espik_raw_send ("JOIN #e.fr");
- printf ("<<<<<<<< DUMMMMY CODE >>>>>>>\n");
+ espik_debug_print ("<<<<<<<< DUMMMMY CODE >>>>>>>");
ecore_main_loop_begin ();
@@ -127,17 +125,16 @@ int main (int argc, char **argv)
free (a_infos.server->host);
free (a_infos.server);
- /* free (a_infos.client->nickname);
- free (a_infos.client->username);
- free (a_infos.client->realname);
+ /*
+ free (a_infos.client->nickname);
+ free (a_infos.client->username);
+ free (a_infos.client->realname);
*/
free (a_infos.client);
/* ecore_main_loop_quit (); */
-#if _ESPIK_DEBUG_
- printf ("end\n");
-#endif
+ espik_debug_print ("end");
ecore_config_shutdown ();
/* ecore_con_shutdown (); */
diff --git a/src/espik.h b/src/espik.h
index 3b7d007..6a54a37 100644
--- a/src/espik.h
+++ b/src/espik.h
@@ -3,7 +3,7 @@
typedef struct
{
- char* host;
+ char* host;
unsigned short port;
} t_servinfo;
diff --git a/src/espik_common_handler.c b/src/espik_common_handler.c
index b8097b7..ba9483f 100644
--- a/src/espik_common_handler.c
+++ b/src/espik_common_handler.c
@@ -12,6 +12,7 @@
#include "espik_net.h"
#include "espik.h"
#include "espik_error.h"
+#include "espik_debug.h"
int server_data (void* data __UNUSED__, int ev_type __UNUSED__,
Ecore_Con_Event_Server_Data* ev)
@@ -21,9 +22,7 @@ int server_data (void* data __UNUSED__, int ev_type __UNUSED__,
msg = strdup((char*)ev->data);
-#if _ESPIK_DEBUG_
- printf ("%s", msg);
-#endif
+ espik_debug_print ("%s", msg);
for (i=0 ; i < strlen(msg) ; i++)
{
@@ -74,13 +73,9 @@ int kb_get (void* data __UNUSED__, Ecore_Fd_Handler* fd_handler)
if (count == 0)
{
tmp = irc_quit ("", "^D pressed");
-#if _ESPIK_DEBUG_
- printf ("kb_get:\ntmp: %s\n", tmp);
-#endif
+ espik_debug_print ("tmp: %s", tmp);
espik_raw_send (tmp);
-#if _ESPIK_DEBUG_
- printf ("AFTER espik_raw_send\n");
-#endif
+ espik_debug_print ("AFTER espik_raw_send");
espik_raw_send (tmp);
/* irc_disconnect(); */
diff --git a/src/espik_common_handler.h b/src/espik_common_handler.h
index 65972bb..0aa5d92 100644
--- a/src/espik_common_handler.h
+++ b/src/espik_common_handler.h
@@ -1,10 +1,11 @@
#ifndef HAVE_ESPIK_COMMON_HANDLER_H
#define HAVE_ESPIK_COMMON_HANDLER_H
-#include "espik_global.h"
#include <Ecore_Con.h>
#include <Ecore.h>
+#include "espik_global.h"
+
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 2df8d65..3d8150c 100644
--- a/src/espik_config.c
+++ b/src/espik_config.c
@@ -38,8 +38,10 @@ t_userinfo* espik_user_sysinfo_get ()
u_info->nickname = pw->pw_name;
u_info->username = pw->pw_name;
- if (! (pw->pw_gecos[0]) ) u_info->realname = strdup ("espik user");
- else u_info->realname = pw->pw_gecos;
+ if (! (pw->pw_gecos[0]) )
+ u_info->realname = strdup ("espik user");
+ else
+ u_info->realname = pw->pw_gecos;
//free (pw); /*FIXME: segv */
@@ -100,7 +102,7 @@ void espik_config_get (t_info *s_info)
if (ecore_config_save () != ECORE_CONFIG_ERR_SUCC)
{
- fprintf (stderr, "espik_config_get: Save ecore_config failed\n");
+ espik_debug_print ("Save ecore_config failed");
exit (-1);
}
}
@@ -118,7 +120,7 @@ void espik_config_set (t_info config)
if (ecore_config_save () != ECORE_CONFIG_ERR_SUCC)
{
- fprintf (stderr, "espik_config_get: Save ecore_config failed\n");
+ espik_debug_print ("Save ecore_config failed");
exit (-1);
}
}
diff --git a/src/espik_config.h b/src/espik_config.h
index 87549c3..cc52771 100644
--- a/src/espik_config.h
+++ b/src/espik_config.h
@@ -22,11 +22,13 @@ struct _espik_config
char* name;
char* host;
- int port;
+ int port;
char* nick;
char* pass;
+ int connect_at_startup : 1 ;
+
struct server* next;
} server;
diff --git a/src/espik_debug.c b/src/espik_debug.c
index 11b3188..7403dd5 100644
--- a/src/espik_debug.c
+++ b/src/espik_debug.c
@@ -5,19 +5,19 @@
#include "espik_debug.h"
#ifdef __GLIBC__
-# include <execinfo.h>
-#endif /* __GLIBC__ */
+#include <execinfo.h>
+#endif /* __GLIBC__ */
#ifdef _ESPIK_DEBUG_
-# include <signal.h>
-#endif /* _ESPIK_DEBUG_ */
+#include <signal.h>
+#endif /* _ESPIK_DEBUG_ */
//static int indent_level = 0;
inline void espik_debug_bt (int num)
{
#ifdef __GLIBC__
-# ifdef _ESPIK_DEBUG_
+#ifdef _ESPIK_DEBUG_
void* array[128];
size_t size;
@@ -35,7 +35,7 @@ inline void espik_debug_bt (int num)
if (strings)
free(strings);
-# endif /* _ESPIK_DEBUG_ */
+#endif /* _ESPIK_DEBUG_ */
#endif /* __GLIBC__ */
#ifndef __GLIBC__
diff --git a/src/espik_debug.h b/src/espik_debug.h
index a3ad93c..22d7c7b 100644
--- a/src/espik_debug.h
+++ b/src/espik_debug.h
@@ -3,18 +3,26 @@
#include "espik_global.h"
+#define DEBUG_FILENO stderr
+
+#ifdef _ESPIK_DEBUG_
#ifdef __GNUC__
#define espik_debug_print(fmt, ...) \
{ \
- fprintf (stdout, "%s+%i @%s: '", __FILE__, __LINE__, __func__); \
- fprintf (stdout, fmt, __VA_ARGS__); \
- fprintf (stdout, "'\n"); \
+ fprintf (DEBUG_FILENO, "%s+%i @%s: '", __FILE__, __LINE__, __func__); \
+ fprintf (DEBUG_FILENO, fmt, ##__VA_ARGS__); \
+ fprintf (DEBUG_FILENO, "'\n"); \
+}
+#else /* __GNUC__ */
+#define espik_debug_print(fmt, ...) \
+{ \
}
-#else
+#endif /* __GNUC__ */
+#else /* _ESPIK_DEBUG_ */
#define espik_debug_print(fmt, ...) \
{ \
}
-#endif /* __GNUC__ */
+#endif /* _ESPIK_DEBUG_ */
inline void espik_bt (void);
void espik_debug_init();
diff --git a/src/espik_irc.c b/src/espik_irc.c
index a87f904..731d7ad 100644
--- a/src/espik_irc.c
+++ b/src/espik_irc.c
@@ -3,14 +3,15 @@
#include <stdio.h>
#include <Ecore.h>
-//#include <Ecore_Con.h>
+/*#include <Ecore_Con.h>*/
#include "espik_global.h"
#include "espik_irc.h"
#include "espik_error.h"
-//#include "espik_common_handler.h"
+/*#include "espik_common_handler.h"*/
#include "espik.h"
#include "espik_net.h"
+#include "espik_debug.h"
char* current_chan;
@@ -75,9 +76,7 @@ void string_upper (char *str)
if (str[i] >= 0x61 && str[i] <= 0x7A)
str[i] -= 0x20;
}
-#if _ESPIK_DEBUG_
- printf("string_upper: %s\n", str);
-#endif
+ espik_debug_print ("string_upper: %s", str);
}
#endif
@@ -101,8 +100,8 @@ char* irc_privmsg (char* chan, char* msg)
buf_t out;
out = make_buffer (strlen ("PRIVMSG") + 1 /* "PRIVMSG " */
- + strlen (chan) + 2 /* ":<channel> " */
- + strlen (msg) + 1); /* "<msg>EOF" */
+ + strlen (chan) + 2 /* ":<channel> " */
+ + strlen (msg) + 1); /* "<msg>EOF" */
snprintf (out.buf, out.len, "PRIVMSG %s :%s", chan, msg);
@@ -113,17 +112,17 @@ char* irc_join (char* chan __UNUSED__, char* msg)
{
buf_t out;
- /* COuld also by '&' and so one ...
+ /* Could also by '&' and so one ...
* have to look on RFC, dev will be done with # only */
if (msg[0] != '#')
{
- printf ("%s is not a channel\n", msg);
- printf ("Usage: /JOIN #channel\n");
+ espik_debug_print ("%s is not a channel", msg);
+ espik_debug_print ("Usage: /JOIN #channel");
return (0);
}
out = make_buffer (strlen ("JOIN") + 1 /* "JOIN " */
- + strlen (msg) + 1); /* "<msg>EOF" */
+ + strlen (msg) + 1); /* "<msg>EOF" */
snprintf (out.buf, out.len, "JOIN %s", msg);
@@ -137,8 +136,8 @@ char* irc_part (char* chan, char* msg)
if (msg[0] != '#')
{
out = make_buffer (strlen ("PART") + 1 /* "PART " */
- + strlen (chan) + 2 /* ":<chan> " */
- + strlen (msg) + 1); /* "<msg>EOF" */
+ + strlen (chan) + 2 /* ":<chan> " */
+ + strlen (msg) + 1); /* "<msg>EOF" */
snprintf (out.buf, out.len, "PART %s :%s", chan, msg);
}
@@ -148,9 +147,9 @@ char* irc_part (char* chan, char* msg)
sep = separate_commandline (msg);
- out = make_buffer (strlen ("PART") + 1 /* "PART " */
- + strlen (sep[0]) + 2 /* ":<chan> " */
- + strlen (sep[1]) + 1); /* "<msg>EOF" */
+ out = make_buffer (strlen ("PART") + 1 /* "PART " */
+ + strlen (sep[0]) + 2 /* ":<chan> " */
+ + strlen (sep[1]) + 1); /* "<msg>EOF" */
snprintf (out.buf, out.len, "PART %s :%s", sep[0], sep[1]);
}
@@ -163,13 +162,11 @@ char* irc_quit (char* chan __UNUSED__, char* msg)
buf_t out;
out = make_buffer (strlen ("QUIT") + 2 /* "QUIT :" */
- + strlen (msg) + 1); /* "<msg>EOF" */
+ + strlen (msg) + 1); /* "<msg>EOF" */
snprintf (out.buf, out.len, "QUIT :%s", msg);
-#if _ESPIK_DEBUG_
- printf ("msg : %s\nout: %s\n", msg, out.buf);
-#endif
+ espik_debug_print ("msg : %s\nout: %s", msg, out.buf);
/*
espik_raw_send (out);
@@ -191,13 +188,11 @@ char* irc_nick (char* chan __UNUSED__, char* nick)
buf_t out;
out = make_buffer (strlen ("NICK") + 1 /* "NICK " */
- + strlen (nick) + 1); /* "<nick>EOF" */
+ + strlen (nick) + 1); /* "<nick>EOF" */
snprintf (out.buf, out.len, "NICK %s", nick);
-#if _ESPIK_DEBUG_
- printf ("NICK CHANGED REQUEST: %s\n", nick);
-#endif
+ espik_debug_print ("NICK CHANGED REQUEST: %s", nick);
return (out.buf);
}
@@ -210,9 +205,9 @@ Ecore_Con_Server* irc_connect (char* host __UNUSED__, int port __UNUSED__)
void irc_disconnect (Ecore_Con_Server *sock)
{
- printf ("> irc_disconnect\n");
+ espik_debug_print ("> irc_disconnect");
ecore_main_loop_quit ();
- printf ("< irc_disconnect\n");
+ espik_debug_print ("< irc_disconnect");
}
#endif
@@ -231,9 +226,7 @@ char* irc_send (char* msg)
cmd_and_message = separate_commandline (msg + 1);
-#if _ESPIK_DEBUG_
-/* printf ("irc_send: <separate_commandline\n"); */
-#endif
+/* espik_debug_print ("irc_send: <separate_commandline"); */
/*string_upper (cmd_and_message[0]);*/
@@ -248,7 +241,7 @@ char* irc_send (char* msg)
}
if (!out)
{
- printf ("%s is not a know command\n", cmd_and_message[0]);
+ espik_debug_print ("%s is not a know command", cmd_and_message[0]);
return (0);
}
}
@@ -260,9 +253,7 @@ char* irc_send (char* msg)
if (!out)
return (0);
-#if _ESPIK_DEBUG_
- printf ("%s\n", out);
-#endif
+ espik_debug_print ("%sn", out);
return (out);
}
diff --git a/src/espik_irc.h b/src/espik_irc.h
index caed7cf..4e0614d 100644
--- a/src/espik_irc.h
+++ b/src/espik_irc.h
@@ -5,7 +5,7 @@ unsigned short sendmsg_len (char*);
char* irc_send (char*);
char* irc_privmsg (char*, char *);
-//char* irc_action (char *, char *);
+/*char* irc_action (char *, char *);*/
char* irc_join (char*, char*);
char* irc_part (char*, char*);
char* irc_quit (char*, char*);
@@ -15,7 +15,7 @@ char* irc_nick(char*, char*);
char** separate_commandline (char*);
/*void string_upper (char*);*/
-//Ecore_Con_Server* irc_connect (char*, int);
-//void irc_disconnect (Ecore_Con_Server*);
+/*Ecore_Con_Server* irc_connect (char*, int);*/
+/*void irc_disconnect (Ecore_Con_Server*);*/
#endif /* HAVE_ESPIK_IRC_H */
diff --git a/src/espik_net.c b/src/espik_net.c
index 87aaf30..8970f05 100644
--- a/src/espik_net.c
+++ b/src/espik_net.c
@@ -1,5 +1,7 @@
#include <string.h>
#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
#include <Ecore.h>
#include <Ecore_Con.h>
@@ -8,15 +10,13 @@
#include "espik_net.h"
#include "espik_common_handler.h"
#include "espik_error.h"
+#include "espik_debug.h"
#include "espik.h"
-#include <unistd.h>
-#include <stdlib.h>
-
-typedef int (*Handler_Func) (void* data, int ev_type, void* ev);
+typedef int (*Handler_Func) (void* data, int ev_type, void* ev);
-static int ret; /* For debug */
-static char connected = 0;
+static int ret; /* For debug */
+static char connected = 0;
Ecore_Con_Server* con_sock;
@@ -26,36 +26,34 @@ void espik_con_init (t_info serv_info)
nb_launch = ecore_con_init ();
-#if _ESPIK_DEBUG_
-/* printf ("espik_con_init: nb_launch = %d\n", nb_launch); */
-#endif
+/* 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);
+ serv_info.server->host, (int)serv_info.server->port, NULL);
if (!con_sock)
{
- fprintf (stderr, "ecore_con_server_connect failed (ECORE_CON_REMOTE_SYSTEM)\n");
+ 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)))
+ (Handler_Func) server_data, NULL)))
{
- fprintf (stderr, "ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DATA) failed at %s\n", __FUNCTION__);
+ 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)))
+ (Handler_Func) espik_con_up, NULL)))
{
- fprintf (stderr, "ecore_event_handler_add (ECORE_CON_EVENT_SERVER_ADD) failed at %s\n", __FUNCTION__);
+ 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)))
+ (Handler_Func) espik_con_shutdown, NULL)))
{
- fprintf (stderr, "ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DEL) failed at %s\n", __FUNCTION__);
+ espik_debug_print ("ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DEL)");
exit (-1);
}
}
@@ -63,30 +61,26 @@ void espik_con_init (t_info serv_info)
void espik_con_up()
{
printf ("Connected\n");
- connected = 1;
+ connected++;
}
void espik_con_shutdown ()
{
-#if _ESPIK_DEBUG_
-/* printf ("> espik_con_shutdown\n"); */
-#endif
+/* espik_debug_print ("> espik_con_shutdown"); */
if (!connected)
- fprintf (stderr, "Unable to connect to server\n");
+ espik_debug_print ("Unable to connect to server");
ecore_con_server_del (con_sock);
ecore_con_shutdown ();
-#if _ESPIK_DEBUG_
-/* printf ("< espik_con_shutdown\n"); */
-#endif
+/* espik_debug_print ("< espik_con_shutdown"); */
ecore_main_loop_quit ();
}
void espik_raw_send (char *msg)
{
- int len;
+ int len;
char* out;
len = strlen (msg) + 3;
@@ -95,9 +89,7 @@ void espik_raw_send (char *msg)
snprintf (out, len, "%s\r\n", msg);
-#if _ESPIK_DEBUG_
- printf ("espik_raw_send:\nmsg: %s\nout: %s\n", msg, out);
-#endif
+ espik_debug_print ("msg: %s\nout: %s", msg, out);
/*
printf ("out[len-3]: 0x%X\n", out[len - 3]);
printf ("out[len-2]: 0x%X\n", out[len - 2]);
@@ -106,9 +98,7 @@ void espik_raw_send (char *msg)
ret = ecore_con_server_send (con_sock, out, strlen (out));
-#if _ESPIK_DEBUG_
-/* printf ("ecore_con_server_send: %d\n", ret); */
-#endif
+/* espik_debug_print ("%d", ret); */
free (out);
}
diff --git a/tst/.svnignore b/tst/.svnignore
index a05d151..f27c240 100644
--- a/tst/.svnignore
+++ b/tst/.svnignore
@@ -1,3 +1,4 @@
*.o
size
strtok
+strlen
diff --git a/tst/cut.c b/tst/cut.c
new file mode 100644
index 0000000..4567a87
--- /dev/null
+++ b/tst/cut.c
@@ -0,0 +1,16 @@
+char** separate_commandline (char *msg, char sep)
+{
+ unsigned int len;
+ char** two_words;
+
+ /* Yes, do nothing, just get len ! */
+ for (len = 0; msg[len] != sep; len++);
+ two_words = malloc (sizeof(char*) * 2);
+
+ msg[len] = '\0';
+ two_words[0] = msg;
+ two_words[1] = msg + len + 1;
+
+ return (two_words);
+}
+
diff --git a/tst/strlen.c b/tst/strlen.c
new file mode 100644
index 0000000..7762570
--- /dev/null
+++ b/tst/strlen.c
@@ -0,0 +1,9 @@
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main()
+{
+ printf ("%d\n", strlen (""));
+ return 0;
+}