src/irc_conn.h
author Tero Marttila <terom@fixme.fi>
Mon, 09 Mar 2009 16:30:59 +0200
changeset 25 56367df4ce5b
parent 23 542c73d07d3c
child 27 e6639132bead
permissions -rw-r--r--
add irc_net module, and fix Makefile CFLAGS, add -Wextra
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
25
56367df4ce5b add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    36
56367df4ce5b add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    37
/**
56367df4ce5b add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    38
 * The configuration info for an IRC connection.
56367df4ce5b add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    39
 *
56367df4ce5b add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    40
 * XXX: this should probably be reworked, maybe as a separate irc_conn_register function?
56367df4ce5b add irc_net module, and fix Makefile CFLAGS, add -Wextra
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    41
 */
18
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    42
struct irc_conn_config {
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    43
    /* Nickname to use on that server */
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    44
    const char *nickname;
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
    /* Username to supply */
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    47
    const char *username;
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    48
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    49
    /* Realname to supply */
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    50
    const char *realname;
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    51
};
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    52
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
/**
18
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    54
 * 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
    55
 * 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
    56
 *
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    57
 * 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
    58
 * 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
    59
 *
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
    60
 * @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
    61
 * @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
    62
 * @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
    63
 * @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
    64
 * @return error code
18
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    65
 */
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    66
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
    67
20
d9c4c2980a0d irc_conn PING/PONG code, and line_proto fixups
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
    68
/**
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
    69
 * 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
    70
 * 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
    71
 *
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
    72
 * @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
    73
 * @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
    74
 */
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
    75
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
    76
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
    77
/**
20
d9c4c2980a0d irc_conn PING/PONG code, and line_proto fixups
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
    78
 * @group Simple request functions
d9c4c2980a0d irc_conn PING/PONG code, and line_proto fixups
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
    79
 *
d9c4c2980a0d irc_conn PING/PONG code, and line_proto fixups
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
    80
 * 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
    81
 * 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
    82
 *
d9c4c2980a0d irc_conn PING/PONG code, and line_proto fixups
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
    83
 * @{
d9c4c2980a0d irc_conn PING/PONG code, and line_proto fixups
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
    84
 */
d9c4c2980a0d irc_conn PING/PONG code, and line_proto fixups
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
    85
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
    86
/**
21
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
    87
 * 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
    88
 *
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
 * @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
    90
 * @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
    91
 * @return error code
21
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
    92
 */
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
    93
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
    94
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
    95
/**
18
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    96
 * 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
    97
 *
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
 * @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
    99
 */
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   100
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
   101
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   102
/*
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   103
 * 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
   104
 *
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
   105
 * @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
   106
 * @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
   107
 */
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   108
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
   109
20
d9c4c2980a0d irc_conn PING/PONG code, and line_proto fixups
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
   110
/*
d9c4c2980a0d irc_conn PING/PONG code, and line_proto fixups
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
   111
 * 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
   112
 *
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
 * @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
   114
 */
d9c4c2980a0d irc_conn PING/PONG code, and line_proto fixups
Tero Marttila <terom@fixme.fi>
parents: 18
diff changeset
   115
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
   116
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
   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
 * 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
   119
 *
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
   120
 * 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
   121
 *
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
   122
 * @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
   123
 */
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
   124
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
   125
21
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
   126
// @}
0911d0b828d4 add basic log.c module
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
   127
18
dedf137b504f add initial irc_conn code that can register
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   128
#endif /* IRC_CONN_H */