1 /*-----------------------------------------------------------------------------
2 Thanks to http://world.std.com/~jimf/sockets.html
3 -----------------------------------------------------------------------------*/
10 #include <sys/socket.h>
11 #include <netinet/in.h>
20 #include <sys/select.h>
21 #include <sys/socketvar.h>
22 #include <netinet/in.h>
23 #include <arpa/inet.h>
31 //-----------------------------------------------------------------------------
34 extern "C" int close(int);
35 extern "C" int read(int, char *, int);
36 extern "C" int gethostname();
37 extern "C" size_t write(int, char *, int);
38 extern "C" int socket(int, int, int);
39 extern "C" int connect(int, struct sockaddr *, int);
40 extern "C" int bind(int, struct sockaddr *, int);
41 extern "C" int listen(int, int);
42 extern "C" int accept(int, struct sockaddr *, int *);
45 //-----------------------------------------------------------------------------
47 #define BUFFER_SIZE 4096
48 #define SMALL_BUFFER_SIZE 128
50 #define NB_QUEUE_CONNECTS 3
51 #define MAXHOSTNAME 64
52 #define NB_SLICES_MAX 32
54 //-----------------------------------------------------------------------------
56 // This routine gets the nickame from the nick!user@host stuff
58 char *cut_nick_from_prefix(char *name);
60 int is_weird_login(char *login);
62 int is_pattern(char *s);
64 char *clean_banid(char *banid);
66 //-----------------------------------------------------------------------------
68 // This routine copy r in s, and move r to the next ' ', or sets it to
69 // NULL if no more ' ' is find
71 char *next_word(char *buffer, char *r, int buffer_size);
73 //-----------------------------------------------------------------------------
75 // This routine add the d string at the c car, and modify c
76 // ** USE WITH CARE **
78 inline void concat(char *&c, char *d)
80 while(*d != '\0') *c++ = *d++;
83 //-----------------------------------------------------------------------------
85 int is_hostname(char *host);
87 // Evaluate if an IP is numerical or not
89 int is_numeric(char *host);
91 int are_same_site(char *u1, char *u2);
93 //-----------------------------------------------------------------------------
95 void concat_pattern_from_host(char *result, char *host);
96 char *pattern_from_prefix(char *prefix, int site_ban);
98 //-----------------------------------------------------------------------------
100 int Contains(char *string, char c);
101 int find_substring(char *string, char *substring,
102 int *debut, int *debut_sub);
104 // Send back if the string match pattern or not (pattern with '?' and
107 int match_pattern(char *pattern, char *string);
109 //-----------------------------------------------------------------------------
112 void uncap(char *string);
114 // Duplicate a string
115 char *strdup(char *s);
117 // Evaluate if strings are equal
118 int eq(char *s, char *t);
120 //-----------------------------------------------------------------------------
122 char *seconds_to_string(int time);
123 int string_to_seconds(char *string);
125 //-----------------------------------------------------------------------------
129 int call_socket_ip(unsigned short host, unsigned short portnum);
130 int call_socket(char *hostname, unsigned short portnum);
131 int establish(unsigned short portnum);
132 int get_connection(int s);
134 //-----------------------------------------------------------------------------
136 int slice_buffer(char *&src, char *endsrc,
139 char **slice_cmd, int &n_cmd,
141 char **slice_ctcp, int &n_ctcp);
143 //-----------------------------------------------------------------------------
145 class ListChar : public List<char *>
150 void Remove(char *s);
151 int Matches(char *s);
152 int IsMatchedBy(char *s);
153 int Contains(char *s);
156 //-----------------------------------------------------------------------------