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

notificationserver.h

Go to the documentation of this file.
00001 #ifndef __msn_notificationserver_h__
00002 #define __msn_notificationserver_h__
00003 
00004 /*
00005  * notificationserver.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/connection.h>
00027 #include <msn/authdata.h>
00028 #include <msn/errorcodes.h>
00029 #include <msn/buddy.h>
00030 #include <msn/passport.h>
00031 #include <stdexcept>
00032 #include <msn/externals.h>
00033 
00034 namespace MSN
00035 {    
00036     class SwitchboardServerConnection;
00037     
00040     class ListSyncInfo
00041     {
00042 public:
00045         enum SyncProgress
00046         {
00047             LST_FL = 1,        
00048             LST_AL = 2,        
00049             LST_BL = 4,        
00050             LST_RL = 8,        
00051             COMPLETE_BLP = 16, 
00052             COMPLETE_GTC = 32  
00053         };
00054         
00055         
00059         enum PrivacySetting
00060         {
00061             ALLOW = 'A',
00062             BLOCK = 'B'
00063         };
00064         
00067         enum NewReverseListEntryAction
00068         {
00069             PROMPT = 'A',
00070             DONT_PROMPT = 'N'
00071         };
00072 
00075         std::list<Buddy> forwardList;
00076         
00079         std::list<Buddy> reverseList;
00080         
00083         std::list<Buddy> allowList;
00084         
00087         std::list<Buddy> blockList;
00088         
00089         std::map<int, Group> groups;
00090         
00093         unsigned int progress;
00094         
00095         unsigned int usersRemaining, groupsRemaining;
00096         
00099         unsigned int listVersion;
00100         
00106         char privacySetting;
00107         
00113         char reverseListPrompting;
00114         
00115         ListSyncInfo(int listVersion_) : 
00116             progress(0), listVersion(listVersion_), 
00117             privacySetting(ListSyncInfo::ALLOW), reverseListPrompting(ListSyncInfo::PROMPT) {};
00118     };
00119     
00120     // Intermediate steps in connection:
00121     class connectinfo // : public callback_data
00122     {
00123 public:
00124         Passport username;
00125         std::string password;
00126         std::string cookie;
00127         
00128         connectinfo(const Passport & username_, const std::string & password_) : username(username_), password(password_), cookie("") {};
00129     };    
00130         
00137     class NotificationServerConnection : public Connection
00138     {
00139 private:
00140         typedef void (NotificationServerConnection::*NotificationServerCallback)(std::vector<std::string> & args, int trid, void *);
00141         
00142         class AuthData : public ::MSN::AuthData
00143         {
00144 public:
00145             std::string password;
00146             
00147             AuthData(const Passport & passport_,
00148                      const std::string & password_) : 
00149                 ::MSN::AuthData(passport_), password(password_) {} ;
00150         };
00151         
00152         NotificationServerConnection::AuthData auth;
00153         int synctrid;
00154 
00155 public:
00158         NotificationServerConnection(AuthData & auth_, Callbacks & cb);
00159         
00163         NotificationServerConnection(Passport username, std::string password, Callbacks & cb);
00164         
00166         NotificationServerConnection(Callbacks & cb);
00167         
00168         virtual ~NotificationServerConnection();
00169         virtual void dispatchCommand(std::vector<std::string> & args);
00170         
00174         const std::list<SwitchboardServerConnection *> & switchboardConnections();
00175         
00179         void addSwitchboardConnection(SwitchboardServerConnection *);
00180         
00184         void removeSwitchboardConnection(SwitchboardServerConnection *);
00185         
00194         Connection *connectionWithSocket(int fd);
00195         
00201         SwitchboardServerConnection *switchboardWithOnlyUser(Passport username);
00202         
00211         void setState(BuddyStatus state);
00212         
00213         void setBLP(char setting);
00214         void setGTC(char setting);
00215         
00220         void setFriendlyName(std::string friendlyName) throw (std::runtime_error);
00221         
00224         void addToList(std::string list, Passport buddyName);
00225         
00228         void removeFromList(std::string list, Passport buddyName);
00229         
00230         void addToGroup(Passport, int groupID);
00231         void removeFromGroup(Passport buddyName, int groupID);
00232         
00233         void addGroup(std::string groupName);
00234         void removeGroup(int groupId);
00235         void renameGroup(int groupId, std::string newGroupName);
00236         
00243         void synchronizeLists(int version=0);
00244         
00247         void sendPing();
00248         
00252         //        void requestSwitchboardConnection(Passport username, Message *msg, void *tag);
00253         
00256         void requestSwitchboardConnection(const void *tag);
00259         void checkReverseList(ListSyncInfo *);
00260 
00261         virtual void connect(const std::string & hostname, unsigned int port);
00262         virtual void connect(const std::string & hostname, unsigned int port, const Passport & username,  const std::string & password);
00263         virtual void disconnect();
00264         
00269         virtual void addCallback(NotificationServerCallback cb, int trid, void *data);
00270         
00273         virtual void removeCallback(int trid);
00274         
00275         virtual void socketConnectionCompleted();
00276         
00277         
00278         enum NotificationServerState
00279         {
00280             NS_DISCONNECTED,
00281             NS_CONNECTING,
00282             NS_CONNECTED,
00283             NS_SYNCHRONISING,
00284             NS_ONLINE
00285         };
00286 
00287         NotificationServerState connectionState() const { return this->_connectionState; };
00288         Callbacks & externalCallbacks;
00289         virtual NotificationServerConnection *myNotificationServer() { return this; };        
00290 protected:
00291         virtual void handleIncomingData();
00292         NotificationServerState _connectionState;
00293         
00294         void setConnectionState(NotificationServerState s) { this->_connectionState = s; };
00295         void assertConnectionStateIs(NotificationServerState s) { assert(this->_connectionState == s); };
00296         void assertConnectionStateIsNot(NotificationServerState s) { assert(this->_connectionState != s); };
00297         void assertConnectionStateIsAtLeast(NotificationServerState s) { assert(this->_connectionState >= s); };        
00298 private:
00299         std::list<SwitchboardServerConnection *> _switchboardConnections;
00300         std::map<int, std::pair<NotificationServerCallback, void *> > callbacks;
00301         
00302         virtual void disconnectForTransfer();        
00303             
00304         static std::map<std::string, void (NotificationServerConnection::*)(std::vector<std::string> &)> commandHandlers;
00305         void registerCommandHandlers();
00306         void handle_OUT(std::vector<std::string> & args);
00307         void handle_ADD(std::vector<std::string> & args);
00308         void handle_REM(std::vector<std::string> & args);
00309         void handle_BLP(std::vector<std::string> & args);
00310         void handle_GTC(std::vector<std::string> & args);
00311         void handle_REA(std::vector<std::string> & args);
00312         void handle_CHG(std::vector<std::string> & args);
00313         void handle_CHL(std::vector<std::string> & args);
00314         void handle_ILN(std::vector<std::string> & args);
00315         void handle_NLN(std::vector<std::string> & args);
00316         void handle_FLN(std::vector<std::string> & args);
00317         void handle_MSG(std::vector<std::string> & args);
00318         void handle_RNG(std::vector<std::string> & args);
00319         void handle_ADG(std::vector<std::string> & args);
00320         void handle_RMG(std::vector<std::string> & args);
00321         void handle_REG(std::vector<std::string> & args);
00322         
00323         void callback_SyncData(std::vector<std::string> & args, int trid, void *data) throw (std::runtime_error);
00324         void callback_NegotiateCVR(std::vector<std::string> & args, int trid, void *data);
00325         void callback_TransferToSwitchboard(std::vector<std::string> & args, int trid, void *data);
00326         void callback_RequestUSR(std::vector<std::string> & args, int trid, void *data);
00327         void callback_PassportAuthentication(std::vector<std::string> & args, int trid, void * data);        
00328         void callback_AuthenticationComplete(std::vector<std::string> & args, int trid, void * data);
00329     };
00330     
00331 }
00332 
00333 
00334 #endif

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