src/irc_proto.h
author Tero Marttila <terom@fixme.fi>
Thu, 12 Mar 2009 22:50:08 +0200
changeset 45 71e65564afd2
parent 39 a4891d71aca9
child 72 43084f103c2a
permissions -rw-r--r--
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)
39
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
#ifndef IRC_PROTO_H
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     2
#define IRC_PROTO_H
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     4
/**
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     5
 * @file
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     6
 *
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     7
 * General IRC protocol things, such as prefix/nickmask/nickname parsing
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     8
 */
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     9
#include "error.h"
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    10
#include <stddef.h>
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    11
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    12
/**
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
    13
 * Maximum length of an IRC nickname including terminating NUL.
39
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    14
 */
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    15
#define IRC_NICK_MAX 31
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    16
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    17
/**
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
    18
 * Maximum length of an IRC prefix/nickmask string, including any termianting NULs.
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
    19
 *
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
    20
 * XXX: currently this is pretty large, but does it really matter? We have more than 4k stack...
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
    21
 */
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
    22
#define IRC_PREFIX_MAX 510
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
    23
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
    24
/**
39
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    25
 * Parsed nickmask
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    26
 */
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    27
struct irc_nm {
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    28
    /** Nickname, not normalized */
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    29
    const char *nickname;
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    30
    
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    31
    /** Username, including any ident-related prefix from the network */
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    32
    const char *username;
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    33
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    34
    /** Hostname, either reverse DNS hostname, literal IPv4 or literal IPv6 */
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    35
    const char *hostname;
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    36
};
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    37
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    38
/**
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    39
 * Parse a full nickmask from a prefix. This fails if the prefix is a server name.
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    40
 *
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
    41
 * Since we cannot modify the prefix string, the user must provide a buffer of at least IRC_PREFIX_MAX bytes to store
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
    42
 * the procesed prefix. The returned nm's fields will point into this buffer.
39
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    43
 */
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
    44
err_t irc_nm_parse (struct irc_nm *nm, char *buf, const char *prefix);
39
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    45
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    46
/**
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    47
 * Compare two nicknames for equality, with standard strcmp() semantics.
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    48
 */
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    49
int irc_cmp_nick (const char *nick1, const char *nick2);
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    50
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    51
/**
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    52
 * Compare up to the first n chars of the two nickname strings for equality, with standard strcmp() semantics.
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    53
 */
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    54
int irc_ncmp_nick (const char *nick1, const char *nick2, size_t n);
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    55
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    56
/**
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    57
 * Parse the nickname portion of a prefix, storing it in the given buffer of IRC_NICK_MAX bytes.
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    58
 */
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    59
err_t irc_prefix_parse_nick (const char *prefix, char nick[IRC_NICK_MAX]);
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    60
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    61
/**
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    62
 * Compare the nickname in the given prefix and with the given nickname for equality.
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    63
 *
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    64
 * @return -err for invalid prefix, 0 for match, >0 for non-match.
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    65
 */
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    66
int irc_prefix_cmp_nick (const char *prefix, const char *nick);
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    67
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    68
/**
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    69
 * @group IRC command numerics
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    70
 * @{
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    71
 */
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    72
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    73
/**
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    74
 * 001 <nick> :Welcome to the Internet Relay Network <nick>!<user>@<host>
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    75
 */
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    76
#define IRC_RPL_WELCOME         "001"
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    77
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    78
// @}
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    79
a4891d71aca9 rename irc_nm to irc_proto, and move numerics from irc_cmd.h
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    80
#endif