当前位置: 首页>>代码示例>>C++>>正文


C++ IOBuffer::Ignore方法代码示例

本文整理汇总了C++中IOBuffer::Ignore方法的典型用法代码示例。如果您正苦于以下问题:C++ IOBuffer::Ignore方法的具体用法?C++ IOBuffer::Ignore怎么用?C++ IOBuffer::Ignore使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IOBuffer的用法示例。


在下文中一共展示了IOBuffer::Ignore方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: GETIBPOINTER

bool AMF0Serializer::ReadDouble(IOBuffer &buffer, Variant &variant,
		bool readType) {
	if (readType) {
		AMF_CHECK_BOUNDARIES(buffer, 1);
		if (GETIBPOINTER(buffer)[0] != AMF0_NUMBER) {
			FATAL("AMF type not valid: want: %hhu; got: %hhu",
					AMF0_NUMBER, GETIBPOINTER(buffer)[0]);
			return false;
		}

		if (!buffer.Ignore(1)) {
			FATAL("Unable to ignore 1 bytes");
			return false;
		}
	}

	AMF_CHECK_BOUNDARIES(buffer, 8);
	double temp = 0;
	ENTOHDP(GETIBPOINTER(buffer), temp);
	variant = (double) temp;

	if (!buffer.Ignore(8)) {
		FATAL("Unable to ignore 8 bytes");
		return false;
	}
	return true;
}
开发者ID:Undev,项目名称:crtmpserver,代码行数:27,代码来源:amf0serializer.cpp

示例2: SignalInputData

bool BaseVariantProtocol::SignalInputData(IOBuffer &buffer) {
	if (_pProtocolHandler == NULL) {
		FATAL("This protocol is not registered to any application yet");
		return false;
	}

	if (_pFarProtocol->GetType() == PT_OUTBOUND_HTTP
			|| _pFarProtocol->GetType() == PT_INBOUND_HTTP) {
#ifdef HAS_PROTOCOL_HTTP
		//1. This is a HTTP based transfer. We only start doing stuff
		//after a complete request is made.
		BaseHTTPProtocol *pHTTPProtocol = (BaseHTTPProtocol *) _pFarProtocol;
		if (!pHTTPProtocol->TransferCompleted())
			return true;

		if (!Deserialize(GETIBPOINTER(buffer), pHTTPProtocol->GetContentLength(),
				_lastReceived)) {
			FATAL("Unable to deserialize content");
			return false;
		}
		buffer.Ignore(pHTTPProtocol->GetContentLength());

		_lastReceived.Compact();

		return _pProtocolHandler->ProcessMessage(this, _lastSent, _lastReceived);
#else
		FATAL("HTTP protocol not supported");
		return false;
#endif /* HAS_PROTOCOL_HTTP */
	} else if (_pFarProtocol->GetType() == PT_TCP) {
		while (GETAVAILABLEBYTESCOUNT(buffer) > 4) {
			uint32_t size = ENTOHLP(GETIBPOINTER(buffer));
			if (size > 4 * 1024 * 1024) {
				FATAL("Size too big: %u", size);
				return false;
			}
			if (GETAVAILABLEBYTESCOUNT(buffer) < size + 4) {
				FINEST("Need more data");
				return true;
			}

			if (!Deserialize(GETIBPOINTER(buffer) + 4, size, _lastReceived)) {
				FATAL("Unable to deserialize variant");
				return false;
			}
			buffer.Ignore(size + 4);

			_lastReceived.Compact();

			if (!_pProtocolHandler->ProcessMessage(this, _lastSent, _lastReceived)) {
				FATAL("Unable to process message");
				return false;
			}
		}
		return true;
	} else {
		FATAL("Invalid protocol stack");
		return false;
	}
}
开发者ID:dista,项目名称:crtmpserver,代码行数:60,代码来源:basevariantprotocol.cpp

示例3: GETIBPOINTER

