| | @@ -40,130 +40,10 @@ |
| 40 | 40 | int nDeltaRcvd; /* Number of deltas received */ |
| 41 | 41 | int nDanglingFile; /* Number of dangling deltas received */ |
| 42 | 42 | int mxSend; /* Stop sending "file" with pOut reaches this size */ |
| 43 | 43 | }; |
| 44 | 44 | |
| 45 | | -/* |
| 46 | | -** COMMAND: callhook |
| 47 | | -** %fossil callhook PUSHHOOKPATTERN ?--force|-f? |
| 48 | | -** |
| 49 | | -** Call the push hook command on a server, which will normally be called |
| 50 | | -** after a client push (<a>setting</a> push-hook-cmd). |
| 51 | | -** |
| 52 | | -** If --force is used, the given pattern is not checked against the |
| 53 | | -** configuration (<a>setting</a> push-hook-pattern-server). |
| 54 | | -** |
| 55 | | -** This command only works on the server side, it does not send a message |
| 56 | | -** from a client, but executes the hook directly on the server. |
| 57 | | -** |
| 58 | | -** See also <a>push</a>, <a>sync</a>, <a>setting</a> |
| 59 | | -*/ |
| 60 | | -void callhook_cmd(void){ |
| 61 | | - int forceFlag = find_option("force","f",0)!=0; |
| 62 | | - |
| 63 | | - db_open_config(1); |
| 64 | | - db_find_and_open_repository(0); |
| 65 | | - if( (g.argc!=3) || (!g.argv[2]) || (!g.argv[2][0]) ){ |
| 66 | | - usage("PUSHHOOKPATTERN ?--force?"); |
| 67 | | - } |
| 68 | | - if( !forceFlag ){ |
| 69 | | - const char *zPushHookPattern = db_get("push-hook-pattern-server", ""); |
| 70 | | - int lenPushHookPattern = (zPushHookPattern && zPushHookPattern[0]) |
| 71 | | - ? strlen(zPushHookPattern) : 0; |
| 72 | | - if( (!lenPushHookPattern) |
| 73 | | - || memcmp(g.argv[2], zPushHookPattern, lenPushHookPattern) |
| 74 | | - ){ |
| 75 | | - fossil_fatal("push hook pattern '%s' doesn't match configuration '%s'\n", |
| 76 | | - g.argv[2],zPushHookPattern); |
| 77 | | - } |
| 78 | | - } |
| 79 | | - post_push_hook(g.argv[2],'C'); |
| 80 | | -} |
| 81 | | - |
| 82 | | -/* |
| 83 | | -** Let a server-side external agent know that a push has completed. /fatman |
| 84 | | -** The second argument controls, how the command is called: |
| 85 | | -** P - client request with pushed files |
| 86 | | -** F - client request without pushed files(FORCE!) |
| 87 | | -** C - server side command line activation |
| 88 | | -*/ |
| 89 | | -void post_push_hook(char const * const zPushHookLine, const char requestType){ |
| 90 | | - /* |
| 91 | | - ** TO DO: get the string cmd from a config file? Or the database local |
| 92 | | - ** settings, as someone suggested? Ditto output and error logs. /fatman |
| 93 | | - */ |
| 94 | | - const char *zCmd = db_get("push-hook-cmd", ""); |
| 95 | | - int allowForced = db_get_boolean("push-hook-force", 0); |
| 96 | | - const char *zHookPriv = db_get("push-hook-privilege",""); |
| 97 | | - int privOk = 0; |
| 98 | | - |
| 99 | | - if( zHookPriv && *zHookPriv ){ |
| 100 | | - switch( *zHookPriv ){ |
| 101 | | - |
| 102 | | - case 's': |
| 103 | | - if( g.okSetup ) privOk = 1; |
| 104 | | - break; |
| 105 | | - case 'a': |
| 106 | | - if( g.okAdmin ) privOk = 1; |
| 107 | | - break; |
| 108 | | - case 'i': |
| 109 | | - if( g.okWrite ) privOk = 1; |
| 110 | | - break; |
| 111 | | - case 'o': |
| 112 | | - if( g.okRead ) privOk = 1; |
| 113 | | - break; |
| 114 | | - default: |
| 115 | | - fossil_print("Push hook wrong privilege type '%s'\n", zHookPriv); |
| 116 | | - } |
| 117 | | - }else{ |
| 118 | | - privOk = 1; |
| 119 | | - } |
| 120 | | - if( !privOk ){ |
| 121 | | - fossil_print("No privilege to activate hook!\n"); |
| 122 | | - }else if( requestType!='P' && requestType!='C' && requestType!='F' ){ |
| 123 | | - fossil_print("Push hook wrong request type '%c'\n", requestType); |
| 124 | | - }else if( requestType=='F' && !allowForced ){ |
| 125 | | - fossil_print("Forced push call from client not allowed," |
| 126 | | - " skipping call for '%s'\n", zPushHookLine); |
| 127 | | - }else if( zCmd && zCmd[0] ){ |
| 128 | | - int rc; |
| 129 | | - char * zCalledCmd; |
| 130 | | - char * zDate; |
| 131 | | - const char *zRnd; |
| 132 | | - |
| 133 | | - |
| 134 | | - zDate = db_text(0, "SELECT strftime('%%Y%%m%%d%%H%%M%%f','now')"); |
| 135 | | - zRnd = db_text(0, "SELECT lower(hex(randomblob(6)))"); |
| 136 | | - |
| 137 | | - zCalledCmd = mprintf("%s %s-%s %s >hook-log-%s-%s 2>&1",zCmd,zDate,zRnd,zPushHookLine,zDate,zRnd); |
| 138 | | - { /* remove newlines from command */ |
| 139 | | - char *zSrc, *zDest; |
| 140 | | - |
| 141 | | - for (zSrc=zDest=zCalledCmd;;zSrc++){ |
| 142 | | - switch( *zSrc ){ |
| 143 | | - case '\0': |
| 144 | | - *zDest=0; |
| 145 | | - break; |
| 146 | | - default: |
| 147 | | - *zDest++ = *zSrc; |
| 148 | | - /* fall through is intended! */ |
| 149 | | - case '\n': |
| 150 | | - continue; |
| 151 | | - } |
| 152 | | - break; |
| 153 | | - } |
| 154 | | - } |
| 155 | | - rc = system(zCalledCmd); |
| 156 | | - if (rc != 0) { |
| 157 | | - fossil_print("The post-push-hook command '%s' failed.", zCalledCmd); |
| 158 | | - } |
| 159 | | - free(zCalledCmd); |
| 160 | | - free(zDate); |
| 161 | | - }else{ |
| 162 | | - fossil_print("No push hook configured, skipping call for '%s'\n", zPushHookLine); |
| 163 | | - } |
| 164 | | -} |
| 165 | 45 | |
| 166 | 46 | /* |
| 167 | 47 | ** The input blob contains a UUID. Convert it into a record ID. |
| 168 | 48 | ** Create a phantom record if no prior record exists and |
| 169 | 49 | ** phantomize is true. |
| | @@ -747,13 +627,10 @@ |
| 747 | 627 | int isClone = 0; |
| 748 | 628 | int nGimme = 0; |
| 749 | 629 | int size; |
| 750 | 630 | int recvConfig = 0; |
| 751 | 631 | char *zNow; |
| 752 | | - const char *zPushHookPattern = db_get("push-hook-pattern-server", ""); |
| 753 | | - int lenPushHookPattern = (zPushHookPattern && zPushHookPattern[0]) |
| 754 | | - ? strlen(zPushHookPattern) : 0; |
| 755 | 632 | |
| 756 | 633 | if( strcmp(PD("REQUEST_METHOD","POST"),"POST") ){ |
| 757 | 634 | fossil_redirect_home(); |
| 758 | 635 | } |
| 759 | 636 | memset(&xfer, 0, sizeof(xfer)); |
| | @@ -769,21 +646,11 @@ |
| 769 | 646 | db_multi_exec( |
| 770 | 647 | "CREATE TEMP TABLE onremote(rid INTEGER PRIMARY KEY);" |
| 771 | 648 | ); |
| 772 | 649 | manifest_crosslink_begin(); |
| 773 | 650 | while( blob_line(xfer.pIn, &xfer.line) ){ |
| 774 | | - if( blob_buffer(&xfer.line)[0]=='#' ){ |
| 775 | | - if( lenPushHookPattern |
| 776 | | - && blob_buffer(&xfer.line)[1] |
| 777 | | - && blob_buffer(&xfer.line)[2] |
| 778 | | - && (0 == memcmp(blob_buffer(&xfer.line)+2, |
| 779 | | - zPushHookPattern, lenPushHookPattern)) |
| 780 | | - ){ |
| 781 | | - post_push_hook(blob_buffer(&xfer.line)+2,blob_buffer(&xfer.line)[1]); |
| 782 | | - } |
| 783 | | - continue; |
| 784 | | - } |
| 651 | + if( blob_buffer(&xfer.line)[0]=='#' ) continue; |
| 785 | 652 | xfer.nToken = blob_tokenize(&xfer.line, xfer.aToken, count(xfer.aToken)); |
| 786 | 653 | |
| 787 | 654 | /* file UUID SIZE \n CONTENT |
| 788 | 655 | ** file UUID DELTASRC SIZE \n CONTENT |
| 789 | 656 | ** |
| | @@ -1138,13 +1005,10 @@ |
| 1138 | 1005 | int pctDone; /* Percentage done with a message */ |
| 1139 | 1006 | int lastPctDone = -1; /* Last displayed pctDone */ |
| 1140 | 1007 | double rArrivalTime; /* Time at which a message arrived */ |
| 1141 | 1008 | const char *zSCode = db_get("server-code", "x"); |
| 1142 | 1009 | const char *zPCode = db_get("project-code", 0); |
| 1143 | | - const char *zPushHookPattern = db_get("push-hook-pattern-client", ""); |
| 1144 | | - int allowForced = db_get_boolean("push-hook-force", 0); |
| 1145 | | - |
| 1146 | 1010 | |
| 1147 | 1011 | if( db_get_boolean("dont-push", 0) ) pushFlag = 0; |
| 1148 | 1012 | if( pushFlag + pullFlag + cloneFlag == 0 |
| 1149 | 1013 | && configRcvMask==0 && configSendMask==0 ) return; |
| 1150 | 1014 | |
| | @@ -1553,21 +1417,10 @@ |
| 1553 | 1417 | if( cloneFlag && nCycle==1 ) go = 1; |
| 1554 | 1418 | |
| 1555 | 1419 | /* Stop the cycle if the server sends a "clone_seqno 0" card */ |
| 1556 | 1420 | if( cloneSeqno<=0 ) go = 0; |
| 1557 | 1421 | }; |
| 1558 | | - if( pushFlag && ( (nFileSend > 0) || allowForced ) ){ |
| 1559 | | - if( zPushHookPattern && zPushHookPattern[0] ){ |
| 1560 | | - blob_appendf(&send, "#%s%s\n", |
| 1561 | | - ((nFileSend > 0)?"P":"F"), zPushHookPattern); |
| 1562 | | - fossil_print("Triggering push hook %s '%s'\n",((nFileSend > 0)?"P":"F"),zPushHookPattern); |
| 1563 | | - http_exchange(&send, &recv, cloneFlag==0 || nCycle>0); |
| 1564 | | - blob_reset(&send); |
| 1565 | | - nCardSent++; |
| 1566 | | - } |
| 1567 | | - int allowForced = db_get_boolean("push-hook-force", 0); |
| 1568 | | - } |
| 1569 | 1422 | transport_stats(&nSent, &nRcvd, 1); |
| 1570 | 1423 | fossil_print("Total network traffic: %d bytes sent, %d bytes received\n", |
| 1571 | 1424 | nSent, nRcvd); |
| 1572 | 1425 | transport_close(); |
| 1573 | 1426 | transport_global_shutdown(); |
| 1574 | 1427 | |