| | @@ -819,48 +819,66 @@ |
| 819 | 819 | */ |
| 820 | 820 | static void server_private_xfer_not_authorized(void){ |
| 821 | 821 | @ error not\sauthorized\sto\ssync\sprivate\scontent |
| 822 | 822 | } |
| 823 | 823 | |
| 824 | | -static int commonScriptRan = 0; |
| 825 | | - |
| 826 | | -/* |
| 827 | | -** Run the specified TH1 script, if any, and returns 1 on error. |
| 828 | | -*/ |
| 829 | | -int run_script(const char *zScript, const char *zUuid){ |
| 830 | | - int result = 0; |
| 831 | | - if( !commonScriptRan || !zScript || !(zScript = db_get(zScript, 0))){ |
| 832 | | - return 0; /* No script or common script didn't run, return success. */ |
| 833 | | - } |
| 834 | | - if( commonScriptRan == 1 ){ |
| 835 | | - if( zUuid ){ |
| 836 | | - Th_SetVar(g.interp, "uuid", -1, zUuid, strlen(zUuid)); |
| 837 | | - } |
| 838 | | - result = Th_Eval(g.interp, 0, zScript, -1) != TH_OK; |
| 839 | | - }else{ |
| 840 | | - result = TH_ERROR; |
| 841 | | - } |
| 842 | | - if (result) fossil_error(1, "%s", Th_GetResult(g.interp, 0)); |
| 843 | | - return result; |
| 844 | | -} |
| 845 | | - |
| 846 | | -/* |
| 847 | | -** Run the pre-transfer TH1 script, if any, and returns the return code. |
| 848 | | -** Prepare the "http" command for use in other hook scripts. |
| 849 | | -*/ |
| 850 | | -int run_common_script(void){ |
| 851 | | - int result = 0; |
| 852 | | - if( !commonScriptRan ){ |
| 853 | | - Th_FossilInit(TH_INIT_DEFAULT); /* Make sure TH1 is ready. */ |
| 854 | | - commonScriptRan = 1; /* enable run_script to do something */ |
| 855 | | - result = run_script("xfer-common-script", 0); |
| 856 | | - if( result == TH_ERROR ){ |
| 857 | | - /* Error message is left in th interpreter. */ |
| 858 | | - commonScriptRan = 2; |
| 859 | | - } |
| 860 | | - } |
| 861 | | - return result; |
| 824 | +/* |
| 825 | +** Return the common TH1 code to evaluate prior to evaluating any other |
| 826 | +** TH1 transfer notification scripts. |
| 827 | +*/ |
| 828 | +const char *xfer_common_code(void){ |
| 829 | + return db_get("xfer-common-script", 0); |
| 830 | +} |
| 831 | + |
| 832 | +/* |
| 833 | +** Return the TH1 code to evaluate when a push is processed. |
| 834 | +*/ |
| 835 | +const char *xfer_push_code(void){ |
| 836 | + return db_get("xfer-push-script", 0); |
| 837 | +} |
| 838 | + |
| 839 | +/* |
| 840 | +** Return the TH1 code to evaluate when a commit is processed. |
| 841 | +*/ |
| 842 | +const char *xfer_commit_code(void){ |
| 843 | + return db_get("xfer-commit-script", 0); |
| 844 | +} |
| 845 | + |
| 846 | +/* |
| 847 | +** Return the TH1 code to evaluate when a ticket change is processed. |
| 848 | +*/ |
| 849 | +const char *xfer_ticket_code(void){ |
| 850 | + return db_get("xfer-ticket-script", 0); |
| 851 | +} |
| 852 | + |
| 853 | +/* |
| 854 | +** Run the specified TH1 script, if any, and returns 1 on error. |
| 855 | +*/ |
| 856 | +int xfer_run_script(const char *zScript, const char *zUuid){ |
| 857 | + int result; |
| 858 | + if( !zScript ) return TH_OK; |
| 859 | + Th_FossilInit(TH_INIT_DEFAULT); |
| 860 | + if( zUuid ){ |
| 861 | + result = Th_SetVar(g.interp, "uuid", -1, zUuid, -1); |
| 862 | + if( result!=TH_OK ){ |
| 863 | + fossil_error(1, "%s", Th_GetResult(g.interp, 0)); |
| 864 | + return result; |
| 865 | + } |
| 866 | + } |
| 867 | + result = Th_Eval(g.interp, 0, zScript, -1); |
| 868 | + if( result!=TH_OK ){ |
| 869 | + fossil_error(1, "%s", Th_GetResult(g.interp, 0)); |
| 870 | + } |
| 871 | + return result; |
| 872 | +} |
| 873 | + |
| 874 | +/* |
| 875 | +** Runs the pre-transfer TH1 script, if any, and returns its return code. |
| 876 | +*/ |
| 877 | +int xfer_run_common_script(void){ |
| 878 | + Th_FossilInit(TH_INIT_DEFAULT); |
| 879 | + return xfer_run_script(xfer_common_code(), 0); |
| 862 | 880 | } |
| 863 | 881 | |
| 864 | 882 | /* |
| 865 | 883 | ** If this variable is set, disable login checks. Used for debugging |
| 866 | 884 | ** only. |
| | @@ -918,11 +936,11 @@ |
| 918 | 936 | db_begin_transaction(); |
| 919 | 937 | db_multi_exec( |
| 920 | 938 | "CREATE TEMP TABLE onremote(rid INTEGER PRIMARY KEY);" |
| 921 | 939 | ); |
| 922 | 940 | manifest_crosslink_begin(); |
| 923 | | - if( run_common_script() ){ |
| 941 | + if( xfer_run_common_script()!=TH_OK ){ |
| 924 | 942 | cgi_reset_content(); |
| 925 | 943 | @ error common\sscript\sfailed:\s%F(Th_GetResult(g.interp, 0)) |
| 926 | 944 | nErr++; |
| 927 | 945 | } |
| 928 | 946 | while( blob_line(xfer.pIn, &xfer.line) ){ |
| | @@ -1245,11 +1263,11 @@ |
| 1245 | 1263 | } |
| 1246 | 1264 | blobarray_reset(xfer.aToken, xfer.nToken); |
| 1247 | 1265 | blob_reset(&xfer.line); |
| 1248 | 1266 | } |
| 1249 | 1267 | if( isPush ){ |
| 1250 | | - if( run_script("xfer-push-script", 0) ){ |
| 1268 | + if( xfer_run_script(xfer_push_code(), 0)!=TH_OK ){ |
| 1251 | 1269 | cgi_reset_content(); |
| 1252 | 1270 | @ error push\sscript\sfailed:\s%F(g.zErrMsg) |
| 1253 | 1271 | nErr++; |
| 1254 | 1272 | } |
| 1255 | 1273 | request_phantoms(&xfer, 500); |
| 1256 | 1274 | |