src/irc_chan.c
author Tero Marttila <terom@fixme.fi>
Thu, 26 Mar 2009 22:03:20 +0200
changeset 73 2780a73c71f3
parent 72 43084f103c2a
child 74 11ec458d1cbf
permissions -rw-r--r--
add set_log_level function, and add --debug/--quiet options to test
26
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
#include "irc_chan.h"
39
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents: 38
diff changeset
     2
#include "irc_proto.h"
37
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
     3
#include "log.h"
26
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     4
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     5
#include <stdlib.h>
72
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
     6
#include <string.h>
26
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     7
#include <assert.h>
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     8
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     9
const char* irc_chan_name (struct irc_chan *chan)
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    10
{
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    11
    return chan->info.channel;
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    12
}
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    13
37
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    14
/**
72
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    15
 * Add or update a nickname to the irc_chan.users list.
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    16
 *
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    17
 * If the given nickname already exists in our users list, this does nothing. Otherwise, an irc_user is aquired using
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    18
 * irc_net_get_user, and a new irc_chan_user struct added to our users list.
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    19
 */
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    20
static err_t irc_chan_add_user (struct irc_chan *chan, const char *nickname)
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    21
{
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    22
    struct irc_user *user;
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    23
    struct irc_chan_user *chan_user;
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    24
    err_t err;
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    25
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    26
    // skip if already listed
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    27
    if (irc_chan_get_user(chan, nickname))
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    28
        return SUCCESS;
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    29
    
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    30
    // lookup/create the irc_user state
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    31
    if ((err = irc_net_get_user(chan->net, &user, nickname)))
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    32
        return err;
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    33
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    34
    // alloc the new irc_chan_user
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    35
    if ((chan_user = calloc(1, sizeof(*chan_user))) == NULL) {
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    36
        // XXX: release irc_user
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    37
        return ERR_CALLOC;
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    38
    }
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    39
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    40
    // store
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    41
    chan_user->user = user;
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    42
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    43
    // add to users list
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    44
    LIST_INSERT_HEAD(&chan->users, chan_user, chan_users);
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    45
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    46
    // ok
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    47
    return SUCCESS;
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    48
}
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    49
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    50
/**
37
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    51
 * :nm JOIN <channel>
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    52
 */ 
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    53
static void irc_chan_on_JOIN (const struct irc_line *line, void *arg)
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    54
{
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    55
    struct irc_chan *chan = arg;
72
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    56
    err_t err;
37
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    57
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    58
    // us?
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    59
    if (irc_prefix_cmp_nick(line->prefix, chan->net->conn->nickname) == 0) {
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    60
        // twiddle state
45
71e65564afd2 remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    61
        chan->joining = false;
71e65564afd2 remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    62
        chan->joined = true;
37
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    63
38
0c2e0cb46c3a implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents: 37
diff changeset
    64
        // invoke callback
0c2e0cb46c3a implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents: 37
diff changeset
    65
        IRC_CHAN_INVOKE_CALLBACK(chan, on_self_join);
45
71e65564afd2 remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    66
71e65564afd2 remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    67
    } else {
72
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    68
        char prefix_buf[IRC_PREFIX_MAX];
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    69
        struct irc_nm nm;
45
71e65564afd2 remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    70
        
72
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    71
        // parse the nickname
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    72
        if ((err = irc_nm_parse(&nm, prefix_buf, line->prefix)))
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    73
            return log_warn("invalid prefix: %s", line->prefix);
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    74
        
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    75
        // add them
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    76
        if ((err = irc_chan_add_user(chan, nm.nickname)))
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    77
            return log_warn("irc_chan_add_user(%s, %s): %s", irc_chan_name(chan), nm.nickname, error_name(err));
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    78
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    79
        // invoke callback (source)
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
    80
        IRC_CHAN_INVOKE_CALLBACK(chan, on_join, &nm);
38
0c2e0cb46c3a implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents: 37
diff changeset
    81
    }
0c2e0cb46c3a implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents: 37
diff changeset
    82
}
37
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
    83
38
0c2e0cb46c3a implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents: 37
diff changeset
    84
/**
0c2e0cb46c3a implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents: 37
diff changeset
    85
 * :nm PRIVMSG <channel> <message>
0c2e0cb46c3a implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents: 37
diff changeset
    86
 */
0c2e0cb46c3a implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents: 37
diff changeset
    87
