ircproxy The Ultimate Cyborg |
00001 // ircproxy -- An IRC bouncer. 00002 // 00003 //! @file UserAnswer.cc 00004 //! @brief This file contains the implementation of the UserAnswer events related code. 00005 // 00006 // Copyright (C) 2006, 2007 by 00007 // 00008 // Carlo Wood, Run on IRC <carlo@alinoe.com> 00009 // RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt 00010 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61 00011 // 00012 // This file may be distributed under the terms of the Q Public License 00013 // version 1.0 as appearing in the file LICENSE.QPL included in the 00014 // packaging of this file. 00015 00016 #ifndef USE_PCH 00017 #include "sys.h" 00018 #include "debug.h" 00019 #endif 00020 00021 #include "UserAnswer.h" 00022 #include "QuestionTarget.h" 00023 #include "ClientSession.h" 00024 #include "Identity.h" 00025 00026 //! Convert question index \a number into the channel name it belongs to. 00027 char const* question_target_name(question_nt number) 00028 { 00029 switch(number) 00030 { 00031 case network_domain_question: 00032 return "&NetworkDomain"; 00033 case server_port_question: 00034 return "&WhatServerPort"; 00035 case no_related_question: 00036 DoutFatal(dc::core, "Calling question_target_name(no_related_question)"); 00037 } 00038 return NULL; // Suppress compiler warning. 00039 } 00040 00041 //! Construct a UserAnswerEventRequestBase. 00042 UserAnswerEventRequestBase::UserAnswerEventRequestBase(event_client_tracker_ct* event_client_tracker, 00043 event_request_data_ct request_data) : 00044 event_request_base_tct<UserAnswerEventType>(event_client_tracker), M_request_data(request_data) 00045 { 00046 Dout(dc::objects, "Constructing UserAnswerEventRequestBase(" << request_data << ")"); 00047 00048 ClientSession& client_session(M_request_data.client_session()); 00049 00050 std::string target_name = question_target_name(request_data.user_question()->number()); 00051 ClientSession::private_targets_type::iterator priv_iter = client_session.private_targets().find(target_name); 00052 if (priv_iter != client_session.private_targets().end()) 00053 M_target = priv_iter->second; 00054 else 00055 { 00056 M_target.reset(new QuestionTarget(client_session, target_name, client_session.identity().private_network())); 00057 client_session.add_private_target(M_target); 00058 } 00059 boost::static_pointer_cast<QuestionTarget>(M_target)->set_user_question(request_data.user_question()); 00060 boost::static_pointer_cast<QuestionTarget>(M_target)->create_channel_and_ask_question(); 00061 } 00062 00063 //! Destruct UserAnswerEventRequestBase. 00064 UserAnswerEventRequestBase::~UserAnswerEventRequestBase() 00065 { 00066 Dout(dc::objects, "Destructing UserAnswerEventRequestBase " << *this); 00067 boost::static_pointer_cast<QuestionTarget>(M_target)->reset_user_question(); 00068 } 00069 00070 bool UserAnswer::is_match(boost::shared_ptr<Target> const& target) const 00071 { 00072 return &M_client_session.identity().network() == &target->network() && 00073 M_target_name == target->in_name(M_client_session); 00074 }
Copyright © 2005-2007 Carlo Wood. All rights reserved. |
---|