Esempio n. 1
0
static char *avt_GetPositionInfo(AVTransport *avt)
{
	IXML_Document *in = NULL, *out = NULL;
	char *errorString = NULL, *value = NULL;
	
	GetPositionInfo(in, &out, &errorString);
	json_object *output = json_object_new_object();

	value = UpnpUtil_GetFirstDocumentItem(out, "AbsTime");
	json_object_object_add(output, "AbsTime", s_DmrYx_json_object_new_string(value)); 
	if(value)
		free(value);

	value = UpnpUtil_GetFirstDocumentItem(out, "AbsCount");
	json_object_object_add(output, "AbsCount", s_DmrYx_json_object_new_string(value));  
	if(value)
		free(value);

	char *result = (char *)json_object_to_json_string(output);//bug!!!!
	json_object_put(output);
	if(in)
		ixmlDocument_free(in);
	if(out)
		ixmlDocument_free(out);
	return result;
}
Esempio n. 2
0
/*
*****************************************************************************
** FUNCTION NAME: ResponseCMD
**
** FUNCTION INPUTS:
**  @char *objID: object ID
**
** FUNCTION DESCRIPTION
**   This function will create response xml string without error
**
** FUNCTION OUTPUTS:
**   Returns ZAPP_SUCCESS on success, or ZAPP_FAILED on failed.
**
** HISTORY:
** 2008-7-2	Steven Leong	Created
*****************************************************************************
*/
int ResponseCMD(char *objID)
{
	IXML_Document *dom = NULL;
	IXML_Element *element = NULL;
	char *ptrXml = NULL;
	
	/* Package response xml */
	if((dom = ixmlDocument_createDocument()) == NULL)
		return ZAPP_FAILED;
	//ret node
	if((element = ixmlDocument_createElement(dom,"ret")) == NULL)
		goto errOut;
	ixmlNode_appendChild(&dom->n, (IXML_Node *)element);
	//err node
	if(createElementTextNode(element,"err","0") == NULL)
		goto errOut;
	//msg node
	if(createElementTextNode(element,"msg","") == NULL)
		goto errOut;
	//category node
	if(createElementTextNode(element,"objID", objID) == NULL)
		goto errOut;
	
	ptrXml = ixmlPrintDocument(dom);

	ZRipResponse(ptrXml);

	ZFREE(ptrXml);
	ixmlDocument_free(dom);
	return ZAPP_SUCCESS;

errOut:
	ixmlDocument_free(dom);
	return ZAPP_FAILED;
}
Esempio n. 3
0
static char *avt_GetMediaInfo(AVTransport *avt)
{
	IXML_Document *in = NULL, *out = NULL;
	char *errorString = NULL, *value = NULL;
	char *result;
	GetMediaInfo(in, &out, &errorString);
	
	json_object *output = json_object_new_object();
	
	value = UpnpUtil_GetFirstDocumentItem(out, "CurrentMediaDuration");
	json_object_object_add(output, "CurrentMediaDuration", s_DmrYx_json_object_new_string(value));
	if(value)
		free(value);

	value = UpnpUtil_GetFirstDocumentItem(out, "AVTransportURI");
	json_object_object_add(output, "AVTransportURI", s_DmrYx_json_object_new_string(value));
	if(value)
		free(value);

	value = UpnpUtil_GetFirstDocumentItem(out, "AVTransportURIMetaData");
	json_object_object_add(output, "AVTransportURIMetaData", s_DmrYx_json_object_new_string(value));
	if(value)
		free(value);

	result = (char *)json_object_to_json_string(output);//bug!!!!
	json_object_put(output);
	if(in)
		ixmlDocument_free(in);
	if(out)
		ixmlDocument_free(out);
	return result;
}
Esempio n. 4
0
static char *avt_GetCurrentTransportActions(AVTransport *avt)
{
	IXML_Document *in = NULL, *out = NULL;
	char *errorString = NULL;
	
	GetCurrentTransportActions(in, &out, &errorString);
	char *action = UpnpUtil_GetFirstDocumentItem(out, "Actions");
	if(in)
		ixmlDocument_free(in);
	if(out)
		ixmlDocument_free(out);
	return action;
}
Esempio n. 5
0
/*
 * Fetches and parses the UPNP response
 */
