Mercurial > pidgin
annotate plugins/icq/eventhandle.c @ 1840:00aef397a1fe
[gaim-migrate @ 1850]
reworked some of the proxy stuff so that it's non-blocking now. next thing to do is to get IRC, MSN, Napster, and Jabber to use the new proxy_connect code. After that, Oscar and Yahoo (maybe Zephyr too? not likely)
committer: Tailor Script <tailor@pidgin.im>
| author | Eric Warmenhoven <eric@warmenhoven.org> |
|---|---|
| date | Sat, 12 May 2001 01:38:04 +0000 |
| parents | 4c510ca3563f |
| children | 8ed70631ed15 |
| rev | line source |
|---|---|
| 1309 | 1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
| 2 | |
| 3 /* | |
|
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
4 * $Id: eventhandle.c 1442 2001-01-28 01:52:27Z warmenhoven $ |
| 1309 | 5 * |
| 6 * $Log$ | |
|
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
7 * Revision 1.2 2001/01/28 01:52:27 warmenhoven |
|
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
8 * icqlib 1.1.5 |
| 1309 | 9 * |
| 10 * Revision 1.3 2000/12/19 06:00:07 bills | |
| 11 * moved members from ICQLINK to ICQLINK_private struct | |
| 12 * | |
| 13 * Revision 1.1 2000/06/15 18:50:03 bills | |
| 14 * committed for safekeeping - this code will soon replace tcphandle.c | |
| 15 * | |
| 16 */ | |
| 17 | |
| 18 #include <time.h> | |
| 19 | |
| 20 #ifndef _WIN32 | |
| 21 #include <unistd.h> | |
| 22 #endif | |
| 23 | |
| 24 #include "icqevent.h" | |
| 25 #include "icqpacket.h" | |
| 26 #include "tcplink.h" | |
| 27 #include "chatsession.h" | |
| 28 #include "filesession.h" | |
| 29 | |
| 30 #include "eventhandle.h" | |
| 31 | |
| 32 void icq_TCPProcessPacket2(icq_Packet *p, icq_TCPLink *plink) | |
| 33 { | |
| 34 icq_MessageEvent *pevent=(icq_MessageEvent *)icq_ParsePacket(p); | |
| 35 icq_Event *pbase=(icq_Event *)pevent; | |
| 36 | |
| 37 ICQLINK *icqlink=plink->icqlink; | |
| 38 | |
| 39 if (pbase->uin != plink->remote_uin) | |
| 40 { | |
| 41 /* TODO: spoofed packet! */ | |
| 42 } | |
| 43 | |
| 44 pbase->handleEvent(pbase, icqlink); | |
| 45 | |
| 46 /* notify library client than the ack was received from remote client */ | |
| 47 if (pbase->subtype==ICQ_EVENT_ACK) | |
| 48 { | |
| 49 icq_FmtLog(plink->icqlink, ICQ_LOG_MESSAGE, "received ack %d\n", p->id); | |
| 50 if(icqlink->icq_RequestNotify) | |
| 51 { | |
| 52 (*icqlink->icq_RequestNotify)(icqlink, pbase->id, | |
| 53 ICQ_NOTIFY_ACK, pevent->status, (void *)pevent->message); | |
| 54 (*icqlink->icq_RequestNotify)(icqlink, pbase->id, | |
| 55 ICQ_NOTIFY_SUCCESS, 0, 0); | |
| 56 } | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 void icq_HandleMessageEvent(icq_Event *pbase, ICQLINK *icqlink) | |
| 61 { | |
| 62 icq_MessageEvent *pevent=(icq_MessageEvent *)pbase; | |
| 63 struct tm *ptime=localtime(&(pbase->time)); | |
| 64 | |
| 65 if (pbase->subtype==ICQ_EVENT_MESSAGE && icqlink->icq_RecvMessage) | |
| 66 { | |
| 67 (*icqlink->icq_RecvMessage)(icqlink, pbase->uin, ptime->tm_hour, | |
| 68 ptime->tm_min, ptime->tm_mday, ptime->tm_mon+1, | |
| 69 ptime->tm_year+1900, pevent->message); | |
| 70 /* TODO: send ack */ | |
| 71 } | |
| 72 | |
| 73 } | |
| 74 | |
| 75 void icq_HandleURLEvent(icq_Event *pbase, ICQLINK *icqlink) | |
| 76 { | |
| 77 icq_URLEvent *pevent=(icq_URLEvent *)pbase; | |
| 78 struct tm *ptime=localtime(&(pbase->time)); | |
| 79 | |
| 80 if (pbase->subtype==ICQ_EVENT_MESSAGE && icqlink->icq_RecvURL) | |
| 81 { | |
| 82 (*icqlink->icq_RecvURL)(icqlink, pbase->uin, ptime->tm_hour, | |
| 83 ptime->tm_min, ptime->tm_mday, ptime->tm_mon+1, | |
| 84 ptime->tm_year+1900, pevent->url, pevent->message); | |
| 85 /* TODO: send ack */ | |
| 86 } | |
| 87 } | |
| 88 | |
| 89 void icq_HandleChatRequestEvent(icq_Event *pbase, ICQLINK *icqlink) | |
| 90 { | |
| 91 icq_ChatRequestEvent *pevent=(icq_ChatRequestEvent *)pbase; | |
| 92 icq_MessageEvent *pmsgevent=(icq_MessageEvent *)pmsgevent; | |
| 93 | |
| 94 struct tm *ptime=localtime(&(pbase->time)); | |
| 95 | |
| 96 switch(pbase->subtype) | |
| 97 { | |
| 98 case ICQ_EVENT_MESSAGE: | |
| 99 if (icqlink->icq_RecvChatReq) | |
| 100 (*icqlink->icq_RecvChatReq)(icqlink, pbase->uin, | |
| 101 ptime->tm_hour, ptime->tm_min, ptime->tm_mday, ptime->tm_mon+1, | |
| 102 ptime->tm_year+1900, pmsgevent->message, pbase->id); | |
| 103 /* don't send an ack to the remote client! library client is | |
| 104 * responsible for sending the ack once the user accepts | |
| 105 * or denies the request */ | |
| 106 break; | |
| 107 case ICQ_EVENT_ACK: | |
| 108 icq_HandleChatRequestAck(pbase, icqlink); | |
| 109 break; | |
| 110 case ICQ_EVENT_CANCEL: | |
| 111 /* TODO */ | |
| 112 break; | |
| 113 default: | |
| 114 /* TODO */ | |
| 115 break; | |
| 116 } | |
| 117 } | |
| 118 | |
| 119 void icq_HandleChatRequestAck(icq_Event *pbase, ICQLINK *icqlink) | |
| 120 { | |
| 121 icq_ChatRequestEvent *pevent=(icq_ChatRequestEvent *)pbase; | |
| 122 icq_TCPLink *pchatlink; | |
| 123 icq_ChatSession *pchat; | |
| 124 icq_Packet *p2; | |
| 125 | |
| 126 /* once a chat request acknowledgement has been received, the remote | |
| 127 * client opens up a listening port for us. we need to connect to | |
| 128 * this port and all chat session communication takes place over | |
| 129 * this new tcp link */ | |
| 130 pchatlink=icq_TCPLinkNew(icqlink); | |
| 131 pchatlink->type=TCP_LINK_CHAT; | |
| 132 pchatlink->id=pbase->id; | |
| 133 | |
| 134 /* create a new chat session to manage the communication, and link | |
| 135 * it to the tcp link */ | |
| 136 pchat=icq_ChatSessionNew(icqlink); | |
| 137 pchat->id=pbase->id; | |
| 138 pchat->remote_uin=pbase->uin; | |
| 139 pchatlink->session=pchat; | |
| 140 | |
| 141 icq_ChatSessionSetStatus(pchat, CHAT_STATUS_CONNECTING); | |
| 142 | |
| 143 /* initiate the connection to the remote client's chat session | |
| 144 * port, which was specified in the ack event they sent */ | |
| 145 icq_TCPLinkConnect(pchatlink, pbase->uin, pevent->port); | |
| 146 | |
| 147 /* send off chat init event */ | |
| 148 p2=icq_TCPCreateChatInfoPacket(pchatlink, icqlink->icq_Nick, 0x00ffffff, | |
| 149 0x00000000); | |
| 150 icq_TCPLinkSend(pchatlink, p2); | |
| 151 } | |
| 152 | |
| 153 | |
| 154 void icq_HandleFileRequestEvent(icq_Event *pbase, ICQLINK *icqlink) | |
| 155 { | |
| 156 icq_FileRequestEvent *pevent=(icq_FileRequestEvent *)pbase; | |
| 157 icq_MessageEvent *pmsgevent=(icq_MessageEvent *)pmsgevent; | |
| 158 struct tm *ptime=localtime(&(pbase->time)); | |
| 159 | |
| 160 switch(pbase->subtype) | |
| 161 { | |
| 162 case ICQ_EVENT_MESSAGE: | |
| 163 if (icqlink->icq_RecvFileReq) | |
| 164 (*icqlink->icq_RecvFileReq)(icqlink, pbase->uin, | |
| 165 ptime->tm_hour, ptime->tm_min, ptime->tm_mday, ptime->tm_mon+1, | |
| 166 ptime->tm_year+1900, pmsgevent->message, pevent->filename, | |
| 167 pevent->filesize, pbase->id); | |
| 168 /* don't send an ack to the remote client! library client is | |
| 169 * responsible for sending the ack once the user accepts | |
| 170 * or denies the request */ | |
| 171 break; | |
| 172 case ICQ_EVENT_ACK: | |
| 173 icq_HandleFileRequestAck(pbase, icqlink); | |
| 174 break; | |
| 175 case ICQ_EVENT_CANCEL: | |
| 176 break; | |
| 177 default: | |
| 178 /* TODO */ | |
| 179 break; | |
| 180 } | |
| 181 } | |
| 182 | |
| 183 void icq_HandleFileRequestAck(icq_Event *pbase, ICQLINK *icqlink) | |
| 184 { | |
| 185 icq_FileRequestEvent *pevent=(icq_FileRequestEvent *)pbase; | |
| 186 icq_TCPLink *pfilelink; | |
| 187 icq_FileSession *pfile; | |
| 188 icq_Packet *p2; | |
| 189 | |
| 190 /* once a file request acknowledgement has been received, the remote | |
| 191 * client opens up a listening port for us. we need to connect to | |
| 192 * this port and all file transfer communication takes place over | |
| 193 * this new tcp link */ | |
| 194 pfilelink=icq_TCPLinkNew(icqlink); | |
| 195 pfilelink->type=TCP_LINK_FILE; | |
| 196 | |
| 197 /* a file session was created when the request was initially sent, | |
| 198 * but it wasn't attached to a tcp link because one did not exist. | |
| 199 * find the file sesion now and link it to the new tcp link */ | |
| 200 pfile=icq_FindFileSession(icqlink, pbase->uin, | |
| 201 pbase->id); /* TODO: make sure find session succeeded */ | |
| 202 pfile->tcplink=pfilelink; | |
| 203 pfilelink->id=pfile->id; | |
| 204 pfilelink->session=pfile; | |
| 205 | |
| 206 /* notify the library client of the created file session */ | |
| 207 if (icqlink->icq_RequestNotify) | |
| 208 (*icqlink->icq_RequestNotify)(icqlink, pfile->id, | |
| 209 ICQ_NOTIFY_FILESESSION, sizeof(icq_FileSession), pfile); | |
| 210 icq_FileSessionSetStatus(pfile, FILE_STATUS_CONNECTING); | |
| 211 | |
| 212 /* initiate the connection to the remote client's file session | |
| 213 * port, which was specified in the ack event they sent */ | |
| 214 icq_TCPLinkConnect(pfilelink, pbase->uin, pevent->port); | |
| 215 | |
| 216 /* send off the file transfer init event */ | |
| 217 /* TODO: convert file packets to events */ | |
| 218 p2=icq_TCPCreateFile00Packet( pfile->total_files, | |
| 219 pfile->total_bytes, pfile->current_speed, icqlink->icq_Nick); | |
| 220 icq_TCPLinkSend(pfilelink, p2); | |
| 221 } | |
| 222 | |
| 223 | |
| 224 /* | |
| 225 icq_FmtLog(plink->icqlink, ICQ_LOG_WARNING, "unknown message type %d!\n", type); | |
| 226 icq_FmtLog(plink->icqlink, ICQ_LOG_WARNING, "unknown packet command %d!\n", | |
| 227 command); | |
| 228 | |
| 229 TODO: conversion | |
| 230 strncpy(data,message,512) ; | |
| 231 icq_RusConv("wk",data) ; | |
| 232 | |
| 233 | |
| 234 TODO: ack code | |
| 235 | |
| 236 if(plink) | |
| 237 { | |
| 238 pack=icq_TCPCreateMessageAck(plink,0); | |
| 239 icq_PacketAppend32(pack, id); | |
| 240 icq_PacketSend(pack, plink->socket); | |
| 241 icq_PacketDelete(pack); | |
| 242 } | |
| 243 */ |
