@CHIP-RTOS - Data Structures used in CGI API

    IPC@CHIP® Documentation Index

Data Structures

Here are the data structures used by the CGI API.
All constants and data structures are defined in the header file cgi.h

  • Byte alignment is required for all data structures used within the API.

Contents :

  • typedef CGI_Entry
  • define CGI HTTP Request
  • typedef FormItem
  • typedef rpCgi
  • typedef SSI_Params

  • typedef CGI_Entry

    typedef struct tag_cgi_table
        char         *PathPtr;     // Name of the page, URL
        int           method;      // http method: Get, Head  or Post
        RpCgiFuncPtr  CgiFuncPtr;  // ptr to callback function for this page
    } CGI_Entry;


    The members of the CGI_Entry structure should be filled as follows.

      This is a far pointer to a zero terminated URL address of the page.  

      This int is an enumerator used to specify what HTTP method this CGI function supports.

      This is a far vector to the CGI function for this Web page.   For Borland C compilers the RpCgiFuncPtr type is:

        typedef void (huge _pascal *RpCgiFuncPtr)
                    (rpCgi far *CgiRequestPtr);

            ... and therefore the CGI function itself is declared as ...

        void huge _pascal CGI_Func(rpCgi far *CgiRequest);

      For Microsoft Visual C compilers the RpCgiFuncPtr type is:

        typedef void far _saveregs _loadds _pascal
            (*RpCgiFuncPtr)(rpCgi far *CgiRequestPtr);

            ... and the CGI function declared as ...

        void far _saveregs _loadds _pascal
                CGI_Func(rpCgi far *CgiRequest);

    Related Topics

    API function CGI_INSTALL - Install a CGI function
    rpCgi structure type

    Top of list
    Index page

    define CGI HTTP Request

    #define CgiHttpGet  1       //  Cgi request is HTTP GET
    #define CgiHttpHead 2       //  Cgi request is HTTP HEAD
    #define CgiHttpPost 3       //  Cgi request is HTTP POST
    #define CgiHttpAll  255     //  Cgi request handler for all methods


    These defines are used as enumeration names for request methods.

    Related Topics

    method member of CGI_Entry type

    Top of list
    Index page

    typedef FormItem

    typedef struct tag_form_item
        char   *NamePtr;
        char   *ValuePtr;
    } FormItem;


    Both strings referenced here are null terminated.

    Related Topics

    API function CGI_GETFORMITEM - Split a form item into name and value

    Top of list
    Index page

    typedef rpCgi

    typedef struct {
        //    Request fields  (Read Only!!!!)
        unsigned char  fConnectionId;          // SC1x3/SC2x: 0=HTTP/1=HTTPS (SSL) server
                                               // SC1x: -- internal use only --
        int            fHttpRequest;           // CgiHttpGet or CgiHttpPost
        char          *fPathPtr;               // URL
        char          *fHostPtr;               // Host
        char          *fRefererPtr;            // Referer (SC1x3/SC2x only)
        char          *fAgentPtr;              // Agent (SC1x3/SC2x only)
        char          *fLanguagePtr;           // Accept-Language (SC1x3/SC2x only)
        unsigned long  fBrowserDate;           // Date:   (internal)
        char          *fArgumentBufferPtr;     // Pointer to argument buf
        long           fArgumentBufferLength;  // Length of argument buf
        char          *fUserNamePtr;           // Username from Authorization
        char          *fPasswordPtr;           // Password from Authorization
        long          *fRemoteIPPtr;           // points to the remoteIP,
                                               // you must split the octets
                                               // For using the IP to establish TCP/IP
                                               // connections, you have to exchange
                                               // low byte and high byte!
        //    Response fields  (Set by CGI function)
        int            fResponseState;         // -- internal, do not modify --
        int            fHttpResponse;          // Response httpmsg e.g. CgiHttpOk
        int            fDataType;              // Content type, e.g. text/HTML, text/plain
        char          *fResponseBufferPtr;     // Pointer to the created page
        long           fResponseBufferLength;  // Length of the page
                                               // (on SC1x: max. length is 65519 chars)
        unsigned long  fObjectDate;            // -- internal, do not modify --
        unsigned int   fHostIndex;             // -- internal, do not modify --
        char far *     fSetCookieHeaders;      // The SetCookie header to send to browser
        int            fNumOfSetCookieHeaders; // Number of cookies to send to browser
        char far *     fCookieHeader;          // The cookie header, received from browser
        char far *     fResponseHeadersPtr;    // Pointer to a string that contains user
                                               // specific headers. Multiple headers have to
                                               // be separated by "\r\n". See example below.
        unsigned int   fFlags;                 // Contains several flags according to the response
        unsigned long  fLongParam;             // 32 bit parameter to keep management data
    } rpCgi, *rpCgiPtr;


      Contains the method of the that request:
      #define CgiHttpGet                    1  //  CGI request is HTTP GET 
      #define CgiHttpHead                   2  //  CGI request is HTTP HEAD 
      #define CgiHttpPost                   3  //  CGI request is HTTP POST 

      This is an enumeration type that specifies the web server response.
      You should use one of the macros defined in the CLIB:
      #define  CgiHttpOk               0  //  CGI returns HTTP 200 Ok 
      #define  CgiHttpOkStatic         1  //  CGI returns HTTP 200 Ok - Static Object 
      #define  CgiHttpRedirect         2  //  CGI returns HTTP 302 Moved Temp 
      #define  CgiHttpNotModified      3  //  CGI returns HTTP 304 Not Modified 
      #define  CgiHttpUnauthorized     4  //  CGI returns HTTP 401 Unauthorized 
      #define  CgiHttpNotFound         5  //  CGI returns HTTP 404 Not Found 
      #define  CgiHttpOKNoDoc          6  //  CGI returns HTTP 204 No document follows 
      #define  CgiHttpNotAvail         7  //  CGI returns HTTP 503 Service Not Available 
      #define  CgiHttpSrvError         8  //  CGI returns HTTP 500 Internal Srv Error 

      This is an enumeration type that specifies the file type.
      You should use one of the macros defined in the CLIB:
      #define  CGIDataTypeHtml                  0  // CGI returns  text/html 
      #define  CGIDataTypeImageGif              1  // image/gif 
      #define  CGIDataTypeApplet                2  // application/octet-stream 
      #define  CGIDataTypeText                  3  // text/plain 
      #define  CGIDataTypeImageJpeg             4  // image/jpeg 
      #define  CGIDataTypeImagePict             5  // image/pict 
      #define  CGIDataTypeImageTiff             6  // image/tiff 
      #define  CGIDataTypeImagePng              7  // image/png 
      #define  CGIDataTypeForm                  8  // application/x-www-form-urlencoded 
      #define  CGIDataTypeIpp                   9  // application/ipp 
      #define  CGIDataTypeCss                  10  // text/css 
      #define  CGIDataTypeXml                  11  // text/xml 
      #define  CGIDataTypeWav                  12  // audio/wav 
      #define  CGIDataTypePdf                  13  // application/pdf 
      #define  CGIDataTypeJavaArchive          14  // application/java-archive 
      #define  CGIDataTypeOctet                15  // application/octet-stream 
      #define  CGIDataTypeVndWapWml            16  // text/vnd.wap.wml 
      #define  CGIDataTypeVndWapWbmp           17  // image/vnd.wap.wbmp 
      #define  CGIDataTypeVndWapWmlc           18  // application/vnd.wap.wmlc 
      #define  CGIDataTypeVndWapWmlscript      19  // text/vnd.wap.wmlscript 
      #define  CGIDataTypeVndWapWmlscriptc     20  // text/vnd.wap.wmlscriptc 
      #define  CGIDataTypeScaleVectGraph       21  // image/svg+xml 
      #define  CGIDataTypeScaleVectGraphZipped 24  // image/svg+xml (content encoding: gzip) 

      This is an unsigned long value that represents the IPv4 address of the remote host. To get the string representation of the IP address use the following code:

      On SC1x:
      sprintf( ipString, "%d.%d.%d.%d",
           (int)( ( *( CgiRequest->fRemoteIPPtr ) & 0xFF000000l ) >> 24 ),
           (int)( ( *( CgiRequest->fRemoteIPPtr ) & 0x00FF0000l ) >> 16 ),
           (int)( ( *( CgiRequest->fRemoteIPPtr ) & 0x0000FF00l ) >> 8 ),
           (int)( *( CgiRequest->fRemoteIPPtr ) & 0x000000FFl ) );

      On SC1x3/SC2x:
      InetToAscii((const unsigned long far *)CgiRequest->fRemoteIPPtr, ipString);

      This field allows to define one or more additional header fields that will be included in the HTTP response. When more than one header field is contained all fields have to be separated by "\r\n".

      Example 1:
      CgiRequest->fResponseHeadersPtr = "Content-Length: 123"; 

      Example 2:
      CgiRequest->fResponseHeadersPtr = "My-First-Header: somevalue\r\nMy-Second-Header: someothervalue"; 

      This flag field contains several flags to control the handling of the HTTP response. The flags below are allowed to use:
      #define CGI_FLAG_TRANSFERENCODING_CHUNKED  1  // sends the response in chunked encoded mode (enabled by default) 
      #define CGI_FLAG_CALL_AGAIN                2  // CGI function sets this to true if it should be called again 
      #define CGI_FLAG_REQUEST_ABORTED           4  // Web server sets this true if the http request was aborted 

      32 bit parameter, could be used by the application to keep management data when the fFlags specifies the CGI_FLAG_CALL_AGAIN value

    Related Topics

    CGI Callback Function

    Top of list
    Index page


    typedef struct
      unsigned int mimeId;    // enum value, >= 100 for new types
      char far*    mimeExt;   // file extension, e.g. "gif"
      char far*    mimeType;  // mime type, e.g. "image/gif"


      This is an enumeration type. If the value is equal to the internal used fDatatype value, the MIME type value is overwritten for this ID. For new custom MIME types, values greater 100 should be used.

      On Sc1x only three letter extensions are allowed.

    Related Topics

    API function CGI_MIME_INSTALL - Install custom MIME table

    Top of list
    Index page




    Contains the null terminated string which will be send to the browser. A Null pointer or an empty string will be identified as no encoding type. In that case the http content-encoding header will not created.

    Related Topics

    API function CGI_CONTENT_ENCODING_INSTALL - Install custom content encoding table

    Top of list
    Index page


    typedef char far *CUSTOM_HEADERS_TABLE;


    Contains the null terminated string which will be send to the browser. If multiple header fields should be send, they should be separated by CR/LF.

    Related Topics

    API function CGI_HEADERS_INSTALL - Install custom headers table

    Top of list
    Index page

    typedef SSI_Params

    typedef struct
      unsigned char             structVersion; // Version of this struct, for future extenstions of this struct.
                                               // Set to zero for current version V0.
      unsigned char             serverHandle;  // V0 member, Server handle
                                               // 0 = HTTP / 1 = HTTPS (SSL) server
      struct sockaddr_storage * peerSockAddr;  // V0 member, Peer socket address
      struct sockaddr_storage * localSockAddr; // V0 member, Local socket address
      char *                    pathPtr;       // V0 member, URL path name
      char *                    hostPtr;       // V0 member, Host name
      char *                    userNamePtr;   // V0 member, User name from authorization
      char *                    passwordPtr;   // V0 member, Password from authorization
    } SSI_Params;

    Related Topics

    See sockaddr_storage data structure definition

    Top of list
    Index page

    End of document