Example #1
0
LONG32 SnarlInterface::DoRequest(LPCWSTR request, SnarlParameterList<wchar_t>& spl, UINT replyTimeout)
{
    // <action>[?<data>=<value>[&<data>=<value>]]
    const std::vector<SnarlParameterList<wchar_t>::PairType>&list = spl.GetList();

    if (list.size() > 0)
    {
        std::basic_string<wchar_t> requestStr = request;
        requestStr.append(L"?");

        std::vector<SnarlParameterList<wchar_t>::PairType>::const_iterator listEnd = list.end(); // cend();
        for (std::vector<SnarlParameterList<wchar_t>::PairType>::const_iterator iter = list.begin(); // cbegin();
            iter != listEnd; ++iter)
        {
            if (iter->second.length() > 0)
            {
                std::basic_string<wchar_t>& value = const_cast<std::basic_string<wchar_t>&>(iter->second);
                requestStr.append(iter->first).append(L"=").append(Escape(value));
                requestStr.append(L"&");
            }
        }
        // Delete last &
        requestStr.erase(requestStr.size() - 1);

        return DoRequest(requestStr.c_str(), replyTimeout);
    }
    else
        return DoRequest(request, replyTimeout);
}
Example #2
0
bool ThreadedFileWorker::FlushDirCache( const CString &sPath )
{
	/* FlushDirCache() is often called globally, on all drivers, which means it's called with
	 * no timeout.  Temporarily enable a timeout if needed. */
	bool bTimeoutEnabled = TimeoutEnabled();
	if( !bTimeoutEnabled )
		SetTimeout(1);

	if( m_pChildDriver == NULL )
		return false;

	/* If we're currently in a timed-out state, fail. */
	if( IsTimedOut() )
		return false;

	m_sRequestPath = sPath;

	/* Kick off the worker thread, and wait for it to finish. */
	if( !DoRequest(REQ_FLUSH_DIR_CACHE) )
	{
		if( !bTimeoutEnabled )
			SetTimeout(-1);

		LOG->Trace( "FlushDirCache(%s) timed out", sPath.c_str() );
		return false;
	}

	if( !bTimeoutEnabled )
		SetTimeout(-1);

	return true;
}
Example #3
0
RageFileBasic *ThreadedFileWorker::Copy( RageFileBasic *&pFile, CString &sError )
{
	ASSERT( m_pChildDriver != NULL ); /* how did you get a file to begin with? */

	/* If we're currently in a timed-out state, fail. */
	if( IsTimedOut() )
	{
		this->Close( pFile );
		pFile = NULL;
	}

	if( pFile == NULL )
	{
		sError = "Operation timed out";
		return NULL;
	}

	m_pRequestFile = pFile;
	if( !DoRequest(REQ_COPY) )
	{
		/* If we time out, we can no longer access pFile. */
		sError = "Operation timed out";
		pFile = NULL;
		return NULL;
	}

	RageFileBasic *pRet = m_pResultFile;
	m_pRequestFile = NULL;
	m_pResultFile = NULL;

	return pRet;
}
Example #4
0
int ThreadedFileWorker::Flush( RageFileBasic *&pFile, CString &sError )
{
	ASSERT( m_pChildDriver != NULL ); /* how did you get a file to begin with? */

	/* If we're currently in a timed-out state, fail. */
	if( IsTimedOut() )
	{
		this->Close( pFile );
		pFile = NULL;
	}

	if( pFile == NULL )
	{
		sError = "Operation timed out";
		return -1;
	}

	m_pRequestFile = pFile;

	if( !DoRequest(REQ_FLUSH) )
	{
		/* If we time out, we can no longer access pFile. */
		sError = "Operation timed out";
		pFile = NULL;
		return -1;
	}

	if( m_iResultRequest == -1 )
		sError = m_sResultError;

	m_pRequestFile = NULL;

	return m_iResultRequest;
}
Example #5
0
int ThreadedFileWorker::GetFileSize( RageFileBasic *&pFile )
{
	ASSERT( m_pChildDriver != NULL ); /* how did you get a file to begin with? */
	
	/* If we're currently in a timed-out state, fail. */
	if( IsTimedOut() )
	{
		this->Close( pFile );
		pFile = NULL;
	}

	if( pFile == NULL )
		return -1;

	m_pRequestFile = pFile;

	if( !DoRequest(REQ_GET_FILE_SIZE) )
	{
		/* If we time out, we can no longer access pFile. */
		pFile = NULL;
		return -1;
	}

	m_pRequestFile = NULL;

	return m_iResultRequest;
}
Example #6
0
RageFileBasic *ThreadedFileWorker::Open( const CString &sPath, int iMode, int &iErr )
{
	if( m_pChildDriver == NULL )
	{
		iErr = ENODEV;
		return NULL;
	}

	/* If we're currently in a timed-out state, fail. */
	if( IsTimedOut() )
	{
		iErr = EFAULT; /* Win32 has no ETIMEDOUT */
		return NULL;
	}

	m_sRequestPath = sPath;
	m_iRequestMode = iMode;

	if( !DoRequest(REQ_OPEN) )
	{
		LOG->Trace( "Open(%s) timed out", sPath.c_str() );
		iErr = EFAULT; /* Win32 has no ETIMEDOUT */
		return NULL;
	}

	iErr = m_iResultRequest;
	RageFileBasic *pRet = m_pResultFile;
	m_pResultFile = NULL;

	return pRet;
}
Example #7
0
	void Platform::DoAccept(int sfd)
	{
		int clientSock = -1;
		struct sockaddr_in clientSA;
		socklen_t clientSALen;
		pthread_t newThread;

		while(!shouldStop)
		{
			clientSock = accept(sfd, (struct sockaddr*)&clientSA, &clientSALen);
			
			if(clientSock == -1)
			{
				perror("accept");
				exit(-1);
			}

/*
			if(pthread_create(&newThread, NULL, DoRequest, clientSock) != 0)
			{
				perror("pthrea_create");
			}
*/
			DoRequest(clientSock);
		}

		close(sfd);
	}
