Пример #1
0
static void XMLCALL mupnp_expat_element_start(void* userData, const char* el, const char** attr)
{
  mUpnpExpatData* expatData;
  mUpnpXmlNode* node;
  int n;
#if defined DEBUG_XML
  int out, j;
  char* outbuf;
  char* lpout;
#endif

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

#if defined DEBUG_XML
  outbuf = (char*)malloc(4096);
  lpout = outbuf;
  outbuf[4095] = (char)0;
  for (out = 0; out < indent; out++)
    outbuf[out] = (char)' ';
  lpout += out;
  for (j = 0; attr[j]; j += 2) {
    lpout += sprintf(lpout, "%s='%s'", attr[j], attr[j + 1]);
  }
  lpout[0] = 0;
  printf("%8x XML Node start %s - %d Attribute %s\n", userData, el, j / 2, outbuf);
  free(outbuf);
  ++indent;
#endif
  //memdiags_memlist_report_unmarkedsize();

  expatData = (mUpnpExpatData*)userData;

  node = mupnp_xml_node_new();
  mupnp_xml_node_setname(node, (char*)el);

  for (n = 0; attr[n]; n += 2)
    mupnp_xml_node_setattribute(node, (char*)attr[n], (char*)attr[n + 1]);

  if (expatData->rootNode != NULL) {
    if (expatData->currNode != NULL)
      mupnp_xml_node_addchildnode(expatData->currNode, node);
    else
      mupnp_xml_node_addchildnode(expatData->rootNode, node);
  }
  else
    expatData->rootNode = node;

  expatData->currNode = node;

  mupnp_log_debug_l4("Leaving...\n");
}
Пример #2
0
void mupnp_control_action_response_setresponse(mUpnpActionResponse *actionRes, mUpnpAction *action)
{
	mUpnpSoapResponse *soapRes;
	mUpnpHttpResponse *httpRes;
	mUpnpXmlNode *bodyNode;
	mUpnpXmlNode *resNode;
	mUpnpXmlNode *envNode;

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

	soapRes = mupnp_control_action_response_getsoapresponse(actionRes);
	httpRes = mupnp_soap_response_gethttpresponse(soapRes);

	mupnp_http_response_setstatuscode(httpRes, MUPNP_HTTP_STATUS_OK);
	mupnp_control_soap_response_initializeenvelopenode(soapRes);

	bodyNode = mupnp_soap_response_getbodynode(soapRes);
	resNode = mupnp_control_action_response_createresponsenode(action);
	mupnp_xml_node_addchildnode(bodyNode, resNode);
	
	envNode = mupnp_soap_response_getenvelopenode(soapRes);
	mupnp_soap_response_setcontent(soapRes, envNode);

	mupnp_log_debug_l4("Leaving...\n");
}
Пример #3
0
void mupnp_xml_node_copy(mUpnpXmlNode *dstNode, mUpnpXmlNode *srcNode)
{
	mUpnpXmlAttribute *attr;
	mUpnpXmlNode *dstChildNode;
	mUpnpXmlNode *srcChildNode;
	
	mupnp_log_debug_l4("Entering...\n");
	
	if (!dstNode || !srcNode)
		return;

	mupnp_xml_node_setname(dstNode, mupnp_xml_node_getname(srcNode));
	mupnp_xml_node_setvalue(dstNode, mupnp_xml_node_getvalue(srcNode));
	
	for (attr = mupnp_xml_node_getattributes(srcNode); attr != NULL; attr = mupnp_xml_attribute_next(attr))
		mupnp_xml_node_setattribute(dstNode, mupnp_xml_attribute_getname(attr), mupnp_xml_attribute_getvalue(attr));
	
	for (srcChildNode = mupnp_xml_node_getchildnodes(srcNode); srcChildNode != NULL; srcChildNode = mupnp_xml_node_next(srcChildNode)) {
		dstChildNode = mupnp_xml_node_new();
		mupnp_xml_node_copy(dstChildNode, srcChildNode);
		mupnp_xml_node_addchildnode(dstNode, dstChildNode);
	}
	
	 mupnp_log_debug_l4("Leaving...\n");
}
Пример #4
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");
}
Пример #5
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;
}
Пример #6
0
static mUpnpXmlNode *mupnp_control_action_response_createresponsenode(mUpnpAction *action)
{
	mUpnpXmlNode *actionNameResNode;
	char nodeName[MUPNP_ACTOINNAME_LEN_MAX + sizeof(MUPNP_SOAP_METHODNS) + sizeof(MUPNP_SOAP_DELIM) + sizeof(MUPNP_SOAP_RESPONSE) + 1];
	char attrName[sizeof(MUPNP_SOAP_ATTRIBUTE_XMLNS) + sizeof(MUPNP_SOAP_DELIM) + sizeof(MUPNP_SOAP_METHODNS) + 1];
	const char *actionName;
	mUpnpXmlNode *serviceNode;
	mUpnpService *service;
	mUpnpArgumentList *argList;
	mUpnpArgument *arg;
	mUpnpXmlNode *argNode;
	
	mupnp_log_debug_l4("Entering...\n");

	actionNameResNode = mupnp_xml_node_new();

	/* action name */
	actionName = mupnp_action_getname(action);
	mupnp_strcpy(nodeName, MUPNP_SOAP_METHODNS);
	mupnp_strcat(nodeName, MUPNP_SOAP_DELIM);
	mupnp_strncat(nodeName, actionName, MUPNP_ACTOINNAME_LEN_MAX);
	mupnp_strcat(nodeName, MUPNP_SOAP_RESPONSE);
	mupnp_xml_node_setname(actionNameResNode, nodeName);

	/* service attribute */
	serviceNode = mupnp_service_getservicenode(mupnp_action_getservice(action));
	if (serviceNode != NULL) {
		service = mupnp_service_new();
		mupnp_service_setservicenode(service, serviceNode);
		mupnp_strcpy(attrName, MUPNP_SOAP_ATTRIBUTE_XMLNS);
		mupnp_strcat(attrName, MUPNP_SOAP_DELIM);
		mupnp_strcat(attrName, MUPNP_SOAP_METHODNS);
		mupnp_xml_node_setattribute(actionNameResNode, attrName, mupnp_service_getservicetype(service));
		mupnp_service_delete(service);
	}

	/* arguments */
	argList = mupnp_action_getargumentlist(action);
	for (arg = mupnp_argumentlist_gets(argList); arg != NULL; arg = mupnp_argument_next(arg)) {
		if (mupnp_argument_isoutdirection(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(actionNameResNode, argNode);
	}

	return actionNameResNode;

	mupnp_log_debug_l4("Leaving...\n");
}
Пример #7
0
void mupnp_xml_node_setchildnode(mUpnpXmlNode *node, const char *name, const char *value)
{
	mUpnpXmlNode *childNode;

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

	childNode = mupnp_xml_node_getchildnode(node, name);
	if (childNode != NULL) {
		mupnp_xml_node_setvalue(childNode, value);
		return;
	}
	childNode = mupnp_xml_node_new();
	mupnp_xml_node_setname(childNode, name);
	mupnp_xml_node_setvalue(childNode, value);
	
	mupnp_xml_node_addchildnode(node, childNode);

	mupnp_log_debug_l4("Leaving...\n");
}
Пример #8
0
mUpnpXmlNode *mupnp_soap_createenvelopebodynode()
{
	mUpnpXmlNode *envNode;
	mUpnpXmlNode *bodyNode;
	
	mupnp_log_debug_l4("Entering...\n");

	envNode = mupnp_xml_node_new();
	mupnp_xml_node_setname(envNode, CG_SOAP_XMLNS CG_SOAP_DELIM CG_SOAP_ENVELOPE);
	mupnp_xml_node_setattribute(envNode, CG_SOAP_ATTRIBUTE_XMLNS CG_SOAP_DELIM CG_SOAP_XMLNS, CG_SOAP_XMLNS_URL);
	mupnp_xml_node_setattribute(envNode, CG_SOAP_XMLNS CG_SOAP_DELIM CG_SOAP_ENCORDING, CG_SOAP_ENCSTYLE_URL);

	bodyNode = mupnp_xml_node_new();
	mupnp_xml_node_setname(bodyNode, CG_SOAP_XMLNS CG_SOAP_DELIM CG_SOAP_BODY);
	mupnp_xml_node_addchildnode(envNode, bodyNode);

	return envNode;

	mupnp_log_debug_l4("Leaving...\n");
}
Пример #9
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;
}