aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbeber <beber>2005-08-22 18:39:41 +0000
committerbeber <beber>2005-08-22 18:39:41 +0000
commit759cc5ec91cdffe47cb5dee8f6e5134c8501e579 (patch)
tree69fe44e0fc2c783e1678058f77e611a3d2643646 /src
parentSome jobs on irc commands (diff)
downloadespik-759cc5ec91cdffe47cb5dee8f6e5134c8501e579.tar.xz
Some work too
Del struct.h, move contents to espik.h
Diffstat (limited to '')
-rw-r--r--src/Makefile.am1
-rw-r--r--src/espik.c113
-rw-r--r--src/espik.h26
-rw-r--r--src/espik_common_handler.c5
-rw-r--r--src/espik_config.c25
-rw-r--r--src/espik_config.h14
-rw-r--r--src/espik_error.c10
-rw-r--r--src/espik_error.h2
-rw-r--r--src/espik_net.c20
-rw-r--r--src/espik_net.h2
-rw-r--r--src/struct.h18
11 files changed, 184 insertions, 52 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index b14c64d..94e237d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -9,7 +9,6 @@ ESPIKHEADERS = \
espik_net.h \
espik_config.h \
espik_common_handler.h \
- struct.h \
global.h
espik_SOURCES = \
diff --git a/src/espik.c b/src/espik.c
new file mode 100644
index 0000000..a976767
--- /dev/null
+++ b/src/espik.c
@@ -0,0 +1,113 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+
+/* EFL Stuff */
+#include <Ecore.h>
+#include <Ecore_Config.h> /* Configuration lib */
+//#include <Ecore_Con.h> /* Socket lib */
+
+/* Ebic Stuff */
+#include "global.h"
+#include "espik_config.h"
+#include "espik_irc.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);
+
+int del_backslash (char *msg)
+{
+ int i, count;
+
+ for (i = 0, count = 0; msg[i]; i++)
+ {
+ if (msg[i] == '\n')
+ {
+ msg[i] = '\0';
+ count++;
+ }
+ }
+
+ return (count);
+}
+
+int main (int argc, char **argv)
+{
+ t_info a_infos;
+ Ecore_Fd_Handler *fd_kb;
+
+ printf ("Welcome to %s %s\n", APPS_NAME, ESPIK_VERSION);
+
+ espik_config_init ();
+
+ if (argc < 3)
+ {
+ fprintf (stderr, "Loading from conf ...\n");
+ espik_config_get (&a_infos);
+ }
+ else
+ {
+ printf ("Connecting to %s:%s\n", argv[1], argv[2]);
+ a_infos.client = espik_user_sysinfo_get ();
+ a_infos.server = espik_server_config_set (argv[1], (unsigned short)atoi (argv[2]));
+ }
+
+ espik_config_set (a_infos);
+
+ printf ("host: %s\n", a_infos.server->host);
+ printf ("port: %hd\n", a_infos.server->port);
+ printf ("nick: %s\n", a_infos.client->nickname);
+ printf ("user: %s\n", a_infos.client->username);
+ printf ("real: %s\n", a_infos.client->realname);
+
+ ecore_init ();
+ espik_con_init (a_infos);
+
+ /*
+ * con_sock =
+ * ecore_con_server_connect (ECORE_CON_REMOTE_SYSTEM, a_infos.server->host,
+ * (int)a_infos.server->port, NULL);
+ * if (!con_sock)
+ * {
+ * fprintf (stderr, "Baaa\n");
+ * exit (-1);
+ * }
+ */
+
+ /* Handler Network & Keyboard */
+ fd_kb = ecore_main_fd_handler_add (STDIN_FILENO, ECORE_FD_READ, kb_get, NULL, NULL, NULL);
+ //ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DATA, (Handler_Func) server_data, NULL);
+
+ /* Init IRC connection */
+ espik_raw_send ("NICK espik");
+ espik_raw_send ("USER beber beber guybrush.melee :Ronnie Reagan");
+ espik_raw_send ("JOIN #test");
+
+ ecore_main_loop_begin ();
+
+// ecore_con_server_del (con_sock);
+
+ 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);
+
+ // ecore_main_loop_quit ();
+
+ printf (" end\n");
+
+ ecore_config_shutdown ();
+// ecore_con_shutdown ();
+ ecore_shutdown ();
+
+ return (0);
+}
diff --git a/src/espik.h b/src/espik.h
new file mode 100644
index 0000000..e8fad1c
--- /dev/null
+++ b/src/espik.h
@@ -0,0 +1,26 @@
+#ifndef _HAVE_ESPIK_H
+#define _HAVE_ESPIK_H
+
+typedef struct
+{
+ char *host;
+ unsigned short port;
+} t_servinfo;
+
+typedef struct
+{
+ char *nickname;
+ char *username;
+ char *realname; /* gecos */
+} t_userinfo;
+
+typedef struct
+{
+ t_servinfo *server;
+ t_userinfo *client;
+} t_info;
+
+int del_backslash (char *);
+int main (int, char **);
+
+#endif /* _HAVE_ESPIK_H */
diff --git a/src/espik_common_handler.c b/src/espik_common_handler.c
index c8fa693..ae3e119 100644
--- a/src/espik_common_handler.c
+++ b/src/espik_common_handler.c
@@ -13,7 +13,8 @@
#include "espik.h"
#include "espik_error.h"
-int server_data (void *data __UNUSED__, int ev_type __UNUSED__, Ecore_Con_Event_Server_Data * ev)
+int server_data (void *data __UNUSED__, int ev_type __UNUSED__,
+ Ecore_Con_Event_Server_Data * ev)
{
printf ("%s\n", (char *)ev->data);
@@ -58,7 +59,7 @@ int kb_get (void *data __UNUSED__, Ecore_Fd_Handler * fd_handler)
espik_raw_send (tmp);
printf ("AFTER espik_raw_send\n");
- // irc_disconnect();
+/* irc_disconnect(); */
espik_con_shutdown ();
ecore_main_loop_quit ();
diff --git a/src/espik_config.c b/src/espik_config.c
index f3e9668..e0a3b87 100644
--- a/src/espik_config.c
+++ b/src/espik_config.c
@@ -10,7 +10,7 @@
#include "espik_config.h"
#include "espik_error.h"
-t_servinfo *espik_server_config_set (char *server, unsigned short port)
+t_servinfo* espik_server_config_set (char *server, unsigned short port)
{
t_servinfo *s_info;
@@ -49,9 +49,12 @@ void espik_config_default_set ()
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);
@@ -79,11 +82,15 @@ void espik_config_get (t_info * s_info)
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->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->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");
ecore_config_save ();
}
diff --git a/src/espik_config.h b/src/espik_config.h
new file mode 100644
index 0000000..129d2a7
--- /dev/null
+++ b/src/espik_config.h
@@ -0,0 +1,14 @@
+#ifndef _HAVE_ESPIK_CONFIG_H
+#define _HAVE_ESPIK_CONFIG_H
+
+#include "global.h"
+#include "espik.h"
+
+t_servinfo *espik_server_config_set (char *, unsigned short);
+t_userinfo *espik_user_sysinfo_get ();
+void espik_config_default_set ();
+void espik_config_init ();
+void espik_config_get (t_info * s_info);
+void espik_config_set (t_info config);
+
+#endif /* _HAVE_ESPIK_CONFIG_H */
diff --git a/src/espik_error.c b/src/espik_error.c
index e8303dc..c673946 100644
--- a/src/espik_error.c
+++ b/src/espik_error.c
@@ -2,13 +2,3 @@
#include <stdio.h> /* fprintf */
#include <stdlib.h> /* exit */
-
-void chk_malloc (void *ptr)
-{
- if (ptr == NULL)
- {
- fprintf (stderr, "Malloc failed\n");
- fprintf (stderr, "exiting ...\n");
- exit (128);
- }
-}
diff --git a/src/espik_error.h b/src/espik_error.h
index bd8541e..d512f36 100644
--- a/src/espik_error.h
+++ b/src/espik_error.h
@@ -1,6 +1,4 @@
#ifndef _HAVE_ESPIK_ERROR_H
#define _HAVE_ESPIK_ERROR_H
-void chk_malloc (void *ptr);
-
#endif /* _HAVE_ESPIK_ERROR_H */
diff --git a/src/espik_net.c b/src/espik_net.c
index c008234..16498de 100644
--- a/src/espik_net.c
+++ b/src/espik_net.c
@@ -6,8 +6,8 @@
#include "espik_net.h"
#include "espik_common_handler.h"
-#include "struct.h"
#include "espik_error.h"
+#include "espik.h"
typedef int (*Handler_Func) (void *data, int ev_type, void *ev);
@@ -17,16 +17,16 @@ void espik_con_init (t_info serv_info)
{
ecore_con_init ();
- con_sock =
- ecore_con_server_connect (ECORE_CON_REMOTE_SYSTEM, serv_info.server->host,
- (int)serv_info.server->port, NULL);
+ con_sock = ecore_con_server_connect (ECORE_CON_REMOTE_SYSTEM,
+ serv_info.server->host, (int)serv_info.server->port, NULL);
if (!con_sock)
{
fprintf (stderr, "ecore_con_server_connect failed\n");
exit (-1);
}
- ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DATA, (Handler_Func) server_data, NULL);
+ ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DATA,
+ (Handler_Func) server_data, NULL);
}
void espik_con_shutdown ()
@@ -37,7 +37,7 @@ void espik_con_shutdown ()
ecore_con_shutdown ();
printf ("< espik_con_shutdown\n");
-// ecore_main_loop_quit ();
+/* ecore_main_loop_quit (); */
}
void espik_raw_send (char *msg)
@@ -53,12 +53,14 @@ void espik_raw_send (char *msg)
snprintf (out, len, "%s\r\n", msg);
printf ("espik_raw_send:\nmsg: %s\nout: %s\n", msg, out);
-/* printf ("out[len-3]: 0x%X\n", out[len - 3]);
+/*
+ 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]);
- */
+*/
- printf ("ecore_con_server_send: %d\n", ecore_con_server_send (con_sock, out, strlen (out)));
+ printf ("ecore_con_server_send: %d\n", ecore_con_server_send (con_sock,
+ out, strlen (out)));
free (out);
}
diff --git a/src/espik_net.h b/src/espik_net.h
index 64e9717..3bc88b2 100644
--- a/src/espik_net.h
+++ b/src/espik_net.h
@@ -1,7 +1,7 @@
#ifndef _HAVE_ESPIK_NET_H
#define _HAVE_ESPIK_NET_H
-#include "struct.h"
+#include "espik.h"
void espik_raw_send (char *);
void espik_con_init (t_info);
diff --git a/src/struct.h b/src/struct.h
index 18e36a5..de90e31 100644
--- a/src/struct.h
+++ b/src/struct.h
@@ -1,23 +1,5 @@
#ifndef _HAVE_ESPIK_STRUCT_H
#define _HAVE_ESPIK_STRUCT_H
-typedef struct
-{
- char *host;
- unsigned short port;
-} t_servinfo;
-
-typedef struct
-{
- char *nickname;
- char *username;
- char *realname; /* gecos */
-} t_userinfo;
-
-typedef struct
-{
- t_servinfo *server;
- t_userinfo *client;
-} t_info;
#endif /* _HAVE_ESPIK_STRUCT_H */