bool AMF0Serializer::ReadLongString(IOBuffer &buffer, Variant &variant, bool readType) {
	if (readType) {
		AMF_CHECK_BOUNDARIES(buffer, 1);
		if (GETIBPOINTER(buffer)[0] != AMF0_LONG_STRING) {
			FATAL("AMF type not valid: want: %"PRIu8"; got: %"PRIu8,
					AMF0_LONG_STRING, GETIBPOINTER(buffer)[0]);
			return false;
		}

		if (!buffer.Ignore(1)) {
			FATAL("Unable to ignore 1 bytes");
			return false;
		}
	}

	AMF_CHECK_BOUNDARIES(buffer, 4);
	uint32_t length = ENTOHLP(GETIBPOINTER(buffer)); //----MARKED-LONG---
	if (!buffer.Ignore(4)) {
		FATAL("Unable to ignore 4 bytes");
		return false;
	}

	AMF_CHECK_BOUNDARIES(buffer, length);
	variant = string((char *) (GETIBPOINTER(buffer)), length);
	if (!buffer.Ignore(length)) {
		FATAL("Unable to ignore %"PRIu32" bytes", length);
		return false;
	}
	return true;
}
开发者ID:Akagi201,项目名称:crtmpserver,代码行数:30,代码来源:amf0serializer.cpp

示例4: SignalInputData

bool InboundJSONCLIProtocol::SignalInputData(IOBuffer &buffer) {
	//1. Get the buffer and the length
	uint8_t *pBuffer = GETIBPOINTER(buffer);
	uint32_t length = GETAVAILABLEBYTESCOUNT(buffer);
	if (length == 0)
		return true;

	//2. Walk through the buffer and execute the commands
	string command = "";
	for (uint32_t i = 0; i < length; i++) {
		if ((pBuffer[i] == 0x0d) || (pBuffer[i] == 0x0a)) {
			if (command != "") {
				if (!ParseCommand(command)) {
					FATAL("Unable to parse command\n`%s`", STR(command));
					return false;
				}
			}
			command = "";
			buffer.Ignore(i);
			pBuffer = GETIBPOINTER(buffer);
			length = GETAVAILABLEBYTESCOUNT(buffer);
			i = 0;
			continue;
		}
		command += (char) pBuffer[i];
		if (command.length() >= MAX_COMMAND_LENGTH) {
			FATAL("Command too long");
			return false;
		}
	}

	//3. Done
	return true;
}
开发者ID:andviro,项目名称:crtmpserver,代码行数:34,代码来源:inboundjsoncliprotocol.cpp

示例5: HandleFixedLengthContent

bool BaseHTTPProtocol::HandleFixedLengthContent(IOBuffer &buffer) {
	//1. Compute the chunk size that we areg going to read
	//which is how many bytes we have available, but no more than _contentLength
	uint32_t chunkSize = GETAVAILABLEBYTESCOUNT(buffer);
	o_assert(_sessionDecodedBytesCount <= _contentLength);
	uint32_t remaining = _contentLength - _sessionDecodedBytesCount;
	chunkSize = chunkSize > remaining ? remaining : chunkSize;

	//2. Update the session decoded bytes count and decoded bytes count
	_sessionDecodedBytesCount += chunkSize;
	_decodedBytesCount += chunkSize;

	//3. Make the copy and ignore the chunk size
	_inputBuffer.ReadFromBuffer(GETIBPOINTER(buffer), chunkSize);
	buffer.Ignore(chunkSize);

	//3. Call the near protocol
	if (!_pNearProtocol->SignalInputData(_inputBuffer)) {
		FATAL("Unable to call the next protocol in stack");
		return false;
	}

	//4. reset the state if necessary
	if (TransferCompleted()) {
		_headers.Reset();
		_contentLength = 0;
		_chunkedContent = false;
		_lastChunk = false;
		_state = HTTP_STATE_HEADERS;
		_sessionDecodedBytesCount = 0;
	}

	//5. we are done
	return true;
}
开发者ID:focusware,项目名称:crtmpserver,代码行数:35,代码来源:basehttpprotocol.cpp