bool MediaServer::fetchContents()
{
    IXML_Document* p_response = _browseAction( m_psz_objectId,
                                "BrowseDirectChildren",
                                "*",
                                // Some servers don't understand "0" as "no-limit"
                                "1000", /* RequestedCount */
                                "" /* SortCriteria */
                                             );
    if ( !p_response )
    {
        msg_Err( m_access, "No response from browse() action" );
        return false;
    }

    IXML_Document* p_result = parseBrowseResult( p_response );

    ixmlDocument_free( p_response );

    if ( !p_result )
    {
        msg_Err( m_access, "browse() response parsing failed" );
        return false;
    }

#ifndef NDEBUG
    msg_Dbg( m_access, "Got DIDL document: %s", ixmlPrintDocument( p_result ) );
#endif

    IXML_NodeList* containerNodeList =
        ixmlDocument_getElementsByTagName( p_result, "container" );

    if ( containerNodeList )
    {
        for ( unsigned int i = 0; i < ixmlNodeList_length( containerNodeList ); i++ )
            addContainer( (IXML_Element*)ixmlNodeList_item( containerNodeList, i ) );
        ixmlNodeList_free( containerNodeList );
    }

    IXML_NodeList* itemNodeList = ixmlDocument_getElementsByTagName( p_result,
                                  "item" );
    if ( itemNodeList )
    {
        for ( unsigned int i = 0; i < ixmlNodeList_length( itemNodeList ); i++ )
            addItem( (IXML_Element*)ixmlNodeList_item( itemNodeList, i ) );
        ixmlNodeList_free( itemNodeList );
    }

    ixmlDocument_free( p_result );
    return true;
}
Esempio n. 6
0
/*
*****************************************************************************
** FUNCTION NAME: ParseCMD
**
** FUNCTION INPUTS:
**  @char *ptrXml: xml string will be parse
**  @char **objID: return the objID if exists
**  @char **cdid: return the cdid
**  @char **category: return the category
**
** FUNCTION DESCRIPTION
**   This function will parse command xml string.
**
** FUNCTION OUTPUTS:
**   Returns ZAPP_SUCCESS on success, or ZAPP_FAILED on failed.
**
** HISTORY:
** 2008-7-4	Steven Leong	Created
*****************************************************************************
*/
int ParseCMD(char *ptrXml, char **objID, char **cdid, char **category)
{
	IXML_Document *dom = NULL;
	IXML_Node *node = NULL;
	char *ptrObjID = NULL;
	char *ptrCdid = NULL;
	char *ptrCategory = NULL;
	int ret = ZAPP_SUCCESS;
	char strArray[BUF_128_BITS];
	
	if((dom = ixmlParseBuffer(ptrXml))==NULL){
		dprintf("Parse command xml string failed.\n");
		return ZAPP_FAILED;
	}

	if((node = ixmlGetFirstNodeByTagName(dom, "cmd"))==NULL){
		dprintf("Cannot get cmd tag.\n");
		ixmlDocument_free(dom);
		return ZAPP_FAILED;
	}
	
	ptrObjID = ixmlGetFirstElementItem((IXML_Element*)node, "objID");
	ptrCdid = ixmlGetFirstElementItem((IXML_Element*)node, "cdid");
	ptrCategory = ixmlGetFirstElementItem((IXML_Element*)node, "categoryname");
	
	/*NOTE: we need to check objID's format,
	if it's ROOT_ALLAL_ALXXX, change it to unsigned int. */
	if(ptrObjID == NULL){
		*objID = NULL;
	}
	else {
		if(strstr(ptrObjID, "AL")){
			/* string objID, like: ROOT_ALLAL_ALxxx */
			memset(strArray, 0, BUF_128_BITS);
			sprintf(strArray, "%u", GetTrackNum(ptrObjID, "AL"));
			*objID = strdup(strArray);
		}
		else{
			/* int objID */
			*objID = strdup(ptrObjID);
		}
	}
	*cdid = (ptrCdid==NULL) ? NULL : strdup(ptrCdid);
	*category = (ptrCategory==NULL) ? NULL : strdup(ptrCategory);

	ZFREE(ptrObjID);
	ZFREE(ptrCdid);
	ZFREE(ptrCategory);
	ixmlDocument_free(dom);
	return ret;
}
Esempio n. 7
0
KeyMode getState(char *message)
{

	IXML_Document *doc = NULL;
	char *state = NULL;

	if ((doc = ixmlParseBuffer(message)) == NULL)
		return -1;
	
	state = ixmlGetFirstDocumentItem(doc, "value");
	
	ixmlDocument_free(doc);
	if ((strcmp(state, "Powersaving") == 0) || (strcmp(state, "PartialActive") == 0))
	{
		printf("get state is POLICY\n");
		return POLICY;
	}
	else if (strcmp(state, "Active") == 0)
	{
		printf("get state is NORMAL\n");
		return NORMAL;
	}
	else
	{
		printf("get state is -1, failed!!!\n");
		return -1;
	}
}
Esempio n. 8
0
/********************************************************************************
 * upnp_igd_send_action
 *
 * Description:
 *       Send an Action request to the specified service of a device.
 *
 * Parameters:
 *   igd_ctxt    -- The upnp igd context
 *   device_node -- The device
 *   service     -- The service
 *   actionname  -- The name of the action.
 *   param_name  -- An array of parameter names
 *   param_val   -- The corresponding parameter values
 *   param_count -- The number of parameters
 *   fun         -- Callback function
 *   cookie      -- Callback cookie
 *
 ********************************************************************************/
