Table of Contents
This appendix describes how to create, compile, and execute a client program for WebtoB and Tmax integration.
The following is the client program for apsl.m file described in "4.4.1. Tmax Integration Configuration".
This client program uses the TOUPPER service of svr2, a Tmax sample server program. TOUPPER is mainly composed of wbsession.c and wbquery.c. The path to tmax.env must be specified in wbuquery.c.
Tmax must be installed separately. For more information on instructions to Tmax and its sample server, refer to the Tmax manual.
The following is wbsession.c.
<wbsession.c>
#include <stdio.h> #include <string.h> #include "../usrinc/wbapi.h" wbsession(WBSVCINFO *rqst) { int len; char *value, *value2; char *name; SESSION *session; name = wbGetData( rqst, "name" ); session= wbGetSession( rqst ); session = wbSessionSetValue( session, "name", name, strlen(name) ); value = wbSessionGetValue( session , "name", &len ); wbSendRedirect( rqst, "/svct/query" ); wbReturn( rqst, WBSUCCESS ); }
The following is wbquery.c.
<wbquery.c>
#include <stdio.h>
#include <usrinc/atmi.h>
#include <usrinc/wbapi.h>
int flag=0;
wbSvrInit( int argc, char *argv[] ) {
fprintf( stdout, "query SERVER Start!\n" );
if( test_tpstart() == -1 ) {
fprintf( stdout,"tpstart failed!!! %s \n",tpstrerror(tperrno) );
}
return 0;
}
wbSvrDone() {
fprintf( stdout, "query SVR DONE!\n" );
tpend();
}
query(WBSVCINFO *rqst) {
int len;
char *name;
SESSION *session;
session= wbGetSession( rqst );
name = wbSessionGetValue( session , "name", &len );
wbPutHdr(rqst,"Content-type","text/html; charset=euc-kr");
wbPrint( rqst, "<HTML><BODY>" );
if( query != NULL ) {
wbPrint(rqst, "<H1>send Data: %s <br></H1>", name);
}
else {
wbPrint( rqst, "<H1>QUERY is null</H1>" );
}
if ( test_tpcall(name) == -1 ) {
wbPrint( rqst, "<H1>tpcall failed : %s</H1>", tpstrerror(tperrno) );
}
else {
wbPrint( rqst, "<H1>recieved Data : %s</H1>",name );
}
wbPrint( rqst, "</body></html>" );
wbReturn( rqst, WBSUCCESS );
}
int test_tpstart() {
int rcode;
rcode = tmaxreadenv( "/data1/gloria/webtob/ap/tmax.env", "TMAX" );
if ( rcode == -1 ) {
printf( "tmax readenv failed %s \n", tpstrerror(tperrno));
return -1;
}
rcode = tpstart( (TPSTART_T *)NULL );
if ( rcode == -1 ){
printf( "tpstart failed %s \n",tpstrerror(tperrno) );
return -1;
}
return 1;
}
int test_tpcall(char *name) {
int rcode;
char *sndbuf, *rcvbuf;
long rcvlen, sndlen;
if ((sndbuf = (char *)tpalloc("STRING", NULL, 0)) == NULL){
printf( "sendbuf alloc failed ! %s \n", tpstrerror(tperrno) );
tpend();
return -1;
}
if ((rcvbuf = (char *)tpalloc("STRING", NULL, 0)) == NULL){
printf( "recvbuf alloc failed ! %s \n", tpstrerror(tperrno) );
tpfree( (char *)sndbuf );
tpend();
return -1;
}
strcpy(sndbuf, name);
if(tpcall("TOUPPER", sndbuf, 0, &rcvbuf, &rcvlen, 0)==-1){
printf("Can't send request to service TOUPPER %s \n", tpstrerror(tperrno));
tpfree( (char *)sndbuf );
tpfree( (char *)rcvbuf );
tpend();
return -1;
}
printf( "[rcvbuf:%s]\n", rcvbuf );
strcpy( name, rcvbuf );
tpfree( (char *)sndbuf );
tpfree( (char *)rcvbuf );
return 1;
}
From the previous source code, modify tmaxreadenv to the path of the Tmax environment file.
The following is the tmax.env file.
<tmax.env>
[TMAX] TMAXDIR=/data1/gloria/tmax TMAX_HOST_ADDR=192.168.1.43 TMAX_HOST_PORT=7979 SDLFILE=/data1/gloria/tmax/sample/sdl/tmax.sdl FDLFILE=/data1/gloria/tmax/sample/fdl/tmax.fdl TMAX_CONNECT_TIMEOUT=2 [TMAX] TMAXDIR=/data1/gloria/tmax TMAX_HOST_ADDR=192.168.1.43 TMAX_HOST_PORT=7979 SDLFILE=/data1/gloria/tmax/sample/sdl/tmax.sdl FDLFILE=/data1/gloria/tmax/sample/fdl/tmax.fdl TMAX_CONNECT_TIMEOUT=2
The following is a makefile used to compile client programs.
#Makefile.c TARGET = $(COMP_TARGET) APOBJS = $(TARGET).o WEBTOB_INCDIR = $(WEBTOBDIR)/usrinc WEBTOB_BINDIR = $(WEBTOBDIR)/bin WEBTOB_LIBDIR = $(WEBTOBDIR)/lib ############### # TMAX_LIBDIR # ############### #32bit Tmax library TMAX_LIBDIR = $(TMAXDIR)/lib #64bit Tmax library #TMAX_LIBDIR = $(TMAXDIR)/lib64 #SDLFILE = demo.s #SDLDIR = $(WEBTOBDIR)/sdl ########## # CFLAGS # ########## #hp 32bit CFLAGS = -Ae +DA1.1 +DD32 +DS2.0 -O -I$(WEBTOBDIR) -L/data1/gloria/tmax/lib #hp 64bit #CFLAGS = -Ae +DA2.0W +DD64 +DS2.0 -O -I$(WEBTOBDIR) -L/data1/gloria/tmax/lib #sun 64bit #CFLAGS = -xarch=v9 -O -I$(WEBTOBDIR) #Linux #CFLAGS = -O -I$(WEBTOBDIR) #ibm 32bit #CFLAGS = -q32 -O -I$(WEBTOBDIR) -brtl #ibm 64bit #CFLAGS = -q64 -O -I$(WEBTOBDIR) -bnoquiet -brtl ######## # LIBS # ######## #hp, sun, linux LIBS = -laps -lcli #ibm #LIBS = -laps -lcli -lz OBJS = $(APOBJS) $(SVCTOBJ) $(SDLOBJ) SVCTOBJ = $(TARGET)_svctab.o #SDLOBJ = ${SDLFILE:.s=_sdl.o} #SDLC = ${SDLFILE:.s=_sdl.c} .SUFFIXES : .v .c.o: $(CC) $(CFLAGS) -c $< # Server $(TARGET): $(APOBJS) $(SVCTOBJ) $(CC) $(CFLAGS) -L$(WEBTOB_LIBDIR) -L$(TMAX_LIBDIR) -o $(TARGET) $(OBJS) $(LIBS) @rm -f *.o @rm -f *_svctab.c $(SVCTOBJ): cp $(WEBTOBDIR)/svct/$(TARGET)_svctab.c . $(CC) $(CFLAGS) -I$(WEBTOB_INCDIR) -c $(TARGET)_svctab.c # clean: -rm -f *.o core
The following shows how to use Makefile.c.
#!/bin/ksh # program compile # #main Param=$1 case "$Param" in c) export COMP_TARGET=$2 make -f Makefile.c;; api) export COMP_TARGET=$2 make -f Makefile.api;; pc) export COMP_TARGET=$2 make -f Makefile.pc all;; clean) make -f Makefile.pc clean;; *) echo "Usage: $0 argument";; esac
The following is an example of compilation.
$ compile c wbsession $ compile c wbquery
Integrate Tmax by using the previous examples as follows.
Compile the WebtoB environment file.
$ wscfl –i apsl.m
Create a service table.
$ wsgst
Compile the client program.
$ compile c wbsession $ compile c wbquery
Compile the Tmax server program.
$ compile c svr2
Boot Tmax.
$ tmboot
Boot WebtoB.
$ wsboot
Use an HTML page, such as toupper.html, to view the execution result.
<html> <head> <title>wbGetQueryString</title> </head> <body> <form method=post action="/svct/wbsession"> <table width=370> <br> <tr> <td> input send Data</td> <td><input type=input name=name></td> <td><input type=submit value="submit"></td> </tr> </table> </form> </body> </html>