|
jabberd14 1.6.2
|
00001 /* 00002 * Copyrights 00003 * 00004 * Copyright (c) 2007 Matthias Wimmer 00005 * 00006 * This file is part of jabberd14. 00007 * 00008 * This software is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU General Public License as 00010 * published by the Free Software Foundation; either version 2 of the 00011 * License, or (at your option) any later version. 00012 * 00013 * This software is distributed in the hope that it will be useful, but 00014 * WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this software; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00021 * 02110-1301, USA. 00022 * 00023 */ 00024 00025 #include <jabberd.h> 00026 #include <sigc++/sigc++.h> 00027 #include <map> 00028 #include <set> 00029 00030 namespace xmppd { 00031 namespace proxy65 { 00032 00033 // forward declaration 00034 class socks5stub; 00035 00039 class connected_sockets { 00040 public: 00051 connected_sockets(socks5stub* socket1, socks5stub* socket2, const std::string& identifier); 00052 00057 ~connected_sockets(); 00058 00064 sigc::signal<void, connected_sockets*>& event_closed() { return closed; } 00065 00071 size_t get_forwarded_traffic() { return forwarded_traffic; } 00072 00078 const std::string& get_identifier() { return identifier; } 00079 private: 00083 std::string identifier; 00084 00088 size_t forwarded_traffic; 00089 00093 mio sockets[2]; 00094 00106 static void mio_event_wrapper(mio m, int state, void *arg, xmlnode unused1, char* buffer, int bufferlen); 00107 00113 void on_closed(int socketindex); 00114 00121 void on_data(int socketindex, const std::string& received_data); 00122 00128 sigc::signal<void, connected_sockets*> closed; 00129 00133 void close_sockets(); 00134 }; 00135 00139 class socks5stub { 00140 public: 00146 socks5stub(mio m); 00147 00151 ~socks5stub(); 00152 00158 sigc::signal<void, socks5stub*>& event_protocol_done() { return protocol_done; } 00159 00165 sigc::signal<void, socks5stub*>& event_disconnected() { return disconnected; } 00166 00172 std::string get_connection_id() { return connection_id; } 00173 00174 private: 00180 sigc::signal<void, socks5stub*> protocol_done; 00181 00187 sigc::signal<void, socks5stub*> disconnected; 00188 00192 enum state { 00193 state_connected, 00194 state_accepted_auth, 00195 state_accepted_connect, 00196 state_error 00197 }; 00198 00202 state current_state; 00203 00207 std::string unprocessed_data; 00208 00214 void on_data(const std::string& received_data); 00215 00219 void on_closed(); 00220 00233 static void mio_event_wrapper(mio m, int state, void *arg, xmlnode unused1, char* buffer, int bufferlen); 00234 00238 mio m; 00239 00249 std::string connection_id; 00250 00254 void close_socket(); 00255 00256 friend class connected_sockets; 00257 }; 00258 00266 class proxy65 : public instance_base { 00267 public: 00274 proxy65(instance i, xmlnode x); 00275 00276 private: 00282 void connecting_connection_disconnected(socks5stub* stub); 00283 00289 void active_connection_disconnected(connected_sockets* conn); 00290 00296 void connecting_connection_protocol_done(socks5stub* stub); 00297 00304 std::map<socks5stub*, time_t> connecting_connections; 00305 00311 std::multimap<std::string, std::pair<socks5stub*, time_t> > waiting_connections; 00312 00316 std::set<connected_sockets*> active_connections; 00317 00323 void connection_accepted(mio m); 00324 00331 result on_iq_stanza(jpacket p); 00332 00339 result iq_disco_info(jpacket p); 00340 00347 result iq_disco_items(jpacket p); 00348 00355 result iq_bytestreams(jpacket p); 00356 00363 result iq_bytestreams_activate(jpacket p); 00364 00375 static void conn_accepted_wrapper(mio m, int state, void *arg, xmlnode unused1, char* unused2, int unused3); 00376 00380 xht std_namespace_prefixes; 00381 }; 00382 } 00383 }
1.7.4