int upnp_igd_send_action(upnp_igd_context* igd_ctxt, upnp_igd_device_node *device_node, int service,
		const char *actionname, const char **param_name, const char **param_val, int param_count,
		Upnp_FunPtr fun, const void *cookie) {
	IXML_Document *actionNode = NULL;
	int ret = 0;
	int param;
	if (0 == param_count) {
		actionNode = UpnpMakeAction(actionname, IGDServiceType[service], 0, NULL);
	} else {
		for (param = 0; param < param_count; param++) {
			if (UpnpAddToAction(&actionNode, actionname, IGDServiceType[service], param_name[param], param_val[param]) != UPNP_E_SUCCESS) {
				upnp_igd_print(igd_ctxt, UPNP_IGD_ERROR, "ERROR: upnp_igd_send_action: Trying to add action param");
			}
		}
	}

	ret = UpnpSendActionAsync(igd_ctxt->upnp_handle, device_node->device.services[service].control_url,
				 IGDServiceType[service], NULL, actionNode, fun, cookie);

	if (ret != UPNP_E_SUCCESS) {
		upnp_igd_print(igd_ctxt, UPNP_IGD_ERROR, "Error in UpnpSendActionAsync -- %d", ret);
		ret = -1;
	}

	if (actionNode)
		ixmlDocument_free(actionNode);

	return ret;
}
Esempio n. 9
0
static int s_CD_GetBestRes (char *dms_ip, char *metadata, IXML_Node **best_res)
{
	int ret = -1;
	
	if(!dms_ip || !metadata || !best_res)
		return -2;
	
	IXML_Document *subdoc = ixmlParseBuffer (discard_const_p (char, metadata));
	if(subdoc)
	{
		IXML_NodeList* items =	ixmlDocument_getElementsByTagName (subdoc, "item"); 
		if(items)
		{
			IXML_Node* node = ixmlNodeList_item(items,  0);
			if(node)
			{
				IXML_NodeList* reslist = ixmlElement_getElementsByTagName ((IXML_Element*)node, "res");
				if(reslist)
				{
					IXML_Node* res = s_CD_GetWantedRes(dms_ip, reslist, "http-get","null");
					if(res)
					{
						*best_res = ixmlNode_cloneNode(res, true);
						ret = 0;
					}
					ixmlNodeList_free (reslist);
				}
			}
			ixmlNodeList_free (items);
		}
		ixmlDocument_free(subdoc);
	}
	return ret;
}
Esempio n. 10
0
/**************************************************************************
* Function: prepareParameter
* Functionality: it will get the parameter from pipe and check it
* @IN : fd: the file description id for the pipe
*      enable: enable or disable flag
* @OUT: 0 success, else failed.
* Used description:
    The parameter is a xml, it will get from the pipe
* Date: 20080108
* Changed history:
* Date 		Who		Reason
* 20080108	kelly  		First  creation
***************************************************************************/
int prepareParameter(char *objID)
{
	IXML_Document	* rootDom = NULL;
	char buffer[1024] = {0};
	char str[1024] = {0}; 
	char *strVal = NULL;

	while(1)
	{
		fgets(str, 1024, stdin);
		str[strlen(str)-1]=0;
		strcat(buffer, str);
		if(strstr(buffer,EndFlag))
			break;
	}

	if(strlen(buffer) == 0)
		goto failed;

	if((rootDom = ixmlParseBuffer(buffer))  == NULL) 
		goto failed;

	strVal = ixmlGetFirstDocumentItem( rootDom,"objID" );
	strcpy(objID,strVal);
	free(strVal);
	
	if (rootDom)
		ixmlDocument_free(rootDom);

	return 0;

failed:
        fprintf(stderr,"Got a command parameter->%s", buffer);
	return -1;
}
Esempio n. 11
0
/*================================================================
*   ixmlDocument_createDocumentEx
*       Creates an document object
*       Internal function.
*   Parameters:
*       rtDoc:  the document created or NULL on failure
*   Return Value:
*       IXML_SUCCESS
*       IXML_INSUFFICIENT_MEMORY:   if not enough memory to finish this operations.
*
*=================================================================*/
int
ixmlDocument_createDocumentEx( OUT IXML_Document ** rtDoc )
{
    IXML_Document *doc;
    int errCode = IXML_SUCCESS;

    doc = NULL;
    doc = ( IXML_Document * ) malloc( sizeof( IXML_Document ) );
    if( doc == NULL ) {
        errCode = IXML_INSUFFICIENT_MEMORY;
        goto ErrorHandler;
    }

    ixmlDocument_init( doc );

    doc->n.nodeName = strdup( DOCUMENTNODENAME );
    if( doc->n.nodeName == NULL ) {
        ixmlDocument_free( doc );
        doc = NULL;
        errCode = IXML_INSUFFICIENT_MEMORY;
        goto ErrorHandler;
    }

    doc->n.nodeType = eDOCUMENT_NODE;
    doc->n.ownerDocument = doc;

  ErrorHandler:
    *rtDoc = doc;
    return errCode;
}
Esempio n. 12
0
/*****************************************************************************
 * ContentDir_GetSearchCapabilities
 *****************************************************************************/
