libmsn: /home/salem/libmsn/tags/libmsn-4.2/msn/notificationserver.h Source File

libmsn 4.2.1

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

/home/salem/libmsn/tags/libmsn-4.2/msn/notificationserver.h

    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  * Refactored by Tiago Salem Herrmann on 08/2007.
    00010  * Copyright (c) 2004 Mark Rowe. All rights reserved.
    00011  * Copyright (c) 2007 Tiago Salem Herrmann. All rights reserved
    00012  *
    00013  * This program is free software; you can redistribute it and/or modify
    00014  * it under the terms of the GNU General Public License as published by
    00015  * the Free Software Foundation; either version 2 of the License, or
    00016  * (at your option) any later version.
    00017  *
    00018  * This program is distributed in the hope that it will be useful,
    00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00021  * GNU General Public License for more details.
    00022  *
    00023  * You should have received a copy of the GNU General Public License
    00024  * along with this program; if not, write to the Free Software
    00025  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00026  */
    00027
    00028 #include <msn/connection.h>
    00029 #include <msn/authdata.h>
    00030 #include <msn/errorcodes.h>
    00031 #include <msn/buddy.h>
    00032 #include <msn/passport.h>
    00033 #include <stdexcept>
    00034 #include <msn/externals.h>
    00035 #include <msn/msnobject.h>
    00036 #include <msn/soap.h>
    00037 #include <cassert>
    00038 #include <sys/types.h>
    00039
    00040 #include "libmsn_export.h"
    00041
    00042 #ifdef _WIN32
    00043 typedef unsigned uint;
    00044 #endif
    00045
    00046 namespace MSN
    00047 {
    00048     class SwitchboardServerConnection;
    00049
    00052     class LIBMSN_EXPORT ListSyncInfo
    00053     {
    00054 public:
    00057         enum SyncProgress
    00058         {
    00059             LST_AB = 1,
    00060             LST_AL = 2,
    00061             LST_BL = 4,
    00062             LST_RL = 8,
    00063             LST_PL = 16,
    00064             COMPLETE_BLP = 32
    00065         };
    00066
    00067
    00071         enum PrivacySetting
    00072         {
    00073             ALLOW = 'A',
    00074             BLOCK = 'B'
    00075         };
    00076
    00079         enum NewReverseListEntryAction
    00080         {
    00081             PROMPT = 'A',
    00082             DONT_PROMPT = 'N'
    00083         };
    00084
    00085
    00088         std::map<std::string, Buddy *> contactList;
    00089
    00090         std::string myDisplayName;
    00091
    00092         std::map<std::string, Group> groups;
    00093
    00096         unsigned int progress;
    00097
    00098         unsigned int usersRemaining, groupsRemaining;
    00099
    00102         std::string lastChange;
    00103
    00109         char privacySetting;
    00110
    00116         char reverseListPrompting;
    00117
    00118         ListSyncInfo(std::string lastChange_) :
    00119             progress(0), lastChange(lastChange_),
    00120             privacySetting(ListSyncInfo::ALLOW), reverseListPrompting(ListSyncInfo::PROMPT) {};
    00121     };
    00122
    00123     // Intermediate steps in connection:
    00124     class LIBMSN_EXPORT connectinfo
    00125     {
    00126 public:
    00127         Passport username;
    00128         std::string password;
    00129         std::string cookie;
    00130
    00131         connectinfo(const Passport & username_, const std::string & password_) : username(username_), password(password_), cookie("") {};
    00132     };
    00133
    00140     class LIBMSN_EXPORT NotificationServerConnection : public Connection
    00141     {
    00142 private:
    00143         typedef void (NotificationServerConnection::*NotificationServerCallback)(std::vector<std::string> & args, int trid, void *);
    00144
    00145         std::string token;
    00146         class AuthData : public ::MSN::AuthData
    00147         {
    00148 public:
    00149             std::string password;
    00150
    00151             AuthData(const Passport & passport_,
    00152                      const std::string & password_) :
    00153                 ::MSN::AuthData(passport_), password(password_) {} ;
    00154         };
    00155         NotificationServerConnection::AuthData auth;
    00156         int synctrid;
    00157
    00158 public:
    00159         MSNObject msnobj;
    00160
    00164         NotificationServerConnection(Passport username, std::string password, Callbacks & cb);
    00165
    00166         virtual ~NotificationServerConnection();
    00167         virtual void dispatchCommand(std::vector<std::string> & args);
    00168
    00172         const std::vector<SwitchboardServerConnection *> & switchboardConnections();
    00173
    00174         /* Add a SwitchboardServerConnection to the list of connections that have
    00175          *  been started from this connection.
    00176          */
    00177         void addSwitchboardConnection(SwitchboardServerConnection *);
    00178
    00179         /* Add the @p Soap object to the list of connections that have
    00180          *  been started from this connection.
    00181          */
    00182         void addSoapConnection(Soap *);
    00183
    00184         /* Remove a SwitchboardServerConnection from the list of connections that have
    00185          *  been started from this connection.
    00186          */
    00187         void removeSwitchboardConnection(SwitchboardServerConnection *);
    00188
    00189         /* Remove the @p Soap object from the list of connections that have
    00190          *  been started from this connection.
    00191          */
    00192         void removeSoapConnection(Soap *);
    00193
    00202         Connection *connectionWithSocket(void *sock);
    00203
    00209         SwitchboardServerConnection *switchboardWithOnlyUser(Passport username);
    00210
    00219         void setCapabilities(uint m_clientId);
    00220
    00221         void disconnectNS();
    00222
    00225         void setState(BuddyStatus state, uint clientID);
    00226
    00229         void setBLP(char setting);
    00230
    00237         void completeConnection(std::map<std::string,int > & allContacts, void *data);
    00238
    00243         void setFriendlyName(std::string friendlyName, bool updateServer = false) throw (std::runtime_error);
    00244
    00248         bool change_DisplayPicture(std::string filename);
    00249
    00252         void setPersonalStatus(personalInfo pInfo);
    00253
    00256         void addToList(MSN::ContactList list, Passport buddyName);
    00257
    00260         void removeFromList(MSN::ContactList list, Passport buddyName);
    00261
    00265         void addToAddressBook(Passport buddyName, std::string displayName);
    00266
    00269         void delFromAddressBook(std::string contactId, std::string passport);
    00270
    00276         void enableContactOnAddressBook(std::string contactId, std::string passport);
    00277
    00280         void disableContactOnAddressBook(std::string contactId, std::string passport);
    00281
    00284         void blockContact(Passport buddyName);
    00285
    00288         void unblockContact(Passport buddyName);
    00289
    00292         void addToGroup(std::string groupId, std::string contactId);
    00293
    00296         void removeFromGroup(std::string groupId, std::string contactId);
    00297
    00300         void addGroup(std::string groupName);
    00301
    00304         void removeGroup(std::string groupId);
    00305
    00308         void renameGroup(std::string groupId, std::string newGroupName);
    00309
    00316         void synchronizeContactList(std::string lastChange="0");
    00317
    00320         void sendPing();
    00321
    00324         void requestSwitchboardConnection(const void *tag);
    00325
    00328         void get_oim(std::string id, bool markAsRead);
    00329
    00332         void delete_oim(std::string id);
    00333
    00336         void send_oim(Soap::OIM oim);
    00337
    00338         void getInboxUrl();
    00339
    00340         /* when we have to send more than 1 ADL command, we need to keep this here to track */
    00341         std::list<std::string> adl_packets;
    00342
    00343         /* Our current Display Name */
    00344         std::string myDisplayName;
    00345
    00346         /* Our passport */
    00347         std::string myPassport;
    00348
    00349         /* Sum of capabilities of the user */
    00350         uint m_clientId;
    00351
    00352         char bplSetting;
    00353
    00354         /* Our IP number reported by notification server */
    00355         std::string server_reported_ip;
    00356
    00357         /* Our TCP source port reported by notification server */
    00358         std::string server_reported_port;
    00359
    00360         std::string login_time;
    00361
    00362         std::string MSPAuth;
    00363
    00364         std::string sid;
    00365
    00366         std::string kv;
    00367
    00368         /* 1 if our email is verified, 0 if not */
    00369         std::string server_email_verified;
    00370
    00371         /* Says if we are direct connected based on server's report */
    00372         bool direct_connection;
    00373
    00374         virtual void connect(const std::string & hostname, unsigned int port);
    00375
    00376         virtual void connect(const std::string & hostname, unsigned int port,
    00377                 const Passport & username,
    00378                 const std::string & password);
    00379
    00380         virtual void disconnect();
    00381
    00382         virtual void addCallback(NotificationServerCallback cb, int trid, void *data);
    00383
    00384         virtual void removeCallback(int trid);
    00385
    00386         virtual void socketConnectionCompleted();
    00387
    00388         enum NotificationServerState
    00389         {
    00390             NS_DISCONNECTED,
    00391             NS_CONNECTING,
    00392             NS_CONNECTED,
    00393             NS_SYNCHRONISING,
    00394             NS_ONLINE
    00395         };
    00396
    00397         connectinfo *info;
    00398         NotificationServerState connectionState() const { return this->_connectionState; };
    00399         Callbacks & externalCallbacks;
    00400         virtual NotificationServerConnection *myNotificationServer() { return this; };
    00401         void gotTickets(Soap & soapConnection, std::vector<MSN::Soap::sitesToAuth> sitesToAuthList);
    00402         void gotLists(Soap &soapConnection);
    00403         void gotAddressBook(Soap &soapConnection);
    00404         void gotOIM(Soap & soapConnection, bool success, std::string id, std::string message);
    00405         void gotOIMLockkey(Soap & soapConnection, std::string lockkey);
    00406         void gotOIMSendConfirmation(Soap & soapConnection, int id, bool sent);
    00407         void gotOIMDeleteConfirmation(Soap & soapConnection, std::string id, bool deleted);
    00408         void gotSoapMailData(Soap & soapConnection, std::string maildata);
    00409         void gotChangeDisplayNameConfirmation(Soap & soapConnection, std::string displayName, bool changed);
    00410         void gotDelContactFromGroupConfirmation(Soap & soapConnection,
    00411                     bool deleted,
    00412                     std::string newVersion,
    00413                     std::string groupId,
    00414                     std::string contactId);
    00415
    00416         void gotAddContactToGroupConfirmation(Soap & soapConnection,
    00417                     bool added,
    00418                     std::string newVersion,
    00419                     std::string groupId,
    00420                     std::string contactId);
    00421
    00422         void gotAddGroupConfirmation(Soap & soapConnection,
    00423                     bool added,
    00424                     std::string newVersion,
    00425                     std::string groupName,
    00426                     std::string groupId);
    00427
    00428         void gotDelGroupConfirmation(Soap & soapConnection,
    00429                     bool removed,
    00430                     std::string newVersion,
    00431                     std::string groupId);
    00432
    00433         void gotRenameGroupConfirmation(Soap & soapConnection,
    00434                     bool renamed,
    00435                     std::string newVersion,
    00436                     std::string newGroupName,
    00437                     std::string groupId);
    00438
    00439         void gotAddContactToAddressBookConfirmation(Soap & soapConnection,
    00440                     bool added,
    00441                     std::string newVersion,
    00442                     std::string passport,
    00443                     std::string displayName,
    00444                     std::string guid);
    00445
    00446         void gotDelContactFromAddressBookConfirmation(Soap & soapConnection,
    00447                     bool removed,
    00448                     std::string newVersion,
    00449                     std::string contactId,
    00450                     std::string passport);
    00451
    00452         void gotEnableContactOnAddressBookConfirmation(Soap & soapConnection,
    00453                     bool enabled,
    00454                     std::string newVersion,
    00455                     std::string contactId,
    00456                     std::string passport);
    00457
    00458         void gotDisableContactOnAddressBookConfirmation(Soap & soapConnection,
    00459                     bool disabled,
    00460                     std::string newVersion,
    00461                     std::string contactId,
    00462                     std::string passport);
    00463
    00464         void gotAddContactToListConfirmation(Soap & soapConnection,
    00465                     bool added,
    00466                     std::string newVersion,
    00467                     std::string passport,
    00468                     MSN::ContactList list);
    00469
    00470         void gotDelContactFromListConfirmation(Soap & soapConnection,
    00471                     bool deleted,
    00472                     std::string newVersion,
    00473                     std::string passport,
    00474                     MSN::ContactList list);
    00475
    00476 protected:
    00477         virtual void handleIncomingData();
    00478         NotificationServerState _connectionState;
    00479
    00480         void setConnectionState(NotificationServerState s) { this->_connectionState = s; };
    00481         void assertConnectionStateIs(NotificationServerState s) { assert(this->_connectionState == s); };
    00482         void assertConnectionStateIsNot(NotificationServerState s) { assert(this->_connectionState != s); };
    00483         void assertConnectionStateIsAtLeast(NotificationServerState s) { assert(this->_connectionState >= s); };
    00484 private:
    00485         std::vector<SwitchboardServerConnection *> _switchboardConnections;
    00486         std::vector<Soap *> _SoapConnections;
    00487         std::map<int, std::pair<NotificationServerCallback, void *> > callbacks;
    00488
    00489         ListSyncInfo *listInfo;
    00490
    00491         std::vector<MSN::Soap::sitesToAuth> sitesToAuthList;
    00492         std::vector<MSN::Soap::OIM> SentQueuedOIMs;
    00493         std::vector<std::string> DeletedQueuedOIMs;
    00494
    00495         std::string lockkey;
    00496         bool generatingLockkey;
    00497         bool removingOIM;
    00498
    00499         void sendQueuedOIMs();
    00500
    00501         // mdi value got by tweener
    00502         std::string mdi;
    00503
    00504         virtual void disconnectForTransfer();
    00505
    00506         static std::map<std::string, void (NotificationServerConnection::*)(std::vector<std::string> &)> commandHandlers;
    00507         static std::map<std::string, void (NotificationServerConnection::*)(std::vector<std::string> &, std::string, std::string)> messageHandlers;
    00508
    00509         void registerHandlers();
    00510         void handle_OUT(std::vector<std::string> & args);
    00511         void handle_RML(std::vector<std::string> & args);
    00512         void handle_BLP(std::vector<std::string> & args);
    00513         void handle_CHG(std::vector<std::string> & args);
    00514         void handle_CHL(std::vector<std::string> & args);
    00515         void handle_ILN(std::vector<std::string> & args);
    00516         void handle_NLN(std::vector<std::string> & args);
    00517         void handle_FLN(std::vector<std::string> & args);
    00518         void handle_MSG(std::vector<std::string> & args);
    00519         void handle_RNG(std::vector<std::string> & args);
    00520         void handle_PRP(std::vector<std::string> & args);
    00521         void handle_UBX(std::vector<std::string> & args);
    00522         void handle_GCF(std::vector<std::string> & args);
    00523         void handle_ADL(std::vector<std::string> & args);
    00524         void handle_UBN(std::vector<std::string> & args);
    00525         void handle_FQY(std::vector<std::string> & args);
    00526
    00527         void callback_NegotiateCVR(std::vector<std::string> & args, int trid, void *data);
    00528         void callback_TransferToSwitchboard(std::vector<std::string> & args, int trid, void *data);
    00529         void callback_RequestUSR(std::vector<std::string> & args, int trid, void *data);
    00530         void callback_PassportAuthentication(std::vector<std::string> & args, int trid, void * data);
    00531         void callback_AuthenticationComplete(std::vector<std::string> & args, int trid, void * data);
    00532         void callback_initialBPL(std::vector<std::string> & args, int trid, void *data);
    00533         void callback_URL(std::vector<std::string> & args, int trid, void *data);
    00534
    00535
    00536         void message_initial_email_notification(std::vector<std::string> & args, std::string mime, std::string body);
    00537         void message_email_notification(std::vector<std::string> & args, std::string mime, std::string body);
    00538         void message_msmsgsprofile(std::vector<std::string> & args, std::string mime, std::string body);
    00539         void message_initialmdatanotification(std::vector<std::string> & args, std::string mime, std::string body);
    00540         void message_oimnotification(std::vector<std::string> & args, std::string mime, std::string body);
    00541
    00542         void gotMailData(std::string maildata);
    00543
    00544     };
    00545
    00546 }
    00547
    00548
    00549 #endif

All Classes Namespaces Functions Variables Enumerations Enumerator