Example #8
0
LONG32 SnarlInterface::Notify(LPCSTR classId, LPCSTR title, LPCSTR text, LONG32 timeout, LPCSTR iconPath, LPCSTR iconBase64, SnarlEnums::MessagePriority priority, LPCSTR uid, LPCSTR callback, LPCSTR value)
{
    // notify?[app-sig=<signature>|token=<application token>][&password=<password>][&id=<class identifier>]
    //        [&title=<title>][&text=<text>][&timeout=<timeout>][&icon=<icon path>][&icon-base64=<MIME data>][&callback=<default callback>]
    //        [&priority=<priority>][&uid=<notification uid>][&value=<value>]

    SnarlParameterList<char> spl(12);
    spl.Add("token", appToken);
    spl.Add("password", szPasswordA);
    
    spl.Add("id", classId);
    spl.Add("title", title);
    spl.Add("text", text);
    spl.Add("icon", iconPath);
    spl.Add("icon-base64", iconBase64);
    spl.Add("uid", uid);
    spl.Add("callback", callback);
    spl.Add("value", value);
    if (timeout != -1)  spl.Add("timeout", timeout);
    if (priority != SnarlEnums::PriorityUndefined) spl.Add("priority", priority); // -1 is a legal priority

    LONG32 request = DoRequest(Requests::NotifyA(), spl);
    lastMsgToken = (request > 0) ? request : 0;

    return request;
}
Example #9
0
/**
 * Interface to other classes for submitting a result of one test
 *
 * @param TestType
 * Constant pointer to a char array containing the test type to be run (i.e. "wine")
 *
 * @param TestInfo
 * Pointer to a CTestInfo object containing information about the test
 */
