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