1 /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /*
3 $Id: proxy.c,v 1.8 2000/05/10 18:51:23 denis Exp $
4 $Log: proxy.c,v $
5 Revision 1.8  2000/05/10 18:51:23  denis
6 icq_Disconnect() now called before icq_Disconnected callback to
7 prevent high CPU usage in kicq's "reconnect on disconnect" code.
8 
9 Revision 1.7  2000/05/03 18:29:15  denis
10 Callbacks have been moved to the ICQLINK structure.
11 
12 Revision 1.6  2000/04/05 14:37:02  denis
13 Applied patch from "Guillaume R." <grs@mail.com> for basic Win32
14 compatibility.
15 
16 Revision 1.5  1999/10/07 18:00:59  denis
17 proxy.h file removed.
18 
19 Revision 1.4  1999/07/16 12:01:06  denis
20 ICQLINK support added.
21 
22 Revision 1.3  1999/07/12 15:13:33  cproch
23 - added definition of ICQLINK to hold session-specific global variabled
24   applications which have more than one connection are now possible
25 - changed nearly every function defintion to support ICQLINK parameter
26 
27 Revision 1.2  1999/04/14 14:51:42  denis
28 Switched from icq_Log callback to icq_Fmt function.
29 Cleanups for "strict" compiling (-ansi -pedantic)
30 
31 Revision 1.1  1999/03/24 11:37:38  denis
32 Underscored files with TCP stuff renamed.
33 TCP stuff cleaned up
34 Function names changed to corresponding names.
35 icqlib.c splitted to many small files by subject.
36 C++ comments changed to ANSI C comments.
37 
38 */
39 
40 #ifndef _WIN32
41 #include <unistd.h>
42 #endif
43 
44 #ifdef _WIN32
45 #include <winsock.h>
46 #endif
47 
48 #include <stdlib.h>
49 
50 #include "util.h"
51 #include "icqtypes.h"
52 #include "icq.h"
53 #include "icqlib.h"
54 
icq_HandleProxyResponse(ICQLINK * link)55 void icq_HandleProxyResponse(ICQLINK *link)
56 {
57   int s;
58   char buf[256];
59 #ifdef _WIN32
60   s = recv(link->icq_ProxySok, buf, sizeof(buf), 0);
61 #else
62   s = read(link->icq_ProxySok, &buf, sizeof(buf));
63 #endif
64   if(s<=0)
65   {
66     icq_FmtLog(link, ICQ_LOG_FATAL, "[SOCKS] Connection terminated\n");
67     icq_Disconnect(link);
68     if(link->icq_Disconnected)
69       (*link->icq_Disconnected)(link);
70   }
71 }
72 
73 /*******************
74 SOCKS5 Proxy support
75 ********************/
icq_SetProxy(ICQLINK * link,const char * phost,unsigned short pport,int pauth,const char * pname,const char * ppass)76 void icq_SetProxy(ICQLINK *link, const char *phost, unsigned short pport, int pauth, const char *pname, const char *ppass)
77 {
78   if(link->icq_ProxyHost)
79     free(link->icq_ProxyHost);
80   if(link->icq_ProxyName)
81     free(link->icq_ProxyName);
82   if(link->icq_ProxyPass)
83     free(link->icq_ProxyPass);
84   if(strlen(pname)>255)
85   {
86     icq_FmtLog(link, ICQ_LOG_ERROR, "[SOCKS] User name greater than 255 chars\n");
87     link->icq_UseProxy = 0;
88     return;
89   }
90   if(strlen(ppass)>255)
91   {
92     icq_FmtLog(link, ICQ_LOG_ERROR, "[SOCKS] User password greater than 255 chars\n");
93     link->icq_UseProxy = 0;
94     return;
95   }
96   link->icq_UseProxy = 1;
97   link->icq_ProxyHost = strdup(phost);
98   link->icq_ProxyPort = pport;
99   link->icq_ProxyAuth = pauth;
100   link->icq_ProxyName = strdup(pname);
101   link->icq_ProxyPass = strdup(ppass);
102 }
103 
icq_UnsetProxy(ICQLINK * link)104 void icq_UnsetProxy(ICQLINK *link)
105 {
106   link->icq_UseProxy = 0;
107 }
108 
icq_GetProxySok(ICQLINK * link)109 int icq_GetProxySok(ICQLINK *link)
110 {
111   return link->icq_ProxySok;
112 }
113