Esempio n. 1
0
int CSVSnmpOID::GetResult(MonitorResult &ResultList)
{
    m_bSum = false;
    int nResult = -1;
    if(m_szOID.empty())
        return nResult;
	
	sprintf(str,"Type:%d\n",m_nType);
    
	if(m_nType == 0)
    {//如果OID类型是简单变量
        SetOID(m_szOID.c_str());
        nResult = GetRequest(ResultList);
		

    }
    else
    {//如果是表格变量
        if(m_szOIDIndex.empty())
        {//如果索引值为空,取表格变量
            SetOID(m_szOID.c_str());
            nResult = GetBulkRequest(ResultList);//获得表格变量结果
        }
        else
        {//索引值不为空,取简单变量
            char chOIDTmp[MAX_BUFF_LEN] = {0};
            sprintf(chOIDTmp, "%s.%s", m_szOID.c_str(), m_szOIDIndex.c_str());
            SetOID(chOIDTmp);//重新设置OID
            nResult = GetRequest(ResultList);//获得简单变量结果
        }
    }
    return nResult;//返回结果   
}
Esempio n. 2
0
DWORD CAsyncUrlReader::ThreadProc()
{
    AfxSocketInit(nullptr);

    DWORD cmd = GetRequest();
    if (cmd != CMD_INIT) {
        Reply((DWORD)E_FAIL);
        return (DWORD) - 1;
    }

    try {
        CInternetSession is;
        CAutoPtr<CStdioFile> fin(is.OpenURL(m_url, 1, INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_NO_CACHE_WRITE));

        TCHAR path[MAX_PATH], fn[MAX_PATH];
        CFile fout;
        if (GetTempPath(MAX_PATH, path) && GetTempFileName(path, _T("mpc_http"), 0, fn)
                && fout.Open(fn, modeCreate | modeWrite | shareDenyWrite | typeBinary)) {
            m_fn = fn;

            char buff[1024];
            int len = fin->Read(buff, sizeof(buff));
            if (len > 0) {
                fout.Write(buff, len);
            }

            Reply(S_OK);

            while (!CheckRequest(&cmd)) {
                int len2 = fin->Read(buff, sizeof(buff));
                if (len2 > 0) {
                    fout.Write(buff, len2);
                }
            }
        } else {
            Reply((DWORD)E_FAIL);
        }

        fin->Close(); // must close it because the destructor doesn't seem to do it and we will get an exception when "is" is destroying
    } catch (CInternetException* ie) {
        ie->Delete();
        Reply((DWORD)E_FAIL);
    }

    //

    cmd = GetRequest();
    ASSERT(cmd == CMD_EXIT);
    Reply(S_OK);

    //

    m_hThread = nullptr;

    return S_OK;
}
Esempio n. 3
0
bool qEnvApache::AppendHeader(const char *str, const char *val)
{
	if (!IsFlushed()) {
		ap_table_add(GetRequest()->headers_out, str, val);
		if (!stricmp(str,"set-cookie"))
			ap_table_add(GetRequest()->err_headers_out, str, val);
		return true;
	}
	return false;
}
Esempio n. 4
0
bool qEnvApache::SetHeader(const char *str, const char *val)
{
	if (!IsFlushed()) {
		ap_table_set(GetRequest()->headers_out, str, val);
		if (!stricmp(str,"content-type")) {
			myReq->content_type = ap_pstrdup(myReq->pool, val);
		} else  if (!stricmp(str,"set-cookie"))
			ap_table_set(GetRequest()->err_headers_out, str, val);
		return true;
	}
	return false;
}
Esempio n. 5
0
/*
 * @brief	主程序
 */
