aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/espik.c12
-rw-r--r--src/espik_config.c48
-rw-r--r--src/espik_net.c23
3 files changed, 57 insertions, 26 deletions
diff --git a/src/espik.c b/src/espik.c
index cc7b215..af7863e 100644
--- a/src/espik.c
+++ b/src/espik.c
@@ -21,6 +21,7 @@ typedef int (*Handler_Func) (void *data, int ev_type, void *ev);
//typedef int (*Handler_Fd_Func) (void *data, Ecore_Fd_Handler * fd_handler);
+/* Use to replace EOL ('\n') with NULL ('\0') */
int del_backslash (char *msg)
{
int i, count;
@@ -68,7 +69,11 @@ int main (int argc, char **argv)
printf ("real: %s\n", a_infos.client->realname);
#endif
- ecore_init ();
+ if (!ecore_init ())
+ {
+ fprintf (stderr, "main: Cannot init ecore\n");
+ exit (-1);
+ }
espik_con_init (a_infos);
/*
@@ -84,6 +89,11 @@ int main (int argc, char **argv)
/* Handler Network & Keyboard */
fd_kb = ecore_main_fd_handler_add (STDIN_FILENO, ECORE_FD_READ, kb_get, NULL, NULL, NULL);
+ if (!fd_kb)
+ {
+ printf (stderr, "main: Cannot ecore_main_fd_handler_add\n");
+ exit (-1);
+ }
//ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DATA, (Handler_Func) server_data, NULL);
/* Init IRC connection */
diff --git a/src/espik_config.c b/src/espik_config.c
index 5640857..3fd79e5 100644
--- a/src/espik_config.c
+++ b/src/espik_config.c
@@ -35,6 +35,8 @@ t_userinfo* espik_user_sysinfo_get ()
u_info->username = pw->pw_name;
u_info->realname = pw->pw_gecos;
+ free (pw);
+
return (u_info);
}
@@ -42,17 +44,14 @@ void espik_config_default_set ()
{
t_userinfo* user_sysinfo;
- ecore_config_string_default ("/config/server/0/host", "beber.melee");
- ecore_config_int_default ("/config/server/0/port", 6667);
+ ecore_config_string_default ("/config/server/0/host", "beber.melee");
+ ecore_config_int_default ("/config/server/0/port", 6667);
user_sysinfo = espik_user_sysinfo_get ();
- ecore_config_string_default ("/config/user/nickname",
- user_sysinfo->nickname);
- ecore_config_string_default ("/config/user/username",
- user_sysinfo->username);
- ecore_config_string_default ("/config/user/realname",
- user_sysinfo->realname);
+ ecore_config_string_default ("/config/user/nickname", user_sysinfo->nickname);
+ ecore_config_string_default ("/config/user/username", user_sysinfo->username);
+ ecore_config_string_default ("/config/user/realname", user_sysinfo->realname);
ecore_config_string_default ("/espik/version", ESPIK_VERSION);
@@ -63,11 +62,15 @@ void espik_config_init ()
{
if (ecore_config_init (APPS_NAME) != ECORE_CONFIG_ERR_SUCC)
{
- printf ("Cannot init Ecore_Config");
+ fprintf (stderr, "espik_config_init: init ecore_config failed\n");
exit (-1);
}
- ecore_config_load ();
+ if (ecore_config_load () != ECORE_CONFIG_ERR_SUCC)
+ {
+ fprintf (stderr, "espik_config_init: Load ecore_config failed\n");
+ exit (-1);
+ }
}
void espik_config_get (t_info *s_info)
@@ -75,20 +78,21 @@ void espik_config_get (t_info *s_info)
s_info->server = malloc (sizeof (t_servinfo));
s_info->client = malloc (sizeof (t_userinfo));
+ /* If an config option is not present, this will force it to a value */
espik_config_default_set ();
s_info->server->host = ecore_config_string_get ("/config/server/0/host");
- s_info->server->port
- = (unsigned short)ecore_config_int_get ("/config/server/0/port");
+ s_info->server->port = (unsigned short)ecore_config_int_get ("/config/server/0/port");
- s_info->client->nickname
- = ecore_config_string_get ("/config/user/nickname");
- s_info->client->username
- = ecore_config_string_get ("/config/user/username");
- s_info->client->realname
- = ecore_config_string_get ("/config/user/realname");
+ s_info->client->nickname = ecore_config_string_get ("/config/user/nickname");
+ s_info->client->username = ecore_config_string_get ("/config/user/username");
+ s_info->client->realname = ecore_config_string_get ("/config/user/realname");
- ecore_config_save ();
+ if (ecore_config_save () != ECORE_CONFIG_ERR_SUCC)
+ {
+ fprintf (stderr, "espik_config_get: Save ecore_config failed\n");
+ exit (-1);
+ }
}
void espik_config_set (t_info config)
@@ -102,5 +106,9 @@ void espik_config_set (t_info config)
ecore_config_string_set ("/config/user/username", config.client->username);
ecore_config_string_set ("/config/user/realname", config.client->realname);
- ecore_config_save ();
+ if (ecore_config_save () != ECORE_CONFIG_ERR_SUCC)
+ {
+ fprintf (stderr, "espik_config_get: Save ecore_config failed\n");
+ exit (-1);
+ }
}
diff --git a/src/espik_net.c b/src/espik_net.c
index 8057ae0..ee271c1 100644
--- a/src/espik_net.c
+++ b/src/espik_net.c
@@ -19,7 +19,13 @@ Ecore_Con_Server* con_sock;
void espik_con_init (t_info serv_info)
{
- ecore_con_init ();
+ int nb_launch;
+
+ nb_launch = ecore_con_init ();
+
+#if _ESPIK_DEBUG_
+ printf ("espik_con_init: nb_launch = %d\n", nb_launch);
+#endif
con_sock = ecore_con_server_connect (ECORE_CON_REMOTE_SYSTEM,
serv_info.server->host, (int)serv_info.server->port, NULL);
@@ -29,8 +35,12 @@ void espik_con_init (t_info serv_info)
exit (-1);
}
- ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DATA,
- (Handler_Func) server_data, NULL);
+ if (! (ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DATA,
+ (Handler_Func) server_data, NULL)))
+ {
+ fprintf (stderr, "ecore_event_handler_add failed at espik_con_init\n");
+ exit (-1);
+ }
}
void espik_con_shutdown ()
@@ -38,6 +48,7 @@ void espik_con_shutdown ()
#if _ESPIK_DEBUG_
printf ("> espik_con_shutdown\n");
#endif
+
ecore_con_server_del (con_sock);
ecore_con_shutdown ();
@@ -51,6 +62,7 @@ void espik_raw_send (char *msg)
{
int len;
char* out;
+ int ret; /* FIXME: DEL THAT ! */
len = strlen (msg) + 3;
@@ -67,9 +79,10 @@ void espik_raw_send (char *msg)
printf ("out[len-1]: 0x%X\n", out[len - 1]);
*/
+ ret = ecore_con_server_send (con_sock, out, strlen (out));
+
#if _ESPIK_DEBUG_
- printf ("ecore_con_server_send: %d\n", ecore_con_server_send (con_sock,
- out, strlen (out)));
+ printf ("ecore_con_server_send: %d\n", ret);
#endif
free (out);