Update of /cvsroot/webware/Webware/WebKit/Adapters/wkcgi
In directory usw-pr-cvs1:/tmp/cvs-serv10193/WebKit/Adapters/wkcgi
Added Files:
Makefile README webkit.cfg wkcgi.c wkcgi.dsp wkcgi.dsw wkcgi.h
Log Message:
Rearranged the WebKit directory, so all the adapters are in an
Adapters subdirectory -- including WebKit.cgi, OneShot.cgi,
and all the subdirectories of Native.
Also added LRWPAdapter for the Xitami web server.
Updated InstallGuide.html -- both minor changes to paths and
general updating (including adapters which have been added
since that was written).
--- NEW FILE: Makefile ---
all: wkcgi
CFLAGS = -O2
COMMON = ../common
.c.o:
$(CC) $(CFLAGS) -c $(@D)/$(<F) -o $(@D)/$(@F)
wkcgi: wkcgi.o marshal.o environ.o wkcommon.o parsecfg.o
wkcgi.o: wkcgi.c wkcgi.h
marshal.o: $(COMMON)/marshal.c $(COMMON)/marshal.h
$(CC) $(CFLAGS) -c $(COMMON)/marshal.c
environ.o: $(COMMON)/environ.c $(COMMON)/environ.h
$(CC) $(CFLAGS) -c $(COMMON)/environ.c
wkcommon.o: $(COMMON)/wkcommon.c $(COMMON)/wkcommon.h
$(CC) $(CFLAGS) -c $(COMMON)/wkcommon.c
parsecfg.o: $(COMMON)/parsecfg.c
$(CC) $(CFLAGS) -c $(COMMON)/parsecfg.c
clean:
-rm *.o
-rm wkcgi
--- NEW FILE: README ---
This is a C coded cgi script for talking to the WebKit AppServer. Just put it in a directory where your webserver can execute cgi's, and you're good to go.
By default, it will try to talk to the AppServer on host localhost on port 8086. It'll retry the connection 10 times with a delay of 1 second between retries.
To change any of these parameters, put a file name webkit.cfg in the same directory as the cgi executable. A sample file is included here.
Build Instructions:
On UNIX:
Just run make
On Windows:
A VC6 project file is included. You will be able to get prebuilt binaries
from webware.sourceforge.net. If you don't see any there, ask on the
webware-discuss mailing list.
Enjoy
--- NEW FILE: webkit.cfg ---
Host = localhost
Port = 8086
MaxConnectAttempts = 10
ConnectRetryDelay = 1
--- NEW FILE: wkcgi.c ---
//wkcgi.c
#include <stdlib.h>
#include <stdio.h>
#include "wkcgi.h"
int log_message(char * msg) {
// fprintf (stderr, msg);
return 0;
}
int sendCgiRequest(int sock, DictHolder* alldicts) {
int bs = 0;
int length=0;
int totalsent=0;
int content_length=0;
char *buffer;
int buflen=8092;
char *len_str;
bs = send( sock, alldicts->int_dict->str, alldicts->int_dict->ptr - alldicts->int_dict->str, 0);
bs = 0;
length = alldicts->whole_dict->ptr - alldicts->whole_dict->str;
while (totalsent < length) {
bs = send( sock, alldicts->whole_dict->str + totalsent, buflen>(length-totalsent)?length-totalsent:buflen, 0);
if( bs < 0 ) {
log_message("send() returned error code");
return -1;
}
totalsent = totalsent + bs;
}
log_message("whole_dict sent\n");
len_str = getenv("CONTENT_LENGTH");
if (len_str !=NULL) {
int read=0;
int sent=0;
int read_this_time=0;
int sent_this_time=0;
int amount_to_read=0;
int amount_to_send=0;
content_length = atoi(getenv("CONTENT_LENGTH"));
log_message("There is post data");
buffer = (char*) calloc(8092,1);
while (read < content_length) {
amount_to_read = content_length-read;
if( amount_to_read > 8092 ) {
amount_to_read = 8092;
}
read_this_time = fread(buffer, 1, amount_to_read, stdin);
if( read_this_time <= 0 ) {
if( ferror(stdin) ) {
log_message("error during fread(stdin)");
return -1;
} else {
log_message("premature end of input on stdin");
return -1;
}
}
read = read + read_this_time;
amount_to_send = read_this_time;
while( amount_to_send > 0 ) {
sent_this_time = send(sock, buffer+(read_this_time-amount_to_send), amount_to_send, 0);
if( sent_this_time<=0 ) {
log_message("send() returned error code");
return -1;
}
sent += sent_this_time;
amount_to_send -= sent_this_time;
}
}
}
log_message("Sent Request to server");
//Let the AppServer know we're done
shutdown(sock, 1);
return 0;
}
int processCgiResponse(sock) {
char* buff;
int buflen = 8092;
int br;
buff = calloc(buflen,1);
do {
br = recv(sock, buff, buflen, 0);
fwrite(buff, br, 1, stdout);
} while (br > 0);
return 1;
}
#ifdef WIN32
int winStartup() {
WORD wVersionRequested;
WSADATA wsaData;
int err;
_setmode(_fileno(stdin), _O_BINARY);
_setmode(_fileno(stdout), _O_BINARY);
wVersionRequested = MAKEWORD( 1, 0 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
/* Tell the user that we could not find a usable */
/* WinSock DLL. */
return 0;
}
return 1;
}
#endif
int main(char* argc, char* argv[]) {
int sock = 0;
DictHolder* dicts;
char msgbuf[500];
// char* addrstr = /*"localhost";//*/ "127.0.0.1";
// int port = 8086;
unsigned long addr;
EnvItem **envItems;
// int retryattempts = 10;
// int retrydelay = 1;
int retrycount = 0;
Configuration* config;
#ifdef WIN32
char configFile[500];
char* p;
#endif
#ifdef WIN32
winStartup();
#endif
config = malloc(sizeof(Configuration));
#ifdef WIN32
/* IIS runs CGI's in a different directory than they live in. So */
/* we need to construct the full path to the config file by */
/* doing some string manipulation. */
strcpy(configFile, argv[0]);
p = strrchr(configFile, '\\');
if( !p ) {
p = strrchr(configFile, '/');
}
if( p ) {
strcpy(p+1, ConfigFilename);
} else {
strcpy(configFile, ConfigFilename);
}
GetConfiguration(config, configFile);
#else
GetConfiguration(config, ConfigFilename);
#endif
// retryattempts = config->retry_attempts;
// retrydelay = config->retry_delay;
// addrstr = config->host;
// port = config->port;
addr = resolve_host(config->host); //(addrstr);
log_message("Got addr translation");
/* while (sock < 0) {
sock = wksock_open(addr, config->port);
}
*/
while (sock <= 0 ) {
sock = wksock_open(addr, config->port);
if (sock > 0 || (retrycount > config->retry_attempts)) break;
// if (errno != EAGAIN) break;
sprintf(msgbuf, "Couldn't connect to AppServer,attempt %i of %i", retrycount, config->retry_attempts);
log_message(msgbuf);
retrycount++;
#ifdef WIN32
Sleep(config->retry_delay*1000);
#else
sleep(config->retry_delay);
#endif
}
if( sock <= 0 ) {
return 1;
}
envItems = extractEnviron();
dicts = createDicts(envItems);
freeEnviron(envItems);
log_message("created dicts");
sendCgiRequest(sock, dicts);
log_message("Sent Request\n");
freeWFILE(dicts->int_dict);
freeWFILE(dicts->whole_dict);
free(dicts);
processCgiResponse(sock);
return 0;
}
--- NEW FILE: wkcgi.dsp ---
# Microsoft Developer Studio Project File - Name="WKCGI" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=WKCGI - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "WKCGI.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "WKCGI.mak" CFG="WKCGI - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "WKCGI - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "WKCGI - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "WKCGI - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "WKCGI - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "WKCGI - Win32 Release"
# Name "WKCGI - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=..\common\environ.c
# End Source File
# Begin Source File
SOURCE=..\common\marshal.c
# End Source File
# Begin Source File
SOURCE=..\common\parsecfg.c
# End Source File
# Begin Source File
SOURCE=.\wkcgi.c
# End Source File
# Begin Source File
SOURCE=..\common\wkcommon.c
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=..\common\environ.h
# End Source File
# Begin Source File
SOURCE=..\common\marshal.h
# End Source File
# Begin Source File
SOURCE=..\common\parsecfg.h
# End Source File
# Begin Source File
SOURCE=.\wkcgi.h
# End Source File
# Begin Source File
SOURCE=..\common\wkcommon.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project
--- NEW FILE: wkcgi.dsw ---
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "WKCGI"=.\WKCGI.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################
--- NEW FILE: wkcgi.h ---
#include "../common/wkcommon.h"
#include "../common/marshal.h"
int log_message(char* msg);
unsigned long resolve_host(char *value);
int wksock_open(unsigned long address, int port);
//DictHolder createDicts(EnvItem ** envItems);
|