1 /* 2 * This file is part of Licq, an instant messaging client for UNIX. 3 * Copyright (C) 2010-2012 Licq developers <licq-dev@googlegroups.com> 4 * 5 * Licq is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * Licq is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with Licq; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 */ 19 20 #ifndef LICQ_PROTOCOLSIGNAL_H 21 #define LICQ_PROTOCOLSIGNAL_H 22 23 #include <list> 24 #include <pthread.h> 25 #include <string> 26 27 #include "color.h" 28 #include "userid.h" 29 30 namespace Licq 31 { 32 33 class ProtocolSignal 34 { 35 public: 36 enum SignalType 37 { 38 SignalLogon = 1, // Log on 39 SignalLogoff = 2, // Log off 40 SignalChangeStatus = 3, // Change status 41 SignalAddUser = 4, // Add a contact to list 42 SignalRemoveUser = 5, // Remove a contact from list 43 SignalRenameUser = 6, // Rename a contact in server list 44 SignalChangeUserGroups=7, // Change groups for a user 45 SignalSendMessage = 8, // Send a message to a user 46 SignalNotifyTyping = 9, // Send typing notification 47 SignalGrantAuth = 10, // Grant authorization to a user 48 SignalRefuseAuth = 11, // Refuse authorization for a user 49 SignalRequestInfo = 12, // Request user information 50 SignalUpdateInfo = 13, // Update owner information 51 SignalRequestPicture= 14, // Request user picture 52 SignalBlockUser = 15, // Add user to invisible/block list 53 SignalUnblockUser = 16, // Remove user from inivisible/block list 54 SignalAcceptUser = 17, // Add user to visible/accept list 55 SignalUnacceptUser = 18, // Removed user from visible/accept list 56 SignalIgnoreUser = 19, // Add user to ignore list 57 SignalUnignoreUser = 20, // Remove user from ignore list 58 SignalSendFile = 21, // Send file to user 59 SignalSendChat = 22, // Send chat request 60 SignalCancelEvent = 23, // Cancel an event (chat, secure, file, etc.) 61 SignalSendReply = 24, // Accept/refuse file/chat request 62 SignalOpenSecure = 27, // Request secure channel with user 63 SignalCloseSecure = 28, // Close secure channel with user 64 SignalRequestAuth = 29, // Request authorization from user 65 SignalRenameGroup = 30, // Rename a user group 66 SignalRemoveGroup = 31, // Remove a user group 67 SignalSendUrl = 32, // Send an URL to a user 68 SignalProtocolSpecific = 33, // Protocol specific signal 69 }; 70 71 // Flags for send events 72 enum SendFlags 73 { 74 SendToList = 1, // Flag a message as low prio (send to contact list) 75 SendUrgent = 2, // Flag a message as urgent 76 SendDirect = 4, // Don't send message via server (if supported by protocol) 77 SendToMultiple = 8, // Message is sent to multiple recipients 78 }; 79 80 ProtocolSignal(SignalType signal, const UserId& userId, unsigned long eventId = 0); 81 82 virtual ~ProtocolSignal(); 83 84 //! The signal is being sent to the plugin. signal()85 SignalType signal() const 86 { return mySignal; } 87 88 //! The user id that this signal is being used for. userId()89 const UserId& userId() const 90 { return myUserId; } 91 92 /// Id to use for event generated by this signal eventId()93 unsigned long eventId() const 94 { return myEventId; } 95 96 //! The calling thread. callerThread()97 pthread_t callerThread() const 98 { return myCallerThread; } 99 100 101 private: 102 SignalType mySignal; 103 UserId myUserId; 104 unsigned long myEventId; 105 pthread_t myCallerThread; 106 }; 107 108 109 class ProtoLogonSignal : public ProtocolSignal 110 { 111 public: 112 ProtoLogonSignal(const UserId& ownerId, unsigned status); 113 ~ProtoLogonSignal(); 114 115 //! The requested initial status. status()116 unsigned status() const { return myStatus; } 117 118 private: 119 unsigned myStatus; 120 }; 121 122 class ProtoLogoffSignal : public ProtocolSignal 123 { 124 public: 125 ProtoLogoffSignal(const UserId& ownerId); 126 ~ProtoLogoffSignal(); 127 }; 128 129 class ProtoChangeStatusSignal : public ProtocolSignal 130 { 131 public: 132 ProtoChangeStatusSignal(const UserId& ownerId, unsigned status); 133 ~ProtoChangeStatusSignal(); 134 135 //! The requested status. status()136 unsigned status() const { return myStatus; } 137 138 private: 139 unsigned myStatus; 140 }; 141 142 class ProtoAddUserSignal : public ProtocolSignal 143 { 144 public: 145 ProtoAddUserSignal(const UserId& userId); 146 ~ProtoAddUserSignal(); 147 }; 148 149 class ProtoRemoveUserSignal : public ProtocolSignal 150 { 151 public: 152 ProtoRemoveUserSignal(const UserId& userId); 153 ~ProtoRemoveUserSignal(); 154 }; 155 156 class ProtoRenameUserSignal : public ProtocolSignal 157 { 158 public: 159 ProtoRenameUserSignal(const UserId& userId); 160 ~ProtoRenameUserSignal(); 161 }; 162 163 class ProtoChangeUserGroupsSignal : public ProtocolSignal 164 { 165 public: 166 ProtoChangeUserGroupsSignal(const UserId& userId); 167 ~ProtoChangeUserGroupsSignal(); 168 }; 169 170 class ProtoSendMessageSignal : public ProtocolSignal 171 { 172 public: 173 ProtoSendMessageSignal(unsigned long eventId, const UserId& userId, 174 const std::string& message, unsigned flags, const Color* color = NULL, 175 unsigned long convoId = 0); 176 ~ProtoSendMessageSignal(); 177 178 //! The message to be sent message()179 const std::string& message() const { return myMessage; } 180 //! The message flags flags()181 unsigned flags() const { return myFlags; } 182 /// Message color color()183 const Color* color() const { return &myColor; } 184 //! The conversation id to use (gets the socket). convoId()185 unsigned long convoId() const { return myConvoId; } 186 187 private: 188 std::string myMessage; 189 unsigned myFlags; 190 Color myColor; 191 unsigned long myConvoId; 192 }; 193 194 class ProtoTypingNotificationSignal : public ProtocolSignal 195 { 196 public: 197 ProtoTypingNotificationSignal(const UserId& userId, bool active, unsigned long convoId = 0); 198 ~ProtoTypingNotificationSignal(); 199 active()200 bool active() const { return myActive; } 201 //! The conversation id to use (gets the socket). convoId()202 unsigned long convoId() const { return myConvoId; } 203 204 private: 205 bool myActive; 206 unsigned long myConvoId; 207 }; 208 209 class ProtoGrantAuthSignal : public ProtocolSignal 210 { 211 public: 212 ProtoGrantAuthSignal(unsigned long eventId, const UserId& userId, const std::string& message); 213 ~ProtoGrantAuthSignal(); 214 message()215 const std::string& message() const { return myMessage; } 216 217 private: 218 std::string myMessage; 219 }; 220 221 class ProtoRefuseAuthSignal : public ProtocolSignal 222 { 223 public: 224 ProtoRefuseAuthSignal(unsigned long eventId, const UserId& userId, const std::string& message); 225 ~ProtoRefuseAuthSignal(); 226 message()227 const std::string& message() const { return myMessage; } 228 229 private: 230 std::string myMessage; 231 }; 232 233 class ProtoRequestInfo : public ProtocolSignal 234 { 235 public: 236 ProtoRequestInfo(unsigned long eventId, const UserId& userId); 237 ~ProtoRequestInfo(); 238 }; 239 240 class ProtoUpdateInfoSignal : public ProtocolSignal 241 { 242 public: 243 ProtoUpdateInfoSignal(unsigned long eventId, const UserId& ownerId); 244 ~ProtoUpdateInfoSignal(); 245 }; 246 247 class ProtoRequestPicture : public ProtocolSignal 248 { 249 public: 250 ProtoRequestPicture(unsigned long eventId, const UserId& userId); 251 ~ProtoRequestPicture(); 252 }; 253 254 class ProtoBlockUserSignal : public ProtocolSignal 255 { 256 public: 257 ProtoBlockUserSignal(const UserId& userId); 258 ~ProtoBlockUserSignal(); 259 }; 260 261 class ProtoUnblockUserSignal : public ProtocolSignal 262 { 263 public: 264 ProtoUnblockUserSignal(const UserId& userId); 265 ~ProtoUnblockUserSignal(); 266 }; 267 268 class ProtoAcceptUserSignal : public ProtocolSignal 269 { 270 public: 271 ProtoAcceptUserSignal(const UserId& userId); 272 ~ProtoAcceptUserSignal(); 273 }; 274 275 class ProtoUnacceptUserSignal : public ProtocolSignal 276 { 277 public: 278 ProtoUnacceptUserSignal(const UserId& userId); 279 ~ProtoUnacceptUserSignal(); 280 }; 281 282 class ProtoIgnoreUserSignal : public ProtocolSignal 283 { 284 public: 285 ProtoIgnoreUserSignal(const UserId& userId); 286 ~ProtoIgnoreUserSignal(); 287 }; 288 289 class ProtoUnignoreUserSignal : public ProtocolSignal 290 { 291 public: 292 ProtoUnignoreUserSignal(const UserId& userId); 293 ~ProtoUnignoreUserSignal(); 294 }; 295 296 class ProtoSendFileSignal : public ProtocolSignal 297 { 298 public: 299 ProtoSendFileSignal(unsigned long eventId, const UserId& userId, const std::string& filename, 300 const std::string& message, const std::list<std::string>& files, unsigned flags = 0); 301 ~ProtoSendFileSignal(); 302 filename()303 const std::string& filename() const { return myFilename; } message()304 const std::string& message() const { return myMessage; } files()305 const std::list<std::string>& files() const { return myFiles; } flags()306 unsigned flags() const { return myFlags; } 307 308 private: 309 std::string myFilename; 310 std::string myMessage; 311 std::list<std::string> myFiles; 312 unsigned myFlags; 313 }; 314 315 class ProtoSendChatSignal : public ProtocolSignal 316 { 317 public: 318 ProtoSendChatSignal(const UserId& userId, const std::string& message); 319 ~ProtoSendChatSignal(); 320 message()321 const std::string& message() const { return myMessage; } 322 323 private: 324 std::string myMessage; 325 }; 326 327 class ProtoCancelEventSignal : public ProtocolSignal 328 { 329 public: 330 ProtoCancelEventSignal(const UserId& userId, unsigned long eventId); 331 ~ProtoCancelEventSignal(); 332 }; 333 334 class ProtoSendEventReplySignal : public ProtocolSignal 335 { 336 public: 337 ProtoSendEventReplySignal(const UserId& userId, const std::string& message, 338 bool accepted, unsigned short port, unsigned long sequence = 0, 339 unsigned long flag1 = 0, unsigned long flag2 = 0, bool direct = false, 340 const std::string& filename = std::string(), unsigned long filesize = 0); 341 ~ProtoSendEventReplySignal(); 342 message()343 const std::string& message() const { return myMessage; } accept()344 bool accept() const { return myAccept; } port()345 unsigned short port() const { return myPort; } sequence()346 unsigned long sequence() const { return mySequence; } flag1()347 unsigned long flag1() const { return myFlag1; } flag2()348 unsigned long flag2() const { return myFlag2; } direct()349 bool direct() const { return myDirect; } filename()350 const std::string& filename() const { return myFilename; } filesize()351 unsigned long filesize() const { return myFilesize; } 352 353 private: 354 std::string myMessage; 355 bool myAccept; 356 unsigned short myPort; 357 unsigned long mySequence; 358 unsigned long myFlag1; 359 unsigned long myFlag2; 360 bool myDirect; 361 std::string myFilename; 362 unsigned long myFilesize; 363 }; 364 365 class ProtoOpenSecureSignal : public ProtocolSignal 366 { 367 public: 368 ProtoOpenSecureSignal(unsigned long eventId, const UserId& userId); 369 ~ProtoOpenSecureSignal(); 370 }; 371 372 class ProtoCloseSecureSignal : public ProtocolSignal 373 { 374 public: 375 ProtoCloseSecureSignal(unsigned long eventId, const UserId& userId); 376 ~ProtoCloseSecureSignal(); 377 }; 378 379 class ProtoRequestAuthSignal : public ProtocolSignal 380 { 381 public: 382 ProtoRequestAuthSignal(const UserId& userId, const std::string& message); 383 ~ProtoRequestAuthSignal(); 384 message()385 const std::string& message() const { return myMessage; } 386 387 private: 388 std::string myMessage; 389 }; 390 391 class ProtoRenameGroupSignal : public ProtocolSignal 392 { 393 public: 394 ProtoRenameGroupSignal(const UserId& ownerId, int groupId); 395 ~ProtoRenameGroupSignal(); 396 groupId()397 int groupId() const { return myGroupId; } 398 399 private: 400 int myGroupId; 401 }; 402 403 class ProtoRemoveGroupSignal : public ProtocolSignal 404 { 405 public: 406 ProtoRemoveGroupSignal(const UserId& ownerId, int groupId, unsigned long groupServerId, 407 const std::string& groupName); 408 ~ProtoRemoveGroupSignal(); 409 groupId()410 int groupId() const { return myGroupId; } groupServerId()411 unsigned long groupServerId() const { return myGroupServerId; } groupName()412 const std::string& groupName() const { return myGroupName; } 413 414 private: 415 int myGroupId; 416 unsigned long myGroupServerId; 417 std::string myGroupName; 418 }; 419 420 class ProtoSendUrlSignal : public ProtocolSignal 421 { 422 public: 423 ProtoSendUrlSignal(unsigned long eventId, const UserId& userId, const std::string& url, 424 const std::string& message, unsigned flags, const Color* color = NULL); 425 ~ProtoSendUrlSignal(); 426 url()427 const std::string& url() const { return myUrl; } message()428 const std::string& message() const { return myMessage; } flags()429 unsigned flags() const { return myFlags; } color()430 const Color* color() const { return &myColor; } 431 432 private: 433 std::string myUrl; 434 std::string myMessage; 435 unsigned myFlags; 436 Color myColor; 437 }; 438 439 } // namespace Licq 440 441 #endif 442