Check-in [84358b7db1]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add the "pragma client-url" card to the sync protocol.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 84358b7db1bfe5d7e2afd701fcd0a08b0672c9b39d4b81b7b985eaff7001ca20
User & Date: drh 2021-12-21 12:43:58.445
Context
2021-12-21
14:04
For sync, the client should only send "pragma client-url" if not doing a cross-project import. check-in: b330ce6cfb user: drh tags: trunk
12:43
Add the "pragma client-url" card to the sync protocol. check-in: 84358b7db1 user: drh tags: trunk
2021-12-20
20:52
Better documentation for the email-url setting. Add a new entry form for the email-url setting on the /setup_config page. check-in: 7e993c709a user: drh tags: trunk
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/xfer.c.
1148
1149
1150
1151
1152
1153
1154



















1155
1156
1157
1158
1159
1160
1161
**   # ... code here
**   set common_done 1
** }
*/
int xfer_run_common_script(void){
  return xfer_run_script(xfer_common_code(), 0, 0);
}




















/*
** If this variable is set, disable login checks.  Used for debugging
** only.
*/
static int disableLogin = 0;








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
**   # ... code here
**   set common_done 1
** }
*/
int xfer_run_common_script(void){
  return xfer_run_script(xfer_common_code(), 0, 0);
}

/*
** This routine makes a "syncwith:URL" entry in the CONFIG table to
** indicate that a sync is occuring with zUrl.
*/
static void xfer_syncwith(const char *zUrl){
  UrlData x;
  memset(&x, 0, sizeof(x));
  url_parse_local(zUrl, URL_OMIT_USER, &x);
  if( x.protocol && strncmp(x.protocol,"http",4)==0
   && x.name && sqlite3_strlike("%localhost%", x.name, 0)!=0
  ){
    db_unprotect(PROTECT_CONFIG);
    db_multi_exec("REPLACE INTO config(name,value,mtime)"
                  "VALUES('syncwith:%q',1,now())", x.canonical);
    db_protect_pop();
  }
  url_unparse(&x);
}

/*
** If this variable is set, disable login checks.  Used for debugging
** only.
*/
static int disableLogin = 0;

1705
1706
1707
1708
1709
1710
1711













1712
1713
1714
1715
1716
1717
1718
          "DELETE FROM config"
          " WHERE name GLOB 'ci-lock-*'"
          "   AND json_extract(value,'$.clientid')=%Q",
          blob_str(&xfer.aToken[2])
        );
        db_protect_pop();
      }














    }else

    /* Unknown message
    */
    {
      cgi_reset_content();







>
>
>
>
>
>
>
>
>
>
>
>
>







1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
          "DELETE FROM config"
          " WHERE name GLOB 'ci-lock-*'"
          "   AND json_extract(value,'$.clientid')=%Q",
          blob_str(&xfer.aToken[2])
        );
        db_protect_pop();
      }

      /*   pragma client-url URL
      **
      ** This pragma is an informational notification to the server that
      ** their relationship could, in theory, be inverted by having the
      ** server call the client at URL.
      */
      if( blob_eq(&xfer.aToken[1], "client-url")
       && xfer.nToken==3
       && g.perm.Write
      ){
        xfer_syncwith(blob_str(&xfer.aToken[2]));
      }

    }else

    /* Unknown message
    */
    {
      cgi_reset_content();
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152

2153








2154
2155
2156
2157
2158
2159
2160
      go = 2;
      break;
    }

    /* Remember the URL of the sync target in the config file on the
    ** first successful round-trip */
    if( nCycle==0 && db_is_writeable("repository") ){
      db_unprotect(PROTECT_CONFIG);
      db_multi_exec("REPLACE INTO config(name,value,mtime)"
                    "VALUES('syncwith:%q',1,now())", g.url.canonical);

      db_protect_pop();








    }

    /* Output current stats */
    if( syncFlags & SYNC_VERBOSE ){
      fossil_print(zValueFormat /*works-like:"%s%d%d%d%d"*/, "Sent:",
                   blob_size(&send), nCardSent+xfer.nGimmeSent+xfer.nIGotSent,
                   xfer.nFileSent, xfer.nDeltaSent);







<
<
|
>
|
>
>
>
>
>
>
>
>







2175
2176
2177
2178
2179
2180
2181


2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
      go = 2;
      break;
    }

    /* Remember the URL of the sync target in the config file on the
    ** first successful round-trip */
    if( nCycle==0 && db_is_writeable("repository") ){


      xfer_syncwith(g.url.canonical);
    }

    /* Send the client-url pragma on the first cycle if the client has
    ** a known public url.
    */
    if( nCycle==0 ){
      const char *zSelfUrl = public_url();
      if( zSelfUrl ){
        blob_appendf(&send, "pragma client-url %s\n", zSelfUrl);
      }
    }

    /* Output current stats */
    if( syncFlags & SYNC_VERBOSE ){
      fossil_print(zValueFormat /*works-like:"%s%d%d%d%d"*/, "Sent:",
                   blob_size(&send), nCardSent+xfer.nGimmeSent+xfer.nIGotSent,
                   xfer.nFileSent, xfer.nDeltaSent);