home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 4 / AACD04.ISO / AACD / Programming / icqsocket / include / libraries / icqsocket.h next >
Encoding:
C/C++ Source or Header  |  1999-10-25  |  12.1 KB  |  475 lines

  1. #ifndef LIBRARIES_ICQSOCKET_H
  2. #define LIBRARIES_ICQSOCKET_H
  3.  
  4. #ifndef EXEC_LIBRARIES_H
  5. #include <exec/libraries.h>
  6. #endif
  7.  
  8. #ifndef UTILITY_HOOKS_H
  9. #include <utility/hooks.h>
  10. #endif
  11.  
  12. #ifndef UTILITY_TAGITEM_H
  13. #include <utility/tagitem.h>
  14. #endif
  15.  
  16. #include <libraries/llist.h>
  17.  
  18. //
  19. // Tags for is_Init()
  20. //
  21.  
  22. #define ISS_LogFile    (TAG_USER+100)    // (STRPTR) Filename for the message log, default is
  23.                     //          S:ICQ<UIN>.msglog
  24. #define ISS_DataFile    (TAG_USER+101)    // (STRPTR) Filename for the database, default is
  25.                     //          S:ICQ<UIN>.config
  26.  
  27. //
  28. // Tags for is_Connect()
  29. //
  30.  
  31. #define ISS_Host    (TAG_USER+1)    // (STRPTR) Host adress, defaults to icq1.mirabilis.com
  32. #define ISS_Port    (TAG_USER+2)    // (ULONG)  Port, defaults to 4000
  33. #define ISS_Direct    (TAG_USER+3)    // (BOOL)   Accept direct connections
  34. #define ISS_Status    (TAG_USER+4)    // (ULONG)  Status, defaults to online.
  35. #define ISS_Resend    (TAG_USER+5)    // (ULONG)  Number of resends before an error event is generated
  36. #define ISS_Password    (TAG_USER+6)    // (STRPTR) Password
  37.  
  38. //
  39. // Client to server message types (commands) for is_Send().
  40. //
  41.  
  42. #define ISC_NewStatus        (100)    // Set new status
  43.                     // (ULONG status)
  44. #define ISC_TextMessage        (101)    // Send text message
  45.                     // (ULONG recipentUIN, STRPTR message)
  46. #define ISC_URLMessage        (102)    // Send URL message
  47.                     // (ULONG recipentUIN, STRPTR URL, STRPTR description)
  48. #define ISC_ContactMessage    (103)    // Send contacts to user
  49. #define ISC_AuthorizeMessage    (104)    // Authorize remote user
  50.                     // (ULONG UIN)
  51. #define ISC_UserAddedMessage    (105)    // Tell remote user he/she has been added
  52.                     // (ULONG recipentUIN, STRPTR Nick, STRPTR First,
  53.                     //  STRPTR Last, STRPTR Email)
  54. #define ISC_RequestAuth        (109)    // Request Authorization
  55.                     // (ULONG recipentUIN, STRPTR Nick, STRPTR First,
  56.                     //  STRPTR Last, STRPTR Email, STRPTR Reason)
  57. //#define ISC_UINLookup        (110)    // Request user info
  58.                     // (ULONG UIN)
  59. //#define ISC_UINLookupExt    (111)    // Request extended user info
  60.                     // (ULONG UIN)
  61. //#define ISC_Contacts        (200)    // Send contacts to server
  62.                     // (UBYTE num_contacts, ULONG *contarray)
  63. //#define ISC_Visible        (201)    // Visible list
  64. //#define ISC_Invisible        (202)    // Invisible list
  65. //#define ISC_SearchUIN        (300)    // Search for a user (UIN)
  66. //#define ISC_SearchUser        (301)    // Search for a user (name/email)
  67. //#define ISC_ChangePW        (400)    // Change password
  68. //#define ISC_UpdateInfo        (401)    // Update user info
  69. //#define ISC_UpdateInfoExt    (402)    // Update user info (ext)
  70. #define ISC_NewUser        (500)    // Register a new user
  71.                     // (STRPTR password)
  72. #define ISC_NewUserInfo        (501)    // Set the 'new user info'
  73.                     // (STRPTR nick, first, last, email)
  74. #define ISC_RandSearch        (600)    // Find a random user
  75.                     // (UWORD Group)
  76. #define ISC_RandSet        (601)    // Set random info
  77.  
  78. //
  79. // ICQ's 'datestamp'
  80. //
  81.  
  82. typedef struct {
  83.     UWORD    Year;
  84.     UBYTE    Month;
  85.     UBYTE    Day;
  86.     UBYTE    Hour;
  87.     UBYTE    Minute;
  88. } ICQTime;
  89.  
  90. //
  91. // ICQ packet header (server side, for error reporting)
  92. //
  93.  
  94. typedef struct {
  95.     UWORD    Version;
  96.     UWORD    Command;
  97.     ULONG    SID;
  98.     ULONG    UIN;
  99.     ULONG    Seq;
  100.     UBYTE    *Data;
  101. } ICQHeader;
  102.  
  103. //
  104. // ID numbers for callback hooks
  105. //
  106. // The hook functions will recieve a pointer to one of the structures
  107. // defined below.
  108. //
  109. // Example:
  110. //
  111. // ULONG __saveds __asm MyICQMsgFunc( register __a0 struct Hook *hook,
  112. //                      register __a1 ICQMessage *msg )
  113. // {
  114. //    /* Handle the message here. The data remains valid only
  115. //       until the function returns, so you must copy strings
  116. //       etc.
  117. //       hook->h_Data is a user data field, and can be used for
  118. //       whatever you want. */
  119. // }
  120. //
  121. // struct Hook MyICQMsgHook {
  122. //    { NULL, NULL },
  123. //    &MyICQMsgFunc,
  124. //    NULL,
  125. //    "User data"
  126. // };
  127. //
  128. // To install this hook, use
  129. //
  130. // is_InstallHook( IID_MESSAGE, &MyICQMsgHook );
  131. //
  132. // See below for other hook ID's:
  133. //
  134.  
  135. enum ICQHookID {
  136.     IID_MESSAGE=1,        // We recieved a message
  137.     IID_USERINFO,        // User Info reply
  138.     IID_STATUS,        // A user changed her status
  139.     IID_USERFOUND,        // A sought user is found
  140.     IID_ERROR,        // Error
  141.     IID_LOGIN,        // Login is completed
  142.     IID_END_OF_SEARCH,    // No more user_found's will be sent
  143.     IID_UPDATE_SUCCESS,    // User Info update succeded
  144.     IID_NEW_UIN,        // A new UIN for a new user
  145.     IID_RAND,        // Random user found
  146.     IID_USER_ADDED,        // An unknown (or random) user has
  147.                 // interacted with you, and has been
  148.                 // added to the list of unknown users.
  149.     IID_TIMER_EVENT,    // Occurs twice every second after
  150.                 // is_Init has been called.
  151.                 // This hook is intended for use with
  152.                 // flashing symbols, like the Mirabilis'
  153.                 // client does. Internally this interval
  154.                 // is used for 'keep alive' and resends.
  155.  
  156.     MAX_HOOKS
  157. };
  158.  
  159. //
  160. // Message
  161. //
  162.  
  163. typedef struct {
  164.     ULONG    Size;        // Size of the structure
  165.     ULONG    UIN;
  166.     ICQTime    Time;        // When the msg was sent
  167.     UBYTE    Type;        // See below for definitions
  168.     BOOL    Instant;    // TRUE if the message has been instantly delivered
  169.                 // FALSE if the message has waited on the server before delivery
  170.     char    Msg[0];        // Message text, NULL terminated
  171.                 // Fields are separated by 0xFE
  172. } ICQMessage;
  173.  
  174. typedef struct {
  175.     LINK_INFO;
  176.     ICQMessage    im;
  177. } LogMessage;
  178.  
  179. #define MST_TEXT    0x0001    // Plain text message
  180. #define MST_URL        0x0004    // URL (first description, then URL, separated by 0xFE = 'รพ')
  181. #define MST_REQAUTH    0x0006    // Authorization request
  182. #define MST_AUTHORIZE    0x0008    // Authorization recieved
  183. #define MST_USERADDED    0x000C    // A user added us to his/her list
  184. #define MST_CONTACTS    0x0013    // Contact list
  185.  
  186. //#define MST_MASS_MASK    0x8000    //
  187.  
  188. //
  189. // User database entry
  190. //
  191.  
  192. typedef struct {
  193.     struct LinkList ll;    // Contains extendend info (private)
  194.     ULONG        UIN;    // UIN of this user
  195.     ULONG        Status;    // User's status
  196.     ULONG        IP;    // IP adress for TCP
  197.     ULONG        Port;    // Port for TCP
  198.     UWORD        TCPVer;    // TCP message version
  199.     UWORD        Age;    // Age of user
  200.     UWORD        CCode;    // Country code
  201.     UWORD        TZone;    // Time zone
  202.     UBYTE        Sex;    // User's gender
  203.     ULONG        Online;    // Last time seen online
  204.     BOOL        Direct;    // Accepts direct connections
  205.     char        Nick[0]; // User's nickname
  206. } ICQUser;
  207.  
  208. // Reserved string ID's
  209. #define    ICQC_FIRSTNAME    102
  210. #define    ICQC_LASTNAME    103
  211. #define    ICQC_EMAIL_1    104
  212. #define    ICQC_EMAIL_2    105
  213. #define    ICQC_EMAIL_3    106
  214. #define    ICQC_PHONE_1    107
  215. #define    ICQC_PHONE_2    108
  216. #define    ICQC_WEB    120
  217. #define    ICQC_CITY    125
  218. #define    ICQC_NOTES    500
  219.  
  220. // User string ID's (1000 - 31500)
  221. #define ICQC_USERSTRING    1000
  222.  
  223. typedef struct {
  224.     LINK_INFO;
  225.     char Str[0];
  226. } ICQString;
  227.  
  228. //
  229. // User Info
  230. //
  231.  
  232. typedef struct {
  233.     ULONG    UIN;
  234.  
  235.     STRPTR    Nick;
  236.     STRPTR    First;
  237.     STRPTR    Last;
  238.     STRPTR    EMail;
  239.  
  240.     UWORD    Age;
  241.     UWORD    CountryCode;
  242.     UWORD    TimeZone;
  243.     UBYTE    Sex;        // 'M', 'F' or '?'
  244.     UBYTE    Reserved1;
  245.     STRPTR    City;
  246.     STRPTR    State;
  247.     STRPTR    Phone;
  248.     STRPTR    Home;
  249.     STRPTR    About;
  250. } ICQInfo;
  251.  
  252. #define UIT_BASIC    1    // The structure contains basic user info
  253. #define UIT_EXTENDED    2    // The structure contains extended info
  254.  
  255. #define DB_UNKNOWN    1    // Unknown users
  256. #define DB_RANDOM    2    // Random users
  257. #define DB_CONTACTS    3    // Contact list users
  258.  
  259. //
  260. // Random user
  261. //
  262.  
  263. typedef struct {
  264.     BOOL    Found;    // TRUE -> A user was found, details follow. FALSE -> No random user found
  265.     ULONG    UIN;    // Random user's UIN
  266.     ULONG    IP;    // User's IP
  267.     ULONG    Port;    // Port    
  268.     BOOL    Direct;    // TRUE -> Accepts direct connections
  269.     ULONG    Status;    // The user's status
  270.     UWORD    TCPVer;    // TCP version
  271. } ICQRandomUser;
  272.  
  273. //
  274. // Random chat groups
  275. //
  276.  
  277. #define GRP_GENERAL    1
  278. #define GRP_ROMANCE    2
  279. #define GRP_GAMES    3
  280. #define GRP_STUDENTS    4
  281. #define GRP_20        6
  282. #define GRP_30        5
  283. #define GRP_40        8
  284. #define GRP_50        9
  285. #define GRP_REQ_WOMEN    10
  286. #define GRP_REQ_MEN    11
  287.  
  288. //
  289. // Status Update
  290. //
  291.  
  292. typedef struct {
  293.     ULONG    UIN;
  294.     ULONG    Status;    // User's new status
  295.     UWORD    Type;    // see below
  296.  
  297.     // The fields below is only valid for SUT_ONLINE!
  298.     ULONG    IP;
  299.     ULONG    Port;    // The port to connect to
  300.     ULONG    RealIP;    // The IP to make connections to
  301.     UWORD    TCP;    // ICQ TCP Version
  302.     BOOL    Direct;    // TRUE -> Client accepts direct connections
  303. } ICQStatusUpdate;
  304.  
  305. #define SUT_ONLINE    1    // User went online - remember port and ip!
  306. #define SUT_OFFLINE    2    // User went offline
  307. #define SUT_UPDATE    3    // User changed her/his status
  308.  
  309. //
  310. // User Found
  311. //
  312.  
  313. typedef struct {
  314.     ULONG    UIN;
  315.     STRPTR    Nick;
  316.     STRPTR    First;
  317.     STRPTR    Last;
  318.     STRPTR    EMail;
  319.     BOOL    Auth;    // Authorization required
  320.     UBYTE    X1;    // Unknown
  321. } ICQUserFound;
  322.  
  323. //
  324. // End of Search
  325. //
  326.  
  327. typedef struct {
  328.     BOOL TooMany;    // The search generated too many results
  329. } ICQEndOfSearch;
  330.  
  331. //
  332. // Error
  333. //
  334.  
  335. typedef struct {
  336.     ULONG        SokErr;    // bsdsocket.library error code, or NULL
  337.     ULONG        ICQErr;    // ICQSocket error code, or NULL
  338.     ICQHeader    *Hdr;    // Header of unknown messages (ICQERR_UNKNOWN and ICQERR_BAD_VERSION)
  339. } ICQError;
  340.  
  341. // Protocol errors: (for socket errs see sys/errno.h)
  342.  
  343. #define ICQERR_BAD_PASS        1    // Bad password
  344. #define ICQERR_GO_AWAY        2    // Server is forcing us to disconnect
  345. #define ICQERR_ERROR        3    // Server tells us something's wrong, and it won't listen to us any more. (disconnect)
  346. #define ICQERR_BUSY        4    // Server is busy, "try in a few seconds".
  347. #define ICQERR_UNKNOWN        5    // Unrecognized msg recieved.
  348. #define ICQERR_SPOOFED        6    // Someone tried to send a spoofed message
  349. #define ICQERR_BAD_VERSION    7    // A packet with unknown version was recieved
  350.  
  351. #define ICQERR_MEM        100    // Out of memory
  352.  
  353. //
  354. // Login Successful
  355. //
  356.  
  357. typedef struct {
  358.     int x;
  359. } ICQLogin;
  360.  
  361. //
  362. // Return codes for is_Login()
  363. //
  364.  
  365. #define OK        0
  366. #define ERR_MEM        -1
  367. #define ERR_HOSTNAME    -2
  368. #define ERR_CONNECT    -3
  369. #define ERR_SOCKET    -4
  370. #define ERR_SOCKLIB    -5
  371.  
  372. struct ICQSocketBase {
  373.     struct Library    is_Library;
  374.     ULONG        is_SegList;
  375.     ULONG        is_Flags;
  376. };
  377.  
  378. //
  379. // ICQHandle structure
  380. //
  381.  
  382. #define MAX_DUPCHK    64        // more than enough
  383.  
  384. typedef struct {
  385.     ULONG        UIN;        // Theese are _READ_ONLY_
  386.     ULONG        SID;        //
  387.     ULONG        Version;    //
  388.     ULONG        Port;        //
  389.     ULONG        IP;        //
  390.     ULONG        Status;        //
  391.  
  392. #ifdef ICQSOCKET_PRIVATE
  393.     LONG        UDPSocket;        // Socket
  394.     struct Hook    *HookTable[MAX_HOOKS];    // Callback hooks
  395.     fd_set        rd;            //
  396.     struct timerequest    *timer;        // Timer
  397.     struct MsgPort        *tp;        // Timer port
  398.     ULONG        halfsecs;        // 1/2 seconds elapsed since is_Init
  399.     struct LinkList    *Contacts;        // Known contacts
  400.     struct LinkList    *RandomUsers;        // Random contacts
  401.     struct LinkList    *UnknownUsers;        // Unknown contacts
  402.     LONG        MsgLog;            // Message log
  403.     LONG        Console;        // eh?
  404.     struct LinkList    *NotifyList;        // Hooks to call when ack is recieved
  405.     struct LinkList    *AckList;        // Packets waiting for acks
  406.     ULONG        UsedSeqs[MAX_DUPCHK];    // Used seq's for incoming packets
  407.     ULONG        SeqCtr;            // Counter for above
  408.     UWORD        Seq1;            // Sequence numbers (outgoing)
  409.     UWORD        Seq2;            // Sequence numbers (outgoing)
  410.     ICQMessage    *imsg;            // Temp. pointer
  411.     LogMessage    *lmsg;            // Temp. pointer
  412.     struct LinkList    *MsgQueue;        // Queue of incomming messages
  413.     char        CfgFile[180];        // Filename of cfg file
  414.     char        LogFile[180];        // Filename of log file
  415.  
  416.     struct ICQCfgHdr {
  417.         char        ID[4];        // ISoc
  418.         ULONG        Version;    // 1
  419.         ULONG        Key;        // Encryption key
  420.         char        Pass[64];    // Encrypted password
  421.         UBYTE        Reserved[256];    
  422.     } Config;
  423. #endif
  424.  
  425. } ICQHandle;
  426.  
  427. //
  428. // Prototypes
  429. //
  430.  
  431. ICQHandle *is_InitA(ULONG uin, struct TagItem *tags);
  432. void is_Free(ICQHandle *ih);
  433.  
  434. // Debug
  435. void is_Debug(LONG fh, LONG flags);
  436.  
  437. // Connect/disconnect
  438. ULONG is_ConnectA(ICQHandle *, struct TagItem *tags);
  439. ULONG is_Connect(ICQHandle *, ULONG, ...);
  440. void is_Disconnect(ICQHandle *);
  441. ULONG is_NetWait(ICQHandle *, ULONG signals);
  442.  
  443. // Notification
  444. void is_AddAckNot(ICQHandle *, struct Hook *h, ULONG seq, APTR ud);
  445. void is_RemAckNot(ICQHandle *, ULONG seq);
  446. void is_InstallHook(ICQHandle *, ULONG id, struct Hook *hook);
  447.  
  448. // Send packets
  449. ULONG is_Send(ICQHandle *, struct Hook *ack, ULONG command, ...);
  450. ULONG is_SendA(ICQHandle *, struct Hook *ack, ULONG *command);
  451.  
  452. // Database
  453. BOOL is_AddUIN(ICQHandle *, ULONG uin);
  454. BOOL is_AddUINQ(ICQHandle *, ULONG uin);
  455. BOOL is_RemUIN(ICQHandle *, ULONG uin);
  456. ICQUser *is_FindUIN(ICQHandle *, ULONG uin);
  457. BOOL is_OpenDatabase(ICQHandle *, ULONG db);
  458. void is_CloseDatabase(ICQHandle *, ULONG db);
  459. ICQUser *is_GetEntry(ICQHandle *, ULONG db);
  460. STRPTR is_GetString(ICQHandle *, ICQUser *user, UWORD id);
  461. BOOL is_SetString(ICQHandle *, ICQUser *user, UWORD id, STRPTR str);
  462.  
  463. // Message queue
  464. BOOL is_QueryQueue(ICQHandle *, ULONG uin);
  465. BOOL is_OpenMsgQueue(ICQHandle *);
  466. void is_CloseMsgQueue(ICQHandle *);
  467. ICQMessage *is_GetQueuedMsg(ICQHandle *, ULONG uin);
  468.  
  469. // Message log
  470. BOOL is_OpenMsgLog(ICQHandle *);
  471. void is_CloseMsgLog(ICQHandle *);
  472. ICQMessage *is_GetLoggedMsg(ICQHandle *, ULONG uin);
  473.  
  474. #endif
  475.