示例6: PerformHandshake

bool OutboundRTMPProtocol::PerformHandshake(IOBuffer &buffer) {
	switch (_rtmpState) {
		case RTMP_STATE_NOT_INITIALIZED:
		{
			_encrypted = (VariantType) _customParameters[CONF_PROTOCOL] == V_STRING &&
					_customParameters[CONF_PROTOCOL] == CONF_PROTOCOL_OUTBOUND_RTMPE;
			_usedScheme = _encrypted ? 1 : 0;

			if ((VariantType) _customParameters[CONF_PROTOCOL] == V_STRING &&
					_customParameters[CONF_PROTOCOL] == CONF_PROTOCOL_OUTBOUND_RTMPE) {
				return PerformHandshakeStage1(true);
			} else {
				return PerformHandshakeStage1(false);
			}
		}
		case RTMP_STATE_CLIENT_REQUEST_SENT:
		{
			if (GETAVAILABLEBYTESCOUNT(buffer) < 3073)
				return true;

			if (!PerformHandshakeStage2(buffer, _encrypted)) {
				FATAL("Unable to handshake");
				return false;
			}

			if (_pFarProtocol != NULL) {
				if (!_pFarProtocol->EnqueueForOutbound()) {
					FATAL("Unable to signal output data");
					return false;
				}
			}

			if (_pKeyIn != NULL && _pKeyOut != NULL) {
				//insert the RTMPE protocol in the current protocol stack
				BaseProtocol *pFarProtocol = GetFarProtocol();
				RTMPEProtocol *pRTMPE = new RTMPEProtocol(_pKeyIn, _pKeyOut,
						GETAVAILABLEBYTESCOUNT(_outputBuffer));
				ResetFarProtocol();
				pFarProtocol->SetNearProtocol(pRTMPE);
				pRTMPE->SetNearProtocol(this);
				//FINEST("New protocol chain: %s", STR(*pFarProtocol));
			}

			if (!buffer.Ignore(3073)) {
				FATAL("Unable to ignore 3073 bytes");
				return false;
			}
			_handshakeCompleted = true;
			return true;
		}
		default:
		{
			FATAL("Invalid RTMP state: %d", _rtmpState);
			return false;
		}
	}
}
开发者ID:focusware,项目名称:crtmpserver,代码行数:57,代码来源:outboundrtmpprotocol.cpp

示例7: EventSocket

bool UXDomainSocketAppProtocolHandler::EventSocket(UnixDomainSocketProtocol *pFrom, IOBuffer &buffer) {
  uint32_t buflen = GETAVAILABLEBYTESCOUNT(buffer);

  while (buflen>=16) {
    uint8_t* pBuf=GETIBPOINTER(buffer);

    CHK_ALIGN4(pBuf);
    uint32_t msglen=*((uint32_t*)(pBuf+12));
    uint32_t total = PADDED_TOTAL(msglen+16);
    string data;

    if (buflen < total) {
      break;
    }
    uint16_t type=*((uint16_t*)(pBuf));
    uint32_t subType=*((uint16_t*)(pBuf+2));
    uint64_t eventInfo=0;

    DEBUG ("type:%d, subtype:%d", type, subType);
    //message has data
    if (msglen) {
      string temp((char*)(pBuf+16), msglen);
      data=temp;
    }
    QICStreamerApplication *pApp=
        static_cast<QICStreamerApplication*>(GetApplication());

    switch (type) {
      case (CLOUD_MSG_ERROR):
        pApp->SendError(subType, data);
        HardwareManager::SetStatus(subType, false);
        break;
      case (CLOUD_MSG_EVENT):
        eventInfo=*((uint64_t*)(pBuf+4));
        pApp->SendEvent(subType, eventInfo, data);
        break;
      case (DEVICE_EVENT):
        {
          RestCLIMessage restMessage;
          uint32_t start=0;
          ActionRouter *pActionRouter=pApp->GetActionRouter();
          Variant::DeserializeFromJSON(data, restMessage.request, start);
          pActionRouter->RouteRequestAction(restMessage);
        }
        break;
    }
    buffer.Ignore(total);
    buflen = GETAVAILABLEBYTESCOUNT(buffer);
  }

  return true;
}
开发者ID:OpenQCam,项目名称:qcam,代码行数:52,代码来源:uxdomainsocketappprotocolhandler.cpp

