Encoding arbitrary URLs and arguments


In the previous example, the Action URL of a form statement was encoded. It is also possible (and sometimes necessary) to encode normal URLs to access Sigma screens, including passing data as part of the URL. This is easily accomplished using the "sigma.lib" functions and "sigcmd.exe" program, using the "SG_link" function.

The SG_link function is used to encode any URL that is within the Sigma framework. It is not useful for accessing files outside of Sigma (because the URL "payload" is encoded and will not be decipherable to other applications.) It is an easy way to construct hypertext anchors in the form "<a href=url>", where the "url" value may contain additional command arguments passed to the target program.

To illustrate the usage of the SG_link function, consider the following batch file, which resides in the "sigma-web\010_DisplayArg.bat" file.

This file creates a "DisplayArg" tab, which when clicked by a user, performs no substantial action. However, if a URL accesses the program, and that URL contains one to four arguments, those arguments are displayed to the user.

This can be used to illustrate how a URL can not only execute a program, but also pass data to that program similar to the way a form post operates. For example, a URL may contain data that is read as the command arguments of the executed program. (In this case the executed program simply displays the arguments, but more realistic uses of program command arguments are obviously known.)

@Echo off

REM: Filename: sigma-web\010_DisplayArg.bat
REM: Display the first four command arguments.

Echo Program Pathname: %0%

Echo Arg1: %1%
Echo Arg2: %2%
Echo Arg3: %3%
Echo Arg4: %4% 

The above batch file simply displays the first four arguments passed to the program, and is useful to illustrate the operation of passing arguments (if not possessing any other use.) 

Now consider that the user wants to execute the 010_DisplayArg.bat file from another screen, passing that target various arguments. The program to accomplish this is provided as "005_SetArg.cmd", as shown below:

@Echo off
REM: Filename: sigma-web\005_SetArg.cmd
REM: Pass arguments to the 010_DisplayArg.bat file.
REM: An encrypted URL passes these arguments.

Set URL= 010_DisplayArg.bat
Set URL=%URL%;My first argument
Set URL=%URL%;My second argument
Set URL=%URL%;My third argument
Set URL=%URL%;My last argument

sigcmd.exe SG_link "%URL%"
Click to access DisplayArg screen.
Echo "</a>"

The "005_SetArg.cmd", program, above, creates a link. The link consists of various arguments (in addition to the URL to a target program.) When the link is clicked, the target "010_DisplayArg.bat" program is launched, and that target batch file receives the various arguments defined above. The arguments are received as normal and unencrypted arguments %0%, %1%, etc. 

Several things should be noted that are somewhat critical: First, the various arguments, appended to the URL value, are delimited by semicolons, and not by '&' characters. This is because the "&" character is reserved for passing data WITHOUT encoding, as discussed in a previous chapter. This may be an easy programming mistake to make.

Also, note that the SG_link program expects a single parameter, hence the URL is enclosed in double quote marks. (This would not be necessary, except that the various arguments contain spaces.)

Finally, note that the opening anchor <a> is created by the SG_link function, but the user needs to supply the closing anchor. Failure to do so will result in all subsequent text being incorporated as part of the link (a common programming mistake.)


 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*