Mercurial > pidgin
annotate plugins/icq/icqlib.c @ 1467:7f7857c5036e
[gaim-migrate @ 1477]
updates to icqlib and gtkspell. also added catch case for when BYTE_ORDER wasn't defined.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Sun, 04 Feb 2001 07:34:46 +0000 |
parents | 4c510ca3563f |
children | 0ef6603d986e |
rev | line source |
---|---|
1152 | 1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 /* | |
1467
7f7857c5036e
[gaim-migrate @ 1477]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
3 $Id: icqlib.c 1477 2001-02-04 07:34:46Z warmenhoven $ |
1152 | 4 $Log$ |
1467
7f7857c5036e
[gaim-migrate @ 1477]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
5 Revision 1.4 2001/02/04 07:34:46 warmenhoven |
7f7857c5036e
[gaim-migrate @ 1477]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
6 updates to icqlib and gtkspell. also added catch case for when BYTE_ORDER wasn't defined. |
7f7857c5036e
[gaim-migrate @ 1477]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
7 |
7f7857c5036e
[gaim-migrate @ 1477]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
8 Revision 1.50 2001/02/03 17:04:16 mwh |
7f7857c5036e
[gaim-migrate @ 1477]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
9 Add an icq_UserData field to the ICQLINK struct. |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
10 |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
11 Revision 1.49 2001/01/17 01:29:17 bills |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
12 Rework chat and file session interfaces; implement socket notifications. |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
13 |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
14 Revision 1.48 2001/01/15 06:20:24 denis |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
15 Cleanup. |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
16 |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
17 Revision 1.47 2000/12/19 21:29:51 bills |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
18 actually return the link in icq_ICQLINKNew |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
19 |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
20 Revision 1.46 2000/12/19 06:00:07 bills |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
21 moved members from ICQLINK to ICQLINK_private struct |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
22 |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
23 Revision 1.45 2000/11/02 07:29:07 denis |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
24 Ability to disable TCP protocol has been added. |
1152 | 25 |
26 Revision 1.44 2000/07/24 03:10:08 bills | |
27 added support for real nickname during TCP transactions like file and | |
28 chat, instead of using Bill all the time (hmm, where'd I get that from? :) | |
29 | |
30 Revision 1.43 2000/07/09 22:05:11 bills | |
31 removed unnecessary functions | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
32 */ |
1152 | 33 |
34 #include "icqlib.h" | |
35 | |
36 #include <stdlib.h> | |
37 | |
38 #ifndef _WIN32 | |
39 #include <unistd.h> | |
40 #endif | |
41 | |
42 #include <time.h> | |
43 | |
44 #ifdef _WIN32 | |
45 #include <winsock.h> | |
46 #else | |
47 #include <netdb.h> | |
48 #include <sys/socket.h> | |
49 #endif | |
50 | |
51 #include <sys/stat.h> | |
52 | |
53 #ifndef _WIN32 | |
54 #include <sys/time.h> | |
55 #include <netinet/in.h> | |
56 #endif | |
57 | |
58 #include "util.h" | |
59 #include "icqtypes.h" | |
60 #include "icq.h" | |
61 #include "udp.h" | |
62 #include "tcp.h" | |
63 #include "queue.h" | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
64 #include "socketmanager.h" |
1152 | 65 |
66 int icq_Russian = FALSE; | |
67 BYTE icq_LogLevel = 0; | |
68 | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
69 void (*icq_SocketNotify)(int socket, int type, int status); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
70 |
1152 | 71 DWORD icq_SendMessage(ICQLINK *link, DWORD uin, const char *text, BYTE thruSrv) |
72 { | |
73 if(thruSrv==ICQ_SEND_THRUSERVER) | |
74 return icq_UDPSendMessage(link, uin, text); | |
75 else if(thruSrv==ICQ_SEND_DIRECT) | |
76 return icq_TCPSendMessage(link, uin, text); | |
77 else if(thruSrv==ICQ_SEND_BESTWAY) | |
78 { | |
79 icq_ContactItem *pcontact=icq_ContactFind(link, uin); | |
80 if(pcontact) | |
81 { | |
82 if(pcontact->tcp_flag == 0x04) | |
83 return icq_TCPSendMessage(link, uin, text); | |
84 else | |
85 return icq_UDPSendMessage(link, uin, text); | |
86 } | |
87 else | |
88 { | |
89 return icq_UDPSendMessage(link, uin, text); | |
90 } | |
91 } | |
92 return 0; | |
93 } | |
94 | |
95 DWORD icq_SendURL(ICQLINK *link, DWORD uin, const char *url, const char *descr, BYTE thruSrv) | |
96 { | |
97 if(thruSrv==ICQ_SEND_THRUSERVER) | |
98 return icq_UDPSendURL(link, uin, url, descr); | |
99 else if(thruSrv==ICQ_SEND_DIRECT) | |
100 return icq_TCPSendURL(link, uin, descr, url); | |
101 else if(thruSrv==ICQ_SEND_BESTWAY) | |
102 { | |
103 icq_ContactItem *pcontact=icq_ContactFind(link, uin); | |
104 if(pcontact) | |
105 { | |
106 if(pcontact->tcp_flag == 0x04) | |
107 return icq_TCPSendURL(link, uin, descr, url); | |
108 else | |
109 return icq_UDPSendURL(link, uin, url, descr); | |
110 } | |
111 else | |
112 { | |
113 return icq_UDPSendURL(link, uin, url, descr); | |
114 } | |
115 } | |
116 return 0; | |
117 } | |
118 | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
119 ICQLINK *icq_ICQLINKNew(DWORD uin, const char *password, const char *nick, |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
120 unsigned char useTCP) |
1152 | 121 { |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
122 ICQLINK *link = (ICQLINK*)malloc(sizeof(ICQLINK)); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
123 link->d = (ICQLINK_private*)malloc(sizeof(ICQLINK_private)); |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
124 |
1152 | 125 srand(time(0L)); |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
126 /* initialize icq_SocketList on first call */ |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
127 if (!icq_SocketList) |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
128 icq_SocketList = list_new(); |
1152 | 129 |
130 /* Initialize all callbacks */ | |
131 link->icq_Logged = 0L; | |
132 link->icq_Disconnected = 0L; | |
133 link->icq_RecvMessage = 0L; | |
134 link->icq_RecvURL = 0L; | |
135 link->icq_RecvWebPager = 0L; | |
136 link->icq_RecvMailExpress = 0L; | |
137 link->icq_RecvChatReq = 0L; | |
138 link->icq_RecvFileReq = 0L; | |
139 link->icq_RecvAdded = 0L; | |
140 link->icq_RecvAuthReq = 0L; | |
141 link->icq_UserFound = 0L; | |
142 link->icq_SearchDone = 0L; | |
143 link->icq_UserOnline = 0L; | |
144 link->icq_UserOffline = 0L; | |
145 link->icq_UserStatusUpdate = 0L; | |
146 link->icq_InfoReply = 0L; | |
147 link->icq_ExtInfoReply = 0L; | |
148 link->icq_WrongPassword = 0L; | |
149 link->icq_InvalidUIN = 0L; | |
150 link->icq_Log = 0L; | |
151 link->icq_SrvAck = 0L; | |
152 link->icq_RequestNotify = 0L; | |
153 link->icq_NewUIN = 0L; | |
154 link->icq_SetTimeout = 0L; | |
155 link->icq_MetaUserFound = 0L; | |
156 link->icq_MetaUserInfo = 0L; | |
157 link->icq_MetaUserWork = 0L; | |
158 link->icq_MetaUserMore = 0L; | |
159 link->icq_MetaUserAbout = 0L; | |
160 link->icq_MetaUserInterests = 0L; | |
161 link->icq_MetaUserAffiliations = 0L; | |
162 link->icq_MetaUserHomePageCategory = 0L; | |
163 | |
164 /* General stuff */ | |
165 link->icq_Uin = uin; | |
166 link->icq_Password = strdup(password); | |
167 link->icq_Nick = strdup(nick); | |
168 link->icq_OurIP = -1; | |
169 link->icq_OurPort = 0; | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
170 link->d->icq_ContactList = list_new(); |
1152 | 171 link->icq_Status = -1; |
1467
7f7857c5036e
[gaim-migrate @ 1477]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1432
diff
changeset
|
172 link->icq_UserData = 0L; |
1152 | 173 |
174 /* UDP stuff */ | |
175 link->icq_UDPSok = -1; | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
176 memset(link->d->icq_UDPServMess, FALSE, sizeof(link->d->icq_UDPServMess)); |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
177 link->d->icq_UDPSeqNum1 = 0; |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
178 link->d->icq_UDPSeqNum2 = 0; |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
179 link->d->icq_UDPSession = 0; |
1152 | 180 icq_UDPQueueNew(link); |
181 | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
182 /* TCP stuff */ |
1152 | 183 icq_TCPInit(link); |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
184 link->icq_UseTCP = useTCP; |
1152 | 185 |
186 /* Proxy stuff */ | |
187 link->icq_UseProxy = 0; | |
188 link->icq_ProxyHost = 0L; | |
189 link->icq_ProxyIP = -1; | |
190 link->icq_ProxyPort = 0; | |
191 link->icq_ProxyAuth = 0; | |
192 link->icq_ProxyName = 0L; | |
193 link->icq_ProxyPass = 0L; | |
194 link->icq_ProxySok = -1; | |
195 link->icq_ProxyOurPort = 0; | |
196 link->icq_ProxyDestIP = -1; | |
197 link->icq_ProxyDestPort = 0; | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
198 |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
199 return link; |
1152 | 200 } |
201 | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
202 void icq_ICQLINKDelete(ICQLINK *link) |
1152 | 203 { |
204 icq_TCPDone(link); | |
205 if(link->icq_Password) | |
206 free(link->icq_Password); | |
207 if(link->icq_Nick) | |
208 free(link->icq_Nick); | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
209 if(link->d->icq_ContactList) |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
210 list_delete(link->d->icq_ContactList, icq_ContactDelete); |
1152 | 211 icq_UDPQueueDelete(link); |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
212 free(link->d); |
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
213 free(link); |
1152 | 214 } |
215 | |
216 /****************************** | |
217 Main function connects gets icq_Uin | |
218 and icq_Password and logins in and sits | |
219 in a loop waiting for server responses. | |
220 *******************************/ | |
221 void icq_Main(ICQLINK *link) | |
222 { | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
223 icq_SocketPoll(); |
1152 | 224 } |
225 | |
226 /********************************** | |
227 Connects to hostname on port port | |
228 hostname can be DNS or nnn.nnn.nnn.nnn | |
229 write out messages to the FD aux | |
230 ***********************************/ | |
231 int icq_Connect(ICQLINK *link, const char *hostname, int port) | |
232 { | |
233 char buf[1024]; /*, un = 1;*/ | |
234 /* char tmpbuf[256], our_host[256]*/ | |
235 int conct, res; | |
236 unsigned int length; | |
237 struct sockaddr_in sin, prsin; /* used to store inet addr stuff */ | |
238 struct hostent *host_struct; /* used in DNS llokup */ | |
239 | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
240 /* create the unconnected socket*/ |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
241 link->icq_UDPSok = icq_SocketNew(AF_INET, SOCK_DGRAM, 0); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
242 |
1152 | 243 if(link->icq_UDPSok == -1) |
244 { | |
245 icq_FmtLog(link, ICQ_LOG_FATAL, "Socket creation failed\n"); | |
246 return -1; | |
247 } | |
248 icq_FmtLog(link, ICQ_LOG_MESSAGE, "Socket created attempting to connect\n"); | |
249 sin.sin_addr.s_addr = INADDR_ANY; | |
250 sin.sin_family = AF_INET; /* we're using the inet not appletalk*/ | |
251 sin.sin_port = 0; | |
252 if(bind(link->icq_UDPSok, (struct sockaddr*)&sin, sizeof(struct sockaddr))<0) | |
253 { | |
254 icq_FmtLog(link, ICQ_LOG_FATAL, "Can't bind socket to free port\n"); | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
255 icq_SocketDelete(link->icq_UDPSok); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
256 link->icq_UDPSok = -1; |
1152 | 257 return -1; |
258 } | |
259 length = sizeof(sin); | |
260 getsockname(link->icq_UDPSok, (struct sockaddr*)&sin, &length); | |
261 link->icq_ProxyOurPort = ntohs(sin.sin_port); | |
262 if(link->icq_UseProxy) | |
263 { | |
264 icq_FmtLog(link, ICQ_LOG_MESSAGE, "[SOCKS] Trying to use SOCKS5 proxy\n"); | |
265 prsin.sin_addr.s_addr = inet_addr(link->icq_ProxyHost); | |
266 if(prsin.sin_addr.s_addr == (unsigned long)-1) /* name isn't n.n.n.n so must be DNS */ | |
267 { | |
268 host_struct = gethostbyname(link->icq_ProxyHost); | |
269 if(host_struct == 0L) | |
270 { | |
271 icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] Can't find hostname: %s\n", link->icq_ProxyHost); | |
272 return -1; | |
273 } | |
274 prsin.sin_addr = *((struct in_addr*)host_struct->h_addr); | |
275 } | |
276 link->icq_ProxyIP = ntohl(prsin.sin_addr.s_addr); | |
277 prsin.sin_family = AF_INET; /* we're using the inet not appletalk*/ | |
278 prsin.sin_port = htons(link->icq_ProxyPort); /* port */ | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
279 |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
280 /* create the unconnected socket*/ |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
281 link->icq_ProxySok = icq_SocketNew(AF_INET, SOCK_STREAM, 0); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
282 |
1152 | 283 if(link->icq_ProxySok == -1) |
284 { | |
285 icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] Socket creation failed\n"); | |
286 return -1; | |
287 } | |
288 icq_FmtLog(link, ICQ_LOG_MESSAGE, "[SOCKS] Socket created attempting to connect\n"); | |
289 conct = connect(link->icq_ProxySok, (struct sockaddr *) &prsin, sizeof(prsin)); | |
290 if(conct == -1) /* did we connect ?*/ | |
291 { | |
292 icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] Connection refused\n"); | |
293 return -1; | |
294 } | |
295 buf[0] = 5; /* protocol version */ | |
296 buf[1] = 1; /* number of methods */ | |
297 if(!strlen(link->icq_ProxyName) || !strlen(link->icq_ProxyPass) || !link->icq_ProxyAuth) | |
298 buf[2] = 0; /* no authorization required */ | |
299 else | |
300 buf[2] = 2; /* method username/password */ | |
301 #ifdef _WIN32 | |
302 send(link->icq_ProxySok, buf, 3, 0); | |
303 res = recv(link->icq_ProxySok, buf, 2, 0); | |
304 #else | |
305 write(link->icq_ProxySok, buf, 3); | |
306 res = read(link->icq_ProxySok, buf, 2); | |
307 #endif | |
308 if(strlen(link->icq_ProxyName) && strlen(link->icq_ProxyPass) && link->icq_ProxyAuth) | |
309 { | |
310 if(res != 2 || buf[0] != 5 || buf[1] != 2) /* username/password authentication*/ | |
311 { | |
312 icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] Authentication method incorrect\n"); | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
313 icq_SocketDelete(link->icq_ProxySok); |
1152 | 314 return -1; |
315 } | |
316 buf[0] = 1; /* version of subnegotiation */ | |
317 buf[1] = strlen(link->icq_ProxyName); | |
318 memcpy(&buf[2], link->icq_ProxyName, buf[1]); | |
319 buf[2+buf[1]] = strlen(link->icq_ProxyPass); | |
320 memcpy(&buf[3+buf[1]], link->icq_ProxyPass, buf[2+buf[1]]); | |
321 #ifdef _WIN32 | |
322 send(link->icq_ProxySok, buf, buf[1]+buf[2+buf[1]]+3, 0); | |
323 res = recv(link->icq_ProxySok, buf, 2, 0); | |
324 #else | |
325 write(link->icq_ProxySok, buf, buf[1]+buf[2+buf[1]]+3); | |
326 res = read(link->icq_ProxySok, buf, 2); | |
327 #endif | |
328 if(res != 2 || buf[0] != 1 || buf[1] != 0) | |
329 { | |
330 icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] Authorization failure\n"); | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
331 icq_SocketDelete(link->icq_ProxySok); |
1152 | 332 return -1; |
333 } | |
334 } | |
335 else | |
336 { | |
337 if(res != 2 || buf[0] != 5 || buf[1] != 0) /* no authentication required */ | |
338 { | |
339 icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] Authentication method incorrect\n"); | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
340 icq_SocketDelete(link->icq_ProxySok); |
1152 | 341 return -1; |
342 } | |
343 } | |
344 buf[0] = 5; /* protocol version */ | |
345 buf[1] = 3; /* command UDP associate */ | |
346 buf[2] = 0; /* reserved */ | |
347 buf[3] = 1; /* address type IP v4 */ | |
348 buf[4] = (char)0; | |
349 buf[5] = (char)0; | |
350 buf[6] = (char)0; | |
351 buf[7] = (char)0; | |
352 *(unsigned short*)&buf[8] = htons(link->icq_ProxyOurPort); | |
353 /* memcpy(&buf[8], &link->icq_ProxyOurPort, 2); */ | |
354 #ifdef _WIN32 | |
355 send(link->icq_ProxySok, buf, 10, 0); | |
356 res = recv(link->icq_ProxySok, buf, 10, 0); | |
357 #else | |
358 write(link->icq_ProxySok, buf, 10); | |
359 res = read(link->icq_ProxySok, buf, 10); | |
360 #endif | |
361 if(res != 10 || buf[0] != 5 || buf[1] != 0) | |
362 { | |
363 switch(buf[1]) | |
364 { | |
365 case 1: | |
366 icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] General SOCKS server failure\n"); | |
367 break; | |
368 case 2: | |
369 icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] Connection not allowed by ruleset\n"); | |
370 break; | |
371 case 3: | |
372 icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] Network unreachable\n"); | |
373 break; | |
374 case 4: | |
375 icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] Host unreachable\n"); | |
376 break; | |
377 case 5: | |
378 icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] Connection refused\n"); | |
379 break; | |
380 case 6: | |
381 icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] TTL expired\n"); | |
382 break; | |
383 case 7: | |
384 icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] Command not supported\n"); | |
385 break; | |
386 case 8: | |
387 icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] Address type not supported\n"); | |
388 break; | |
389 default: | |
390 icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] Unknown SOCKS server failure\n"); | |
391 break; | |
392 } | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
393 icq_SocketDelete(link->icq_ProxySok); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
394 link->icq_ProxySok = -1; |
1152 | 395 return -1; |
396 } | |
397 } | |
398 sin.sin_addr.s_addr = inet_addr(hostname); /* checks for n.n.n.n notation */ | |
399 if(sin.sin_addr.s_addr == (unsigned long)-1) /* name isn't n.n.n.n so must be DNS */ | |
400 { | |
401 host_struct = gethostbyname(hostname); | |
402 if(host_struct == 0L) | |
403 { | |
404 icq_FmtLog(link, ICQ_LOG_FATAL, "Can't find hostname: %s\n", hostname); | |
405 if(link->icq_UseProxy) | |
406 { | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
407 icq_SocketDelete(link->icq_ProxySok); |
1152 | 408 } |
409 return -1; | |
410 } | |
411 sin.sin_addr = *((struct in_addr *)host_struct->h_addr); | |
412 } | |
413 if(link->icq_UseProxy) | |
414 { | |
415 link->icq_ProxyDestIP = ntohl(sin.sin_addr.s_addr); | |
416 memcpy(&sin.sin_addr.s_addr, &buf[4], 4); | |
417 } | |
418 sin.sin_family = AF_INET; /* we're using the inet not appletalk*/ | |
419 sin.sin_port = htons(port); /* port */ | |
420 if(link->icq_UseProxy) | |
421 { | |
422 link->icq_ProxyDestPort = port; | |
423 memcpy(&sin.sin_port, &buf[8], 2); | |
424 } | |
425 conct = connect(link->icq_UDPSok, (struct sockaddr*)&sin, sizeof(sin)); | |
426 if(conct == -1) /* did we connect ?*/ | |
427 { | |
428 icq_FmtLog(link, ICQ_LOG_FATAL, "Connection refused\n"); | |
429 if(link->icq_UseProxy) | |
430 { | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
431 icq_SocketDelete(link->icq_ProxySok); |
1152 | 432 } |
433 return -1; | |
434 } | |
435 length = sizeof(sin) ; | |
436 getsockname(link->icq_UDPSok, (struct sockaddr*)&sin, &length); | |
437 link->icq_OurIP = ntohl(sin.sin_addr.s_addr); | |
438 link->icq_OurPort = ntohs(sin.sin_port); | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
439 |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
440 /* sockets are ready to receive data - install handlers */ |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
441 icq_SocketSetHandler(link->icq_UDPSok, ICQ_SOCKET_READ, |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
442 icq_HandleServerResponse, link); |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
443 if (link->icq_UseProxy) |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
444 icq_SocketSetHandler(link->icq_ProxySok, ICQ_SOCKET_READ, |
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
445 icq_HandleProxyResponse, link); |
1152 | 446 return link->icq_UDPSok; |
447 } | |
448 | |
449 void icq_Disconnect(ICQLINK *link) | |
450 { | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
451 icq_SocketDelete(link->icq_UDPSok); |
1152 | 452 if(link->icq_UseProxy) |
453 { | |
1432
4c510ca3563f
[gaim-migrate @ 1442]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1309
diff
changeset
|
454 icq_SocketDelete(link->icq_ProxySok); |
1152 | 455 } |
456 icq_UDPQueueFree(link); | |
457 } | |
458 | |
459 /* | |
460 void icq_InitNewUser(const char *hostname, DWORD port) | |
461 { | |
462 srv_net_icq_pak pak; | |
463 int s; | |
464 struct timeval tv; | |
465 fd_set readfds; | |
466 | |
467 icq_Connect(hostname, port); | |
468 if((icq_UDPSok == -1) || (icq_UDPSok == 0)) | |
469 { | |
470 printf("Couldn't establish connection\n"); | |
471 exit(1); | |
472 } | |
473 icq_RegNewUser(icq_Password); | |
474 for(;;) | |
475 { | |
476 tv.tv_sec = 2; | |
477 tv.tv_usec = 500000; | |
478 | |
479 FD_ZERO(&readfds); | |
480 FD_SET(icq_UDPSok, &readfds); | |
481 | |
482 select(icq_UDPSok+1, &readfds, 0L, 0L, &tv); | |
483 | |
484 if(FD_ISSET(icq_UDPSok, &readfds)) | |
485 { | |
486 s = icq_UDPSockRead(icq_UDPSok, &pak.head, sizeof(pak)); | |
487 if(icqtohs(pak.head.cmd) == SRV_NEW_UIN) | |
488 { | |
489 icq_Uin = icqtohl(&pak.data[2]); | |
490 return; | |
491 } | |
492 } | |
493 } | |
494 } | |
495 */ | |
496 | |
497 /************************ | |
498 icq_UDPServMess functions | |
499 *************************/ | |
500 BOOL icq_GetServMess(ICQLINK *link, WORD num) | |
501 { | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
502 return ((link->d->icq_UDPServMess[num/8] & (1 << (num%8))) >> (num%8)); |
1152 | 503 } |
504 | |
505 void icq_SetServMess(ICQLINK *link, WORD num) | |
506 { | |
1309
0a766047b4fd
[gaim-migrate @ 1319]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1152
diff
changeset
|
507 link->d->icq_UDPServMess[num/8] |= (1 << (num%8)); |
1152 | 508 } |
509 | |
510 int icq_GetSok(ICQLINK *link) | |
511 { | |
512 return link->icq_UDPSok; | |
513 } |