const char*
ContentDir_GetSearchCapabilities (ContentDir* self, void* unused)
{
	if (self == NULL)
		return NULL; // ---------->
	
	// Send Action if result not already cached
	if (self->search_caps == NULL) {

		IXML_Document* doc = NULL;
		int rc = Service_SendActionVa
			(OBJECT_SUPER_CAST(self), &doc,
			 "GetSearchCapabilities",
			 NULL, NULL);
		if (rc == UPNP_E_SUCCESS && doc != NULL) {
			self->search_caps = talloc_strdup 
				(self, XMLUtil_FindFirstElementValue
				 (XML_D2N (doc), "SearchCaps", true, true));
			
			Log_Printf (LOG_DEBUG, 
				    "ContentDir_GetSearchCapabilities = '%s'",
				    NN(self->search_caps));
		}
		ixmlDocument_free (doc);
	}
	
	return self->search_caps;
}
Esempio n. 13
0
BOOL CVCAMetaParserIXML::ParseMetaData( unsigned char *pMetadata, int nLength )
{
	pMetadata[nLength] = '\0';
	m_pDOMDoc = ixmlParseBuffer((char*)pMetadata);
//	puts(ixmlPrintDocument(m_pDOMDoc));
	if(m_pDOMDoc) {
		ParseHeader();
		ParseStab();
		ParseObjects();
		ParseEvents();
		ParseCounts();
		
		ParseBlobsImp(_XML_TAMPERMAP, &m_TamperInfo);
		ParseBlobsImp(_XML_SCENECHANGEMAP, &m_SceneChangeInfo);
		ParseBlobsImp(_XML_BLOBMAP, &m_BlobMap);
		ParseBlobsImp(_XML_STATBLOBMAP, &m_StationaryMap);
		ParseBlobsImp(_XML_SMOKEMAP,&m_SmokeMap);
		ParseBlobsImp(_XML_FIREMAP,&m_FireMap);

		ParseCE();

		ixmlDocument_free(m_pDOMDoc);
	} else {
		printf("!!! Parsing Error\n");
	}

	return TRUE;
}
/*================================================================
*   ixmlNode_cloneDoc
*       Returns a clone of document node
*       Internal to parser only.
*
*=================================================================*/
IXML_Document *
ixmlNode_cloneDoc( IN IXML_Document * nodeptr )
{
    IXML_Document *newDoc;
    IXML_Node *docNode;
    int rc;

    assert( nodeptr != NULL );
    newDoc = ( IXML_Document * ) ixml_malloc( sizeof( IXML_Document ) );
    if( newDoc == NULL ) {
        return NULL;
    }

    ixmlDocument_init( newDoc );
    docNode = ( IXML_Node * ) newDoc;

    rc = ixmlNode_setNodeName( docNode, DOCUMENTNODENAME );
    if( rc != IXML_SUCCESS ) {
        ixmlDocument_free( newDoc );
        return NULL;
    }

    newDoc->n.nodeType = eDOCUMENT_NODE;

    return newDoc;

}
Esempio n. 15
0
// Extract attribute from URI_METADATA
const char *transport_get_attr_metadata(const char *key)
{
	IXML_Document *doc;
	IXML_Element *elm;
	const char *attr = NULL;

	const char *metadata = transport_get_var(TRANSPORT_VAR_AV_URI_META);

	if (!metadata || (strcmp(metadata, "") == 0))
		return NULL;

	doc = ixmlParseBuffer(metadata);
	if (doc)
	{
		// Locate 'res' element
		elm = ixmlDocument_getElementById(doc, "res");
		if (elm != NULL)
		{
			// Look for 'key' attribute in 'res' element
			attr = ixmlElement_getAttribute(elm, key);
			// Copy of result (caller must free)
			if (attr)
				attr = strdup(attr);
		}

		// Free the whole DOM
		ixmlDocument_free(doc);
	}

	DBG_PRINT(DBG_LVL1, "Track metadata: %s = %s\n", key, (attr) ? attr : "<not found>");

	// NULL if not found
	return attr;
}
Esempio n. 16
0
int
main (int argc, char* argv[])
{
	int i;

	if (argc < 2) {
		fprintf (stderr, "Usage: %s [xml files to load]\n",
			 argv[0]);
		exit (EXIT_FAILURE);
	}

	for (i = 1; i < argc; i++) {
		int rc;
		IXML_Document* doc = NULL;
		DOMString s;
		char* p;

		printf ("Test \"%s\" \n", argv[i]);
		printf ("    Loading ... ");
		fflush (stdout);

		rc = ixmlLoadDocumentEx (argv[i], &doc);
		if (rc != IXML_SUCCESS) {
			fprintf (stderr, 
				 "** error : can't load document %s : "
				 "error %d (%s)\n",
				 argv[i], rc, get_ixml_error_string (rc));
			exit (EXIT_FAILURE);
		}

		printf ("OK\n");

		printf ("    Printing ... ");
		fflush (stdout);
		
		s = ixmlPrintDocument (doc);
		if (s == NULL || s[0] == '\0') {
			fprintf (stderr, 
				 "** error : can't print loaded document %s\n",
				 argv[i]);
			exit (EXIT_FAILURE);
		}
		p = s + strlen(s)-1;
		while (isspace(*p) && p > s)
			p--;
		if (*s != '<' || *p != '>') {
			fprintf (stderr, 
				 "** error : malformed printed document '%s' :"
				 "%s\n", argv[i], s);
			exit (EXIT_FAILURE);
		}

		printf ("OK\n");

		ixmlFreeDOMString (s);
		ixmlDocument_free (doc);
	}
	
	exit (EXIT_SUCCESS);
}
Esempio n. 17
0
int discovery_search_result(struct Upnp_Discovery *event) {
    if (event->ErrCode != UPNP_E_SUCCESS) {
        fprintf(stderr, "Error in discovering device\n");
        exit(-1);
    }

    IXML_Document *desc = NULL;
    int ret = UpnpDownloadXmlDoc(event->Location, &desc);
    
    if (ret != UPNP_E_SUCCESS) {
        fprintf(stderr, "Error in obtaining device description\n");
        exit(-1);
    }
    
    const char *UUID = get_device_property(desc, "UDN");

    if (!list_contains(&devices, UUID, chromecast_matches_UUID)) {
        struct chromecast_device *device = malloc(sizeof(struct chromecast_device));
        device->addr = ((struct sockaddr_in *)&event->DestAddr)->sin_addr;     
        device->device_name = create_string_copy(get_device_property(desc, "friendlyName"));
        device->device_type = create_string_copy(get_device_property(desc, "deviceType"));
        device->device_UUID = create_string_copy(UUID);
        device->device_OS = create_string_copy(event->Os);
        device->device_manufacturer = create_string_copy(get_device_property(desc, "manufacturer"));
        device->device_model_name = create_string_copy(get_device_property(desc, "modelName"));
        device->service_type = create_string_copy(get_device_property(desc, "serviceType"));
        device->service_version = create_string_copy(event->ServiceVer);
        device->service_id = create_string_copy(get_device_property(desc, "serviceId"));
        list_add_sync(&devices, device);
        print_device(device);
    }
    ixmlDocument_free(desc);
    return 0;
}
Esempio n. 18
0
char *ReadElement(const char *Path,const char *NodeElement)
{
	char *Val = NULL;
	IXML_Document *doc = NULL;
	IXML_NodeList *node = NULL;
	IXML_Node *NodePtr = NULL;

	if(ixmlLoadDocumentEx(Path, &doc) == IXML_INVALID_PARAMETER)
		goto EXIT_THIS;

	node = ixmlDocument_getElementsByTagName(doc, NodeElement);

	if (node) 
	{
		if (NodePtr = ixmlNodeList_item(node, 0)) 
		{
			NodePtr = ixmlNode_getFirstChild(NodePtr);
			if(!NodePtr)
			{
				Val = (NULL);
			}
			Val = NodePtr->nodeValue;//strdup(NodePtr->nodeValue);
			if(!Val)
			{
				Val = (NULL);
			}
		} 
	}

	if (node)
		ixmlNodeList_free(node);
	ixmlDocument_free(doc);  
EXIT_THIS:
	return Val;
}
Esempio n. 19
0
File: upnp.cpp Progetto: ZMacer/vlc
/*
 * Handles servers listing UPnP events
 */
