1 /*-----------------------------------------------------------------------------
2 Thanks to http://world.std.com/~jimf/sockets.html
3 -----------------------------------------------------------------------------*/
10 #include <sys/socket.h>
11 #include <netinet/in.h>
18 #include <sys/select.h>
26 //-----------------------------------------------------------------------------
29 extern "C" int close(int);
30 extern "C" int read(int, char *, int);
31 extern "C" int gethostname();
32 extern "C" size_t write(int, char *, int);
33 extern "C" int socket(int, int, int);
34 extern "C" int connect(int, struct sockaddr *, int);
35 extern "C" int bind(int, struct sockaddr *, int);
36 extern "C" int listen(int, int);
37 extern "C" int accept(int, struct sockaddr *, int *);
40 //-----------------------------------------------------------------------------
42 #define BUFFER_SIZE 4096
43 #define SMALL_BUFFER_SIZE 128
45 #define NB_QUEUE_CONNECTS 3
46 #define MAXHOSTNAME 64
47 #define NB_SLICES_MAX 32
49 //-----------------------------------------------------------------------------
51 // This routine gets the nickame from the nick!user@host stuff
53 char *cut_nick_from_prefix(char *name);
55 int is_weird_login(char *login);
57 int is_pattern(char *s);
59 char *clean_banid(char *banid);
61 //-----------------------------------------------------------------------------
63 // This routine copy r in s, and move r to the next ' ', or sets it to
64 // NULL if no more ' ' is find
66 char *next_word(char *buffer, char *r, int buffer_size);
68 //-----------------------------------------------------------------------------
70 // This routine add the d string at the c car, and modify c
71 // ** USE WITH CARE **
73 inline void concat(char *&c, char *d)
75 while(*d != '\0') *c++ = *d++;
78 //-----------------------------------------------------------------------------
80 int is_hostname(char *host);
82 // Evaluate if an IP is numerical or not
84 int is_numeric(char *host);
86 int are_same_site(char *u1, char *u2);
88 //-----------------------------------------------------------------------------
90 void concat_pattern_from_host(char *result, char *host);
91 char *patter_from_prefix(char *prefix, int site_ban, char *&pattern);
93 //-----------------------------------------------------------------------------
95 int Contains(char *string, char c);
96 int find_substring(char *string, char *substring,
97 int *debut, int *debut_sub);
99 // Send back if the string match pattern or not (pattern with '?' and
102 int match_pattern(char *pattern, char *string);
104 //-----------------------------------------------------------------------------
107 void uncap(char *string);
109 // Duplicate a string
110 char *strdup(char *s);
112 // Evaluate if strings are equal
113 int eq(char *s, char *t);
115 //-----------------------------------------------------------------------------
117 char *seconds_to_string(int time);
118 int string_to_seconds(char *string);
120 //-----------------------------------------------------------------------------
124 int call_socket_ip(unsigned short host, unsigned short portnum);
125 int call_socket(char *hostname, unsigned short portnum);
126 int establish(unsigned short portnum);
127 int get_connection(int s);
129 //-----------------------------------------------------------------------------
131 int slice_buffer(char *&src, char *endsrc,
134 char **slice_cmd, int &n_cmd,
136 char **slice_ctcp, int &n_ctcp);
138 //-----------------------------------------------------------------------------
140 class ListChar : public List<char *>
146 void Remove(char *s);
147 int Matches(char *s);
148 int IsMatchedBy(char *s);
149 int Contains(char *s);
152 //-----------------------------------------------------------------------------