IPC@CHIP® RTOS-PPC – API Documentation

Header image

Main page


int CGI_Install ( const CGI_Entry cgiEntryPtr  ) 

This function must be called to install a CGI function.

Parameters:
cgiEntryPtr Pointer to a CGI_Entry type structure. The CGI_Entry object does not need to persist after the call.
Returns:
zero on success, non-zero on failure. Return value contains error code CGI_NO_FREE_ENTRY or CGI_INVALID_METHOD.
Example:
void cgiFunction( rpCgiPtr CgiRequest )
{
  static char buffer[1024];  // Buffer to contain web page
  char tmpString[16];

  // Convert remote IP address
  InetToAscii((const unsigned long *)CgiRequest->fRemoteIPPtr, tmpString);

  // Check for buffer overrun
  if (CgiRequest->fArgumentBufferLength < 512)
  {
      // Construct HTML page
      sprintf( buffer, "<html>\r\n"
                       "<head><title>CGI Example</title></head>\r\n"
                       "<body>\r\n"
                       "<h1>CGI Example</h1>\r\n"
                       "<p>\r\n"
                       "Url: %s<br />\r\n"
                       "Host: %s<br />\r\n"
                       "Remote IP: %s<br />\r\n"
                       "Arguments: %s<br />\r\n"
                       "</p>\r\n"
                       "</body>\r\n"
                       "</html>\r\n",
                       CgiRequest->fPathPtr,
                       CgiRequest->fHostPtr,
                       tmpString,
                       ( CgiRequest->fArgumentBufferLength > 0 ) ?
                             CgiRequest->fArgumentBufferPtr : "No arguments"
      );

      // Give it to the web server
      CgiRequest->fHttpResponse         = CgiHttpOk;
      CgiRequest->fDataType             = CGIDataTypeHtml;
      CgiRequest->fResponseBufferPtr    = buffer;
      CgiRequest->fResponseBufferLength = strlen( buffer );
  }
}


void InitializeCGI (void)
{
   CGI_Entry cgiEntry;

   cgiEntry.PathPtr    = "mycgi";         // Name of the page
   cgiEntry.method     = CgiHttpGet;      // HTTP method
   cgiEntry.CgiFuncPtr = cgiFunction;     // Function called on browser request

   if( CGI_Install( &cgiEntry ) != 0 )
   {
      printf("\r\nError: Installing CGI function %s failed", cgiEntry.PathPtr );
   }
}
Since:
SC2x3 V1.00 - CLIB V1.00
See also:
CGI_Delete(), MAXCGIENTRIES





Top of page | Main page

Copyright © 2017 Beck IPC GmbH
Generated on Thu Jan 26 16:21:36 2017 by Doxygen 1.6.1