libsrsirc  0.0.14
Lightweight, cross-platform IRC library
Functions
Utility function interface provided by util.h

Functions

void lsi_ut_ident2nick (char *dest, size_t dest_sz, const char *ident)
 Extract the nick from a nick[!user][@host]-style identity. More...
 
void lsi_ut_ident2uname (char *dest, size_t dest_sz, const char *ident)
 does the same as lsi_ut_ident2nick, just for the user part More...
 
void lsi_ut_ident2host (char *dest, size_t dest_sz, const char *ident)
 does the same as lsi_ut_ident2nick, just for the host part More...
 
int lsi_ut_istrcmp (const char *n1, const char *n2, int casemap)
 case-insensitively compare strings, taking case mapping into account. More...
 
int lsi_ut_istrncmp (const char *n1, const char *n2, size_t len, int casemap)
 like lsi_ut_istrcmp, but compare only a maximum of len chars
 
char lsi_ut_tolower (char c, int casemap)
 casemap-aware translate a char to lowercase, if uppercase
 
void lsi_ut_strtolower (char *dest, size_t destsz, const char *str, int casemap)
 casemap-aware translate a string to lowercase More...
 
void lsi_ut_parse_hostspec (char *hoststr, size_t hoststr_sz, uint16_t *port, bool *ssl, const char *hostspec)
 parse a "host spec" (i.e. something "host:port"-ish) More...
 
bool lsi_ut_parse_pxspec (int *ptype, char *hoststr, size_t hoststr_sz, uint16_t *port, const char *pxspec)
 parse a "proxy specifier". More...
 
char * lsi_ut_sndumpmsg (char *dest, size_t dest_sz, void *tag, tokarr *msg)
 glue a tokenized message back together into a single line More...
 
void lsi_ut_dumpmsg (void *tag, tokarr *msg)
 Like lsi_ut_sndumpmsg(), but print the result to stderr.
 
bool lsi_ut_conread (tokarr *msg, void *tag)
 dump-to-stderr conread handler (see irc_regcb_conread()) More...
 
void lsi_ut_mut_nick (char *nick, size_t nick_sz)
 Default alternative nickname generator. More...
 
char ** lsi_ut_parse_MODE (irc *ctx, tokarr *msg, size_t *num, bool is324)
 Dissect a MODE message, correlating mode chars with their arguments. More...
 
int lsi_ut_classify_chanmode (irc *ctx, char c)
 Determine class of a channel mode. More...
 
tokarrlsi_ut_clonearr (tokarr *arr)
 deep-copy a tokarr (usually containing a tokenized irc msg) More...
 
void lsi_ut_freearr (tokarr *arr)
 free a tokarr (as obtained by lsi_ut_clonearr()) More...
 
char * lsi_ut_snrcmsg (char *dest, size_t destsz, tokarr *msg, bool coltr)
 Reconstruct a valid protocol message from a tokarr. More...
 
bool lsi_ut_tokenize (char *buf, tokarr *tok)
 In-place field-split an IRC protocol message and populate a tokarr. More...
 
const char * lsi_ut_casemap_nam (int cm)
 Determine the name of a given case mapping. More...
 
bool lsi_ut_ischan (irc *ctx, const char *str)
 Determine whether a given string is a channel. More...
 

Detailed Description

Function Documentation

void lsi_ut_ident2nick ( char *  dest,
size_t  dest_sz,
const char *  ident 
)

Extract the nick from a nick[!user][@host]-style identity.

Parameters
destBuffer where the extracted nickname will be put in
dest_szSize of dest buffer (\0-termination is ensured)
identThe nick[!user][@host]-style identity to deal with.
void lsi_ut_ident2uname ( char *  dest,
size_t  dest_sz,
const char *  ident 
)

does the same as lsi_ut_ident2nick, just for the user part

If there is no user part, dest will point to an empty string

void lsi_ut_ident2host ( char *  dest,
size_t  dest_sz,
const char *  ident 
)

does the same as lsi_ut_ident2nick, just for the host part