示例8: Deserialize

bool StreamCapabilities::Deserialize(IOBuffer &src, StreamCapabilities &capabilities) {
	uint8_t *pBuffer = GETIBPOINTER(src);
	uint32_t length = GETAVAILABLEBYTESCOUNT(src);
	if (length < 28) {
		FATAL("Not enough data");
		return false;
	}
	uint64_t ver = ENTOHLLP(pBuffer);
	if (ver != __STREAM_CAPABILITIES_VERSION) {
		FATAL("Invalid stream capabilities version. Wanted: %"PRIu64"; Got: %"PRIu64,
				__STREAM_CAPABILITIES_VERSION, ver);
		return false;
	}
	capabilities.Clear();
	capabilities.videoCodecId = ENTOHLLP(pBuffer + 8);
	capabilities.audioCodecId = ENTOHLLP(pBuffer + 16);
	capabilities.bandwidthHint = ENTOHLP(pBuffer + 24);
	src.Ignore(28);
	switch (capabilities.videoCodecId) {
		case CODEC_VIDEO_AVC:
		{
			if (!_VIDEO_AVC::Deserialize(src, capabilities.avc)) {
				FATAL("Unable to deserialize avc");
				return false;
			}
			break;
		}
		default:
		{
			break;
		}
	}
	switch (capabilities.audioCodecId) {
		case CODEC_AUDIO_AAC:
		{
			if (!_AUDIO_AAC::Deserialize(src, capabilities.aac)) {
				FATAL("Unable to deserialize aac");
				return false;
			}
			break;
		}
		default:
		{
			break;
		}
	}
	return true;
}
开发者ID:OpenQCam,项目名称:qcam,代码行数:48,代码来源:streamcapabilities.cpp

示例9: IpcEventSocket

bool UXDomainSocketAppProtocolHandler::IpcEventSocket(UnixDomainSocketProtocol *pFrom, IOBuffer &buffer) {
    uint32_t length = GETAVAILABLEBYTESCOUNT(buffer);
    uint8_t *pBuf = GETIBPOINTER(buffer);
    BaseAVCVideoCapture *_pAVCCaptureInstance;

    _pAVCCaptureInstance = reinterpret_cast<BaseAVCVideoCapture *>(HardwareManager::GetHardwareInstance(HT_VIDEO_AVC));

    printf ("buf length (%d): %s\n", length, pBuf);
    buffer.Ignore(length);

    _pAVCCaptureInstance->VerifyResolution(640,360);
    _pAVCCaptureInstance->SetResolution(640,360);

    UnixDomainSocketManager::SendResponseToIpcEvent ("2");

    return true;
}
开发者ID:OpenQCam,项目名称:qcam,代码行数:17,代码来源:uxdomainsocketappprotocolhandler.cpp

示例10: PerformSimpleHandshake

