Tip

CGI APIs you need to know

CGI APIs you need to know

In preparation for CGI programming, you are going to have to get very familiar with a few APIs. Let's take a look at them in detail:

QtmhRdStin. The QtmhRdStin API allows you to read the CGI input from stdin by placing the contents of stdin in a receiver buffer. Its parameters are:

  • Receiver variable - char(*). This is the receiver buffer. You can define it with any length you think you will need, but error on the heavy side; that is, define it too large instead of too short. Alternatively, you could define and allocate it in dynamic memory. Use the CONTENT_LENGTH environment variable (more on this later) to determine how many bytes you need to allocate. We'll cover the format of the data in the next couple of months.
  • Length of receiver variable - int(4). This is a four-byte integer (10.0 I for RPGers) used to specify how many bytes you are providing for the receiver buffer. The API may not need all of it, but will never use more.
  • Bytes available on stdin - int(4). In this four-byte integer, the API will provide your program with the actual number of bytes of data available to be read from stdin. If it is larger than the number specified for the previous parameter (length of receiver variable), you will need to call this API again with a larger receiver buffer. This API does not remove data from stdin, it only reads it, so you can reread the data as many times as you require.
  • Error code - char(*). Generic API error code structure. I like to send four bytes of hexadecimal zeros, which causes APIs to generate escape messages when they encounter errors.

QtmhWrStout. The QtmhWrStout API allows you to write data to the CGI output device stdout. Its parameters are:

  • Data to write to stdout - char(*). There are a couple of different formats in which you can write the data (again, we will cover these formats in the next few months). However, most of the time it is just normal HTML code. It can be as long as you require.
  • Length of data - int(4). In this four-byte integer, specify how many bytes you want to write to stdout.
  • Error code - char(*). Generic API error code structure. Again, I find four bytes of hexadecimal zeros works best and is the easiest.

QtmhGetEnv. Remember, part of the CGI standard includes defining, at least partially, the environment in which CGI programs will run. This environment is made up of a handful of what's called environmental variables, each of which contains pertinent information that a CGI program can read. For example, the server will set the CONTENT_LENGTH environment variable to the length of the data in stdin. The QtmhGetEnv API lets you retrieve the value of an environment variable. Its parameters to this API are:

  • Receiver variable - char(*). This is the receiver buffer in which the value of the specified environment variable is placed.
  • Length of receiver variable - int(4). This is a four-byte integer used to specify how many bytes you are providing for the receiver buffer. The API may not need all of it, but will never use more.
  • Length of environment variable value- int(4). In this parameter, the actual length of the value of the environment variable is returned. If it is zero, the environment variable was not found.
  • Environment variable requested- char(*). Specify the name of the environment variable for which you want the value. For example, CONTENT_LENGTH.
  • Length of environment variable - int(4). Specify the length of the name of the environment variable specified in the previous parameter. For example, if you specify the CONTENT_LENGTH environment variable, the length is 14.
  • Error code - char(*). Generic API error code structure.

QtmhPutEnv. This API allows you to create and set your own environment variables for communications, for example, between a CGI program and a Net.Data macro (Net.Data macros have access to CGI environment variables and all other environment variables). The parameters are:

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.