Thu, 12 Jun 2003 05:01:11 +0000
[gaim-migrate @ 6269]
regain the ability to remember what plugins we had loaded
| 2086 | 1 | /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
| 2 | ||
| 3 | /* | |
| 4 | * $Id: proxy.c 2096 2001-07-31 01:00:39Z warmenhoven $ | |
| 5 | * | |
| 6 | * Copyright (C) 1998-2001, Denis V. Dmitrienko <denis@null.net> and | |
| 7 | * Bill Soudan <soudan@kde.org> | |
| 8 | * | |
| 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. | |
| 13 | * | |
| 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. | |
| 18 | * | |
| 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. | |
| 22 | * | |
| 23 | */ | |
| 24 | ||
| 25 | #ifdef _WIN32 | |
| 26 | #include <winsock.h> | |
| 27 | #endif | |
| 28 | ||
| 29 | #include <stdlib.h> | |
| 30 | ||
| 31 | #include "icqlib.h" | |
| 32 | ||
| 33 | void icq_HandleProxyResponse(icq_Link *icqlink) | |
| 34 | { | |
| 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) | |
| 43 | { | |
| 44 | icq_FmtLog(icqlink, ICQ_LOG_FATAL, "[SOCKS] Connection terminated\n"); | |
| 45 | icq_Disconnect(icqlink); | |
| 46 | invoke_callback(icqlink, icq_Disconnected)(icqlink); | |
| 47 | } | |
| 48 | } | |
| 49 | ||
| 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) | |
| 55 | { | |
| 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); | |
| 62 | ||
| 63 | if(!phost) | |
| 64 | { | |
| 65 | icq_FmtLog(icqlink, ICQ_LOG_ERROR, "[SOCKS] Proxy host is empty\n"); | |
| 66 | icqlink->icq_UseProxy = 0; | |
| 67 | return; | |
| 68 | } | |
| 69 | if(!pname) | |
| 70 | { | |
| 71 | icq_FmtLog(icqlink, ICQ_LOG_ERROR, "[SOCKS] User name is empty\n"); | |
| 72 | icqlink->icq_UseProxy = 0; | |
| 73 | return; | |
| 74 | } | |
| 75 | if(!pname) | |
| 76 | { | |
| 77 | icq_FmtLog(icqlink, ICQ_LOG_ERROR, "[SOCKS] User password is empty\n"); | |
| 78 | icqlink->icq_UseProxy = 0; | |
| 79 | return; | |
| 80 | } | |
| 81 | ||
| 82 | if(strlen(pname)>255) | |
| 83 | { | |
| 84 | icq_FmtLog(icqlink, ICQ_LOG_ERROR, "[SOCKS] User name greater than 255 chars\n"); | |
| 85 | icqlink->icq_UseProxy = 0; | |
| 86 | return; | |
| 87 | } | |
| 88 | if(strlen(ppass)>255) | |
| 89 | { | |
| 90 | icq_FmtLog(icqlink, ICQ_LOG_ERROR, "[SOCKS] User password greater than 255 chars\n"); | |
| 91 | icqlink->icq_UseProxy = 0; | |
| 92 | return; | |
| 93 | } | |
| 94 | ||
| 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); | |
| 101 | } | |
| 102 | ||
| 103 | void icq_UnsetProxy(icq_Link *icqlink) | |
| 104 | { | |
| 105 | icqlink->icq_UseProxy = 0; | |
| 106 | } | |
| 107 | ||
| 108 | int icq_GetProxySok(icq_Link *icqlink) | |
| 109 | { | |
| 110 | return icqlink->icq_ProxySok; | |
| 111 | } |