00001 /*************************************************************************** 00002 * Copyright (C) 2005 by yunfan * 00003 * yunfan_zg@163.com * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 * This program is distributed in the hope that it will be useful, * 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00013 * GNU General Public License for more details. * 00014 * * 00015 * You should have received a copy of the GNU General Public License * 00016 * along with this program; if not, write to the * 00017 * Free Software Foundation, Inc., * 00018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00019 ***************************************************************************/ 00020 00021 #ifndef LIBEVAGROUP_H 00022 #define LIBEVAGROUP_H 00023 00024 #include "evapacket.h" 00025 #ifndef WIN32 00026 #include <inttypes.h> 00027 #endif 00028 #include <list> 00029 #include <string> 00030 #include <map> 00031 00032 // This file is for all group related operations 00033 00034 // can be used to upload or download group names, default is download 00035 class GroupNameOpPacket : public OutPacket { 00036 public: 00037 GroupNameOpPacket(); 00038 GroupNameOpPacket(const char cmdType); 00039 GroupNameOpPacket(const GroupNameOpPacket &rhs); 00040 virtual ~GroupNameOpPacket() {}; 00041 00042 virtual OutPacket* copy() { return new GroupNameOpPacket(*this); } 00043 GroupNameOpPacket &operator=(const GroupNameOpPacket &rhs); 00044 00045 const std::list<std::string> getGroups() const { return groups; } 00046 const char getType() const { return type; } 00047 00048 void setGroups(const std::list<std::string> &l) { groups = l; } 00049 void setType(const char type); 00050 protected: 00051 virtual int putBody(unsigned char* buf); 00052 private: 00053 std::list<std::string> groups; 00054 char type; 00055 }; 00056 00057 class GroupNameOpReplyPacket : public InPacket 00058 { 00059 public: 00060 GroupNameOpReplyPacket() {}; 00061 GroupNameOpReplyPacket(unsigned char* buf, int len); 00062 GroupNameOpReplyPacket(const GroupNameOpReplyPacket &rhs); 00063 virtual ~GroupNameOpReplyPacket() {}; 00064 00065 InPacket *copy() { return new GroupNameOpReplyPacket(*this); } 00066 GroupNameOpReplyPacket &operator=( const GroupNameOpReplyPacket &rhs ); 00067 00068 const std::list<std::string> getGroupNames() const { return groupNames; } 00069 const char getType() const { return type; } 00070 const bool isDownloadReply() const ;// otherwise, upload reply 00071 protected: 00072 virtual void parseBody(); 00073 private: 00074 std::list<std::string> groupNames; 00075 char type; 00076 }; 00077 00078 class DownloadFriendEntry 00079 { 00080 public: 00081 DownloadFriendEntry() {}; 00082 DownloadFriendEntry(const char *buf); 00083 DownloadFriendEntry(const DownloadFriendEntry &rhs); 00084 ~DownloadFriendEntry() {}; 00085 00086 DownloadFriendEntry &operator=(const DownloadFriendEntry &rhs); 00087 00088 const int readData(const char *buf); 00089 const int numberOfBytesRead() const { return 6; } 00090 00091 const int getQQ() const { return qqNum; } 00092 const char getType() const { return type; } 00093 const uint8_t getGroupID() const { return groupID; } 00094 00095 const bool isQun() const ; 00096 private: 00097 int qqNum; 00098 char type; 00099 uint8_t groupID; 00100 }; 00101 00102 class DownloadGroupFriendPacket : public OutPacket 00103 { 00104 public: 00105 DownloadGroupFriendPacket(); 00106 DownloadGroupFriendPacket(const int start); 00107 DownloadGroupFriendPacket( const DownloadGroupFriendPacket &rhs); 00108 00109 virtual ~DownloadGroupFriendPacket() {}; 00110 00111 DownloadGroupFriendPacket &operator=(const DownloadGroupFriendPacket &rhs); 00112 virtual OutPacket * copy() { return new DownloadGroupFriendPacket(*this); } 00113 00114 void setStartID(const int start) { startID = start; } 00115 const int getStartID() const { return startID; } 00116 protected: 00117 virtual int putBody(unsigned char* buf); 00118 private: 00119 int startID; 00120 }; 00121 00122 class DownloadGroupFriendReplyPacket : public InPacket 00123 { 00124 public: 00125 DownloadGroupFriendReplyPacket() {} 00126 DownloadGroupFriendReplyPacket(unsigned char* buf, int len); 00127 DownloadGroupFriendReplyPacket( const DownloadGroupFriendReplyPacket &rhs); 00128 00129 virtual ~DownloadGroupFriendReplyPacket() {}; 00130 00131 InPacket *copy() { return new DownloadGroupFriendReplyPacket( *this); } 00132 DownloadGroupFriendReplyPacket &operator=( const DownloadGroupFriendReplyPacket &rhs); 00133 virtual void parseBody(); 00134 00135 const int getNextStartID() const { return nextStartID; } 00136 const std::list<DownloadFriendEntry> &getGroupedFriends() const { return friends; } 00137 private: 00138 int nextStartID; 00139 std::list<DownloadFriendEntry> friends; 00140 00141 }; 00142 00143 class UploadGroupFriendPacket : public OutPacket 00144 { 00145 public: 00146 UploadGroupFriendPacket(); 00147 UploadGroupFriendPacket(const UploadGroupFriendPacket &rhs); 00148 00149 virtual ~UploadGroupFriendPacket(); 00150 00151 OutPacket *copy() { return new UploadGroupFriendPacket(*this); } 00152 UploadGroupFriendPacket &operator=( const UploadGroupFriendPacket &rhs); 00153 00154 // note that the groups do not include Anonymous and Black List groups. 00155 void setGroupedFriends(std::map<int, int> &list) { privateList = list; } 00156 const std::map<int, int> &getGroupedFriends() const { return privateList; } 00157 protected: 00158 virtual int putBody(unsigned char* buf); 00159 private: 00160 std::map<int, int> privateList; // qq number, gourp index 00161 }; 00162 00163 class UploadGroupFriendReplyPacket : public InPacket 00164 { 00165 public: 00166 UploadGroupFriendReplyPacket() {} 00167 UploadGroupFriendReplyPacket(unsigned char* buf, int len); 00168 UploadGroupFriendReplyPacket(const UploadGroupFriendReplyPacket &rhs); 00169 00170 virtual ~UploadGroupFriendReplyPacket(); 00171 00172 InPacket *copy() { return new UploadGroupFriendReplyPacket(*this); } 00173 UploadGroupFriendReplyPacket &operator=(const UploadGroupFriendReplyPacket &rhs); 00174 00175 virtual void parseBody(); 00176 00177 const bool uploadOk() { return replyCode == 0; } 00178 const uint8_t getReplyCode() const { return replyCode; } 00179 private: 00180 uint8_t replyCode; 00181 }; 00182 00183 #endif 00184
1.4.4