
São várias as linguagens de programação de aplicativos Internet que utilizam as interfaces CGI e ISAPI, entre elas, as linguagens OPUS e OPUSWin, da Tecnocoop Sistemas.
Vamos apresentar, a seguir, exemplos para as interfaces CGI e ISAPI, utilizando as linguagens C/C++, OPUS e OPUSWin.
O exemplo que segue apresenta ao usuário a mensagem "Bem-vindo ao CGI!".
#include <stdio.h>
void main()
{
printf("Content-type: text/html\n\n");
printf("<html><head><title>CGI C Demo</title></head>");
printf("<body><h1>Bem-vindo ao CGI!</h1>");
printf("</body></html>");
exit(0);
}
Este exemplo é idêntico ao anterior, porém, utilizando a interface ISAPI e emitindo a mensagem "Bem-vindo ao ISAPI!".
#include <windows.h>
#include <httpext.h>
#include <string.h>
#include <stdio.h>
BOOL WINAPI GetExtensionVersion( HSE_VERSION_INFO *pVer )
{
pVer->dwExtensionVersion = MAKELONG(HSE_VERSION_MINOR,
HSE_VERSION_MAJOR);
lstrcpyn( pVer->lpszExtensionDesc, "ISAPI C Demo",
HSE_MAX_EXT_DLL_NAME_LEN );
return TRUE;
}
DWORD WINAPI HttpExtensionProc(EXTENSION_CONTROL_BLOCK *pECB)
{
CHAR buff[2048];
DWORD dwLen=0;
pECB->dwHttpStatusCode=0;
wsprintf(buff,"Content-Type: text/html\r\n\r\n"
"<head><title>ISAPI C Demo</title></head>\n"
"<body><h1>Bem-vindo ao ISAPI!</h1>\n");
dwLen=lstrlen(buff);
if (!pECB->ServerSupportFunction( pECB->ConnID,
HSE_REQ_SEND_RESPONSE_HEADER, "200 OK",
&dwLen,(LPDWORD) buff ))
{
return HSE_STATUS_ERROR;
}
pECB->dwHttpStatusCode=200;
return HSE_STATUS_SUCCESS;
}
O exemplo apresentado a seguir é idêntico aos anteriores, utilizando a interface CGI.
$web
prog demo
html_init()
html_head()
html_put ("<html><head><title>CGI OPUS Demo</title></head>")
html_put("<body><h1>Bem-vindo ao CGI</h1>")
html_put ("</body></html>")
html_write("")
return
O exemplo apresentado a seguir é idêntico aos anteriores, utilizando a interface ISAPI.
$dll=demo.dll
proc HttpExtensionProc
html_init()
html_head()
html_put ("<html><head><title>ISAPI OPUSWin Demo</title></head>")
html_put("<body><h1>Bem-vindo ao ISAPI!</h1>")
html_put ("</body></html>")
html_write("")
return
