Fossil

Check-in [a0612174]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:remove hook command to be compatible with other hook designs
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | StvPrivateHook2
Files: files | file ages | folders
SHA1:a06121740a37e703b1e2645bc71c3b516fac9ac3
User & Date: wolfgang 2010-11-08 23:01:40
Context
2010-11-09
01:17
Cleanup of help_page() in preparation for merging with trunk. Leaf check-in: a298a0e2 user: drh tags: StvPrivateHook2
2010-11-08
23:01
remove hook command to be compatible with other hook designs check-in: a0612174 user: wolfgang tags: StvPrivateHook2
20:04
merge from trunk check-in: 1e801695 user: wolfgang tags: StvPrivateHook2
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/db.c.

1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
....
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
  { "ignore-glob",   0,               40, ""                    },
  { "http-port",     0,               16, "8080"                },
  { "localauth",     0,                0, "off"                 },
  { "manifest",      0,                0, "off"                 },
  { "mtime-changes", 0,                0, "on"                  },
  { "pgp-command",   0,               32, "gpg --clearsign -o " },
  { "proxy",         0,               32, "off"                 },
  { "push-hook-cmd", 0,               32, ""                    },
  { "push-hook-force",
                     0,                0, ""                    },
  { "push-hook-pattern-client",
                     0,               32, ""                    },
  { "push-hook-pattern-server",
                     0,               32, ""                    },
  { "push-hook-privilege",
                     0,               1,  ""                    },
  { "repo-cksum",    0,                0, "on"                  },
  { "ssh-command",   0,               32, ""                    },
  { "web-browser",   0,               32, ""                    },
  { 0,0,0,0 }
};

/*
................................................................................
**                  The default is "gpg --clearsign -o ".
**
**    proxy         URL of the HTTP proxy.  If undefined or "off" then
**                  the "http_proxy" environment variable is consulted.
**                  If the http_proxy environment variable is undefined
**                  then a direct HTTP connection is used.
**
**    push-hook-cmd this is the command line, that will be activated
**                  as push hook. Output redirects should be added to
**                  this command line.
**                  The complete command line looks like:
**                    command name: the configured value for push-hook-cmd
**                    argument 1:   timestamp followed by random-number
**                    argument 2:   pattern sent by client
**                  As fallback, stdin/stderr are redirected to files
**                    hook-log-<timestamp followed by random-number>
**
**    push-hook-force
**                  if this is set on the client, it will request always
**                  the hook activation, even if no files where pushed on
**                  the sync.
**                  if this is set on the server, it will accept hook
**                  activiation, even if no files where pushed.
**                     Default: on
**
**    push-hook-pattern-client
**                  if set, a client push will sent this message to the
**                  server, to activate the push hook command.
**                     Default: on
**
**    push-hook-pattern-server
**                  if set, and a client send this pattern at the end of
**                  a push, the push hook command will be executed. This
**                  might be a prefix of the pattern, sent by the client.
**
**    push-hook-privilege
**                  if set, the user doing the push needs this privilege
**                  to trigger the hook. Valid privileges are:
**                    s (setup), a (admin), i (checkin) or o (checkout)
**
**    repo-cksum    Compute checksums over all files in each checkout
**                  as a double-check of correctness.  Defaults to "on".
**                  Disable on large repositories for a performance
**                  improvement.
**
**    ssh-command   Command used to talk to a remote machine with
**                  the "ssh://" protocol.







<
<
<
<
<
<
<
<
<







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







1524
1525
1526
1527
1528
1529
1530









1531
1532
1533
1534
1535
1536
1537
....
1601
1602
1603
1604
1605
1606
1607

































1608
1609
1610
1611
1612
1613
1614
  { "ignore-glob",   0,               40, ""                    },
  { "http-port",     0,               16, "8080"                },
  { "localauth",     0,                0, "off"                 },
  { "manifest",      0,                0, "off"                 },
  { "mtime-changes", 0,                0, "on"                  },
  { "pgp-command",   0,               32, "gpg --clearsign -o " },
  { "proxy",         0,               32, "off"                 },









  { "repo-cksum",    0,                0, "on"                  },
  { "ssh-command",   0,               32, ""                    },
  { "web-browser",   0,               32, ""                    },
  { 0,0,0,0 }
};

/*
................................................................................
**                  The default is "gpg --clearsign -o ".
**
**    proxy         URL of the HTTP proxy.  If undefined or "off" then
**                  the "http_proxy" environment variable is consulted.
**                  If the http_proxy environment variable is undefined
**                  then a direct HTTP connection is used.
**

































**    repo-cksum    Compute checksums over all files in each checkout
**                  as a double-check of correctness.  Defaults to "on".
**                  Disable on large repositories for a performance
**                  improvement.
**
**    ssh-command   Command used to talk to a remote machine with
**                  the "ssh://" protocol.

Changes to src/sync.c.

163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
...
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
** is used.
**
** The URL specified normally becomes the new "remote-url" used for
** subsequent <a>push</a>, <a>pull</a>, and <a>sync</a> operations.  However,
** the "--once" command-line option makes the URL a one-time-use URL
** that is not saved.
**
** If configured (<a>setting</a> push-hook-..), the push hook command will be
** executed on the server after pushing files.
**
** See also: <a>callhook</a>, <a>clone</a>, <a>pull</a>, <a>sync</a>, <a>remote-url</a>
*/
void push_cmd(void){
  process_sync_args();
  client_sync(1,0,0,0,0);
}


