Diff
Not logged in

Differences From:

File src/xfer.c part of check-in [64c58fd64f] - Remove the "Dangling" column from the sync status display. by drh on 2008-05-18 17:33:25. [view]

To:

File src/xfer.c part of check-in [28e56282c9] - Finish implementing the configuration command by adding method implementations for "import", "reset", and "pull". by drh on 2008-05-23 19:21:03. [view]

@@ -25,37 +25,8 @@
 */
 #include "config.h"
 #include "xfer.h"
 
-#if INTERFACE
-/*
-** Configuration transfers occur in groups.  These are the allowed
-** groupings:
-*/
-#define CONFIGSET_SKIN   0x000001     /* WWW interface appearance */
-#define CONFIGSET_TKT    0x000002     /* Ticket configuration */
-#define CONFIGSET_PROJ   0x000004     /* Project name */
-
-#endif /* INTERFACE */
-
-/*
-** The following is a list of settings that we are willing to
-** transfer.
-*/
-static struct {
-  const char *zName;   /* Name of the configuration parameter */
-  int groupMask;       /* Which config groups is it part of */
-} aSafeConfig[] = {
-  { "css",                   CONFIGSET_SKIN },
-  { "header",                CONFIGSET_SKIN },
-  { "footer",                CONFIGSET_SKIN },
-  { "project-name",          CONFIGSET_PROJ },
-  { "project-description",   CONFIGSET_PROJ },
-  { "index-page",            CONFIGSET_SKIN },
-  { "timeline-block-markup", CONFIGSET_SKIN },
-  { "timeline-max-comment",  CONFIGSET_SKIN },
-};
-
 /*
 ** This structure holds information about the current state of either
 ** a client or a server that is participating in xfer.
 */
@@ -681,18 +652,14 @@
      && xfer.nToken==2
     ){
       if( g.okRead ){
         char *zName = blob_str(&xfer.aToken[1]);
-        int i;
-        for(i=0; i<count(aSafeConfig); i++){
-          if( strcmp(aSafeConfig[i].zName, zName)==0 ){
-            char *zValue = db_get(zName, 0);
-            if( zValue ){
-              blob_appendf(xfer.pOut, "config %s %d\n%s\n", zName,
-                           strlen(zValue), zValue);
-              free(zValue);
-            }
-            break;
+        if( configure_is_exportable(zName) ){
+          char *zValue = db_get(zName, 0);
+          if( zValue ){
+            blob_appendf(xfer.pOut, "config %s %d\n%s\n", zName,
+                         strlen(zValue), zValue);
+            free(zValue);
           }
         }
       }
     }else
@@ -792,15 +759,17 @@
 ** Records are pushed to the server if pushFlag is true.  Records
 ** are pulled if pullFlag is true.  A full sync occurs if both are
 ** true.
 */
-void client_sync(int pushFlag, int pullFlag, int cloneFlag){
+void client_sync(int pushFlag, int pullFlag, int cloneFlag, int configMask){
   int go = 1;        /* Loop until zero */
   const char *zSCode = db_get("server-code", "x");
   const char *zPCode = db_get("project-code", 0);
   int nCard = 0;         /* Number of cards sent or received */
   int nCycle = 0;        /* Number of round trips to the server */
+  int size;               /* Size of a config value */
   int nFileSend = 0;
+  int origConfigMask;     /* Original value of configMask */
   int nFileRecv;          /* Number of files received */
   int mxPhantomReq = 200; /* Max number of phantoms to request per comm */
   const char *zCookie;    /* Server cookie */
   Blob send;        /* Text we are sending to the server */
@@ -811,9 +780,9 @@
   xfer.pIn = &recv;
   xfer.pOut = &send;
   xfer.mxSend = db_get_int("max-upload", 250000);
 
-  assert( pushFlag || pullFlag || cloneFlag );
+  assert( pushFlag || pullFlag || cloneFlag || configMask );
   assert( !g.urlIsFile );          /* This only works for networking */
 
   db_begin_transaction();
   db_multi_exec(
@@ -823,8 +792,9 @@
   blob_zero(&send);
   blob_zero(&recv);
   blob_zero(&xfer.err);
   blob_zero(&xfer.line);
+  origConfigMask = configMask;
 
   /*
   ** Always begin with a clone, pull, or push message
   */
@@ -863,8 +833,19 @@
     }
     if( pushFlag ){
       send_unsent(&xfer);
       nCard += send_unclustered(&xfer);
+    }
+
+    /* Send configuration parameter requests */
+    if( configMask ){
+      const char *zName;
+      zName = configure_first_name(configMask);
+      while( zName ){
+        blob_appendf(&send, "reqconfig %s\n", zName);
+        zName = configure_next_name(configMask);
+      }
+      configMask = 0;
     }
 
     /* Exchange messages with the server */
     nFileSend = xfer.nFileSent + xfer.nDeltaSent;
@@ -977,12 +958,22 @@
       /*   config NAME SIZE \n CONTENT
       **
       ** Receive a configuration value from the server.
       */
-      if( blob_eq(&xfer.aToken[0],"config") ){
-        /* TBD: Extract name and content */
-        /* Check to see if configuration name is authorized */
-        /* Store content in the config table */
+      if( blob_eq(&xfer.aToken[0],"config") && xfer.nToken==3
+          && blob_is_int(&xfer.aToken[2], &size) ){
+        const char *zName = blob_str(&xfer.aToken[1]);
+        Blob content;
+        blob_zero(&content);
+        blob_extract(xfer.pIn, size, &content);
+        if( configure_is_exportable(zName) & origConfigMask ){
+          db_multi_exec(
+              "REPLACE INTO config(name,value) VALUES(%Q,%Q)",
+              zName, blob_str(&content)
+          );
+        }
+        blob_reset(&content);
+        blob_seek(xfer.pIn, 1, BLOB_SEEK_CUR);
       }else
 
 
       /*    cookie TEXT