Improve output with bad setups (non-existing local proxy or remote non-proxy servers)

git-svn-id: https://proxytunnel.svn.sourceforge.net/svnroot/proxytunnel/trunk/proxytunnel@137 bc163920-b10d-0410-b2c5-a5491ca2ceef
This commit is contained in:
Dag Wieers 2006-09-01 14:51:28 +00:00
parent fc95112e19
commit e6893458fe
3 changed files with 27 additions and 19 deletions

30
http.c
View file

@ -49,7 +49,7 @@ void analyze_HTTP()
p = strtok( buf, " ");
else
{
message( "analyze_HTTP: readline failed: Connection closed by foreign host\n" );
message( "analyze_HTTP: readline failed: Connection closed by remote host\n" );
exit(2);
}
}
@ -60,17 +60,17 @@ void analyze_HTTP()
exit( 1 );
}
p = strtok( 0, " ");
p = strtok( NULL, " ");
if( strcmp( p, "200" ) != 0 )
{
if( ! args_info.quiet_flag )
message( "HTTP return code: '%s'\n", p );
message( "HTTP return code: %s ", p );
p += strlen( p ) + 1;
if( ! args_info.quiet_flag )
message( "%s\n", p );
message( "%s", p );
if (!ntlm_challenge && strcmp( p, "407") != 0)
{
@ -93,14 +93,18 @@ void analyze_HTTP()
}
}
void print_line(char *buf)
/*
* Prints lines from a buffer prepended with a prefix
*/
void print_line_prefix(char *buf, char *prefix)
{
char *buf2 = strdup(buf);
char *p = strtok(buf2, "\r\n");
while ( p != NULL) {
message( "-> %s\n", p );
p = strtok(NULL, "\r\n");
buf = strdup(buf);
char *cur = strtok(buf, "\r\n");
while ( cur != NULL) {
message( "%s %s\n", prefix, cur );
cur = strtok(NULL, "\r\n");
}
// free(buf);
}
/*
@ -160,7 +164,7 @@ void proxy_protocol()
*/
if( args_info.verbose_flag ) {
message( "Connect string sent to local proxy:\n");
print_line(buf);
print_line_prefix(buf, "->");
}
/*
@ -175,7 +179,7 @@ void proxy_protocol()
* Read the first line of the response and analyze it
*/
if( args_info.verbose_flag )
message( "Received from local proxy:\n");
message( "Data received from local proxy:\n");
analyze_HTTP();
@ -202,7 +206,7 @@ void proxy_protocol()
*/
if( args_info.verbose_flag ) {
message( "Connect string sent to remote proxy:\n");
print_line(buf);
print_line_prefix(buf, "->");
}
/*

View file

@ -47,7 +47,10 @@ void message( char *s, ... )
*/
void my_perror( char *msg )
{
char *err = strerror( errno );
message( "Error! %s: %s\n", msg, err );
if (errno == 0) {
message( "error: %s.\n", msg );
} else {
char *errstr = strerror( errno );
message( "error: %s: [%d] %s\n", msg, errno, errstr );
}
}

View file

@ -88,7 +88,8 @@ void tunnel_connect() {
*/
if( ! ( he = gethostbyname( args_info.proxyhost_arg ) ) )
{
my_perror("Proxy host not found");
// FIXME: my_perror("Local proxy %s could not be resolved", args_info.proxyhost_arg);
my_perror("Local proxy could not be resolved" );
exit(1);
}
@ -96,7 +97,7 @@ void tunnel_connect() {
snprintf(ip, 16, "%d.%d.%d.%d", he->h_addr[0] & 255, he->h_addr[1] & 255, he->h_addr[2] & 255, he->h_addr[3] & 255);
if( args_info.verbose_flag && strcmp(args_info.proxyhost_arg, ip))
{
message( "%s is %d.%d.%d.%d\n",
message( "Local proxy %s resolves to %d.%d.%d.%d\n",
args_info.proxyhost_arg,
he->h_addr[0] & 255,
he->h_addr[1] & 255,
@ -354,7 +355,7 @@ int main( int argc, char *argv[] )
* - Check if we need to run as a daemon. If so, a completely
* different mainline is needed...
* - Set a signal for the hangup (HUP) signal
* - Optionally create the proxy basic authenticcation cookie
* - Optionally create the proxy basic authentication cookie
* - Connect the sd socket to the proxy
* - Execute the proxy protocol to connect it to the origin server
* - Enter copy in-out mode to channel data hence and forth