int main(void)
{
	Request req;
	char weightBUf[32];
	char devCode[32];

  	SystemInit();
	ModulesInit();

	SelectChannel(GPRS_CHANNEL);
	GPRS_GetDevCode(devCode, sizeof(devCode));

	SelectChannel(BLUETOOTH_CHANNEL);
	while(GetRequest() != SYS_START){}	/* 等待接收SYS_START信号以开始工作 */
	SendResponse(SYS_START);

	BT_Println(devCode);

	while(1) {
		myWDGInit(30);	/* 设置定时器,值为30*2=60s=1min。超时会导致系统认为蓝牙已断开,从而进入alarm模式。 */

		req = GetRequest();	/* 获取应用请求,并调用相应功能API */
		if(FALSE == TimeoutFlag) {
			switch(req) {
				case KEEP_ALIVE:
					SendResponse(KEEP_ALIVE);
					ResetWDGCounter();
					break;

				case GET_WEIGHT:
					SendResponse(GET_WEIGHT);
					GetWeight(weightBUf);
					BT_Println(weightBUf);
					ResetWDGCounter();
					break;

				case UNLOCK_DEVICE:
					SendResponse(UNLOCK_DEVICE);
					LOCK_Unlock();	/* 解锁电子锁 */
					ResetWDGCounter();
					break;

				default:
					BT_Println("Request invalid.");
			}
		}else {
			while(1) { ReportLocation(); }
		}

	}

	return 0;
}
Esempio n. 6
0
void HTTP::DiscardRequest(int requestHandle)
	{
	Request* request=GetRequest(requestHandle);

	if (request)
		{
		if (request->connection)
			{
			delete request->connection;
			}
		if (request->requestString)
			{
			Free(request->requestString);
			}
		if (request->resource)
			{
			delete request->resource;
			}
		BagIterator<Request*> it(requests_);
		if (it.Find(request))
			{
			requests_.Remove(it);
			}
		delete request;
		}

	}
Esempio n. 7
0
FileRequestAsync* AsyncHandler::RequestFile(const std::string& folder_name, const std::string& file_name) {
	std::string path = FileFinder::MakePath(folder_name, file_name);

	FileRequestAsync* request = GetRequest(path);

	if (request) {
		return request;
	}

	FileRequestAsync req(folder_name, file_name);
	RegisterRequest(path, req);

	//Output::Debug("Waiting for %s", path.c_str());

	return GetRequest(path);
}
Esempio n. 8
0
DWORD
CPullPin::ThreadProc(void)
{
    for (;;) {
	DWORD cmd = GetRequest();
	switch(cmd) {
	case TM_Exit:
	    Reply(S_OK);
	    return 0;

	case TM_Pause:
	    // we are paused already
	    Reply(S_OK);
	    break;

	case TM_Start:
	    Reply(S_OK);
	    Process();
	    break;
	}

	// at this point, there should be no outstanding requests on the
	// upstream filter.
	// We should force begin/endflush to ensure that this is true.
	// !!!Note that we may currently be inside a BeginFlush/EndFlush pair
	// on another thread, but the premature EndFlush will do no harm now
	// that we are idle.
	m_pReader->BeginFlush();
	CleanupCancelled();
	m_pReader->EndFlush();
    }
}
DWORD CWavPackDSSplitterInputPin::ThreadProc()
{
    Command com; 
    
    DebugLog("===> Entering CWavPackDSSplitterInputPin::ThreadProc... 0x%08X", GetCurrentThreadId());

    do 
    { 
        DebugLog("===> ThreadProc waiting command... 0x%08X", GetCurrentThreadId());
        com = (Command)GetRequest();
        switch (com) 
        { 
        case CMD_EXIT:
            DebugLog("===> ThreadProc CMD_EXIT 0x%08X", GetCurrentThreadId());
            Reply(NOERROR); 
            break; 
            
        case CMD_STOP: 
            DebugLog("===> ThreadProc CMD_STOP 0x%08X", GetCurrentThreadId());
            Reply(NOERROR); 
            break; 
            
        case CMD_RUN:
            DebugLog("===> ThreadProc CMD_RUN 0x%08X", GetCurrentThreadId());
            DebugLog("===> Entering DoProcessingLoop... 0x%08X", GetCurrentThreadId());
            DoProcessingLoop(); 
            DebugLog("<=== Leaving DoProcessingLoop 0x%08X", GetCurrentThreadId());
            break; 
        } 
    } while (com != CMD_EXIT);

    DebugLog("<=== Leaving CWavPackDSSplitterInputPin::ThreadProc 0x%08X", GetCurrentThreadId());
    
    return NOERROR; 
}
Esempio n. 10
0
int iislua_req_get_headers(lua_State *L)
{
    auto ctx = iislua_get_http_ctx(L);

    if (ctx == NULL)
    {
        return luaL_error(L, "context is null");
    }

    auto headers = ctx->GetRequest()->GetRawHttpRequest()->Headers;

    lua_createtable(L, 0, headers.UnknownHeaderCount);

    for (USHORT i = 0; i < HttpHeaderRequestMaximum; i++)
    {
        if (headers.KnownHeaders[i].pRawValue != NULL)
        {
            lua_pushstring(L, iislua_util_get_http_req_header(i));
            lua_pushlstring(L, headers.KnownHeaders[i].pRawValue, headers.KnownHeaders[i].RawValueLength);
            lua_settable(L, -3);
        }
    }

    for (USHORT i = 0; i < headers.UnknownHeaderCount; i++)
    {
        lua_pushlstring(L, headers.pUnknownHeaders[i].pName, headers.pUnknownHeaders[i].NameLength);
        lua_pushlstring(L, headers.pUnknownHeaders[i].pRawValue, headers.pUnknownHeaders[i].RawValueLength);
        lua_settable(L, -3);
    }

    return 1;
}
Esempio n. 11
0
	void GetCountRequest::Info()
	{
		GLogger* pLogger = augeGetLoggerInstance();
		char str[AUGE_MSG_MAX];
		const char* value = GetRequest();
		pLogger->Debug("[Requet Parameters]");
		g_sprintf(str,"\t%s:%s", "Request", (value==NULL)?"":value);
		pLogger->Debug(str);
		
		value = GetVersion();
		g_sprintf(str,"\t%s:%s", "Version", (value==NULL)?"":value);
		pLogger->Debug(str);

		g_sprintf(str,"\t%s:%s", "Service", "wfs");
		pLogger->Debug(str);

		value = GetMimeType();
		g_sprintf(str,"\t%s:%s", "MimeType", (value==NULL)?"":value);
		pLogger->Debug(str);

		value = GetTypeName();
		g_sprintf(str,"\t%s:%s", "TypeName", (value==NULL)?"":value);
		pLogger->Debug(str);

	}
