00001 #ifndef __msn_connection_h__
00002 #define __msn_connection_h__
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <string>
00027 #include <list>
00028 #include <vector>
00029 #include <map>
00030 #include <msn/sstream_fix.h>
00031 #include <stdexcept>
00032
00033 namespace MSN
00034 {
00035 class callback;
00036 class Message;
00037 class Passport;
00038 class NotificationServerConnection;
00039
00049 class Connection
00050 {
00051 public:
00058 int sock;
00059
00067 bool connected;
00068
00069 protected:
00072 int trID;
00073
00074 std::string readBuffer;
00075 public:
00076 void * user_data;
00077
00078 Connection();
00079 virtual ~Connection();
00080
00085 virtual void dispatchCommand(std::vector<std::string> & args) = 0;
00086
00091 std::vector<std::string> getLine();
00092
00093 bool isWholeLineAvailable();
00094 bool bytesAvailable();
00095
00099 virtual size_t write(std::string s, bool log=true) throw (std::runtime_error);
00100
00110 virtual size_t write(std::ostringstream & s, bool log=true) throw (std::runtime_error);
00111
00114 virtual void connect(const std::string & hostname, unsigned int port) = 0;
00115 virtual void disconnect() = 0;
00116
00126 virtual void dataArrivedOnSocket();
00127
00130 virtual void socketConnectionCompleted();
00131
00132 virtual void socketIsWritable() {};
00133
00136 virtual void errorOnSocket(int errno_);
00142 void showError(int errorCode);
00143
00146 bool isConnected() { return this->connected; };
00147 virtual NotificationServerConnection *myNotificationServer() = 0;
00148
00149 protected:
00156 void handle_MSG(std::vector<std::string> & args);
00157
00158 virtual void handleIncomingData() = 0;
00159 private:
00160 std::string writeBuffer;
00161 static std::map<std::string, void (Connection::*)(std::vector<std::string> &, std::string, std::string)> messageHandlers;
00162 void message_plain(std::vector<std::string> & args, std::string mime, std::string body);
00163 void message_initial_email_notification(std::vector<std::string> & args, std::string mime, std::string body);
00164 void message_email_notification(std::vector<std::string> & args, std::string mime, std::string body);
00165 void message_invitation(std::vector<std::string> & args, std::string mime, std::string body);
00166 void message_typing_user(std::vector<std::string> & args, std::string mime, std::string body);
00167 };
00168 }
00169 #endif