ircu2.10.12 pk910 fork
[ircu2.10.12-pk.git] / tools / Bounce / Bounce.h
1 /*
2  * IRC - Internet Relay Chat, tools/Bounce/Bounce.h
3  * Copyright (C) 1990 Jarkko Oikarinen and
4  *                    University of Oulu, Computing Center
5  *
6  * See file AUTHORS in IRC package for additional names of
7  * the programmers.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 1, or (at your option)
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  *
23  * $Id: Bounce.h,v 1.3 2002/03/07 22:52:57 ghostwolf Exp $
24  *
25  */
26
27 #include <sys/types.h> 
28 #include <sys/time.h>
29 #include <sys/wait.h> 
30 #include <sys/socket.h>
31 #include <sys/ioctl.h>
32 #include <arpa/inet.h>
33 #include <netinet/in.h>
34 #include <netdb.h> 
35 #include <ctype.h>
36 #include <time.h>
37 #include <stdio.h>
38 #include <unistd.h>
39 #include <stdarg.h>
40 #include <signal.h>
41 #include <fcntl.h>
42 #include <stdio.h> 
43 #include <stdlib.h> 
44 #include <errno.h> 
45 #include <string.h> 
46 #include <netdb.h> 
47 #include <ctype.h>
48 #include <time.h>
49 #include <list>
50 using std::list; 
51
52 #define DEBUG
53  
54 /*
55  *  "Bounce" Class.
56  */
57
58 class Listener;
59 class Connection;
60 class Bounce
61 {
62 public:
63   list<Listener*> listenerList;      // List of 'Listeners'.
64   list<Connection*> connectionsList; // List of 'Connections'. 
65
66   void bindListeners(); // Binds Listening Ports.
67   void checkSockets();  // Polls all sockets.
68   void recieveNewConnection(Listener*); // Accepts connections.
69 };
70
71 /*
72  *  "Socket" Class.
73  */
74
75 class Socket 
76 {
77 public:
78   int fd;                               // File descriptor.
79   int lastReadSize;                     // Size of last read buffer.
80   struct sockaddr_in address;           // Socket addr_in struct.
81   int connectTo(char*, unsigned short); // Connects the socket.
82   int write(char*, int);                // Writes 'int' bytes from message.
83   int write(char*);                     // Writes strlen(message).
84   char* read();                         // Reads as much as possible into a 4k buffer.
85   Socket();                             // Constructor.
86 };
87
88 /*
89  *  "Listener" Class.
90  */
91
92 class Bounce;
93 class Listener
94 {
95 public:
96   int fd;                 // File descriptor.
97   int remotePort;         // Remote port from config.
98   int localPort;          // Local port for binding.
99   char myVhost[15];       // Vhost to bind locally.
100   char remoteServer[15];  // Remote server to connect to.
101
102   void beginListening();  // Bind listening ports.
103   Socket* handleAccept(); // Accept a new connection.
104 };
105
106 /*
107  *  "Connection" Class.
108  *  Simply a container for a local/remote Socket pair.
109  */
110
111 class Connection 
112
113 public:
114   Socket* localSocket;
115   Socket* remoteSocket;
116 };
117