Initial commit, version 2.6.3a
[tropbot.git] / tblib.h
1 /*-----------------------------------------------------------------------------
2   Thanks to http://world.std.com/~jimf/sockets.html
3 -----------------------------------------------------------------------------*/
4
5 #ifndef TBLIB_H
6 #define TBLIB_H
7
8 #include <sys/time.h>
9 #include <sys/types.h>
10 #include <sys/socket.h>
11 #include <netinet/in.h>
12 #include <netdb.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <signal.h>
16
17 #ifdef _AIX
18 #include <sys/select.h>
19 #endif
20
21 #include <iostream.h>
22 #include <string.h>
23
24 #include "list.cc"
25
26 //-----------------------------------------------------------------------------
27
28 /*
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 *);
38 */
39
40 //-----------------------------------------------------------------------------
41
42 #define BUFFER_SIZE 4096
43 #define SMALL_BUFFER_SIZE 128
44
45 #define NB_QUEUE_CONNECTS 3
46 #define MAXHOSTNAME 64
47 #define NB_SLICES_MAX 32
48
49 //-----------------------------------------------------------------------------
50
51 // This routine gets the nickame from the nick!user@host stuff
52
53 char *cut_nick_from_prefix(char *name);
54
55 int is_weird_login(char *login);
56
57 int is_pattern(char *s);
58
59 char *clean_banid(char *banid);
60
61 //-----------------------------------------------------------------------------
62
63 // This routine copy r in s, and move r to the next ' ', or sets it to
64 // NULL if no more ' ' is find
65
66 char *next_word(char *buffer, char *r, int buffer_size);
67
68 //-----------------------------------------------------------------------------
69
70 // This routine add the d string at the c car, and modify c
71 //                       ** USE WITH CARE **
72
73 inline void concat(char *&c, char *d)
74 {
75   while(*d != '\0') *c++ = *d++;
76 };
77
78 //-----------------------------------------------------------------------------
79
80 int is_hostname(char *host);
81
82 // Evaluate if an IP is numerical or not
83
84 int is_numeric(char *host);
85
86 int are_same_site(char *u1, char *u2);
87
88 //-----------------------------------------------------------------------------
89
90 void concat_pattern_from_host(char *result, char *host);
91 char *patter_from_prefix(char *prefix, int site_ban, char *&pattern);
92
93 //-----------------------------------------------------------------------------
94
95 int Contains(char *string, char c);
96 int find_substring(char *string, char *substring,
97                    int *debut, int *debut_sub);
98
99 // Send back if the string match pattern or not (pattern with '?' and
100 // '*')
101
102 int match_pattern(char *pattern, char *string);
103
104 //-----------------------------------------------------------------------------
105
106 // Uncap string
107 void uncap(char *string);
108
109 // Duplicate a string
110 char *strdup(char *s);
111
112 // Evaluate if strings are equal
113 int eq(char *s, char *t);
114
115 //-----------------------------------------------------------------------------
116
117 char *seconds_to_string(int time);
118 int string_to_seconds(char *string);
119
120 //-----------------------------------------------------------------------------
121
122 // Socket stuff
123
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);
128
129 //-----------------------------------------------------------------------------
130
131 int slice_buffer(char *&src, char *endsrc,
132                  char *&dest_cmd,
133                  char *&prefix,
134                  char **slice_cmd, int &n_cmd,
135                  char *&dest_ctcp,
136                  char **slice_ctcp, int &n_ctcp);
137
138 //-----------------------------------------------------------------------------
139
140 class ListChar : public List<char *>
141 {
142 public:
143   void Print();
144   void Clear();
145   void Add(char *s);
146   void Remove(char *s);
147   int Matches(char *s);
148   int IsMatchedBy(char *s);
149   int Contains(char *s);
150 };
151
152 //-----------------------------------------------------------------------------
153
154 #endif