The qDecoder Project

qDecoder Function Reference



Query and Cookie Handling Functions

qDecoder()

Syntax:int qDecoder(void);
Function:Interprets encoded query strings and stores them in the linked-list. COOKIE, GET, POST(including multipart/form-data encoding) are supported.
Return:In case of success, returns the number of received arguments. In case of failure, return -1.
Note:The parsing sequence is (1)COOKIE (2)GET (3)POST. Thus if same query names (which are sent by different method) exist, qValue() will return the value of COOKIE.

This function, qDecoder(), is called automatically when you use qValue() or related functions, so you do not need to call directly.

In case of multipart/form-data encoding(used for file uploading), the variables of "variable_name.length", "variable_name.contenttype" and "variable_name.name" are automatically inserted. The number of bytes of data is stored in "variable_name.length", and the content type of data is stored in "variable_name.contenttype" and the file names(file name itself, path information will be removed) transmitted by users are stored in "variable_name.name". (/reference/In%20case%20of%20"C:Data/reference/a.gif", only "/reference/a.gif" is stored.) In counter of return values, a total of 4 lists are stored but since the 4 lists are for one data, they are regarded as 1 list.
Example:Example 1: application/x-www-form-urlencoded (GET/POST Method) [HTML] <form method="post" action="https://qdecoder.org"> User ID <input type="text" name="userID"><br class="h3qerggmton60mpt5"> <input type="submit"> </form> [Parsed Queries] name = &#8220;userID&#8221; value = &#8220;character strings users input&#8221; [C] #include <stdio.h> #include &#8220;qDecoder.h&#8221; void main(void) { char *id; qContentType(&#8220;text/html&#8221;); id = qValue(&#8220;userID&#8221;); printf(&#8220;%s&#8221;, id); } Example 2: multipart/form-data [HTML] <form method="post" action="https://qdecoder.org" enctype="multipart/form-data"> User ID <input type="text" name="userID"><br class="h3qerggmton60mpt5"> Attachment <input type="file" name="binary"><br class="h3qerggmton60mpt5"> <input type="submit"> </form> [Parsed Queries] name = &#8220;userID&#8221; value = &#8220;character strings users input&#8221; name = &#8220;binary&#8221; value = &#8220;/reference/binary%20data%20of%20/reference/a.gif&#8221; name = &#8220;binary.length&#8221; value = &#8220;128&#8221; name = &#8220;binary.filename&#8221; value = &#8220;/reference/a.gif&#8221; [C] #include <stdio.h> #include <stdlib.h> #include &#8220;qDecoder.h&#8221; void main(void) { FILE *fp; char *userID; char *filedata, *filename; int filelength, i; qContentType(&#8220;text/plain&#8221;); userID = qValue(&#8220;userID&#8221;); filedata = qValue(&#8220;binary&#8221;); filelength = qiValue(&#8220;binary.length&#8221;); filename = qValue(&#8220;binary.filename&#8221;); fp = fopen(filename, &#8220;wb&#8221;); for(i = filelength; i &gt; 0; i&#8211;) fprintf(fp, &#8220;%c&#8221;, *(filedata++)); fclose(fp); printf(&#8220;%s : %s(%s bytes) saved.&#8221;, userID, filename, filelength); }

qValue()

Syntax:char *qValue(char *format, …);
Function:Finds out the value (COOKIE, GET, POST) for variable names at the linked-list and hands over the pointers.
Return:The pointer of the variable value if a variable name exists. NULL if there is no variable name.
Note:qValue() returns only the pointers of query index created by qDecoder().Accordingly, you should not free() the pointers received at qValue. The deallocation of allocated memory should be performed through the qFree() function (generally before the program is shut down).

