wcDriverCallApp( )

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

Establishes a connection to the application, sends the environment and stdin, if applicable, and finally reads any output from the application and returns it to the browser.

Example

returnCode = wcDriverCallApp(cntrlHandle, pvResult, nDataLen, pvPostData, nPostDataLen);

Syntax

int wcDriverCallApp(void *controlHandle, 
                    void **pvResult, 
                    size_t *nDataLen, 
                    const void *_pvPostData, 
                    size_t nPostDataLen)
controlHandleThe handle to the control structure.
pvResultGets a reference to a pointer that will contain the content data to be sent back to the client.
nDataLenGets a referenct to a size_t object that will contain the amount of data to be passed to the client.
pvPostDataGets a referenct to a "POST" buffer. Will be NULL on "GET".
nPostDataLenGets a size_t object that will contain the amount of "POST" data to be passed to the application pocket. Will be NULL on "GET".

Returns

0Success.
Error codeFailure or exception. For a list of possible error codes, see Error Messages.

Tips

Program Example

The following code shows how wcDriverCallApp( ) 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

wcDriverInit( )
wcDriverFreeBuffer( )


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