DWORD  CAVISplitter::ThreadProc()
{
	m_threadid = GetCurrentThreadId();
	while (1) 
	{
		DWORD cmd = GetRequest();
		switch (cmd)
		{
		case tm_exit:
            stopPinsProcessingThreads();
			Reply(S_OK);
            return 0;

		case tm_pause:
			// we are paused already
            stopPinsProcessingThreads();
			Reply(S_OK);
            break;

		case tm_start:
			startPinsProcessingThreads();
            Reply(S_OK);
            break;
		}

	}
	return 0;
}
Esempio n. 13
0
	void GetFeatureRequest::Info()
	{
		GLogger* pLogger = augeGetLoggerInstance();
		char str[AUGE_MSG_MAX];
		const char* value = GetRequest();
		pLogger->Debug("[Requet Parameters]");
		g_sprintf(str,"\t%s:%s", "Request", (value==NULL)?"":value);
		pLogger->Debug(str);
		
		value = GetVersion();
		g_sprintf(str,"\t%s:%s", "Version", (value==NULL)?"":value);
		pLogger->Debug(str);

		g_sprintf(str,"\t%s:%s", "Service", "wfs");
		pLogger->Debug(str);

		value = GetMimeType();
		g_sprintf(str,"\t%s:%s", "MimeType", (value==NULL)?"":value);
		pLogger->Debug(str);

		value = GetTypeName();
		g_sprintf(str,"\t%s:%s", "TypeName", (value==NULL)?"":value);
		pLogger->Debug(str);

		value = GetOutputFormat();
		g_sprintf(str,"\t%s:%s", "OutputFormat", (value==NULL)?"":value);
		pLogger->Debug(str);

		g_sprintf(str,"\t%s:%d", "MaxFeatures", GetMaxFeatures());
		pLogger->Debug(str);

		g_sprintf(str,"\t%s:%d", "Offset", GetOffset());
		pLogger->Debug(str);
	}
