Fossil SCM

Add the "pragma client-url" card to the sync protocol.

drh 2021-12-21 12:43 trunk
Commit 84358b7db1bfe5d7e2afd701fcd0a08b0672c9b39d4b81b7b985eaff7001ca20
1 file changed +43 -4
+43 -4
--- src/xfer.c
+++ src/xfer.c
@@ -1150,10 +1150,29 @@
11501150
** }
11511151
*/
11521152
int xfer_run_common_script(void){
11531153
return xfer_run_script(xfer_common_code(), 0, 0);
11541154
}
1155
+
1156
+/*
1157
+** This routine makes a "syncwith:URL" entry in the CONFIG table to
1158
+** indicate that a sync is occuring with zUrl.
1159
+*/
1160
+static void xfer_syncwith(const char *zUrl){
1161
+ UrlData x;
1162
+ memset(&x, 0, sizeof(x));
1163
+ url_parse_local(zUrl, URL_OMIT_USER, &x);
1164
+ if( x.protocol && strncmp(x.protocol,"http",4)==0
1165
+ && x.name && sqlite3_strlike("%localhost%", x.name, 0)!=0
1166
+ ){
1167
+ db_unprotect(PROTECT_CONFIG);
1168
+ db_multi_exec("REPLACE INTO config(name,value,mtime)"
1169
+ "VALUES('syncwith:%q',1,now())", x.canonical);
1170
+ db_protect_pop();
1171
+ }
1172
+ url_unparse(&x);
1173
+}
11551174
11561175
/*
11571176
** If this variable is set, disable login checks. Used for debugging
11581177
** only.
11591178
*/
@@ -1707,10 +1726,23 @@
17071726
" AND json_extract(value,'$.clientid')=%Q",
17081727
blob_str(&xfer.aToken[2])
17091728
);
17101729
db_protect_pop();
17111730
}
1731
+
1732
+ /* pragma client-url URL
1733
+ **
1734
+ ** This pragma is an informational notification to the server that
1735
+ ** their relationship could, in theory, be inverted by having the
1736
+ ** server call the client at URL.
1737
+ */
1738
+ if( blob_eq(&xfer.aToken[1], "client-url")
1739
+ && xfer.nToken==3
1740
+ && g.perm.Write
1741
+ ){
1742
+ xfer_syncwith(blob_str(&xfer.aToken[2]));
1743
+ }
17121744
17131745
}else
17141746
17151747
/* Unknown message
17161748
*/
@@ -2145,14 +2177,21 @@
21452177
}
21462178
21472179
/* Remember the URL of the sync target in the config file on the
21482180
** first successful round-trip */
21492181
if( nCycle==0 && db_is_writeable("repository") ){
2150
- db_unprotect(PROTECT_CONFIG);
2151
- db_multi_exec("REPLACE INTO config(name,value,mtime)"
2152
- "VALUES('syncwith:%q',1,now())", g.url.canonical);
2153
- db_protect_pop();
2182
+ xfer_syncwith(g.url.canonical);
2183
+ }
2184
+
2185
+ /* Send the client-url pragma on the first cycle if the client has
2186
+ ** a known public url.
2187
+ */
2188
+ if( nCycle==0 ){
2189
+ const char *zSelfUrl = public_url();
2190
+ if( zSelfUrl ){
2191
+ blob_appendf(&send, "pragma client-url %s\n", zSelfUrl);
2192
+ }
21542193
}
21552194
21562195
/* Output current stats */
21572196
if( syncFlags & SYNC_VERBOSE ){
21582197
fossil_print(zValueFormat /*works-like:"%s%d%d%d%d"*/, "Sent:",
21592198
--- src/xfer.c
+++ src/xfer.c
@@ -1150,10 +1150,29 @@
1150 ** }
1151 */
1152 int xfer_run_common_script(void){
1153 return xfer_run_script(xfer_common_code(), 0, 0);
1154 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1155
1156 /*
1157 ** If this variable is set, disable login checks. Used for debugging
1158 ** only.
1159 */
@@ -1707,10 +1726,23 @@
1707 " AND json_extract(value,'$.clientid')=%Q",
1708 blob_str(&xfer.aToken[2])
1709 );
1710 db_protect_pop();
1711 }
 
 
 
 
 
 
 
 
 
 
 
 
 
