Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

switchboardserver.h

Go to the documentation of this file.
00001 #ifndef __msn_switchboardserver_h__
00002 #define __msn_switchboardserver_h__
00003 
00004 /*
00005  * switchboardserver.h
00006  * libmsn
00007  *
00008  * Created by Mark Rowe on Mon Mar 22 2004.
00009  * Copyright (c) 2004 Mark Rowe. All rights reserved.
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024  */
00025 
00026 #include <msn/message.h>
00027 #include <msn/authdata.h>
00028 #include <msn/connection.h>
00029 #include <msn/passport.h>
00030 #include <string>
00031 #include <cassert>
00032 
00033 namespace MSN
00034 {
00035     class NotificationServerConnection;
00036     class FileTransferConnection;
00037     class FileTransferInvitation;
00038     class Invitation;
00039     
00042     class SwitchboardServerConnection : public Connection
00043     {
00044         friend class FileTransferConnection;        
00045         friend class FileTransferInvitation;
00046 private:
00047         typedef void (SwitchboardServerConnection::*SwitchboardServerCallback)(std::vector<std::string> & args, int trid, void *);
00048 public:
00049         class AuthData : public ::MSN::AuthData
00050         {
00051 public:
00052             std::string sessionID;
00053             std::string cookie;
00054             const void *tag;
00055             
00056             AuthData(Passport & username_, const std::string & sessionID_, 
00057                      const std::string & cookie_, const void *tag_=NULL) : 
00058                 ::MSN::AuthData(username_), sessionID(sessionID_), cookie(cookie_), tag(tag_) {};
00059             
00060             AuthData(Passport & username_, const void *tag_=NULL) :
00061                 ::MSN::AuthData(username_), sessionID(""), cookie(""), tag(tag_) {};        
00062         };
00063         
00064         SwitchboardServerConnection::AuthData auth;
00065         
00068         std::list<Passport> users;
00069 
00072         std::list<Invitation *> invitationsSent;         
00073         
00076         std::list<Invitation *> invitationsReceived;
00077         
00078         SwitchboardServerConnection(AuthData & auth_, NotificationServerConnection &);
00079         virtual ~SwitchboardServerConnection();
00080         virtual void dispatchCommand(std::vector<std::string> & args);
00081         
00090         Connection *connectionWithSocket(int fd);
00091         
00095         std::list<FileTransferConnection *> & fileTransferConnections() const;
00096         
00099         void addFileTransferConnection(FileTransferConnection *);
00100         
00103         void removeFileTransferConnection(FileTransferConnection *);
00104         
00108         void removeFileTransferConnection(FileTransferInvitation *inv);
00109         
00112         void sendTypingNotification();
00113         
00116         void inviteUser(Passport userName);
00117 
00118         virtual void connect(const std::string & hostname, unsigned int port);
00119         virtual void disconnect();
00120         virtual void sendMessage(const Message *msg);
00121         virtual void sendMessage(const std::string & s);
00122         
00123         FileTransferInvitation *sendFile(const std::string path);
00124 
00128         virtual void addCallback(SwitchboardServerCallback, int trid, void *data);
00129         
00132         virtual void removeCallback(int trid);
00133         
00134         Invitation *invitationWithCookie(const std::string & cookie);
00135         
00136         virtual void socketConnectionCompleted();
00137         
00138         enum SwitchboardServerState
00139         {
00140             SB_DISCONNECTED,
00141             SB_CONNECTING,
00142             SB_CONNECTED,            
00143             SB_WAITING_FOR_USERS,
00144             SB_READY
00145         };
00146         
00147         SwitchboardServerState connectionState() const { return this->_connectionState; };
00148         virtual NotificationServerConnection *myNotificationServer() { return &notificationServer; };        
00149 protected:
00150         virtual void handleIncomingData();
00151         SwitchboardServerState _connectionState;
00152 
00153         void setConnectionState(SwitchboardServerState s) { this->_connectionState = s; };
00154         void assertConnectionStateIs(SwitchboardServerState s) { assert(this->_connectionState == s); };
00155         void assertConnectionStateIsNot(SwitchboardServerState s) { assert(this->_connectionState != s); };
00156         void assertConnectionStateIsAtLeast(SwitchboardServerState s) { assert(this->_connectionState >= s); };
00157 private:
00158         NotificationServerConnection & notificationServer;
00159         std::list<FileTransferConnection *> _fileTransferConnections;
00160         std::map<int, std::pair<SwitchboardServerCallback, void *> > callbacks;        
00161         
00162         static std::map<std::string, void (SwitchboardServerConnection::*)(std::vector<std::string> &)> commandHandlers;
00163         void registerCommandHandlers(); 
00164         void handle_BYE(std::vector<std::string> & args);
00165         void handle_JOI(std::vector<std::string> & args);
00166         void handle_NAK(std::vector<std::string> & args);
00167         void handle_MSG(std::vector<std::string> & args);
00168         
00169         void callback_InviteUsers(std::vector<std::string> & args, int trid, void * data);
00170         void callback_AnsweredCall(std::vector<std::string> & args, int trid, void * data);
00171         
00172         void handleInvite(Passport from, const std::string & friendly, const std::string & mime, const std::string & body);
00173         void handleNewInvite(Passport & from, const std::string & friendly, const std::string & mime, const std::string & body);
00174         friend class Connection;
00175     };
00176 }
00177 #endif

Generated on Sun Feb 6 19:59:40 2005 for libmsn by  doxygen 1.4.1