bool InboundRTMPProtocol::PerformSimpleHandshake(IOBuffer &buffer) {
	if (_pOutputBuffer == NULL) {
		_pOutputBuffer = new uint8_t[1536];
	} else {
		delete[] _pOutputBuffer;
		_pOutputBuffer = new uint8_t[1536];
	}

	for (uint32_t i = 0; i < 1536; i++) {
		_pOutputBuffer[i] = rand() % 256;
	}
	for (uint32_t i = 0; i < 10; i++) {
		uint32_t index = (rand() + 8) % (1536 - HTTP_HEADERS_SERVER_US_LEN);
		memcpy(_pOutputBuffer + index, HTTP_HEADERS_SERVER_US, HTTP_HEADERS_SERVER_US_LEN);
	}

	_outputBuffer.ReadFromByte(3);
	_outputBuffer.ReadFromBuffer(_pOutputBuffer, 1536);
	_outputBuffer.ReadFromBuffer(GETIBPOINTER(buffer), 1536);

	//final cleanup
	delete[] _pOutputBuffer;
	_pOutputBuffer = NULL;
	if (!buffer.Ignore(1536)) {
		FATAL("Unable to ignore input buffer");
		return false;
	}

	//signal outbound data
	if (!EnqueueForOutbound()) {
		FATAL("Unable to signal outbound data");
		return false;
	}

	//move to the next stage in the handshake
	_rtmpState = RTMP_STATE_SERVER_RESPONSE_SENT;

	return true;
}
开发者ID:2php,项目名称:crtmpserver-1,代码行数:39,代码来源:inboundrtmpprotocol.cpp

示例11: InfoSocket

bool UXDomainSocketAppProtocolHandler::InfoSocket(UnixDomainSocketProtocol *pFrom, IOBuffer &buffer) {
  uint32_t avail=GETAVAILABLEBYTESCOUNT(buffer);
  QICStreamerApplication* pApp=
      reinterpret_cast<QICStreamerApplication*>(GetApplication());


  //DEBUG ("data:%s", STR(buffer.ToString()));
  while (avail>=12) {
    uint8_t* pBuf=GETIBPOINTER(buffer);
    CHK_ALIGN4(pBuf);
    uint32_t type=*((uint32_t*)(pBuf));
    uint32_t msgId=*((uint32_t*)(pBuf+4));
    uint32_t length=*((uint32_t*)(pBuf+8));
    uint32_t total=PADDED_TOTAL(length+12);

    if (avail<total)
      break;

    UnixDomainSocketManager::SendDataToUXCallback(msgId, (uint8_t*)(GETIBPOINTER(buffer)+12), length);

    if (type==INFO_OP_SYSTEMINFO) {
      pApp->SendInfo(INFO_SYSTEM, (uint8_t*)(GETIBPOINTER(buffer)+12), length);
    }
    else if (type==INFO_OP_CMD && length) {
      uint32_t errorCode=*((uint32_t*)(pBuf+12));

      if (errorCode!=EC_RESERVED) {
        pApp->SendError(ERROR_CODE(errorCode), ERROR_DESCRIPTION(errorCode));
      }
    }

    buffer.Ignore(total);
    avail=GETAVAILABLEBYTESCOUNT(buffer);
  }
  return true;
}
开发者ID:OpenQCam,项目名称:qcam,代码行数:36,代码来源:uxdomainsocketappprotocolhandler.cpp

示例12: ParseUXDomainSocketData

inline void UXDomainSocketAppProtocolHandler::ParseUXDomainSocketData(queue<UXSocketData*> &socketData, IOBuffer &buffer) {
  uint32_t length = GETAVAILABLEBYTESCOUNT(buffer);

  while (length>=12) {
    UXSocketData *pSocketData = (UXSocketData*) new UXSocketData();
    uint8_t *pBuf = GETIBPOINTER(buffer);

    CHK_ALIGN4(pBuf);
    pSocketData->type = (*pBuf);
    pSocketData->id = *((uint32_t*)(pBuf+4));
    pSocketData->dataLength = *((uint32_t*)(pBuf+8));
    uint32_t total=PADDED_TOTAL(pSocketData->dataLength+12);

    if (length<total) {
      delete pSocketData;
      break;
    } else {
      pSocketData->dataBuffer.ReadFromBuffer(pBuf+12, pSocketData->dataLength);
      buffer.Ignore(total);
      socketData.push(pSocketData);
    }
    length = GETAVAILABLEBYTESCOUNT(buffer);
  }
}
开发者ID:OpenQCam,项目名称:qcam,代码行数:24,代码来源:uxdomainsocketappprotocolhandler.cpp

