00001
00002
#ifndef KIM_YAHOO_PROTOCOL_H
00003
#define KIM_YAHOO_PROTOCOL_H
00004
00005
00006
#include <vector>
00007
#include <string>
00008
00009
#include "gm/protocol.h"
00010
#include "gm/manager.h"
00011
#include "gm/basenetwork.h"
00012
#include "gm/wrapexpat.h"
00013
00014
namespace GNUMessenger {
00015
00016
#define YAHOO_PROTO_ID 5
00017
#define YAHOO_PACKET_HEADER_SIZE 104
00018
#define YAHOO_PROTOCOL_HEADER "YPNS2.0"
00019
00020
#define YAHOO_SERVICE_LOGON 1
00021
#define YAHOO_SERVICE_LOGOFF 2
00022
#define YAHOO_SERVICE_ISAWAY 3
00023
#define YAHOO_SERVICE_ISBACK 4
00024
#define YAHOO_SERVICE_IDLE 5
00025
#define YAHOO_SERVICE_MESSAGE 6
00026
#define YAHOO_SERVICE_IDACT 7
00027
#define YAHOO_SERVICE_IDDEACT 8
00028
#define YAHOO_SERVICE_MAILSTAT 9
00029
#define YAHOO_SERVICE_USERSTAT 10
00030
#define YAHOO_SERVICE_NEWMAIL 11
00031
#define YAHOO_SERVICE_CHATINVITE 12
00032
#define YAHOO_SERVICE_CALENDAR 13
00033
#define YAHOO_SERVICE_NEWPERSONALMAIL 14
00034
#define YAHOO_SERVICE_NEWCONTACT 15
00035
#define YAHOO_SERVICE_ADDIDENT 16
00036
#define YAHOO_SERVICE_ADDIGNORE 17
00037
#define YAHOO_SERVICE_PING 18
00038
#define YAHOO_SERVICE_GROUPRENAME 19
00039
#define YAHOO_SERVICE_SYSMESSAGE 20
00040
#define YAHOO_SERVICE_PASSTHROUGH2 22
00041
#define YAHOO_SERVICE_CONFINVITE 24
00042
#define YAHOO_SERVICE_CONFLOGON 25
00043
#define YAHOO_SERVICE_CONFDECLINE 26
00044
#define YAHOO_SERVICE_CONFLOGOFF 27
00045
#define YAHOO_SERVICE_CONFADDINVITE 28
00046
#define YAHOO_SERVICE_CONFMSG 29
00047
#define YAHOO_SERVICE_CHATLOGON 30
00048
#define YAHOO_SERVICE_CHATLOGOFF 31
00049
#define YAHOO_SERVICE_CHATMSG 32
00050
#define YAHOO_SERVICE_GAMELOGON 40
00051
#define YAHOO_SERVICE_GAMELOGOFF 41
00052
#define YAHOO_SERVICE_FILETRANSFER 70
00053
00054
class XMLNode;
00055
class YahooProtocol;
00056
00057
class HttpClient
00058 {
00059
public:
00060
typedef map<string,string> httpArgMap;
00061 HttpClient();
00062
void setOwner(YahooProtocol *parent);
00063 ~HttpClient();
00064
void connect(
const string &host,
int port);
00065
void get(
const string &url,
const httpArgMap &args);
00066
void setCookie(
const string &c);
00067
void clearCookie();
00068
static vector<string> lineSplit(
const string &s);
00069
static string urlEncode(
const string &s);
00070 Network *net() {
return m_net;};
00071
private:
00072 YahooProtocol *m_parent;
00073 Network *m_net;
00074
int m_cid;
00075 string m_host;
00076 string m_cookie;
00077 };
00078
00089 class YahooPacket
00090 {
00091
public:
00092
char version[8];
00093
unsigned char len[4];
00094
unsigned char service[4];
00095
00096
00097
00098
unsigned char connection_id[4];
00099
unsigned char magic_id[4];
00100
unsigned char unknown1[4];
00101
00102
unsigned char msgtype[4];
00103
char nick1[36];
00104
char nick2[36];
00105
char content[1];
00106 };
00107
00108
00118 class YahooProtocol:
public Protocol
00119 {
00120
public:
00121
00122
YahooProtocol(
XMLNode &,
ProtocolManager *manager);
00123
virtual ~
YahooProtocol();
00124
00125
const string screenName() {
return ""; };
00126
00127
virtual void update();
00128
00129
virtual void login();
00130
virtual void logout();
00131
virtual bool sendMessage(
const Contact &recipient,
const string &message);
00132
virtual void addBuddy(
const Contact &c);
00133
virtual void delBuddy(
const Contact &c);
00134
virtual void newUser();
00135
virtual void getPubkey();
00136
00137 virtual void reset() {}
00138
00139
virtual void handleData(
Network *n);
00140
virtual void handleData(
Network *n,
const string& buf);
00141
virtual void connectionError(
Network *n,
int error);
00142
virtual void connectedToServer(
Network *n);
00143
protected:
00144
00145
friend class HttpClient;
00146
Network *addNet() {
return Protocol::addNet();};
00147
void removeNet(Network *n) {Protocol::removeNet(n);};
00148
void sendCmd(
int cmd,
const string &data,
int msgtype);
00149
void storeInt(
unsigned char *dest,
unsigned int src);
00150
private:
00151
00152
enum YahooState { S_none=YAHOO_PROTO_ID*65536, S_getCookie, S_connect,
00153 S_getConfig, S_logon };
00154 Network *m_net;
00155 YahooState m_istate;
00156 string m_login_cookie;
00157
unsigned int m_magicId;
00158 HttpClient httpClient;
00159
00160 };
00161
00162 }
00163
00164
#endif