int MediaServerList::Callback( Upnp_EventType event_type, void* p_event, void* p_user_data )
{
    MediaServerList* self = static_cast<MediaServerList*>( p_user_data );
    services_discovery_t* p_sd = self->p_sd_;

    switch( event_type )
    {
    case UPNP_DISCOVERY_ADVERTISEMENT_ALIVE:
    case UPNP_DISCOVERY_SEARCH_RESULT:
    {
        struct Upnp_Discovery* p_discovery = ( struct Upnp_Discovery* )p_event;

        IXML_Document *p_description_doc = NULL;

        int i_res;
        i_res = UpnpDownloadXmlDoc( p_discovery->Location, &p_description_doc );
        if ( i_res != UPNP_E_SUCCESS )
        {
            msg_Warn( p_sd, "Could not download device description! "
                            "Fetching data from %s failed: %s",
                            p_discovery->Location, UpnpGetErrorMessage( i_res ) );
            return i_res;
        }
        self->parseNewServer( p_description_doc, p_discovery->Location );
        ixmlDocument_free( p_description_doc );
    }
    break;

    case UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE:
    {
        struct Upnp_Discovery* p_discovery = ( struct Upnp_Discovery* )p_event;

        self->removeServer( p_discovery->DeviceId );
    }
    break;

    case UPNP_EVENT_SUBSCRIBE_COMPLETE:
        msg_Warn( p_sd, "subscription complete" );
        break;

    case UPNP_DISCOVERY_SEARCH_TIMEOUT:
        msg_Warn( p_sd, "search timeout" );
        break;

    case UPNP_EVENT_RECEIVED:
    case UPNP_EVENT_AUTORENEWAL_FAILED:
    case UPNP_EVENT_SUBSCRIPTION_EXPIRED:
        // Those are for the access part
        break;

    default:
        msg_Err( p_sd, "Unhandled event, please report ( type=%d )", event_type );
        break;
    }

    return UPNP_E_SUCCESS;
}
Esempio n. 20
0
int GetDMSState()
{
	IXML_Document *stateDoc = NULL;
	char *state = NULL;
	int dmsState = 0;

	stateDoc = CMDGetStateDMS();
	if(stateDoc == NULL) {
		goto errOut;
	}
	state = ixmlGetFirstDocumentItem(stateDoc, "value");
	if(state == NULL) {
		goto errOut;
	}
	if(strcmp(state,"0") == 0){
		dmsState = DMS_IDLE;
	}
	else if(strcmp(state,"1") == 0){
		dmsState = DMS_STREAMING;
	}
	ZInfo4(DBG_MISC, "Parse DMS state structure success, it is %s", state);

	if(dmsState == DMS_STREAMING && GetSysState(DMSState) == DMS_IDLE){
		SetSysState(DMSState, DMS_STREAMING);
		streamingStart();
	}
	else if(dmsState == DMS_IDLE && GetSysState(DMSState) == DMS_STREAMING){
		SetSysState(DMSState, DMS_IDLE);
		streamingStop();
	}

	if(state != NULL){
		free (state);
	}
	ixmlDocument_free(stateDoc);
	return 0;
errOut:
	if(state != NULL){
		free (state);
	}
	ixmlDocument_free(stateDoc);
	ZError(DBG_MISC, "GetState from DMS Failed!");
	return -1;
}
Esempio n. 21
0
/********************************************************************************
 * TvCtrlPointSendAction
 *
 * Description: 
 *       Send an Action request to the specified service of a device.
 *
 * Parameters:
 *   service -- The service
 *   devnum -- The number of the device (order in the list,
 *             starting with 1)
 *   actionname -- The name of the action.
 *   param_name -- An array of parameter names
 *   param_val -- The corresponding parameter values
 *   param_count -- The number of parameters
 *
 ********************************************************************************/
