Fossil SCM
Refactoring some of the configuration sync logic in preparation for bigger changes.
Commit
b44d4a89d0f0a3eb8965cbd7fa462b813d818e36
Parent
0a89d03cf658ecb…
2 files changed
+34
+9
-54
+34
| --- src/configure.c | ||
| +++ src/configure.c | ||
| @@ -290,10 +290,44 @@ | ||
| 290 | 290 | flag_clear_function, 0, 0); |
| 291 | 291 | flag_value = 0xffff; |
| 292 | 292 | db_multi_exec(zSQL2); |
| 293 | 293 | } |
| 294 | 294 | } |
| 295 | + | |
| 296 | +/* | |
| 297 | +** Process a single "config" card received from the other side of a | |
| 298 | +** sync session. | |
| 299 | +** | |
| 300 | +** Mask consists of one or more CONFIGSET_* values ORed together, to | |
| 301 | +** designate what types of configuration we are allowed to receive. | |
| 302 | +*/ | |
| 303 | +void configure_receive(const char *zName, Blob *pContent, int mask){ | |
| 304 | + if( (configure_is_exportable(zName) & mask)==0 ) return; | |
| 305 | + if( strcmp(zName, "logo-image")==0 ){ | |
| 306 | + Stmt ins; | |
| 307 | + db_prepare(&ins, | |
| 308 | + "REPLACE INTO config(name, value) VALUES(:name, :value)" | |
| 309 | + ); | |
| 310 | + db_bind_text(&ins, ":name", zName); | |
| 311 | + db_bind_blob(&ins, ":value", pContent); | |
| 312 | + db_step(&ins); | |
| 313 | + db_finalize(&ins); | |
| 314 | + }else if( zName[0]=='@' ){ | |
| 315 | + /* Notice that we are evaluating arbitrary SQL received from the | |
| 316 | + ** client. But this can only happen if the client has authenticated | |
| 317 | + ** as an administrator, so presumably we trust the client at this | |
| 318 | + ** point. | |
| 319 | + */ | |
| 320 | + db_multi_exec("%s", blob_str(pContent)); | |
| 321 | + }else{ | |
| 322 | + db_multi_exec( | |
| 323 | + "REPLACE INTO config(name,value) VALUES(%Q,%Q)", | |
| 324 | + zName, blob_str(pContent) | |
| 325 | + ); | |
| 326 | + } | |
| 327 | +} | |
| 328 | + | |
| 295 | 329 | |
| 296 | 330 | /* |
| 297 | 331 | ** After receiving configuration data, call this routine to transfer |
| 298 | 332 | ** the results into the main database. |
| 299 | 333 | */ |
| 300 | 334 |
| --- src/configure.c | |
| +++ src/configure.c | |
| @@ -290,10 +290,44 @@ | |
| 290 | flag_clear_function, 0, 0); |
| 291 | flag_value = 0xffff; |
| 292 | db_multi_exec(zSQL2); |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | /* |
| 297 | ** After receiving configuration data, call this routine to transfer |
| 298 | ** the results into the main database. |
| 299 | */ |
| 300 |
| --- src/configure.c | |
| +++ src/configure.c | |
| @@ -290,10 +290,44 @@ | |
| 290 | flag_clear_function, 0, 0); |
| 291 | flag_value = 0xffff; |
| 292 | db_multi_exec(zSQL2); |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | /* |
| 297 | ** Process a single "config" card received from the other side of a |
| 298 | ** sync session. |
| 299 | ** |
| 300 | ** Mask consists of one or more CONFIGSET_* values ORed together, to |
| 301 | ** designate what types of configuration we are allowed to receive. |
| 302 | */ |
| 303 | void configure_receive(const char *zName, Blob *pContent, int mask){ |
| 304 | if( (configure_is_exportable(zName) & mask)==0 ) return; |
| 305 | if( strcmp(zName, "logo-image")==0 ){ |
| 306 | Stmt ins; |
| 307 | db_prepare(&ins, |
| 308 | "REPLACE INTO config(name, value) VALUES(:name, :value)" |
| 309 | ); |
| 310 | db_bind_text(&ins, ":name", zName); |
| 311 | db_bind_blob(&ins, ":value", pContent); |
| 312 | db_step(&ins); |
| 313 | db_finalize(&ins); |
| 314 | }else if( zName[0]=='@' ){ |
| 315 | /* Notice that we are evaluating arbitrary SQL received from the |
| 316 | ** client. But this can only happen if the client has authenticated |
| 317 | ** as an administrator, so presumably we trust the client at this |
| 318 | ** point. |
| 319 | */ |
| 320 | db_multi_exec("%s", blob_str(pContent)); |
| 321 | }else{ |
| 322 | db_multi_exec( |
| 323 | "REPLACE INTO config(name,value) VALUES(%Q,%Q)", |
| 324 | zName, blob_str(pContent) |
| 325 | ); |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | |
| 330 | /* |
| 331 | ** After receiving configuration data, call this routine to transfer |
| 332 | ** the results into the main database. |
| 333 | */ |
| 334 |
+9
-54
| --- src/xfer.c | ||
| +++ src/xfer.c | ||
| @@ -1052,38 +1052,15 @@ | ||
| 1052 | 1052 | cgi_reset_content(); |
| 1053 | 1053 | @ error not\sauthorized\sto\spush\sconfiguration |
| 1054 | 1054 | nErr++; |
| 1055 | 1055 | break; |
| 1056 | 1056 | } |
| 1057 | - if( zName[0]!='@' ){ | |
| 1058 | - if( strcmp(zName, "logo-image")==0 ){ | |
| 1059 | - Stmt ins; | |
| 1060 | - db_prepare(&ins, | |
| 1061 | - "REPLACE INTO config(name, value) VALUES(:name, :value)" | |
| 1062 | - ); | |
| 1063 | - db_bind_text(&ins, ":name", zName); | |
| 1064 | - db_bind_blob(&ins, ":value", &content); | |
| 1065 | - db_step(&ins); | |
| 1066 | - db_finalize(&ins); | |
| 1067 | - }else{ | |
| 1068 | - db_multi_exec( | |
| 1069 | - "REPLACE INTO config(name,value) VALUES(%Q,%Q)", | |
| 1070 | - zName, blob_str(&content) | |
| 1071 | - ); | |
| 1072 | - } | |
| 1073 | - }else{ | |
| 1074 | - /* Notice that we are evaluating arbitrary SQL received from the | |
| 1075 | - ** client. But this can only happen if the client has authenticated | |
| 1076 | - ** as an administrator, so presumably we trust the client at this | |
| 1077 | - ** point. | |
| 1078 | - */ | |
| 1079 | - if( !recvConfig ){ | |
| 1080 | - configure_prepare_to_receive(0); | |
| 1081 | - recvConfig = 1; | |
| 1082 | - } | |
| 1083 | - db_multi_exec("%s", blob_str(&content)); | |
| 1084 | - } | |
| 1057 | + if( !recvConfig ){ | |
| 1058 | + configure_prepare_to_receive(0); | |
| 1059 | + recvConfig = 1; | |
| 1060 | + } | |
| 1061 | + configure_receive(zName, &content, CONFIGSET_ALL); | |
| 1085 | 1062 | blob_reset(&content); |
| 1086 | 1063 | blob_seek(xfer.pIn, 1, BLOB_SEEK_CUR); |
| 1087 | 1064 | }else |
| 1088 | 1065 | |
| 1089 | 1066 | |
| @@ -1545,44 +1522,22 @@ | ||
| 1545 | 1522 | }else |
| 1546 | 1523 | |
| 1547 | 1524 | /* config NAME SIZE \n CONTENT |
| 1548 | 1525 | ** |
| 1549 | 1526 | ** Receive a configuration value from the server. |
| 1527 | + ** | |
| 1528 | + ** The received configuration setting is silently ignored if it was | |
| 1529 | + ** not requested by a prior "reqconfig" sent from client to server. | |
| 1550 | 1530 | */ |
| 1551 | 1531 | if( blob_eq(&xfer.aToken[0],"config") && xfer.nToken==3 |
| 1552 | 1532 | && blob_is_int(&xfer.aToken[2], &size) ){ |
| 1553 | 1533 | const char *zName = blob_str(&xfer.aToken[1]); |
| 1554 | 1534 | Blob content; |
| 1555 | 1535 | blob_zero(&content); |
| 1556 | 1536 | blob_extract(xfer.pIn, size, &content); |
| 1557 | 1537 | g.okAdmin = g.okRdAddr = 1; |
| 1558 | - if( configure_is_exportable(zName) & origConfigRcvMask ){ | |
| 1559 | - if( zName[0]!='@' ){ | |
| 1560 | - if( strcmp(zName, "logo-image")==0 ){ | |
| 1561 | - Stmt ins; | |
| 1562 | - db_prepare(&ins, | |
| 1563 | - "REPLACE INTO config(name, value) VALUES(:name, :value)" | |
| 1564 | - ); | |
| 1565 | - db_bind_text(&ins, ":name", zName); | |
| 1566 | - db_bind_blob(&ins, ":value", &content); | |
| 1567 | - db_step(&ins); | |
| 1568 | - db_finalize(&ins); | |
| 1569 | - }else{ | |
| 1570 | - db_multi_exec( | |
| 1571 | - "REPLACE INTO config(name,value) VALUES(%Q,%Q)", | |
| 1572 | - zName, blob_str(&content) | |
| 1573 | - ); | |
| 1574 | - } | |
| 1575 | - }else{ | |
| 1576 | - /* Notice that we are evaluating arbitrary SQL received from the | |
| 1577 | - ** server. But this can only happen if we have specifically | |
| 1578 | - ** requested configuration information from the server, so | |
| 1579 | - ** presumably the operator trusts the server. | |
| 1580 | - */ | |
| 1581 | - db_multi_exec("%s", blob_str(&content)); | |
| 1582 | - } | |
| 1583 | - } | |
| 1538 | + configure_receive(zName, &content, origConfigRcvMask); | |
| 1584 | 1539 | nCardSent++; |
| 1585 | 1540 | blob_reset(&content); |
| 1586 | 1541 | blob_seek(xfer.pIn, 1, BLOB_SEEK_CUR); |
| 1587 | 1542 | }else |
| 1588 | 1543 | |
| 1589 | 1544 |
| --- src/xfer.c | |
| +++ src/xfer.c | |
| @@ -1052,38 +1052,15 @@ | |
| 1052 | cgi_reset_content(); |
| 1053 | @ error not\sauthorized\sto\spush\sconfiguration |
| 1054 | nErr++; |
| 1055 | break; |
| 1056 | } |
| 1057 | if( zName[0]!='@' ){ |
| 1058 | if( strcmp(zName, "logo-image")==0 ){ |
| 1059 | Stmt ins; |
| 1060 | db_prepare(&ins, |
| 1061 | "REPLACE INTO config(name, value) VALUES(:name, :value)" |
| 1062 | ); |
| 1063 | db_bind_text(&ins, ":name", zName); |
| 1064 | db_bind_blob(&ins, ":value", &content); |
| 1065 | db_step(&ins); |
| 1066 | db_finalize(&ins); |
| 1067 | }else{ |
| 1068 | db_multi_exec( |
| 1069 | "REPLACE INTO config(name,value) VALUES(%Q,%Q)", |
| 1070 | zName, blob_str(&content) |
| 1071 | ); |
| 1072 | } |
| 1073 | }else{ |
| 1074 | /* Notice that we are evaluating arbitrary SQL received from the |
| 1075 | ** client. But this can only happen if the client has authenticated |
| 1076 | ** as an administrator, so presumably we trust the client at this |
| 1077 | ** point. |
| 1078 | */ |
| 1079 | if( !recvConfig ){ |
| 1080 | configure_prepare_to_receive(0); |
| 1081 | recvConfig = 1; |
| 1082 | } |
| 1083 | db_multi_exec("%s", blob_str(&content)); |
| 1084 | } |
| 1085 | blob_reset(&content); |
| 1086 | blob_seek(xfer.pIn, 1, BLOB_SEEK_CUR); |
| 1087 | }else |
| 1088 | |
| 1089 | |
| @@ -1545,44 +1522,22 @@ | |
| 1545 | }else |
| 1546 | |
| 1547 | /* config NAME SIZE \n CONTENT |
| 1548 | ** |
| 1549 | ** Receive a configuration value from the server. |
| 1550 | */ |
| 1551 | if( blob_eq(&xfer.aToken[0],"config") && xfer.nToken==3 |
| 1552 | && blob_is_int(&xfer.aToken[2], &size) ){ |
| 1553 | const char *zName = blob_str(&xfer.aToken[1]); |
| 1554 | Blob content; |
| 1555 | blob_zero(&content); |
| 1556 | blob_extract(xfer.pIn, size, &content); |
| 1557 | g.okAdmin = g.okRdAddr = 1; |
| 1558 | if( configure_is_exportable(zName) & origConfigRcvMask ){ |
| 1559 | if( zName[0]!='@' ){ |
| 1560 | if( strcmp(zName, "logo-image")==0 ){ |
| 1561 | Stmt ins; |
| 1562 | db_prepare(&ins, |
| 1563 | "REPLACE INTO config(name, value) VALUES(:name, :value)" |
| 1564 | ); |
| 1565 | db_bind_text(&ins, ":name", zName); |
| 1566 | db_bind_blob(&ins, ":value", &content); |
| 1567 | db_step(&ins); |
| 1568 | db_finalize(&ins); |
| 1569 | }else{ |
| 1570 | db_multi_exec( |
| 1571 | "REPLACE INTO config(name,value) VALUES(%Q,%Q)", |
| 1572 | zName, blob_str(&content) |
| 1573 | ); |
| 1574 | } |
| 1575 | }else{ |
| 1576 | /* Notice that we are evaluating arbitrary SQL received from the |
| 1577 | ** server. But this can only happen if we have specifically |
| 1578 | ** requested configuration information from the server, so |
| 1579 | ** presumably the operator trusts the server. |
| 1580 | */ |
| 1581 | db_multi_exec("%s", blob_str(&content)); |
| 1582 | } |
| 1583 | } |
| 1584 | nCardSent++; |
| 1585 | blob_reset(&content); |
| 1586 | blob_seek(xfer.pIn, 1, BLOB_SEEK_CUR); |
| 1587 | }else |
| 1588 | |
| 1589 |
| --- src/xfer.c | |
| +++ src/xfer.c | |
| @@ -1052,38 +1052,15 @@ | |
| 1052 | cgi_reset_content(); |
| 1053 | @ error not\sauthorized\sto\spush\sconfiguration |
| 1054 | nErr++; |
| 1055 | break; |
| 1056 | } |
| 1057 | if( !recvConfig ){ |
| 1058 | configure_prepare_to_receive(0); |
| 1059 | recvConfig = 1; |
| 1060 | } |
| 1061 | configure_receive(zName, &content, CONFIGSET_ALL); |
| 1062 | blob_reset(&content); |
| 1063 | blob_seek(xfer.pIn, 1, BLOB_SEEK_CUR); |
| 1064 | }else |
| 1065 | |
| 1066 | |
| @@ -1545,44 +1522,22 @@ | |
| 1522 | }else |
| 1523 | |
| 1524 | /* config NAME SIZE \n CONTENT |
| 1525 | ** |
| 1526 | ** Receive a configuration value from the server. |
| 1527 | ** |
| 1528 | ** The received configuration setting is silently ignored if it was |
| 1529 | ** not requested by a prior "reqconfig" sent from client to server. |
| 1530 | */ |
| 1531 | if( blob_eq(&xfer.aToken[0],"config") && xfer.nToken==3 |
| 1532 | && blob_is_int(&xfer.aToken[2], &size) ){ |
| 1533 | const char *zName = blob_str(&xfer.aToken[1]); |
| 1534 | Blob content; |
| 1535 | blob_zero(&content); |
| 1536 | blob_extract(xfer.pIn, size, &content); |
| 1537 | g.okAdmin = g.okRdAddr = 1; |
| 1538 | configure_receive(zName, &content, origConfigRcvMask); |
| 1539 | nCardSent++; |
| 1540 | blob_reset(&content); |
| 1541 | blob_seek(xfer.pIn, 1, BLOB_SEEK_CUR); |
| 1542 | }else |
| 1543 | |
| 1544 |