Exemplo n.º 1
0
mUpnpAvProtocolInfo *mupnp_upnpav_protocolinfo_new()
{
	mUpnpAvProtocolInfo *info;

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

	info = (mUpnpAvProtocolInfo *)malloc(sizeof(mUpnpAvProtocolInfo));

	if  ( NULL != info ) {
		mupnp_list_node_init((mUpnpList *)info);

		info->protocol = mupnp_string_new();
		info->network = mupnp_string_new();
		info->mimeType = mupnp_string_new();
		info->additionalInfo = mupnp_string_new();
		info->string = mupnp_string_new();

		mupnp_upnpav_protocolinfo_setprotocol(info, "*");
		mupnp_upnpav_protocolinfo_setnetwork(info, "*");
		mupnp_upnpav_protocolinfo_setmimetype(info, "*");
		mupnp_upnpav_protocolinfo_setadditionainfo(info, "*");
    }
	mupnp_log_debug_l4("Leaving...\n");

	return info;
}
Exemplo n.º 2
0
mUpnpXmlNode *mupnp_xml_node_new()
{
	mUpnpXmlNode *node;
	
	mupnp_log_debug_l4("Entering...\n");

	node = (mUpnpXmlNode *)malloc(sizeof(mUpnpXmlNode));

	if ( NULL != node )
	{
		mupnp_list_node_init((mUpnpList *)node);

		node->name = mupnp_string_new();
		node->value = mupnp_string_new();
		node->attrList = mupnp_xml_attributelist_new();
		node->nodeList = mupnp_xml_nodelist_new();
		node->parentNode = NULL;
		node->userData = NULL;
		node->userDataDestructorFunc = NULL;
	}

	mupnp_log_debug_l4("Leaving...\n");
	
	return node;
}
Exemplo n.º 3
0
mUpnpHttpPersistentConnection *mupnp_http_persistentconnection_new(void)
{
       mUpnpHttpPersistentConnection *new_node;
       
       mupnp_log_debug_l4("Entering...\n");

       new_node = (mUpnpHttpPersistentConnection *)malloc(sizeof(mUpnpHttpPersistentConnection));

       if ( NULL != new_node )
       {
	       new_node->headFlag = FALSE;
	       new_node->next = NULL;
	       new_node->prev = NULL;

	       new_node->host = mupnp_string_new();
	       new_node->port = 0;
	       new_node->cacheData = NULL;

	       new_node->timestamp = 0;
       }

       return new_node;

	mupnp_log_debug_l4("Leaving...\n");
}
Exemplo n.º 4
0
mUpnpXmlNode *mupnp_control_action_request_createactionnode(mUpnpAction *action)
{
	mUpnpService *service;
	mUpnpXmlNode *actionNode;
	mUpnpArgument *arg;
	mUpnpXmlNode *argNode;
	mUpnpString *nameWithNamespace;
		
	mupnp_log_debug_l4("Entering...\n");

	service = mupnp_action_getservice(action);
	
	actionNode = mupnp_xml_node_new();
	/**** Thanks for Visa Smolander (10/31/2005) ****/
	nameWithNamespace = mupnp_string_new();
	mupnp_string_addvalue( nameWithNamespace, MUPNP_CONTROL_NS ":" );
	mupnp_string_addvalue( nameWithNamespace, mupnp_action_getname(action) );
	mupnp_xml_node_setname(actionNode, mupnp_string_getvalue( nameWithNamespace ) );
	mupnp_string_delete( nameWithNamespace );
	mupnp_xml_node_setnamespace(actionNode, MUPNP_CONTROL_NS, mupnp_service_getservicetype(service));
	
	for (arg = mupnp_action_getarguments(action); arg; arg = mupnp_argument_next(arg)) {
		if (mupnp_argument_isindirection(arg) == false)
			continue;
		argNode = mupnp_xml_node_new();
		mupnp_xml_node_setname(argNode, mupnp_argument_getname(arg));			
		mupnp_xml_node_setvalue(argNode, mupnp_argument_getvalue(arg));			
		mupnp_xml_node_addchildnode(actionNode, argNode);
	}
	
	mupnp_log_debug_l4("Leaving...\n");
	
	return actionNode;
}
Exemplo n.º 5
0
void mupnp_control_action_request_setaction(mUpnpActionRequest *actionReq, mUpnpAction *action)
{
	mUpnpService *service;
	mUpnpSoapRequest *soapReq;
	mUpnpString *soapAction;	
	mUpnpXmlNode *bodyNode;
	mUpnpXmlNode *contentNode;
	
	mupnp_log_debug_l4("Entering...\n");

	service = mupnp_action_getservice(action);
	soapReq = mupnp_control_action_request_getsoaprequest(actionReq);
	
	soapAction = mupnp_string_new();
	mupnp_string_addvalue(soapAction, "\"");
	mupnp_string_addvalue(soapAction, mupnp_service_getservicetype(service));
	mupnp_string_addvalue(soapAction, "#");
	mupnp_string_addvalue(soapAction, mupnp_action_getname(action));
	mupnp_string_addvalue(soapAction, "\"");
	mupnp_soap_request_setsoapaction(soapReq, mupnp_string_getvalue(soapAction));
	mupnp_string_delete(soapAction);
		
	mupnp_control_request_sethostfromservice(soapReq, service);
	
	mupnp_control_soap_request_initializeenvelopenode(soapReq);
	bodyNode = mupnp_soap_request_getbodynode(soapReq);
	contentNode = mupnp_control_action_request_createactionnode(action);
	mupnp_xml_node_addchildnode(bodyNode, contentNode);

	mupnp_soap_request_createcontent(soapReq);

	mupnp_log_debug_l4("Leaving...\n");
}
Exemplo n.º 6
0
bool mupnp_ssdpresponse_server_post(mUpnpSSDPResponseServer* server, mUpnpSSDPRequest* ssdpReq)
{
  mUpnpHttpUSocket* httpuSock;
  char* ifAddr;
  const char* ssdpAddr;
  mUpnpString* ssdpMsg;
  size_t sentLen = 0;

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

  httpuSock = mupnp_ssdpresponse_server_getsocket(server);

  ifAddr = mupnp_socket_getaddress(httpuSock);
  ssdpAddr = mupnp_ssdp_gethostaddress(ifAddr);
  mupnp_ssdprequest_sethost(ssdpReq, ssdpAddr, MUPNP_SSDP_PORT);

  ssdpMsg = mupnp_string_new();
  mupnp_ssdprequest_tostring(ssdpReq, ssdpMsg);

  sentLen = mupnp_socket_sendto(httpuSock, ssdpAddr, MUPNP_SSDP_PORT, mupnp_string_getvalue(ssdpMsg), mupnp_string_length(ssdpMsg));
  mupnp_string_delete(ssdpMsg);

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

  return (sentLen > 0);
}
Exemplo n.º 7
0
void  mupnp_xml_node_print(mUpnpXmlNode *node)
{
	mUpnpString *str = mupnp_string_new();
	mupnp_xml_node_tostring(node, true, str);
	printf("%s", mupnp_string_getvalue(str));
	mupnp_string_delete(str);
}
Exemplo n.º 8
0
mUpnpHttpHeader* mupnp_http_header_new()
{
  mUpnpHttpHeader* header;

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

  header = (mUpnpHttpHeader*)malloc(sizeof(mUpnpHttpHeader));

  if (NULL != header) {
    mupnp_list_node_init((mUpnpList*)header);
    header->name = mupnp_string_new();
    header->value = mupnp_string_new();
  }

  return header;

  mupnp_log_debug_l4("Leaving...\n");
}
Exemplo n.º 9
0
void mupnp_event_subscription_request_settimeout(mUpnpSubscriptionRequest* subReq, long timeout)
{
  mUpnpString* timeoutBuf;

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

  timeoutBuf = mupnp_string_new();
  mupnp_http_packet_setheadervalue(((mUpnpHttpPacket*)subReq), MUPNP_HTTP_TIMEOUT, mupnp_event_subscription_totimeoutheaderstring(timeout, timeoutBuf));
  mupnp_string_delete(timeoutBuf);

  mupnp_log_debug_l4("Leaving...\n");
}
Exemplo n.º 10
0
void mupnp_event_subscription_response_settimeout(mUpnpSubscriptionResponse* subRes, long value)
{
  mUpnpString* buf;

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

  buf = mupnp_string_new();
  mupnp_http_packet_setheadervalue((mUpnpHttpPacket*)subRes, MUPNP_HTTP_TIMEOUT, mupnp_event_subscription_totimeoutheaderstring(value, buf));
  mupnp_string_delete(buf);

  mupnp_log_debug_l4("Leaving...\n");
}
Exemplo n.º 11
0
mUpnpNetworkInterface *mupnp_net_interface_new()
{
	mUpnpNetworkInterface *netIf;

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

	netIf = (mUpnpNetworkInterface *)malloc(sizeof(mUpnpNetworkInterface));

	if ( NULL != netIf )
	{
		mupnp_list_node_init((mUpnpList *)netIf);
		netIf->name = mupnp_string_new();
		netIf->ipaddr = mupnp_string_new();
		netIf->netmask = mupnp_string_new();
		mupnp_net_interface_setindex(netIf, 0);
		memset(netIf->macaddr, 0, (size_t)MUPNP_NET_MACADDR_SIZE);
	}
	
	mupnp_log_debug_l4("Leaving...\n");

	return netIf;
}
Exemplo n.º 12
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");
}
Exemplo n.º 13
0
/**
 * Create a new event subscriber
 */