int TvCtrlPointSendAction(
	int service,
	int devnum,
	const char *actionname,
	const char **param_name,
	char **param_val,
	int param_count)
{
	struct TvDeviceNode *devnode;
	IXML_Document *actionNode = NULL;
	int rc = TV_SUCCESS;
	int param;

	ithread_mutex_lock(&DeviceListMutex);

	rc = TvCtrlPointGetDevice(devnum, &devnode);
	if (TV_SUCCESS == rc) {
		if (0 == param_count) {
			actionNode =
			    UpnpMakeAction(actionname, TvServiceType[service],
					   0, NULL);
		} else {
			for (param = 0; param < param_count; param++) {
				if (UpnpAddToAction
				    (&actionNode, actionname,
				     TvServiceType[service], param_name[param],
				     param_val[param]) != UPNP_E_SUCCESS) {
					SampleUtil_Print
					    ("ERROR: TvCtrlPointSendAction: Trying to add action param\n");
					/*return -1; // TBD - BAD! leaves mutex locked */
				}
			}
		}

		rc = UpnpSendActionAsync(ctrlpt_handle,
					 devnode->device.
					 TvService[service].ControlURL,
					 TvServiceType[service], NULL,
					 actionNode,
					 TvCtrlPointCallbackEventHandler, NULL);

		if (rc != UPNP_E_SUCCESS) {
			SampleUtil_Print("Error in UpnpSendActionAsync -- %d\n",
					 rc);
			rc = TV_ERROR;
		}
	}

	ithread_mutex_unlock(&DeviceListMutex);

	if (actionNode)
		ixmlDocument_free(actionNode);

	return rc;
}
Esempio n. 22
0
static void s_CD_Release(pClassContentDirectory me)
{
	int killMeNow = 1;

	HT_DBG_FUNC_START(HT_MOD_DMC, HT_BIT_MANY, (int)me, 0);
	
	if( me == NULL )
		return;
	
	SEM_WAIT();
	if(me->busy)
	{
		me->killMeInCallback = 1;
		killMeNow = 0;
	}
	SEM_POST();
	
	HT_DBG_FUNC(killMeNow*100, 0);
	
	if( killMeNow )
	{
		s_Dmscp_UnRegisterCalback((int)me);
		s_Dmscp_UnRegister_ServiceCalback((int)me);
		sem_destroy(&(me->lock));
		sem_destroy(&(me->semResultOK));
		
		if( me->filter )			free(me->filter);
		if( me->searchCriteria )	free(me->searchCriteria);
		if( me->sortCriteria )		free(me->sortCriteria);
		if( me->ActionXml ) 		free(me->ActionXml);
		
		if(me->subdoc)
			ixmlDocument_free(me->subdoc);
		if(me->ActionResult)
			ixmlDocument_free(me->ActionResult);
		
        if( me->objectid )          free(me->objectid);
		free(me);
	}
	HT_DBG_FUNC_END(killMeNow, 0);
}
Esempio n. 23
0
void UpdateDMRState()
{
	IXML_Document *stateDoc = NULL;
	stateDoc = CMDGetStateDMR();
	if(stateDoc == NULL) {
		ZError(DBG_MISC, "Get state from DMR failed!");
		return;
	} else {
		SetDMRState(stateDoc);
		ixmlDocument_free(stateDoc);	
	}
}
Esempio n. 24
0
/********************************************************************************
 * WscUPnPCPSendAction
 *
 * Description: 
 *       Send an Action request to the specified service of a device.
 *
 * Parameters:
 *   devnum -- The number of the device (order in the list,
 *             starting with 1)
 *   actionname -- The name of the action.
 *   param_name -- An array of parameter names
 *   param_val -- The corresponding parameter values
 *   param_count -- The number of parameters
 *
 ********************************************************************************/
