src/irc_conn.h
author Tero Marttila <terom@fixme.fi>
Sun, 08 Mar 2009 17:17:37 +0200
changeset 23 542c73d07d3c
parent 21 0911d0b828d4
child 25 56367df4ce5b
permissions -rw-r--r--
add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
18
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
#ifndef IRC_CONN_H
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     2
#define IRC_CONN_H
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
23
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
     4
/**
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
     5
 * @file
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
     6
 *
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
     7
 * Support for connections to IRC servers, a rather fundamental thing. This holds the line_proto to handle the network
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
     8
 * communications, and then takes care of sending/receiving commands, as well as updating some core state like
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
     9
 * current nickname.
18
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    10
 */
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    11
23
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    12
struct irc_conn;
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    13
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    14
#include "error.h"
18
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    15
#include "sock.h"
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    16
#include "line_proto.h"
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    17
#include "irc_line.h"
23
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    18
#include "irc_cmd.h"
21
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
    19
#include <stdbool.h>
18
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    20
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    21
/*
23
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    22
 * Connection state
18
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    23
 */
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    24
struct irc_conn {
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    25
    /* We are a line-based protocol */
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    26
    struct line_proto *lp;
21
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
    27
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
    28
    /* Registered (as in, we have a working nickname)? */
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
    29
    bool registered;
23
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    30
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    31
    /* Command handlers */
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    32
    STAILQ_HEAD(irc_conn_handlers, irc_cmd_chain) handlers;
18
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    33
};
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    34
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    35
// XXX: this should probably be slightly reworked
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    36
struct irc_conn_config {
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    37
    /* Nickname to use on that server */
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    38
    const char *nickname;
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    39
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    40
    /* Username to supply */
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    41
    const char *username;
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    42
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    43
    /* Realname to supply */
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    44
    const char *realname;
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    45
};
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    46
23
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    47
/**
18
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    48
 * Create a new irc_conn using the given sock_stream, which should be connected to an IRC server. The parameters given
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    49
 * in \a config will be used to identify with the IRC server.
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    50
 *
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    51
 * On success, the resulting irc_conn is returned via *conn with SUCCESS. Otherwise, -ERR_* and error info is returned
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    52
 * via *err.
23
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    53
 *
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    54
 * @param conn the new irc_conn structure is returned via this pointer
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    55
 * @param sock the socket connected to the IRC server
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    56
 * @param config the basic information used to register
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    57
 * @param err errors are returned via this pointer
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    58
 * @return error code
18
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    59
 */
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    60
err_t irc_conn_create (struct irc_conn **conn, struct sock_stream *sock, const struct irc_conn_config *config, struct error_info *err);
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    61
20
d9c4c2980a0d irc_conn PING/PONG code, and line_proto fixups
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
    62
/**
23
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    63
 * Add a new chain of command handler callbacks to be used to handle irc_lines from the server. The given arg will be
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    64
 * passed to the callbacks as the context argument. The chain will be appended to the end of the current list of chains.
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    65
 *
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    66
 * @param chain the array of irc_cmd_handler structs, terminated with a NULL entry
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    67
 * @param arg the context argument to use for the callbacks
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    68
 */
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    69
err_t irc_conn_register_handler_chain (struct irc_conn *conn, struct irc_cmd_handler *handlers, void *arg);
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    70
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    71
/**
20
d9c4c2980a0d irc_conn PING/PONG code, and line_proto fixups
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
    72
 * @group Simple request functions
d9c4c2980a0d irc_conn PING/PONG code, and line_proto fixups
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
    73
 *
d9c4c2980a0d irc_conn PING/PONG code, and line_proto fixups
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
    74
 * The error handling of these functions is such that the error return code is can be used or ignored as convenient,
d9c4c2980a0d irc_conn PING/PONG code, and line_proto fixups
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
    75
 * as connection-fatal errors will be handled internally.
d9c4c2980a0d irc_conn PING/PONG code, and line_proto fixups
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
    76
 *
d9c4c2980a0d irc_conn PING/PONG code, and line_proto fixups
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
    77
 * @{
d9c4c2980a0d irc_conn PING/PONG code, and line_proto fixups
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
    78
 */
d9c4c2980a0d irc_conn PING/PONG code, and line_proto fixups
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
    79
23
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    80
/**
21
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
    81
 * Send a generic IRC message
23
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    82
 *
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    83
 * @param conn the IRC protocol connection
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    84
 * @param line the irc_line protocol line to send
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    85
 * @return error code
21
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
    86
 */
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
    87
err_t irc_conn_send (struct irc_conn *conn, const struct irc_line *line);
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
    88
23
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    89
/**
18
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    90
 * Send a NICK message
23
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    91
 *
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    92
 * @param nickname the new nickname to use
18
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    93
 */
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    94
err_t irc_conn_NICK (struct irc_conn *conn, const char *nickname);
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    95
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    96
/*
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    97
 * Send a USER message
23
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    98
 *
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
    99
 * @param username the username to register with, may be replaced with ident reply
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
   100
 * @param realname the full-name to register with
18
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   101
 */
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   102
err_t irc_conn_USER (struct irc_conn *conn, const char *username, const char *realname);
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   103
20
d9c4c2980a0d irc_conn PING/PONG code, and line_proto fixups
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
   104
/*
d9c4c2980a0d irc_conn PING/PONG code, and line_proto fixups
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
   105
 * Send a PONG message to the given target
23
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
   106
 *
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
   107
 * @param target the PING source, aka. the target to send the PONG reply to
20
d9c4c2980a0d irc_conn PING/PONG code, and line_proto fixups
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
   108
 */
d9c4c2980a0d irc_conn PING/PONG code, and line_proto fixups
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
   109
err_t irc_conn_PONG (struct irc_conn *conn, const char *target);
18
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   110
23
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
   111
/*
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
   112
 * Send a JOIN message for the given channel
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
   113
 *
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
   114
 * XXX: this doesn't implement the full command options
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
   115
 *
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
   116
 * @param channel the full channel name to join
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
   117
 */
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
   118
err_t irc_conn_JOIN (struct irc_conn *conn, const char *channel);
542c73d07d3c add a simple irc_log module (with evsql code) that joins a channel and log_info's PRIVMSGs
Tero Marttila <terom@fixme.fi>
parents: 21
diff changeset
   119
21
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
   120
// @}
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
   121
18
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   122
#endif /* IRC_CONN_H */