|
jabberd14 1.6.2
|
00001 /* 00002 * Copyrights 00003 * 00004 * Copyright (c) 2008 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 00027 namespace xmppd { 00028 namespace resolver { 00029 00037 class resend_service { 00038 public: 00045 resend_service(xmlnode resend); 00046 00052 bool is_explicit_service() const; 00053 00057 Glib::ustring const& get_service_prefix() const; 00058 00064 xmppd::jabberid get_resend_host() const; 00065 private: 00069 Glib::ustring service; 00070 00074 std::list< std::pair<int, xmppd::jabberid> > resend_hosts; 00075 00081 int weight_sum; 00082 }; 00083 00084 // forward declaration 00085 class resolver; 00086 00094 class resolver_job { 00095 public: 00102 resolver_job(resolver& owner, dpacket dp); 00103 00107 ~resolver_job(); 00108 00115 void add_packet(dpacket dp); 00116 00122 std::list<dpacket> const& get_packets() const; 00123 00129 sigc::connection register_result_callback(sigc::signal<void, resolver_job&>::slot_type const& callback); 00130 00136 Glib::ustring get_result() const; 00137 00143 xmppd::jabberid get_resend_host() const; 00144 00145 00146 private: 00150 Glib::ustring destination; 00151 00155 resolver& owner; 00156 00160 std::list<dpacket> waiting_packets; 00161 00167 std::list<resend_service> resend_services; 00168 00172 std::list<resend_service>::const_iterator current_service; 00173 00179 void start_resolving_service(); 00180 00186 std::list< std::pair<Glib::ustring, Glib::ustring> > providing_hosts; 00187 00191 std::list< std::pair<Glib::ustring, Glib::ustring> >::const_iterator current_providing_host; 00192 00200 void resolve_providing_hosts(); 00201 00207 void resolve_current_providing_host(); 00208 00212 void resolve_current_providing_host_a(); 00213 00217 std::list<sigc::connection> connected_signals; 00218 00222 void on_srv_query_result(xmppd::lwresc::lwresult const& result); 00223 00227 void on_aaaa_query_result(xmppd::lwresc::lwresult const& result); 00228 00232 void on_a_query_result(xmppd::lwresc::lwresult const& result); 00233 00237 std::ostringstream result_buffer; 00238 00242 std::list<sigc::signal<void, resolver_job&> > result_listeners; 00243 00247 time_t timestamp; 00248 00252 long serial; 00253 00257 static long next_serial; 00258 00259 friend std::ostream& operator<<(std::ostream& out, resolver_job& job); 00260 }; 00261 00262 std::ostream& operator<<(std::ostream& out, resolver_job& job); 00263 00271 class resolver : public instance_base { 00272 public: 00279 resolver(instance i, xmlnode x); 00280 00286 std::list<resend_service> const& get_resend_services(); 00287 00293 void send_query(xmppd::lwresc::lwquery const& query); 00294 00298 sigc::connection register_result_callback(uint32_t serial, sigc::signal<void, xmppd::lwresc::lwresult const&>::slot_type const& callback); 00299 00300 private: 00310 void resend_packet(xmlnode pkt, Glib::ustring ips, Glib::ustring to); 00311 00317 void handle_completed_job(resolver_job& job); 00318 00325 result on_stanza_packet(dpacket dp); 00326 00330 result on_route_packet(dpacket dp); 00331 00335 void open_lwresd_socket(); 00336 00347 static void mio_callback(mio m, int state, void* arg, xmlnode x, char* buffer, int bufsz); 00348 00352 void mio_event(mio m, int state, std::string const& buffer); 00353 00357 void mio_event_buffer(mio m, std::string const& buffer); 00358 00362 void mio_event_closed(mio m); 00363 00367 void mio_event_error(mio m); 00368 00372 mio lwresd_socket; 00373 00377 void configurate(); 00378 00382 std::list<resend_service> resend_services; 00383 00389 int queue_timeout; 00390 00394 Glib::ustring lwresd_host; 00395 00399 Glib::ustring lwresd_service; 00400 00404 xmppd::xhash< xmppd::pointer<resolver_job> > pending_jobs; 00405 00412 std::map<uint32_t, std::pair<time_t, sigc::signal<void, xmppd::lwresc::lwresult const&> > > result_listeners; 00413 }; 00414 } 00415 }
1.7.4