................................................................................
** command is used.
**
** The URL specified normally becomes the new "remote-url" used for
** subsequent <a>push</a>, <a>pull</a>, and <a>sync</a> operations.  However,
** the "--once" command-line option makes the URL a one-time-use URL
** that is not saved.
**
** If configured (<a>setting</a> push-hook-..), the push hook command will be
** executed on the server after pushing files.
**
** See also: <a>callhook</a>, <a>clone</a>, <a>push</a>, <a>pull</a>, <a>remote-url</a>
*/
void sync_cmd(void){
  int syncFlags = process_sync_args();
  client_sync(1,1,0,syncFlags,0);
}

/*







<
<
<
|







 







<
<
<
|







163
164
165
166
167
168
169



170
171
172
173
174
175
176
177
...
194
195
196
197
198
199
200



201
202
203
204
205
206
207
208
** is used.
**
** The URL specified normally becomes the new "remote-url" used for
** subsequent <a>push</a>, <a>pull</a>, and <a>sync</a> operations.  However,
** the "--once" command-line option makes the URL a one-time-use URL
** that is not saved.
**



** See also: <a>clone</a>, <a>pull</a>, <a>sync</a>, <a>remote-url</a>
*/
void push_cmd(void){
  process_sync_args();
  client_sync(1,0,0,0,0);
}


................................................................................
** command is used.
**
** The URL specified normally becomes the new "remote-url" used for
** subsequent <a>push</a>, <a>pull</a>, and <a>sync</a> operations.  However,
** the "--once" command-line option makes the URL a one-time-use URL
** that is not saved.
**



** See also: <a>clone</a>, <a>push</a>, <a>pull</a>, <a>remote-url</a>
*/
void sync_cmd(void){
  int syncFlags = process_sync_args();
  client_sync(1,1,0,syncFlags,0);
}

/*

Changes to src/xfer.c.

38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
...
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
...
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
....
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
....
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
  int nDeltaSent;     /* Number of deltas sent */
  int nFileRcvd;      /* Number of files received */
  int nDeltaRcvd;     /* Number of deltas received */
  int nDanglingFile;  /* Number of dangling deltas received */
  int mxSend;         /* Stop sending "file" with pOut reaches this size */
};

