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