Fossil SCM

Prevent the test command 'test-th-hook' from segfaulting when TH1 hooks are disabled. Also, add and enhance comments.

mistachkin 2015-11-24 23:38 trunk
Commit ddd4cb52545c3e8406643e41e2c9606192e3d000
1 file changed +44 -4
+44 -4
--- src/th_main.c
+++ src/th_main.c
@@ -2288,10 +2288,11 @@
22882288
** Options:
22892289
**
22902290
** --cgi Include a CGI response header in the output
22912291
** --http Include an HTTP response header in the output
22922292
** --open-config Open the configuration database
2293
+** --th-trace Trace TH1 execution (for debugging purposes)
22932294
*/
22942295
void test_th_render(void){
22952296
int forceCgi = 0, fullHttpReply = 0;
22962297
Blob in;
22972298
Th_InitTraceLog();
@@ -2324,10 +2325,11 @@
23242325
** Options:
23252326
**
23262327
** --cgi Include a CGI response header in the output
23272328
** --http Include an HTTP response header in the output
23282329
** --open-config Open the configuration database
2330
+** --th-trace Trace TH1 execution (for debugging purposes)
23292331
*/
23302332
void test_th_eval(void){
23312333
int rc;
23322334
const char *zRc;
23332335
int forceCgi, fullHttpReply;
@@ -2351,15 +2353,48 @@
23512353
}
23522354
23532355
#ifdef FOSSIL_ENABLE_TH1_HOOKS
23542356
/*
23552357
** COMMAND: test-th-hook
2358
+**
2359
+** Usage: %fossil test-th-hook TYPE NAME FLAGS
2360
+**
2361
+** Executes the TH1 script configured for the pre-operation (i.e. a command
2362
+** or web page) "hook" or post-operation "notification". The results of the
2363
+** script evaluation, if any, will be printed to the standard output channel.
2364
+** The NAME argument must be the name of a command or web page; however, it
2365
+** does not necessarily have to be a command or web page that is normally
2366
+** recognized by Fossil. The FLAGS argument will be used to set the value
2367
+** of the "cmd_flags" and/or "web_flags" TH1 variables, if applicable. The
2368
+** TYPE argument must be one of the following:
2369
+**
2370
+** cmdhook Executes the TH1 procedure [command_hook], after
2371
+** setting the TH1 variables "cmd_name", "cmd_args",
2372
+** and "cmd_flags" to appropriate values.
2373
+**
2374
+** cmdnotify Executes the TH1 procedure [command_notify], after
2375
+** setting the TH1 variables "cmd_name", "cmd_args",
2376
+** and "cmd_flags" to appropriate values.
2377
+**
2378
+** webhook Executes the TH1 procedure [webpage_hook], after
2379
+** setting the TH1 variables "web_name", "web_args",
2380
+** and "web_flags" to appropriate values.
2381
+**
2382
+** webnotify Executes the TH1 procedure [webpage_notify], after
2383
+** setting the TH1 variables "web_name", "web_args",
2384
+** and "web_flags" to appropriate values.
2385
+**
2386
+** Options:
2387
+**
2388
+** --cgi Include a CGI response header in the output
2389
+** --http Include an HTTP response header in the output
2390
+** --th-trace Trace TH1 execution (for debugging purposes)
23562391
*/
23572392
void test_th_hook(void){
23582393
int rc = TH_OK;
23592394
int nResult = 0;
2360
- char *zResult;
2395
+ char *zResult = 0;
23612396
int forceCgi, fullHttpReply;
23622397
Th_InitTraceLog();
23632398
forceCgi = find_option("cgi", 0, 0)!=0;
23642399
fullHttpReply = find_option("http", 0, 0)!=0;
23652400
if( fullHttpReply ) forceCgi = 1;
@@ -2376,15 +2411,20 @@
23762411
}else if( fossil_stricmp(g.argv[2], "webnotify")==0 ){
23772412
rc = Th_WebpageNotify(g.argv[3], (char)atoi(g.argv[4]));
23782413
}else{
23792414
fossil_fatal("Unknown TH1 hook %s\n", g.argv[2]);
23802415
}
2381
- zResult = (char*)Th_GetResult(g.interp, &nResult);
2416
+ if( g.interp ){
2417
+ zResult = (char*)Th_GetResult(g.interp, &nResult);
2418
+ }
23822419
sendText("RESULT (", -1, 0);
23832420
sendText(Th_ReturnCodeName(rc, 0), -1, 0);
2384
- sendText("): ", -1, 0);
2385
- sendText(zResult, nResult, 0);
2421
+ sendText(")", -1, 0);
2422
+ if( zResult && nResult>0 ){
2423
+ sendText(": ", -1, 0);
2424
+ sendText(zResult, nResult, 0);
2425
+ }
23862426
sendText("\n", -1, 0);
23872427
Th_PrintTraceLog();
23882428
if( forceCgi ) cgi_reply();
23892429
}
23902430
#endif
23912431
--- src/th_main.c
+++ src/th_main.c
@@ -2288,10 +2288,11 @@
2288 ** Options:
2289 **
2290 ** --cgi Include a CGI response header in the output
2291 ** --http Include an HTTP response header in the output
2292 ** --open-config Open the configuration database
 