/*
** COMMAND: callhook
** %fossil callhook PUSHHOOKPATTERN ?--force|-f?
**
** Call the push hook command on a server, which will normally be called
** after a client push (<a>setting</a> push-hook-cmd).
**
** If --force is used, the given pattern is not checked against the
** configuration (<a>setting</a> push-hook-pattern-server).
**
** This command only works on the server side, it does not send a message
** from a client, but executes the hook directly on the server.
**
** See also <a>push</a>, <a>sync</a>, <a>setting</a>
*/
void callhook_cmd(void){
  int forceFlag = find_option("force","f",0)!=0;

  db_open_config(1);
  db_find_and_open_repository(0);
  if( (g.argc!=3) || (!g.argv[2]) || (!g.argv[2][0]) ){
    usage("PUSHHOOKPATTERN ?--force?");
  }
  if( !forceFlag ){
    const char *zPushHookPattern = db_get("push-hook-pattern-server", "");
    int lenPushHookPattern = (zPushHookPattern && zPushHookPattern[0])
                              ? strlen(zPushHookPattern) : 0;
    if(    (!lenPushHookPattern)
        || memcmp(g.argv[2], zPushHookPattern, lenPushHookPattern)
    ){
      fossil_fatal("push hook pattern '%s' doesn't match configuration '%s'\n",
                     g.argv[2],zPushHookPattern);
    }
  }
  post_push_hook(g.argv[2],'C');
}

/*
** Let a server-side external agent know that a push has completed. /fatman
** The second argument controls, how the command is called:
**   P - client request with pushed files
**   F - client request without pushed files(FORCE!)
**   C - server side command line activation
*/
void post_push_hook(char const * const zPushHookLine, const char requestType){
  /*
  ** TO DO: get the string cmd from a config file? Or the database local
  ** settings, as someone suggested? Ditto output and error logs. /fatman
  */
  const char *zCmd = db_get("push-hook-cmd", "");
  int allowForced = db_get_boolean("push-hook-force", 0);
  const char *zHookPriv = db_get("push-hook-privilege","");
  int privOk = 0;

  if( zHookPriv && *zHookPriv ){
    switch( *zHookPriv ){
      
      case 's':
        if( g.okSetup ) privOk = 1;
        break;
      case 'a':
        if( g.okAdmin ) privOk = 1;
        break;
      case 'i':
        if( g.okWrite ) privOk = 1;
        break;
      case 'o':
        if( g.okRead ) privOk = 1;
        break;
      default:
        fossil_print("Push hook wrong privilege type '%s'\n", zHookPriv);
    }
  }else{
    privOk = 1;
  }
  if( !privOk ){
    fossil_print("No privilege to activate hook!\n");
  }else if( requestType!='P' &&  requestType!='C' && requestType!='F' ){
    fossil_print("Push hook wrong request type '%c'\n", requestType);
  }else if( requestType=='F' && !allowForced ){
    fossil_print("Forced push call from client not allowed,"
                 " skipping call for '%s'\n", zPushHookLine);
  }else if( zCmd && zCmd[0] ){
    int rc;
    char * zCalledCmd;
    char * zDate;
    const char *zRnd;


    zDate = db_text(0, "SELECT strftime('%%Y%%m%%d%%H%%M%%f','now')");
    zRnd = db_text(0, "SELECT lower(hex(randomblob(6)))");

    zCalledCmd = mprintf("%s %s-%s %s >hook-log-%s-%s 2>&1",zCmd,zDate,zRnd,zPushHookLine,zDate,zRnd);
    { /* remove newlines from command */
      char *zSrc, *zDest;

      for (zSrc=zDest=zCalledCmd;;zSrc++){
        switch( *zSrc ){
          case '\0':
            *zDest=0;
            break;
          default:
            *zDest++ = *zSrc;
            /* fall through is intended! */
          case '\n':
            continue;
        }
        break;
      }
    }
    rc = system(zCalledCmd);
    if (rc != 0) {
      fossil_print("The post-push-hook command '%s' failed.", zCalledCmd);
    }
    free(zCalledCmd);
    free(zDate);
  }else{
    fossil_print("No push hook configured, skipping call for '%s'\n", zPushHookLine);
  }
}

