Check-in [676fdd088a]
Not logged in
Overview

SHA1 Hash:676fdd088ad1a95ef587a25fe5c64bd3e42787fd
Date: 2008-05-01 22:49:57
User: drh
Comment:Enable proxy support using the "fossil setting proxy" command. This check-in is made using a proxy.
Timelines: ancestors | descendants | both | trunk
Other Links: files | ZIP archive | manifest

Tags And Properties
Changes
[hide diffs]

Modified src/clone.c from [f6aae5647c] to [dbac624435].

@@ -72,10 +72,11 @@
       db_multi_exec("INSERT OR IGNORE INTO %Q SELECT * FROM orig.%Q",
                     zTab, zTab);
     }
     db_finalize(&q);
   }else{
+    url_enable_proxy(0);
     client_sync(0,0,1);
   }
   verify_cancel();
   db_end_transaction(0);
 }

Modified src/db.c from [ce0cf6d921] to [79e9e0ceda].

@@ -895,10 +895,30 @@
     once = 0;
   }
 }
 
 /*
+** Return true if the string zVal represents "true" (or "false").
+*/
+int is_truth(const char *zVal){
+  static const char *azOn[] = { "on", "yes", "true", "1" };
+  int i;
+  for(i=0; i<sizeof(azOn)/sizeof(azOn[0]); i++){
+    if( strcmp(zVal,azOn[i])==0 ) return 1;
+  }
+  return 0;
+}
+int is_false(const char *zVal){
+  static const char *azOff[] = { "off", "no", "false", "0" };
+  int i;
+  for(i=0; i<sizeof(azOff)/sizeof(azOff[0]); i++){
+    if( strcmp(zVal,azOff[i])==0 ) return 1;
+  }
+  return 0;
+}
+
+/*
 ** Get and set values from the CONFIG, GLOBAL_CONFIG and VVAR table in the
 ** repository and local databases.
 */
 char *db_get(const char *zName, char *zDefault){
   char *z = 0;
@@ -956,20 +976,13 @@
     db_multi_exec("DELETE FROM config WHERE name=%Q", zName);
   }
   db_end_transaction(0);
 }
 int db_get_boolean(const char *zName, int dflt){
-  static const char *azOn[] = { "on", "yes", "true", "1" };
-  static const char *azOff[] = { "off", "no", "false", "0" };
-  int i;
   char *zVal = db_get(zName, dflt ? "on" : "off");
-  for(i=0; i<sizeof(azOn)/sizeof(azOn[0]); i++){
-    if( strcmp(zVal,azOn[i])==0 ) return 1;
-  }
-  for(i=0; i<sizeof(azOff)/sizeof(azOff[0]); i++){
-    if( strcmp(zVal,azOff[i])==0 ) return 0;
-  }
+  if( is_truth(zVal) ) return 1;
+  if( is_false(zVal) ) return 0;
   return dflt;
 }
 char *db_lget(const char *zName, char *zDefault){
   return db_text((char*)zDefault,
                  "SELECT value FROM vvar WHERE name=%Q", zName);
@@ -1064,10 +1077,12 @@
 **                     unrestricted access to the repository.
 **
 **    omitsign         When enabled, fossil will not attempt to sign any
 **                     commit with gpg. All commits will be unsigned.
 **
+**    proxy            URL of the HTTP proxy to use
+**
 **    diff-command     External command to run when performing a diff.
 **                     If undefined, the internal text diff will be used.
 **
 **    gdiff-command    External command to run when performing a graphical
 **                     diff. If undefined, text diff will be used.
@@ -1077,10 +1092,11 @@
     "autosync",
     "pgp-command",
     "editor",
     "localauth",
     "omitsign",
+    "proxy",
     "diff-command",
     "gdiff-command",
   };
   int i;
   int globalFlag = find_option("global","g",0)!=0;

Modified src/sync.c from [6d1a08c4d7] to [b1aa8a41a0].

@@ -58,10 +58,11 @@
   if( g.urlPort!=80 ){
     printf("Autosync:  http://%s:%d%s\n", g.urlName, g.urlPort, g.urlPath);
   }else{
     printf("Autosync:  http://%s%s\n", g.urlName, g.urlPath);
   }
+  url_enable_proxy("via proxy: ");
   client_sync((flags & AUTOSYNC_PUSH)!=0, 1, 0);
   return 1;
 }
 
 /*
@@ -92,10 +93,11 @@
       printf("Server:    http://%s:%d%s\n", g.urlName, g.urlPort, g.urlPath);
     }else{
       printf("Server:    http://%s%s\n", g.urlName, g.urlPath);
     }
   }
+  url_enable_proxy("via proxy: ");
 }
 
 /*
 ** COMMAND: pull
 **

Modified src/url.c from [6f5bc8946f] to [7c8f0faf01].

@@ -111,11 +111,11 @@
 
 /*
 ** COMMAND: test-urlparser
 */
 void cmd_test_urlparser(void){
-  if( g.argc!=3 ){
+  if( g.argc!=3 && g.argc!=4 ){
     usage("URL");
   }
   url_parse(g.argv[2]);
   printf("g.urlIsFile    = %d\n", g.urlIsFile);
   printf("g.urlName      = %s\n", g.urlName);
@@ -122,6 +122,20 @@
   printf("g.urlPort      = %d\n", g.urlPort);
   printf("g.urlPath      = %s\n", g.urlPath);
   printf("g.urlUser      = %s\n", g.urlUser);
   printf("g.urlPasswd    = %s\n", g.urlPasswd);
   printf("g.urlCanonical = %s\n", g.urlCanonical);
+}
+
+/*
+** If the "proxy" setting is defined, then change the URL to refer
+** to the proxy server.
+*/
+void url_enable_proxy(const char *zMsg){
+  const char *zProxy = db_get("proxy", 0);
+  if( zProxy && zProxy[0] && !is_false(zProxy) ){
+    char *zOriginalUrl = g.urlCanonical;
+    if( zMsg ) printf("%s%s\n", zMsg, zProxy);
+    url_parse(zProxy);
+    g.urlPath = zOriginalUrl;
+  }
 }