Esempio n. 14
0
const CCgiEntry& CCgiContext::GetRequestValue(const string& name,
                                              bool*         is_found)
    const
{
    pair<TCgiEntriesCI, TCgiEntriesCI> range =
        GetRequest().GetEntries().equal_range(name);

    if (range.second == range.first) {
        if ( is_found ) {
            *is_found = false;
        }
        static CSafeStaticPtr<CCgiEntry> s_EmptyCgiEntry; 
        return s_EmptyCgiEntry.Get();
    }
    if ( is_found ) {
        *is_found = true;
    }

    const CCgiEntry& value = range.first->second;
    while (++range.first != range.second) {
        if (range.first->second != value) {
            THROW1_TRACE(runtime_error,
                         "duplicate entries in request with name: " +
                         name + ": " + value.GetValue() + "!=" +
                         range.first->second.GetValue());
        }
    }
    return value;
}
Esempio n. 15
0
int iislua_req_get_remote_addr(lua_State *L)
{
    auto ctx = iislua_get_http_ctx(L);

    if (ctx == NULL)
    {
        return luaL_error(L, "context is null");
    }

    auto remoteAddr = ctx->GetRequest()->GetRemoteAddress();

    char ipAddress[INET6_ADDRSTRLEN];

    if (remoteAddr->sa_family == AF_INET)
    {
        inet_ntop(AF_INET, &reinterpret_cast<SOCKADDR_IN *>(remoteAddr)->sin_addr, ipAddress, sizeof(ipAddress));
    }
    else
    {
        inet_ntop(AF_INET6, &reinterpret_cast<SOCKADDR_IN6 *>(remoteAddr)->sin6_addr, ipAddress, sizeof(ipAddress));
    }

    lua_pushstring(L, ipAddress);

    return 1;
}
void* WorkerThread::Entry()
{
	while( true )
	{
		// Did we get a request to terminate?
		if(TestDestroy())
			break;

		ThreadRequest *request = GetRequest();
		if( request )
		{
			// Call user's implementation for processing request
			ProcessRequest( request );

			wxThread::Sleep(10);  // Allow other threads to work as well
			delete request;
			request = NULL;
			continue; // to avoid the sleep
		}

		// Sleep for 1 seconds, and then try again
		wxThread::Sleep(200);
	}
	return NULL;
}
Esempio n. 17
0
//CAMThread Stuff
DWORD OggDemuxFilter::ThreadProc() 
{	
	while(true) 
    {
		DWORD locThreadCommand = GetRequest();
	
		switch(locThreadCommand) 
        {
			case THREAD_EXIT:
	
				Reply(S_OK);
                LOG(logDEBUG) << __FUNCTIONW__ << " THREAD IS EXITING";
				return S_OK;

			case THREAD_RUN:
	
				Reply(S_OK);
				DataProcessLoop();
                LOG(logDEBUG) << __FUNCTIONW__ << " Data Process Loop has returned";
				break;

           case THREAD_SEEK:

               m_oggBuffer.clearData();
               SetCurrentReaderPos(GetRequestedSeekPos());
               Reply(S_OK);

               DataProcessLoop();
               LOG(logDEBUG) << __FUNCTIONW__ << " Seek request";
               break;
		}
	}

	return S_OK;
}
Esempio n. 18
0
bool qEnvApache::SetReplyCode(int reply)
{
	if (!IsFlushed()) {
		GetRequest()->status = reply;
		return true;
	}
	return false;
}
Esempio n. 19
0
int iislua_req_get_url_args(lua_State *L)
{
    auto ctx = iislua_get_http_ctx(L);

    if (ctx == NULL)
    {
        return luaL_error(L, "context is null");
    }

    lua_createtable(L, 0, 0);

    if (ctx->GetRequest()->GetRawHttpRequest()->CookedUrl.pQueryString != NULL)
    {
        auto queryString = iislua_to_str(ctx->GetRequest()->GetRawHttpRequest()->CookedUrl.pQueryString);
    }

    return 1;
}
_Must_inspect_result_
PVOID
FxRequestSystemBuffer::GetBuffer(
    VOID
    )
