1 #ifndef HEADER_SERVERDCC
2 #define HEADER_SERVERDCC
3 
4 #include <errno.h>
5 #include <strings.h>
6 
7 //#include <map>
8 
9 #include "config.h"
10 
11 #include <string>
12 #ifdef USING_STD_STRING
13 using std::string;
14 #endif
15 
16 #ifdef DMALLOC
17 #include <dmalloc.h>
18 #endif
19 
20 #include "defines.h"
21 #include "support.h"
22 #include "llist.h"
23 #include "nick.h"
24 #include "channel.h"
25 #include "query.h"
26 #include "illist.h"
27 #include "hash.h"
28 #include "network.h"
29 
30 enum {
31   DCC_OVERWRITE = 1<<0
32 };
33 
34 class thide {
35 public:
36   int n315;
37   int n352;
38   int n353;
39   int n366;
thide()40   thide() {
41     n315=0;
42     n352=0;
43     n353=0;
44     n366=0;
45   }
46 };
47 
48 class tacceptitem {
49  private:
50   char *nick;
51  public:
52   int type;
53   int port;
54   char ip[IPLEN];
55   int id;
56   int size;
57   char file[TEMPLEN];
58 
59   int operator>=(tacceptitem &acceptitem) {
60     return(id==acceptitem.id);
61   }
62   int operator==(tacceptitem &acceptitem) {
63     return(id==acceptitem.id);
64   }
65 
getnick(void)66   const char *getnick(void) {
67     return nick;
68   }
69 
setnick(const char * n)70   void setnick(const char *n) {
71     free(nick);
72     nick = mystrdup(n);
73   }
74 
tacceptitem(tacceptitem & t)75   tacceptitem(tacceptitem &t) {
76     nick = mystrdup(t.nick);
77     type = t.type;
78     port = t.port;
79     memcpy(ip, t.ip, IPLEN);
80     id = t.id;
81     size = t.size;
82     memcpy(file, t.file, TEMPLEN);
83   }
84 
tacceptitem()85   tacceptitem() {
86     nick = mystrdup("");
87   }
88 
~tacceptitem()89   ~tacceptitem() {
90     free(nick);
91   }
92 };
93 
94 class tdcc : public handleable {
95  private:
96     char *nick;
97   public:
98     int port;
99     int connected;
100     int connecting;
101     int listening;
102     char ip[IPLEN];
103     class tserver* server;
104     char buffer[BUFLEN];
105     char pathname[20];
106     int errortest;
107     char file[TEMPLEN];
108     char destfile[TEMPLEN];
109     int index;
110     int entryindex;
111     int flags;
112     int checkflags;
113     int sockfd;
114     int filefd;
115     int type;
116     int lastchunk;
117     long size;
118     int transmitted;
119     int written;
120     int acknowledged;
121     long long timestarted;
122     long dccseconds;
123     long dccmilliseconds;
124     tdcc(class tserver *serverp, const char *thenick);
125     tdcc(class tserver *serverp,
126 	 const char *thenick,
127 	 const char *thefile);
128     tdcc(class tserver *serverp, const char *thenick, char *theip, int theport);
129     tdcc(class tserver *serverp, const char *thenick, char *theip, int theport,
130 	 char *thefile, int thesize, int dccflags, const char *renamedfile);
131     int operator>=(tdcc &dcc) {
132       if(strlen(dcc.nick)) return 0; else return 0;
133     }
134     int operator==(tdcc &dcc) {
135       return(!strcasecmp(nick,dcc.nick)||!strcmp(pathname,dcc.pathname));
136     }
137 
getnick(void)138     const char *getnick(void) {
139       return nick;
140     }
141 
setnick(const char * n)142     void setnick(const char *n) {
143       free(nick);
144       nick = mystrdup(n);
145     }
146 
147     void handle(int mask);
148     int getflags();
149     int getsockfd();
150     void sendchunk();
151     int handle_incoming();
152     void usedata();
153     void handle_outgoing();
154     void complete_connect(void);
155     int senddata(const char *);
156     int disconnect(void);
157     void do_accept(void);
158     void perror(char *message);
159     void perror(char *message, int number);
160     void filemessage(char *message);
161     ~tdcc();
162 };
163 
164 class tdccentry {
165  public:
166   int index;
167   tdcc *dcc;
168   int operator>=(tdccentry &entryitem) {
169     return (index-entryitem.index);
170   }
171   int operator==(tdccentry &entryitem) {
172     return(index==entryitem.index||dcc==entryitem.dcc);
173   }
tdccentry()174   tdccentry() {
175     index=-1;
176     dcc=0;
177   }
178 };
179 
180 class tpair {
181  public:
182   string name;
183   string value;
184   int operator>=(const tpair &pair) {
185     return 0;
186   }
187   int operator==(const tpair &pair) {
188     return (name==pair.name);
189   }
190 };
191 
192 class tfullpair {
193  public:
194   string name;
195   string value;
196   int operator>=(const tfullpair &fullpair) {
197     return 0;
198   }
199   int operator==(const tfullpair &fullpair) {
200     return (name==fullpair.name && value==fullpair.value);
201   }
202 };
203 
204 class tuserlist {
205  public:
206   string type;
207   string info;
208   list<tpair> flags;
209   int index;
210   int operator>=(const tuserlist &userlist) {
211     return (index>=userlist.index);
212   }
213   int operator==(const tuserlist &userlist) {
214     return (type==userlist.type && info==userlist.info);
215   }
216 };
217 
218 class tuserlistalias {
219  public:
220   string name;
221   list<tfullpair> typeinfos;
222   int operator>=(const tuserlistalias &userlistalias) {
223     return 0;
224   }
225   int operator==(const tuserlistalias &userlistalias) {
226     return(name==userlistalias.name);
227   }
228 };
229 
230 class tserver : public handleable {
231   private:
232     char temp[TEMPLEN];
233     char *mynick;
234   public:
235     hash ial;
236     //map<string,string> ial;
237     char *name;
238     char *desc;
239     thide hide;
240     int port;
241     char ip[IPLEN];
242     char localip[IPLEN];
243     char buffer[BUFLEN];
244     int flags;
245     int sockfd;
246     int connected;
247     int connecting;
248     char pathname[20];
249     string pass;
250     int index;
251     list<tchan> chanlist;
252     list<tquery> querylist;
253     list<tglobalnick> nicklist;
254     list<tacceptitem> acceptlist;
255     list<tuserlistalias> aliaslist;
256     ilist<tuserlist> userlist;
257     int userlist_nocase;
258     ilist<tdccentry> dcclist;
259 
260     int script(char *name, char *format, ...);
261     void ial_prefix(char *);
262     void ial_add(char *, char *);
263     void perror(char *);
264     void perror(char *message, int number);
265     void createchannel(const char *);
266     void createquery(const char *);
267     tserver(const char *address, int theport, const char *password);
268     void server(const char *address, int theport, const char *password);
269     ~tserver();
270     void usedata();
271 
tserver()272     tserver() {}
273 
274     // Network Handling
275     void handle(int mask);
276     void handle_connect(void);
277     int getflags();
278     int getsockfd();
279 
280     // Network Functions
281     int senddata(const char *);
282     int do_connect(void);
283     int disconnect(int);
284 
285     // Dynamic nick management
getmynick(void)286     const char *getmynick(void) {
287       return mynick;
288     }
289 
setmynick(const char * n)290     void setmynick(const char *n) {
291       free(mynick);
292       mynick = mystrdup(n);
293     }
294 
295 };
296 
297 #endif
298