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 using std::string;
00038
00039 namespace ICQ2000 {
00040
00041 class Contact;
00042
00043
00044
00045
00046
00051 class Event {
00052 protected:
00056 time_t m_time;
00057
00058 public:
00059 Event();
00060 Event(time_t t);
00061
00062 time_t getTime() const;
00063 void setTime(time_t t);
00064 };
00065
00066
00067
00068
00069
00073 class SocketEvent : public Event {
00074 private:
00075 int m_fd;
00076
00077 public:
00078 SocketEvent(int fd);
00079 virtual ~SocketEvent();
00080
00081 int getSocketHandle() const;
00082
00086 enum Mode {
00087 READ = 1 << 0,
00088 WRITE = 1 << 1,
00089 EXCEPTION = 1 << 2
00090 };
00091 };
00092
00098 class AddSocketHandleEvent : public SocketEvent {
00099 private:
00100 Mode m_mode;
00101
00102 public:
00103 AddSocketHandleEvent(int fd, Mode m);
00104
00105 Mode getMode() const;
00106 bool isRead() const;
00107 bool isWrite() const;
00108 bool isException() const;
00109 };
00110
00116 class RemoveSocketHandleEvent : public SocketEvent {
00117 public:
00118 RemoveSocketHandleEvent(int fd);
00119 };
00120
00121
00122
00123
00124
00129 class ConnectedEvent : public Event {
00130 public:
00131 ConnectedEvent();
00132 };
00133
00134
00135
00136
00137
00143 class DisconnectedEvent : public Event {
00144 public:
00148 enum Reason {
00149 REQUESTED,
00150 FAILED_LOWLEVEL,
00151 FAILED_BADUSERNAME,
00152 FAILED_TURBOING,
00153 FAILED_BADPASSWORD,
00154 FAILED_MISMATCH_PASSWD,
00155 FAILED_DUALLOGIN,
00156 FAILED_UNKNOWN
00157 };
00158
00159 private:
00160 Reason m_reason;
00161
00162 public:
00163 DisconnectedEvent(Reason r);
00164
00165 Reason getReason() const;
00166 };
00167
00168
00169
00170
00171
00175 class LogEvent : public Event {
00176 public:
00180 enum LogType {
00181 WARN,
00182 ERROR,
00183 INFO,
00184 PACKET,
00185 DIRECTPACKET
00186 };
00187
00188 private:
00189 LogType m_type;
00190 string m_msg;
00191
00192 public:
00193 LogEvent(LogType type, const string& msg);
00194
00195 LogType getType() const;
00196 string getMessage() const;
00197 };
00198
00199
00200
00201
00202
00206 class ContactListEvent : public Event {
00207 public:
00211 enum EventType {
00212 UserAdded,
00213 UserRemoved
00214 };
00215
00216 protected:
00220 ContactRef m_contact;
00221
00222 public:
00223 ContactListEvent(ContactRef c);
00224 virtual ~ContactListEvent();
00225
00226 ContactRef getContact() const;
00227 unsigned int getUIN() const;
00228
00234 virtual EventType getType() const = 0;
00235 };
00236
00240 class UserAddedEvent : public ContactListEvent {
00241 public:
00242 UserAddedEvent(ContactRef c);
00243 EventType getType() const;
00244 };
00245
00249 class UserRemovedEvent : public ContactListEvent {
00250 public:
00251 UserRemovedEvent(ContactRef c);
00252 EventType getType() const;
00253 };
00254
00255
00256
00257
00258
00262 class ContactEvent : public Event {
00263 public:
00267 enum EventType {
00268 StatusChange,
00269 UserInfoChange,
00270 };
00271
00272 protected:
00276 ContactRef m_contact;
00277
00278 public:
00279 ContactEvent(ContactRef c);
00280 virtual ~ContactEvent();
00281
00282 ContactRef getContact() const;
00283 unsigned int getUIN() const;
00284
00290 virtual EventType getType() const = 0;
00291 };
00292
00296 class UserInfoChangeEvent : public ContactEvent {
00297 private:
00298 bool m_is_transient_detail;
00299 public:
00300 UserInfoChangeEvent(ContactRef c, bool is_transient_detail);
00301 EventType getType() const;
00302 bool isTransientDetail() const;
00303 };
00304
00308 class StatusChangeEvent : public ContactEvent {
00309 private:
00310 Status m_status;
00311 Status m_old_status;
00312
00313 public:
00314 StatusChangeEvent(ContactRef contact, Status status, Status old_status);
00315
00316 EventType getType() const;
00317 Status getStatus() const;
00318 Status getOldStatus() const;
00319 };
00320
00321
00322
00323
00324
00329 class MessageEvent : public Event {
00330 public:
00334 enum MessageType {
00335 Normal,
00336 URL,
00337 SMS,
00338 SMS_Receipt,
00339 AuthReq,
00340 AuthAck,
00341 AwayMessage,
00342 EmailEx,
00343 UserAdd,
00344 Email
00345 };
00346
00347 enum DeliveryFailureReason {
00348 Failed,
00349 Failed_NotConnected,
00350 Failed_ClientNotCapable,
00351 Failed_Denied,
00352 Failed_Occupied,
00353 Failed_DND,
00354 Failed_SMTP
00355 };
00356
00357 protected:
00359 ContactRef m_contact;
00361 bool m_finished;
00363 bool m_delivered;
00365 bool m_direct;
00366
00367 DeliveryFailureReason m_failure_reason;
00368
00369 public:
00370 MessageEvent(ContactRef c);
00371 virtual ~MessageEvent();
00372
00378 virtual MessageType getType() const = 0;
00379 ContactRef getContact();
00380
00381 bool isFinished() const;
00382 bool isDelivered() const;
00383 bool isDirect() const;
00384
00385 void setFinished(bool f);
00386 void setDelivered(bool f);
00387 void setDirect(bool f);
00388
00389 DeliveryFailureReason getDeliveryFailureReason() const;
00390 void setDeliveryFailureReason(DeliveryFailureReason d);
00391 };
00392
00396 class ICQMessageEvent : public MessageEvent {
00397 private:
00398 bool m_urgent, m_tocontactlist, m_offline;
00399 std::string m_away_message;
00400
00401 public:
00402 ICQMessageEvent(ContactRef c);
00403
00404 bool isUrgent() const;
00405 void setUrgent(bool b);
00406 bool isToContactList() const;
00407 void setToContactList(bool b);
00408 bool isOfflineMessage() const;
00409 void setOfflineMessage(bool b);
00410 unsigned int getSenderUIN() const;
00411 std::string getAwayMessage() const;
00412 void setAwayMessage(const std::string& msg);
00413 };
00414
00418 class NormalMessageEvent : public ICQMessageEvent {
00419 private:
00420 string m_message;
00421 bool m_multi;
00422 unsigned int m_foreground, m_background;
00423
00424 public:
00425 NormalMessageEvent(ContactRef c, const string& msg, bool multi = false);
00426 NormalMessageEvent(ContactRef c, const string& msg, time_t t, bool multi);
00427 NormalMessageEvent(ContactRef c, const string& msg, unsigned int fg, unsigned int bg);
00428
00429 string getMessage() const;
00430 MessageType getType() const;
00431 bool isMultiParty() const;
00432 unsigned int getForeground() const;
00433 unsigned int getBackground() const;
00434 void setForeground(unsigned int f);
00435 void setBackground(unsigned int b);
00436 };
00437
00441 class URLMessageEvent : public ICQMessageEvent {
00442 private:
00443 string m_message, m_url;
00444
00445 public:
00446 URLMessageEvent(ContactRef c, const string& msg, const string& url);
00447 URLMessageEvent(ContactRef c, const string& msg, const string& url, time_t t);
00448
00449 string getMessage() const;
00450 string getURL() const;
00451 MessageType getType() const;
00452 };
00453
00457 class SMSMessageEvent : public MessageEvent {
00458 private:
00459 string m_message, m_source, m_sender, m_senders_network;
00460 string m_smtp_from, m_smtp_to, m_smtp_subject;
00461 bool m_rcpt;
00462
00463 public:
00464 SMSMessageEvent(ContactRef c, const string& msg, bool rcpt);
00465 SMSMessageEvent(ContactRef c, const string& msg, const string& source,
00466 const string& senders_network, const string& time);
00467
00468 string getMessage() const;
00469 MessageType getType() const;
00470 string getSource() const;
00471 string getSender() const;
00472 string getSenders_network() const;
00473 bool getRcpt() const;
00474
00475 void setSMTPFrom(const string& from);
00476 string getSMTPFrom() const;
00477
00478 void setSMTPTo(const string& to);
00479 string getSMTPTo() const;
00480
00481 void setSMTPSubject(const string& subj);
00482 string getSMTPSubject() const;
00483 };
00484
00488 class SMSReceiptEvent : public MessageEvent {
00489 private:
00490 string m_message, m_message_id, m_destination, m_submission_time, m_delivery_time;
00491 bool m_delivered;
00492
00493 public:
00494 SMSReceiptEvent(ContactRef c, const string& msg, const string& message_id,
00495 const string& submission_time, const string& delivery_time, bool del);
00496
00497 MessageType getType() const;
00498 string getMessage() const;
00499 string getMessageId() const;
00500 string getDestination() const;
00501 string getSubmissionTime() const;
00502 string getDeliveryTime() const;
00503 bool delivered() const;
00504 };
00505
00513 class AwayMessageEvent : public ICQMessageEvent {
00514 public:
00515 AwayMessageEvent(ContactRef c);
00516
00517 MessageType getType() const;
00518 };
00519
00523 class AuthReqEvent : public ICQMessageEvent {
00524 private:
00525 string m_message;
00526
00527 public:
00528 AuthReqEvent(ContactRef c, const string& msg);
00529 AuthReqEvent(ContactRef c, const string& msg, time_t time);
00530
00531 string getMessage() const;
00532 MessageType getType() const;
00533 };
00534
00538 class AuthAckEvent : public ICQMessageEvent {
00539 private:
00540 string m_message;
00541 bool m_granted;
00542
00543 public:
00544 AuthAckEvent(ContactRef c, bool granted);
00545 AuthAckEvent(ContactRef c, bool granted, time_t time);
00546 AuthAckEvent(ContactRef c, const string& msg, bool granted);
00547 AuthAckEvent(ContactRef c, const string& msg, bool granted, time_t time);
00548
00549 string getMessage() const;
00550 MessageType getType() const;
00551 bool isGranted() const;
00552 };
00553
00557 class EmailExEvent : public MessageEvent {
00558 private:
00559 string m_sender, m_email, m_message;
00560
00561 public:
00562 EmailExEvent(ContactRef c, const string &email, const string &sender, const string &msg);
00563
00564 string getMessage() const;
00565 string getEmail() const;
00566 string getSender() const;
00567
00568 MessageType getType() const;
00569 unsigned int getSenderUIN() const;
00570 };
00571
00575 class UserAddEvent : public ICQMessageEvent {
00576 public:
00577 UserAddEvent(ContactRef c);
00578
00579 MessageType getType() const;
00580 unsigned int getSenderUIN() const;
00581 };
00582
00586 class EmailMessageEvent : public MessageEvent {
00587 private:
00588 string m_message;
00589
00590 public:
00591 EmailMessageEvent(ContactRef c, const string &msg);
00592
00593 string getMessage() const;
00594
00595 MessageType getType() const;
00596 };
00597
00598
00599
00600
00601
00605 class SearchResultEvent : public Event {
00606 public:
00607 enum SearchType {
00608 ShortWhitepage,
00609 FullWhitepage,
00610 UIN,
00611 Keyword
00612 };
00613
00614 private:
00615 bool m_finished, m_expired;
00616 SearchType m_searchtype;
00617 ContactList m_clist;
00618 ContactRef m_last_contact;
00619 unsigned int m_more_results;
00620
00621 public:
00622 SearchResultEvent(SearchType t);
00623
00624 SearchType getSearchType() const;
00625 ContactList& getContactList();
00626 ContactRef getLastContactAdded() const;
00627 void setLastContactAdded(ContactRef c);
00628 unsigned int getNumberMoreResults() const;
00629
00630 bool isFinished() const;
00631 void setFinished(bool b);
00632 bool isExpired() const;
00633 void setExpired(bool b);
00634 void setNumberMoreResults(unsigned int m);
00635 };
00636
00640 class ServerBasedContactEvent : public Event {
00641 private:
00642 ContactList m_clist;
00643 public:
00644 ServerBasedContactEvent(const ContactList& l);
00645 ContactList& getContactList();
00646 };
00647
00648
00649
00650
00651
00655 class NewUINEvent : public Event {
00656 private:
00657 unsigned int m_uin;
00658 bool m_success;
00659
00660 public:
00661 NewUINEvent(unsigned int uin, bool success=true);
00662 unsigned int getUIN() const;
00663 bool isSuccess() const;
00664 };
00665
00669 class RateInfoChangeEvent : public Event {
00670 public:
00674 enum RateClass {
00675 RATE_CHANGE=1,
00676 RATE_WARNING,
00677 RATE_LIMIT,
00678 RATE_LIMIT_CLEARED
00679 };
00680
00681 private:
00682 unsigned short m_code;
00683 unsigned short m_rateclass;
00684 unsigned int m_windowsize;
00685 unsigned int m_clear;
00686 unsigned int m_alert;
00687 unsigned int m_limit;
00688 unsigned int m_disconnect;
00689 unsigned int m_currentavg;
00690 unsigned int m_maxavg;
00691
00692 public:
00693 RateInfoChangeEvent(unsigned short code, unsigned short rateclass,
00694 unsigned int windowsize,unsigned int clear,
00695 unsigned int alert,unsigned int limit,
00696 unsigned int disconnect,unsigned int currentavg,
00697 unsigned int maxavg);
00698
00700 unsigned short getCode() const { return m_code; }
00702 unsigned short getRateClass() const { return m_rateclass; }
00704 unsigned int getWindowSize() const { return m_windowsize; }
00706 unsigned int getClear() const { return m_clear; }
00708 unsigned int getAlert() const { return m_alert; }
00710 unsigned int getLimit() const { return m_limit; }
00712 unsigned int getDisconnect() const { return m_disconnect; }
00714 unsigned int getCurrentAvg() const { return m_currentavg; }
00716 unsigned int getMaxAvg() const { return m_maxavg; }
00717 };
00718
00719 }
00720
00721 #endif