00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef EVENTS_H
00028 #define EVENTS_H
00029
00030 #include <time.h>
00031 #include <string>
00032
00033 #include <libicq2000/constants.h>
00034
00035 #include <libicq2000/ContactList.h>
00036
00037 namespace ICQ2000 {
00038
00039 class Contact;
00040
00041
00042
00043
00044
00049 class Event {
00050 protected:
00054 time_t m_time;
00055
00056 public:
00057 Event();
00058 Event(time_t t);
00059
00060 time_t getTime() const;
00061 void setTime(time_t t);
00062 };
00063
00064
00065
00066
00067
00071 class SocketEvent : public Event {
00072 private:
00073 int m_fd;
00074
00075 public:
00076 SocketEvent(int fd);
00077 virtual ~SocketEvent();
00078
00079 int getSocketHandle() const;
00080
00084 enum Mode {
00085 READ = 1 << 0,
00086 WRITE = 1 << 1,
00087 EXCEPTION = 1 << 2
00088 };
00089 };
00090
00096 class AddSocketHandleEvent : public SocketEvent {
00097 private:
00098 Mode m_mode;
00099
00100 public:
00101 AddSocketHandleEvent(int fd, Mode m);
00102
00103 Mode getMode() const;
00104 bool isRead() const;
00105 bool isWrite() const;
00106 bool isException() const;
00107 };
00108
00114 class RemoveSocketHandleEvent : public SocketEvent {
00115 public:
00116 RemoveSocketHandleEvent(int fd);
00117 };
00118
00119
00120
00121
00122
00126 class ConnectingEvent : public Event {
00127 public:
00128 ConnectingEvent();
00129 };
00130
00131
00132
00133
00134
00139 class ConnectedEvent : public Event {
00140 public:
00141 ConnectedEvent();
00142 };
00143
00144
00145
00146
00147
00153 class DisconnectedEvent : public Event {
00154 public:
00158 enum Reason {
00159 REQUESTED,
00160 FAILED_LOWLEVEL,
00161 FAILED_BADUSERNAME,
00162 FAILED_TURBOING,
00163 FAILED_BADPASSWORD,
00164 FAILED_MISMATCH_PASSWD,
00165 FAILED_DUALLOGIN,
00166 FAILED_UNKNOWN
00167 };
00168
00169 private:
00170 Reason m_reason;
00171
00172 public:
00173 DisconnectedEvent(Reason r);
00174
00175 Reason getReason() const;
00176 };
00177
00178
00179
00180
00181
00185 class LogEvent : public Event {
00186 public:
00190 enum LogType {
00191 WARN,
00192 ERROR,
00193 INFO,
00194 PACKET,
00195 DIRECTPACKET
00196 };
00197
00198 private:
00199 LogType m_type;
00200 std::string m_msg;
00201
00202 public:
00203 LogEvent(LogType type, const std::string& msg);
00204
00205 LogType getType() const;
00206 std::string getMessage() const;
00207 };
00208
00209
00210
00211
00212
00216 class ContactListEvent : public Event {
00217 public:
00221 enum EventType {
00222 UserAdded,
00223 UserRemoved
00224 };
00225
00226 protected:
00230 ContactRef m_contact;
00231
00232 public:
00233 ContactListEvent(ContactRef c);
00234 virtual ~ContactListEvent();
00235
00236 ContactRef getContact() const;
00237 unsigned int getUIN() const;
00238
00244 virtual EventType getType() const = 0;
00245 };
00246
00250 class UserAddedEvent : public ContactListEvent {
00251 public:
00252 UserAddedEvent(ContactRef c);
00253 EventType getType() const;
00254 };
00255
00259 class UserRemovedEvent : public ContactListEvent {
00260 public:
00261 UserRemovedEvent(ContactRef c);
00262 EventType getType() const;
00263 };
00264
00265
00266
00267
00268
00272 class ContactEvent : public Event {
00273 public:
00277 enum EventType {
00278 StatusChange,
00279 UserInfoChange,
00280 };
00281
00282 protected:
00286 ContactRef m_contact;
00287
00288 public:
00289 ContactEvent(ContactRef c);
00290 virtual ~ContactEvent();
00291
00292 ContactRef getContact() const;
00293 unsigned int getUIN() const;
00294
00300 virtual EventType getType() const = 0;
00301 };
00302
00306 class UserInfoChangeEvent : public ContactEvent {
00307 private:
00308 bool m_is_transient_detail;
00309 public:
00310 UserInfoChangeEvent(ContactRef c, bool is_transient_detail);
00311 EventType getType() const;
00312 bool isTransientDetail() const;
00313 };
00314
00318 class StatusChangeEvent : public ContactEvent {
00319 private:
00320 Status m_status;
00321 Status m_old_status;
00322
00323 public:
00324 StatusChangeEvent(ContactRef contact, Status status, Status old_status);
00325
00326 EventType getType() const;
00327 Status getStatus() const;
00328 Status getOldStatus() const;
00329 };
00330
00331
00332
00333
00334
00339 class MessageEvent : public Event {
00340 public:
00344 enum MessageType {
00345 Normal,
00346 URL,
00347 SMS,
00348 SMS_Receipt,
00349 AuthReq,
00350 AuthAck,
00351 AwayMessage,
00352 EmailEx,
00353 UserAdd,
00354 Email,
00355 WebPager
00356 };
00357
00358 enum DeliveryFailureReason {
00359 Failed,
00360 Failed_NotConnected,
00361 Failed_ClientNotCapable,
00362 Failed_Denied,
00363 Failed_Ignored,
00364 Failed_Occupied,
00365 Failed_DND,
00366 Failed_SMTP
00367 };
00368
00369 protected:
00371 ContactRef m_contact;
00373 bool m_finished;
00375 bool m_delivered;
00377 bool m_direct;
00378
00379 DeliveryFailureReason m_failure_reason;
00380
00381 public:
00382 MessageEvent(ContactRef c);
00383 virtual ~MessageEvent();
00384
00390 virtual MessageType getType() const = 0;
00391 ContactRef getContact();
00392
00393 bool isFinished() const;
00394 bool isDelivered() const;
00395 bool isDirect() const;
00396
00397 void setFinished(bool f);
00398 void setDelivered(bool f);
00399 void setDirect(bool f);
00400
00401 DeliveryFailureReason getDeliveryFailureReason() const;
00402 void setDeliveryFailureReason(DeliveryFailureReason d);
00403 };
00404
00408 class ICQMessageEvent : public MessageEvent {
00409 private:
00410 bool m_urgent, m_tocontactlist, m_offline;
00411 std::string m_away_message;
00412
00413 public:
00414 ICQMessageEvent(ContactRef c);
00415
00416 bool isUrgent() const;
00417 void setUrgent(bool b);
00418 bool isToContactList() const;
00419 void setToContactList(bool b);
00420 bool isOfflineMessage() const;
00421 void setOfflineMessage(bool b);
00422 unsigned int getSenderUIN() const;
00423 std::string getAwayMessage() const;
00424 void setAwayMessage(const std::string& msg);
00425
00426 virtual ICQMessageEvent* copy() const = 0;
00427 };
00428
00432 class NormalMessageEvent : public ICQMessageEvent {
00433 private:
00434 std::string m_message;
00435 bool m_multi;
00436 unsigned int m_foreground, m_background;
00437
00438 public:
00439 NormalMessageEvent(ContactRef c, const std::string& msg, bool multi = false);
00440 NormalMessageEvent(ContactRef c, const std::string& msg, time_t t, bool multi);
00441 NormalMessageEvent(ContactRef c, const std::string& msg, unsigned int fg, unsigned int bg);
00442
00443 std::string getMessage() const;
00444 MessageType getType() const;
00445 bool isMultiParty() const;
00446 unsigned int getForeground() const;
00447 unsigned int getBackground() const;
00448 void setForeground(unsigned int f);
00449 void setBackground(unsigned int b);
00450
00451 ICQMessageEvent* copy() const;
00452 };
00453
00457 class URLMessageEvent : public ICQMessageEvent {
00458 private:
00459 std::string m_message, m_url;
00460
00461 public:
00462 URLMessageEvent(ContactRef c, const std::string& msg, const std::string& url);
00463 URLMessageEvent(ContactRef c, const std::string& msg, const std::string& url, time_t t);
00464
00465 std::string getMessage() const;
00466 std::string getURL() const;
00467 MessageType getType() const;
00468
00469 ICQMessageEvent* copy() const;
00470 };
00471
00475 class SMSMessageEvent : public MessageEvent {
00476 private:
00477 std::string m_message, m_source, m_sender, m_senders_network;
00478 std::string m_smtp_from, m_smtp_to, m_smtp_subject;
00479 bool m_rcpt;
00480
00481 public:
00482 SMSMessageEvent(ContactRef c, const std::string& msg, bool rcpt);
00483 SMSMessageEvent(ContactRef c, const std::string& msg, const std::string& source,
00484 const std::string& senders_network, const std::string& time);
00485
00486 std::string getMessage() const;
00487 MessageType getType() const;
00488 std::string getSource() const;
00489 std::string getSender() const;
00490 std::string getSenders_network() const;
00491 bool getRcpt() const;
00492
00493 void setSMTPFrom(const std::string& from);
00494 std::string getSMTPFrom() const;
00495
00496 void setSMTPTo(const std::string& to);
00497 std::string getSMTPTo() const;
00498
00499 void setSMTPSubject(const std::string& subj);
00500 std::string getSMTPSubject() const;
00501 };
00502
00506 class SMSReceiptEvent : public MessageEvent {
00507 private:
00508 std::string m_message, m_message_id, m_destination, m_submission_time, m_delivery_time;
00509 bool m_delivered;
00510
00511 public:
00512 SMSReceiptEvent(ContactRef c, const std::string& msg, const std::string& message_id,
00513 const std::string& submission_time, const std::string& delivery_time, bool del);
00514
00515 MessageType getType() const;
00516 std::string getMessage() const;
00517 std::string getMessageId() const;
00518 std::string getDestination() const;
00519 std::string getSubmissionTime() const;
00520 std::string getDeliveryTime() const;
00521 bool delivered() const;
00522 };
00523
00531 class AwayMessageEvent : public ICQMessageEvent {
00532 public:
00533 AwayMessageEvent(ContactRef c);
00534
00535 MessageType getType() const;
00536
00537 ICQMessageEvent* copy() const;
00538 };
00539
00543 class AuthReqEvent : public ICQMessageEvent {
00544 private:
00545 std::string m_message;
00546
00547 public:
00548 AuthReqEvent(ContactRef c, const std::string& msg);
00549 AuthReqEvent(ContactRef c, const std::string& msg, time_t time);
00550
00551 std::string getMessage() const;
00552 MessageType getType() const;
00553
00554 ICQMessageEvent* copy() const;
00555 };
00556
00560 class AuthAckEvent : public ICQMessageEvent {
00561 private:
00562 std::string m_message;
00563 bool m_granted;
00564
00565 public:
00566 AuthAckEvent(ContactRef c, bool granted);
00567 AuthAckEvent(ContactRef c, bool granted, time_t time);
00568 AuthAckEvent(ContactRef c, const std::string& msg, bool granted);
00569 AuthAckEvent(ContactRef c, const std::string& msg, bool granted, time_t time);
00570
00571 std::string getMessage() const;
00572 MessageType getType() const;
00573 bool isGranted() const;
00574
00575 ICQMessageEvent* copy() const;
00576 };
00577
00581 class EmailExEvent : public MessageEvent {
00582 private:
00583 std::string m_sender, m_email, m_message;
00584
00585 public:
00586 EmailExEvent(ContactRef c, const std::string &email, const std::string &sender, const std::string &msg);
00587
00588 std::string getMessage() const;
00589 std::string getEmail() const;
00590 std::string getSender() const;
00591
00592 MessageType getType() const;
00593 unsigned int getSenderUIN() const;
00594 };
00595
00599 class WebPagerEvent : public MessageEvent {
00600 private:
00601 std::string m_sender, m_email, m_message;
00602
00603 public:
00604 WebPagerEvent(ContactRef c, const std::string& email, const std::string& sender, const std::string& msg);
00605
00606 std::string getMessage() const;
00607 std::string getEmail() const;
00608 std::string getSender() const;
00609
00610 MessageType getType() const;
00611 };
00612
00616 class UserAddEvent : public ICQMessageEvent {
00617 public:
00618 UserAddEvent(ContactRef c);
00619
00620 MessageType getType() const;
00621 unsigned int getSenderUIN() const;
00622
00623 ICQMessageEvent* copy() const;
00624 };
00625
00629 class EmailMessageEvent : public MessageEvent {
00630 private:
00631 std::string m_message;
00632
00633 public:
00634 EmailMessageEvent(ContactRef c, const std::string &msg);
00635
00636 std::string getMessage() const;
00637
00638 MessageType getType() const;
00639 };
00640
00641
00642
00643
00644
00648 class SearchResultEvent : public Event {
00649 public:
00650 enum SearchType {
00651 ShortWhitepage,
00652 FullWhitepage,
00653 UIN,
00654 Keyword
00655 };
00656
00657 private:
00658 bool m_finished, m_expired;
00659 SearchType m_searchtype;
00660 ContactList m_clist;
00661 ContactRef m_last_contact;
00662 unsigned int m_more_results;
00663
00664 public:
00665 SearchResultEvent(SearchType t);
00666
00667 SearchType getSearchType() const;
00668 ContactList& getContactList();
00669 ContactRef getLastContactAdded() const;
00670 void setLastContactAdded(ContactRef c);
00671 unsigned int getNumberMoreResults() const;
00672
00673 bool isFinished() const;
00674 void setFinished(bool b);
00675 bool isExpired() const;
00676 void setExpired(bool b);
00677 void setNumberMoreResults(unsigned int m);
00678 };
00679
00683 class ServerBasedContactEvent : public Event {
00684 private:
00685 ContactList m_clist;
00686 public:
00687 ServerBasedContactEvent(const ContactList& l);
00688 ContactList& getContactList();
00689 };
00690
00691
00692
00693
00694
00698 class NewUINEvent : public Event {
00699 private:
00700 unsigned int m_uin;
00701 bool m_success;
00702
00703 public:
00704 NewUINEvent(unsigned int uin, bool success=true);
00705 unsigned int getUIN() const;
00706 bool isSuccess() const;
00707 };
00708
00712 class RateInfoChangeEvent : public Event {
00713 public:
00717 enum RateClass {
00718 RATE_CHANGE=1,
00719 RATE_WARNING,
00720 RATE_LIMIT,
00721 RATE_LIMIT_CLEARED
00722 };
00723
00724 private:
00725 unsigned short m_code;
00726 unsigned short m_rateclass;
00727 unsigned int m_windowsize;
00728 unsigned int m_clear;
00729 unsigned int m_alert;
00730 unsigned int m_limit;
00731 unsigned int m_disconnect;
00732 unsigned int m_currentavg;
00733 unsigned int m_maxavg;
00734
00735 public:
00736 RateInfoChangeEvent(unsigned short code, unsigned short rateclass,
00737 unsigned int windowsize,unsigned int clear,
00738 unsigned int alert,unsigned int limit,
00739 unsigned int disconnect,unsigned int currentavg,
00740 unsigned int maxavg);
00741
00743 unsigned short getCode() const { return m_code; }
00745 unsigned short getRateClass() const { return m_rateclass; }
00747 unsigned int getWindowSize() const { return m_windowsize; }
00749 unsigned int getClear() const { return m_clear; }
00751 unsigned int getAlert() const { return m_alert; }
00753 unsigned int getLimit() const { return m_limit; }
00755 unsigned int getDisconnect() const { return m_disconnect; }
00757 unsigned int getCurrentAvg() const { return m_currentavg; }
00759 unsigned int getMaxAvg() const { return m_maxavg; }
00760 };
00761
00762 }
00763
00764 #endif