示例13: STR

bool InboundHTTP4RTMP::SignalInputData(IOBuffer &buffer) {
	//1. Get the HTTP far protool and test to see if it has ContentLength
	InboundHTTPProtocol *pHTTP = (InboundHTTPProtocol *) _pFarProtocol;
	if (pHTTP == NULL || pHTTP->GetContentLength() == 0) {
		FATAL("Invalid HTTP request");
		return false;
	}

	//2. Test it and see if all the data was transfered
	if (!pHTTP->TransferCompleted()) {
		return true;
	}

	//3. Get the HTTP request
	Variant request = pHTTP->GetHeaders();

	//4. Is this a keep-alive?
	pHTTP->SetDisconnectAfterTransfer(
			request[HTTP_HEADERS][HTTP_HEADERS_CONNECTION]
			!= HTTP_HEADERS_CONNECTION_KEEP_ALIVE);
	DeleteNearProtocol(false);

	//4. Get the URL
	string url = request[HTTP_FIRST_LINE][HTTP_URL];

	//5. split it in meaningful parts
	vector<string> parts;
	split(url, "/", parts);
	if (parts.size() < 2) {
		FATAL("Invalid request:\n%s", STR(request.ToString()));
		return false;
	}

	//7. Do the dammage
	bool result;
	if (parts[1] == "fcs") {
		result = ProcessFcs(parts);
		buffer.Ignore(pHTTP->GetContentLength());
	} else if (parts[1] == "open") {
		result = ProcessOpen(parts);
		buffer.Ignore(pHTTP->GetContentLength());
	} else if (parts[1] == "idle") {
		result = ProcessIdle(parts);
		buffer.Ignore(pHTTP->GetContentLength());
	} else if (parts[1] == "send") {
		if (GETAVAILABLEBYTESCOUNT(buffer) < 1)
			return false;
		_inputBuffer.ReadFromBuffer(GETIBPOINTER(buffer), pHTTP->GetContentLength());
		buffer.Ignore(pHTTP->GetContentLength());
		result = ProcessSend(parts);
	} else {
		FATAL("Invalid command: %s", STR(parts[1]));
		result = false;
	}

	//8. Cleanup
	if (!result) {
		DeleteNearProtocol(true);
		EnqueueForDelete();
	}

	//9. Done
	return result;
}
开发者ID:Undev,项目名称:crtmpserver,代码行数:64,代码来源:inboundhttp4rtmp.cpp

示例14: HandleChunkedContent

