Fossil SCM
Prevent the test command 'test-th-hook' from segfaulting when TH1 hooks are disabled. Also, add and enhance comments.
Commit
ddd4cb52545c3e8406643e41e2c9606192e3d000
Parent
565d1b0a3880421…
1 file changed
+44
-4
+44
-4
| --- src/th_main.c | ||
| +++ src/th_main.c | ||
| @@ -2288,10 +2288,11 @@ | ||
| 2288 | 2288 | ** Options: |
| 2289 | 2289 | ** |
| 2290 | 2290 | ** --cgi Include a CGI response header in the output |
| 2291 | 2291 | ** --http Include an HTTP response header in the output |
| 2292 | 2292 | ** --open-config Open the configuration database |
| 2293 | +** --th-trace Trace TH1 execution (for debugging purposes) | |
| 2293 | 2294 | */ |
| 2294 | 2295 | void test_th_render(void){ |
| 2295 | 2296 | int forceCgi = 0, fullHttpReply = 0; |
| 2296 | 2297 | Blob in; |
| 2297 | 2298 | Th_InitTraceLog(); |
| @@ -2324,10 +2325,11 @@ | ||
| 2324 | 2325 | ** Options: |
| 2325 | 2326 | ** |
| 2326 | 2327 | ** --cgi Include a CGI response header in the output |
| 2327 | 2328 | ** --http Include an HTTP response header in the output |
| 2328 | 2329 | ** --open-config Open the configuration database |
| 2330 | +** --th-trace Trace TH1 execution (for debugging purposes) | |
| 2329 | 2331 | */ |
| 2330 | 2332 | void test_th_eval(void){ |
| 2331 | 2333 | int rc; |
| 2332 | 2334 | const char *zRc; |
| 2333 | 2335 | int forceCgi, fullHttpReply; |
| @@ -2351,15 +2353,48 @@ | ||
| 2351 | 2353 | } |
| 2352 | 2354 | |
| 2353 | 2355 | #ifdef FOSSIL_ENABLE_TH1_HOOKS |
| 2354 | 2356 | /* |
| 2355 | 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) | |
| 2356 | 2391 | */ |
| 2357 | 2392 | void test_th_hook(void){ |
| 2358 | 2393 | int rc = TH_OK; |
| 2359 | 2394 | int nResult = 0; |
| 2360 | - char *zResult; | |
| 2395 | + char *zResult = 0; | |
| 2361 | 2396 | int forceCgi, fullHttpReply; |
| 2362 | 2397 | Th_InitTraceLog(); |
| 2363 | 2398 | forceCgi = find_option("cgi", 0, 0)!=0; |
| 2364 | 2399 | fullHttpReply = find_option("http", 0, 0)!=0; |
| 2365 | 2400 | if( fullHttpReply ) forceCgi = 1; |
| @@ -2376,15 +2411,20 @@ | ||
| 2376 | 2411 | }else if( fossil_stricmp(g.argv[2], "webnotify")==0 ){ |
| 2377 | 2412 | rc = Th_WebpageNotify(g.argv[3], (char)atoi(g.argv[4])); |
| 2378 | 2413 | }else{ |
| 2379 | 2414 | fossil_fatal("Unknown TH1 hook %s\n", g.argv[2]); |
| 2380 | 2415 | } |
| 2381 | - zResult = (char*)Th_GetResult(g.interp, &nResult); | |
| 2416 | + if( g.interp ){ | |
| 2417 | + zResult = (char*)Th_GetResult(g.interp, &nResult); | |
| 2418 | + } | |
| 2382 | 2419 | sendText("RESULT (", -1, 0); |
| 2383 | 2420 | 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 | + } | |
| 2386 | 2426 | sendText("\n", -1, 0); |
| 2387 | 2427 | Th_PrintTraceLog(); |
| 2388 | 2428 | if( forceCgi ) cgi_reply(); |
| 2389 | 2429 | } |
| 2390 | 2430 | #endif |
| 2391 | 2431 |
| --- 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 |