aboutsummaryrefslogblamecommitdiff
path: root/src/espik.c
blob: d092a71692e3d78a61c6c57a32591abff6f6d08f (plain) (tree)
1
2
3
4
5
6
7
8
9
10



                   
                   


                  

                                                               

                
                         




                                 


                               


                                                                            
                                                                                                  
 
                                                
 

                             











                                           



                                




                                                                
                 
                           

      



                             
                                                   










                                                                                                   




                                                                 
        




                                                              














                                                                                                  

                   
                                                                             

                          
                                                                                                      

                                 

                                                   


                         
                                                                                           
                                                                                                                                             
 

                                                                                                                                 
        

                              
                                      

                                                   


                                 
                                              









                                                        
                                      
 
                 
                         
      

                                 
                                    


                          
 
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>

/* EFL Stuff */
#include <Ecore.h>
#include <Ecore_Config.h>		/* Configuration lib */
/*#include <Ecore_Con.h> */		/* Socket lib */

/* Ebic 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

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;

	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);

#if _ESPIK_DEBUG_
	espik_debug_init();
#endif

	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);

	espik_debug_print ("host: %s", a_infos.server->host);
	espik_debug_print ("port: %hd", a_infos.server->port);
	espik_debug_print ("nick: %s", a_infos.client->nickname);
	espik_debug_print ("user: %s", a_infos.client->username);
	espik_debug_print ("real: %s", a_infos.client->realname);
	
	if (!ecore_init ())
	{
		fprintf (stderr, "main: Cannot init ecore\n");
		exit (-1);
	}
	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);
	if (!fd_kb)
	{
		fprintf (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 */
	
	printf ("<<<<<<<< DUMMMMY CODE >>>>>>>\n");

	char *tmp, *tmp2;

	tmp = malloc (sizeof(char)* (strlen("NICK ") + strlen (a_infos.client->nickname)));
	tmp2 = malloc (sizeof(char)* (strlen("USER   localhost:") + strlen(a_infos.client->nickname)*2 + strlen (a_infos.client->realname)));

	sprintf (tmp, "NICK %s", a_infos.client->nickname);
	sprintf (tmp2, "USER %s %s localhost: %s", a_infos.client->nickname, a_infos.client->nickname, a_infos.client->realname);
	
	espik_raw_send (tmp);
	espik_raw_send (tmp2);
	espik_raw_send ("JOIN #e.fr");
	
	printf ("<<<<<<<< DUMMMMY CODE >>>>>>>\n");

	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 (); */

#if _ESPIK_DEBUG_
	printf ("end\n");
#endif

	ecore_config_shutdown ();
	/* ecore_con_shutdown (); */
	ecore_shutdown ();

	return (0);
}