Files
@ f2d21db482c7
Branch filter:
Location: libtransport.git/include/transport/networkplugin.h - annotation
f2d21db482c7
14.8 KiB
text/plain
Merge branch 'master' of https://github.com/hanzz/libtransport
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | 1105d3f1e37a 1105d3f1e37a 1105d3f1e37a 1105d3f1e37a 1105d3f1e37a 1105d3f1e37a 1105d3f1e37a 1105d3f1e37a 1105d3f1e37a 1105d3f1e37a 1105d3f1e37a 1105d3f1e37a 1105d3f1e37a 1105d3f1e37a 1105d3f1e37a 1105d3f1e37a 1105d3f1e37a 1105d3f1e37a 1105d3f1e37a 1105d3f1e37a 1105d3f1e37a 1105d3f1e37a 1105d3f1e37a cbcf2f145298 cbcf2f145298 cbcf2f145298 1105d3f1e37a 1105d3f1e37a 1105d3f1e37a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 1105d3f1e37a 1105d3f1e37a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a cbcf2f145298 1105d3f1e37a 632afeabe03a 1105d3f1e37a 1105d3f1e37a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 1105d3f1e37a 6b81ff06d6c5 8ee031044843 1105d3f1e37a 1105d3f1e37a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a cbcf2f145298 cbcf2f145298 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 62fcb141926d 62fcb141926d 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 8720eb96789d bc585576a9ab 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a a1eba9bedbbd a1eba9bedbbd 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a a7f77b72a8e1 a7f77b72a8e1 632afeabe03a 632afeabe03a 632afeabe03a bf5cc016f827 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a bf5cc016f827 bf5cc016f827 632afeabe03a 632afeabe03a 632afeabe03a bf5cc016f827 bf5cc016f827 632afeabe03a 632afeabe03a 632afeabe03a b0bcade44c94 b0bcade44c94 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 67c1817031d3 67c1817031d3 7b692e883783 b55ba07e93d3 7b692e883783 715efadbdf98 715efadbdf98 632afeabe03a 48c2ae07de16 48c2ae07de16 48c2ae07de16 48c2ae07de16 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 632afeabe03a 1105d3f1e37a 48c2ae07de16 48c2ae07de16 48c2ae07de16 48c2ae07de16 48c2ae07de16 1105d3f1e37a 48c2ae07de16 48c2ae07de16 48c2ae07de16 48c2ae07de16 48c2ae07de16 48c2ae07de16 a9ccbdc50107 48c2ae07de16 48c2ae07de16 48c2ae07de16 48c2ae07de16 48c2ae07de16 48c2ae07de16 48c2ae07de16 48c2ae07de16 48c2ae07de16 48c2ae07de16 48c2ae07de16 48c2ae07de16 48c2ae07de16 48c2ae07de16 a7f77b72a8e1 48c2ae07de16 48c2ae07de16 48c2ae07de16 48c2ae07de16 48c2ae07de16 ca76287f4d9c 48c2ae07de16 48c2ae07de16 1ebe5535c4f3 2c526db0f32e bdc94b104270 6b81ff06d6c5 6b81ff06d6c5 8ee031044843 d699f6614f22 d699f6614f22 d699f6614f22 d699f6614f22 fb420ef1254e 1bf1343ac5e3 7b692e883783 46f5c51d006f 260262c39300 260262c39300 7b692e883783 cbcf2f145298 cbcf2f145298 4503fd1dede8 2626035bc26c 2626035bc26c 1105d3f1e37a 1105d3f1e37a 1105d3f1e37a 1105d3f1e37a bdc94b104270 b62274f1ddda 1ebe5535c4f3 2c526db0f32e a7f77b72a8e1 a6781df77f76 ed6b548f485d cbcf2f145298 fb420ef1254e 7b692e883783 46f5c51d006f 260262c39300 260262c39300 1105d3f1e37a 1105d3f1e37a e8b61aa9b6fd 330ecc6dd45f cbcf2f145298 cbcf2f145298 98687145b02a 330ecc6dd45f 1105d3f1e37a 1105d3f1e37a 1105d3f1e37a 1105d3f1e37a | /**
* libtransport -- C++ library for easy XMPP Transports development
*
* Copyright (C) 2011, Jan Kaluza <hanzz.k@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*/
#pragma once
#include <time.h>
#include "transport/protocol.pb.h"
// #include "conversation.h"
#include <iostream>
namespace Transport {
/// Represents Spectrum2 legacy network plugin.
/// This class is base class for all C++ legacy network plugins. It provides a way to connect
/// Spectrum2 NetworkPluginServer and allows to use high-level API for legacy network plugins
/// development.
class NetworkPlugin {
public:
/// Creates new NetworkPlugin and connects the Spectrum2 NetworkPluginServer.
/// \param loop Event loop.
/// \param host Host where Spectrum2 NetworkPluginServer runs.
/// \param port Port.
NetworkPlugin();
/// Destructor.
virtual ~NetworkPlugin();
/// Call this function when legacy network buddy changed.
/// \param user XMPP JID of user for which this event occurs. You can get it from NetworkPlugin::handleLoginRequest(). (eg. "user%gmail.com@xmpp.domain.tld")
/// \param buddyName Name of legacy network buddy. (eg. "user2@gmail.com")
/// \param alias Alias of legacy network buddy. If empty, then it's not changed on XMPP side.
/// \param groups Groups in which buddy currently is. If empty, then it's not changed on XMPP side.
/// \param status Status of this buddy.
/// \param statusMessage Status message of this buddy.
/// \param iconHash MD5 hash of buddy icon. Empty if none buddy icon.
/// \param blocked True if this buddy is blocked in privacy lists in legacy network.
void handleBuddyChanged(const std::string &user, const std::string &buddyName, const std::string &alias,
const std::vector<std::string> &groups, pbnetwork::StatusType status, const std::string &statusMessage = "", const std::string &iconHash = "",
bool blocked = false
);
/// Call this function when participant in room changed.
/// \param user XMPP JID of user for which this event occurs. You can get it from NetworkPlugin::handleLoginRequest(). (eg. "user%gmail.com@xmpp.domain.tld")
/// \param nickname Nickname of participant. If participant renamed, this is old name of participant. (eg. "HanzZ")
/// \param room Room in which participant changed. (eg. #spectrum)
/// \param flags Participant flags.
/// \param status Current status of participant. Swift::StatusShow::None if participant left the room.
/// \param statusMessage Current status message of participant.
/// \param newname New name of participant if he changed the nickname. Otherwise empty.
void handleParticipantChanged(const std::string &user, const std::string &nickname, const std::string &room, int flags,
pbnetwork::StatusType = pbnetwork::STATUS_NONE, const std::string &statusMessage = "", const std::string &newname = "");
/// Call this function when user disconnected the legacy network because of some legacy network error.
/// \param user XMPP JID of user for which this event occurs. You can get it from NetworkPlugin::handleLoginRequest(). (eg. "user%gmail.com@xmpp.domain.tld")
/// \param error Reserved for future use, currently keep it on 0.
/// \param message XMPP message which is sent to XMPP user.
void handleDisconnected(const std::string &user, int error = 0, const std::string &message = "");
/// Call this function when user connected the legacy network and is logged in.
/// \param user XMPP JID of user for which this event occurs. You can get it from NetworkPlugin::handleLoginRequest(). (eg. "user%gmail.com@xmpp.domain.tld")
void handleConnected(const std::string &user);
/// Call this function when new message is received from legacy network for user.
/// \param user XMPP JID of user for which this event occurs. You can get it from NetworkPlugin::handleLoginRequest(). (eg. "user%gmail.com@xmpp.domain.tld")
/// \param legacyName Name of legacy network buddy or name of room. (eg. "user2@gmail.com")
/// \param message Plain text message.
/// \param nickname Nickname of buddy in room. Empty if it's normal chat message.
/// \param xhtml XHTML message.
void handleMessage(const std::string &user, const std::string &legacyName, const std::string &message, const std::string &nickname = "", const std::string &xhtml = "");
/// Call this function when subject in room changed.
/// \param user XMPP JID of user for which this event occurs. You can get it from NetworkPlugin::handleLoginRequest(). (eg. "user%gmail.com@xmpp.domain.tld")
/// \param legacyName Name of room. (eg. "#spectrum")
/// \param message Subject message.
/// \param nickname Nickname of user who changed subject.
void handleSubject(const std::string &user, const std::string &legacyName, const std::string &message, const std::string &nickname = "");
/// Call this function XMPP user's nickname changed.
/// \param user XMPP JID of user for which this event occurs. You can get it from NetworkPlugin::handleLoginRequest(). (eg. "user%gmail.com@xmpp.domain.tld")
/// \param room Room in which participant changed. (eg. #spectrum)
/// \param nickname New nickname.
void handleRoomNicknameChanged(const std::string &user, const std::string &room, const std::string &nickname);
/// Call this function when requested VCard arrived.
/// \param user XMPP JID of user for which this event occurs. You can get it from NetworkPlugin::handleLoginRequest(). (eg. "user%gmail.com@xmpp.domain.tld")
/// \param id VCard ID.
/// \param legacyName Name of legacy network buddy. (eg. "user2@gmail.com")
/// \param fullName Name of legacy network buddy. (eg. "Monty Python")
/// \param nickname Nickname.
/// \param photo Raw photo.
void handleVCard(const std::string &user, unsigned int id, const std::string &legacyName, const std::string &fullName, const std::string &nickname, const std::string &photo);
/// Call this function when buddy started typing.
/// \param user XMPP JID of user for which this event occurs. You can get it from NetworkPlugin::handleLoginRequest(). (eg. "user%gmail.com@xmpp.domain.tld")
/// \param buddyName Name of legacy network buddy. (eg. "user2@gmail.com")
void handleBuddyTyping(const std::string &user, const std::string &buddyName);
/// Call this function when buddy typed, but is not typing anymore.
/// \param user XMPP JID of user for which this event occurs. You can get it from NetworkPlugin::handleLoginRequest(). (eg. "user%gmail.com@xmpp.domain.tld")
/// \param buddyName Name of legacy network buddy. (eg. "user2@gmail.com")
void handleBuddyTyped(const std::string &user, const std::string &buddyName);
/// Call this function when buddy has been typing, but paused for a while.
/// \param user XMPP JID of user for which this event occurs. You can get it from NetworkPlugin::handleLoginRequest(). (eg. "user%gmail.com@xmpp.domain.tld")
/// \param buddyName Name of legacy network buddy. (eg. "user2@gmail.com")
void handleBuddyStoppedTyping(const std::string &user, const std::string &buddyName);
/// Call this function when new authorization request arrived form legacy network
/// \param user XMPP JID of user for which this event occurs. You can get it from NetworkPlugin::handleLoginRequest(). (eg. "user%gmail.com@xmpp.domain.tld")
/// \param buddyName Name of legacy network buddy. (eg. "user2@gmail.com")
void handleAuthorization(const std::string &user, const std::string &buddyName);
/// Call this function when attention request arrived from legacy network.
/// \param user XMPP JID of user for which this event occurs. You can get it from NetworkPlugin::handleLoginRequest(). (eg. "user%gmail.com@xmpp.domain.tld")
/// \param buddyName Name of legacy network buddy. (eg. "user2@gmail.com")
/// \param message Message.
void handleAttention(const std::string &user, const std::string &buddyName, const std::string &message);
void handleFTStart(const std::string &user, const std::string &buddyName, const std::string fileName, unsigned long size);
void handleFTFinish(const std::string &user, const std::string &buddyName, const std::string fileName, unsigned long size, unsigned long ftid);
void handleFTData(unsigned long ftID, const std::string &data);
/// Called when XMPP user wants to connect legacy network.
/// You should connect him to legacy network and call handleConnected or handleDisconnected function later.
/// \param user XMPP JID of user for which this event occurs.
/// \param legacyName Legacy network name of this user used for login.
/// \param password Legacy network password of this user.
/**
\msc
NetworkPlugin,YourNetworkPlugin,LegacyNetwork;
NetworkPlugin->YourNetworkPlugin [label="handleLoginRequest(...)", URL="\ref NetworkPlugin::handleLoginRequest()"];
YourNetworkPlugin->LegacyNetwork [label="connect the legacy network"];
--- [label="If password was valid and user is connected and logged in"];
YourNetworkPlugin<-LegacyNetwork [label="connected"];
YourNetworkPlugin->NetworkPlugin [label="handleConnected()", URL="\ref NetworkPlugin::handleConnected()"];
--- [label="else"];
YourNetworkPlugin<-LegacyNetwork [label="disconnected"];
YourNetworkPlugin->NetworkPlugin [label="handleDisconnected()", URL="\ref NetworkPlugin::handleDisconnected()"];
\endmsc
*/
virtual void handleLoginRequest(const std::string &user, const std::string &legacyName, const std::string &password) = 0;
/// Called when XMPP user wants to disconnect legacy network.
/// You should disconnect him from legacy network.
/// \param user XMPP JID of user for which this event occurs.
/// \param legacyName Legacy network name of this user used for login.
virtual void handleLogoutRequest(const std::string &user, const std::string &legacyName) = 0;
/// Called when XMPP user sends message to legacy network.
/// \param user XMPP JID of user for which this event occurs.
/// \param legacyName Legacy network name of buddy or room.
/// \param message Plain text message.
/// \param xhtml XHTML message.
virtual void handleMessageSendRequest(const std::string &user, const std::string &legacyName, const std::string &message, const std::string &xhtml = "") = 0;
/// Called when XMPP user requests VCard of buddy.
/// \param user XMPP JID of user for which this event occurs.
/// \param legacyName Legacy network name of buddy whose VCard is requested.
/// \param id ID which is associated with this request. You have to pass it to handleVCard function when you receive VCard.
/**
\msc
NetworkPlugin,YourNetworkPlugin,LegacyNetwork;
NetworkPlugin->YourNetworkPlugin [label="handleVCardRequest(...)", URL="\ref NetworkPlugin::handleVCardRequest()"];
YourNetworkPlugin->LegacyNetwork [label="start VCard fetching"];
YourNetworkPlugin<-LegacyNetwork [label="VCard fetched"];
YourNetworkPlugin->NetworkPlugin [label="handleVCard()", URL="\ref NetworkPlugin::handleVCard()"];
\endmsc
*/
virtual void handleVCardRequest(const std::string &/*user*/, const std::string &/*legacyName*/, unsigned int /*id*/) {}
/// Called when XMPP user updates his own VCard.
/// You should update the VCard in legacy network too.
/// \param user XMPP JID of user for which this event occurs.
/// \param photo Raw photo data.
virtual void handleVCardUpdatedRequest(const std::string &/*user*/, const std::string &/*photo*/, const std::string &nickname) {}
virtual void handleJoinRoomRequest(const std::string &/*user*/, const std::string &/*room*/, const std::string &/*nickname*/, const std::string &/*pasword*/) {}
virtual void handleLeaveRoomRequest(const std::string &/*user*/, const std::string &/*room*/) {}
virtual void handleStatusChangeRequest(const std::string &/*user*/, int status, const std::string &statusMessage) {}
virtual void handleBuddyUpdatedRequest(const std::string &/*user*/, const std::string &/*buddyName*/, const std::string &/*alias*/, const std::vector<std::string> &/*groups*/) {}
virtual void handleBuddyRemovedRequest(const std::string &/*user*/, const std::string &/*buddyName*/, const std::vector<std::string> &/*groups*/) {}
virtual void handleBuddyBlockToggled(const std::string &/*user*/, const std::string &/*buddyName*/, bool /*blocked*/) {}
virtual void handleTypingRequest(const std::string &/*user*/, const std::string &/*buddyName*/) {}
virtual void handleTypedRequest(const std::string &/*user*/, const std::string &/*buddyName*/) {}
virtual void handleStoppedTypingRequest(const std::string &/*user*/, const std::string &/*buddyName*/) {}
virtual void handleAttentionRequest(const std::string &/*user*/, const std::string &/*buddyName*/, const std::string &/*message*/) {}
virtual void handleFTStartRequest(const std::string &/*user*/, const std::string &/*buddyName*/, const std::string &/*fileName*/, unsigned long size, unsigned long ftID) {}
virtual void handleFTFinishRequest(const std::string &/*user*/, const std::string &/*buddyName*/, const std::string &/*fileName*/, unsigned long size, unsigned long ftID) {}
virtual void handleFTPauseRequest(unsigned long ftID) {}
virtual void handleFTContinueRequest(unsigned long ftID) {}
virtual void handleExitRequest() { exit(1); }
void handleDataRead(std::string &data);
virtual void sendData(const std::string &string) {}
void checkPing();
private:
void handleLoginPayload(const std::string &payload);
void handleLogoutPayload(const std::string &payload);
void handleStatusChangedPayload(const std::string &payload);
void handleConvMessagePayload(const std::string &payload);
void handleJoinRoomPayload(const std::string &payload);
void handleLeaveRoomPayload(const std::string &payload);
void handleVCardPayload(const std::string &payload);
void handleBuddyChangedPayload(const std::string &payload);
void handleBuddyRemovedPayload(const std::string &payload);
void handleChatStatePayload(const std::string &payload, int type);
void handleAttentionPayload(const std::string &payload);
void handleFTStartPayload(const std::string &payload);
void handleFTFinishPayload(const std::string &payload);
void handleFTPausePayload(const std::string &payload);
void handleFTContinuePayload(const std::string &payload);
void send(const std::string &data);
void sendPong();
void sendMemoryUsage();
std::string m_data;
bool m_pingReceived;
double m_init_res;
};
}
|