static void irc_chan_on_PRIVMSG (const struct irc_line *line, void *arg)
0c2e0cb46c3a implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents: 37
diff changeset
    88
{
0c2e0cb46c3a implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents: 37
diff changeset
    89
    struct irc_chan *chan = arg;
45
71e65564afd2 remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    90
    char prefix_buf[IRC_PREFIX_MAX];
67
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 45
diff changeset
    91
    struct irc_nm nm;
45
71e65564afd2 remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    92
    err_t err;
38
0c2e0cb46c3a implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents: 37
diff changeset
    93
45
71e65564afd2 remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    94
    const char *msg = line->args[1];
71e65564afd2 remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    95
71e65564afd2 remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    96
    // parse nickmask
67
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 45
diff changeset
    97
    if ((err = irc_nm_parse(&nm, prefix_buf, line->prefix))) {
45
71e65564afd2 remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    98
        log_warn("invalid prefix: %s", line->prefix);
71e65564afd2 remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
    99
        
72
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   100
        // invoke callback with NULL source
45
71e65564afd2 remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   101
        IRC_CHAN_INVOKE_CALLBACK(chan, on_msg, NULL, msg);
71e65564afd2 remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   102
71e65564afd2 remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   103
    } else {
72
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   104
        // invoke callback (source, message)
67
aa94bf2b5f9b implement the SQL logs table and the INSERT-logging code for mod_irc_log
Tero Marttila <terom@fixme.fi>
parents: 45
diff changeset
   105
        IRC_CHAN_INVOKE_CALLBACK(chan, on_msg, &nm, msg);
45
71e65564afd2 remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   106
    }
37
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   107
}
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   108
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   109
/**
72
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   110
 * Add/update nicknames to users list using irc_chan_add_user
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   111
 *
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   112
 * @see IRC_RPL_NAMREPLY
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   113
 */
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   114
static void irc_chan_on_RPL_NAMREPLY (const struct irc_line *line, void *arg)
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   115
{
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   116
    struct irc_chan *chan = arg;
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   117
    char chanflags[IRC_CHANFLAGS_MAX];
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   118
    const char *nickname;
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   119
    err_t err;
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   120
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   121
    // the args
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   122
    const char *arg_names = line->args[3];
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   123
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   124
    // copy the nicklist to a mutable buffer
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   125
    char names_buf[strlen(arg_names) + 1], *names = names_buf;
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   126
    strcpy(names, arg_names);
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   127
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   128
    // iterate over each name
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   129
    // XXX: nickflags
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   130
    while ((nickname = strsep(&names, " "))) {
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   131
        // parse off the channel flags
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   132
        nickname = irc_nick_chanflags(nickname, chanflags);
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   133
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   134
        // add/update
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   135
        // XXX: do something with chanflags
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   136
        if ((err = irc_chan_add_user(chan, nickname)))
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   137
            log_warn("irc_chan_add_user(%s, %s): %s", irc_chan_name(chan), nickname, error_name(err));
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   138
    }
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   139
}
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   140
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   141
/**
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   142
 * Channel join sequence complete
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   143
 *
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   144
 * @see IRC_RPL_ENDOFNAMES
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   145
 */
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   146
static void irc_chan_on_RPL_ENDOFNAMES (const struct irc_line *line, void *arg)
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   147
{
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   148
    struct irc_chan *chan = arg;
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   149
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   150
    // XXX: update state
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   151
    log_info("channel join sync complete");
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   152
}
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   153
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   154
/**
37
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   155
 * Core command handlers
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   156
 */
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   157
struct irc_cmd_handler _cmd_handlers[] = {
72
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   158
    {   "JOIN",             &irc_chan_on_JOIN           },
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   159
    {   "PRIVMSG",          &irc_chan_on_PRIVMSG        },
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   160
    {   IRC_RPL_NAMREPLY,   &irc_chan_on_RPL_NAMREPLY   },
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   161
    {   IRC_RPL_ENDOFNAMES, &irc_chan_on_RPL_ENDOFNAMES },
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   162
    {   NULL,       NULL                                }
37
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   163
};
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   164
26
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   165
err_t irc_chan_create (struct irc_chan **chan_ptr, struct irc_net *net, const struct irc_chan_info *info, struct error_info *err)
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   166
{
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   167
    struct irc_chan *chan;
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   168
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   169
    // allocate
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   170
    if ((chan = calloc(1, sizeof(*chan))) == NULL)
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   171
        return SET_ERROR(err, ERR_CALLOC);
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   172
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   173
    // store
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   174
    chan->net = net;
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   175
    chan->info = *info;
37
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   176
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   177
    // init
72
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   178
    LIST_INIT(&chan->users);
37
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   179
    irc_cmd_init(&chan->handlers);
38
0c2e0cb46c3a implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents: 37
diff changeset
   180
    CHAIN_INIT(&chan->callbacks);
37
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   181
    
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   182
    // add handlers
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   183
    if ((ERROR_CODE(err) = irc_cmd_add(&chan->handlers, _cmd_handlers, chan)))
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   184
        goto error;
26
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   185
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   186
    // ok
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   187
    *chan_ptr = chan;
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   188
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   189
    return SUCCESS;
37
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   190
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   191
error:
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   192
    // cleanup
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   193
    irc_chan_destroy(chan);
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   194
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   195
    return ERROR_CODE(err);
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   196
}
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   197
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   198
void irc_chan_destroy (struct irc_chan *chan)
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   199
{
72
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   200
    // XXX: free chan_users list
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   201
37
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   202
    // free command handlers
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   203
    irc_cmd_free(&chan->handlers);
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   204
38
0c2e0cb46c3a implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents: 37
diff changeset
   205
    // free callbacks
0c2e0cb46c3a implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents: 37
diff changeset
   206
    chain_free(&chan->callbacks);
0c2e0cb46c3a implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents: 37
diff changeset
   207
37
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   208
    // free chan itself
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   209
    free(chan);
26
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   210
}
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   211
38
0c2e0cb46c3a implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents: 37
diff changeset
   212