int WscUPnPCPSendAction(
	IN uint32 ipAddr,
	IN char *actionname,
	IN char **param_name,
	IN char **param_val,
	IN int param_count)
{
	struct upnpDeviceNode *devnode;
	IXML_Document *actionNode = NULL;
	int rc = WSC_SYS_SUCCESS;
	int param;

    rc = WscUPnPCPGetDevice(ipAddr, &devnode);
	if (rc == WSC_SYS_SUCCESS)
	{
		if (param_count == 0) 
		{
			actionNode = UpnpMakeAction(actionname, WscServiceTypeStr, 0, NULL);
		}
		else
		{
			for (param = 0; param < param_count; param++)
			{
				rc = UpnpAddToAction(actionNode, actionname, WscServiceTypeStr, 
										param_name[param], param_val[param]);
				if (rc != UPNP_E_SUCCESS ) 
				{
					DBGPRINTF(RT_DBG_ERROR, "ERROR: WscUPnPCPSendAction: Trying to add action param, rc=%d!\n", rc);
					//return -1; // TBD - BAD! leaves mutex locked
				}
			}
		}
		DBGPRINTF(RT_DBG_INFO, "ControlURL=%s!\n", devnode->device.services.ControlURL);
		rc = UpnpSendActionAsync( WscCPHandle, devnode->device.services.ControlURL, 
									WscServiceTypeStr, NULL, actionNode, 
									WscUPnPCPDeviceHandler, NULL);

        if (rc != UPNP_E_SUCCESS)
		{
			DBGPRINTF(RT_DBG_ERROR, "Error in UpnpSendActionAsync -- %d\n", rc);
			rc = WSC_SYS_ERROR;
		}
	}
	else 
	{
		DBGPRINTF(RT_DBG_ERROR, "WscUPnPCPGetDevice failed!\n");
	}
	
	if (actionNode)
		ixmlDocument_free(actionNode);

	return rc;
}
Esempio n. 25
0
/*----------------------------------------------------
******FUNCTION NAME:getDMRName
***FUNCTION INPUTS:
**PSystemConfig pConfig:system config
***FUNCTION OUTPUTS:

**FUNCTION DESCRIPTION
**This function will get the dmr name by parse the xml file
**RETURN: 0 ok else error
**HISTORY:
**2009-03-02 James Update
**********************************************************/
int getDMRName(PSystemConfig pConfig)
{
    IXML_Document *rootDom = NULL;
    IXML_NodeList   *nodeList = NULL;
    IXML_Node       *node = NULL;

	/* DMSCFGFILE from /data/MediaServer1.xml */
    rootDom = ixmlLoadDocument(MEDIARENDERCFGFILE);
	
    if (rootDom == NULL )
    {
/*        fprintf(stderr, "Document not parsed successfully.");*/
/*        errIndex = 12;//configure file in wrong format*/
		ZCommandResponseError(GETSYSTEMCONFIGURATION,1);
        return -1;
    }
    nodeList = ixmlDocument_getElementsByTagName(rootDom,"friendlyName");
	
    if (nodeList == NULL)
    {
/*        fprintf(stderr, "empty document");*/
/*        errIndex = 12;//configure file in wrong format*/
		ZCommandResponseError(GETSYSTEMCONFIGURATION,1);
        ixmlDocument_free(rootDom);
        return -1;
    }
    node = ixmlNodeList_item(nodeList, 0);
    if(node)
       pConfig->value = ixmlElementToString(node);

    if (nodeList)
        ixmlNodeList_free(nodeList);

    if (rootDom)
        ixmlDocument_free(rootDom);

    return ZSUCCESS;
	
}
bool cConnectionManager::OnConnectionChange(){
  IXML_Document* PropertySet = NULL;
  UpnpAddToPropertySet(&PropertySet, "CurrentConnectionIDs", GetConnectionIDsCVS().c_str());
  int ret = UpnpNotifyExt(mDeviceHandle, mMediaServer->GetDeviceUUID().c_str(), mServiceDescription.serviceID.c_str(), PropertySet);
  ixmlDocument_free(PropertySet);

  if(ret != UPNP_E_SUCCESS){
      esyslog("UPnP\tState change notification failed (Error code: %d)",ret);
      return false;
  }

  return true;
}
Esempio n. 27
0
/****************************************************************************
*	Function :	soap_device_callback
*
*	Parameters :
*		  IN http_parser_t *parser : Parsed request received by the device
*		  IN http_message_t* request :	HTTP request
*		  INOUT SOCKINFO *info :	socket info
*
*	Description :	This is a callback called by minisever after receiving
*		the request from the control point. This function will start
*		processing the request. It calls handle_invoke_action to handle the
*		SOAP action
*
*	Return :	void
*
*	Note :
****************************************************************************/
void
soap_device_callback( IN http_parser_t * parser,
                      IN http_message_t * request,
                      INOUT SOCKINFO * info )
{
    int err_code;
    const char *err_str;
    memptr action_name;
    IXML_Document *xml_doc = NULL;

    // set default error
    err_code = SOAP_INVALID_ACTION;
    err_str = Soap_Invalid_Action;

    // validate: content-type == text/xml
    if( !has_xml_content_type( request ) ) {
        goto error_handler;
    }
    // type of request
    if( get_request_type( request, &action_name ) != 0 ) {
        goto error_handler;
    }
    // parse XML
    err_code = ixmlParseBufferEx( request->entity.buf, &xml_doc );
    if( err_code != IXML_SUCCESS ) {
        if( err_code == IXML_INSUFFICIENT_MEMORY ) {
            err_code = UPNP_E_OUTOF_MEMORY;
        } else {
            err_code = SOAP_ACTION_FAILED;
        }

        err_str = "XML error";
        goto error_handler;
    }

    if( action_name.length == 0 ) {
        // query var
        handle_query_variable( info, request, xml_doc );
    } else {
        // invoke action
        handle_invoke_action( info, request, action_name, xml_doc );
    }

    err_code = 0;               // no error

error_handler:
    ixmlDocument_free( xml_doc );
    if( err_code != 0 ) {
        send_error_response( info, err_code, err_str, request );
    }
}
Esempio n. 28
0
/*!
 * \brief This is a callback called by minisever after receiving the request
 * from the control point. This function will start processing the request.
 * It calls handle_invoke_action to handle the SOAP action.
 */
