• No results found

This macro defines the size of a buffer in xmem that is used to hold WEB_ERROR() error mes- sages. This buffer limits the total size of the error messages associated with a single form up- date. Defaults to 512.

A.3 Compiler Directives

The RabbitWeb compiler directives are summarized here.

#web

Registers a variable, array or a structure with the server. For more information, see Section 2.1. The #web statement has several optional parts that can be used when a variable (or array or structure) is registered. The optional parts are:

An error-checking expression to limit the acceptable values that are submitted. For more information see Section 2.2. A macro called WEB_ERROR can be included in the error- checking expression to associate a string with an error. For more information, see

Section 2.2.1.

The “auth=” parameter is a comma separated list of acceptable authentication methods. The possible choices are basic, digest and ssl. For more information, see Section 2.3.

The “groups= “ parameter is a comma separated list of user groups that are allowed access to the web variable (or array or structure). For more information, see Section 2.3.

One or more of the optional parts can be used in a #web statement.

#web_groups

This directive defines a web group. For more information, see Section 2.3.

#web_update

This directive identifies a user-defined function to call in response to a variable update. For more information, see Section 2.4.

A.4 ZHTML Grammar

Terminals are in bold, “[ ]” indicate optional parts, and “|” indicates an OR in the statement.

zhtml-tag -> <?z statement ?>

statement -> print-function | printf-function | varname-function | print_opt-function |

print_select-function | if-statement | for-loop print-function -> print( variable )

variable -> $ registered-variable | loop-variable

registered-variable is an array, structure or variable that is registered with the web server.

loop-variable -> $ A-Z

loop-variable is a one-letter variable (A-Z) defined in the for loop, and can be used as the index for an array.

printf-function -> printf ( printf-specifier , variable )

The printf-specifier is like a C printf specifier, except that it is limited to a single variable.

varname-function -> varname( variable )

print_opt-function -> print_opt( variable , number ) | print_opt( variable , loop-variable )

print_select-function -> print_select( variable )

count-expression -> count( variable, number ) | count( variable )

Note that in the first option variable is an array; in the second option it is a selection-type variable.

numeric-expression -> loop-variable | integral-variable | count-expression | numeric-literal

integral-variable refers to a registered #web variable of integral (int or long, signed or

unsigned) type.

if-statement -> if ( if-expression ) { html-code }

if-expression ->numeric-expression operator numeric-expression | [ ! ] error( variable ) |

[ ! ] auth( variable , “ group-rights “ ) | [ ! ] updating( )

operator -> == | != | > | < | >= | <=

group-rights -> ro | rw

for-loop -> for ( loop-variable = numeric-expression ;

loop-variable operator numeric-expression ;

loop-variable for-inc ) { html-code }

for-inc -> ++ | -- | += numeric-expression | -= numeric-expression ro stands for read-only

A.5 RabbitWeb Functions

This section lists all of the functions that can be called within ZHTML tags.

auth()

This function is used to check if a user has authorization for accessing a specific variable.

<?z if (auth($foo, “rw”)) { ?>

You have read-write access to the variable foo. <?z } ?>

This function can be preceded by “!” (the not operator).

count()

This function is for arrays and selection-type variables.

If the first parameter is an array, the second parameter specifies an array dimension. For a one- dimensional array, the second parameter must be zero. For a two-dimensional array, the second parameter must be zero or one. And so on. If the first parameter is an array, the return value of the function is the upper bound for the specified array dimension.

If the first parameter is a selection variable, there is no second parameter. The count() func- tion returns the number of options for a selection variable.

The return value of count() can be used in a for loop to cycle through all elements of an array.

<?z for ($A = 0; $A < count($foo, 0); $A++) { ?>

echo(), print()

These are display functions to make web variables visible on an HTML page. They display the variable passed to them using a default conversion specifier. The function echo() is an alias for print().

<?z print($foo) ?>

error()

The error() function can be called both with and without a parameter. If it is called without a parameter it will return TRUE if there were any errors in the form submission and FALSE oth- erwise. To call error() with a parameter, you must pass it the name of a web variable. The function will return TRUE if that variable did not pass its error check, and FALSE otherwise. It can be used to print out the WEB_ERROR() message:

printf()

This is a display function to make web variables visible on an HTML page. With printf()

you can display a variable of type int or long:

<?z printf(“%ld”, $long_foo) ?>

print_opt()

This is a display function to make selection-type web variables visible on an HTML page. It takes two parameters. The first parameter is a selection-type variable and the second parameter is the index into the list of possible values for the selection-type variable.

<?z print_opt($select_var, $A) ?>

print_select()

This is a display function to make selection-type web variables visible on an HTML page. It

automatically generates the option list for a given selection variable:

<?z print_select($select_var) ?>

selected()

The selected() function takes two parameters. The first parameter is a selection variable and the second parameter is an integer index into the array of options for the specified selection variable. The function returns TRUE if the option indicated by the index parameter matches the currently selected option, and FALSE if it doesn’t.

For example, to iterate through all possible values of a selection-type variable and output the appropriate “<OPTION>” or “<OPTION SELECTED>” tags, something like the following can be done:

<?z for ($A = 0; $A < count($select_var, 0); $A++) { ?> <OPTION <?z if (selected($select_var, $A)) { ?> SELECTED <?z } ?> > <?z print_opt($select_var, $A) ?>

The page Samples/tcpip/rabbitweb/pages/selection.zhtml uses the

updating()

This function can be used with an if statement to test whether the current page is being dis- played as the result of a POST request instead of a GET request. This is useful to redirect to another page on a successful form submission. Use this function as follows:

<?z if (updating()) { ?> <?z if (!error()) { ?>

<META HTTP-EQUIV=”Refresh” CONTENT=”0; URL=http://yoururl.com/”>

<?z } ?> <?z } ?>

This function can be preceded by “!” (the not operator).

varname()

This is a convenience function that gets around the limitation of no square brackets in the NAME attribute of the INPUT tag in HTML.

<INPUT TYPE=”text” NAME=”<?z varname($foo[3]) ?> ”VALUE=” <?z echo($foo[3]) ?>”>

Related documents