** DRAFT **
The TH1 hooks feature allows TH1 scripts to be configured that can monitor, create, alter, or cancel the execution of Fossil commands and web pages.
This feature requires the TH1 hooks feature to be enabled at compile-time. Additionally, the "th1-hooks" repository setting must be enabled at runtime in order to successfully make use of this feature.
TH1 Hook Related User-Defined Procedures
In order to activate TH1 hooks, one or more of the following user-defined procedures should be defined, generally from within the "th1-setup" script (setting) for a repository. The following bullets summarize the available TH1 hooks:
- command_hook -- Called before execution of a command.
- command_notify -- Called after execution of a command.
- webpage_hook -- Called before rendering of a web page.
- webpage_notify -- Called after rendering of a web page.
TH1 Hook Related Variables for Commands
- cmd_name -- Name of command being executed.
- cmd_args -- Current command line arguments.
- cmd_flags -- Bitmask of CMDFLAG values for the command being executed.
TH1 Hook Related Variables for Web Pages
- web_name -- Name of web page being rendered.
- web_args -- Current web page arguments.
- web_flags -- Bitmask of CMDFLAG values for the web page being rendered.
TH1 Hook Related Return Codes for Commands
- TH_OK -- Command will be executed, notification will be executed.
- TH_ERROR -- Command will be skipped, notification will be skipped, error message will be emitted.
- TH_BREAK -- Command will be skipped, notification will be skipped.
- TH_RETURN -- Command will be executed, notification will be skipped.
- TH_CONTINUE -- Command will be skipped, notification will be executed.
For commands that are not included in the Fossil binary, allowing their execution will cause the standard "unknown command" error message to be generated, which will typically exit the process. Therefore, adding a new command generally requires using the TH_CONTINUE return code.
TH1 Hook Related Return Codes for Web Pages
- TH_OK -- Web page will be rendered, notification will be executed.
- TH_ERROR -- Web page will be skipped, notification will be skipped, error message will be emitted.
- TH_BREAK -- Web page will be skipped, notification will be skipped.
- TH_RETURN -- Web page will be rendered, notification will be skipped.
- TH_CONTINUE -- Web page will be skipped, notification will be executed.
For web pages that are not included in the Fossil binary, allowing their rendering will cause the standard "Not Found" error message to be generated, which will cause an HTTP 404 status code to be sent. Therefore, adding a new web page generally requires using the TH_CONTINUE return code.
Triggering TH1 Return Codes from a Script
- TH_OK -- This is the default return code, nothing special needed.
- TH_ERROR -- Use the error command.
- TH_BREAK -- Use the break command.
- TH_RETURN -- Use the return -code 5 command.
- TH_CONTINUE -- Use the continue command.
TH1 command_hook Procedure
- command_hook
This user-defined procedure, if present, is called just before the execution of a command. The name of the command being executed will be stored in the "cmd_name" global variable. The arguments to the command being executed will be stored in the "cmd_args" global variable. The associated CMDFLAG value will be stored in the "cmd_flags" global variable. Before exiting, the procedure should trigger the return code that corresponds to the desired action to take next.
TH1 command_notify Procedure
- command_notify
This user-defined procedure, if present, is called just after the execution of a command. The name of the command being executed will be stored in the "cmd_name" global variable. The arguments to the command being executed will be stored in the "cmd_args" global variable. The associated CMDFLAG value will be stored in the "cmd_flags" global variable. Before exiting, the procedure should trigger the return code that corresponds to the desired action to take next.
TH1 webpage_hook Procedure
- webpage_hook
This user-defined procedure, if present, is called just before the rendering of a web page. The name of the web page being rendered will be stored in the "web_name" global variable. The arguments to the web page being rendered will be stored in the "web_args" global variable. The associated CMDFLAG value will be stored in the "web_flags" global variable. Before exiting, the procedure should trigger the return code that corresponds to the desired action to take next.
TH1 webpage_notify Procedure
- webpage_notify
This user-defined procedure, if present, is called just after the rendering of a web page. The name of the web page being rendered will be stored in the "web_name" global variable. The arguments to the web page being rendered will be stored in the "web_args" global variable. The associated CMDFLAG value will be stored in the "web_flags" global variable. Before exiting, the procedure should trigger the return code that corresponds to the desired action to take next.