1 /* 2 * This file is part of Licq, an instant messaging client for UNIX. 3 * Copyright (C) 2011-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_USEREVENTS_H 21 #define LICQ_USEREVENTS_H 22 23 #include <cstdlib> 24 #include <ctime> 25 #include <list> 26 27 #include "color.h" 28 #include "userid.h" 29 30 namespace LicqIcq 31 { 32 class IcqProtocol; 33 } 34 35 namespace LicqMsn 36 { 37 class CMSN; 38 } 39 40 namespace LicqJabber 41 { 42 class Plugin; 43 } 44 45 namespace LicqDaemon 46 { 47 class Daemon; 48 class UserHistory; 49 } 50 51 namespace Licq 52 { 53 class User; 54 55 56 //=====CUserEvent=============================================================== 57 class UserEvent 58 { 59 public: 60 // Define some event flags, leave the 2 LSB's for the licq version 61 enum Flags 62 { 63 FlagLicqVerMask = 0x0000ffff, 64 FlagDirect = 0x00010000, 65 FlagMultiRec = 0x00020000, 66 FlagUrgent = 0x00040000, 67 FlagCancelled = 0x00080000, 68 FlagEncrypted = 0x00100000, 69 FlagSender = 0x00200000, 70 FlagOffline = 0x00400000, 71 FlagUnicode = 0x00800000, // Only used in history files for UTF8 encoded messages 72 FlagUnknown = 0x80000000, 73 }; 74 75 // Event type, for now these must be the same as the ICQ protocol sub commands 76 enum EventType 77 { 78 TypeMessage = 0x0001, 79 TypeChat = 0x0002, 80 TypeFile = 0x0003, 81 TypeUrl = 0x0004, 82 TypeAuthRequest = 0x0006, 83 TypeAuthRefused = 0x0007, 84 TypeAuthGranted = 0x0008, 85 TypeMsgServer = 0x0009, 86 TypeAdded = 0x000C, 87 TypeWebPanel = 0x000D, 88 TypeEmailPager = 0x000E, 89 TypeContactList = 0x0013, 90 TypeSms = 0x001A, 91 TypeEmailAlert = 0x001C, 92 TypeUnknownSys = 0x001F, 93 }; 94 95 // Only used for history files, must be same as ICQ protocol commands 96 enum HistoryCommand 97 { 98 CommandDirect = 0x07EE, 99 CommandSent = 0x010E, 100 CommandRcvOnline = 0x0104, 101 CommandRcvOffline = 0x00DC, 102 CommandCancelled = 0x07D0, 103 }; 104 105 static const time_t TimeNow = 0; 106 107 /// Return translated event name for an event type 108 static std::string eventName(unsigned eventType); 109 110 UserEvent(EventType eventType, 111 unsigned short _nSequence, time_t _tTime, 112 unsigned long _nFlags, unsigned long _nConvoId = 0); 113 UserEvent(const UserEvent *); 114 virtual ~UserEvent(); 115 116 virtual UserEvent* Copy() const = 0; 117 118 /** 119 * Description (including message text) of event 120 * 121 * @return Text description (in UTF-8) 122 */ 123 const std::string& text() const; 124 125 /** 126 * Description (including message text) of event 127 * 128 * @return Text description (converted to current locale) 129 */ 130 const std::string& textLoc() const; 131 132 std::string description() const; Time()133 time_t Time() const { return m_tTime; } licqVersionStr()134 const std::string licqVersionStr() const 135 { return licqVersionToString(LicqVersion()); } 136 137 static const std::string licqVersionToString(unsigned long); Sequence()138 unsigned short Sequence() const { return m_nSequence; } 139 140 /// Get type of event eventType()141 unsigned eventType() const { return myEventType; } 142 143 /// Returns translated event name eventName()144 std::string eventName() const 145 { return eventName(eventType()); } 146 Id()147 int Id() const { return m_nId; } IsDirect()148 bool IsDirect() const { return m_nFlags & FlagDirect; } IsMultiRec()149 bool IsMultiRec() const { return m_nFlags & FlagMultiRec; } IsUrgent()150 bool IsUrgent() const { return m_nFlags & FlagUrgent; } IsCancelled()151 bool IsCancelled() const { return m_nFlags & FlagCancelled; } IsLicq()152 bool IsLicq() const { return LicqVersion() != 0; }; IsEncrypted()153 bool IsEncrypted() const { return m_nFlags & FlagEncrypted; }; LicqVersion()154 unsigned short LicqVersion() const { return m_nFlags & FlagLicqVerMask; } 155 156 /// Was message sent from us isSender()157 bool isSender() const { return m_nFlags & FlagSender; } 158 159 /// Was message sent while receiver was offline isOffline()160 bool isOffline() const { return m_nFlags & FlagOffline; } 161 isReceiver()162 bool isReceiver() const { return !isSender(); } color()163 const Color* color() const { return &myColor; } ConvoId()164 unsigned long ConvoId() const { return m_nConvoId; } 165 Pending()166 bool Pending() const { return m_bPending; } SetPending(bool b)167 void SetPending(bool b) { m_bPending = b; } 168 169 protected: 170 virtual void AddToHistory(User* user, bool isReceiver) const = 0; 171 172 /** 173 * Construct a header for the history entry 174 * 175 * @param isReceived True if message was received 176 * @return String with header data formated for history 177 */ 178 std::string historyHeader(bool isReceiver) const; 179 180 /** 181 * Write to user history 182 * 183 * @param User to write to, must be write locked 184 * @param text History entry, including header and formatting 185 */ 186 void writeUserHistory(User* u, const std::string& text) const; 187 Cancel()188 void Cancel() { m_nFlags |= FlagCancelled; } SetColor(unsigned fore,unsigned back)189 void SetColor(unsigned fore, unsigned back) { myColor.set(fore, back); } SetColor(const Color * c)190 void SetColor(const Color* c) { myColor.set(c); } 191 192 void CopyBase(const UserEvent* e); 193 194 // CreateDescription() is const even though it changes m_szText since 195 // it may be called to perform delayed initialization in const context. 196 virtual void CreateDescription() const = 0; 197 static int s_nId; 198 199 // m_szText is not initialized until it is accessed. Allow this delayed 200 // initialization even if called in const context. 201 mutable std::string myText, myTextLoc; 202 unsigned myEventType; 203 unsigned short m_nSequence; 204 int m_nId; 205 time_t m_tTime; 206 unsigned long m_nFlags; 207 208 bool m_bPending; 209 Color myColor; 210 unsigned long m_nConvoId; 211 212 friend class LicqIcq::IcqProtocol; 213 friend class LicqDaemon::Daemon; 214 friend class LicqMsn::CMSN; 215 friend class LicqJabber::Plugin; 216 friend class User; 217 }; 218 219 220 //-----CEventMsg------------------------------------------------------------- 221 class EventMsg : public UserEvent 222 { 223 public: 224 EventMsg(const std::string& message, 225 time_t _tTime, unsigned long _nFlags, unsigned long _nConvoId = 0); 226 227 virtual EventMsg* Copy() const; message()228 const std::string& message() const { return myMessage; } 229 virtual void AddToHistory(User* u, bool isReceiver) const; 230 231 protected: 232 void CreateDescription() const; 233 234 std::string myMessage; 235 }; 236 237 238 //-----CEventFile--------------------------------------------------------------- 239 class EventFile : public UserEvent 240 { 241 public: 242 EventFile(const std::string& filename, const std::string& fileDescription, 243 unsigned long _nFileSize, const std::list<std::string>& lFileList, 244 unsigned short _nSequence, time_t _tTime, 245 unsigned long _nFlags, unsigned long _nConovId = 0, 246 unsigned long _nMsgID1 = 0, unsigned long _nMsgID2 = 0); 247 virtual EventFile* Copy() const; 248 virtual void AddToHistory(User* u, bool isReceiver) const; 249 filename()250 const std::string& filename() const { return myFilename; } FileSize()251 unsigned long FileSize() const { return m_nFileSize; } fileDescription()252 const std::string& fileDescription() const { return myFileDescription; } FileList()253 const std::list<std::string>& FileList() const { return m_lFileList; } MessageID()254 const unsigned long* MessageID() const { return m_nMsgID; } 255 protected: 256 void CreateDescription() const; 257 258 std::string myFilename; 259 std::string myFileDescription; 260 unsigned long m_nFileSize; 261 std::list<std::string> m_lFileList; 262 unsigned long m_nMsgID[2]; 263 }; 264 265 266 //-----CEventUrl---------------------------------------------------------------- 267 class EventUrl : public UserEvent 268 { 269 public: 270 EventUrl(const std::string& url, const std::string& urlDescription, 271 time_t _tTime, unsigned long _nFlags, unsigned long _nConvoId = 0); 272 virtual EventUrl* Copy() const; 273 virtual void AddToHistory(User* u, bool isReceiver) const; url()274 const std::string& url() const { return myUrl; } urlDescription()275 const std::string& urlDescription() const { return myUrlDescription; } 276 277 protected: 278 void CreateDescription() const; 279 280 std::string myUrl; 281 std::string myUrlDescription; 282 }; 283 284 285 //-----CEventChat--------------------------------------------------------------- 286 class EventChat : public UserEvent 287 { 288 public: 289 EventChat(const std::string& reason, unsigned short nSequence, time_t tTime, 290 unsigned long nFlags, unsigned long nConvoId = 0, unsigned long nMsgID1 = 0, 291 unsigned long nMsgID2 = 0); 292 EventChat(const std::string& reason, const std::string& clients, unsigned short nPort, 293 unsigned short nSequence, time_t tTime, unsigned long nFlags, 294 unsigned long _nConvoId = 0, unsigned long nMsgID1 = 0, unsigned long nMsgID2 = 0); 295 virtual EventChat* Copy() const; 296 virtual void AddToHistory(User* u, bool isReceiver) const; reason()297 const std::string& reason() const { return myReason; } clients()298 const std::string& clients() const { return myClients; } Port()299 unsigned short Port() const { return m_nPort; } MessageID()300 const unsigned long* MessageID() const { return m_nMsgID; } 301 protected: 302 void CreateDescription() const; 303 304 std::string myReason; 305 std::string myClients; 306 unsigned short m_nPort; 307 unsigned long m_nMsgID[2]; 308 }; 309 310 311 //-----CEventAdded-------------------------------------------------------------- 312 class EventAdded : public UserEvent 313 { 314 public: 315 EventAdded(const UserId& userId, const std::string& alias, 316 const std::string& firstName, const std::string& lastName, 317 const std::string& email, time_t _tTime, unsigned long _nFlags); 318 virtual EventAdded* Copy() const; 319 virtual void AddToHistory(User* u, bool isReceiver) const; userId()320 const UserId& userId() const { return myUserId; } 321 322 protected: 323 void CreateDescription() const; 324 325 UserId myUserId; 326 std::string myAlias; 327 std::string myFirstName; 328 std::string myLastName; 329 std::string myEmail; 330 }; 331 332 333 //-----CEventAuthReq--------------------------------------------------------- 334 class EventAuthRequest : public UserEvent 335 { 336 public: 337 EventAuthRequest(const UserId& userId, const std::string& alias, 338 const std::string& firstName, const std::string& lastName, 339 const std::string& email, const std::string& reason, 340 time_t _tTime, unsigned long _nFlags); 341 virtual EventAuthRequest* Copy() const; 342 virtual void AddToHistory(User* u, bool isReceiver) const; userId()343 const UserId& userId() const { return myUserId; } reason()344 const std::string& reason() const { return myReason; } 345 346 protected: 347 void CreateDescription() const; 348 349 UserId myUserId; 350 std::string myAlias; 351 std::string myFirstName; 352 std::string myLastName; 353 std::string myEmail; 354 std::string myReason; 355 }; 356 357 358 //-----CEventAuthGranted------------------------------------------------------- 359 class EventAuthGranted : public UserEvent 360 { 361 public: 362 EventAuthGranted(const UserId& userId, const std::string& message, 363 time_t _tTime, unsigned long _nFlags); 364 virtual EventAuthGranted* Copy() const; 365 virtual void AddToHistory(User* u, bool isReceiver) const; userId()366 const UserId& userId() const { return myUserId; } message()367 const std::string& message() const { return myMessage; } 368 369 protected: 370 void CreateDescription() const; 371 372 UserId myUserId; 373 std::string myMessage; 374 }; 375 376 377 //-----CEventAuthRefused------------------------------------------------------ 378 class EventAuthRefused : public UserEvent 379 { 380 public: 381 EventAuthRefused(const UserId& userId, const std::string& message, 382 time_t _tTime, unsigned long _nFlags); 383 virtual EventAuthRefused* Copy() const; 384 virtual void AddToHistory(User* u, bool isReceiver) const; userId()385 const UserId& userId() const { return myUserId; } message()386 const std::string& message() const { return myMessage; } 387 388 protected: 389 void CreateDescription() const; 390 391 UserId myUserId; 392 std::string myMessage; 393 }; 394 395 396 //-----CEventWebPanel---------------------------------------------------------- 397 class EventWebPanel : public UserEvent 398 { 399 public: 400 EventWebPanel(const std::string& name, const std::string& email, 401 const std::string& message, time_t _tTime, unsigned long _nFlags); 402 virtual EventWebPanel* Copy() const; 403 virtual void AddToHistory(User* u, bool isReceiver) const; message()404 const std::string& message() const { return myMessage; } 405 406 protected: 407 void CreateDescription() const; 408 409 std::string myName; 410 std::string myEmail; 411 std::string myMessage; 412 }; 413 414 415 //-----CEventEmailPager---------------------------------------------------------- 416 class EventEmailPager : public UserEvent 417 { 418 public: 419 EventEmailPager(const std::string& name, const std::string& email, 420 const std::string& message, time_t _tTime, unsigned long _nFlags); 421 virtual EventEmailPager* Copy() const; 422 virtual void AddToHistory(User* u, bool isReceiver) const; message()423 const std::string& message() const { return myMessage; } 424 425 protected: 426 void CreateDescription() const; 427 428 std::string myName; 429 std::string myEmail; 430 std::string myMessage; 431 }; 432 433 434 //-----CEventContactList---------------------------------------------------------- 435 class EventContactList : public UserEvent 436 { 437 public: 438 class Contact 439 { 440 public: 441 Contact(const UserId& userId, const std::string& alias); 442 userId()443 const UserId& userId() const { return myUserId; } alias()444 const std::string& alias() const { return myAlias; } 445 446 protected: 447 UserId myUserId; 448 std::string myAlias; 449 }; 450 typedef std::list<Contact *> ContactList; 451 452 453 EventContactList(const ContactList& cl, bool bDeep, 454 time_t tTime, unsigned long nFlags); 455 virtual ~EventContactList(); 456 virtual EventContactList* Copy() const; 457 virtual void AddToHistory(User* u, bool isReceiver) const; 458 Contacts()459 const ContactList &Contacts() const { return m_vszFields; } 460 461 protected: 462 void CreateDescription() const; 463 464 ContactList m_vszFields; 465 }; 466 467 468 //-----CEventSms--------------------------------------------------------------- 469 class EventSms : public UserEvent 470 { 471 public: 472 EventSms(const std::string& number, const std::string& message, 473 time_t _tTime, unsigned long _nFlags); 474 virtual EventSms* Copy() const; number()475 const std::string& number() const { return myNumber; } message()476 const std::string& message() const { return myMessage; } 477 virtual void AddToHistory(User* u, bool isReceiver) const; 478 479 protected: 480 void CreateDescription() const; 481 482 std::string myNumber; 483 std::string myMessage; 484 }; 485 486 //-----CEventServerMessage----------------------------------------------------- 487 class EventServerMessage : public UserEvent 488 { 489 public: 490 EventServerMessage(const std::string& name, const std::string& email, 491 const std::string& message, time_t _tTime); 492 virtual EventServerMessage* Copy() const; message()493 const std::string& message() const { return myMessage; } 494 virtual void AddToHistory(User* u, bool isReceiver) const; 495 496 protected: 497 void CreateDescription() const; 498 499 std::string myName; 500 std::string myEmail; 501 std::string myMessage; 502 }; 503 504 //-----CEventEmailAlert----------------------------------------------------- 505 class EventEmailAlert : public UserEvent 506 { 507 public: 508 EventEmailAlert(const std::string& name, const std::string& email, 509 const std::string& to, const std::string& subject, time_t _tTime, 510 const std::string& mspAuth = "", const std::string& sid = "", 511 const std::string& kv = "", const std::string& id = "", 512 const std::string& postUrl = "", const std::string& msgUrl = "", 513 const std::string& creds = "", unsigned long sessionLength = 0); 514 virtual EventEmailAlert* Copy() const; 515 virtual void AddToHistory(User* u, bool isReceiver) const; 516 from()517 const std::string& from() const { return myName; } to()518 const std::string& to() const { return myTo; } email()519 const std::string& email() const { return myEmail; } subject()520 const std::string& subject() const { return mySubject; } 521 mspAuth()522 const std::string& mspAuth() const { return myMspAuth; } sid()523 const std::string& sid() const { return mySid; } kv()524 const std::string& kv() const { return myKv; } id()525 const std::string& id() const { return myId; } postUrl()526 const std::string& postUrl() const { return myPostUrl; } msgUrl()527 const std::string& msgUrl() const { return myMsgUrl; } creds()528 const std::string& creds() const { return myCreds; } sessionLength()529 unsigned long sessionLength() const { return mySessionLength; } 530 531 protected: 532 void CreateDescription() const; 533 534 // Info 535 std::string myName; 536 std::string myTo; 537 std::string myEmail; 538 std::string mySubject; 539 540 // For Licq to view an MSN email 541 std::string myMspAuth; 542 std::string mySid; 543 std::string myKv; 544 std::string myId; 545 std::string myPostUrl; 546 std::string myMsgUrl; 547 std::string myCreds; 548 unsigned long mySessionLength; 549 }; 550 551 //-----CEventUnknownSysMsg----------------------------------------------------- 552 class EventUnknownSysMsg : public UserEvent 553 { 554 public: 555 EventUnknownSysMsg(unsigned short _nSubCommand, unsigned short _nCommand, 556 const UserId& userId, const std::string& message, time_t _tTime, unsigned long _nFlags); 557 virtual EventUnknownSysMsg* Copy() const; 558 virtual void AddToHistory(User* u, bool isReceiver) const; subCommand()559 unsigned short subCommand() const { return m_nSubCommand; } Command()560 unsigned short Command() const { return m_nCommand; } 561 562 protected: 563 void CreateDescription() const; 564 565 unsigned short m_nCommand; 566 unsigned short m_nSubCommand; 567 UserId myUserId; 568 std::string myMessage; 569 }; 570 571 } // namespace Licq 572 573 #endif 574