void soap_device_callback(
    int iface,
	/*! [in] Parsed request received by the device. */
	http_parser_t *parser,
	/*! [in] HTTP request. */
	http_message_t *request,
	/*! [in,out] Socket info. */
	SOCKINFO *info)
{
	int err_code;
	const char *err_str;
	memptr action_name;
	IXML_Document *xml_doc = NULL;

	/* set default error */
	err_code = SOAP_INVALID_ACTION;
	err_str = Soap_Invalid_Action;

	/* validate: content-type == text/xml */
	if (!has_xml_content_type(request))
		goto error_handler;
	/* type of request */
	if (get_request_type(request, &action_name) != 0)
		goto error_handler;
	/* parse XML */
	err_code = ixmlParseBufferEx(request->entity.buf, &xml_doc);
	if (err_code != IXML_SUCCESS) {
		if (err_code == IXML_INSUFFICIENT_MEMORY)
			err_code = UPNP_E_OUTOF_MEMORY;
		else
			err_code = SOAP_ACTION_FAILED;
		err_str = "XML error";
		goto error_handler;
	}
	if (action_name.length == 0)
		/* query var */
		handle_query_variable(iface, info, request, xml_doc);
	else
		/* invoke action */
		handle_invoke_action(iface, info, request, action_name, xml_doc);
	/* no error */
	err_code = 0;

 error_handler:
	ixmlDocument_free(xml_doc);
	if (err_code != 0)
		send_error_response(info, err_code, err_str, request);
	return;
	parser = parser;
}
Esempio n. 29
0
int xmldoc_free(struct xmldoc *doc)
{
	int result = -1;
	assert(doc != NULL);
#ifdef HAVE_LIBUPNP
	ixmlDocument_free(doc->doc);
#else
#ifdef HAVE_LIBXML
	xmlFreeDoc(doc->doc);
#endif
#endif
	free(doc);
	result = 0;
	return result;
}
Esempio n. 30
0
/*----------------------------------------------------
******FUNCTION NAME:getSWVersion
***FUNCTION INPUTS:
**PSystemConfig pConfig:system config
***FUNCTION OUTPUTS:

**FUNCTION DESCRIPTION
**This function will get the dms name by parse the xml file
**RETURN: 0 ok else error
**HISTORY:
**2009-03-02 James Update
**********************************************************/
int getSWVersion(PSystemConfig pConfig)
{
    IXML_Document *rootDom = NULL;

	/* VERSTIONFILE is the file where in /zapp/version.xml  */
    if((rootDom = ixmlLoadDocument(VERSIONFILE)) == NULL)
        return 1;

	/* Get the <SWVersion> value which in file /zapp/version.xml with tag <software>  */
    pConfig->value = ixmlGetFirstElementItem((IXML_Element *)rootDom, "software");
   
    if (rootDom)
        ixmlDocument_free(rootDom);

    return 0;
}