void
CWebService::Submit(const char* TestType, CTestInfo* TestInfo)
{
    auto_array_ptr<char> Response;
    auto_array_ptr<char> SuiteID;
    string Data;
    stringstream ss;

    if(!m_TestID)
        GetTestID(TestType);

    SuiteID.reset(GetSuiteID(TestType, TestInfo));

    Data = "action=submit";
    Data += Configuration.GetAuthenticationRequestString();
    Data += "&testtype=";
    Data += TestType;
    Data += "&testid=";
    Data += m_TestID;
    Data += "&suiteid=";
    Data += SuiteID;
    Data += "&log=";
    Data += EscapeString(TestInfo->Log);

    Response.reset(DoRequest(Data));

    if (strcmp(Response, "OK"))
    {
        ss << "When submitting the result, the server responded:" << endl << Response << endl;
        SSEXCEPTION;
    }
}
Example #10
0
void DChannelComm::HandleMsg(TMessageBase* aMsg)
	{
	TThreadMessage& m = *(TThreadMessage*)aMsg;
	TInt id = m.iValue;
	if (id == (TInt)ECloseMsg)
		{
		Shutdown();
		iStatus = EClosed;
		m.Complete(KErrNone, EFalse);
		return;
		}
	else if (id == KMaxTInt)
		{
		// DoCancel
		DoCancel(m.Int0());
		m.Complete(KErrNone, ETrue);
		return;
		}

	if (id < 0)
		{
		// DoRequest
		TRequestStatus* pS = (TRequestStatus*)m.Ptr0();
		TInt r = DoRequest(~id, pS, m.Ptr1(), m.Ptr2());
		if (r != KErrNone)
			Kern::RequestComplete(iClient, pS, r);
		m.Complete(KErrNone, ETrue);
		}
	else
		{
		// DoControl
		TInt r = DoControl(id, m.Ptr0(), m.Ptr1());
		m.Complete(r, ETrue);
		}
	}
Example #11
0
/**
* Interface to other classes for finishing this test run
*
* @param TestType
* Constant pointer to a char array containing the test type to be run (i.e. "wine")
*/
void
CWebService::Finish(const char* TestType)
{
    auto_array_ptr<char> Response;
    string Data;
    stringstream ss;

    if (!m_TestID)
        EXCEPTION("CWebService::Finish was called, but not a single result had been submitted!");

    Data = "action=finish";
    Data += Configuration.GetAuthenticationRequestString();
    Data += "&testtype=";
    Data += TestType;
    Data += "&testid=";
    Data += m_TestID;

    Response.reset(DoRequest(Data));

    if (strcmp(Response, "OK"))
    {
        ss << "When finishing the test run, the server responded:" << endl << Response << endl;
        SSEXCEPTION;
    }
}
Example #12
0
/**
 * Gets a Suite ID from the Web Service for this module/test combination.
 *
 * @param TestType
 * Constant pointer to a char array containing the test type to be run (i.e. "wine")
 *
 * @param TestInfo
 * Pointer to a CTestInfo object containing information about the test
 *
 * @return
 * Returns a pointer to a char array containing the Suite ID received from the Web Service.
 * The caller needs to free that pointer.
 */
PCHAR
CWebService::GetSuiteID(const char* TestType, CTestInfo* TestInfo)
{
    auto_array_ptr<char> SuiteID;
    string Data;

    Data = "action=getsuiteid";
    Data += Configuration.GetAuthenticationRequestString();
    Data += "&testtype=";
    Data += TestType;
    Data += "&module=";
    Data += TestInfo->Module;
    Data += "&test=";
    Data += TestInfo->Test;

    SuiteID.reset(DoRequest(Data));

    /* Verify that this is really a number */
    if(!IsNumber(SuiteID))
    {
        stringstream ss;

        ss << "Expected Suite ID, but received:" << endl << SuiteID << endl;
        SSEXCEPTION;
    }

    return SuiteID.release();
}
Example #13
0
/**
 * Requests a Test ID from the Web Service for our test run.
 *
 * @param TestType
 * Constant pointer to a char array containing the test type to be run (i.e. "wine")
 */