/*
** The input blob contains a UUID.  Convert it into a record ID.
** Create a phantom record if no prior record exists and
** phantomize is true.
**
** Compare to uuid_to_rid().  This routine takes a blob argument
................................................................................
  Xfer xfer;
  int deltaFlag = 0;
  int isClone = 0;
  int nGimme = 0;
  int size;
  int recvConfig = 0;
  char *zNow;
  const char *zPushHookPattern = db_get("push-hook-pattern-server", "");
  int lenPushHookPattern = (zPushHookPattern && zPushHookPattern[0])
                            ? strlen(zPushHookPattern) : 0;

  if( strcmp(PD("REQUEST_METHOD","POST"),"POST") ){
     fossil_redirect_home();
  }
  memset(&xfer, 0, sizeof(xfer));
  blobarray_zero(xfer.aToken, count(xfer.aToken));
  cgi_set_content_type(g.zContentType);
................................................................................

  db_begin_transaction();
  db_multi_exec(
     "CREATE TEMP TABLE onremote(rid INTEGER PRIMARY KEY);"
  );
  manifest_crosslink_begin();
  while( blob_line(xfer.pIn, &xfer.line) ){
    if( blob_buffer(&xfer.line)[0]=='#' ){
      if(    lenPushHookPattern
          && blob_buffer(&xfer.line)[1]
          && blob_buffer(&xfer.line)[2]
          && (0 == memcmp(blob_buffer(&xfer.line)+2,
                          zPushHookPattern, lenPushHookPattern))
      ){
        post_push_hook(blob_buffer(&xfer.line)+2,blob_buffer(&xfer.line)[1]);
      }
      continue;
    }
    xfer.nToken = blob_tokenize(&xfer.line, xfer.aToken, count(xfer.aToken));

    /*   file UUID SIZE \n CONTENT
    **   file UUID DELTASRC SIZE \n CONTENT
    **
    ** Accept a file from the client.
    */
................................................................................
  Blob recv;              /* Reply we got back from the server */
  Xfer xfer;              /* Transfer data */
  int pctDone;            /* Percentage done with a message */
  int lastPctDone = -1;   /* Last displayed pctDone */
  double rArrivalTime;    /* Time at which a message arrived */
  const char *zSCode = db_get("server-code", "x");
  const char *zPCode = db_get("project-code", 0);
  const char *zPushHookPattern = db_get("push-hook-pattern-client", "");
  int allowForced = db_get_boolean("push-hook-force", 0);


  if( db_get_boolean("dont-push", 0) ) pushFlag = 0;
  if( pushFlag + pullFlag + cloneFlag == 0 
     && configRcvMask==0 && configSendMask==0 ) return;

  transport_stats(0, 0, 1);
  socket_global_init();
................................................................................

    /* If this is a clone, the go at least two rounds */
    if( cloneFlag && nCycle==1 ) go = 1;

    /* Stop the cycle if the server sends a "clone_seqno 0" card */
    if( cloneSeqno<=0 ) go = 0;   
  };
  if( pushFlag && ( (nFileSend > 0) || allowForced ) ){
    if( zPushHookPattern && zPushHookPattern[0] ){
      blob_appendf(&send, "#%s%s\n",
                   ((nFileSend > 0)?"P":"F"), zPushHookPattern);
      fossil_print("Triggering push hook %s '%s'\n",((nFileSend > 0)?"P":"F"),zPushHookPattern);
      http_exchange(&send, &recv, cloneFlag==0 || nCycle>0);
      blob_reset(&send);
      nCardSent++;
    }
  int allowForced = db_get_boolean("push-hook-force", 0);
  }
  transport_stats(&nSent, &nRcvd, 1);
  fossil_print("Total network traffic: %d bytes sent, %d bytes received\n",
               nSent, nRcvd);
  transport_close();
  transport_global_shutdown();
  db_multi_exec("DROP TABLE onremote");
  manifest_crosslink_end();
  content_enable_dephantomize(1);
  db_end_transaction(0);
}







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







