summaryrefslogtreecommitdiff
path: root/functions.h
blob: fe1bee8790dcd36f0da26b6c4c9c4bd43ecbacc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef FUNCTIONS_H_INCLUDED
#define FUNCTIONS_H_INCLUDED

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/select.h>

#define MAXDATASIZE 513 // max number of bytes we can get at once (RFC2812 says 512, plus one for null terminator)
#define MAXTOKENS 100 // maximum number of (CRLF or space) separated tokens per server response we expect (TODO - check this is reasonable)

// getstdin() return codes
#define OK       0
#define NO_INPUT 1
#define TOO_LONG 2

// Get stdin line with buffer overrun protection
int getstdin(char *prompt, char *buff, size_t sz);

// Append CR-LF to the end of a string (after cleaning up any existing trailing CR or LF)
void appendcrlf(char *string);

// Remove leading colon ':' which is the starting character of a prefix in an IRC message
void stripprefix(char *string);

// Extract final parameter from IRC message, removing the leading colon ':'
void extractfinalparameter(char *string);

// Extract the IRC nick from a prefix
void extractnickfromprefix(char *string);

// Update an existing nickuserhost string with a new nick
void updatenickuserhost(char *nickuserhost, char *nick);

// Update an existing 001 greeting with a new nickuserhost
void updategreetings(char *greeting001, char *greeting002, char *greeting003, char *greeting004, char *greeting005a, char *greeting005b, char *greeting005c, char *newnickuserhost, char *oldnickuserhost, char *newnick, char *oldnick);

#endif