aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBertrand Jacquin (Beber) <beber.mailing@gmail.com>2006-04-30 03:01:03 +0200
committerbeber <beber@meathook.melee>2006-04-30 03:01:03 +0200
commit20e7c8f2225cb5861317a7aef8998362fdd35b25 (patch)
treed026bd0cd0cd6d97bd19084213c7ce5c29628310 /src
parentoops, forgot to change get_version in m4 macros (diff)
downloadespik-20e7c8f2225cb5861317a7aef8998362fdd35b25.tar.xz
indent fixe
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/espik.c150
-rw-r--r--src/espik.h30
-rw-r--r--src/espik_common_handler.c122
-rw-r--r--src/espik_common_handler.h8
-rw-r--r--src/espik_config.c188
-rw-r--r--src/espik_config.h66
-rw-r--r--src/espik_error.c4
-rw-r--r--src/espik_error.h2
-rw-r--r--src/espik_global.h14
-rw-r--r--src/espik_irc.c354
-rw-r--r--src/espik_irc.h34
-rw-r--r--src/espik_irc_return_value.h24
-rw-r--r--src/espik_net.c214
-rw-r--r--src/espik_net.h12
15 files changed, 611 insertions, 613 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 761be98..d730c0d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,3 +1 @@
-FIND_LIBRARY(Ecore Ecore.h ${X11_LIB_SEARCH_PATH})
-INCLUDE_DIRECTORIES(. /usr/include)
ADD_EXECUTABLE(espik espik_common_handler.c espik_config.c espik_error.c espik_irc.c espik_net.c espik_opts.c espik.c)
diff --git a/src/espik.c b/src/espik.c
index 6b49e7b..7f6ef72 100644
--- a/src/espik.c
+++ b/src/espik.c
@@ -6,9 +6,9 @@
/* EFL Stuff */
#include <Ecore.h>
-#include <Ecore_Config.h> /* Configuration lib */
-/*#include <Ecore_Con.h> */ /* Socket lib */
-#include <Ecore_Data.h> /* List */
+#include <Ecore_Config.h> /* Configuration lib */
+/*#include <Ecore_Con.h> */ /* Socket lib */
+#include <Ecore_Data.h> /* List */
/* Espik Stuff */
#include "espik_global.h"
@@ -17,107 +17,107 @@
#include "espik_net.h"
#include "espik.h"
-typedef int (*Handler_Func) (void *data, int ev_type, void *ev);
+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)
{
- if (ptr)
- {
- printf ("Freeing data...");
- free (ptr);
- ptr = NULL;
- }
+ if (ptr)
+ {
+ printf ("Freeing data %p ...", ptr_list);
+ free (ptr);
+ ptr = NULL;
+ }
}
static void espik_init (void)
{
- printf ("Welcome to %s-%s\n", APPS_NAME, ESPIK_VERSION);
- ptr_list = ecore_list_new();
-
+ printf ("Welcome to %s-%s\n", APPS_NAME, ESPIK_VERSION);
+ ptr_list = ecore_list_new();
+
if (!ecore_init ())
- {
- printf ("Cannot init ecore; %d\n", 1);
- exit (-1);
- }
+ {
+ printf ("Cannot init ecore; %d\n", 1);
+ exit (-1);
+ }
- ecore_list_set_free_cb (ptr_list, espik_destroy_ptr);
+ ecore_list_set_free_cb (ptr_list, espik_destroy_ptr);
}
void espik_free (void *ptr)
{
- ecore_list_append (ptr_list, ptr);
+ ecore_list_append (ptr_list, ptr);
}
void espik_shutdown (void)
{
- ecore_main_loop_quit();
+ ecore_main_loop_quit();
}
/* Use to replace EOL ('\n') with NULL ('\0') */
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 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)
{
- Ecore_Fd_Handler *fd_kb;
-
- espik_init ();
- espik_config_init ();
-
- if (argc < 3)
- {
- printf ("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);
-
- /* Handler Keyboard */
- fd_kb = ecore_main_fd_handler_add (STDIN_FILENO, ECORE_FD_READ, kb_get,
- NULL, NULL, NULL);
- espik_free (fd_kb);
- if (!fd_kb)
- {
- printf ("Cannot ecore_main_fd_handler_add\n");
- exit (-1);
- }
-
+ Ecore_Fd_Handler *fd_kb;
+
+ espik_init ();
+ espik_config_init ();
+
+ if (argc < 3)
+ {
+ printf ("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);
+
+ /* Handler Keyboard */
+ fd_kb = ecore_main_fd_handler_add (STDIN_FILENO, ECORE_FD_READ, kb_get,
+ NULL, NULL, NULL);
+ espik_free (fd_kb);
+ if (!fd_kb)
+ {
+ printf ("Cannot ecore_main_fd_handler_add\n");
+ exit (-1);
+ }
+
espik_con_init (a_infos);
- ecore_main_loop_begin ();
+ ecore_main_loop_begin ();
- espik_shutdown ();
- espik_config_shutdown (a_infos);
-
- ecore_shutdown ();
- ecore_list_destroy (ptr_list);
+ espik_shutdown ();
+ espik_config_shutdown (a_infos);
+
+ ecore_shutdown ();
+//ecore_list_destroy (ptr_list);
- return (0);
+ return (0);
}
diff --git a/src/espik.h b/src/espik.h
index 6f89e99..8ada989 100644
--- a/src/espik.h
+++ b/src/espik.h
@@ -1,33 +1,33 @@
-#ifndef ESPIK_H
-#define ESPIK_H
+#ifndef ESPIK_H
+#define ESPIK_H
#include <Ecore_Data.h>
typedef struct
{
- char* host;
- unsigned short port;
+ char* host;
+ unsigned short port;
} t_servinfo;
typedef struct
{
- char* nickname;
- char* username;
- char* realname; /* gecos */
+ char* nickname;
+ char* username;
+ char* realname; /* gecos */
} t_userinfo;
typedef struct
{
- t_servinfo* server;
- t_userinfo* client;
+ t_servinfo* server;
+ t_userinfo* client;
} t_info;
t_info a_infos;
-Ecore_List *ptr_list;
+Ecore_List *ptr_list;
-void espik_free (void*);
-int del_backslash (char*);
-void espik_shutdown();
-int main (int, char**);
+void espik_free (void*);
+int del_backslash (char*);
+void espik_shutdown();
+int main (int, char**);
-#endif /* ESPIK_H */
+#endif /* ESPIK_H */
diff --git a/src/espik_common_handler.c b/src/espik_common_handler.c
index c53268a..479babd 100644
--- a/src/espik_common_handler.c
+++ b/src/espik_common_handler.c
@@ -12,78 +12,78 @@
#include "espik_common_handler.h"
#define INPUT_LENGHT 200
-
-static int count_num_recv = 0;
+
+static int count_num_recv = 0;
-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)
{
- unsigned int i;
- char* msg;
+ 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);
+ 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;
+ if (!msg)
+ return 0;
- count_num_recv++;
-
- printf ("%s", msg);
+ count_num_recv++;
+
+ printf ("%s", msg);
- for (i = 0 ; i < strlen(msg) ; i++)
- {
- if (msg[i] == ' ')
- msg[i] = '\0';
- }
+ 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 (count_num_recv >= 1)
+ {
+ //server_dns = strdup (msg+1);
+ send_login ();
+ }
- if (! (strcmp (msg, "PING")))
- espik_raw_send ("PONG guybrush.melee");
+ if (! (strcmp (msg, "PING")))
+ espik_raw_send ("PONG guybrush.melee");
- memset (msg, 0, strlen(msg));
- free (msg);
+ memset (msg, 0, strlen(msg));
+ free (msg);
- return (0);
+ return (0);
}
-int kb_get (void* data __UNUSED__, Ecore_Fd_Handler* fd_handler)
+int kb_get (void* data __UNUSED__, Ecore_Fd_Handler* fd_handler)
{
- char kb[INPUT_LENGHT];
- int count;
-
- do
- {
- memset (kb, 0, INPUT_LENGHT);
- count = read (ecore_main_fd_handler_fd_get (fd_handler), kb,
- INPUT_LENGHT - 2);
-
- if (count > 1)
- {
- del_backslash (kb);
- printf ("%s", kb);
- }
- }
- while (count >= INPUT_LENGHT - 2);
-
- if (count == -1)
- {
- perror ("read");
- espik_shutdown();
- return (0);
- }
-
- if (count == 0)
- {
- espik_shutdown();
- return (0);
- }
-
- return (1);
+ char kb[INPUT_LENGHT];
+ int count;
+
+ do
+ {
+ memset (kb, 0, INPUT_LENGHT);
+ count = read (ecore_main_fd_handler_fd_get (fd_handler), kb,
+ INPUT_LENGHT - 2);
+
+ if (count > 1)
+ {
+ del_backslash (kb);
+ printf ("%s", kb);
+ }
+ }
+ while (count >= INPUT_LENGHT - 2);
+
+ if (count == -1)
+ {
+ perror ("read");
+ espik_shutdown();
+ return (0);
+ }
+
+ if (count == 0)
+ {
+ espik_shutdown();
+ return (0);
+ }
+
+ return (1);
}
diff --git a/src/espik_common_handler.h b/src/espik_common_handler.h
index f07b75b..f4dcab7 100644
--- a/src/espik_common_handler.h
+++ b/src/espik_common_handler.h
@@ -6,8 +6,8 @@
#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);
+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 */
+#endif /* ESPIK_COMMON_HANDLER_H */
diff --git a/src/espik_config.c b/src/espik_config.c
index a840e67..2ce70ba 100644
--- a/src/espik_config.c
+++ b/src/espik_config.c
@@ -11,133 +11,133 @@
#include "espik_error.h"
#include "espik_config.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;
+ t_servinfo* s_info;
- s_info = malloc (sizeof (t_servinfo));
+ s_info = malloc (sizeof (t_servinfo));
- s_info->host = strdup (server);
- s_info->port = port;
+ s_info->host = strdup (server);
+ s_info->port = port;
- espik_free (server);
- return (s_info);
+ espik_free (server);
+ return (s_info);
}
-t_userinfo* espik_user_sysinfo_get (void)
+t_userinfo* espik_user_sysinfo_get (void)
{
- struct passwd* pw;
- t_userinfo* u_info;
+ struct passwd* pw;
+ t_userinfo* u_info;
- pw = getpwuid (getuid ());
+ pw = getpwuid (getuid ());
- u_info = malloc (sizeof (t_userinfo));
+ u_info = malloc (sizeof (t_userinfo));
- //u_info->nickname = pw->pw_name;
- u_info->nickname = strdup ("beber_espik_test");
- u_info->username = strdup (pw->pw_name);
-
- if (! (pw->pw_gecos[0]) )
- u_info->realname = strdup ("espik user");
- else
- u_info->realname = strdup (pw->pw_gecos);
+ //u_info->nickname = pw->pw_name;
+ u_info->nickname = strdup ("beber_espik_test");
+ u_info->username = strdup (pw->pw_name);
+
+ if (! (pw->pw_gecos[0]) )
+ u_info->realname = strdup ("espik user");
+ else
+ u_info->realname = strdup (pw->pw_gecos);
- espik_free (u_info);
- espik_free (pw);
+ espik_free (u_info);
+ espik_free (pw);
- return (u_info);
+ return (u_info);
}
-void espik_config_default_set (void)
+void espik_config_default_set (void)
{
- t_userinfo* user_sysinfo;
+ 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 ();
+ 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);
+ ecore_config_string_default ("/espik/version", ESPIK_VERSION);
- espik_free (user_sysinfo->nickname);
- espik_free (user_sysinfo->username);
- espik_free (user_sysinfo->realname);
- espik_free (user_sysinfo);
+ espik_free (user_sysinfo->nickname);
+ espik_free (user_sysinfo->username);
+ espik_free (user_sysinfo->realname);
+ espik_free (user_sysinfo);
}
-void espik_config_init (void)
+void espik_config_init (void)
{
- if (ecore_config_init (APPS_NAME) != ECORE_CONFIG_ERR_SUCC)
- printf ("Init ecore_config failed\n");
-
- 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\n");
- espik_config_default_set ();
- }
+ if (ecore_config_init (APPS_NAME) != ECORE_CONFIG_ERR_SUCC)
+ printf ("Init ecore_config failed\n");
+
+ 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\n");
+ espik_config_default_set ();
+ }
}
void espik_config_shutdown (t_info s_info)
{
- espik_free (s_info.server);
- espik_free (s_info.client);
+ espik_free (s_info.server);
+ espik_free (s_info.client);
/* free (s_info); */
- ecore_config_save();
- ecore_config_shutdown();
+ ecore_config_save();
+ ecore_config_shutdown();
}
-void espik_config_get (t_info *s_info)
+void espik_config_get (t_info *s_info)
{
- s_info->server = malloc (sizeof (t_servinfo));
- s_info->client = malloc (sizeof (t_userinfo));
-
- 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");
-
- if (ecore_config_save () != ECORE_CONFIG_ERR_SUCC)
- {
- printf ("Save ecore_config failed");
- exit (-1);
- }
+ s_info->server = malloc (sizeof (t_servinfo));
+ s_info->client = malloc (sizeof (t_userinfo));
+
+ 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");
+
+ if (ecore_config_save () != ECORE_CONFIG_ERR_SUCC)
+ {
+ printf ("Save ecore_config failed");
+ exit (-1);
+ }
}
-void espik_config_set (t_info config)
+void espik_config_set (t_info config)
{
- ecore_config_int_set ("/config/server/len", 1);
- ecore_config_string_set ("/config/server/0/host", config.server->host);
- ecore_config_int_set ("/config/server/0/port",
- (int)config.server->port);
- ecore_config_int_set ("/config/server/0/autoconnect", 1);
-
- ecore_config_string_set ("/config/user/nickname",
- config.client->nickname);
- ecore_config_string_set ("/config/user/username",
- config.client->username);
- ecore_config_string_set ("/config/user/realname",
- config.client->realname);
-
- if (ecore_config_save () != ECORE_CONFIG_ERR_SUCC)
- {
- printf ("Save ecore_config failed");
- exit (-1);
- }
+ ecore_config_int_set ("/config/server/len", 1);
+ ecore_config_string_set ("/config/server/0/host", config.server->host);
+ ecore_config_int_set ("/config/server/0/port",
+ (int)config.server->port);
+ ecore_config_int_set ("/config/server/0/autoconnect", 1);
+
+ ecore_config_string_set ("/config/user/nickname",
+ config.client->nickname);
+ ecore_config_string_set ("/config/user/username",
+ config.client->username);
+ ecore_config_string_set ("/config/user/realname",
+ config.client->realname);
+
+ if (ecore_config_save () != ECORE_CONFIG_ERR_SUCC)
+ {
+ printf ("Save ecore_config failed");
+ exit (-1);
+ }
}
diff --git a/src/espik_config.h b/src/espik_config.h
index 77f49ce..5f6e0ed 100644
--- a/src/espik_config.h
+++ b/src/espik_config.h
@@ -4,42 +4,42 @@
#include "espik.h"
#include "espik_global.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*);
-void espik_config_set (t_info);
-void espik_config_shutdown (t_info);
+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*);
+void espik_config_set (t_info);
+void espik_config_shutdown (t_info);
-#define ESPIK_CONFIG_VERSION 1
+#define ESPIK_CONFIG_VERSION 1
struct _espik_config
{
- int config_version;
-
- struct
- {
- char* name;
-
- char* host;
- int port;
-
- char* nick;
- char* pass;
-
- unsigned int connect_at_startup : 1 ;
-
- struct server* next;
- } server;
-
- struct
- {
- char* name;
- } channel;
-
- struct server* current_server;
- struct channel* cuurent_channel;
+ int config_version;
+
+ struct
+ {
+ char* name;
+
+ char* host;
+ int port;
+
+ char* nick;
+ char* pass;
+
+ unsigned int connect_at_startup : 1 ;
+
+ struct server* next;
+ } server;
+
+ struct
+ {
+ char* name;
+ } channel;
+
+ struct server* current_server;
+ struct channel* cuurent_channel;
};
-#endif /* ESPIK_CONFIG_H */
+#endif /* ESPIK_CONFIG_H */
diff --git a/src/espik_error.c b/src/espik_error.c
index 72ebd66..e18b389 100644
--- a/src/espik_error.c
+++ b/src/espik_error.c
@@ -1,4 +1,4 @@
#include "espik_error.h"
-#include <stdio.h> /* fprintf */
-#include <stdlib.h> /* exit */
+#include <stdio.h> /* fprintf */
+#include <stdlib.h> /* exit */
diff --git a/src/espik_error.h b/src/espik_error.h
index 44b6875..18eb7f5 100644
--- a/src/espik_error.h
+++ b/src/espik_error.h
@@ -1,4 +1,4 @@
#ifndef ESPIK_ERROR_H
#define ESPIK_ERROR_H
-#endif /* ESPIK_ERROR_H */
+#endif /* ESPIK_ERROR_H */
diff --git a/src/espik_global.h b/src/espik_global.h
index 1e5ab3e..c731828 100644
--- a/src/espik_global.h
+++ b/src/espik_global.h
@@ -3,15 +3,15 @@
#include "../config.h"
-#define APPS_NAME PACKAGE
-#define ESPIK_VERSION VERSION
+#define APPS_NAME PACKAGE
+#define ESPIK_VERSION VERSION
-#define MAX_LEN 512
+#define MAX_LEN 512
#if HAVE___ATTRIBUTE__
-# define __UNUSED__ __attribute__((unused))
+# define __UNUSED__ __attribute__((unused))
#else
-# define __UNUSED__
-#endif /* HAVE___ATTRIBUTE__ */
+# define __UNUSED__
+#endif /* HAVE___ATTRIBUTE__ */
-#endif /* ESPIK_GLOBAL_H */
+#endif /* ESPIK_GLOBAL_H */
diff --git a/src/espik_irc.c b/src/espik_irc.c
index ff58dea..de418ca 100644
--- a/src/espik_irc.c
+++ b/src/espik_irc.c
@@ -12,259 +12,259 @@
#include "espik_net.h"
#include "espik.h"
-char* current_chan;
+char* current_chan;
typedef struct
{
- char* cmd_name;
- char* (*format) (char *dest, char *msg);
+ char* cmd_name;
+ char* (*format) (char *dest, char *msg);
} cmd_t;
-cmd_t cmd_tab[] = {
- { "JOIN", irc_join },
- { "PART", irc_part },
- { "PRIVMSG", irc_privmsg },
- { "QUIT", irc_quit },
- { "RAW", irc_raw },
- { "NICK", irc_nick },
-/* { "ACTION", irc_action }, */
- { 0, 0 }
+cmd_t cmd_tab[] = {
+ { "JOIN", irc_join },
+ { "PART", irc_part },
+ { "PRIVMSG", irc_privmsg },
+ { "QUIT", irc_quit },
+ { "RAW", irc_raw },
+ { "NICK", irc_nick },
+/* { "ACTION", irc_action }, */
+ { 0, 0 }
};
/* Cut the commandline in two string
* 1: The first word
* 2: The rest (without any trailer whitespace between firt and rest).
*/
-char** separate_commandline (char *msg)
+char** separate_commandline (char *msg)
{
- unsigned int len;
- char** two_words;
+ unsigned int len;
+ char** two_words;
- /* Yes, do nothing, just get len ! */
- for (len = 0 ; msg[len] != ' ' && msg[len] != '\t' ; len++);
+ /* Yes, do nothing, just get len ! */
+ for (len = 0 ; msg[len] != ' ' && msg[len] != '\t' ; len++);
- two_words = malloc (2 * sizeof(char*));
+ two_words = malloc (2 * sizeof(char*));
- msg[len] = '\0';
- two_words[0] = msg;
+ msg[len] = '\0';
+ two_words[0] = msg;
- do
- {
- two_words[1] = msg + ++len;
- }
- while (*two_words[1] == ' ' || *two_words[1] == '\t');
+ do
+ {
+ two_words[1] = msg + ++len;
+ }
+ while (*two_words[1] == ' ' || *two_words[1] == '\t');
- return (two_words);
+ return (two_words);
}
#if 0
-void string_upper (char *str)
+void string_upper (char *str)
{
- unsigned int len, i;
- espik_enter();
-
- len = strlen (str);
-
- for (i = 0; i < len; i++)
- {
- if (str[i] >= 0x61 && str[i] <= 0x7A)
- str[i] -= 0x20;
- }
- printf ("string_upper: %s", str);
- espik_leave();
+ unsigned int len, i;
+ espik_enter();
+
+ len = strlen (str);
+
+ for (i = 0; i < len; i++)
+ {
+ if (str[i] >= 0x61 && str[i] <= 0x7A)
+ str[i] -= 0x20;
+ }
+ printf ("string_upper: %s", str);
+ espik_leave();
}
#endif
-unsigned short sendmsg_len (char* msg)
+unsigned short sendmsg_len (char* msg)
{
- return (strlen (msg) + 2);
+ return (strlen (msg) + 2);
}
-buf_t make_buffer(int len)
+buf_t make_buffer(int len)
{
- buf_t buf;
+ buf_t buf;
- buf.buf = malloc (len);
- buf.len = len + 1; /* Alloc trailing \0 */
+ buf.buf = malloc (len);
+ buf.len = len + 1; /* Alloc trailing \0 */
- return (buf);
+ return (buf);
}
-char* irc_privmsg (char* chan, char* msg)
+char* irc_privmsg (char* chan, char* msg)
{
- buf_t out;
+ buf_t out;
- out = make_buffer (strlen ("PRIVMSG") + 1 /* "PRIVMSG " */
- + strlen (chan) + 2 /* ":<channel> "*/
- + strlen (msg)); /* "<msg>EOF" */
+ out = make_buffer (strlen ("PRIVMSG") + 1 /* "PRIVMSG " */
+ + strlen (chan) + 2 /* ":<channel> "*/
+ + strlen (msg)); /* "<msg>EOF" */
- snprintf (out.buf, out.len, "PRIVMSG %s :%s", chan, msg);
+ snprintf (out.buf, out.len, "PRIVMSG %s :%s", chan, msg);
- free (msg);
- return (out.buf);
+ free (msg);
+ return (out.buf);
}
-char* irc_join (char* chan __UNUSED__, char* msg)
+char* irc_join (char* chan __UNUSED__, char* msg)
{
- buf_t out;
-
- /* 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", msg);
- printf ("Usage: /JOIN #channel");
- return (0);
- }
-
- out = make_buffer (strlen ("JOIN") + 1 /* "JOIN " */
- + strlen (msg)); /* "<msg>EOF" */
-
- snprintf (out.buf, out.len, "JOIN %s", msg);
-
- free (msg);
- return (out.buf);
+ buf_t out;
+
+ /* 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", msg);
+ printf ("Usage: /JOIN #channel");
+ return (0);
+ }
+
+ out = make_buffer (strlen ("JOIN") + 1 /* "JOIN " */
+ + strlen (msg)); /* "<msg>EOF" */
+
+ snprintf (out.buf, out.len, "JOIN %s", msg);
+
+ free (msg);
+ return (out.buf);
}
-char* irc_part (char* chan, char* msg)
+char* irc_part (char* chan, char* msg)
{
- buf_t out;
+ buf_t out;
- if (msg[0] != '#')
- {
- out = make_buffer (strlen ("PART") + 1 /* "PART " */
- + strlen (chan) + 2 /* ":<chan> " */
- + strlen (msg)); /* "<msg>EOF" */
+ if (msg[0] != '#')
+ {
+ out = make_buffer (strlen ("PART") + 1 /* "PART " */
+ + strlen (chan) + 2 /* ":<chan> " */
+ + strlen (msg)); /* "<msg>EOF" */
- snprintf (out.buf, out.len, "PART %s :%s", chan, msg);
- }
- else
- {
- char** sep;
+ snprintf (out.buf, out.len, "PART %s :%s", chan, msg);
+ }
+ else
+ {
+ char** sep;
- sep = separate_commandline (msg);
+ sep = separate_commandline (msg);
- out = make_buffer (strlen ("PART") + 1 /* "PART " */
- + strlen (sep[0]) + 2 /* ":<chan> "*/
- + strlen (sep[1])); /* "<msg>EOF"*/
+ out = make_buffer (strlen ("PART") + 1 /* "PART " */
+ + strlen (sep[0]) + 2 /* ":<chan> "*/
+ + strlen (sep[1])); /* "<msg>EOF"*/
- snprintf (out.buf, out.len, "PART %s :%s", sep[0], sep[1]);
- }
+ snprintf (out.buf, out.len, "PART %s :%s", sep[0], sep[1]);
+ }
- free (msg);
- return (out.buf);
+ free (msg);
+ return (out.buf);
}
-char* irc_quit (char* chan __UNUSED__, char* msg)
+char* irc_quit (char* chan __UNUSED__, char* msg)
{
- buf_t out;
+ buf_t out;
- out = make_buffer (strlen ("QUIT") + 2 /* "QUIT :" */
- + strlen (msg)); /* "<msg>EOF" */
+ out = make_buffer (strlen ("QUIT") + 2 /* "QUIT :" */
+ + strlen (msg)); /* "<msg>EOF" */
- snprintf (out.buf, out.len, "QUIT :%s", msg);
+ snprintf (out.buf, out.len, "QUIT :%s", msg);
- printf ("msg : %s\nout: %s", msg, out.buf);
+ printf ("msg : %s\nout: %s", msg, out.buf);
- /*
- espik_raw_send (out);
- espik_con_shutdown ();
+ /*
+ espik_raw_send (out);
+ espik_con_shutdown ();
- irc_disconnect(sock);
- */
- free (msg);
+ irc_disconnect(sock);
+ */
+ free (msg);
- return (out.buf);
+ return (out.buf);
}
-char* irc_raw (char* chan __UNUSED__, char* msg)
+char* irc_raw (char* chan __UNUSED__, char* msg)
{
- return (msg);
+ return (msg);
}
-char* irc_nick (char* chan __UNUSED__, char* nick)
+char* irc_nick (char* chan __UNUSED__, char* nick)
{
- buf_t out;
+ buf_t out;
- out = make_buffer (strlen ("NICK") + 1 /* "NICK " */
- + strlen (nick)); /* "<nick>EOF" */
+ out = make_buffer (strlen ("NICK") + 1 /* "NICK " */
+ + strlen (nick)); /* "<nick>EOF" */
- snprintf (out.buf, out.len, "NICK %s", nick);
+ snprintf (out.buf, out.len, "NICK %s", nick);
- printf ("NICK CHANGED REQUEST: %s", nick);
+ printf ("NICK CHANGED REQUEST: %s", nick);
- return (out.buf);
+ return (out.buf);
}
#if 0
-Ecore_Con_Server* irc_connect (char* host __UNUSED__, int port __UNUSED__)
+Ecore_Con_Server* irc_connect (char* host __UNUSED__, int port __UNUSED__)
{
- espik_enter();
- espik_leave();
- return (NULL);
+ espik_enter();
+ espik_leave();
+ return (NULL);
}
-void irc_disconnect (Ecore_Con_Server *sock)
+void irc_disconnect (Ecore_Con_Server *sock)
{
- espik_enter();
- printf ("> irc_disconnect");
- ecore_main_loop_quit ();
- printf ("< irc_disconnect");
- espik_leave();
+ espik_enter();
+ printf ("> irc_disconnect");
+ ecore_main_loop_quit ();
+ printf ("< irc_disconnect");
+ espik_leave();
}
#endif
-char* irc_send (char* msg)
+char* irc_send (char* msg)
{
- char* out;
-
- out = NULL;
-
- current_chan = "#e.fr";
-
- if (msg[0] == '/')
- {
- char** cmd_and_message;
- cmd_t* cmd;
-
- cmd_and_message = separate_commandline (msg + 1);
-
- /*
- printf ("irc_send: <separate_commandline");
- */
-
- /*
- string_upper (cmd_and_message[0]);
- */
-
- for (cmd = cmd_tab; cmd->cmd_name != 0; cmd++)
- {
- 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;
- }
- }
- if (!out)
- {
- printf ("%s is not a know command",
- cmd_and_message[0]);
- return (0);
- }
- }
- else
- out = irc_privmsg (current_chan, msg);
-
- if (!out)
- {
- free (msg);
- return (0);
- }
-
- printf ("%s", out);
-
- return (out);
+ char* out;
+
+ out = NULL;
+
+ current_chan = "#e.fr";
+
+ if (msg[0] == '/')
+ {
+ char** cmd_and_message;
+ cmd_t* cmd;
+
+ cmd_and_message = separate_commandline (msg + 1);
+
+ /*
+ printf ("irc_send: <separate_commandline");
+ */
+
+ /*
+ string_upper (cmd_and_message[0]);
+ */
+
+ for (cmd = cmd_tab; cmd->cmd_name != 0; cmd++)
+ {
+ 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;
+ }
+ }
+ if (!out)
+ {
+ printf ("%s is not a know command",
+ cmd_and_message[0]);
+ return (0);
+ }
+ }
+ else
+ out = irc_privmsg (current_chan, msg);
+
+ if (!out)
+ {
+ free (msg);
+ return (0);
+ }
+
+ printf ("%s", out);
+
+ return (out);
}
diff --git a/src/espik_irc.h b/src/espik_irc.h
index af099fd..273b02b 100644
--- a/src/espik_irc.h
+++ b/src/espik_irc.h
@@ -3,27 +3,27 @@
typedef struct
{
- char* buf;
- int len;
+ char* buf;
+ int len;
} buf_t;
-unsigned short sendmsg_len (char*);
-char* irc_send (char*);
-char* irc_privmsg (char*, char *);
+unsigned short sendmsg_len (char*);
+char* irc_send (char*);
+char* irc_privmsg (char*, char *);
-/*char* irc_action (char *, char *);*/
-char* irc_join (char*, char*);
-char* irc_part (char*, char*);
-char* irc_quit (char*, char*);
-char* irc_raw (char*, char*);
-char* irc_nick(char*, char*);
+/*char* irc_action (char *, char *);*/
+char* irc_join (char*, char*);
+char* irc_part (char*, char*);
+char* irc_quit (char*, char*);
+char* irc_raw (char*, char*);
+char* irc_nick(char*, char*);
-char** separate_commandline (char*);
-buf_t make_buffer(int);
-/*void string_upper (char*);*/
+char** separate_commandline (char*);
+buf_t make_buffer(int);
+/*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 /* ESPIK_IRC_H */
+#endif /* ESPIK_IRC_H */
diff --git a/src/espik_irc_return_value.h b/src/espik_irc_return_value.h
index 3ff1bbd..03652bb 100644
--- a/src/espik_irc_return_value.h
+++ b/src/espik_irc_return_value.h
@@ -1,17 +1,17 @@
#ifndef ESPIK_IRC_RETURN_VALUE_H
#define ESPIK_IRC_RETURN_VALUE_H
-#define RPL_WELCOME 001 /* Welcome to the IRC <nick>!<user>@<host> */
-#define RPL_YOURHOST 002 /* Your host is <servername>, running version <ver>" */
-#define RPL_CREATED 003 /* This server was created <date>" */
-#define RPL_MYINFO 004 /* <servername> <version> <available user mode> <available channel mode> */
-#define RPL_BOUNCE 005 /* Try server <server name>, port <port number>
- Server suggest you to connect to another server */
-#define RPL_USERHOST 006 /* :*1<reply> *( " " <reply> )" */
+#define RPL_WELCOME 001 /* Welcome to the IRC <nick>!<user>@<host> */
+#define RPL_YOURHOST 002 /* Your host is <servername>, running version <ver>" */
+#define RPL_CREATED 003 /* This server was created <date>" */
+#define RPL_MYINFO 004 /* <servername> <version> <available user mode> <available channel mode> */
+#define RPL_BOUNCE 005 /* Try server <server name>, port <port number>
+ Server suggest you to connect to another server */
+#define RPL_USERHOST 006 /* :*1<reply> *( " " <reply> )" */
-#define ERR_NONICKNAMEGIVEN 431
-#define ERR_ERRONEUSNICKNAME 432
-#define ERR_NICKNAMEINUSE 433
-#define ERR_NICKCOLLISION 436
+#define ERR_NONICKNAMEGIVEN 431
+#define ERR_ERRONEUSNICKNAME 432
+#define ERR_NICKNAMEINUSE 433
+#define ERR_NICKCOLLISION 436
-#endif /* ESPIK_IRC_RETURN_VALUE_H */
+#endif /* ESPIK_IRC_RETURN_VALUE_H */
diff --git a/src/espik_net.c b/src/espik_net.c
index ec11430..67fd9af 100644
--- a/src/espik_net.c
+++ b/src/espik_net.c
@@ -13,136 +13,136 @@
#include <Ecore.h>
#include <Ecore_Con.h>
-typedef int (*Handler_Func) (void* data, int ev_type, void* ev);
+typedef int (*Handler_Func) (void* data, int ev_type, void* ev);
-Ecore_Con_Server* con_sock;
-Ecore_Event_Handler* ret;
+Ecore_Con_Server* con_sock;
+Ecore_Event_Handler* ret;
int connected = 0;
-void espik_con_init (t_info serv_info)
+void espik_con_init (t_info serv_info)
{
- int nb_launch;
-
- nb_launch = ecore_con_init ();
-
- /* 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)
- {
- printf ("ecore_con_server_connect failed "
- "(ECORE_CON_REMOTE_SYSTEM)");
- exit (-1);
- }
- espik_free (con_sock);
-
- if (! (ret = ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DATA,
- (Handler_Func) server_data, NULL)))
- {
- printf ("ecore_event_handler_add "
- "(ECORE_CON_EVENT_SERVER_DATA)");
- exit (-1);
- }
- espik_free (ret);
-
- if (! (ret = ecore_event_handler_add (ECORE_CON_EVENT_SERVER_ADD,
- (Handler_Func) espik_con_up, NULL)))
- {
- printf ("ecore_event_handler_add "
- "(ECORE_CON_EVENT_SERVER_ADD)");
- exit (-1);
- }
- espik_free (ret);
-
- if (! (ret = ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DEL,
- (Handler_Func) espik_con_shutdown, NULL)))
- {
- printf ("ecore_event_handler_add "
- "(ECORE_CON_EVENT_SERVER_DEL)");
- exit (-1);
- }
- espik_free (ret);
+ int nb_launch;
+
+ nb_launch = ecore_con_init ();
+
+ /* 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)
+ {
+ printf ("ecore_con_server_connect failed "
+ "(ECORE_CON_REMOTE_SYSTEM)");
+ exit (-1);
+ }
+ espik_free (con_sock);
+
+ if (! (ret = ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DATA,
+ (Handler_Func) server_data, NULL)))
+ {
+ printf ("ecore_event_handler_add "
+ "(ECORE_CON_EVENT_SERVER_DATA)");
+ exit (-1);
+ }
+ espik_free (ret);
+
+ if (! (ret = ecore_event_handler_add (ECORE_CON_EVENT_SERVER_ADD,
+ (Handler_Func) espik_con_up, NULL)))
+ {
+ printf ("ecore_event_handler_add "
+ "(ECORE_CON_EVENT_SERVER_ADD)");
+ exit (-1);
+ }
+ espik_free (ret);
+
+ if (! (ret = ecore_event_handler_add (ECORE_CON_EVENT_SERVER_DEL,
+ (Handler_Func) espik_con_shutdown, NULL)))
+ {
+ printf ("ecore_event_handler_add "
+ "(ECORE_CON_EVENT_SERVER_DEL)");
+ exit (-1);
+ }
+ espik_free (ret);
}
-void send_login (void)
+void send_login (void)
{
-/* printf ("<<<<<<<< DUMMMMY CODE >>>>>>>"); */
-
- char *tmp, *tmp2;
-
- 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 %s: %s", a_infos.client->nickname,
- a_infos.client->nickname, a_infos.server->host,
- a_infos.client->realname);
-
- printf("tmp: %s", tmp);
- espik_raw_send (tmp);
- printf("tmp2: %s", tmp2);
- espik_raw_send (tmp2);
- espik_raw_send ("JOIN #e.fr");
-
-/* printf ("<<<<<<<< DUMMMMY CODE >>>>>>>"); */
-
- free (tmp);
- free (tmp2);
-
- connected++;
+/* printf ("<<<<<<<< DUMMMMY CODE >>>>>>>"); */
+
+ char *tmp, *tmp2;
+
+ 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 %s: %s", a_infos.client->nickname,
+ a_infos.client->nickname, a_infos.server->host,
+ a_infos.client->realname);
+
+ printf("tmp: %s", tmp);
+ espik_raw_send (tmp);
+ printf("tmp2: %s", tmp2);
+ espik_raw_send (tmp2);
+ espik_raw_send ("JOIN #e.fr");
+
+/* printf ("<<<<<<<< DUMMMMY CODE >>>>>>>"); */
+
+ free (tmp);
+ free (tmp2);
+
+ connected++;
}
-void espik_con_up(void)
+void espik_con_up(void)
{
- printf ("Connected\n");
+ printf ("Connected\n");
}
-void espik_con_shutdown (void)
+void espik_con_shutdown (void)
{
- if (!connected)
- printf ("Unable to connect to server");
-
- printf ("ecore_con_server_del: %p",
- ecore_con_server_del (con_sock));
+ if (!connected)
+ printf ("Unable to connect to server");
+
+ printf ("ecore_con_server_del: %p",
+ ecore_con_server_del (con_sock));
- ecore_con_shutdown ();
+ ecore_con_shutdown ();
- /*
- ecore_event_handler_del (handler_list.data);
- ecore_event_handler_del (handler_list.up);
- ecore_event_handler_del (handler_list.down);
- */
+ /*
+ ecore_event_handler_del (handler_list.data);
+ ecore_event_handler_del (handler_list.up);
+ ecore_event_handler_del (handler_list.down);
+ */
- ecore_main_loop_quit ();
+ ecore_main_loop_quit ();
}
-void espik_raw_send (const char *msg)
+void espik_raw_send (const char *msg)
{
- buf_t buf;
- int i;
+ buf_t buf;
+ int i;
- buf = make_buffer (strlen(msg) + 1); /* <MESSAGE>\r\n\0" */
+ buf = make_buffer (strlen(msg) + 1); /* <MESSAGE>\r\n\0" */
- snprintf (buf.buf, buf.len, "%s\r\n", msg);
- /* Override trailing \0 */
- buf.buf[buf.len-1] = '\n';
-/* buf.buf[buf.len] = '\0'; */
+ snprintf (buf.buf, buf.len, "%s\r\n", msg);
+ /* Override trailing \0 */
+ buf.buf[buf.len-1] = '\n';
+/* buf.buf[buf.len] = '\0'; */
- /*
- 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 ("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]);
+ */
- ecore_con_server_send (con_sock, buf.buf, buf.len);
+ ecore_con_server_send (con_sock, buf.buf, buf.len);
- free (buf.buf);
-/* free (msg); */
+ free (buf.buf);
+/* free (msg); */
}
diff --git a/src/espik_net.h b/src/espik_net.h
index 1474721..b875999 100644
--- a/src/espik_net.h
+++ b/src/espik_net.h
@@ -3,10 +3,10 @@
#include "espik.h"
-void espik_raw_send (const char*);
-void espik_con_init (t_info);
-void espik_con_up();
-void espik_con_shutdown ();
-void send_login();
+void espik_raw_send (const char*);
+void espik_con_init (t_info);
+void espik_con_up();
+void espik_con_shutdown ();
+void send_login();
-#endif /* ESPIK_NET_H */
+#endif /* ESPIK_NET_H */