2293 */
2294 void test_th_render(void){
2295 int forceCgi = 0, fullHttpReply = 0;
2296 Blob in;
2297 Th_InitTraceLog();
@@ -2324,10 +2325,11 @@
2324 ** Options:
2325 **
2326 ** --cgi Include a CGI response header in the output
2327 ** --http Include an HTTP response header in the output
2328 ** --open-config Open the configuration database
 
2329 */
2330 void test_th_eval(void){
2331 int rc;
2332 const char *zRc;
2333 int forceCgi, fullHttpReply;
@@ -2351,15 +2353,48 @@
2351 }
2352
2353 #ifdef FOSSIL_ENABLE_TH1_HOOKS
2354 /*
2355 ** COMMAND: test-th-hook
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2356 */
2357 void test_th_hook(void){
2358 int rc = TH_OK;
2359 int nResult = 0;
2360 char *zResult;
2361 int forceCgi, fullHttpReply;
2362 Th_InitTraceLog();
2363 forceCgi = find_option("cgi", 0, 0)!=0;
2364 fullHttpReply = find_option("http", 0, 0)!=0;
2365 if( fullHttpReply ) forceCgi = 1;
@@ -2376,15 +2411,20 @@
2376 }else if( fossil_stricmp(g.argv[2], "webnotify")==0 ){
2377 rc = Th_WebpageNotify(g.argv[3], (char)atoi(g.argv[4]));
2378 }else{
2379 fossil_fatal("Unknown TH1 hook %s\n", g.argv[2]);
2380 }
2381 zResult = (char*)Th_GetResult(g.interp, &nResult);
 
 
2382 sendText("RESULT (", -1, 0);
2383 sendText(Th_ReturnCodeName(rc, 0), -1, 0);
2384 sendText("): ", -1, 0);
2385 sendText(zResult, nResult, 0);
 
 
 
2386 sendText("\n", -1, 0);
2387 Th_PrintTraceLog();
2388 if( forceCgi ) cgi_reply();
2389 }
2390 #endif
2391
--- src/th_main.c
+++ src/th_main.c
@@ -2288,10 +2288,11 @@
2288 ** Options:
2289 **
2290 ** --cgi Include a CGI response header in the output
2291 ** --http Include an HTTP response header in the output
2292 ** --open-config Open the configuration database
2293 ** --th-trace Trace TH1 execution (for debugging purposes)
2294 */
2295 void test_th_render(void){
2296 int forceCgi = 0, fullHttpReply = 0;
2297 Blob in;
2298 Th_InitTraceLog();
@@ -2324,10 +2325,11 @@
2325 ** Options:
2326 **
2327 ** --cgi Include a CGI response header in the output
2328 ** --http Include an HTTP response header in the output
2329 ** --open-config Open the configuration database
2330 ** --th-trace Trace TH1 execution (for debugging purposes)
2331 */
2332 void test_th_eval(void){
2333 int rc;
2334 const char *zRc;
2335 int forceCgi, fullHttpReply;
@@ -2351,15 +2353,48 @@
2353 }
2354
2355 #ifdef FOSSIL_ENABLE_TH1_HOOKS
2356 /*
2357 ** COMMAND: test-th-hook
2358 **
2359 ** Usage: %fossil test-th-hook TYPE NAME FLAGS
2360 **
2361 ** Executes the TH1 script configured for the pre-operation (i.e. a command
2362 ** or web page) "hook" or post-operation "notification". The results of the
2363 ** script evaluation, if any, will be printed to the standard output channel.
2364 ** The NAME argument must be the name of a command or web page; however, it
2365 ** does not necessarily have to be a command or web page that is normally
2366 ** recognized by Fossil. The FLAGS argument will be used to set the value
2367 ** of the "cmd_flags" and/or "web_flags" TH1 variables, if applicable. The
2368 ** TYPE argument must be one of the following:
2369 **
2370 ** cmdhook Executes the TH1 procedure [command_hook], after
2371 ** setting the TH1 variables "cmd_name", "cmd_args",
2372 ** and "cmd_flags" to appropriate values.
2373 **
2374 ** cmdnotify Executes the TH1 procedure [command_notify], after
2375 ** setting the TH1 variables "cmd_name", "cmd_args",
2376 ** and "cmd_flags" to appropriate values.
2377 **
2378 ** webhook Executes the TH1 procedure [webpage_hook], after
2379 ** setting the TH1 variables "web_name", "web_args",
2380 ** and "web_flags" to appropriate values.
2381 **
2382 ** webnotify Executes the TH1 procedure [webpage_notify], after
2383 ** setting the TH1 variables "web_name", "web_args",
2384 ** and "web_flags" to appropriate values.
2385 **
2386 ** Options:
2387 **
2388 ** --cgi Include a CGI response header in the output
2389 ** --http Include an HTTP response header in the output
2390 ** --th-trace Trace TH1 execution (for debugging purposes)
2391 */
2392 void test_th_hook(void){
2393 int rc = TH_OK;
2394 int nResult = 0;
2395 char *zResult = 0;
2396 int forceCgi, fullHttpReply;
2397 Th_InitTraceLog();
2398 forceCgi = find_option("cgi", 0, 0)!=0;
2399 fullHttpReply = find_option("http", 0, 0)!=0;
2400 if( fullHttpReply ) forceCgi = 1;
@@ -2376,15 +2411,20 @@
2411 }else if( fossil_stricmp(g.argv[2], "webnotify")==0 ){
2412 rc = Th_WebpageNotify(g.argv[3], (char)atoi(g.argv[4]));
2413 }else{
2414 fossil_fatal("Unknown TH1 hook %s\n", g.argv[2]);
2415 }
2416 if( g.interp ){
2417 zResult = (char*)Th_GetResult(g.interp, &nResult);
2418 }
2419 sendText("RESULT (", -1, 0);
2420 sendText(Th_ReturnCodeName(rc, 0), -1, 0);
2421 sendText(")", -1, 0);
2422 if( zResult && nResult>0 ){
2423 sendText(": ", -1, 0);
2424 sendText(zResult, nResult, 0);
2425 }
2426 sendText("\n", -1, 0);
2427 Th_PrintTraceLog();
2428 if( forceCgi ) cgi_reply();
2429 }
2430 #endif
2431

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button