1712
1713 }else
1714
1715 /* Unknown message
1716 */
@@ -2145,14 +2177,21 @@
2145 }
2146
2147 /* Remember the URL of the sync target in the config file on the
2148 ** first successful round-trip */
2149 if( nCycle==0 && db_is_writeable("repository") ){
2150 db_unprotect(PROTECT_CONFIG);
2151 db_multi_exec("REPLACE INTO config(name,value,mtime)"
2152 "VALUES('syncwith:%q',1,now())", g.url.canonical);
2153 db_protect_pop();
 
 
 
 
 
 
 
2154 }
2155
2156 /* Output current stats */
2157 if( syncFlags & SYNC_VERBOSE ){
2158 fossil_print(zValueFormat /*works-like:"%s%d%d%d%d"*/, "Sent:",
2159
--- src/xfer.c
+++ src/xfer.c
@@ -1150,10 +1150,29 @@
1150 ** }
1151 */
1152 int xfer_run_common_script(void){
1153 return xfer_run_script(xfer_common_code(), 0, 0);
1154 }
1155
1156 /*
1157 ** This routine makes a "syncwith:URL" entry in the CONFIG table to
1158 ** indicate that a sync is occuring with zUrl.
1159 */
1160 static void xfer_syncwith(const char *zUrl){
1161 UrlData x;
1162 memset(&x, 0, sizeof(x));
1163 url_parse_local(zUrl, URL_OMIT_USER, &x);
1164 if( x.protocol && strncmp(x.protocol,"http",4)==0
1165 && x.name && sqlite3_strlike("%localhost%", x.name, 0)!=0
1166 ){
1167 db_unprotect(PROTECT_CONFIG);
1168 db_multi_exec("REPLACE INTO config(name,value,mtime)"
1169 "VALUES('syncwith:%q',1,now())", x.canonical);
1170 db_protect_pop();
1171 }
1172 url_unparse(&x);
1173 }
1174
1175 /*
1176 ** If this variable is set, disable login checks. Used for debugging
1177 ** only.
1178 */
@@ -1707,10 +1726,23 @@
1726 " AND json_extract(value,'$.clientid')=%Q",
1727 blob_str(&xfer.aToken[2])
1728 );
1729 db_protect_pop();
1730 }
1731
1732 /* pragma client-url URL
1733 **
1734 ** This pragma is an informational notification to the server that
1735 ** their relationship could, in theory, be inverted by having the
1736 ** server call the client at URL.
1737 */
1738 if( blob_eq(&xfer.aToken[1], "client-url")
1739 && xfer.nToken==3
1740 && g.perm.Write
1741 ){
1742 xfer_syncwith(blob_str(&xfer.aToken[2]));
1743 }
1744
1745 }else
1746
1747 /* Unknown message
1748 */
@@ -2145,14 +2177,21 @@
2177 }
2178
2179 /* Remember the URL of the sync target in the config file on the
2180 ** first successful round-trip */
2181 if( nCycle==0 && db_is_writeable("repository") ){
2182 xfer_syncwith(g.url.canonical);
2183 }
2184
2185 /* Send the client-url pragma on the first cycle if the client has
2186 ** a known public url.
2187 */
2188 if( nCycle==0 ){
2189 const char *zSelfUrl = public_url();
2190 if( zSelfUrl ){
2191 blob_appendf(&send, "pragma client-url %s\n", zSelfUrl);
2192 }
2193 }
2194
2195 /* Output current stats */
2196 if( syncFlags & SYNC_VERBOSE ){
2197 fossil_print(zValueFormat /*works-like:"%s%d%d%d%d"*/, "Sent:",
2198

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button