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

Overview
Comment:added output redirect and client force for hook
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | StvPrivateHook2
Files: files | file ages | folders
SHA1:ccef28b54b3662d4b9dc9f556a3b35c9c4b6e8a4
User & Date: wolfgang 2010-10-18 15:46:37
Context
2010-10-18
19:40
some error corrections for force hook check-in: a94ef5c0 user: wolfgang tags: StvPrivateHook2
15:46
added output redirect and client force for hook check-in: ccef28b5 user: wolfgang tags: StvPrivateHook2
2010-10-17
16:37
merge from old hook branch check-in: 9cf288de user: wolfgang tags: StvPrivateHook2
Changes

Changes to src/db.c.

1524
1525
1526
1527
1528
1529
1530


1531
1532
1533
1534
1535
1536
1537
....
1603
1604
1605
1606
1607
1608
1609
1610









1611


1612
1613
1614
1615
1616
1617
1618
  { "ignore-glob",   0,               40, ""                    },
  { "http-port",     0,               16, "8080"                },
  { "localauth",     0,                0, "0"                   },
  { "mtime-changes", 0,                0, "0"                   },
  { "pgp-command",   0,               32, "gpg --clearsign -o " },
  { "proxy",         0,               32, "off"                 },
  { "push-hook-cmd", 0,               32, ""                    },


  { "push-hook-pattern-client",
                     0,               32, ""                    },
  { "push-hook-pattern-server",
                     0,               32, ""                    },
  { "ssh-command",   0,               32, ""                    },
  { "web-browser",   0,               32, ""                    },
  { 0,0,0,0 }
................................................................................
**                  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 pattern, sent by the client will be









**                  appended to the command line.


**
**    push-hook-pattern-client
**                  if set, a client push will sent this message to the
**                  server, to activate the push hook command.
**
**    push-hook-pattern-server
**                  if set, and a client send this pattern at the end of







>
>







 







|
>
>
>
>
>
>
>
>
>
|
>
>







1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
....
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
  { "ignore-glob",   0,               40, ""                    },
  { "http-port",     0,               16, "8080"                },
  { "localauth",     0,                0, "0"                   },
  { "mtime-changes", 0,                0, "0"                   },
  { "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, ""                    },
  { "ssh-command",   0,               32, ""                    },
  { "web-browser",   0,               32, ""                    },
  { 0,0,0,0 }
................................................................................
**                  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.
**
**    push-hook-pattern-client
**                  if set, a client push will sent this message to the
**                  server, to activate the push hook command.
**
**    push-hook-pattern-server
**                  if set, and a client send this pattern at the end of

Changes to src/xfer.c.

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
...
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
....
1019
1020
1021
1022
1023
1024
1025

1026
1027
1028
1029
1030
1031
1032
....
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411

1412
1413
1414
1415

1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
    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]);
}

/*
** Let a server-side external agent know that a push has completed. /fatman




*/
void post_push_hook(char const * const zPushHookLine){
  /*
  ** 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", "");

  



  if( zCmd && zCmd[0] ){
    int rc;
    char * zCalledCmd;







    zCalledCmd = mprintf("%s %s",zCmd,zPushHookLine);
    rc = system(zCalledCmd);
    if (rc != 0) {
      fossil_print("The post-push-hook command \"%s\" failed.", zCalledCmd);
    }
    free(zCalledCmd);

  }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.
................................................................................
  manifest_crosslink_begin();
  while( blob_line(xfer.pIn, &xfer.line) ){
    if( blob_buffer(&xfer.line)[0]=='#' ){
      if(    lenPushHookPattern
          && 0 == memcmp(blob_buffer(&xfer.line)+1,
                         zPushHookPattern, lenPushHookPattern)
      ){
        post_push_hook(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
................................................................................
  int nSent, nRcvd;       /* Bytes sent and received (after compression) */
  Blob send;              /* Text we are sending to the server */
  Blob recv;              /* Reply we got back from the server */
  Xfer xfer;              /* Transfer data */
  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", "");



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

  transport_stats(0, 0, 1);
................................................................................
    if( xfer.nFileSent+xfer.nDeltaSent>0 ){
      go = 1;
    }

    /* If this is a clone, the go at least two rounds */
    if( cloneFlag && nCycle==1 ) go = 1;
  };
  if (pushFlag && nFileSend > 0) {
    if( zPushHookPattern && zPushHookPattern[0] ){
      blob_appendf(&send, "#%s\n", zPushHookPattern);

      http_exchange(&send, &recv, cloneFlag==0 || nCycle>0);
      blob_reset(&send);
      nCardSent++;
    }

  }
  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();
  db_end_transaction(0);
}







|




>
>
>
>

|





>

>
>
>
|


>
>

>
>
>
>
|





>







 







|







 







>







 







|

|
>




>










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
...
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
....
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
....
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
    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);
  
  if( requestType=='P' && !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);
    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.
................................................................................
  manifest_crosslink_begin();
  while( blob_line(xfer.pIn, &xfer.line) ){
    if( blob_buffer(&xfer.line)[0]=='#' ){
      if(    lenPushHookPattern
          && 0 == memcmp(blob_buffer(&xfer.line)+1,
                         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
................................................................................
  int nSent, nRcvd;       /* Bytes sent and received (after compression) */
  Blob send;              /* Text we are sending to the server */
  Blob recv;              /* Reply we got back from the server */
  Xfer xfer;              /* Transfer data */
  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);
................................................................................
    if( xfer.nFileSent+xfer.nDeltaSent>0 ){
      go = 1;
    }

    /* If this is a clone, the go at least two rounds */
    if( cloneFlag && nCycle==1 ) go = 1;
  };
  if( pushFlag && ( (nFileSend > 0) || allowForced ) ){
    if( zPushHookPattern && zPushHookPattern[0] ){
      blob_appendf(&send, "#%c%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();
  db_end_transaction(0);
}