예제 #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;
}
예제 #2
0
void mupnp_control_action_response_setresponse(mUpnpActionResponse *actionRes, mUpnpAction *action)
{
	mUpnpSoapResponse *soapRes;
	mUpnpHttpResponse *httpRes;
	mUpnpXmlNode *bodyNode;
	mUpnpXmlNode *resNode;
	mUpnpXmlNode *envNode;

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

	soapRes = mupnp_control_action_response_getsoapresponse(actionRes);
	httpRes = mupnp_soap_response_gethttpresponse(soapRes);

	mupnp_http_response_setstatuscode(httpRes, MUPNP_HTTP_STATUS_OK);
	mupnp_control_soap_response_initializeenvelopenode(soapRes);

	bodyNode = mupnp_soap_response_getbodynode(soapRes);
	resNode = mupnp_control_action_response_createresponsenode(action);
	mupnp_xml_node_addchildnode(bodyNode, resNode);
	
	envNode = mupnp_soap_response_getenvelopenode(soapRes);
	mupnp_soap_response_setcontent(soapRes, envNode);

	mupnp_log_debug_l4("Leaving...\n");
}
예제 #3
0
void mupnp_http_response_clear(mUpnpHttpResponse* httpRes)
{
  mupnp_log_debug_l4("Entering...\n");

  mupnp_http_packet_clear((mUpnpHttpPacket*)httpRes);
  mupnp_http_response_setversion(httpRes, NULL);
  mupnp_http_response_setstatuscode(httpRes, MUPNP_HTTP_STATUS_INTERNAL_SERVER_ERROR);
  mupnp_http_response_setreasonphrase(httpRes, NULL);
  mupnp_http_response_setuserdata(httpRes, NULL);

  mupnp_log_debug_l4("Leaving...\n");
}
예제 #4
0
void mupnp_http_response_copy(mUpnpHttpResponse* destHttpRes, mUpnpHttpResponse* srcHttpRes)
{
  mupnp_log_debug_l4("Entering...\n");

  mupnp_http_response_setversion(destHttpRes, mupnp_http_response_getversion(srcHttpRes));
  mupnp_http_response_setstatuscode(destHttpRes, mupnp_http_response_getstatuscode(srcHttpRes));
  mupnp_http_response_setreasonphrase(destHttpRes, mupnp_http_response_getreasonphrase(srcHttpRes));

  mupnp_http_packet_copy((mUpnpHttpPacket*)destHttpRes, (mUpnpHttpPacket*)srcHttpRes);

  mupnp_log_debug_l4("Leaving...\n");
}
예제 #5
0
파일: HttpTest.cpp 프로젝트: Coramo/mupnp
void ClinkTestcaseHttpRequestRecieved(mUpnpHttpRequest* httpReq)
{
  mUpnpHttpResponse* httpRes;

  httpRes = mupnp_http_response_new();
  mupnp_http_response_setstatuscode(httpRes, MUPNP_HTTP_STATUS_OK);
  mupnp_http_response_setcontent(httpRes, MUPNP_TESTCASE_HTTP_PAGE);
  mupnp_http_response_setcontenttype(httpRes, "text/html");
  mupnp_http_response_setcontentlength(httpRes, strlen(MUPNP_TESTCASE_HTTP_PAGE));
  mupnp_http_request_postresponse(httpReq, httpRes);
  mupnp_http_response_delete(httpRes);
}
예제 #6
0
void mupnp_event_subscription_subscriberesponse_setresponse(mUpnpSubscriptionResponse* subRes, int code)
{
  char server[MUPNP_SEVERNAME_MAXLEN];
  mupnp_log_debug_l4("Entering...\n");

  mupnp_http_response_setstatuscode(subRes, code);
  mupnp_getservername(server, sizeof(server));
  mupnp_http_packet_setheadervalue(((mUpnpHttpPacket*)subRes),
      MUPNP_HTTP_SERVER,
      server);
  mupnp_http_response_setcontentlength(subRes, 0);

  mupnp_log_debug_l4("Leaving...\n");
}
예제 #7
0
void round_upnp_server_httprequestrecieved(mUpnpHttpRequest* httpReq)
{
  RoundRpcServer* server = round_upnp_server_getrpcserverfromrequest(httpReq);

  if (server && round_upnp_server_isjsonrpcrequest(httpReq)) {
    // TODO : Change to post message queue
    // round_upnp_server_postrpcrequest(NULL, httpReq);
    server->upnpServer->rpcReqListener(httpReq);
    return;
  }
  else if (round_upnp_server_isrootrequest(httpReq)) {
    mUpnpHttpResponse* httpRes = mupnp_http_response_new();
    mupnp_http_response_setstatuscode(httpRes, MUPNP_HTTP_STATUS_OK);
    mupnp_http_response_setcontentlength(httpRes, 0);
    mupnp_http_request_postresponse(httpReq, httpRes);
    mupnp_http_response_delete(httpRes);
    return;
  }

  mupnp_device_httprequestrecieved(httpReq);
}
예제 #8
0
mUpnpHttpResponse* mupnp_http_response_new()
{
  mUpnpHttpResponse* httpRes;

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

  httpRes = (mUpnpHttpResponse*)malloc(sizeof(mUpnpHttpResponse));

  if (NULL != httpRes) {
    mupnp_http_packet_init((mUpnpHttpPacket*)httpRes);
    httpRes->version = mupnp_string_new();
    httpRes->reasonPhrase = mupnp_string_new();

    mupnp_http_response_setversion(httpRes, MUPNP_HTTP_VER11);
    mupnp_http_response_setstatuscode(httpRes, MUPNP_HTTP_STATUS_BAD_REQUEST);
    mupnp_http_response_setuserdata(httpRes, NULL);

    mupnp_http_response_settimeout(httpRes, MUPNP_HTTP_CONN_TIMEOUT);
  }

  return httpRes;

  mupnp_log_debug_l4("Leaving...\n");
}
예제 #9
0
void upnp_clock_device_httprequestrecieved(mUpnpHttpRequest *httpReq)
{
	mUpnpTime currTime;
	mUpnpDevice *dev;
	char *uri;
	char content[2048];
	char sysTimeStr[SYSTEM_TIME_BUF_LEN];
	char serverName[MUPNP_SEVERNAME_MAXLEN];
	mUpnpHttpResponse *httpRes;
	BOOL postRet;
	
	dev = (mUpnpDevice *)mupnp_http_request_getuserdata(httpReq);

	uri = mupnp_http_request_geturi(httpReq);
	if (strcmp(uri, "/presentation") != 0) {
		mupnp_device_httprequestrecieved(httpReq);
		return;
	}

	currTime = mupnp_getcurrentsystemtime();

#if defined(HAVE_SNPRINTF)
	snprintf(content, sizeof(content),
#else
	sprintf(content,
#endif
		"<HTML>"
		"<HEAD>"
		"<TITLE>UPnP Clock Sample</TITLE>"
		"</HEAD>"
		"<META HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=/presentation\">"
		"<BODY><CENTER>"
		"<H1>UPnP Clock Sample</H1>"
		"<TABLE border=\"0\" cellpadding=\"0\" cellspacing=\"0\">"
		"<TR>"
		"<TD style=\"width: 50px; height: 50px; background-color: rgb(176, 176, 176);\"></TD>"
		"<TD style=\"background-color: rgb(176, 176, 176);\"></TD>"
		"<TD style=\"width: 50px; height: 50px; background-color: rgb(176, 176, 176);\"></TD>"
		"</TR>"
		"<TR>"
		"<TD style=\"height: 50px; background-color: rgb(176, 176, 176);\"></TD>"
		"<TD style=\"height: 50px; background-color: rgb(221, 236, 245);\" align=\"center\"><H1>"
		"%s"
		"</H1></TD>"
		"<TD style=\"height: 50px; background-color: rgb(176, 176, 176);\"></TD>"
		"</TR>"
		"<TR>"
		"<TD style=\"height: 50px; background-color: rgb(176, 176, 176);\"></TD>"
		"<TD style=\"height: 50px; background-color: rgb(221, 236, 245);\" align=\"center\"><H3>"
		"Server : %s"
		"</H3></TD>"
		"<TD style=\"height: 30px; background-color: rgb(176, 176, 176);\"></TD>"
		"</TR>"
		"<TR>"
		"<TD style=\"width: 30px; height: 50px; background-color: rgb(176, 176, 176);\"></TD>"
		"<TD style=\"background-color: rgb(176, 176, 176);\"></TD>"
		"<TD style=\"width: 30px; height: 50px; background-color: rgb(176, 176, 176);\"></TD>"
		"</TR>"
		"</TABLE>"
		"<CENTER></BODY>"
		"</HTML>",
		GetSystemTimeString(currTime, sysTimeStr),
		mupnp_getservername(serverName, sizeof(serverName)));

	httpRes = mupnp_http_response_new();
	mupnp_http_response_setstatuscode(httpRes, CG_HTTP_STATUS_OK);
	mupnp_http_response_setcontent(httpRes, content);
	mupnp_http_response_setcontenttype(httpRes, "text/html");
	mupnp_http_response_setcontentlength(httpRes, strlen(content));
	postRet = mupnp_http_request_postresponse(httpReq, httpRes);
	mupnp_http_response_delete(httpRes);
}