SEND API
1. wbFlush
wbFlush records all contents of the current buffer, providing the same functionality as the fflush() function C. It writes all data from the current system buffer to the screen.
-
Prototype
#include <wbapi.h> #include <atmi.h> int wbFlush(WBSVCINFO *rqst)
-
Return value
If the function is executed successfully, it returns 1. If an error occurs, it returns -1.
-
Example
<flush.m>
*DOMAIN webtob1 *NODE tmaxh1 WEBTOBDIR="/user2/haninho/webtob", SHMKEY = 54777, DOCROOT="/user2/haninho/webtob/docs", APPDIR="/user2/haninho/webtob/ap", PORT = “7654” *SVRGROUP htmlg NODENAME = "tmaxh1", SvrType = HTML webapg NODENAME = "tmaxh1", SVRTYPE = WEBSTD *SERVER html SVGNAME = htmlg, MinProc = 1, MaxProc =2 flush SVGNAME = webapg, MinProc = 1, MaxProc = 2, *SERVICE test SVRNAME = flush test2 SVRNAME = flush *URI wbapi Uri = "/svct/", Svrtype = WEBSTD *EXT htm MimeType = "text/html", SvrType = HTML
-
Compile the configuration file.
$wscfl –i flush.m
-
Create a service table.
$wsgst
-
Generate a source file. The following is an example WBAPI program that processes a request, named flush.c.
#include <stdio.h> #include "../usrinc/atmi.h" #include "../usrinc/wbapi.h" test(WBSVCINFO *rqst) { wbPrint(rqst, "<HTML>\n"); wbFlush(rqst); wbPrint(rqst,"<H1>Tmax soft</H1> \n"); wbFlush(rqst); wbPrint(rqst,"<h2>Tmax soft</h2> \n"); wbFlush(rqst); wbPrint(rqst, "</HTML>\n"); wbReturn(rqst, WBSUCCESS); } test2(WBSVCINFO *rqst) { wbPrint(rqst, "<HTML>\n"); wbPrint(rqst,"<H1>Tmax soft</H1> \n"); wbPrint(rqst,"<h2>Tmax soft</h2> \n"); wbPrint(rqst, "</HTML>\n"); wbReturn(rqst, WBSUCCESS); }
-
Compile the C file created with WBAPI using the Makefile file.
$compile c flush
-
The following is an example of the resulting output.
If you request a WBAPI service test via Telnet, the following is displayed.
wbFlush() used. HTTP/1.1 200 OK Date: Thu, 01 Nov 2001 04:43:30 GMT Server: WebtoB/3.0 Content-Type: text/html Transfer-Encoding: chunked 7 <HTML> 14 <H1>Tmax soft</H1> 14 <h2>Tmax soft</h2> 8 </HTML> 0
When requesting the WBAPI service test2 via Telnet, the following is displayed.
HTTP/1.1 200 OK Date: Thu, 01 Nov 2001 04:43:52 GMT Server: WebtoB/3.0 Content-Type: text/html Content-Length: 55 <HTML> <H1>Tmax soft</H1> <h2>Tmax soft</h2> </HTML>
-
2. wbSendError
wbSendError displays a specific message to the client when the status code indicates an error.
wbSendError() can display a simple message set in the argument msg
, which is appended to the original message according to the status code set in the argument status
. The set msg
is a plain text message, not formatted in HTML. If msg
is set to NULL, only the basic message is output.
When using the wbSendError() function, the browser screen cannot be refreshed. Therefore, after calling wbSendError(), any subsequent output functions, such as wbPrint(), will be ineffective. To send additional messages to the client in HTML format, it is recommended to use the wbSetStatus() function instead.
While it is impossible to refresh the screen when wbSendError() is in use, the function does not internally call wbReturn(). Therefore, you must explicitly call wbReturn() to exit.
The message set in the wbSendError() function may not display in some browsers, depending on their configuration. For example, if Microsoft Internet Explorer is set to display HTTP error messages, WebtoB may create an HTML page with the message specified in wsSendError(); however, Internet Explorer will display its own pre-configured HTML error page based on the status code instead.
-
Prototype
#include <wbapi.h> #include <atmi.h> int wbSendError(WBSVCINFO *rqst, int status, char *msg)
-
Return value
If the function is executed successfully, it returns 1. If an error occurs, it returns -1.
-
Example
<senderror.m>
*DOMAIN webtob1 *NODE tmaxh1 WEBTOBDIR="/user2/haninho/webtob", SHMKEY = 54777, DOCROOT="/user2/haninho/webtob/docs", APPDIR="/user2/haninho/webtob/ap", PORT = “7654” *SVRGROUP htmlg NODENAME = "tmaxh1", SvrType = HTML webapg NODENAME = "tmaxh1", SVRTYPE = WEBSTD *SERVER html SVGNAME = htmlg, MinProc = 1, MaxProc =2 senderror SVGNAME = webapg, MinProc = 1, MaxProc = 2, *SERVICE test SVRNAME = senderror *URI wbapi Uri = "/svct/", Svrtype = WEBSTD *EXT htm MimeType = "text/html", SvrType = HTML
-
Compile the configuration file.
$wscfl –i senderror.m
-
Create a service table.
$wsgst
-
Generate a source file. The following is an example WBAPI program that processes a request, named senderror.c.
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/wbapi.h> test(WBSVCINFO *rqst) { wbPrint(rqst, "<HTML>\n"); wbPrint(rqst, "<HEAD><TITLE>wbSendError Test</TITLE> </HEAD>\n"); wbPrint(rqst, "<BODY>\n"); wbPrint(rqst, "<H1>Not Printed</H1>\n"); wbPrint(rqst, "</BODY>\n"); wbPrint(rqst, "</HTML>\n"); wbSendError(rqst, 404, "File is not exist"); wbReturn(rqst, WBSUCCESS); }
-
Compile the C file created with WBAPI using the Makefile file.
$compile c senderror
-
The following is the screen where the results are printed.
If you request the WBAPI service test with a browser, you will get the following result.
For Internet Explorer, you can see these results by unchecking [Tools] > [Internet Options] > [Advanced] > [Show HTTP error messages].
-
-
Related functions
wbSetStatus()
3. wbSendRedirect
wbSendRedirect sends a response to a specified address, setting both the status code and location header accordingly. The address can be specified as either a relative or an absolute path; if setting an absolute path, begin it with "http://".
When using the wbSendRedirect() function, you cannot refresh the screen. Additionally, since wbSendRedirect() does not internally call wbReturn(), you must explicitly call wbReturn() to complete the process.
-
Prototype
#include <wbapi.h> #include <atmi.h> int wbSendRedirect(WBSVCINFO *rqst, char *location);
-
Return value
If the function is executed successfully, it returns 1. If an error occurs, it returns -1.
-
Example
<redirect.m>
*DOMAIN webtob1 *NODE tmaxh1 WEBTOBDIR="/user2/haninho/webtob", SHMKEY = 54777, DOCROOT="/user2/haninho/webtob/docs", APPDIR="/user2/haninho/webtob/ap", PORT = “7654” *SVRGROUP htmlg NODENAME = "tmaxh1", SvrType = HTML webapg NODENAME = "tmaxh1", SVRTYPE = WEBSTD *SERVER html SVGNAME = htmlg, MinProc = 1, MaxProc =2 redirect SVGNAME = webapg, MinProc = 1, MaxProc = 2, *SERVICE test SVRNAME = redirect *URI wbapi Uri = "/svct/", Svrtype = WEBSTD *EXT htm MimeType = "text/html", SvrType = HTML
-
Compile the configuration file.
$wscfl –i redirect.m
-
Create a service table.
$wsgst
-
Generate a source file. The following is an example WBAPI program that handles requests, named redirect.c.
#include <stdio.h> #include "../usrinc/atmi.h" #include "../usrinc/wbapi.h" test(WBSVCINFO *rqst) { wbSetStatus(rqst, 302, NULL); wbSendRedirect(rqst, "http://www.tmax.co.kr"); wbReturn(rqst, WBSUCCESS); }
-
Compile the C file created with WBAPI using the Makefile file.
$compile c redirect
-
The following is the screen where the results are printed.
When you request a WBAPI service with a browser, you will get the following result:
-
4. wbReturn
wbReturn signals the return of a WBAPI.
It signals the end of a WBAPI function, similar to the return statement in C. At the end of each WBAPI program, wbReturn() must be called to terminate the requested service. When wbReturn() executes successfully, it returns WBSUCCESS. If it encounters an error, it may return WBEXIT, WBDOWN, WBERROR, or WBFAIL, depending on the specific situation. Using an incorrect return value may lead to issues within the program, so be sure to use wbReturn() as intended.
The following values can be used as the rval
argument:
Argument | Description |
---|---|
[WBSUCCESS] |
The service was terminated successfully. |
[WBEXIT] |
The service was terminated abnormally. If you set this value in |
[WBDOWN] |
The service was terminated abnormally. Setting this value in Terminating the server process using [WBDOWN] has the same result as terminating the server process using “wsdown –S”. |
[WBERROR] |
The service was terminated abnormally. If you set this value in the Additionally, by returning [WBERROR], you can display a custom user-defined screen to the client. This can be done using the PUT series of functions within the current API service to render the user-defined screen in the client’s browser. |
[WBFAIL] |
The service was terminated abnormally. If you set this value in the |
-
Prototype
#include <wbapi.h> #include <atmi.h> wbReturn(WBSVCINFO *rqst, int rval)
-
Return value
If the function is executed successfully, it returns 1. If an error occurs, it returns -1.
-
Example
<return.m>
*DOMAIN webtob1 *NODE tmaxh1 WEBTOBDIR="/user2/haninho/webtob", SHMKEY = 54777, DOCROOT="/user2/haninho/webtob/docs", APPDIR="/user2/haninho/webtob/ap", PORT = “7654” *SVRGROUP htmlg NODENAME = "tmaxh1", SvrType = HTML webapg NODENAME = "tmaxh1", SVRTYPE = WEBSTD *SERVER html SVGNAME = htmlg, MinProc = 1, MaxProc =2 return SVGNAME = webapg, MinProc = 1, MaxProc = 2, *SERVICE test SVRNAME = return test2 SVRNAME = return *URI wbapi Uri = "/svct/", Svrtype = WEBSTD *EXT htm MimeType = "text/html", SvrType = HTML
-
Compile the configuration file.
$wscfl –i return.m
-
Create a service table.
$wsgst
-
Generate a source file. The following is an example WBAPI program that processes a request, named return.c.
#include <stdio.h> #include "../usrinc/atmi.h" #include "../usrinc/wbapi.h" test(WBSVCINFO *rqst) { wbPrint(rqst, "<HTML>\n"); wbPrint(rqst,"<H1>Tmax soft</H1> \n"); wbPrint(rqst,"<h2>Tmax soft</h2> \n"); wbPrint(rqst, "</HTML>\n"); wbReturn(rqst, WBSUCCESS); } test2(WBSVCINFO *rqst) { wbPrint(rqst, "<HTML>\n"); wbPrint(rqst,"<H1>Tmax soft</H1> \n"); wbPrint(rqst,"<h2>Tmax soft</h2> \n"); wbPrint(rqst, "</HTML>\n"); wbReturn(rqst, WBFAIL); }
-
Compile the C file created with WBAPI using the Makefile file.
$compile c return
-
The following is the screen where the results are printed.
When you request a WBAPI service with a browser, you get the following result:
wbReturn(rqst, WBSUCCESS)
When you request a WBAPI service with a browser, you get the following result:
wbReturn(rqst, WBFAIL)
-