Esempio n. 1
0
mUpnpSoapRequest *mupnp_soap_request_new()
{
	mUpnpSoapRequest *soapReq;

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

	soapReq = (mUpnpSoapRequest *)malloc(sizeof(mUpnpSoapRequest));

	if ( NULL != soapReq )
	{
		soapReq->rootNodeList = mupnp_xml_nodelist_new();
		soapReq->soapRes = mupnp_soap_response_new();

		soapReq->httpReq = mupnp_http_request_new();
		soapReq->isHttpReqCreated = true;
		mupnp_http_request_setcontenttype(soapReq->httpReq, MUPNP_SOAP_CONTENT_TYPE);
		mupnp_http_request_setmethod(soapReq->httpReq, MUPNP_HTTP_POST);
	
		mupnp_soap_request_setuserdata(soapReq, NULL);
	}

	mupnp_log_debug_l4("Leaving...\n");
	
	return soapReq;
}
Esempio n. 2
0
void mupnp_event_subscription_request_setunsubscription(mUpnpSubscriptionRequest* subReq, mUpnpService* service)
{
  mupnp_log_debug_l4("Entering...\n");

  mupnp_http_request_setmethod(subReq, MUPNP_HTTP_UNSUBSCRIBE);
  mupnp_event_subscription_request_setservice(subReq, service);
  mupnp_event_subscription_request_setsid(subReq, mupnp_service_getsubscriptionsid(service));
  mupnp_log_debug_l4("Leaving...\n");
}
Esempio n. 3
0
void mupnp_event_subscription_request_setrenewsubscription(mUpnpSubscriptionRequest* subReq, mUpnpService* service, const char* uuid, mUpnpTime timeout)
{
  mupnp_log_debug_l4("Entering...\n");

  mupnp_http_request_setmethod(subReq, MUPNP_HTTP_SUBSCRIBE);
  mupnp_event_subscription_request_setservice(subReq, service);
  mupnp_event_subscription_request_setsid(subReq, uuid);
  mupnp_event_subscription_request_settimeout(subReq, timeout);
  mupnp_log_debug_l4("Leaving...\n");
}
Esempio n. 4
0
void mupnp_event_subscription_request_setnewsubscription(mUpnpSubscriptionRequest* subReq, mUpnpService* service, const char* callback, mUpnpTime timeout)
{
  mupnp_log_debug_l4("Entering...\n");

  mupnp_http_request_setmethod(subReq, MUPNP_HTTP_SUBSCRIBE);
  mupnp_event_subscription_request_setservice(subReq, service);
  mupnp_event_subscription_request_setcallback(subReq, callback);
  mupnp_event_subscription_request_setnt(subReq, MUPNP_NT_EVENT);
  mupnp_event_subscription_request_settimeout(subReq, timeout);
  mupnp_log_debug_l4("Leaving...\n");
}
Esempio n. 5
0
mUpnpSoapResponse *mupnp_soap_request_post(mUpnpSoapRequest *soapReq, const char *ipaddr, int port)
{
	mUpnpHttpResponse *httpRes;
	char *content;
	size_t contentLen;
	mUpnpXmlParser *xmlParser;
	mUpnpHttpHeader *header = NULL;
	
	mupnp_log_debug_l4("Entering...\n");

	httpRes = mupnp_http_request_post(soapReq->httpReq, ipaddr, port);
	
	/* Check for HTTP response 405 Method Not Allowed */
	if (mupnp_http_response_getstatuscode(httpRes) == MUPNP_HTTP_STATUS_METHOD_NOT_ALLOWED)
	{
		/* Status code implies that we need to use M-POST */
		mupnp_http_request_setmethod(soapReq->httpReq, MUPNP_HTTP_MPOST);
		
		/* Add MAN header */
		header = mupnp_http_header_new();
		mupnp_http_header_setname(header, MUPNP_HTTP_MAN);
		mupnp_http_header_setvalue(header, MUPNP_HTTP_SOAP_MAN_VALUE);
		mupnp_http_packet_addheader((mUpnpHttpPacket*)soapReq->httpReq, header);
		
		/* Change soapaction header name to include namespace */
		header = mupnp_http_packet_getheader((mUpnpHttpPacket*)soapReq->httpReq, 
						  MUPNP_HTTP_SOAP_ACTION);
		if (header != NULL)
		{
			mupnp_http_header_setname(header, MUPNP_HTTP_SOAP_ACTION_WITH_NS);
		}
		
		/* New attempt */
		httpRes = mupnp_http_request_post(soapReq->httpReq, ipaddr, port);
	}
	
	mupnp_soap_response_sethttpresponse(soapReq->soapRes,httpRes);

	content = mupnp_http_response_getcontent(httpRes);
	contentLen = mupnp_http_response_getcontentlength(httpRes);
	if (content == NULL || contentLen <= 0)
		return soapReq->soapRes;

	xmlParser = mupnp_xml_parser_new();
	mupnp_xml_parse(xmlParser, soapReq->soapRes->rootNodeList, content, contentLen);
	mupnp_xml_parser_delete(xmlParser);

	mupnp_log_debug_l4("Leaving...\n");
	
	return soapReq->soapRes;
}
Esempio n. 6
0
void mupnp_soap_request_clear(mUpnpSoapRequest *soapReq)
{
	mupnp_log_debug_l4("Entering...\n");

	mupnp_xml_nodelist_clear(soapReq->rootNodeList);

	if (soapReq->isHttpReqCreated == true)
		mupnp_http_request_delete(soapReq->httpReq);

	soapReq->httpReq = mupnp_http_request_new();
	soapReq->isHttpReqCreated = true;
	mupnp_http_request_setcontenttype(soapReq->httpReq, MUPNP_SOAP_CONTENT_TYPE);
	mupnp_http_request_setmethod(soapReq->httpReq, MUPNP_HTTP_POST);

	mupnp_log_debug_l4("Leaving...\n");
}
Esempio n. 7
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;
}