wcDriverInit( )

Syntax . . Returns . . Tips . . Program Example . . Related Topics . . A-Z Index . . Home

Attaches to shared memory, sets up state variables that will be used by other functions, allocates a slot in the session table if necessary, and validates the connection if the session has already been defined.

Example

returnCode = wcDriverInit(argv[0], &cntrlHandle, ENV[list]);

Syntax

int wcDriverInit (char *name,
                  void **controlHandle,
                  const char *Env[])
name[To Be Supplied]
controlHandleOut parameter used to return a pointer to a control structure.
listEnvironment list. List of applicable environment variables. See Program Example for an example of how to contruct an environment list.

Returns

Control structure handleIf successful, returns a pointer to a control structure.
Error codeFailure or exception. For a list of possible error codes, see Error Messages.

Tips

Program Example

The following code shows how wcDriverInit( ) is used in UWC CGI driver.

int go(argc, argv)
    int		argc;
    char	*argv[];
{
    void	*wcp;
    int		ret;
    static char *gpszVar[] =
    {
       "AUTH_TYPE",
       "CONTENT_LENGTH",
       "CONTENT_TYPE",
       "GATEWAY_INTERFACE",
       "HTTP_ACCEPT",
       "HTTP_REFERER",
       "HTTP_USER_AGENT",
       "PATH_INFO",
       "PATH_TRANSLATED",
       "QUERY_STRING",
       "REMOTE_ADDR",
       "REMOTE_HOST",
       "REMOTE_IDENT",
       "REMOTE_USER",
       "REQUEST_METHOD",
       "SCRIPT_NAME",
       "SERVER_NAME",
       "SERVER_PORT",
       "SERVER_PROTOCOL",
       "SERVER_SOFTWARE",
       "HTTP_COOKIE",
       "MI_WEBDIR",
       "MI_WEBCONFIG"
    };

    char* pszBuf[sizeof (gpszVar) / sizeof (gpszVar[0])];

    /*  Get Message context information... */

    for (Index = 0; Index < ((sizeof (pszBuf) / sizeof (pszBuf[0])) ); Index++)
    {
        ptr = getenv (gpszVar[Index]);
        if (ptr)
            pszBuf[Index] = strdup (ptr);
        else
            pszBuf[Index] = 0;     
    }   

    ret = wcDriverInit(argv[0], &wcp, pszBuf);

    if(ret == ERR_OK)
    {
        int nDataLen   = 0;
        void *pOutput  = 0;
        void *pInput   = 0;
        size_t ulSize  = 0;

        wcCheckLogSize(wcp);

        ptr = wcGetEnv (wcp, (const char *) "REQUEST_METHOD");
        if (ptr && !strcmp(ptr, "POST"))
        {
            ptr = wcGetEnv (wcp, (const char *) "CONTENT_LENGTH");
            if ( ptr )
            {
                int count;            
                if ((count=sscanf(ptr, "%d", &nDataLen ))!=1)
                    nDataLen = atol(ptr); 
            }
            else
                nDataLen = 0;

            pInput = malloc (nDataLen+3);
            memset (pInput, 0, nDataLen+3);

#ifdef WIN32 
            _setmode(_fileno(stdin), _O_BINARY); /* need to set to binary for file upload */
#endif /* WIN32 */   
            nDataLen = fread (pInput, 1, nDataLen, stdin);

            if (nDataLen <= 0)
                return wcTraceErr(wcp, ERR_SOCK_IO);
      }

      ret = wcDriverCallApp (wcp, &pOutput, &ulSize, pInput, nDataLen);
      wcLogPrintf(wcp, "-- WCDRVR ---, done with wcDriverCallApp\n");

      if (pInput)
         free (pInput);

      if (ret==ERR_OK)
      { 
        if (pOutput)
        {
#ifdef WIN32
            _setmode (_fileno (stdout), _O_BINARY);
#endif /* WIN32 */

            ulSize = (size_t) _write (_fileno (stdout), pOutput, ulSize);
            fflush (stdout);
            close (fileno(stdout));
            wcDriverFreeBuffer (pOutput);
        }
        /* change sesId so that wcFreeSession is not called in wcExit */
        wcp->sesId = -1;
      }
   }
   
   wcLogPrintf(wcp, "Webdriver terminating (%d).\n", ret);

   wcExit(wcp);

#ifdef WIN32
   WSACleanup();
#endif /* WIN32 */

   for (Index = 0; Index < ((sizeof (pszBuf) / sizeof (pszBuf[0])) ); Index++)
   {
      if (pszBuf[Index])
         free (pszBuf[Index]);
   }

   return (ret);
}

Related Topics

wcDriverCallApp( )
wcDriverFreeBuffer( )


Top of Page . . Syntax . . Returns . . Tips . . Program Example . . A-Z Index . . Home