API Overview

A-Z Index . . Home

The following skeleton pseudo-code shows how the major INFORMIX-Universal Web Connect API functions are used together in a typical application.

#include <wclib.h>

int main(argc, argv)
        int     argc;
        char    **argv;
{
        void        *wcp;
        int	    ret;
        char        *dbname, *dbuser, *dbpass;
        char        *pageId, *pagePtr=NULL;

        /* Initialize and synchronize application: */
        wcInit(argc, argv, &wcp);        

        while(1)
        {
            /* wait for user request */
    	    if ( (ret = wcConOpen(wcp, 0)) == ERR_MSGSHUTDOWN) {
                /* the session time out */
                wcDBClose(wcp, wcAppPageConnName(wcp));
                wcConClose(wcp);
                return(0);
    	    }

    	    if (ret < 0) {
                wcConClose(wcp);
                continue;
    	    }

            if ( wcAppPageIsOpen(wcp) == 0)
    	    {
                /* only connect to the database once */
                wcGetVariable(wcp, "$MI_SERVER", &dbname);
                wcGetVariable(wcp, "$MI_USER", &dbuser);
                wcGetVariable(wcp, "$MI_PASSWORD", &dbpass);
                ret = wcDBOpen(wcp, wcAppPageConnName(wcp), dbname, dbuser , dbpass);
                if (ret < 0)
                    wcConClose(wcp);
                    continue;
                }        
    	    }

            /* find out which page we need to load */
            wcGetVariable(wcp, "$MIval", &pageId);
            if(pageId != NULL) {
                /* now load the page */
                ret = wcLoad(wcp, pageId, &pagePtr);
                if (ret==ERR_OK) /* now explode the page */
                    ret = WebExplode(wcp, pagePtr, NULL);

                /* free the memory allocated by wcLoad() */
                if(pagePtr != NULL)
    	            free(pagePtr);
    	    }

    	    wcDropVariable(wcp, "$MIval");
    
    	    if((ret = wcConClose(wcp)) < 0) {
    		    wcLogPrintf(wcp, "Error in wcConClose(): errno = %d\n", ret);
    	    }
        }

        return wcExit(wcp);
}

The application starts up, waits for the user to request the HTML page in the application. When the request is received, the page is returned to the user. The loop repeats immediately, then stops and waits again for the next user request.

The application exits if the connection times out while waiting for a user request. The timeout is set in the MI_WEBTIMEOUT parameter in the configuration file (wcconfig.std). If the browser session times out, wcConOpen( ) returns the error message ERR_MSGSHUTDOWN. This message notifies the application so it can perform cleanup tasks and exit. If you do not include cleanup code in your application to respond to this error message, Universal Web Connect will terminate the application process automatically with no cleanup.


Top of Page . . A-Z Index . . Home