err_t irc_chan_add_callbacks (struct irc_chan *chan, const struct irc_chan_callbacks *callbacks, void *arg)
0c2e0cb46c3a implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents: 37
diff changeset
   213
{
0c2e0cb46c3a implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents: 37
diff changeset
   214
    return chain_add(&chan->callbacks, callbacks, arg);
0c2e0cb46c3a implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents: 37
diff changeset
   215
}
0c2e0cb46c3a implement irc_chan_callbacks, and add on_msg
Tero Marttila <terom@fixme.fi>
parents: 37
diff changeset
   216
69
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   217
void irc_chan_remove_callbacks (struct irc_chan *chan, const struct irc_chan_callbacks *callbacks, void *arg)
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   218
{
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   219
    chain_remove(&chan->callbacks, callbacks, arg);
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   220
}
6f298b6e0d5f create irc_log_chan function to log a new irc_log_chan, and irc_log_chan_destroy to remove the added callbacks/command handlers
Tero Marttila <terom@fixme.fi>
parents: 67
diff changeset
   221
72
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   222
struct irc_chan_user* irc_chan_get_user (struct irc_chan *chan, const char *nickname)
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   223
{
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   224
    struct irc_chan_user *chan_user = NULL;
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   225
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   226
    // look for it...
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   227
    LIST_FOREACH(chan_user, &chan->users, chan_users) {
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   228
        if (irc_cmp_nick(nickname, chan_user->user->nickname) == 0) {
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   229
            // found
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   230
            return chan_user;
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   231
        }
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   232
    }
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   233
    
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   234
    // not found
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   235
    return NULL;
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   236
}
43084f103c2a add irc_user module for irc_chan to track users on a channel
Tero Marttila <terom@fixme.fi>
parents: 69
diff changeset
   237
26
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   238
err_t irc_chan_join (struct irc_chan *chan)
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   239
{
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   240
    err_t err;
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   241
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   242
    // XXX: error instead?
45
71e65564afd2 remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   243
    assert(!chan->joining && !chan->joined);
71e65564afd2 remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   244
    assert(chan->net->conn);
26
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   245
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   246
    // send JOIN message on the appropriate connection
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   247
    if ((err = irc_conn_JOIN(chan->net->conn, chan->info.channel)))
37
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   248
        // XXX: error state?
26
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   249
        return err;
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   250
37
4fe4a3c4496e change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
Tero Marttila <terom@fixme.fi>
parents: 26
diff changeset
   251
    // ok
45
71e65564afd2 remove irc_chan.state, modify irc_chan_callbacks.on_msg to take a irc_nm, improve error handling a bit further (up to irc_net now)
Tero Marttila <terom@fixme.fi>
parents: 39
diff changeset
   252
    chan->joining = true;
26
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   253
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   254
    return SUCCESS;
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   255
}
aec062af155d add irc_chan module
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   256