void
CWebService::GetTestID(const char* TestType)
{
    string Data;

    Data = "action=gettestid";
    Data += Configuration.GetAuthenticationRequestString();
    Data += Configuration.GetSystemInfoRequestString();
    Data += "&testtype=";
    Data += TestType;

    if(!Configuration.GetComment().empty())
    {
        Data += "&comment=";
        Data += Configuration.GetComment();
    }

    m_TestID = DoRequest(Data);

    /* Verify that this is really a number */
    if(!IsNumber(m_TestID))
    {
        stringstream ss;

        ss << "Expected Test ID, but received:" << endl << m_TestID << endl;
        SSEXCEPTION;
    }
}
Example #14
0
/**
	@param sRequest The page requested from the server
	@param buffer Buffer object to fill with the request response
	@param lpServer Server name (can be NULL; if so, will use the current connection if any or fail if there is none)
	@param lpOptional Additional data for POST (can be NULL)
	@param lpHeaders Additional headers (can be NULL)
	@param pProgress Pointer to the progress interface (can be NULL)
	@return true if the request was successful, false if failed
*/
bool InternetRequest::DoRequest(const std::tstring& sRequest, InternetRequestBuffer& buffer, LPCTSTR lpServer /* = NULL */, LPCSTR lpOptional /* = NULL */, LPCTSTR lpHeaders /* = NULL */, ProgressInterface* pProgress /* = &piDefault */)
{
	// Create a data structure for the request information
	RequestData* pData = new RequestData(this, sRequest, pProgress, buffer, lpServer, lpOptional, lpHeaders);
	// Run the request
	return DoRequest(pData);
}
/** Process a message for this logical channel */
void DTestResManLdd::HandleMsg(TMessageBase* aMsg)
	{
	TThreadMessage& m=*(TThreadMessage*)aMsg;
	TInt id=m.iValue;

	if (id==(TInt)ECloseMsg)
		{
		// Channel close.
		m.Complete(KErrNone,EFalse);
		return;
		}
	else if (id==KMaxTInt)
		{
		// DoCancel
		m.Complete(KErrNone,ETrue);
		return;
		}
	else if (id<0)
		{
		// DoRequest
		TRequestStatus* pS=(TRequestStatus*)m.Ptr0();
		TInt r=DoRequest(~id,pS,m.Ptr1(),m.Ptr2());
		if (r!=KErrNone)
			Kern::RequestComplete(iClientThreadPtr,pS,r);
		m.Complete(KErrNone,ETrue);
		}
	else
		{
		// DoControl
		TInt r=DoControl(id,m.Ptr0(),m.Ptr1());
		m.Complete(r,ETrue);
		}
	}
Example #16
0
LONG32 SnarlInterface::RemoveClass(LPCWSTR classId)
{
    SnarlParameterList<wchar_t> spl(3);
    spl.Add(L"token", appToken);
    spl.Add(L"password", szPasswordW);
    
    spl.Add(L"id", classId);

    return DoRequest(Requests::RemoveClassW(), spl);
}
Example #17
0
LONG32 SnarlInterface::IsVisible(LONG32 msgToken)
{
    // isvisible?[token=<notification token>|app-sig=<app-sig>&uid=<uid>][&password=<password>]

    SnarlParameterList<char> spl(2);
    spl.Add("token", msgToken);
    spl.Add("password", szPasswordA);

    return DoRequest(Requests::IsVisibleA(), spl);
}
Example #18
0
LONG32 SnarlInterface::ClearClasses()
{
    // clearclasses?[token=app-sig=<signature>|token=<application token>][&password=<password>]

    SnarlParameterList<char> spl(2);
    spl.Add("token", appToken);
    spl.Add("password", szPasswordA);

    return DoRequest(Requests::ClearClassesA(), spl);
}
Example #19
0
LONG32 SnarlInterface::AddAction(LONG32 msgToken, LPCWSTR label, LPCWSTR cmd)
{
    SnarlParameterList<wchar_t> spl(4);
    spl.Add(L"token", msgToken);
    spl.Add(L"password", szPasswordW);
    
    spl.Add(L"label", label);
    spl.Add(L"cmd", cmd);

    return DoRequest(Requests::AddActionW(), spl);
}
Example #20
0
LONG32 SnarlInterface::Unregister(LPCWSTR signature)
{
    SnarlParameterList<wchar_t> spl(2);
    spl.Add(L"app-sig", signature);
    spl.Add(L"password", szPasswordW);

    appToken = 0;
    lastMsgToken = 0;
    ClearPassword();

    return DoRequest(Requests::UnregisterW(), spl);
}
Example #21
0
void RKmsChannelTest::TestInvalidGenArgsDescriptor(TRequestStatus& aStatus)
/**
	Supply an invalid TGenKeyArgs descriptor to the driver to ensure the current
	thread is panicked as expected.

	@param	aStatus			This object is passed to the driver, but it should not
							be used because the thread should be panicked.
							It is supplied to this function as a convenience so this
							function does not have to declare its own instance.
 */
	{
	DoRequest(KmsLddImpl::EGenerateKey, aStatus, NULL);
	}
