[gaim-migrate @ 3063]
[pidgin-git.git] / src / protocols / icq / proxy.c
bloba20dd28210c1cc3ab52ddec3f22cd98411851ae5
1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
3 /*
4 * $Id: proxy.c 2096 2001-07-31 01:00:39Z warmenhoven $
6 * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and
7 * Bill Soudan <soudan@kde.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #ifdef _WIN32
26 #include <winsock.h>
27 #endif
29 #include <stdlib.h>
31 #include "icqlib.h"
33 void icq_HandleProxyResponse(icq_Link *icqlink)
35 int s;
36 char buf[256];
37 #ifdef _WIN32
38 s = recv(icqlink->icq_ProxySok, buf, sizeof(buf), 0);
39 #else
40 s = read(icqlink->icq_ProxySok, &buf, sizeof(buf));
41 #endif
42 if(s<=0)
44 icq_FmtLog(icqlink, ICQ_LOG_FATAL, "[SOCKS] Connection terminated\n");
45 icq_Disconnect(icqlink);
46 invoke_callback(icqlink, icq_Disconnected)(icqlink);
50 /*******************
51 SOCKS5 Proxy support
52 ********************/
53 void icq_SetProxy(icq_Link *icqlink, const char *phost, unsigned short pport,
54 int pauth, const char *pname, const char *ppass)
56 if(icqlink->icq_ProxyHost)
57 free(icqlink->icq_ProxyHost);
58 if(icqlink->icq_ProxyName)
59 free(icqlink->icq_ProxyName);
60 if(icqlink->icq_ProxyPass)
61 free(icqlink->icq_ProxyPass);
63 if(!phost)
65 icq_FmtLog(icqlink, ICQ_LOG_ERROR, "[SOCKS] Proxy host is empty\n");
66 icqlink->icq_UseProxy = 0;
67 return;
69 if(!pname)
71 icq_FmtLog(icqlink, ICQ_LOG_ERROR, "[SOCKS] User name is empty\n");
72 icqlink->icq_UseProxy = 0;
73 return;
75 if(!pname)
77 icq_FmtLog(icqlink, ICQ_LOG_ERROR, "[SOCKS] User password is empty\n");
78 icqlink->icq_UseProxy = 0;
79 return;
82 if(strlen(pname)>255)
84 icq_FmtLog(icqlink, ICQ_LOG_ERROR, "[SOCKS] User name greater than 255 chars\n");
85 icqlink->icq_UseProxy = 0;
86 return;
88 if(strlen(ppass)>255)
90 icq_FmtLog(icqlink, ICQ_LOG_ERROR, "[SOCKS] User password greater than 255 chars\n");
91 icqlink->icq_UseProxy = 0;
92 return;
95 icqlink->icq_UseProxy = 1;
96 icqlink->icq_ProxyHost = strdup(phost);
97 icqlink->icq_ProxyPort = pport;
98 icqlink->icq_ProxyAuth = pauth;
99 icqlink->icq_ProxyName = strdup(pname);
100 icqlink->icq_ProxyPass = strdup(ppass);
103 void icq_UnsetProxy(icq_Link *icqlink)
105 icqlink->icq_UseProxy = 0;
108 int icq_GetProxySok(icq_Link *icqlink)
110 return icqlink->icq_ProxySok;