Internally calls qDecoder if qDecoder() has not been called before.
Example:char *test; test = qValue(&#8220;VARIABLE NAME&#8221;); char *test; int i = 1; test = qValue(&#8220;COUNT.%d&#8221;, i);

qiValue()

Syntax:int qiValue(char *format, …);
Function:Same as that of qValue(). But this returns the value(numeric character string) after converting it into integers.
Return:In case of success, returns the integer value for the variable value (numericcharacter string). If a variable name does not exist or cannot be converted, returns 0.
Example:int test; test = qiValue(&#8220;VARIABLE NAME&#8221;); int test, i = 1; test = qValue(&#8220;COUNT.%d&#8221;, i);

qValueDefault()

Syntax:char *qValueDefault(char *defstr, char *format, …);
Function:This is a simple function of qValue() used for setting up a primary argument when there is no query.
Return:Same as that of qValue(). But this returns the pointer of defstr when there is no query.
Example:value = qValueDefault(&#8220;Seoul&#8221;, &#8220;COUNTRY&#8221;);

qValueNotEmpty()

Syntax:char *qValueNotEmpty(char *errmsg, char *format, …);
Function:Displays specified error messages by using the qError() function when there is no query or blank character strings ("") are returned.
Return:Same as qValue except that it has "error handling" within for NULL.
Example:value = qValueNotEmpty(&#8220;Enter country name&#8221;, &#8220;COUNTRY&#8221;);

qValueReplace()

Syntax:char *qValueReplace(char *mode, char *name, char *tokstr, char *word);
Function:Transposes tokens and character strings for the linked-list character strings.
Return:Transposed character-string pointers.
Note:Basically, qValueReplace() is the wrapping function of qStrReplace(). The difference is that the source character string is the query value (the value of the linked-list for names) in it, and the conversion can be directly done to the linked-list itself.
Accordingly, the usage of arguments of qValueReplace() is basically the same as that of qStrReplace().

The ‘name’ argument is the query name of the linked-list to be used as source character strings. And it is the source character string to be used when the corresponding value is transposed.

The ‘mode’ argument is a character string made up of two separate characters like "sr".

The first character defines the transposition method. ‘t’ or ‘s’ can be located in its place. ‘t’ stands for [t]oken. It compares the source character strings (the value character string of the linked-list for given names) using each character of the tokstr character string as a token and transposes the matching characters into a word character string. ‘s’ stands for [s]tring. It transposes into a word character string the tokstr matching character strings appearing inside the source string using the tokstr string itself as a token.

The second character stands for the recording type of the transposed character string. Eigher ‘n’ or ‘r’ can be used for it. ‘n’ stands for [n]ew. It makes the corresponding pointer returned by storing the transposed result character string in a new memory space. Accordingly, the source string linked-list should be maintained in its original state, and the pertinent memory needs to be free() from the user’s aspect. ‘r’ stands for [r]eplace and means overwriting the transposition results on the linked-list itself. This is accomplished through the internal reallocation of memory.

As a result, there are 4 possible occasions in which the ‘mode’ argument can be assembled.

 Mode "tn" : [t]oken transposition & stores results in a [n]ew space and returns
 Mode "tr" : [t]oken transposition & [r]eplaces the linked-list itself
 Mode "sn" : [s]tring transposition & stores results in a [n]ew space and returns
 Mode "sr" : [s]tring transposition & [r]eplaces the linked-list itself
Example:Example 1) char *retstr, *mode; mode = qValue(&#8220;mode&#8221;); qContentType(&#8220;text/plain&#8221;); printf(&#8220;before %s : srcstr = %sn&#8221;, mode, qValue(&#8220;srcstr&#8221;)); retstr = qValueReplace(mode, &#8220;srcstr&#8221;, &#8220;hello&#8221;, &#8220;[?]&#8221;); printf(&#8220;after %s : srcstr = %sn&#8221;, mode, qValue(&#8220;srcstr&#8221;)); printf(&#8221; retstr = %snn&#8221;, retstr); if(mode[1] == &#8216;n&#8217;) free(retstr); return 0; Result &#8216;tn&#8217;) before tn : srcstr = hello world after tn : srcstr = hello world retstr = [?][?][?][?][?] w[?]r[?]d Result &#8216;tr&#8217;) before tr : srcstr = hello world after tr : srcstr = [?][?][?][?][?] w[?]r[?]d retstr = [?][?][?][?][?] w[?]r[?]d Result &#8216;sn&#8217;) before sn : srcstr = hello world after sn : srcstr = hello world retstr = [?] world Result &#8216;sr&#8217;) before sr : srcstr = hello world after sr : srcstr = [?] world retstr = [?] world

qGetFirstEntry()

Syntax:Q_Entry *qGetFirstEntry(void);
Function:Returns the first Q_Entry pointer of the linked-list.
Return:If there is stored data in linked-list, return Q_Entry first pointer. Or return NULL.
Note:This is used to acquire a root pointer when the linked-list used by qDecoder() is to be directly manipulated.
Example:Q_Entry *first; first = qGetFirstEntry();

qValueFirst()

Syntax:char *qValueFirst(char *format, …);
Function:Used for patching the arguments having an identical variable name inregular sequence.
Return:In case of success, returns the first variable-value pointer for the arguments having an identical variable name. If there is no variable name, returns NULL.
Example:char *list; for(list = qValueFirst(&#8220;checklist&#8221;); list; list = qValueNext()) { printf(&#8220;checklist = %s<br class="h3qerggmton60mpt5">n&#8221;, list); }

qValueNext()

Syntax:char *qValueNext(void);
Function:Continues to find out with qValueFirst().
Return:In case of success, returns the pointer of the variable value. If there is no more identical variable name, returns NULL.
Example:char *list; for(list = qValueFirst(&#8220;checklist&#8221;); list; list = qValueNext()) { printf(&#8220;checklist = %s<br class="h3qerggmton60mpt5">n&#8221;, list); }

qValueAdd()

Syntax:char *qValueAdd(char *name, char *format, …);
Function:Force to add given name and value to linked list.
Return:String pointer of added entry in linked-list.
Note:If same name exists, it’ll be replaced.
Example:qValueAdd(&#8220;NAME&#8221;, &#8220;Seung-young Kim&#8221;); name = qValue(&#8220;NAME&#8221;);

qValueRemove()

Syntax:void qValueRemove(char *format, …);
Function:Remove entry from linked list.
Example:qValueRemove(&#8220;NAME&#8221;);

qValueType()

Syntax:char qValueType(char *format, …);
Function:Returns type(Cookie, GET, POST) of query.
Return:Cookie `C`, Get method `G`, Post method `P`, New data(qValueAdd)  `N`, Not found `-`.
Example:switch(qValueType(name)) { case &#8216;C&#8217; : { cookie_cnt++; break; } case &#8216;G&#8217; : { get_cnt++; break; } case &#8216;P&#8217; : { post_cnt++; break; } case &#8216;N&#8217; : { new_cnt++; break; } }

qCookieSet()

Syntax:void qCookieSet(char *name, char *value, int exp_days, char *path, char *domain, char *secure);
Function:Sets up those cookies that correspond to name=value.
Note:When cookies are set up through qCookieSet(), the point of time when values are handed over through qValue() is when the next program is called. In some implementations, however, cookies need to be set up for the simplicity of logic while, at the same time, this needs to be applied to other routines. In this case, qValueAdd() can prevent the alteration of logic and the waste of additional codes by adding values to the cookie linked-list. But with regard to qCookieSet(), setting up cookies at clients (browsers) does not succeed always. Thus, users should be careful when using qValueAdd().

This should be used before qContentType() is called.
Example:char *name = &#8220;NAME&#8221;, *value = &#8220;Kim&#8221;; // Apply the NAME=Kim information in the current domain and directory for 30 days. qCookieSet(name, value, 30, NULL, NULL, NULL); // Apply the NAME=Kim information to the &#8220;/&#8221; directory of &#8220;ANYTHING.qdecoder.org&#8221; // until the browser is shut down. qCookieSet(name, value, 0, &#8220;/&#8221;, &#8220;.qdecoder.org&#8221;, NULL); // As for the followings, cookies will be set up only when security // requirements are satisfied. qCookieSet(name, value, 0, NULL, NULL, &#8220;SECURE&#8221;); // As for the followings, you can remove cookies. qCookieSet(name, &#8220;&#8221;, -1, NULL, NULL, NULL);

qCookieRemove()

Syntax:void qCookieRemove(char *name, char *path, char *domain, char *secure);
Function:Remove cookie from client(browser).
Note:The arguments(path, domain, secure) must be exactly same as the arguments of qCookieSet().

When cookies are removed through qCookieRemove(), the point of time when values in linked-list removed is when the next program is called. In some implementations, however, cookies need to be removed for the simplicity of logic while, at the same time, this needs to be applied to other routines. In this case, qValueRemove() can prevent the alteration of logic and the waste of additional codes by removing values to the linked-list. But with regard to qCookieRemove(), removing cookies at clients (browsers) does not succeed always. Thus, users should be careful when using qValueRemove().
Example:qCookieSet(&#8220;NAME&#8221;, &#8220;VALUE&#8221;, 0, NULL, NULL, NULL); qCookieRemove(&#8220;NAME&#8221;, NULL, NULL, NULL); qCookieSet(&#8220;NAME&#8221;, &#8220;VALUE&#8221;, 0, &#8220;/&#8221;, NULL, NULL); qCookieRemove(&#8220;NAME&#8221;, &#8220;/&#8221;, NULL, NULL); qCookieSet(&#8220;NAME&#8221;, &#8220;VALUE&#8221;, 0, &#8220;/&#8221;, &#8220;www.qdecoder.org&#8221;, NULL); qCookieRemove(&#8220;NAME&#8221;, &#8220;/&#8221;, &#8220;www.qdecoder.org&#8221;, NULL);

qCookieValue()

Syntax:char *qCookieValue(char *format, …);
Function:Return cookie value.
Return:The pointer of the cookie value if a cookie name exists. NULL if there is no cookie name.
Example:char *cookie; cookie = qCookieValue(&#8220;NAME&#8221;); if(cookie == NULL) qError(&#8220;Cookies are not set.&#8221;);

qPrint()

Syntax:int qPrint(void);
Function:Displays all the arguments transmitted for the purpose of debugging programs.
Return:The number of arguments.
Example:qPrint();

qFree()

Syntax:void qValueAdd(char *name, char *value);
Function:Deallocates the allocated memory by qDecoder().
Note:Please refer qFreeAll() too.
Example:qFree();


Session Functions

qSession()

Syntax:int qSession(char *repository);
Function:Start Session.
Return:New session 1, else 0.
Note:To use session, you must call qSession() at the start. qSession() stores 32 bytes session id to client using cookie, then stores session data to server side. By default, session data will be expired in 1800 seconds since last access. You can adjust this period by using qSessionSetTimeout().

To use session on clients which does not support cookie such like WAP phone.
add QSESSIONID into your link below.

http://domain/application?QSESSIONID=ab77bbb49dd61cd510db121a948ab4d9&other;=arguments

qSession() will store default session values below.

 _Q_SESSIONID   : Session ID (ex: ab77bbb49dd61cd510db121a948ab4d9)
 _Q_CREATED-GMT : Created GMT Time (ex: Thu, 19-Jul-2001 21:50:19 GMT)
 _Q_CREATED     : Created Time (ex: 995579419)
 _Q_CONNECTIONS : Connection Count (ex: 15)
 _Q_INTERVAL    : Expire Period/Seconds (ex: 1800)

Session data is stored in filesystem(unix: "/tmp", win32: "C:WindowsTemp").
You can change storage path using argument ‘repository’ when you call qSession(). qSession() generates "qsession-" prefixed files in session storage and manage automatically. (In case of WIN32 environment, the session files in repository are not managed automatically, so you would better to clean periodically repository)

Session data will be stored when qSessionFree(), qSessionSave() or qFreeAll() is called.
Example:qSession(NULL); // use default storage qSession(&#8220;/tmp&#8221;); // use /tmp for session storage

qSessionAdd()

Syntax:char *qSessionAdd(char *name, char *format, …);
Function:Add session value.
Return:Stored String pointer of value.
Example:qSessionAdd(&#8220;name&#8221;, &#8220;qDecoder&#8221;); qSessionAdd(&#8220;cginame&#8221;, &#8220;%s&#8221;, qCGIname());

qSessionAddInteger()

Syntax:int qSessionAddInteger(char *name, int valueint);
Function:Add session value of integer type.
Return:Stored integer value.
Example:qSessionAddInteger(&#8220;count&#8221;, 32);

qSessionUpdateInteger()

Syntax:int qSessionUpdateInteger(char *name, int plusint);
Function:Update session value of integer type.
Return:Updated integer value.

qSessionValue()

Syntax:char *qSessionValue(char *format, …);
Function:Return session value.
Return:Success pointer of value string, Fail NULL.
Example:char *value; value = qSessionValue(&#8220;name&#8221;); value = qSessionValue(&#8220;%d.name&#8221;, i);

qSessionValueInteger()

Syntax:int qSessionValueInteger(char *format, …);
Function:Return session value of integer type.
Return:Success integer of value, Fail 0.
Example:int value; value = qSessionValueInteger(&#8220;count&#8221;);

qSessionRemove()

Syntax:void qSessionRemove(char *format, …);
Function:Remove session variable.
Example:qSessionRemove(&#8220;name&#8221;); qSessionRemove(&#8220;%d.name&#8221;, i);

qSessionGetID()

Syntax:char *qSessionGetID(void);
Function:Return current session id.
Return:String pointer of session id(32bytes).
Example:char *sessionid; char *sessionidstr[32+1]; sessionid = qSessionGetID(); strcpy(sessionidstr, sessionid);

qSessionGetCreated()

Syntax:time_t qSessionGetCreated(void);
Function:Return session created time in seconds.
Return:Value of created time in seconds since 0 hours, 0 minutes, 0 seconds, January 1, 1970.
Example:time_t created; struct tm *gmtime; created = qSessionGetCreated(); gmtime = gmtime(&created;);

qSessionSetTimeout()

Syntax:void qSessionSetTimeout(time_t seconds);
Function:Change current session expiration period.
Return:New expiration period.
Note:By default, expiration period is 1800 seconds.
Example:qSessionSetTimeout((time_t)3600);

qSessionPrint()

Syntax:int qSessionPrint(void);
Function:Displays all the session variables for the purpose of debugging programs.
Return:The number of variables.
Example:qSessionPrint();

qSessionSave()

Syntax:void qSessionSave(void);
Function:Save session data immediately.
Note:qSessionSave() will be automatically called, when you callqSessionFree() at the end of program. If program can be quitted before qSessionFree(), you can use
qSessionSave() directly to protect session data.
Example:qSessionSave();

qSessionFree()

Syntax:void qSessionFree(void);
Function:Save session data and deallocate memories.
Example:qSessionFree();

qSessionDestroy()

Syntax:void qSessionDestroy(void);
Function:Destroy current session.
Example:qSessionDestroy();


Configuration File Parsing Functions

qfDecoder()

Syntax:Q_Entry *qfDecoder(char *filename);
Function:Reads file and stores in the linked-list. (no limitations to the line length of files)
Return:The first record pointer of the linked-list, NULL in case of failure.
Note:Reads the file of the following format and stores them in the linked-list.

—- test.conf —-
# this is comment.
name  = Seung-young Kim
age   = 30
addr  = Korea
——————-

Regarded as explanatory notes, those lines starting with sharps(#) are not interpreted.
Example:Q_Entry *first; first = qfDecoder(&#8220;test.conf&#8221;); if(first == NULL) qError(&#8220;File not found.&#8221;);

qfValue()

Syntax:char *qfValue(Q_Entry *first, char *format, …);
Function:Acquires the variable value of variable names.
Return:In case of success, returns the pointer of the variable value. In case of failure, returns NULL.
Example:char *value; value = qfValue(first, &#8220;name&#8221;);

qfiValue()

Syntax:int qfiValue(Q_Entry *first, char *format, …);
Function:Converts the variable values into integers and hands them over.
Return:In case of success, reurns the integer value for the variable value (numericcharacter strings). When a variable name does not exist or the pertinent value cannot be convertedinto integers, returns 0.
Example:int count; count = qfiValue(first, &#8220;count&#8221;);

qfValueFirst()

Syntax:char *qfValueFirst(Q_Entry *first, char *format, …);
Function:Used for patching the arguments having an identical variable name inregular sequence.
Return:In case of success, returns the first variable-value pointer for the arguments having an identical variable name. If there is no variable name, returns NULL.
Example:char *list; for(list = qfValueFirst(&#8220;checklist&#8221;); list; list = qfValueNext()) { printf(&#8220;checklist = %s<br class="h3qerggmton60mpt5">n&#8221;, list); }

qfValueNext()

Syntax:char *qfValueNext(void);
Function:Continues to find out with qfValueFirst().
Return:In case of success, returns the pointer of the variable value. If there is no more identical variable name, returns NULL.
Example:char *list; for(list = qfValueFirst(&#8220;checklist&#8221;); list; list = qfValueNext()) { printf(&#8220;checklist = %s<br class="h3qerggmton60mpt5">n&#8221;, list); }

qfPrint()

Syntax:int qfPrint(Q_Entry *first);
Function:Displays all the interpreted arguments for debugging programs.
Return:The number of arguments.
Example:qfPrint(first);

qfFree

Syntax:void qfFree(Q_Entry *first);
Function:Deallocates allocated memory.
Example:qfFree(first);


Configuration String Parsing Functions

qsDecoder()

Syntax:Q_Entry *qsDecoder(char *str);
Function:Reads string and stores in the linked-list. (no limitations to the line length of files)
Return:The first record pointer of the linked-list, NULL in case of failure.
Note:Reads the file of the following format and stores them in the linked-list.

—- test.conf —-
# this is comment.
name  = Seung-young Kim
age   = 30
addr  = Korea
——————-

Regarded as explanatory notes, those lines starting with sharps(#) are not interpreted.
Example:Q_Entry *FirstRecord; char *str=&#8221;name=Seung-young Kimnage=26naddr=Korea&#8221;; FirstRecord = qsDecoder(str);

qsValue()

Syntax:char *qsValue(Q_Entry *first, char *format, …);
Function:Acquires the variable value of variable names.
Return:In case of success, returns the pointer of the variable value. In case of failure, returns NULL.
Example:char *value; value = qsValue(first, &#8220;name&#8221;);

qsiValue()

Syntax:int qsiValue(Q_Entry *first, char *format, …);
Function:Converts the variable values into integers and hands them over.
Return:In case of success, reurns the integer value for the variable value (numericcharacter strings). When a variable name does not exist or the pertinent value cannot be convertedinto integers, returns 0.
Example:int count; count = qsiValue(first, &#8220;count&#8221;);

qsValueFirst()

Syntax:char *qsValueFirst(Q_Entry *first, char *format, …);
Function:Used for patching the arguments having an identical variable name inregular sequence.
Return:In case of success, returns the first variable-value pointer for the arguments having an identical variable name. If there is no variable name, returns NULL.
Example:char *list; for(list = qsValueFirst(&#8220;checklist&#8221;); list; list = qsValueNext()) { printf(&#8220;checklist = %s<br class="h3qerggmton60mpt5">n&#8221;, list); }

qsValueNext()

Syntax:char *qsValueNext(void);
Function:Continues to find out with qfValueFirst().
Return:In case of success, returns the pointer of the variable value. If there is no more identical variable name, returns NULL.
Example:char *list; for(list = qsValueFirst(&#8220;checklist&#8221;); list; list = qsValueNext()) { printf(&#8220;checklist = %s<br class="h3qerggmton60mpt5">n&#8221;, list); }

qsPrint()

Syntax:int qsPrint(Q_Entry *first);
Function:Displays all the interpreted arguments for debugging programs.
Return:The number of arguments.
Example:qsPrint(first);

qsFree

Syntax:void qsFree(Q_Entry *first);
Function:Deallocates allocated memory.
Example:qsFree(first);


SED: Context Generation Functions

qSedArgAdd()

Syntax:Q_Entry *qSedArgAdd(Q_Entry *first, char *name, char *format, …);
Function:Add a variable to argument list for use of qSedFile() and qSedStr().
Return:Pointer of argument list.
Example:Q_Entry *args; args = NULL; args = qSedArgAdd(args, &#8220;${NAME}&#8221;, &#8220;%s&#8221;, &#8220;Seung-young Kim&#8221;); /* recommanded */ args = qSedArgAdd(args, &#8220;${HOBBY}&#8221;, Playing Guitar&#8221;); /* not recommanded, but it works */

qSedArgAddDirect()

Syntax:Q_Entry *qSedArgAddDirect(Q_Entry *first, char *name, char *value);
Function:Add a variable with huge data to argument list for use of qSedFile() and qSedStr().
Return:First pointer of argument list.
Note:This function is same as qSedArg() except the value string is not formatted. So you can use value string which size is bigger than 1024-1 bytes.
Example:Q_Entry *args; char *hugevalue = &#8220;&#8230;huge&#8230;string&#8230;&#8221;; args = NULL; args = qSedArgAddDirect(args, &#8220;${NAME}&#8221;, hugevalue);

qSedArgPrint()

Syntax:int qSedArgPrint(Q_Entry *first);
Function:Displays all the variables for debugging programs.
Return:The number of arguments.
Example:qSedArgPrint(first);

qSedArgFree()

Syntax:void qSedArgFree(Q_Entry *first);
Function:Deallocates allocated memory by qSedArgAdd().
Example:qSedArgFree(first);

qSedFile()

Syntax:int qSedFile(Q_Entry *first, char *filename, FILE *fpout);
Function:Replaces specified symbols with defined character strings in files and displays them. And supports part of the SSI grammar.
Return:In case of success, returns 1. When files cannot be opened, returns 0.
Note:Plays a similar function to the SED command of UNIX systems.

—- ex) streamedit.html.in —-
<!–#include file="streamedit-header.html.in"–>
<p>Hi <b>${NAME}</b>.
<p>You got a really cool hobby.
<br>I’m sure that your hobby, <b>${HOBBY}</b>, can make your life more compatible.
<p>Bye 🙂
<!–#include file="streamedit-tailer.html.in"–>
———————

By utilizing qSedFile, CGI programming can be performed even without including HTML codes in the programs. Thus, UI-related debugging time can be reduced to a great extent, and the design and development works can be separately performed. Package products can be easily customized by users.
filename is an input(target) file while fpout stands for output streams. When you wish to display the results in files, open files in "w" and then, hand over the corresponding file pointers. And if you wish to display them on-screen, just specify stdout.

It interprets the SSI grammar. (Currently, only [an error occurred while processing this directive] is supported.) If there is the following lines in a document, the corresponding document is included in the display. And the replacement and SSI functions are valid for the included document. (Cascading)

<!–#include file="streamedit-header.html.in"–>

Note) The included file can be marked by relative paths on the basis of the location where CGI is executed. Or it may be marked by system absolute paths.

If you wish to use the SSI function only without replacing character strings, transmit the NULL value using the arg argument as follows:

ex) qSedFile(NULL, "streamedit.html.in", stdout);
Example:Q_Entry *args; char *name, *hobby; qContentType(&#8220;text/html&#8221;); name = qValueDefault(&#8220;Not Found&#8221;, &#8220;name&#8221;); hobby = qValueDefault(&#8220;Not Found&#8221;, &#8220;hobby&#8221;); args = NULL; args = qSedArgAdd(args, &#8220;${NAME}&#8221;, name); args = qSedArgAdd(args, &#8220;${HOBBY}&#8221;, hobby); if(qSedFile(args, &#8220;streamedit.html.in&#8221;, stdout) == 0) qError(&#8220;File not found.&#8221;); qSedArgFree(args);

qSedStr()

Syntax:int qSedStr(Q_Entry *first, char *srcstr, FILE *fpout);
Function:Plays same functions as qSedFile(), but input is done in character strings.
Return:Same as that of qSedFile().
Example:Q_Entry *args; char *sp; sp = &#8220;My name is ${NAME}.&#8221;; args = NULL; args = qSedArgAdd(args, &#8220;${NAME}&#8221;, &#8220;Seung-young Kim&#8221;); qSedStr(args, sp, stdout); qSedArgFree(args);


AWK: Pattern Scanning Functions

qAwkOpen()

Syntax:int qAwkOpen(char *filename, char separator);
Function:Opens files and sets up delimiters.
Return:In case of success, returns 1. When files cannot be opened, return 0.
Note:Plays a similar function to the AWK command of UNIX systems.

—- ex) /etc/passwd —-
shpark:x:1008:1000:Sang-hyun Park:/home/shpark:/bin/csh
teamwork:x:1011:1000:Seung-young Kim:/home/teamwork:/bin/csh
kikuchi:x:1015:2000:KIKUCHI:/home/kikuchi:/bin/csh
————————-
Example:qAwkOpen(&#8220;/etc/passwd&#8221;, &#8216;:&#8217;);

qAwkNext()

Syntax:int qAwkNext(char array[][1024]);
Function:Reads a line and stores it in an array given as a argument.
Return:In case of success, returns the number of fields. The end of files, -1.
Note:There is no limitation to the length of lines. But each field should not exceed 1024-1 bytes.
Example:char array[7][1024]; qAwkOpen(&#8220;/etc/passwd&#8221;, &#8216;:&#8217;); for( ; qAwkNext(array) &gt; 0; ) printf(&#8220;ID=%s, Name=%s&#8221;, array[0], array[5]); qAwkClose();

qAwkClose()

Syntax:Q_BOOL qAwkClose(FILE *fp);
Function:Closes open files.
Return:Success Q_TRUE. Otherwise Q_FALSE.
Example:qAwkClose();

qAwkStr()

Syntax:int qAwkStr(char array[][1024], char *str, char delim);
Function:Reads a string and stores it in an array given as a argument.
Return:returns the number of fields.
Note:There is no limitation to the length of lines. But each field should not exceed 1024-1 bytes.
Example:char *string = &#8220;root:*:0:0:Charlie &#038;:/root:/bin/csh&#8221;; char array[7][1024]; qAwkStr(array, string, &#8216;:&#8217;);


Search Key Words & Pattern Matching Functions

qArgMake()

Syntax:int qArgMake(char *str, char **qlist);
Function:Divides queries into tokens. The delimiters are generally space characters. And the redundant spaces between tokens and the spaces before and after queries are disregarded.
Return:The number of divided tokens.
Note:A group of functions related to search words classifies query character strings on the basis of spaces and double quotation marks(") and then, stores them in the lists. And it provides a group of functions connected with the matching tests and display of target character strings.


—- Example —-
Query Input: I am a "pretty girl"
—————–
     |  |
     V  V
—- qArgMake() —-
qlist[0] = I
qlist[1] = am
qlist[2] = a
qlist[3] = pretty girl
qlist[4] = NULL
Return: 4 (4 Tokens)
——————–
     |  |
     V  V
—- qArgPrint() —-
‘I’ (1 bytes)
‘am’ (2 bytes)
‘a’ (1 bytes)
‘pretty girl’ (11 bytes)
———————
     |  |
     V  V
—- qArgMatch() —-
Target String: Hi, I’m a pretty boy. Are you pretty girl?
               =  =   =             =       ===========
               0  0   2             2             3
Return: 3 (3 matches: qlist[0], qlist[2], qlist[3])
———————
     |  |
     V  V
—- qArgEmprint() —-
Target String..: Hi, I’m a pretty boy. Are you pretty girl?
Result………: Hi, I’m a pretty boy. Are you pretty girl?
                 =  =   =             =       ===========
                 1  2   3             4             5
Return: 5 (5 matches)
———————–
Example:char *query=&#8221;I am a &#8220;pretty girl&#8221;.&#8221;, *qlist[MAX_TOKENS]; int queries; queries = qArgMake(query, qlist);

qArgMatch()

Syntax:int qArgMatch(char *str, char **qlist);
Function:Performs token-matching tests without distinguishing lowercase/uppercase letters.
Return:Returns the number of tokens found in a specific character string.
Note:Counts only once the same tokens even if they are matched repeatedly. Refer to the return value of qArgemprint() for the total matching counts in a character string including repeated matchings. Being divided into a hundred parts by the total number of the tokens acquired at qArgMake(), these values can be used for calculating the search accuracy.
Example:int matches; matches = qArgMatch(&#8220;Hi, I&#8217;m a pretty boy. Are you pretty girl?&#8221;, qlist);

qArgEmprint()

Syntax:int qArgEmprint(int mode, char *str, char **qlist);
Function:Bold-prints the parts matched with tokens in a character string. This does not distinguish lowercase/uppercase letters.
Return:Returns the number of tokens found in a character string. And unlike qArgMatch(), this returns all the matching counts including repeated matchings.
Note:The mode value is same as that of qPrintf(). For a general purpose, 1 can be generally used.
Example:qArgEmprint(1, &#8220;Hi, I&#8217;m a pretty boy. Are you pretty girl?&#8221;, qlist);

qArgPrint()

Syntax:int qArgPrint(char **qlist);
Function:Displays all the tokens interpreted for debugging programs.
Example:qArgPrint(qlist);

qArgFree()

Syntax:void qArgFree(char **qlist);
Function:Deallocates qlist which memory is allocated to.
Example:qArgFree(qlist);


HTTP Response Functions

qContentType()

Syntax:void qContentType(char *mimetype);
Function:Prints MimeType.
Note:Executed only once even if it is called many times.
Example:qContentType(&#8220;text/html&#8221;); // when displaying HTML qContentType(&#8220;/reference/image/gif.jpg&#8221;); // when displaying the GIF image

qGetContentFlag()

Syntax:int qGetContentFlag(void);
Function:Check execution of qContentType().
Return:If qContentType() is executed before, returns 1. Or returns 0.
Example:if(qGetContentFlag() == 0) qCookieRemove(&#8220;NAME&#8221;, NULL, NULL, NULL);

qResetContentFlag()

Syntax:void qResetContentFlag(void);
Function:Sets the internal flag of qContentType() to the initial status.
Note:qContentType() is executed only once even if it is called many times. When you need to forcibly display it again, call qContentType() after executing qResetContentFlag().
Example:qContentType(&#8220;text/html&#8221;); &#8230;some business logic here&#8230; qResetContentFlag(); qContentType(&#8220;text/html&#8221;); &#8230;some business logic here&#8230; qResetContentFlag(); qContentType(&#8220;text/html&#8221;); &#8230;some business logic here&#8230;

qRedirect()

Syntax:void qRedirect(char *url);
Function:Jumps to a specific page using the Location: headers of HTTP.
Note:Since qRedirect uses the HTTP headers, qConteneType() should be the only command that streams out in the corresponding process.
Example:qRedirect(&#8220;/&#8221;);

qJavaScript()

Syntax:void qJavaScript(char *format, …);
Function:Print out some JavaScript code.
Note:It will print out below codes.

<script language="JavaScript">
YOUR CODES HERE
</script>
Example:qContentType(&#8220;text/html&#8221;); qJavaScript(&#8220;alert(&#8220;hello&#8221;);&#8221;);


Encoding/decoding Functions

qURLencode()

Syntax:char *qURLencode(char *str);
Function:Encodes character strings in URL.
Return:The character strings encoded in URL are returned with memory allocation. Deallocation(free) needs to be done by users.
Note:It does not encode ‘@’, ‘.’, ‘/’, ”, ‘-‘, ‘_’, ‘:’ characters.
Example:char *encstr; encstr = qURLencode(&#8220;Hello!&#8221;);

qURLdecode

Syntax:char *qURLdecode(char *str);
Function:Decodes the character string that is URL-encoded into %xx.
Return:Decoded string pointer.
Note:It stores decoded string into str directly.
Example:char *encstr; qURLdecode(encstr);

qMD5Str()

Syntax:char *qMD5Str(char *string);
Function:Calculate a message-digest fingerprint (checksum) for a string.
Return:String pointer of 32 bytes fingerprint.
Note:The return string pointer is declared as static inside the functions instead of being returned with memory allocation. This is to remove the inconvenience that users have to free() memory every tiem. Accordingly, it should be noted that the previous value is deleted whenever the functions are performed. And you should not modify or free() it directly.
Example:printf(&#8220;Hash Result = %s&#8221;, MD5Str(&#8220;Hello&#8221;)); [Result] Hash Result = 8b1a9953c4611296a827abf8c47804d7

qMD5File()

Syntax:char *qMD5File(char *string);
Function:Calculate a message-digest fingerprint (checksum) for a file.
Return:String pointer of 32 bytes fingerprint.
Note:The return string pointer is declared as static inside the functions instead of being returned with memory allocation. This is to remove the inconvenience that users have to free() memory every tiem. Accordingly, it should be noted that the previous value is deleted whenever the functions are performed. And you should not modify or free() it directly.
Example:printf(&#8220;Hash Result = %s&#8221;, MD5File(&#8220;qDecoder.tar.Z&#8221;)); [Result] Hash Result = 499589b930e48996a64317c79e6cc36b

qFnv32Hash()

Syntax:unsigned int qFnv32Hash(char *str, unsigned int max);
Function:This function will be released at 8.1R


String Handling Functions

qPrintf()

Syntax:int qPrintf(int mode, char *format, …);
Function:Usage is same as that of printf(). Checks whether the HTML tag is applied and performs automatic links.
Return:In case of success – returns the number of displayed bytes. In case of failure, returns EOF.
Note:The maximum size of the assembled strings should not exceed 10K(1024 * 10 – 1).

Mode 00 : Same as printf()
Mode 10  :Mode 0 + Convert

Mode 01 : Print HTML TAG
Mode 11 : Print HTML TAG + Convert

Mode 02 : Print HTML TAG + Auto Link
Mode 12 : Print HTML TAG + Auto Link + Convert

Mode 03 : Print HTML TAG + Auto Link(_top)
Mode 13 : Print HTML TAG + Auto Link(_top) + Convert
Mode 23 : Print HTML TAG + Auto Link(new window)
Mode 33 : Print HTML TAG + Auto Link(new window) + Convert

Mode 04 : Waste HTML TAG
Mode 14 : Waste HTML TAG + Convert

Mode 05 : Waste HTML TAG + Auto Link
Mode 15 : Waste HTML TAG + Auto Link + Convert

Mode 06 : Waste HTML TAG + Auto Link(_top)
Mode 16 : Waste HTML TAG + Auto Link(_top) + Convert
Mode 26 : Waste HTML TAG + Auto Link(new window)
Mode 36 : Waste HTML TAG + Auto Link(new window) + Convert

Convert : " "   -> " "
         "  "  -> "  "
         "   " -> "   "
         "n"   -> "<br>n"
         "rn" -> "<br>n"

The Mode values of 10 and over can be efficiently used when successive
blank is to be displayed on the screen without using the <pre> tag.
In this case, the line change is automatically performed according to
the changes of  screen width.
Example:qPrintf(i, &#8220;Mode %d: <font>&#8220;&#8221;</font>n&#8221;, i); Mode 0: <font>&#8220;&#8221;</font> Mode 1: <font>&#8220;&#8221;</font> Mode 2: <font>&#8220;<a href="https://qdecoder.org" target="" rel="noopener"></a>&#8220;</font> Mode 3: <font>&#8220;<a href="https://qdecoder.org" target="_top" rel="noopener"></a>&#8220;</font> Mode 4: &#8220;&#8221; Mode 5: &#8220;<a href="https://qdecoder.org" target="" rel="noopener"></a>&#8221; Mode 6: &#8220;<a href="https://qdecoder.org" target="_top" rel="noopener"></a>&#8221; Mode 10: <font>&#8220;&#8221;</font><br class="h3qerggmton60mpt5"> Mode 11: <font>&#8220;&#8221;</font><br class="h3qerggmton60mpt5"> Mode 12: <font>&#8220;<a href="https://qdecoder.org" target="" rel="noopener"></a>&#8220;</font><br class="h3qerggmton60mpt5"> Mode 13: <font>&#8220;<a href="https://qdecoder.org" target="_top" rel="noopener"></a>&#8220;</font><br class="h3qerggmton60mpt5"> Mode 14: &#8220;&#8221;<br class="h3qerggmton60mpt5"> Mode 15: &#8220;<a href="https://qdecoder.org" target="" rel="noopener"></a>&#8220;<br class="h3qerggmton60mpt5"> Mode 16: &#8220;<a href="https://qdecoder.org" target="_top" rel="noopener"></a>&#8220;<br class="h3qerggmton60mpt5"> qPrintf(i, &#8220;Mode %d: &#8216; &#8216;, &#8216; &#8216;, &#8216; &#8216;, &#8216; &#8216;n&#8221;, i); Mode 0: &#8216; &#8216;, &#8216; &#8216;, &#8216; &#8216;, &#8216; &#8216; Mode 1: &#8216; &#8216;, &#8216; &#8216;, &#8216; &#8216;, &#8216; &#8216; Mode 2: &#8216; &#8216;, &#8216; &#8216;, &#8216; &#8216;, &#8216; &#8216; Mode 3: &#8216; &#8216;, &#8216; &#8216;, &#8216; &#8216;, &#8216; &#8216; Mode 4: &#8216; &#8216;, &#8216; &#8216;, &#8216; &#8216;, &#8216; &#8216; Mode 5: &#8216; &#8216;, &#8216; &#8216;, &#8216; &#8216;, &#8216; &#8216; Mode 6: &#8216; &#8216;, &#8216; &#8216;, &#8216; &#8216;, &#8216; &#8216; Mode 10: &#8216; &#8216;, &#8216; &nbsp;&#8216;, &#8216; &nbsp;&nbsp;&#8216;, &#8216; &nbsp;&nbsp;&nbsp;&#8216;<br class="h3qerggmton60mpt5"> Mode 11: &#8216; &#8216;, &#8216; &nbsp;&#8216;, &#8216; &nbsp;&nbsp;&#8216;, &#8216; &nbsp;&nbsp;&nbsp;&#8216;<br class="h3qerggmton60mpt5"> Mode 12: &#8216; &#8216;, &#8216; &nbsp;&#8216;, &#8216; &nbsp;&nbsp;&#8216;, &#8216; &nbsp;&nbsp;&nbsp;&#8216;<br class="h3qerggmton60mpt5"> Mode 13: &#8216; &#8216;, &#8216; &nbsp;&#8216;, &#8216; &nbsp;&nbsp;&#8216;, &#8216; &nbsp;&nbsp;&nbsp;&#8216;<br class="h3qerggmton60mpt5"> Mode 14: &#8216; &#8216;, &#8216; &nbsp;&#8216;, &#8216; &nbsp;&nbsp;&#8216;, &#8216; &nbsp;&nbsp;&nbsp;&#8216;<br class="h3qerggmton60mpt5"> Mode 15: &#8216; &#8216;, &#8216; &nbsp;&#8216;, &#8216; &nbsp;&nbsp;&#8216;, &#8216; &nbsp;&nbsp;&nbsp;&#8216;<br class="h3qerggmton60mpt5"> Mode 16: &#8216; &#8216;, &#8216; &nbsp;&#8216;, &#8216; &nbsp;&nbsp;&#8216;, &#8216; &nbsp;&nbsp;&nbsp;&#8216;<br class="h3qerggmton60mpt5">

qPuts()

Syntax:void qPuts(int mode, char *buf);
Function:Same as that of qPrintf() except that arguments cannot be transmitted by formats.
Note:since the given argument of buf is modified, constant character strings(ex: str = "character string") or the variables that need to be used again should not be displayed in qPuts(). The reason why qPuts() exists is that there is no limitation to the length of argument strings unlike in qPrintf() and that the speed is a bit faster because the strdup() function is not used.

The character strings transmitted to arguments are transformed. Accordingly if a constant character string like qPuts(mode, "character string"); is used, errors occur. In this case, copy the arguments as example.
Example:char buf[100]; strcpy(buf, &#8221; mailto:nobreak@hongik.com&#8221;); qPuts(2, buf); char *buf; buf = strdup(&#8221; mailto:nobreak@hongik.com&#8221;); qPuts(2, buf); free(buf);

qRemoveSpace()

Syntax:char *qRemoveSpace(char *str);
Function:Removes white spaces(including CR, LF) before and after character strings.
Return:In case of success, returns the pointer of character strings. In case of failure, returns NULL.
Note:If this is used like qRemoveSpace("character string");, errors may occur. In this case, copy the arguments as example.
Example:char teststr[100]; strcpy(teststr, &#8221; Hello, world rn &#8220;); qRemoveSpace(teststr); // After deletion, &#8220;Hello, world&#8221; is inserted in teststr. char *teststr; teststr = strdup(&#8221; Hello, world rn &#8220;); qRemoveSpace(teststr); // After deletion, &#8220;Hello, world&#8221; is inserted in teststr.

qRemoveTailSpace

Syntax:char *qRemoveTailSpace(char *str);
Function:This function will be released at 8.1R

qStrReplace()

Syntax:char *qStrReplace(char *mode, char *srcstr, char *tokstr, char *word);
Function:Transposes character strings and tokens for character strings.
Return:Transposed string pointers.
Note:The ‘mode’ argument is a character string consisting of two separate characters like "sr".
The first character defines the transposition method, and ‘t’ or ‘s’ can be located in its place. ‘t’ stands for [t]oken. It compares the source character string of srcstr using each character of the tokstr character string as tokens and transposes matching characters into the word character strings. ‘s’ stands for [s]tring. Using the tokstr string itself as the token, it transposes into the word character string the tokstr matching character strings appearing inside the source strings.

The second character represents the record type of transposed character strings, and ‘n’ and ‘r’ can be used in its place. ‘n’ stands for [n]ew. It makes the corresponding pointers returned by storing the transposed result character strings in a new memory space. Accordingly, the source string should maintain its original state, and the corresponding memory should be free() from the user aspect. ‘r’ stands for [r]eplace and means overwriting the transposition results on srcstr. Here, srcstr is assumed to allow some leeway (it’s not reallocatied for convenience sake). This should be noted when the [r]eplace mode is to be used.

As a result, the ‘mode’ argument has 4 possible occasions of assembly as follows:

 Mode "tn" : [t]oken transposition & stores results in a [n]ew space and returns
 Mode "tr" : [t]oken transposition & [r]eplaces the string itself
 Mode "sn" : [s]tring transposition & stores results in a [n]ew space and returns
 Mode "sr" : [s]tring transposition & [r]eplaces the string itself
Example:Example) int i; char srcstr[256], *retstr; char mode[4][2+1] = {&#8220;tn&#8221;, &#8220;tr&#8221;, &#8220;sn&#8221;, &#8220;sr&#8221;}; for(i = 0; i &lt; 4; i++) { strcpy(srcstr, &#8220;Welcome to the qDecoder project.&#8221;); printf(&#8220;before %s : srcstr = %sn&#8221;, mode[i], srcstr); retstr = qStrReplace(mode[i], srcstr, &#8220;the&#8221;, &#8220;_&#8221;); printf(&#8220;after %s : srcstr = %sn&#8221;, mode[i], srcstr); printf(&#8221; retstr = %snn&#8221;, retstr); if(mode[i][1] == &#8216;n&#8217;) free(retstr); } Result) before tn : srcstr = Welcome to the qDecoder project. after tn : srcstr = Welcome to the qDecoder project. retstr = W_lcom_ _o ___ qD_cod_r proj_c_. before tr : srcstr = Welcome to the qDecoder project. after tr : srcstr = W_lcom_ _o ___ qD_cod_r proj_c_. retstr = W_lcom_ _o ___ qD_cod_r proj_c_. before sn : srcstr = Welcome to the qDecoder project. after sn : srcstr = Welcome to the qDecoder project. retstr = Welcome to _ qDecoder project. before sr : srcstr = Welcome to the qDecoder project. after sr : srcstr = Welcome to _ qDecoder project. retstr = Welcome to _ qDecoder project. Example 2) Convert to SQL String qStrReplace(&#8220;sr&#8221;, sqlvalue, &#8220;\&#8221;, &#8220;\\&#8221;); qStrReplace(&#8220;sr&#8221;, sqlvalue, &#8220;&#8216;&#8221;, &#8220;\'&#8221;);

qStr09AZaz()

Syntax:int qStr09AZaz(char *str);
Function:Checks to see if character strings consist of 0-9, A-Z, a-z.
Return:If the condition is satisfied, return 1. If not, return 0.
Example:if(qStr09AZaz(&#8220;abc1234&#8221;) == 1) printf(&#8220;True&#8221;);

qStrupr()

Syntax:char *qStrupr(char *str);
Function:Converts into uppercase letters the character strings given in arguments.
Return:The pointer of the pertinent characher string.
Example:char *str; str = strdup(&#8220;Hello World&#8221;); qStrupr(str);

qStrlwr()

Syntax:char *qStrlwr(char *str);
Function:Converts into lowercase letters the character strings given in arguments.
Return:The pointer of the pertinent characher string.
Example:char *str; str = strdup(&#8220;Hello World&#8221;); qStrlwr(str);

qStristr()

Syntax:char *qStristr(char *big, char *small);
Function:Same as that of the strstr() function. But makes a comparison without distinguishing lowercase/uppercase letters.
Return:Same as that of strstr().
Example:printf(&#8220;%s&#8221;, qStristr(&#8220;Hello World&#8221;, &#8220;WORLD&#8221;));

qStricmp()

Syntax:int qStricmp(char *s1, char *s2);
Function:Same as that of the strcmp() function. But this does not distinguish lowercase/uppercase letters.
Return:Same as that of strcmp().
Example:if(!qStricmp(&#8220;Hello&#8221;, &#8220;HELLO&#8221;)) printf(&#8220;Equal&#8221;); else printf(&#8220;Differ&#8221;);

qStrincmp()

Syntax:int qStrincmp(char *s1, char *s2, size_t len);
Function:Same as that of the strncmp() function. But this does not distinguish lowercase/uppercase letters.
Return:Same as that of strncmp().
Example:if(!qStrincmp(&#8220;Hello World&#8221;, &#8220;HELLO&#8221;, 5)) printf(&#8220;Equal&#8221;); else printf(&#8220;Differ&#8221;);

qitocomma()

Syntax:char *qitocomma(int value);
Function:Converts numeric characters into comma character strings.
Return:The string pointer converted into characters.
Note:The return string pointer is declared as static inside the functions instead of being returned with memory allocation. This is to remove the inconvenience that users have to free() memory every tiem. Accordingly, qitocomma() comes to return the same string pointer every time. And it should be noted that the previous value is deleted whenever the functions are performed.
Example:1) (O) example of right usage, when single arguments are used printf(&#8220;Price = %s&#8221;, qitocomma(1234567)); Price = 1,234,567 2) (O) example of right usage, when plural arguments are used char a[14+1], b[14+1]; strcpy(a, qitocomma(1234)); strcpy(b, qitocomma(5678)); printf(&#8220;Price = %s + %sn&#8221;, a, b); Price = 1,234 + 5,678 3) (X) example of wrong usage printf(&#8220;%s %sn&#8221;, qitocomma(1234), qitocomma(5678)); Price = 1,234 + 1,234

qStrcat()

Syntax:char *qStrcat(char str, char *format, …);
Function:This function will be released at 8.1R

qStrdupBetween()

Syntax:char *qStrdupBetween(char *str, char *start, char *end);
Function:This function will be released at 8.1R


File Handling Functions

qfopen()

Syntax:FILE *qfopen(char *path, char *mode);
Function:Open file with file lock.
Return:Same as fopen().
Note:A file which is opened by qfopen() must be closed by qfclose().
Example:FILE *fp; fp = qfopen(&#8220;/tmp/report.txt&#8221;, &#8220;w&#8221;); &#8230; qfclose(fp);

qfclose()

Syntax:int qfclose(FILE *stream);
Function:Close the file stream which is opened by qfopen().
Return:Same as fclose().

qCheckFile()

Syntax:int qCheckFile(char *format, …);
Function:Identifies the existence of files.
Return:If files exist, return 1. If not, return 0.
Note:When files cannot be accessed due to "permission", it judges that there is no file.
Example:if(qCheckFile(&#8220;test.dat&#8221;) == 0) qError(&#8220;File not found&#8221;);

qCatFile()

Syntax:int qCatFile(char *format, …);
Function:Displays the contents of files.
Return:In normal cases, the number of displayed characters. In case of errors, returns -1.
Example:qContentType(&#8220;/reference/image/gif.jpg&#8221;); qCatFile(&#8220;/reference/mypic.gif&#8221;); qContentType(&#8220;text/html&#8221;); qCatFile(&#8220;myhtml.html&#8221;);

qReadFile()

Syntax:char *qReadFile(char *filename, int *size);
Function:Returns pointers after it reads files and stores them in memory.
Return:In normal cases, returns string pointers. In case of errors, returns NULL.
Note:When memory is allocated to qReadFile, additional 1 byte needs to be allocated (1 byte more than the actual file size) for string termination character ‘’. This is for easy-to-manage purpose by reading text files. The number of characters of files is stored in size. The NULL argument is transmitted to the size item when the number of characters is not needed.
Example:char *sp, *sp2; int spsize; sp = qReadFile(&#8220;filename&#8221;, &spsize;); sp2 = qReadFile(&#8220;filename2&#8221;, NULL); &#8230; free(sp), free(sp2);

qSaveStr()

Syntax:int qSaveStr(char *sp, int spsize, char *filename, char *mode);
Function:Stores the contents of strings in the files.
Return:In normal cases – the number of stored characters(file size). In case of errors, returns -1.
Note:The mode argument is same as the mode value used in case of fopen. qSaveStr will open files via corresponding modes. File permission depends on the umask() settings value existing before calls.
Example:char *sp = &#8220;To subscribe qDecoder mailing listnSend mail to majordomo@qdecoder.org&#8221;; int len; umask(022); len = qSaveStr(sp, strlen(sp), &#8220;howto-mailing.txt&#8221;, &#8220;w&#8221;);

qFileSize()

Syntax:long qFileSize(char *filename);
Function:Returns the file size by the unit of byte.
Return:In case of success, returns the file size. No files, returns -1.
Example:long size; size = qFileSize(&#8220;/home/nobreak/sample.pdf&#8221;);

qfGetLine()

Syntax:char *qfGetLine(FILE *fp);
Function:Reads lines of files without the length limitations.
Return:Allocated memory pointers, end of file NULL.
Note:Users need to deallocated the memory of the returned string pointer.
Example:line = qfGetLine(fp);

qfGets()

Syntax:char *qfGets(FILE *fp);
Function:This function will be released at 8.1R

qCmd()

Syntax:char *qCmd(char *cmd);
Function:This function will be released at 8.1R


Validation Functions

qCheckEmail()

Syntax:int qCheckEmail(char *email);
Function:Checks the validation of e-mail addresses.
Return:No errors, 1. Invalid email, 0.
Example:qCheckEmail(&#8220;nobreak@openbird.com&#8221;);

qCheckURL()

Syntax:int qCheckURL(char *url);
Function:Checks the errors of URL addresses.
Return:No errors, 1. If the addresses fail to meet rules, return 0.
Example:qCheckURL(&#8220;/&#8221;);


Download Handling Functions

qDownload()

Syntax:int qDownload(char *filename);
Function:Transmits files to clients. Displays downloading boxes in browsers regardless of the kinds of files.
Return:In case of success, returns the number of transmitted bytes. If there is no file, returns -1.
Note:This function is a shell function of qDownloadMime() that is for convenience.
Example:qDownload(&#8220;/home/nobreak/myprg.exe&#8221;);

qDownloadMime()

Syntax:int qDownloadMime(char *filename, char *mime);
Function:Transmits files to clients in accordance with MIME.
Return:In case of success, returns the number of transmitted bytes. If there is no file, returns -1.
Note:The results of this function are the same as those acquired when the corresponding files are directly linked to the Web. But this is especially useful in preprocessing files to be downloaded only with user certification and in enabling downloading those files, which cannot be opned on the Web, only through specific programs. When MIME is ‘application/octet-stream’, it isthe same as qDownload(). And since processes are executed until streams are terminated, this is a file that can be linked on the Web. When it is to be used as preprocessing for the downloading count, it is better to utilize qRedirect().
Example:qDownloadMime(&#8220;/home/nobreak/myprg.gif&#8221;, &#8220;/reference/image/gif.jpg&#8221;);


Counter Handling Functions

qCountRead()

Syntax:int qCountRead(char *filename);
Function:Reads counter file.
Return:In case of success, returns the counter value. In case of failure, returns 0.
Note:Handles the following types of counter files.

—- number.dat —-
74
——————–
Example:int count; count = qCountRead(&#8220;number.dat&#8221;);

qCountSave()

Syntax:Q_BOOL qCountSave(char *filename, int number);
Function:Stores(updates) the counter value in the specified file name.
Return:Success Q_TRUE. Otherwise Q_FALSE.
Example:qCountSave(&#8220;number.dat&#8221;, 75);

qCountUpdate()

Syntax:int qCountUpdate(char *filename, int number);
Function:Increases the counter value of specified file names as much as number.
Return:In case of success, returns the updated counter value. In case of failure, returns 0.
Example:int count; count = qCountUpdate(&#8220;number.dat&#8221;, -3);


Environment Related Functions

qCGIenv()

Syntax:void qCGIenv(Q_CGIenv *env);
Function:Stores the environment variable of CGI and time in the structure.
Example:Q_CGIenv myenv; qCGIenv(&myenv;); /* Q_CGIenv Data Structure */ typedef struct Q_CGIenv Q_CGIenv; struct Q_CGIenv{ char *auth_type; char *content_length; char *content_type; char *document_root; char *gateway_interface; char *http_accept; char *http_accept_encoding; char *http_accept_language; char *http_connection; char *http_cookie; char *http_host; char *http_referer; char *http_user_agent; char *query_string; char *remote_addr; char *remote_host; char *remote_port; char *remote_user; char *request_method; char *request_uri; char *script_filename; char *script_name; char *server_admin; char *server_name; char *server_port; char *server_protocol; char *server_software; char *server_signature; char *unique_id; /* Miscellaneous Informations Supported by qDecoder */ int year, mon, day, hour, min, sec; };

qCGIname()

Syntax:char *qCGIname(void);
Function:Interprets only the program names at the environment variable of SCRIPT_NAME and returns.
Return:The string pointer containing CGI name.
Example:char *cginame; cginame = qCGIname();

qGetenvDefault()

Syntax:qGetenvDefault(char *nullstr, char *envname);
Function:Operates the same as the getenv() function. But returns default strings instead of NULL.
Example:char *name; name = qGetenvDefault(&#8220;/cgi-bin/CrazyWWWBoard.cgi&#8221;, &#8220;SCRIPT_NAME&#8221;); name = qGetenvDefault(NULL, &#8220;SCRIPT_NAME&#8221;);


Time Functions

qGetTime()

Syntax:struct tm *qGetTime(void);
Function:Stores time in the tm structure.
Return:The pointer of the tm structure.
Example:struct tm *mytime; mytime = qGetTime();

qGetGMTime()

Syntax:time_t qGetGMTime(char *gmt, time_t plus_sec);
Function:Converts present time+plus_sec into the GMT character-string time that is used in cookies.
Return:The seconds from 1970/1/1(00:00:00) to the present + plus_sec.
Example:time_t plus_sec; char gmt[32]; plus_sec = (time_t)300; /* 5min */ qGetGMTime(gmt, plus_sec); printf(&#8220;%s&#8221;, gmt); // &#8220;Fri, 22-Aug-1997 15:11:30 GMT&#8221;

qGetTimeStr()

Syntax:char *qGetTimeStr(void);
Function:returns the string formatted by YYYYMMDDhhmmss.
Return:The pointer of the internal static string.
Example:char *timestr; timestr = qGetTimeStr();


Socket Handling Functions

qSocketOpen()

Syntax:int qSocketOpen(char *hostname, int port);
Function:Create a TCP socket for communication.
Return:returns socket descriptor(positive). In case of invalid hostname, returns -1 and in case of socket creation fail, returns -2.
Example:int sockfd; sockfd = qSocketOpen(&#8220;www.qdecoder.org&#8221;, 80);

qSocketClose()

Syntax:int qSocketClose(int sockfd);
Function:Close the socket.
Return:returns the value 0 if successful, otherwise returns the value -1.
Example:qSocketClose(sockfd)

qSocketWaitReadable()

Syntax:int qSocketWaitReadable(int sockfd, int timeoutsec);
Function:Block the program until the socket has readable data.
Return:returns the value 1 when it is readable, otherwise(such as timeout) the value of 0 is returned.
Note:You don’t need to set the socket as non-block mode. This is magic of qDecoder ^^;
Example:int sockstatus; sockstatus = qSocketWaitReadable(sockfd, 10); if(sockstatus != 1) qError(&#8220;Timeout!&#8221;);

qSocketRead()

Syntax:int qSocketRead(char *binary, int size, int sockfd, int timeoutsec);
Function:Reads socket stream.
Return:Returns the length of data readed. otherwise(timeout) the value -1 is returned.

qSocketGets()

Syntax:int qSocketGets(char *str, int size, int sockfd, int timeoutsec);
Function:Read line from the stream. it does not contain the character CR and LF.
Return:returns the length of data readed from stream. In case of timeout, returns 0 and in case of error(EOF) returns -1
Note:The return value is not differ from the length of str, because it is actual bytes readed from stream, it also counts CR, LF. But we do not store CR, LF into str, so you do not use the return value to calculate the length of str. If you need to know the size stored in str, please use strlen(str);

qSocketWrite()

Syntax:int qSocketWrite(char *binary, int size, int sockfd);
Function:Send some data(text/binary) to socket stream .
Return:Returns the number of bytes sent if successful, otherwise the value -1 is returned.

qSocketPuts()

Syntax:int qSocketPuts(char *str, int sockfd);
Function:Send one line with terminating newline character to socket stream.
Return:Returns the value 1 if successful, otherwise the value 0 is returned.

qSocketPrintf()

Syntax:int qSocketPrintf(int sockfd, char *format, …);
Function:Send formatted data to socket stream.
Return:Returns the value 1 if successful, otherwise(connection closed by foreign host?) the value 0 is returned.
Note:The final length of formatted data must be less than 1024-1.
If you need to send more data, use qSocketPuts instead.

qSocketSendFile()

Syntax:int qSocketSendFile(char *filepath, int offset, int sockfd);
Function:Send file data to socket stream.
Return:Returns total sent bytes, otherwise the value -1 returned.

qSocketSaveIntoFile()

Syntax:int qSocketSaveIntoFile(int sockfd, int size, int timeoutsec, char *filepath, char *mode);
Function:Save stream data into file directly.
Return:Returns total read bytes otherwise(timeout) the value -1 is returned.
Example:qSocketSaveIntoFile(sockfd, reading_length, 10, &#8220;/home/savedata/pic.jpg&#8221;, &#8220;w&#8221;);

qSocketSetNonblock()

Syntax:int qSocketSetNonblock(int sockfd);
Function:Set the socket to non-blocking mode.
Return:returns the value 1 if successful, otherwise the value 0 is returned.
Note:We support this function for compatible resons. But we think you do not need this function to handle non-blocked socket because qDecoder’s other functions supports non-blocking handles inside.

DO NOT USE this function untile you surely know what it means. Please use qSocketWaitReadable() instead.

qSocketConv2file()

Syntax:FILE *qSocketConv2file(int sockfd);
Function:Convert the socket descriptor(int type) to file descriptor(FILE type).
Return:Returns the pointer of converted file descriptor.
Note:So you can use the stream easily by using fprintf(), fscanf()…
But qDecoder supports all same functions, so you do not convert socket descriptor into file descriptor for convenience reasons.
Example:FILE *sockfp; sockfp = qSocketConv2file(sockfd); fprintf(sockfp, &#8220;Hello&#8221;);


Database Independent Wrapper Functions

qDbInit()

Syntax:Q_DB *qDbInit(char *dbtype, char *addr, int port, char *username, char *password, char *database, Q_BOOL autocommit);
Function:This function will be released at 8.1R

qDbFree()

Syntax:int qDbFree(Q_DB *db);
Function:This function will be released at 8.1R

qDbOpen()

Syntax:Q_BOOL qDbOpen(Q_DB *db);
Function:This function will be released at 8.1R

qDbClose()

Syntax:Q_BOOL qDbClose(Q_DB *db);
Function:This function will be released at 8.1R

qDbGetErrMsg()

Syntax:char *qDbGetErrMsg(Q_DB *db);
Function:This function will be released at 8.1R

qDbPing()

Syntax:Q_BOOL qDbPing(Q_DB *db)
Function:This function will be released at 8.1R

qDbGetLastConnStatus()

Syntax:Q_BOOL qDbGetLastConnStatus(Q_DB *db);
Function:This function will be released at 8.1R

qDbExecuteUpdate()

Syntax:int qDbExecuteUpdate(Q_DB *db, char *pszQuery);
Function:This function will be released at 8.1R

qDbExecuteQuery()

Syntax:Q_DBRESULT *qDbExecuteQuery(Q_DB *db, char *pszQuery);
Function:This function will be released at 8.1R

qDbGetRows()

Syntax:int qDbGetRows(Q_DBRESULT *result);
Function:This function will be released at 8.1R

qDbGetCols()

Syntax:int qDbGetCols(Q_DBRESULT *result);
Function:This function will be released at 8.1R

qDbResultNext()

Syntax:int qDbResultNext(Q_DBRESULT *result);
Function:This function will be released at 8.1R

qDbResultFree()

Syntax:Q_BOOL qDbResultFree(Q_DBRESULT *result);
Function:This function will be released at 8.1R

qDbGetValue()

Syntax:char *qDbGetValue(Q_DBRESULT *result, char *field);
Function:This function will be released at 8.1R

qDbGetInt()

Syntax:int qDbGetInt(Q_DBRESULT *result, char *field);
Function:This function will be released at 8.1R

qDbGetValueAt()

Syntax:char *qDbGetValueAt(Q_DBRESULT *result, int idx);
Function:This function will be released at 8.1R

qDbGetIntAt()

Syntax:int qDbGetIntAt(Q_DBRESULT *result, int idx);
Function:This function will be released at 8.1R

qDbBeginTran()

Syntax:Q_BOOL qDbBeginTran(Q_DB *db);
Function:This function will be released at 8.1R

qDbEndTran()

Syntax:Q_BOOL qDbEndTran(Q_DB *db, Q_BOOL commit);
Function:This function will be released at 8.1R

qDbCommit()

Syntax:Q_BOOL qDbCommit(Q_DB *db);
Function:This function will be released at 8.1R

qDbRollback()

Syntax:Q_BOOL qDbRollback(Q_DB *db);
Function:This function will be released at 8.1R


Log Handling Functions

qLogOpen()

Syntax:Q_LOG *qLogOpen(char *pszLogBase, char *pszFilenameFormat, int nRotateInterval, int nFlushFlag);
Function:This function will be released at 8.1R

qLogClose()

Syntax:int qLogClose(Q_LOG *log);
Function:This function will be released at 8.1R

qLogSetConsole()

Syntax:int qLogSetConsole(Q_LOG *log, int nFlag);
Function:This function will be released at 8.1R

qLogFlush()

Syntax:int qLogFlush(Q_LOG *log);
Function:This function will be released at 8.1R

qLog()

Syntax:int qLog(Q_LOG *log, char *pszFormat, …);
Function:This function will be released at 8.1R


Error Handling Functions

qError()

Syntax:void qError(char *format, …);
Function:Displays the messages for errors. Usage is same as that of the printf() function.
Note:The maximum size of the assembled error message should not exceed 1023(1024-1) byte.
Example:qError(&#8220;error message&#8221;); qError(&#8220;errors at %s&#8221;, buf);

qErrorContact()

Syntax:void qErrorContact(char *msg);
Function:As the footer of error messages, always displayed together when qError() is called. This is generally used to provide fixed information such as producers.
Example:qErrorContact(&#8220;- qDecoder Project.&#8221;); qErrorContact(NULL); // disable (default)

qErrorLog()

Syntax:void qErrorLog(char *file);
Function:Sets up the log files on which the error messages–which are transmitted when the qError() function is called–are recorded.
Note:When logs are recorded, the main file is not directly called. Like qErrorLog("logs/error.log"), once it is called at the initial period of programs, logs are automatically recorded in the ‘logs/error.log’ file whenever qError() is called afterwards.
Example:qErrorLog(&#8220;/tmp/error.log&#8221;); // enable log qErrorLog(NULL); // disable log (default)


Miscellaneous Functions

qFreeAll()

Syntax:void qFreeAll(void);
Function:Deallocates the all allocated memories by qDecoder.
Note:Internally, qFreeAll() calls qFree(), qSessionFree(). You can use qFreeAll() instead qFree() and qSessionFree() at the end of program to deallocate all allocated memories by qDecoder.
Example:qDecoder(); qSession(NULL); &#8230; &#8230; &#8230; qFreeAll();

qReset()

Syntax:void qReset(void);
Function:Deallocates the all allocated memories and Initialize qDecoder.
Note:When you wish to make a daemon-type repetitive program or to initialize qDecoder anew, you can use this function. qReset() returns all the allocated memory including the linked-list and restores internal static variables to the initial condition. You do not need to call qFreeAll() when you use qReset().
Example:while(1) { qDecoder(); qSession(NULL); &#8230; &#8230; &#8230; qReset(); }

qUniqueID()

Syntax:char *qUniqueID(void);
Function:Always returns unique 32 bytes string .
Return:String pointer of 32 bytes unique string.
Note:The return string pointer is declared as static inside the functions instead of being returned with memory allocation. This is to remove the inconvenience that users have to free() memory every tiem. Accordingly, it should be noted that the previous value is deleted whenever the functions are performed. And you should not modify or free() it directly.
Example:char *uniqueid; uniqueid = qUniqueID();


[Home] [About] [Examples] [Changes] [Download] [SVN Repository] [Install] [Reference]