PUT/SET API
1. wbPutHdr
wbPutHdr sets the headers of a response.
The results generated by the WBAPI program are delivered to the client following the HTTP protocol. Each response sent to the client consists of a response header and response data. The wbPutHdr() function creates the response header and must be called before any function that writes the data field. This order is required to ensure that WBAPI executes properly.
-
Prototype
#include <wbapi.h> #include <atmi.h> int wbPutHdr(WBSVCINFO *rqst, char *key, char *value)
-
Return value
If the function executes successfully, it returns 1. If an error occurs, it returns -1.
-
Example
<wbputhdr.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 wbputhdr SVGNAME = webapg, MinProc = 1, MaxProc = 2, *SERVICE test SVRNAME = wbputhdr *URI wbapi Uri = "/svct/", Svrtype = WEBSTD *EXT htm MimeType = "text/html", SvrType = HTML
-
Compile the configuration file.
$wscfl –i wbputhdr.m
-
Create a service table.
$wsgst
-
Generate a source file. The following is an example WBAPI program that processes requests, named wbputhdr.c.
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/wbapi.h> test(WBSVCINFO *rqst) { char *header1; wbPutHdr(rqst, "Content-Type", "application/octet-stream"); header1 = wbGetHdr(rqst, "Content-Type"); wbPrint(rqst, "Response content-type : %s", header1); wbReturn(rqst, WBSUCCESS); }
-
Compile the C file created with WBAPI using the Makefile file.
$compile c wbputhdr
-
The following is the screen where the results are printed.
When you call the WBAPI service with a browser, you get the following result:
-
-
Related functions
wbPutIntHdr()
2. wbPutIntHdr
wbPutIntHdr sets the integer header in the response.
This function adds a header by setting the value of the specified header as an integer. It must be called before any function that writes data fields to ensure WBAPI executes properly.
To use wbPutIntHdr(), set the header’s name as the name
argument and its integer value as ivalue
. Note that wbPutIntHdr() will return an error if the specified header is not an integer.
wbPutIntHdr() will throw an error if set to a non-integer header.
-
Prototype
#include <wbapi.h> #include <atmi.h> int wbPutIntHdr(WBSVCINFO *rqst, char *name, int ivalue)
-
Return value
If the function executes successfully, wbPutIntHdr() returns 1. If an error occurs, it returns -1.
-
Example
<wbputinthdr.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 wbputinthdr SVGNAME = webapg, MinProc = 1, MaxProc = 2, *SERVICE test SVRNAME = wbputinthdr *URI wbapi Uri = "/svct/", S1vrtype = WEBSTD *EXT htm MimeType = "text/html", SvrType = HTML
-
Compile the configuration file.
$wscfl –i wbputinthdr.m
-
Create a service table.
$wsgst
-
Generate a source file. The following is an example WBAPI program that processes requests, named wbputinthdr.c.
#include <stdio.h> #include <usrinc/atmi.h> #include <usrinc/wbapi.h> test(WBSVCINFO *rqst) { int header2; wbPutIntHdr(rqst, "Retry-After", 5000); header2 = wbGetIntHdr(rqst, "Retry-After"); wbReturn(rqst, WBSUCCESS); }
-
Compile the C file created with WBAPI using the Makefile file.
$compile c wbputinthdr
-
The following is an example of the resulting output.
Calling the WBAPI service via Telnet produces the following result:
$telnet 61.77.153.5 7654 Trying 61.77.153.5... Connected to 61.77.153.5. Escape character is '^]'. GET /svct/test HTTP/1.1 Host: tmaxh1 HTTP/1.1 200 OK Date: Wed, 31 Oct 2001 07:46:20 GMT Server: WebtoB/3.0 Retry-After: 5000 Content-Type: text/html Content-Length: 0
-
-
Related functions
wbPutHdr()
3. wbSetStatus
wbSetStatus sets the HTTP status code for a response.
Normally, when the server successfully transmits data requested by the client, it sends a status code of 200 OK. If the requested data is missing, the server returns a 404 Not Found. While most standard status codes are handled internally by the web server, wbSetStatus allows you to specify a custom status code. For example, if the location of data has changed, you can use a redirection status code, like 302 Redirect, by setting the Location field.
wbSetStatus should be called before any other PUT functions to write the response header first. This order is necessary for WBAPI to execute properly.
The status
argument sets the HTTP status code for the response, while status_msg
allows you to customize the reason phrase following the status code. If status_msg
is set to NULL, the default reason phrase is used. When you set a specific status code using the wbSetStatus() function, a designated screen can be displayed to the client.
The wbSendError() function allows you to add a simple, user-defined message to an error response. In contrast, the wbSetStatus() function can be used to display a custom HTML-formatted message to the client. By setting the status code with wbSetStatus() and then specifying an HTML response using the PUT functions, you can present a fully formatted HTML message to the client.
-
Prototype
#include <wbapi.h> #include <atmi.h> int wbSetStatus(WBSVCINFO *rqst, int status, char *status_msg)
-
Return value
If the function is executed successfully, it returns 1. If an error occurs, it returns -1.
-
Example
<wbsetstatus.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 wbsetstatus SVGNAME = webapg, MinProc = 1, MaxProc = 2, *SERVICE test SVRNAME = wbsetstaus *URI wbapi Uri = "/svct/", S1vrtype = WEBSTD *EXT htm MimeType = "text/html", SvrType = HTML
-
Compile the configuration file.
$wscfl –i wbsetstatus.m
-
Create a service table.
$wsgst
-
Generate a source file. The following is an example WBAPI program that processes a request, named wbsetstatus.c.
#include<stdio.h> #include <usrinc/wbapi.h> #include <usrinc/atmi.h> test(WBSVCINFO *rqst) { wbSetStatus(rqst, 404, NULL); wbPrint(rqst, "<HTML><HEAD><TITLE>Not Found</TITLE></HEAD>"); wbPrint(rqst, "<BODY><H1>Sorry, File is not Found!!!</H1>"); wbPrint(rqst, "</BODY></HTML>"); wbReturn(rqst, WBSUCCESS); }
-
Compile the C file created with WBAPI using the Makefile file.
$compile c wbsetstatus
-
The following is an example of the resulting output.
Calling the WBAPI service with Telnet produces the following result:
$telnet 61.77.153.5 7654 Trying 61.77.153.5... Connected to 61.77.153.5. Escape character is '^]'. GET /svct/test HTTP/1.1 Host: tmaxh1 HTTP/1.1 404 Date: Wed, 31 Oct 2001 07:58:40 GMT Server: WebtoB/3.0 Content-Type: text/html Content-Length: 99 <HTML><HEAD><TITLE>Not Found</TITLE></HEAD><BODY><H1>Sorry, File is not Found!!!</H1></BODY></HTML>
-
-
Related functions
wbSendError()
4. wbPutStr
wbPutStr outputs a string value.
This function outputs the data after processing the user’s request. Here, note that the output type for this function is specifically a string.
-
Prototype
#include <wbapi.h> #include <atmi.h> int wbPutStr(WBSVCINFO *rqst, char *value)
-
Return value
If the function is executed successfully, it returns 1. If an error occurs, it returns -1.
-
Example
<wbputstr.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 wbputstr SVGNAME = webapg, MinProc = 1, MaxProc = 2, *SERVICE test SVRNAME = wbputstr *URI wbapi Uri = "/svct/", S1vrtype = WEBSTD *EXT htm MimeType = "text/html", SvrType = HTML
-
Compile the configuration file.
$wscfl –i wbputstr.m
-
Create a service table.
$wsgst
-
Generate a source file. The following is an example WBAPI program that processes a request, named wbputstr.c.
#include<stdio.h> #include <usrinc/wbapi.h> #include <usrinc/atmi.h> test(WBSVCINFO *rqst) { wbPutStr(rqst, "this wbPutStr() test!!<br>"); wbPutStr(rqst, "this wbPutStr() test!!<br>"); wbPutStr(rqst, "this wbPutStr() test!!\n"); wbReturn(rqst, WBSUCCESS); }
-
Compile the C file created with WBAPI using the Makefile file.
$compile c wbputstr
-
The following is the screen where the results are printed.
When you call the WBAPI service with a browser, you get the following result:
-
-
Related functions
wbPut(), wbPrint()
5. wbPut
wbPut outputs data of a specific size.
While it has similar functionality to wbPutStr(), the output data type is not a string; instead, it outputs data according to the size specified by the len
argument.
-
Prototype
#include <wbapi.h> #include <atmi.h> int wbPut(WBSVCINFO *rqst, char *value, int len)
-
Return value
If the function is executed successfully, it returns 1. If an error occurs, it returns -1.
-
Example
<wbput.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 wbput SVGNAME = webapg, MinProc = 1, MaxProc = 2, *SERVICE test SVRNAME = wbput *URI wbapi Uri = "/svct/", S1vrtype = WEBSTD *EXT htm MimeType = "text/html", SvrType = HTML
-
Compile the configuration file.
$wscfl –i wbput.m
-
Create a service table.
$wsgst
-
Generate a source file. The following is an example WBAPI program that processes requests, named wbput.c.
#include <stdio.h> #include <usrinc/wbapi.h> #include <usrinc/atmi.h> test(WBSVCINFO *rqst) { wbPut(rqst, "this wbPut() test!!", 19); wbPut(rqst, "this wbPut() test!!",10); wbPut(rqst, "this wbPut() test!!", 5); wbReturn(rqst, WBSUCCESS); }
-
Compile the C file created with WBAPI using the Makefile file.
$compile c wbput
-
The following is the screen where the results are printed.
When you call the WBAPI service with a browser, you get the following result:
-
-
Related functions
wbPutStr(), wbPrint()
6. wbPrint
wbPrint prints user-defined content.
This function can be easily understood by comparing it to the printf() function in C. Developed to replace printf(), wbPrint() uses a similar function prototype, allowing users to insert desired text in quotes ("") and use format specifiers like %s
, %d
, and %f
to output corresponding variables. Line feed characters can also be used in the same manner. Additionally, existing printf() calls written in C can be easily transitioned to wbPrint() by simply changing the function name.
-
Prototype
#include <wbapi.h> #include <atmi.h> int wbPrint(WBSVCINFO *rqst, const char * fmt, …..)
-
Return value
If the function is executed successfully, it returns 1. If an error occurs, it returns -1.
-
Example
<wbprint.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 wbprint SVGNAME = webapg, MinProc = 1, MaxProc = 2, *SERVICE test SVRNAME = wbprint *URI wbapi Uri = "/svct/", S1vrtype = WEBSTD *EXT htm MimeType = "text/html", SvrType = HTML
-
Compile the configuration file.
$wscfl –i wbprint.m
-
Create a service table.
$wsgst
-
Generate a source file. The following is an example WBAPI program that processes a request, named wbprint.c.
#include <stdio.h> #include <usrinc/wbapi.h> #include <usrinc/atmi.h> test(WBSVCINFO *rqst) { wbPrint(rqst, "<HTML>\n"); wbPrint(rqst, "<BODY>\n"); wbPrint(rqst, "Input QueryString :<INPUT TYPE = text NAME=query VALUE=\"\">"); wbPrint(rqst, "<INPUT TYPE = submit VALUE=\"submit\">\n"); wbPrint(rqst, "<H1>srting : %s</h1><br>","example"); wbPrint(rqst, "<H1>character : %c</h1><br>",'e'); wbPrint(rqst, "<H1>inteter : %d</h1><br>",100); wbPrint(rqst, "</FORM>\n"); wbPrint(rqst, "</BODY>\n"); wbPrint(rqst, "</HTML>\n"); wbReturn(rqst, WBSUCCESS); }
-
Compile the C file created with WBAPI using the Makefile file.
$compile c wbprint
-
The following is the screen where the results are printed.
When you call the WBAPI service with a browser, the following screen will be displayed:
-
-
Related functions
wbPutStr(), wbPut()
7. wbPutFile
wbPutFile is a function designed for file downloads. It reads specified files and sends them to the browser.
This functionality is essential when the server needs to send a specific file or share data in response to a client’s request. WebtoB provides wbPutFile() to facilitate this capability by allowing users to specify a physical path. The function then retrieves the file located at that path and sends it to the client.
-
Prototype
#include <wbapi.h> #include <atmi.h> int wbPutFile(WBSVCINFO *rqst, char *path)
-
Return value
If the function is executed successfully, it returns 1. If an error occurs, it returns -1.
-
Example
<wbputfile.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 wbputfile SVGNAME = webapg, MinProc = 1, MaxProc = 2, *SERVICE test SVRNAME = wbputfile *URI wbapi Uri = "/svct/", S1vrtype = WEBSTD *EXT htm MimeType = "text/html", SvrType = HTML
-
Compile the configuration file.
$wscfl –i wbputfile.m
-
Create a service table.
$wsgst
-
Generate source files.
Below is an example of an html file that sends a request.
<putfile.html>
<html> <head><title> wbPutFile test </title></head> <body> <H2>wbPutFile</H2> <form action= "/svct/test" method=post> <input type= submit value=" Download "> </form> </body> </html>
Below is an example WBAPI program that processes the request.
<putfile.c>
#include<stdio.h> #include <usrinc/wbapi.h> #include <usrinc/atmi.h> test(WBSVCINFO *rqst) { char line[50]; memset(line, 0x00, sizeof(line)); wbPutHdr(rqst, "content-type", "application/octet-stream"); sprintf(line, "attachment; filename=%s", "session.c"); wbPutHdr(rqst, "content-disposition", line); wbPutFile(rqst, "/user2/haninho/webtob/session.c"); wbReturn(rqst, WBSUCCESS); }
-
Compile the C file created with WBAPI using the Makefile file.
$compile c wbputfile
-
The following is the screen where the results are printed.
When a user requests a WBAPI service through a browser, a prompt appears asking whether to download the file.
A dialog appears for setting the downLoad location:
The file is downloaded to the specified path.
-
-
Related functions
wbPutPartialFile()
8. wbPutPartialFile
wbPutPartialFile is a function designed for file downloads. It reads a specific portion of a file and sends it to the browser, starting from a specified offset up to the defined size. If the size is set to 0, it will read from the offset to the end of the file.
This function offers similar functionality to the previously explained wbPutFile(), but it is specifically intended for transferring a portion of a file. In scenarios where the client experiences a connection loss due to network instability or other issues while receiving a file, using wbPutPartialFile allows for a more efficient and faster transfer. Rather than restarting the download from the beginning, the client can resume the transfer from the point where it was interrupted.
-
Prototype
#include <wbapi.h> #include <atmi.h> int wbPutPartialFile(WBSVCINFO *rqst,char *path,int offset,int sz)
-
Return value
If the function is executed successfully, it returns 1. If an error occurs, it returns -1.
-
Example
<wbpartial.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 wbpartial SVGNAME = webapg, MinProc = 1, MaxProc = 2, *SERVICE test SVRNAME = wbpartial *URI wbapi Uri = "/svct/", S1vrtype = WEBSTD *EXT htm MimeType = "text/html", SvrType = HTML
-
Compile the configuration file.
$wscfl –i wbpartial.m
-
Create a service table.
$wsgst
-
Generate source files.
Below is an example of an html file that sends a request.
<wbpartial.html>
<html> <head><title> wbPutPartialFile test </title></head> <body> <H2>wbPutPartialFile</H2> <form action= "/svct/test" method=post> <input type= submit value=" Download "> </form> </body> </html>
Below is an example WBAPI program that processes the request.
<wbpartial.c>
#include<stdio.h> #include <usrinc/wbapi.h> #include <usrinc/atmi.h> test(WBSVCINFO *rqst) { char line[50]; memset(line, 0x00, sizeof(line)); wbPutHdr(rqst, "content-type", "application/octet-stream"); sprintf(line, "attachment; filename=%s", "session.c"); wbPutHdr(rqst, "content-disposition", line); wbPutPartialFile(rqst, "/user2/haninho/webtob/session.c",100, 100); wbReturn(rqst, WBSUCCESS); }
-
Compile the C file created with WBAPI using the Makefile file.
$compile c wbpartial
-
The following is the screen where the results are printed.
When a user requests a WBAPI service through a browser, a prompt appears asking whether to download the file.
A dialog appears for setting the download location.
If the file is downloaded successfully to the specified size, it indicates that the function has executed correctly.
-
-
Related functions
wbPutFile()