<
<
<







 







|
<
<
<
<
<
<
<
<
<
<







 







<
<
<







 







<
<
<
<
<
<
<
<
<
<
<










38
39
40
41
42
43
44
























































































































45
46
47
48
49
50
51
...
625
626
627
628
629
630
631



632
633
634
635
636
637
638
...
644
645
646
647
648
649
650
651










652
653
654
655
656
657
658
....
1003
1004
1005
1006
1007
1008
1009



1010
1011
1012
1013
1014
1015
1016
....
1415
1416
1417
1418
1419
1420
1421











1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
  int nDeltaSent;     /* Number of deltas sent */
  int nFileRcvd;      /* Number of files received */
  int nDeltaRcvd;     /* Number of deltas received */
  int nDanglingFile;  /* Number of dangling deltas received */
  int mxSend;         /* Stop sending "file" with pOut reaches this size */
};


























































































































/*
** The input blob contains a UUID.  Convert it into a record ID.
** Create a phantom record if no prior record exists and
** phantomize is true.
**
** Compare to uuid_to_rid().  This routine takes a blob argument
................................................................................
  Xfer xfer;
  int deltaFlag = 0;
  int isClone = 0;
  int nGimme = 0;
  int size;
  int recvConfig = 0;
  char *zNow;




  if( strcmp(PD("REQUEST_METHOD","POST"),"POST") ){
     fossil_redirect_home();
  }
  memset(&xfer, 0, sizeof(xfer));
  blobarray_zero(xfer.aToken, count(xfer.aToken));
  cgi_set_content_type(g.zContentType);
................................................................................

  db_begin_transaction();
  db_multi_exec(
     "CREATE TEMP TABLE onremote(rid INTEGER PRIMARY KEY);"
  );
  manifest_crosslink_begin();
  while( blob_line(xfer.pIn, &xfer.line) ){
    if( blob_buffer(&xfer.line)[0]=='#' ) continue;










    xfer.nToken = blob_tokenize(&xfer.line, xfer.aToken, count(xfer.aToken));

    /*   file UUID SIZE \n CONTENT
    **   file UUID DELTASRC SIZE \n CONTENT
    **
    ** Accept a file from the client.
    */
................................................................................
  Blob recv;              /* Reply we got back from the server */
  Xfer xfer;              /* Transfer data */
  int pctDone;            /* Percentage done with a message */
  int lastPctDone = -1;   /* Last displayed pctDone */
  double rArrivalTime;    /* Time at which a message arrived */
  const char *zSCode = db_get("server-code", "x");
  const char *zPCode = db_get("project-code", 0);




  if( db_get_boolean("dont-push", 0) ) pushFlag = 0;
  if( pushFlag + pullFlag + cloneFlag == 0 
     && configRcvMask==0 && configSendMask==0 ) return;

  transport_stats(0, 0, 1);
  socket_global_init();
................................................................................

    /* If this is a clone, the go at least two rounds */
    if( cloneFlag && nCycle==1 ) go = 1;

    /* Stop the cycle if the server sends a "clone_seqno 0" card */
    if( cloneSeqno<=0 ) go = 0;   
  };











  transport_stats(&nSent, &nRcvd, 1);
  fossil_print("Total network traffic: %d bytes sent, %d bytes received\n",
               nSent, nRcvd);
  transport_close();
  transport_global_shutdown();
  db_multi_exec("DROP TABLE onremote");
  manifest_crosslink_end();
  content_enable_dephantomize(1);
  db_end_transaction(0);
}