Fossil SCM
Add the "pragma client-url" card to the sync protocol.
Commit
84358b7db1bfe5d7e2afd701fcd0a08b0672c9b39d4b81b7b985eaff7001ca20
Parent
7e993c709ad18ef…
1 file changed
+43
-4
+43
-4
| --- src/xfer.c | ||
| +++ src/xfer.c | ||
| @@ -1150,10 +1150,29 @@ | ||
| 1150 | 1150 | ** } |
| 1151 | 1151 | */ |
| 1152 | 1152 | int xfer_run_common_script(void){ |
| 1153 | 1153 | return xfer_run_script(xfer_common_code(), 0, 0); |
| 1154 | 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 | +} | |
| 1155 | 1174 | |
| 1156 | 1175 | /* |
| 1157 | 1176 | ** If this variable is set, disable login checks. Used for debugging |
| 1158 | 1177 | ** only. |
| 1159 | 1178 | */ |
| @@ -1707,10 +1726,23 @@ | ||
| 1707 | 1726 | " AND json_extract(value,'$.clientid')=%Q", |
| 1708 | 1727 | blob_str(&xfer.aToken[2]) |
| 1709 | 1728 | ); |
| 1710 | 1729 | db_protect_pop(); |
| 1711 | 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 | + } | |
| 1712 | 1744 | |
| 1713 | 1745 | }else |
| 1714 | 1746 | |
| 1715 | 1747 | /* Unknown message |
| 1716 | 1748 | */ |
| @@ -2145,14 +2177,21 @@ | ||
| 2145 | 2177 | } |
| 2146 | 2178 | |
| 2147 | 2179 | /* Remember the URL of the sync target in the config file on the |
| 2148 | 2180 | ** first successful round-trip */ |
| 2149 | 2181 | 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 | + } | |
| 2154 | 2193 | } |
| 2155 | 2194 | |
| 2156 | 2195 | /* Output current stats */ |
| 2157 | 2196 | if( syncFlags & SYNC_VERBOSE ){ |
| 2158 | 2197 | fossil_print(zValueFormat /*works-like:"%s%d%d%d%d"*/, "Sent:", |
| 2159 | 2198 |
| --- 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 |