IPC@CHIP® RTOS-LNX – API Documentation

Header image

Main page


◆ CGI_Install()

int CGI_Install ( const CGI_Entry cgiEntryPtr)

This function must be called to install a CGI function.

Parameters
cgiEntryPtrPointer 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_ERROR.
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
V0.80
See also
CGI_Delete()





Top of page | Main page

Copyright © 2018 Beck IPC GmbH
Generated on Tue Jul 10 2018 14:54:14 by Doxygen 1.8.13