[axel-devel] http proxy authorization and user agent configuration patch

volans wang volansw at gmail.com
Sat Jan 16 04:46:17 UTC 2010


diff -Nu ../axel_whole/branches/2.x/axelrc.example ./axelrc.example
--- ../axel_whole/branches/2.x/axelrc.example 2009-05-15 21:10:01.000000000
+0800
+++ ./axelrc.example 2009-05-25 13:30:27.000000000 +0800
@@ -43,9 +43,17 @@
 # I haven't tried it myself, so I would love to hear from you about the
 # results.
 #
-# http_proxy =
+# http_proxy=
+# proxy_user=
+# proxy_password=
 # no_proxy =

+# User-Agent
+# default set to "Axel VERSION (ARCH)"
+#
+# user_agent="xxxxx 2.4 xxxx"
+#
+
 # Keep CGI arguments in the local filename?
 #
 # strip_cgi_parameters = 1
diff -Nu ../axel_whole/branches/2.x/conf.c ./conf.c
--- ../axel_whole/branches/2.x/conf.c 2009-05-15 21:10:01.000000000 +0800
+++ ./conf.c 2010-01-16 12:31:31.000000000 +0800
@@ -79,6 +79,8 @@
  /* Long live macros!! */
  get_config_string( default_filename );
  get_config_string( http_proxy );
+ get_config_string( proxy_user );
+ get_config_string( proxy_password );
  get_config_string( no_proxy );
  get_config_number( strip_cgi_parameters );
  get_config_number( save_state_interval );
@@ -94,6 +96,7 @@
  get_config_number( search_threads );
  get_config_number( search_amount );
  get_config_number( search_top );
+ get_config_string( user_agent );

  /* Option defunct but shouldn't be an error */
  if( strcmp( key, "speed_type" ) == 0 )
@@ -127,6 +130,8 @@
  strcpy( conf->default_filename, "default" );
  *conf->http_proxy = 0;
  *conf->no_proxy = 0;
+ *conf->proxy_user = 0;
+ *conf->proxy_password   = 0;
  conf->strip_cgi_parameters = 1;
  conf->save_state_interval = 10;
  conf->connection_timeout = 45;
diff -Nu ../axel_whole/branches/2.x/conf.h ./conf.h
--- ../axel_whole/branches/2.x/conf.h 2009-05-15 21:10:01.000000000 +0800
+++ ./conf.h 2009-05-25 12:06:21.000000000 +0800
@@ -27,6 +27,8 @@
 {
  char default_filename[MAX_STRING];
  char http_proxy[MAX_STRING];
+ char proxy_user[MAX_STRING];
+ char proxy_password[MAX_STRING];
  char no_proxy[MAX_STRING];
  int strip_cgi_parameters;
  int save_state_interval;
diff -Nu ../axel_whole/branches/2.x/conn.c ./conn.c
--- ../axel_whole/branches/2.x/conn.c 2009-05-15 21:10:01.000000000 +0800
+++ ./conn.c 2010-01-16 12:30:36.000000000 +0800
@@ -27,6 +27,25 @@

 char string[MAX_STRING];

+int base64_encode(const unsigned char *data, int length, char *dest)
+{
+ char base64_table[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz0123456789+/";
+    int i;
+
+ for( i = 0; data[i*3]; i ++ )
+ {
+ dest[i*4] = base64_table[(data[i*3]>>2)];
+ dest[i*4+1] = base64_table[((data[i*3]&3)<<4)|(data[i*3+1]>>4)];
+ dest[i*4+2] = base64_table[((data[i*3+1]&15)<<2)|(data[i*3+2]>>6)];
+ dest[i*4+3] = base64_table[data[i*3+2]&63];
+ if( data[i*3+2] == 0 ) dest[i*4+3] = '=';
+ if( data[i*3+1] == 0 ) dest[i*4+2] = '=';
+ }
+
+    return 0;
+}
+
 /* Convert an URL to a conn_t structure */
 int conn_set( conn_t *conn, char *set_url )
 {
@@ -260,6 +279,23 @@
  http_addheader( conn->http, "User-Agent: %s", conn->conf->user_agent );
  for( i = 0; i < conn->conf->add_header_count; i++)
  http_addheader( conn->http, "%s", conn->conf->add_header[i] );
+
+        if( *conn->conf->http_proxy != 0 )
+        {
+            if( (*conn->conf->proxy_user != 0) &&
(*conn->conf->proxy_password != 0) )
+            {
+                char auth[MAX_STRING];
+                char auth_64[MAX_STRING];
+
+                memset( auth, 0, MAX_STRING );
+                memset( auth_64, 0, MAX_STRING );
+                snprintf( auth, MAX_STRING, "%s:%s",
conn->conf->proxy_user, conn->conf->proxy_password );
+                base64_encode( auth, strlen(auth), auth_64 );
+
+                http_addheader( conn->http, "Proxy-Authorization: Basic
%s", auth_64 );
+
+            }
+        }
  }
  return( 1 );
 }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/axel-devel/attachments/20100116/282e76b6/attachment.htm>


More information about the axel-devel mailing list