IBM Support

C CGI (compiled with locale object type LOCALEUTF) programming example

News


Abstract

C CGI (compiled with locale object type LOCALEUTF) programming example

Content

You are in: IBM i Technology Updates  > Web Integration on i IBM HTTP Server for i > Introduction > CGI programming example > C CGI (compiled with locale object type LOCALEUTF) programming example

This sample code is provided by IBM for illustrative purposes only. It has not been fully tested. It is provided as-is without any warranties of any kind, including but not limited to the implied warranties of merchantability and fitness for a particular purpose.

This program is a simple C program that demonstrates how to create a CGI program compiled using locale object type *LOCALEUTF for use with CGIConvMode BINARY. It also demonstrates the use of two APIs QzsrGetEnvCCSID and QzsrPutEnvCCSID.

As of V5R4 the IBM HTTP server for iSeries is compiled in UTF-8 (CCSID 1208). You can leverage this in your CGI programs by compiling and working with UTF-8 data.

To install the example program, do the following:

  1. Download the following file: 
  2. Use the following CL commands to create a directory structure: 
    • mkdir '/qsys.lib/utfdemo.lib/'
    • CRTSRCPF FILE(UTFDEMO/QCSRC) RCDLEN(240)
    Be aware the mkdir command will use  hierarchical file authorities, unless you specify otherwise, for the *PUBLIC users.  You may want to specifically add read and execute authorities for server user profiles QTMHHTTP and QTMHHTP1 to these new directories.
  3. Use FTP to connect to your server.
  4. Use the following FTP command to copy the file to your server:
    put localeutf.txt   /qsys.lib/utfdemo.lib/qcsrc.file/localeutf.mbr
  5. Use the following CL commands to create the program (*PGM) object called LOCALEUTF: 
    • CRTCMOD MODULE(UTFDEMO/LOCALEUTF) SRCFILE(UTFDEMO/QCSRC) SRCMBR(LOCALEUTF) OUTPUT(*PRINT) SYSIFCOPT(*IFSIO)  LOCALETYPE(*LOCALEUTF) TERASPACE(*YES)
    • CRTPGM PGM(UTFDEMO/LOCALEUTF) MODULE(UTFDEMO/LOCALEUTF) BNDSRVPGM(QHTTPSVR/QZHBCGI)
  6. Use your browser to access the HTTP Server Configuration and Administration forms to create an Apache server named, for example, UTFCONFIG. Once the server has been created, modify the configuration as follows: 
    1. Select the URL Mapping form then the Aliases tab to add directive ScriptAlias as specified below to allow CGI execution. Click OK 
    2. Select Container Management then the Directories tab to add the directory for /QSYS.LIB/UTFDEMO.LIB/. Click OK
    3. Change the Server area: to
              Directory /QSYS.LIB/UTFDEMO.LIB/
    4. Select Dynamic Content and CGI and set Allow CGI programs to run to Enabled. Next select the Advanced tab to set Conversion mode to BINARY. Click OK
    5. Select Security and then the Control Access tab.
      • Under Control access based on where the request is coming from, set Order for evaluating access: to Allow then deny.
      • Select Allow access to all, except the following: Click OK.
    6. Select Request Processing then the Handlers tab.

      Under Handlers for file extensions: select Set handler for all file extensions and enter  cgi-script in the Handler text box. Click OK.
    7. Under Tools, select Display Configuration File to make sure you have the following CGI related directives:

      ScriptAlias /cgi-binary/ /QSYS.LIB/UTFDEMO.LIB/
      <Directory /QSYS.LIB/UTFDEMO.LIB/>
          Options +ExecCGI
          CGIConvMode BINARY
          SetHandler cgi-script
          Order Allow,Deny
          Allow From all
      </Directory>
  7. Start the UTFCONFIG instance from the GUI.
  8. From your browser enter: http://yourservername:port/cgi-library/localeutf.pgm

[{"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SWG60","label":"IBM i"},"Component":"","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"LOB57","label":"Power"}}]

Document Information

Modified date:
26 October 2021

UID

ibm11172230