Exemplo n.º 1
0
void CBHttpRequest::ReadBuffer(void)
{
    m_dwRead = 0;

    m_eventComplete.Reset();

    if(InternetReadFile(m_hFile, &m_aBuffer, sizeof(m_aBuffer), &m_dwRead))
        StatusCallback(INTERNET_STATUS_REQUEST_COMPLETE);
    else if(GetLastError() != ERROR_IO_PENDING)
    {
        m_dwRead = 0;
        StatusCallback(INTERNET_STATUS_REQUEST_COMPLETE);
    }
}
Exemplo n.º 2
0
STDMETHODIMP CBHttpRequest::Send(VARIANT varBody)
{
    if(m_nReadyState != 1)
        return SetErrorInfo(L"Request not initialized.");

    m_eventComplete.Reset();

    BOOL bRet;
    HRESULT hr;

    if(varBody.vt == VT_BSTR)
    {
        CBStringA str;

        str = varBody.bstrVal;

        if(str.GetLength())
        {
            hr = m_mStream.Write((LPVOID)(LPCSTR)str, str.GetLength(), NULL);
            if(FAILED(hr))return hr;
        }
    } else if(varBody.vt != VT_ERROR)
    {
        CBVarPtr varPtr;

        HRESULT hr = varPtr.Attach(varBody);
        if(FAILED(hr))return hr;

        if(varPtr.m_nSize)
        {
            hr = m_mStream.Write(varPtr.m_pData, varPtr.m_nSize, NULL);
            if(FAILED(hr))return hr;
        }
    }

    bRet = HttpSendRequest(m_hFile, NULL, 0, m_mStream.m_pBuffer, m_mStream.m_dwCount);

    if(bRet)StatusCallback(INTERNET_STATUS_REQUEST_COMPLETE);
    else if(GetLastError() != ERROR_IO_PENDING)
    {
        m_nReadyState = 4;
        m_eventComplete.Set();

        return GetErrorResult();
    }

    if(!m_bAsync)m_eventComplete.Wait();

    return S_OK;
}
Exemplo n.º 3
0
//*****************************************************************************
//
// Main entry.  Process command line options, and start the bootp_server.
//
//*****************************************************************************
int
main(int argc, char **argv)
{
    HOSTENT *pHostEnt;
    WSADATA wsaData;
    unsigned long ulLocalAddress;

    //
    // Parse the command line options.
    //
    if(argc > 1)
    {
        ParseOptions(argc, argv);
    }
    else
    {
        DisplayVersion();
        DisplayHelp();
        return(0);
    }

    //
    // Display (if needed) verbose function entry.
    //
    if(g_iOptVerbose > 1)
    {
        DisplayVersion();
    }

    //
    // Install an abort handler.
    //
	signal(SIGINT, SignalIntHandler);

    //
    // Startup winsock.
    //
    VPRINTF(("Starting WINSOCK\n"));
    if(WSAStartup(0x202, &wsaData) != 0)
    {
        EPRINTF(("Winsock Failed to Start\n"));
        WSACleanup();
        return(1);
    }

    //
    // Determine what my local IP address is.
    //
    pHostEnt = gethostbyname("");
    ulLocalAddress = ((struct in_addr *)*pHostEnt->h_addr_list)->s_addr;

    //
    // Start the BOOTP/TFTP server to perform an update.
    //
    QPRINTF(("Starting BOOTP/TFTP Server ...\n"));
    StatusCallback(0);
    StartBOOTPUpdate(g_pucRemoteMAC, ulLocalAddress, g_ulRemoteAddress,
                     g_pcFileName, StatusCallback);

    //
    // Cleanup winsock.
    //
    VPRINTF(("Closing WINSOCK\n"));
    WSACleanup();

    //
    // Clean up and return.
    //
    if(g_bAbortMain)
    {
        return(2);
    }
    return(0);
}