If there is no host part, dest will point to an empty string

int lsi_ut_istrcmp ( const char *  n1,
const char *  n2,
int  casemap 
)

case-insensitively compare strings, taking case mapping into account.

Parameters
n1,n2The strings to be compared
casemapCMAP_* constant (usually what irc_casemap() returns)
Returns
0 if equal; -1 if n2 comes after n1 (lex.), 1 otherwise
See also
irc_casemap()
void lsi_ut_strtolower ( char *  dest,
size_t  destsz,
const char *  str,
int  casemap 
)

casemap-aware translate a string to lowercase

Parameters
destbuffer where the resulting lowercase string will be put in
destszsize of dest (\0-termination is ensured)
strinput string to have its uppercase characters lowered
casemapCMAP_* constant (usually what irc_casemap() returns)
void lsi_ut_parse_hostspec ( char *  hoststr,
size_t  hoststr_sz,
uint16_t *  port,
bool *  ssl,
const char *  hostspec 
)

parse a "host spec" (i.e. something "host:port"-ish)

Parameters
hoststrbuffer where the host part will be put in
hoststr_szsize of said buffer (\0-termination is ensured)
portpoints to where the port will be put in (0 if none)
sslpoints to a bool which tells if SSL was wished for
hostspecthe host specifier to parse. format: host[:port]['/SSL'] where host can be a hostname, an IPv4- or an IPv6-Address, port is a 16 bit unsigned integer and the '/SSL' is literal
bool lsi_ut_parse_pxspec ( int *  ptype,
char *  hoststr,
size_t  hoststr_sz,
uint16_t *  port,
const char *  pxspec 
)

parse a "proxy specifier".

A proxy specifier is a (no-ssl) "host spec" (see lsi_ut_parse_hostspec()), prefixed by either 'HTTP:', 'SOCKS4:' or 'SOCKS5:'.