bool BaseHTTPProtocol::HandleChunkedContent(IOBuffer &buffer) {
	//2. We cycle until we don't have any complete chunks anymore
	//or we hit the 0 bytes chunks (end of chunked content)
	uint8_t *pBuffer = NULL;
	uint32_t chunkSize = 0;
	uint32_t chunkSizeSize = 0;
	while (GETAVAILABLEBYTESCOUNT(buffer) >= 3) {
		//1. Get the raw pointer. We need it almost everywhere
		pBuffer = GETIBPOINTER(buffer);
		//FINEST("%s", STR(buffer));

		chunkSizeSize = 0;
		//3. Read the string which represents the number of bytes in the chunk
		for (uint32_t i = 0; i < GETAVAILABLEBYTESCOUNT(buffer) - 1; i++) {
			//5. Are we at the end of chunk size string?
			if ((pBuffer[i] == 0x0d) && (pBuffer[i + 1] == 0x0a)) {
				chunkSizeSize = i + 2;
				break;
			}

			//4. If the chunk size string has more than 10 bytes, we drop it like
			//is hot! Also test each char to be a hex number.
			//This is a bogus request/response
			if (i >= 10 || (!(((pBuffer[i] >= '0') && (pBuffer[i] <= '9'))
					|| ((pBuffer[i] >= 'a') && (pBuffer[i] <= 'f'))
					|| ((pBuffer[i] >= 'A') && (pBuffer[i] <= 'F'))))) {
				FATAL("Unable to read chunk size length:\n%s", STR(buffer));
				return false;
			}
		}
		//7. Test the newly extracted chunk size
		if (chunkSizeSize == 0) {
			return true;
		}

		//8. Get its actual value and test it as well
		chunkSize = strtol((char *) pBuffer, NULL, 16);
		if (chunkSize > HTTP_MAX_CHUNK_SIZE) {
			FATAL("Chunk size too large. Maximum allowed is %" PRIu32 " and we got %" PRIu32,
					(uint32_t) HTTP_MAX_CHUNK_SIZE, chunkSize);
			return false;
		}

		//9. Now, we know the chunk size... do we have enough data?
		if (GETAVAILABLEBYTESCOUNT(buffer) <
				chunkSizeSize //length of the chunk size string
				- 2 //substract the 0x particle
				+ 2 //the \r\n that follows the chunk size string
				+ chunkSize //chunk size itself
				+ 2 //the \r\n that follows the data chunk
				) {
			return true;
		}

		//10. Update the session decoded bytes count and decoded bytes count
		_sessionDecodedBytesCount += chunkSize;
		_decodedBytesCount += chunkSize;

		if (chunkSize != 0) {
			//11. Make the copy
			_contentLength += chunkSize;
			_inputBuffer.ReadFromBuffer(GETIBPOINTER(buffer) + chunkSizeSize - 2 + 2, chunkSize);
		} else {
			//12. This was the last chunk (0 bytes size)
			_lastChunk = true;
		}

		//12. Call the near protocol
		if (!_pNearProtocol->SignalInputData(_inputBuffer)) {
			FATAL("Unable to call the next protocol in stack");
			return false;
		}

		//13. Ignore the bytes from the input buffer
		DEBUG_HTTP("available bytes before ignore: %" PRIu32, GETAVAILABLEBYTESCOUNT(buffer));
		//				if (GETAVAILABLEBYTESCOUNT(buffer) == ((uint32_t) chunkSizeSize - 2 + 2 + chunkSize + 2)) {
		//					DEBUG_HTTP("%s", STR(buffer));
		//				}
		buffer.Ignore((uint32_t) chunkSizeSize - 2 + 2 + chunkSize + 2);
		DEBUG_HTTP("available bytes  after ignore: %" PRIu32, GETAVAILABLEBYTESCOUNT(buffer));

		//14. reset the state if necessary
		if (TransferCompleted()) {
			_headers.Reset();
			_chunkedContent = false;
			_lastChunk = false;
			_contentLength = 0;
			_state = HTTP_STATE_HEADERS;
			_sessionDecodedBytesCount = 0;
			return true;
		}
	}
	return true;
}
开发者ID:focusware,项目名称:crtmpserver,代码行数:94,代码来源:basehttpprotocol.cpp

示例15: ParseHeaders