mUpnpSubscriber* mupnp_subscriber_new()
{
  mUpnpSubscriber* sub;

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

  sub = (mUpnpSubscriber*)malloc(sizeof(mUpnpSubscriber));

  if (NULL != sub) {
    mupnp_list_node_init((mUpnpList*)sub);

    sub->sid = mupnp_string_new();
    sub->ifAddr = mupnp_string_new();
    sub->deliveryURL = mupnp_net_url_new();

    mupnp_subscriber_settimeout(sub, 0);
    mupnp_subscriber_renew(sub);
    mupnp_subscriber_setnotifycount(sub, 0);
  }

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

  return sub;
}
Exemplo n.º 14
0
/**
 * Create a new control point. Does not start any threads.
 *
 * @return A newly-created mUpnpControlPoint
 */
mUpnpControlPoint *mupnp_controlpoint_new()
{
	mUpnpControlPoint *ctrlPoint;

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

	ctrlPoint = (mUpnpControlPoint *)malloc(sizeof(mUpnpControlPoint));

	if ( NULL != ctrlPoint )
	{
#ifdef MUPNP_HTTP_USE_PERSISTENT_CONNECTIONS	
		mupnp_http_persistentconnection_init();
#endif
		ctrlPoint->mutex = mupnp_mutex_new();
		ctrlPoint->deviceRootNodeList = mupnp_xml_nodelist_new();
		ctrlPoint->deviceList = mupnp_devicelist_new();
		ctrlPoint->ssdpServerList = mupnp_ssdp_serverlist_new();
		ctrlPoint->ssdpResServerList = mupnp_ssdpresponse_serverlist_new();
		ctrlPoint->httpServerList = mupnp_http_serverlist_new();
		ctrlPoint->httpEventURI = mupnp_string_new();
		ctrlPoint->eventListeners = mupnp_eventlistenerlist_new();

		/* Expiration handling */
		ctrlPoint->expThread = mupnp_thread_new();
		mupnp_thread_setaction(ctrlPoint->expThread, mupnp_controlpoint_expirationhandler);
		mupnp_thread_setuserdata(ctrlPoint->expThread, ctrlPoint);
		ctrlPoint->expMutex = mupnp_mutex_new();
		ctrlPoint->expCond = mupnp_cond_new();
		
		ctrlPoint->ifCache = mupnp_net_interfacelist_new();
		
		mupnp_controlpoint_setssdplistener(ctrlPoint, NULL);
		mupnp_controlpoint_setssdpresponselistener(ctrlPoint, NULL);
		mupnp_controlpoint_sethttplistener(ctrlPoint, NULL);
		mupnp_controlpoint_setdevicelistener(ctrlPoint, NULL);
		
		mupnp_controlpoint_setssdpresponseport(ctrlPoint, MUPNP_CONTROLPOINT_SSDP_RESPONSE_DEFAULT_PORT);
		mupnp_controlpoint_setssdpsearchmx(ctrlPoint, MUPNP_CONTROLPOINT_SSDP_DEFAULT_SEARCH_MX);
		mupnp_controlpoint_seteventport(ctrlPoint, MUPNP_CONTROLPOINT_HTTP_EVENT_DEFAULT_PORT);
		mupnp_controlpoint_seteventsuburi(ctrlPoint, MUPNP_CONTROLPOINT_HTTP_EVENTSUB_URI);

		mupnp_controlpoint_setuserdata(ctrlPoint, NULL);
	}

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

	return ctrlPoint;
}
Exemplo n.º 15
0
void mupnp_event_subscription_response_setsid(mUpnpSubscriptionResponse* subRes, const char* sid)
{
  mUpnpString* headerSID;
  ssize_t uuidIdx;

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

  headerSID = mupnp_string_new();

  uuidIdx = mupnp_strstr(sid, MUPNP_ST_UUID_DEVICE);
  if (uuidIdx < 0)
    mupnp_string_addvalue(headerSID, MUPNP_ST_UUID_DEVICE ":");
  mupnp_string_addvalue(headerSID, sid);

  mupnp_http_packet_setheadervalue(((mUpnpHttpPacket*)subRes), MUPNP_HTTP_SID, mupnp_string_getvalue(headerSID));

  mupnp_string_delete(headerSID);

  mupnp_log_debug_l4("Leaving...\n");
}
Exemplo n.º 16
0
/****************************************
* mupnp_upnpav_dms_condir_browsemetadata
****************************************/
static bool mupnp_upnpav_dms_condir_browsemetadata(mUpnpAvServer *dms, mUpnpAction *action)
{
	char *objectID;
	mUpnpAvContent *objectContent;
	mUpnpXmlNode *didlNode;
	mUpnpString *resultStr;
	char intBuf[MUPNP_STRING_INTEGER_BUFLEN];
	mUpnpAvContent *copyContent;

	objectID = mupnp_action_getargumentvaluebyname(action, CG_UPNPAV_DMS_CONTENTDIRECTORY_BROWSE_OBJECT_ID);
	if (mupnp_strlen(objectID) <= 0)
		return false;

	objectContent = mupnp_upnpav_dms_findcontentbyid(dms, objectID);
	if (!objectContent)
		return false;

    didlNode = mupnp_upnpav_didl_node_new();
    copyContent = mupnp_upnpav_content_new();
    mupnp_upnpav_content_copy(copyContent, objectContent);

	mupnp_xml_node_addchildnode(didlNode, copyContent);

	resultStr = mupnp_string_new();
	mupnp_upnpav_didl_node_tostring(didlNode, resultStr);

	mupnp_action_setargumentvaluebyname(action, CG_UPNPAV_DMS_CONTENTDIRECTORY_BROWSE_RESULT, mupnp_string_getvalue(resultStr));
	mupnp_action_setargumentvaluebyname(action, CG_UPNPAV_DMS_CONTENTDIRECTORY_BROWSE_NUMBER_RETURNED, "1");
	mupnp_action_setargumentvaluebyname(action, CG_UPNPAV_DMS_CONTENTDIRECTORY_BROWSE_TOTAL_MACHES, "1");
	mupnp_action_setargumentvaluebyname(action, CG_UPNPAV_DMS_CONTENTDIRECTORY_BROWSE_UPDATE_ID, (char*)mupnp_int2str(mupnp_upnpav_dms_condir_getsystemupdateid(dms), intBuf, sizeof(intBuf)));

    /*
      printf("browsemetadata reply: '%s'\n",
           mupnp_string_getvalue(resultStr));
    */

	mupnp_string_delete(resultStr);
	mupnp_upnpav_didl_node_delete(didlNode);

	return true;
}
Exemplo n.º 17
0
mUpnpArgument* mupnp_argument_new()
{
    mUpnpArgument* arg;

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

    arg = (mUpnpArgument*)malloc(sizeof(mUpnpArgument));

    if (NULL != arg) {
        mupnp_list_node_init((mUpnpList*)arg);

        arg->serviceNode = NULL;
        arg->argumentNode = NULL;

        arg->value = mupnp_string_new();
    }

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

    return arg;
}
Exemplo n.º 18
0
void mupnp_upnpav_dmr_addprotocolinfo(mUpnpAvRenderer *dmr, mUpnpAvProtocolInfo *info)
{
	mUpnpString *protocolInfos;
	mUpnpAvProtocolInfo *protocolInfo;
	mUpnpService *service;
	mUpnpStateVariable *stateVar;

	mupnp_upnpav_protocolinfolist_add(dmr->protocolInfoList, info);

	protocolInfos = mupnp_string_new();
	for (protocolInfo = mupnp_upnpav_dmr_getprotocolinfos(dmr); protocolInfo; protocolInfo = mupnp_upnpav_protocolinfo_next(protocolInfo)) {
		if (0 < mupnp_string_length(protocolInfos))
			mupnp_string_addvalue(protocolInfos, ",");
		mupnp_string_addvalue(protocolInfos, mupnp_upnpav_protocolinfo_getstring(protocolInfo));
	}

	service = mupnp_device_getservicebyexacttype(dmr->dev, CG_UPNPAV_DMR_CONNECTIONMANAGER_SERVICE_TYPE);
	stateVar = mupnp_service_getstatevariablebyname(service, CG_UPNPAV_DMR_CONNECTIONMANAGER_SINKPROTOCOLINFO);
	mupnp_statevariable_setvalue(stateVar, mupnp_string_getvalue(protocolInfos));

	mupnp_string_delete(protocolInfos);
}
Exemplo n.º 19
0
static char *mupnp_xml_node_attribute_tostring(mUpnpXmlNode *node, mUpnpString *str)
{
	mUpnpXmlAttribute *attr;
	const char *name;
	const char *value;
	mUpnpString *valueStr;
	
	mupnp_log_debug_l4("Entering...\n");

	valueStr = mupnp_string_new();
	if (valueStr == NULL) return NULL;

	for (attr = mupnp_xml_node_getattributes(node); attr != NULL; attr = mupnp_xml_attribute_next(attr)) {
		name = mupnp_xml_attribute_getname(attr);
		value = mupnp_xml_attribute_getvalue(attr);
		
		mupnp_string_setvalue(valueStr, value);
		mupnp_xml_escapechars(valueStr);

		/* All the following functions return NULL only when memory 
		   allocation fails, so we can check them all */
		if (!mupnp_string_naddvalue(str, " ", 1) || 
		    !mupnp_string_addvalue(str, name) ||
		    !mupnp_string_naddvalue(str, "=\"", 2) ||
		    !mupnp_string_addvalue(str, mupnp_string_getvalue(valueStr)) ||
		    !mupnp_string_naddvalue(str, "\"", 1))
		{
			/* Memory allocation failed */
			mupnp_string_delete(valueStr);
			return NULL;
		}
	}
	mupnp_string_delete(valueStr);
	
	mupnp_log_debug_l4("Leaving...\n");

	return mupnp_string_getvalue(str);
}
Exemplo n.º 20
0
static char *mupnp_xml_node_tostring_indent(mUpnpXmlNode *node, int indentLevel, bool withChildNode, mUpnpString *str)
{
	char *name;
	char *value;
	mUpnpString *valueStr;
	mUpnpXmlNode *childNode;
	
	mupnp_log_debug_l4("Entering...\n");

	name = mupnp_xml_node_getname(node);
	value = mupnp_xml_node_getvalue(node);

	if (mupnp_xml_node_haschildnodes(node) == false || withChildNode == false) {
		mupnp_string_addrepvalue(str, MUPNP_XML_INDENT_STRING, indentLevel);
		if (!mupnp_string_naddvalue(str, "<", 1) ||
		    !mupnp_string_addvalue(str, name) ||
		    !mupnp_xml_node_attribute_tostring(node, str))
			/* Memory allocation failed */
			return NULL;
		
		valueStr = mupnp_string_new();
		if (!valueStr)
			/* Memory allocation failed */
			return NULL;
		
		mupnp_string_setvalue(valueStr, value);
		mupnp_xml_escapechars(valueStr);

		if (!mupnp_string_naddvalue(str, ">", 1) ||
		    !mupnp_string_addvalue(str, mupnp_string_getvalue(valueStr)) ||
		    !mupnp_string_naddvalue(str, "</", 2) ||
		    !mupnp_string_addvalue(str, name) ||
		    !mupnp_string_naddvalue(str, ">", 1) ||
		    !mupnp_string_addvalue(str, "\n"))
		{
			/* Memory allocation failed */
			mupnp_string_delete(valueStr);
			return NULL;
		}

		mupnp_string_delete(valueStr);
		
		return mupnp_string_getvalue(str);
	}

	mupnp_string_addrepvalue(str, MUPNP_XML_INDENT_STRING, indentLevel);
	if (!mupnp_string_naddvalue(str, "<", 1) ||
	    !mupnp_string_addvalue(str, name) ||
	    !mupnp_xml_node_attribute_tostring(node, str) ||
	    !mupnp_string_naddvalue(str, ">", 1) ||
	    !mupnp_string_addvalue(str, "\n"))
		/* Memory allocation failed */
		return NULL;

	for (childNode = mupnp_xml_node_getchildnodes(node); childNode != NULL; childNode = mupnp_xml_node_next(childNode))
		if (!mupnp_xml_node_tostring_indent(childNode, indentLevel+1, true, str))
			/* Memory allocation failed */
			return NULL;

	mupnp_string_addrepvalue(str, MUPNP_XML_INDENT_STRING, indentLevel);
	if (!mupnp_string_naddvalue(str, "</", 2) ||
	    !mupnp_string_addvalue(str, name) ||
	    !mupnp_string_naddvalue(str, ">", 1) ||
	    !mupnp_string_addvalue(str, "\n"))
		/* Memory allocation failed */
		return NULL;

	mupnp_log_debug_l4("Leaving...\n");
	
	return mupnp_string_getvalue(str);
}
Exemplo n.º 21
0
static bool mupnp_upnpav_dms_condir_browsedirectchildren(mUpnpAvServer *dms, mUpnpAction *action)
{
	char *objectID;
	mUpnpAvContent *objectContent;
	mUpnpAvContent *content;
	mUpnpAvContent *copyContent;
	mUpnpAvContentList *sortedContentList;
	mUpnpAvContent **sortedContentArray;
	int startingIndex;
	int requestedCount;
	int numberReturned;
	int totalMachesCnt;
	char intBuf[MUPNP_STRING_INTEGER_BUFLEN];
	int n;
	mUpnpXmlNode *didlNode;
	mUpnpString *resultStr;

	objectID = mupnp_action_getargumentvaluebyname(action, CG_UPNPAV_DMS_CONTENTDIRECTORY_BROWSE_OBJECT_ID);
	if (mupnp_strlen(objectID) <= 0)
		return false;

	objectContent = mupnp_upnpav_dms_findcontentbyid(dms, objectID);
	if (!objectContent)
		return false;

	totalMachesCnt = 0;
	sortedContentList = mupnp_upnpav_contentlist_new();
	for (content=mupnp_upnpav_content_getchildcontents(objectContent); content; content=mupnp_upnpav_content_next(content)) {
		copyContent = mupnp_upnpav_content_new();
		mupnp_upnpav_content_copy(copyContent, content);
		mupnp_upnpav_contentlist_add(sortedContentList, copyContent);
		totalMachesCnt++;
	}

	/* Not Implemented
	// Sort Content Node Lists
	string sortCriteria = action->getSortCriteria();
	ContentNodeList sortedContentNodeBufList(false);
	ContentNodeList *sortedContentNodeList = sortContentNodeList(&contentNodeList, sortCriteria.c_str(), sortedContentNodeBufList);
	*/

	startingIndex = mupnp_str2int(mupnp_action_getargumentvaluebyname(action, CG_UPNPAV_DMS_CONTENTDIRECTORY_BROWSE_STARTING_INDEX));
	if (startingIndex <= 0)
		startingIndex = 0;

	requestedCount = mupnp_str2int(mupnp_action_getargumentvaluebyname(action, CG_UPNPAV_DMS_CONTENTDIRECTORY_BROWSE_REQUESTED_COUNT));
	if (requestedCount <= 0)
		requestedCount = mupnp_upnpav_contentlist_size(sortedContentList);

	numberReturned = 0;

	didlNode = mupnp_upnpav_didl_node_new();

	sortedContentArray = (mUpnpAvContent **)malloc(sizeof(mUpnpAvContent*) * totalMachesCnt);
	n = 0;
	for (content=mupnp_upnpav_contentlist_gets(sortedContentList); content; content=mupnp_upnpav_content_next(content)) {
		sortedContentArray[n] = content;
		n++;
	}

	for (n=startingIndex; (n<totalMachesCnt && numberReturned<requestedCount); n++) {
		content = sortedContentArray[n];
		mupnp_upnpav_content_remove(content);
		mupnp_upnpav_content_addchildcontent(didlNode, content);
		mupnp_upnpav_content_setparentid(content, objectID);
		numberReturned++;
	}

	resultStr = mupnp_string_new();
	mupnp_upnpav_didl_node_tostring(didlNode, resultStr);

	mupnp_action_setargumentvaluebyname(action, CG_UPNPAV_DMS_CONTENTDIRECTORY_BROWSE_RESULT, mupnp_string_getvalue(resultStr));
	mupnp_action_setargumentvaluebyname(action, CG_UPNPAV_DMS_CONTENTDIRECTORY_BROWSE_NUMBER_RETURNED, (char*)mupnp_int2str(numberReturned, intBuf, sizeof(intBuf)));
	mupnp_action_setargumentvaluebyname(action, CG_UPNPAV_DMS_CONTENTDIRECTORY_BROWSE_TOTAL_MACHES, (char*)mupnp_int2str(totalMachesCnt, intBuf, sizeof(intBuf)));
	mupnp_action_setargumentvaluebyname(action, CG_UPNPAV_DMS_CONTENTDIRECTORY_BROWSE_UPDATE_ID, (char*)mupnp_int2str(mupnp_upnpav_dms_condir_getsystemupdateid(dms), intBuf, sizeof(intBuf)));

	mupnp_string_delete(resultStr);
	free(sortedContentArray);
	mupnp_upnpav_didl_node_delete(didlNode);
	mupnp_upnpav_contentlist_delete(sortedContentList);

	return true;
}
Exemplo n.º 22
0
Arquivo: crss.c Projeto: Coramo/mupnp
mUpnpMediaContent* mupnp_http_getrsscontents(char* rssURL)
{
  mUpnpString* content_str;
  char* content_string;
  mUpnpXmlParser* xmlParser;
  mUpnpXmlNodeList* nodeList;
  mUpnpXmlNode* rootNode;
  mUpnpXmlNode* channelNode;
  mUpnpXmlNode* node;
  mUpnpXmlNode* childNode;
  char* container_title;
  char* content_title;
  char* contentURL;
  char containerID[CG_MD5_STRING_BUF_SIZE];
  char contentID[CG_MD5_STRING_BUF_SIZE];
  long contentSize;
  int nContentent;
  char* contentMimeType;
  mUpnpMediaContent* content;
  mUpnpMediaContent* container;
  mUpnpMediaResource* res;

  content_str = mupnp_string_new();

  if (!mupnp_http_getrestresponse(rssURL, content_str)) {
    mupnp_string_delete(content_str);
    return NULL;
  }

  content_string = mupnp_string_getvalue(content_str);
  if (mupnp_strlen(content_string) <= 0) {
    mupnp_string_delete(content_str);
    return NULL;
  }

  nodeList = mupnp_xml_nodelist_new();
  xmlParser = mupnp_xml_parser_new();
  if (mupnp_xml_parse(xmlParser, nodeList, content_string, mupnp_strlen(content_string)) == FALSE) {
    mupnp_string_delete(content_str);
    mupnp_xml_parser_delete(xmlParser);
    mupnp_xml_nodelist_delete(nodeList);
    return NULL;
  }

  mupnp_string_delete(content_str);
  mupnp_xml_parser_delete(xmlParser);

  nContentent = 0;
  rootNode = mupnp_xml_nodelist_gets(nodeList);
  if (rootNode == NULL) {
    mupnp_xml_nodelist_delete(rootNode);
    return NULL;
  }

  channelNode = mupnp_xml_node_getchildnode(rootNode, "channel");
  if (channelNode == NULL) {
    mupnp_xml_nodelist_delete(rootNode);
    return NULL;
  }

  /**** container ****/

  // Title
  container_title = "";
  childNode = mupnp_xml_node_getchildnode(channelNode, "title");
  if (childNode) {
    if (mupnp_xml_node_getvalue(childNode))
      container_title = mupnp_xml_node_getvalue(childNode);
  }

  if (mupnp_strlen(container_title) <= 0) {
    mupnp_xml_nodelist_delete(rootNode);
    return NULL;
  }

  container = mupnp_media_content_new();
  mupnp_media_content_settype(container, MUPNP_MEDIA_CONTENT_CONTAINER);
  mupnp_media_content_settitle(container, container_title);
  mupnp_str2md5(container_title, containerID);
  mupnp_media_content_setid(container, containerID);

  /**** item ****/
  for (node = mupnp_xml_node_getchildnodes(channelNode); node; node = mupnp_xml_node_next(node)) {

    if (!mupnp_xml_node_isname(node, "item"))
      continue;

    content_title = "";
    contentURL = "";
    contentSize = 0;

    // Title
    childNode = mupnp_xml_node_getchildnode(node, "title");
    if (childNode) {
      if (mupnp_xml_node_getvalue(childNode))
        content_title = mupnp_xml_node_getvalue(childNode);
    }

    // Enclosure
    childNode = mupnp_xml_node_getchildnode(node, "enclosure");
    if (childNode) {
      // url
      if (mupnp_xml_node_getattributevalue(childNode, "url"))
        contentURL = mupnp_xml_node_getattributevalue(childNode, "url");
      // type
      if (mupnp_xml_node_getattributevalue(childNode, "type"))
        contentMimeType = mupnp_xml_node_getattributevalue(childNode, "type");
      // type
      if (mupnp_xml_node_getattributevalue(childNode, "length"))
        contentSize = atol(mupnp_xml_node_getattributevalue(childNode, "length"));
    }

    if (mupnp_strlen(content_title) <= 0 || mupnp_strlen(contentURL) <= 0)
      continue;

    content = mupnp_media_content_new();
    mupnp_media_content_settype(content, MUPNP_MEDIA_CONTENT_ITEM);

    /**** content name ****/
    content_title = mupnp_strtrim(content_title, " ", 1);
    if (mupnp_strlen(content_title) <= 0) {
      continue;
    }
    mupnp_media_content_settitle(content, content_title);

    /**** content id ****/
    mupnp_str2md5(contentURL, contentID);
    mupnp_media_content_setid(content, contentID);
    mupnp_media_content_addchildcontent(container, content);

    res = mupnp_media_resource_new();
    mupnp_media_resource_setmimetype(res, contentMimeType);
    mupnp_media_resource_seturl(res, contentURL);
    mupnp_media_resource_setsize(res, contentSize);
    mupnp_media_content_addresource(content, res);

    nContentent++;
  }

  mupnp_xml_nodelist_delete(nodeList);

  return container;
}
Exemplo n.º 23
0
bool mupnp_xml_parse(mUpnpXmlParser* parser, mUpnpXmlNodeList* nodeList, const char* data, size_t len)
{
#if defined DEBUG_XML_RESULT
  mUpnpString* resdata = NULL;
#endif
  XML_Parser p;
  mUpnpExpatData expatData;
#ifdef MUPNP_SHOW_TIMINGS
  struct timeval start_time, end_time, elapsed_time;
#endif

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

#ifdef MUPNP_SHOW_TIMINGS
  gettimeofday(&start_time, NULL);
#endif

  if (!data || len <= 0)
    return false;

  p = XML_ParserCreate(NULL);
  if (!p)
    return false;
  /* Fix to get expat parser to work with DLink-routers */
  if (data[len - 1] == 0)
    len--;

  expatData.rootNode = NULL;
  expatData.currNode = NULL;
  XML_SetUserData(p, &expatData);
  XML_SetElementHandler(p, mupnp_expat_element_start, mupnp_expat_element_end);
  XML_SetCharacterDataHandler(p, mupnp_expat_character_data);

  parser->parseResult = XML_Parse(p, data, len, 1);
  XML_ParserFree(p);

  if (parser->parseResult == 0 /*XML_STATUS_ERROR*/) {
    if (expatData.rootNode != NULL)
      mupnp_xml_node_delete(expatData.rootNode);
#if defined DEBUG_XML_RESULT
    resdata = mupnp_string_new();
    mupnp_string_naddvalue(resdata, data, len);
    printf("XML parse Error on data %s\n time used = %ds\n",
        mupnp_string_getvalue(resdata),
        time(NULL) - startTime);
    mupnp_string_delete(resdata);
#endif
    return false;
  }

  mupnp_xml_nodelist_add(nodeList, expatData.rootNode);

#ifdef MUPNP_SHOW_TIMINGS
  gettimeofday(&end_time, NULL);
  timersub(&end_time, &start_time, &elapsed_time);
  mupnp_log_debug_s("Parsing XML completed. Elapsed time: "
                    "%ld msec\n",
      ((elapsed_time.tv_sec * 1000) + (elapsed_time.tv_usec / 1000)));
  mupnp_total_elapsed_time += (elapsed_time.tv_sec * 1000000) + (elapsed_time.tv_usec);
  mupnp_log_debug_s("Total elapsed time: %ld msec\n", mupnp_total_elapsed_time / 1000);
#endif

#if defined DEBUG_XML_RESULT
  resdata = mupnp_string_new();
  mupnp_string_naddvalue(resdata, data, len);
  printf("XML parse success - time used %ds\n", time(NULL) - startTime);
  mupnp_string_delete(resdata);
#endif

  return true;

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