Example #22
0
LONG32 SnarlInterface::RemoveClass(LPCSTR classId)
{
    // remclass?[app-sig=<signature>|token=<application token>][&password=<password>][&id=<class identifier>|&all=<0|1>]

    SnarlParameterList<char> spl(3);
    spl.Add("token", appToken);
    spl.Add("password", szPasswordA);
    
    spl.Add("id", classId);
    // instead of all, use ClearClasses

    return DoRequest(Requests::RemoveClassA(), spl);
}
Example #23
0
LONG32 SnarlInterface::AddAction(LONG32 msgToken, LPCSTR label, LPCSTR cmd)
{
    // addaction?[token=<notification token>|app-sig=<signature>&uid=<uid>][&password=<password>]&label=<label>&cmd=<command>

    SnarlParameterList<char> spl(4);
    spl.Add("token", msgToken);
    spl.Add("password", szPasswordA);
    
    spl.Add("label", label);
    spl.Add("cmd", cmd);

    return DoRequest(Requests::AddActionA(), spl);
}
Example #24
0
bool ThreadedMemoryCardWorker::Unmount( const UsbStorageDevice *pDevice )
{
	ASSERT( TimeoutEnabled() );

	// If we're currently in a timed-out state, fail.
	if( IsTimedOut() )
		return false;

	m_RequestDevice = *pDevice;
	if( !DoRequest(REQ_UNMOUNT) )
		return false;

	return true;
}
Example #25
0
LONG32 SnarlInterface::Unregister(LPCSTR signature)
{
    // unregister?[app-sig=<signature>|token=<application token>][&password=<password>]

    SnarlParameterList<char> spl(2);
    spl.Add("app-sig", signature);
    spl.Add("password", szPasswordA);

    appToken = 0;
    lastMsgToken = 0;
    ClearPassword();

    return DoRequest(Requests::UnregisterA(), spl);
}
Example #26
0
LONG32 SnarlInterface::DoRequest(LPCWSTR request, UINT replyTimeout)
{
    LONG32 nResult = 0;

    // Convert to UTF8
    LPSTR utf8Request = WideToUTF8(request);
    if (utf8Request == NULL)
        return -SnarlEnums::ErrorCppInterface;

    nResult = DoRequest(utf8Request, replyTimeout);

    // Cleanup and return result
    FreeString(utf8Request);
    return nResult;
}
Example #27
0
LONG32 SnarlInterface::AddClass(LPCWSTR classId, LPCWSTR name, LPCWSTR title, LPCWSTR text, LPCWSTR icon, LPCWSTR sound, LONG32 duration, LPCWSTR callback, bool enabled)
{
    SnarlParameterList<wchar_t> spl(11);
    spl.Add(L"token", appToken);
    spl.Add(L"password", szPasswordW);
    
    spl.Add(L"id", classId);
    spl.Add(L"name", name);
    spl.Add(L"enabled", enabled);
    spl.Add(L"callback", callback);
    spl.Add(L"title", title);
    spl.Add(L"text", text);
    spl.Add(L"icon", icon);
    spl.Add(L"sound", sound);
    if (duration != -1)	spl.Add(L"duration", duration);

    return DoRequest(Requests::AddClassW(), spl);
}
Example #28
0
int ThreadedFileWorker::Remove( const CString &sPath )
{
	ASSERT( m_pChildDriver != NULL ); /* how did you get a file to begin with? */

	/* If we're currently in a timed-out state, fail. */
	if( IsTimedOut() )
		return -1;

	m_sRequestPath = sPath;

	if( !DoRequest(REQ_REMOVE) )
	{
		/* If we time out, we can no longer access pFile. */
		return -1;
	}

	return m_iResultRequest;
}
Example #29
0
/**
  Process a message for this logical channel.
  This function is called in the context of a DFC thread.

  @param aMessage The message to process.
	              The iValue member of this distinguishes the message type:
	              iValue==ECloseMsg, channel close message
	              iValue==KMaxTInt, a 'DoCancel' message
	              iValue>=0, a 'DoControl' message with function number equal to iValue
	              iValue<0, a 'DoRequest' message with function number equal to ~iValue
*/
void DZeroCopyLoopbackChannel::HandleMsg(TMessageBase* aMsg)
	{
	TThreadMessage& m=*(TThreadMessage*)aMsg;

	// Get message type
	TInt id=m.iValue;

	// Decode the message type and dispatch it to the relevent handler function...

	if (id==(TInt)ECloseMsg)
		{
		// Channel Close
		PRINT_PROBE_POINTS("ldd");
		DoCancel(RZeroCopyLoopbackDriver::EAllRequests);
		m.Complete(KErrNone, EFalse);
		return;
		}

	if (id==KMaxTInt)
		{
		// DoCancel
		DoCancel(m.Int0());
		m.Complete(KErrNone,ETrue);
		return;
		}

	if (id<0)
		{
		// DoRequest
		TRequestStatus* pS=(TRequestStatus*)m.Ptr0();
		TInt r=DoRequest(~id,pS,m.Ptr1(),m.Ptr2());
		if (r!=KErrNone)
			{
			Kern::RequestComplete(iClient,pS,r);
			}
		m.Complete(KErrNone,ETrue);
		}
	else
		{
		// DoControl
		TInt r=DoControl(id,m.Ptr0(),m.Ptr1());
		m.Complete(r,ETrue);
		}
	}
