コード例 #1
0
ファイル: ccontentdir_service.c プロジェクト: jink2005/mupnpc
/****************************************
* 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;
}
コード例 #2
0
ファイル: upnpavdump.c プロジェクト: Coramo/mupnp
void PrintContentDirectory(mUpnpAction* browseAction, int indent, const char* objectId)
{
  int n;
  char indentStr[128];
  char* resultXml;
  mUpnpXmlParser* xmlParser;
  mUpnpXmlNodeList* rootNode;
  mUpnpXmlNode* didlNode;
  mUpnpXmlNode* cnode;
  const char* id;
  const char* title;
  const char* url;

  for (n = 0; n < indent && n < (sizeof(indentStr) - 1); n++)
    indentStr[n] = ' ';
  indentStr[n] = '\0';

  mupnp_action_setargumentvaluebyname(browseAction, "ObjectID", objectId);
  mupnp_action_setargumentvaluebyname(browseAction, "BrowseFlag", "BrowseDirectChildren");
  mupnp_action_setargumentvaluebyname(browseAction, "Filter", "*");
  mupnp_action_setargumentvaluebyname(browseAction, "StartingIndex", "0");
  mupnp_action_setargumentvaluebyname(browseAction, "RequestedCount", "0");
  mupnp_action_setargumentvaluebyname(browseAction, "SortCriteria", "");

  if (!mupnp_action_post(browseAction))
    return;

  resultXml = mupnp_action_getargumentvaluebyname(browseAction, "Result");
  if (mupnp_strlen(resultXml) <= 0)
    return;

  rootNode = mupnp_xml_nodelist_new();
  xmlParser = mupnp_xml_parser_new();
  if (mupnp_xml_parse(xmlParser, rootNode, resultXml, mupnp_strlen(resultXml))) {
    didlNode = mupnp_xml_nodelist_getbyname(rootNode, "DIDL-Lite");
    if (didlNode) {
      for (cnode = mupnp_xml_node_getchildnodes(didlNode); cnode; cnode = mupnp_xml_node_next(cnode)) {
        id = mupnp_xml_node_getattributevalue(cnode, "id");
        title = mupnp_xml_node_getchildnodevalue(cnode, "dc:title");
        if (mupnp_xml_node_isname(cnode, "container")) {
          printf(" %s[%s]%s\n",
              indentStr,
              id,
              ((0 < mupnp_strlen(title)) ? title : ""));
          PrintContentDirectory(browseAction, (indent + 1), id);
        }
        else {
          url = mupnp_xml_node_getchildnodevalue(cnode, "res");
          printf(" %s[%s]%s (%s)\n",
              indentStr,
              id,
              ((0 < mupnp_strlen(title)) ? title : ""),
              ((0 < mupnp_strlen(url)) ? url : ""));
        }
      }
    }
  }
  mupnp_xml_nodelist_delete(rootNode);
  mupnp_xml_parser_delete(xmlParser);
}
コード例 #3
0
ファイル: ccontentdir_service.c プロジェクト: jink2005/mupnpc
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;
}