Example #1
0
mUpnpSSDPRequest *mupnp_ssdprequest_new()
{
	mUpnpSSDPRequest *ssdpReq;

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

	ssdpReq = mupnp_http_request_new();
	
	mupnp_http_request_seturi(ssdpReq, "*");
	mupnp_http_request_setversion(ssdpReq, MUPNP_HTTP_VER11);
	mupnp_http_request_setcontentlength(ssdpReq, 0);

	mupnp_log_debug_l4("Leaving...\n");
	
	return ssdpReq;
}
Example #2
0
void mupnp_soap_request_setcontent(mUpnpSoapRequest *soapReq, mUpnpXmlNode *node)
{
	mUpnpHttpRequest *httpReq;
		
	mupnp_log_debug_l4("Entering...\n");

	httpReq = mupnp_soap_request_gethttprequest(soapReq);
	
	/**** content type ****/
	mupnp_http_request_setcontenttype(httpReq, MUPNP_XML_CONTENT_TYPE);
	
	/**** content ****/
	mupnp_http_request_appendncontent(httpReq, MUPNP_SOAP_VERSION_HEADER,
					mupnp_strlen(MUPNP_SOAP_VERSION_HEADER));
	mupnp_http_request_appendncontent(httpReq, MUPNP_XML_CONTENT_LF,
					mupnp_strlen(MUPNP_XML_CONTENT_LF));
	mupnp_xml_node_tostring(node, true, httpReq->content);
		
	/**** content length ****/
	mupnp_http_request_setcontentlength(httpReq,
					 mupnp_string_length(httpReq->content));

	mupnp_log_debug_l4("Leaving...\n");
}
Example #3
0
bool round_remote_node_posthttpjsonrequest(RoundRemoteNode* node, const char* reqContent, RoundJSONObject** resObj, RoundError* err)
{
  const char* remoteAddr = NULL;
  int remotePort = 0;
  if (!round_remote_node_getaddress(node, &remoteAddr) || !round_remote_node_getport(node, &remotePort)) {
    round_node_rpcerrorcode2error(node, ROUND_RPC_ERROR_CODE_INTERNAL_ERROR, err);
    return false;
  }

  mUpnpHttpRequest* httpReq = mupnp_http_request_new();
  if (!httpReq) {
    round_node_rpcerrorcode2error(node, ROUND_RPC_ERROR_CODE_INTERNAL_ERROR, err);
    return false;
  }

  mupnp_http_request_setmethod(httpReq, MUPNP_HTTP_POST);
  mupnp_http_request_seturi(httpReq, ROUND_RPC_HTTP_ENDPOINT);
  mupnp_http_request_setcontent(httpReq, reqContent);
  mupnp_http_request_setcontentlength(httpReq, mupnp_strlen(reqContent));

  mUpnpHttpResponse* httpRes = mupnp_http_request_post(httpReq, remoteAddr, remotePort);
  if (!httpRes) {
    round_node_rpcerrorcode2error(node, ROUND_RPC_ERROR_CODE_BAD_DESTINATION, err);
    mupnp_http_request_delete(httpReq);
    return false;
  }

  const char* resContent = mupnp_http_response_getcontent(httpRes);
  if (round_strlen(resContent) <= 0) {
    round_node_rpcerrorcode2error(node, ROUND_RPC_ERROR_CODE_BAD_DESTINATION, err);
    mupnp_http_request_delete(httpReq);
    return false;
  }

  // Set JSON Response

  RoundJSON* json = round_json_new();
  if (!json) {
    round_node_rpcerrorcode2error(node, ROUND_RPC_ERROR_CODE_INTERNAL_ERROR, err);
    mupnp_http_request_delete(httpReq);
  }

  *resObj = NULL;
  if (round_json_parse(json, resContent, err)) {
    *resObj = round_json_poprootobject(json);
  }

  round_json_delete(json);

  // Set Error Response

  if (!mupnp_http_response_issuccessful(httpRes)) {
    if (*resObj) {
      RoundJSONObject* errObj;
      if (round_json_rpc_geterror(*resObj, &errObj)) {
        round_error_setjsonrpcerror(err, errObj);
      }
    }
  }

  return true;
}