Example #30
0
//
// DTrkXtiChannel::HandleMsg
//
void DTrkXtiChannel::HandleMsg(TMessageBase* aMsg)
{
	LOG_MSG("DTrkXtiChannel::HandleMsg()");
	
	TThreadMessage& m = *(TThreadMessage*)aMsg;
	TInt id = m.iValue;


	if (id == (TInt)ECloseMsg)
	{
        if (iTrkXtiSubscriber)
        {
            Kern::SemaphoreWait(*iLock);
            delete iTrkXtiSubscriber;
            iTrkXtiSubscriber = NULL;   
            Kern::SemaphoreSignal(*iLock);              
        }
		m.Complete(KErrNone, EFalse);
		return;
	}

	if (id == KMaxTInt)
	{
		// DoCancel
		DoCancel(m.Int0());
		m.Complete(KErrNone, ETrue); 
		return;
	}

	if (id < 0)
	{
		// DoRequest
		TRequestStatus* pStatus = (TRequestStatus*)m.Ptr0();
		DoRequest(~id, pStatus, m.Ptr1(), m.Ptr2());
		m.Complete(KErrNone, ETrue);
	}
	else
	{
		// DoControl
		TInt err = DoControl(id, m.Ptr0(), m.Ptr1());
		m.Complete(err, ETrue);
	}
}