Parameters
hoststrSee lsi_ut_parse_hostspec()
hoststr_szSee lsi_ut_parse_hostspec()
portSee lsi_ut_parse_hostspec()
ptypeThe proxy type (as in one of the IRCPX_* constants
pxspecThe "proxy specifier" format: proxytype:hostspec where proxytype is one of 'HTTP', 'SOCKS5', 'SOCKS5', and hostspec is a host specifier as shown in lsi_ut_parse_hostspec() (with the constraint that /SSL isn't allowed (yet?)) (The other parameters work as in lsi_ut_parse_hostspec())
Returns
true on success; false on invalid format or invalid proxy type
char* lsi_ut_sndumpmsg ( char *  dest,
size_t  dest_sz,
void *  tag,
tokarr msg 
)

glue a tokenized message back together into a single line

This is mostly useful for debugging; it does /not/ generate valid protocol lines.

Parameters
destbuffer where the resulting line string will be put in
dest_szSize of dest buffer (\0-termination is ensured)
tagXXX why is this here? Provide NULL for this parameter...
msgpointer to a tokarr containing the message fields that are to be glued back together.
Returns
dest, where the result is put in.
bool lsi_ut_conread ( tokarr msg,
void *  tag 
)

dump-to-stderr conread handler (see irc_regcb_conread())

Returns
true
See also
fp_con_read
void lsi_ut_mut_nick ( char *  nick,
size_t  nick_sz 
)

Default alternative nickname generator.

See also
irc_regcb_mutnick(), fp_mut_nick
char** lsi_ut_parse_MODE ( irc ctx,
tokarr msg,
size_t *  num,
bool  is324 
)

Dissect a MODE message, correlating mode chars with their arguments.

A typical MODE message looks like this:

1 :irc.example.org MODE #channel +oln-kt NewOp 42 OldKey

As one can see, there are 5 mode letters involved, but only 3 arguments provided – whether or not a mode takes an argument is determined by the channel mode classes the IRC server advertised in its 005 message and hence must be figured out at runtime. To make life easier to the user, this function is provided to take care of how the twists of dealing with MODE by turning a MODE message into an array of strings, where each element has only one mode char followed by its argument, if it had one.

The MDOE message in the above example would be turned into an array like:

1 { [0] = "+o NewOp",
2  [1] = "+l 42"
3  [2] = "+n",
4  [3] = "-k OldKey",
5  [4] = "-t" }

(Assuming typical IRC servers that implement the conventional modes with their conventional semantics. Weird servers may do this differently (which is the reason this function is provided in the first place))

Parameters
msgtokarr (as populated by irc_read(), containing the MODE message in question.
numThe number of elements in the resulting array will be stored in the variable pointed to by this parameter.
is324This function can also be used to dissect the 324 message, which has pretty much identical semantics. Pass true here if your msg contains a 324 rather than a MODE
Returns
A pointer into a newly allocated array of char *, where each element points to one specific mode change as described above

NOTE: The caller is (currently) responsible for free()ing all elements of the returned array, as well as the (pointer into) the array itself.

NOTE2: There is probably little reason to use this function as of the addition of channel tracking, since that can be used to keep track of the mode changes for us.

int lsi_ut_classify_chanmode ( irc ctx,
char  c 
)

Determine class of a channel mode.

Parameters
cThe channel mode letter (b, n, etc) to classify
Returns
If c is a channel mode supported by the IRC server we're talking to, one of the CHANMODE_CLASS_A, CHANMODE_CLASS_B, CHANMODE_CLASS_C, CHANMODE_CLASS_D constants is returned. Otherwise, we return 0.
tokarr* lsi_ut_clonearr ( tokarr arr)

deep-copy a tokarr (usually containing a tokenized irc msg)

Parameters
arrpointer to the tokarr to clone
Returns
A pointer to the cloned result
void lsi_ut_freearr ( tokarr arr)

free a tokarr (as obtained by lsi_ut_clonearr())

Parameters
arrPointer to a tokarr obtained from lsi_ut_clonearr()
char* lsi_ut_snrcmsg ( char *  dest,
size_t  destsz,
tokarr msg,
bool  coltr 
)

Reconstruct a valid protocol message from a tokarr.

There is probably little reason to use this. It might come handy for implementing bouncer-like software, though.

Parameters
destBuffer where the resulting line will be put in
destszSize of dest (\0-termination is ensured)
msgPointer to a tokarr (as obtained from irc_read() or lsi_ut_clonearr()
coltrIf the last field in msg does not contain spaces, this flag determines whether or not to prefix it with a colon anyway (this is normally done as a syntactic trick to allow space in the last argument)
Returns
dest
bool lsi_ut_tokenize ( char *  buf,
tokarr tok 
)

In-place field-split an IRC protocol message and populate a tokarr.

This is the routine that field-splits the protocol messages we read from the IRC server. It is provided as a utility function because it might be useful in its own right.

Parameters
bufPointer to a buffer that contains an IRC protocol message. The contents of this buffer are changed by this function (specifically, \0 characters are inserted)
tokPointer to a tokarr that is to be populated with pointers to the identified fields in buf
See also
tokarr
const char* lsi_ut_casemap_nam ( int  cm)

Determine the name of a given case mapping.

This is useful pretty much only for debugging.

Parameters
cmCasemapping constant (CMAP_*)
Returns
Name of the casemapping
See also
CMAP_ASCII, CMAP_RFC1459, CMAP_STRICT_RFC1459
bool lsi_ut_ischan ( irc ctx,
const char *  str 
)

Determine whether a given string is a channel.

This is a convenience function that tries to find the first character of the given string in the 005 CHANTYPES entry, in order to guess whether it is a channel name.

Parameters
strAn arbitrary string that may or may not be a channel name
Returns
true if str starts with one of the channel types that were advertised in the 005 ISUPPORT message, or with either '#' or '&' if no 005 message was seen.

Note that this function returning true does NOT mean the given string is necessarily a valid channel name (i.e. it might contain blanks or TABs, both of which cannot appear in valid channel names). All we check is just whether it begins with a character that is a known channel type.