bool BaseHTTPProtocol::ParseHeaders(IOBuffer& buffer) {
	//1. We have to have at least 4 bytes (double \r\n)
	if (GETAVAILABLEBYTESCOUNT(buffer) < 4) {
		return true;
	}

	//2. Detect the headers boundaries
	uint32_t headersSize = 0;
	bool markerFound = false;
	uint8_t *pBuffer = GETIBPOINTER(buffer);
	for (uint32_t i = 0; i <= GETAVAILABLEBYTESCOUNT(buffer) - 4; i++) {
		if ((pBuffer[i] == 0x0d)
				&& (pBuffer[i + 1] == 0x0a)
				&& (pBuffer[i + 2] == 0x0d)
				&& (pBuffer[i + 3] == 0x0a)) {
			markerFound = true;
			headersSize = i;
			break;
		}
		if (i >= HTTP_MAX_HEADERS_SIZE) {
			FATAL("Headers section too long");
			return false;
		}
	}

	//3. Are the boundaries correct?
	//Do we have enough data to parse the headers?
	if (headersSize == 0) {
		if (markerFound)
			return false;
		else
			return true;
	}

	//4. Get the raw headers and plit it into lines
	string rawHeaders = string((char *) GETIBPOINTER(buffer), headersSize);
	vector<string> lines;
	split(rawHeaders, "\r\n", lines);
	if (lines.size() == 0) {
		FATAL("Incorrect HTTP request");
		return false;
	}

	//4. Get the fisrt line and parse it. This is either a status code
	//for a previous request made by us, or the request that we just received
	if (!ParseFirstLine(lines[0], _headers[HTTP_FIRST_LINE])) {
		FATAL("Unable to parse the first line");
		return false;
	}

	//5. Consider the rest of the lines as key: value pairs and store them
	//0. Reset the headers
	_headers[HTTP_HEADERS].IsArray(false);
	for (uint32_t i = 1; i < lines.size(); i++) {
		string line = lines[i];
		string::size_type splitterPos = line.find(": ");

		if ((splitterPos == string::npos)
				|| (splitterPos == 0)
				|| (splitterPos == line.size() - 2)) {
			FATAL("Invalid header line");
			return false;
		}
		_headers[HTTP_HEADERS][line.substr(0, splitterPos)] = line.substr(splitterPos + 2, string::npos);
	}

	//6. default a transfer type to Content-Length: 0 if necessary
	if ((!_headers[HTTP_HEADERS].HasKey(HTTP_HEADERS_CONTENT_LENGTH, false)) &&
			(!_headers[HTTP_HEADERS].HasKey(HTTP_HEADERS_TRANSFER_ENCODING, false))) {
		_headers[HTTP_HEADERS][HTTP_HEADERS_CONTENT_LENGTH] = "0";
	}

	//7. read the transfer type and set this request or response flags
	if (_headers[HTTP_HEADERS].HasKey(HTTP_HEADERS_CONTENT_LENGTH, false)) {
		string contentLengthString = _headers[HTTP_HEADERS].GetValue(
				HTTP_HEADERS_CONTENT_LENGTH, false);
		replace(contentLengthString, " ", "");
		if (!isNumeric(contentLengthString)) {
			FATAL("Invalid HTTP headers:\n%s", STR(_headers.ToString()));
			return false;
		}
		_contentLength = atoi(STR(contentLengthString));
		_chunkedContent = false;
		_lastChunk = false;
	} else if (_headers[HTTP_HEADERS].HasKey(HTTP_HEADERS_TRANSFER_ENCODING, false)) {
		if (lowerCase(_headers[HTTP_HEADERS].GetValue(HTTP_HEADERS_TRANSFER_ENCODING, false)) !=
				lowerCase(HTTP_HEADERS_TRANSFER_ENCODING_CHUNKED)) {
			FATAL("The only supported %s is %s",
					HTTP_HEADERS_TRANSFER_ENCODING,
					HTTP_HEADERS_TRANSFER_ENCODING_CHUNKED);
			return false;
		}
		_chunkedContent = true;
		_lastChunk = false;
		_contentLength = 0;
	}

	//7. Advance the state and ignore the headers part from the buffer
	_state = HTTP_STATE_PAYLOAD;
	buffer.Ignore(headersSize + 4);
//.........这里部分代码省略.........
开发者ID:focusware,项目名称:crtmpserver,代码行数:101,代码来源:basehttpprotocol.cpp


注:本文中的IOBuffer::Ignore方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。