Example #1
0
bool mupnp_http_response_read(mUpnpHttpResponse* httpRes, mUpnpSocket* sock, bool onlyHeader)
{
  char lineBuf[MUPNP_HTTP_READLINE_BUFSIZE];
  mUpnpStringTokenizer* strTok;
  char* token;
  ssize_t readLen;

  mupnp_log_debug_l4("Entering...\n");

  mupnp_http_response_clear(httpRes);

  readLen = mupnp_socket_readline(sock, lineBuf, sizeof(lineBuf));
  if (readLen <= 0)
    return false;

  strTok = mupnp_string_tokenizer_new(lineBuf, MUPNP_HTTP_STATUSLINE_DELIM);
  if (mupnp_string_tokenizer_hasmoretoken(strTok) == true)
    mupnp_http_response_setversion(httpRes, mupnp_string_tokenizer_nexttoken(strTok));
  if (mupnp_string_tokenizer_hasmoretoken(strTok) == true)
    mupnp_http_response_setstatuscode(httpRes, atoi(mupnp_string_tokenizer_nexttoken(strTok)));
  if (mupnp_string_tokenizer_hasmoretoken(strTok) == true) {
    token = mupnp_string_tokenizer_nextalltoken(strTok);
    mupnp_strrtrim(token, MUPNP_HTTP_STATUSLINE_DELIM, mupnp_strlen(MUPNP_HTTP_STATUSLINE_DELIM));
    mupnp_http_response_setreasonphrase(httpRes, token);
  }
  mupnp_string_tokenizer_delete(strTok);

  mupnp_http_packet_read((mUpnpHttpPacket*)httpRes, sock, onlyHeader, lineBuf, sizeof(lineBuf));

  mupnp_log_debug_l4("Leaving...\n");

  return true;
}
Example #2
0
void mupnp_ssdp_packet_setheader(mUpnpSSDPPacket *ssdpPkt, char *ssdpMsg)
{
	mUpnpStringTokenizer *ssdpTok;
	mUpnpStringTokenizer *ssdpLineTok;
	mUpnpHttpHeader *header;
	char *lineMsg;
	char *name;
	char *value;
		
	mupnp_log_debug_l4("Entering...\n");

	ssdpTok = mupnp_string_tokenizer_new(ssdpMsg, MUPNP_HTTP_CRLF);

	/**** skip the first line ****/	
	if (mupnp_string_tokenizer_hasmoretoken(ssdpTok) == false)
		return;
	lineMsg = mupnp_string_tokenizer_nexttoken(ssdpTok);
	
	while (mupnp_string_tokenizer_hasmoretoken(ssdpTok) == true) {
		lineMsg = mupnp_string_tokenizer_nexttoken(ssdpTok);
		name = NULL;
		value = NULL;
		ssdpLineTok = mupnp_string_tokenizer_new(lineMsg, MUPNP_HTTP_HEADERLINE_DELIM);
		if (mupnp_string_tokenizer_hasmoretoken(ssdpLineTok) == true)
			name = mupnp_string_tokenizer_nexttoken(ssdpLineTok);
		if (mupnp_string_tokenizer_hasmoretoken(ssdpLineTok) == true) {
			value = mupnp_string_tokenizer_nextalltoken(ssdpLineTok);
			mupnp_strrtrim(value, MUPNP_HTTP_HEADERLINE_DELIM, mupnp_strlen(MUPNP_HTTP_HEADERLINE_DELIM));
		}
		if (name != NULL) {
			if (value == NULL)
				value = "";
			header = mupnp_http_header_new();
			mupnp_http_header_setname(header, name);
			mupnp_http_header_setvalue(header, value);
			mupnp_http_headerlist_add(ssdpPkt->headerList, header);
		}
		mupnp_string_tokenizer_delete(ssdpLineTok);
	}

	mupnp_string_tokenizer_delete(ssdpTok);

	mupnp_log_debug_l4("Leaving...\n");
}