aboutsummaryrefslogtreecommitdiff
path: root/src/espik_common_handler.c
blob: 98ed028522eaa88f0befdc965bbf3f6a6ea68dcc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <Ecore.h>
#include <Ecore_Con.h>

#include "global.h"
#include "espik_common_handler.h"
#include "espik_irc.h"
#include "espik_net.h"
#include "espik.h"
#include "espik_error.h"

int server_data (void *data __UNUSED__, int ev_type __UNUSED__,
				Ecore_Con_Event_Server_Data * ev)
{
    printf ("%s\n", (char *)ev->data);

    return (0);
}

int kb_get (void *data __UNUSED__, Ecore_Fd_Handler * fd_handler)
{
    char                   *kb;
    char                   *tmp;
    int                     count;

    kb = malloc (sizeof (char) * 200);

    do
    {
        memset (kb, 0, 200);
        count = read (ecore_main_fd_handler_fd_get (fd_handler), kb, 198);

        if (count > 1)
        {
            del_backslash (kb);
            tmp = irc_send (kb);

            if (tmp)
            {
                espik_raw_send (tmp);
                free (tmp);
            }
        }
    }
    while (count >= 198);

    if (count == -1)
        perror ("read");

    if (count == 0)
    {
        tmp = irc_quit ("", "^D pressed");
        printf ("kb_get:\ntmp: %s\n", tmp);
        espik_raw_send (tmp);
        printf ("AFTER espik_raw_send\n");

/*		irc_disconnect();	*/
        espik_con_shutdown ();

        ecore_main_loop_quit ();

        free (tmp);
        return (0);
    }

    return (1);
}