Exemplo 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;
}
Exemplo n.º 2
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");
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
0
static void mupnp_http_server_clientthread(mUpnpThread *thread)
{
	mUpnpHttpServerClientData *clientData;
	mUpnpHttpServer *httpServer;
	mUpnpSocket *clientSock;
	void *httpServerUserData;
	mUpnpHttpRequest *httpReq;
	char *version = NULL;

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

	clientData = (mUpnpHttpServerClientData *)mupnp_thread_getuserdata(thread);
	httpServer = clientData->httpServer;
	clientSock = clientData->clientSock;
	httpServerUserData = mupnp_http_server_getuserdata(httpServer);

	httpReq = mupnp_http_request_new();
	mupnp_http_request_setsocket(httpReq, clientSock);

	/**** Thanks for Makela Aapo (10/31/05) ****/
	while (mupnp_http_request_read(httpReq, clientSock) == true && mupnp_thread_isrunnable(thread) == true) {
		/* Check some validity of the request */
		version = mupnp_http_request_getversion(httpReq);
		if (mupnp_strcmp(version, MUPNP_HTTP_VER11) == 0)
		{
			/* According to HTTP/1.1 spec, we must not tolerate
			   HTTP/1.1 request without HOST-header */
			if (mupnp_http_request_gethost(httpReq) == NULL)
			{
				mupnp_http_request_postbadrequest(httpReq);
				continue;
			}
		}

		if (httpServer->listener != NULL) {
            mupnp_http_request_setuserdata(httpReq, httpServerUserData);
			httpServer->listener(httpReq);
		}

		/* Close connection according to HTTP version and headers */
		if (mupnp_strcmp(version, MUPNP_HTTP_VER10) == 0)
		{
			/* Terminate connection after HTTP/1.0 request */
			break;
		}

		/* We are having HTTP/1.1 or better => terminate, if requested */
		if (mupnp_http_request_iskeepaliveconnection(httpReq) == false)
		{
			break;
		}
	}

	mupnp_log_debug_s("Dropping HTTP client\n");
	mupnp_http_request_delete(httpReq);

	mupnp_socket_close(clientSock);
	mupnp_socket_delete(clientSock);

	mupnp_http_server_clientdata_delete(clientData);
	mupnp_thread_setuserdata(thread, NULL);

    // This code frequently crashes. mutex lock referencing free'd memory.
	mupnp_http_server_lock(httpServer);
	mupnp_thread_remove(thread);
	mupnp_http_server_unlock(httpServer);

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

	mupnp_thread_delete(thread);
}
Exemplo n.º 5
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;
}