ENTRYFUNC, EXITFUNC - set entry/exit functions

SYNOPSIS

<ENTRYFUNC = function>
<EXITFUNC = function>


DESCRIPTION
The ENTRYFUNC directive sets an additional function to call first upon entry to the script, before the start function (which is specified in the URL or $cmd). By default, no entry function is called, i.e. execution starts with the start function. The EXITFUNC directive sets an additional function to call when the script ends normally (i.e. not via <exit>). By default no exit function is called.

Since execution of both functions is controlled by the script and not the user, private functions may be specified. As they are directives, both ENTRYFUNC and EXITFUNC must appear before the first function in the script,

An entry function can be useful for setting global variables, checking access permissions, or printing the look and feel HTML for an application. Since it is guaranteed to be called first - before the start function or main - it does not need to be explicitly called by every public function in the script, and will be called for any future public functions added. Once the entry function returns, execution resumes at the start function (or main) as normal. Thus, the entry function can concentrate on tasks that are the same for every invocation, while the specific start function(s) can deal with function-specific tasks (e.g. displaying vs. editing). An entry function has advantages over EntryScript (here) in that it can be used by any script, including command-line and non-Texis-Web-Server scripts, and it can set variables and call functions within the script.

Modules can also have entry/exit functions; the entry function for a module is called before the entry function for the parent file that <uses> it, so that the parent entry function can count on its modules already being initialized. (However, there is no guaranteed call order for multiple modules' entry functions in a single <uses>, nor is the entry function for a module that is used by multiple parents guaranteed to be called before all of its parents'.)

An exit function is useful for logging transactions or printing the bottom part of look at feel HTML. It is called when the script ends normally, i.e. not via exit.


EXAMPLE

<ENTRYFUNC = checkperms>
<EXITFUNC = logtransaction>

<A NAME=checkperms PRIVATE>
  <if "127.0.0.1" neq $REMOTE_ADDR>
    You are not authorized to use this application. <exit>
  </if>
  <HTML><HEAD><TITLE>My Application</TITLE></HEAD>
  <BODY BGCOLOR=white>
</A>

<A NAME=logtransaction PRIVATE>
  <SQL "insert into log(ip, query)
        values($REMOTE_ADDR, $QUERY_STRING)">
  </SQL>
  </BODY>
  </HTML>
</A>

<A NAME=main PUBLIC>
  Hello.
</A>

<A NAME=edit PUBLIC>
  ... edit form ...
</A>

Every run of the script - whether to main or edit or some future function - will first execute checkperms to check permissions and print opening HTML. At the end (if exit is not called), logtransaction will be called to log the transaction.


CAVEATS
The ENTRYFUNC and EXITFUNC directives were added in version 5.01.1098192447 20041019.


SEE ALSO
EntryScript (here), ExitScript (here),


Copyright © Thunderstone Software     Last updated: Apr 15 2024
Copyright © 2024 Thunderstone Software LLC. All rights reserved.