/*++

Routine Description:
    Returns the system buffer that has been cached away by the call to SetBuffer()

Arguments:
    None

Return Value:
    Valid memory or NULL on error

  --*/
{
    FxDevice* pDevice;
    FxIrp* irp = GetRequest()->GetFxIrp();
    WDF_DEVICE_IO_TYPE ioType;

    switch (irp->GetMajorFunction()) {
    case IRP_MJ_DEVICE_CONTROL:
    case IRP_MJ_INTERNAL_DEVICE_CONTROL:
        return m_Buffer;

    case IRP_MJ_READ:
    case IRP_MJ_WRITE:
        pDevice = FxDevice::GetFxDevice(irp->GetDeviceObject());
        ioType = pDevice->GetIoType(); 

        switch (ioType) {
        case WdfDeviceIoBuffered:
            return m_Buffer;

        case WdfDeviceIoDirect:
            //
            // FxRequest::GetMemoryObject has already called MmGetSystemAddressForMdlSafe
            // and returned success, so we know that we can safely call
            // MmGetSystemAddressForMdlSafe again to get a valid VA pointer.
            //
            return Mx::MxGetSystemAddressForMdlSafe(m_Mdl, NormalPagePriority);

        case WdfDeviceIoNeither:
            return m_Buffer;

        default:
            ASSERT(FALSE);
            return NULL;
        }

    default:
        ASSERT(FALSE);
        return NULL;
    }
}
Esempio n. 21
0
DWORD CBaseSplitterOutputPin::ThreadProc()
{
	m_hrDeliver = S_OK;
	m_fFlushing = m_fFlushed = false;
	m_eEndFlush.Set();

	while(1)
	{
		Sleep(1);

		DWORD cmd;
		if(CheckRequest(&cmd))
		{
			m_hThread = NULL;
			cmd = GetRequest();
			Reply(S_OK);
			ASSERT(cmd == CMD_EXIT);
			return 0;
		}

		int cnt = 0;
		do
		{
			CAutoPtr<Packet> p;

			{
				CAutoLock cAutoLock(&m_queue);
				if((cnt = m_queue.GetCount()) > 0)
					p = m_queue.Remove();
			}

			if(S_OK == m_hrDeliver && cnt > 0)
			{
				ASSERT(!m_fFlushing);

				m_fFlushed = false;

				// flushing can still start here, to release a blocked deliver call

				HRESULT hr = p 
					? DeliverPacket(p) 
					: DeliverEndOfStream();

				m_eEndFlush.Wait(); // .. so we have to wait until it is done

				if(hr != S_OK && !m_fFlushed) // and only report the error in m_hrDeliver if we didn't flush the stream
				{
					// CAutoLock cAutoLock(&m_csQueueLock);
					m_hrDeliver = hr;
					break;
				}
			}
		}
		while(--cnt > 0);
	}
}
Esempio n. 22
0
DWORD CBDReaderFilter::ThreadProc()
{
  SetThreadName(-1, "BDReader_WORKER");

  m_bFlushing = false;
  m_eEndFlush.Set();

  for (DWORD cmd = (DWORD)-1; ; cmd = GetRequest())
  {
    if (cmd == CMD_EXIT)
    {
      m_hThread = NULL;
      Reply(S_OK);
      return 0;
    }

    SetThreadPriority(m_hThread, THREAD_PRIORITY_NORMAL);

    m_rtStart = m_rtNewStart;
    m_rtStop = m_rtNewStop;

    if (cmd == CMD_SEEK)
      Seek(m_rtStart);

    if (cmd != (DWORD)-1)
      Reply(S_OK);

    // Wait for the end of any flush
    m_eEndFlush.Wait();

    if (cmd == CMD_SEEK)
    {
      m_pVideoPin->DeliverNewSegment(m_rtStart, m_rtStop, m_dRate);
      m_pAudioPin->DeliverNewSegment(m_rtStart, m_rtStop, m_dRate);
      m_pSubtitlePin->DeliverNewSegment(m_rtStart, m_rtStop, m_dRate);

      m_eEndNewSegment.Set();
    }

    while (!CheckRequest(&cmd)) 
      Sleep(5); // TODO remove polling or maybe start to use the worker thread for pre-caching data

    // If we didnt exit by request, deliver end-of-stream
    if (!CheckRequest(&cmd)) 
    {
      m_pAudioPin->EndOfStream();
      m_pVideoPin->EndOfStream();
      m_pSubtitlePin->EndOfStream();
    }
  }
  ASSERT(0); // we should only exit via CMD_EXIT

  m_hThread = NULL;
  return 0;
}
NS_IMETHODIMP
SmsRequestManager::NotifyGotNextMessage(PRInt32 aRequestId, nsIDOMMozSmsMessage* aMessage)
{
  SmsRequest* request = GetRequest(aRequestId);

  nsCOMPtr<SmsCursor> cursor = static_cast<SmsCursor*>(request->GetCursor());
  NS_ASSERTION(cursor, "Request should have an cursor in that case!");
  cursor->SetMessage(aMessage);

  return NotifySuccess<nsIDOMMozSmsCursor*>(aRequestId, cursor);
}
NS_IMETHODIMP
SmsRequestManager::NotifyCreateMessageList(PRInt32 aRequestId, PRInt32 aListId,
                                           nsIDOMMozSmsMessage* aMessage)
{
  SmsRequest* request = GetRequest(aRequestId);

  nsCOMPtr<SmsCursor> cursor = new SmsCursor(aListId, request);
  cursor->SetMessage(aMessage);

  return NotifySuccess<nsIDOMMozSmsCursor*>(aRequestId, cursor);
}
nsresult
SmsRequestManager::NotifyError(PRInt32 aRequestId, PRInt32 aError)
{
  SmsRequest* request = GetRequest(aRequestId);
  request->SetError(aError);

  nsresult rv = DispatchTrustedEventToRequest(ERROR_EVENT_NAME, request);

  mRequests.ReplaceObjectAt(nsnull, aRequestId);
  return rv;
}
nsresult
SmsRequestManager::NotifySuccess(PRInt32 aRequestId, T aParam)
{
  SmsRequest* request = GetRequest(aRequestId);
  request->SetSuccess(aParam);

  nsresult rv = DispatchTrustedEventToRequest(SUCCESS_EVENT_NAME, request);

  mRequests.ReplaceObjectAt(nsnull, aRequestId);
  return rv;
}
Esempio n. 27
0
float HTTP::GetPercentageReceived(int requestHandle)
	{
	Request* request=GetRequest(requestHandle);

	if (request && request->contentLength>0 && request->headerLength>0)
		{
		return (float)request->receivedData.GetSize()/(float)(request->contentLength+request->headerLength);
		}

	return 0.0f;
	}
Esempio n. 28
0
void
HTMLImageElement::FlushUseCounters()
{
  nsCOMPtr<imgIRequest> request;
  GetRequest(CURRENT_REQUEST, getter_AddRefs(request));

  nsCOMPtr<imgIContainer> container;
  request->GetImage(getter_AddRefs(container));

  static_cast<image::Image*>(container.get())->ReportUseCounters();
}
Esempio n. 29
0
HTTP::RequestStatus HTTP::GetRequestStatus(int requestHandle)
	{
	Request* request=GetRequest(requestHandle);

	if (request)
		{
		return request->status;
		}

	return Status_Invalid;
	}
NS_IMETHODIMP
SmsRequestManager::NotifyReadMessageListFailed(PRInt32 aRequestId, PRInt32 aError)
{
  SmsRequest* request = GetRequest(aRequestId);

  nsCOMPtr<nsIDOMMozSmsCursor> cursor = request->GetCursor();
  if (cursor) {
    static_cast<SmsCursor*>(cursor.get())->Disconnect();
  }

  return NotifyError(aRequestId, aError);
}