Пример #1
0
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);
}
Пример #2
0
void PrintIGDInfo(mUpnpDevice *dev, int igdNum)
{
	mUpnpService *ipConService;
	mUpnpAction *extIpAddrAction;
	mUpnpService *wanComIfCfgService;
	mUpnpAction *totalBytesSentAction;
	mUpnpAction *totalBytesRecvAction;

	if (!mupnp_device_isdevicetype(dev, UPNPAVDUMP_IGD_DEVICETYPE))
		return;
	
	printf("[%d] : %s\n", igdNum, mupnp_device_getfriendlyname(dev));

	ipConService = mupnp_device_getservicebytype(dev, UPNPAVDUMP_IGD_WANIPCON_SERVICETYPE);
	if (ipConService) {
		extIpAddrAction = mupnp_service_getactionbyname(ipConService, "GetExternalIPAddress");
		if (extIpAddrAction) {
			if (mupnp_action_post(extIpAddrAction))
				printf("  GetExternalIPAddress = %s\n", mupnp_action_getargumentvaluebyname(extIpAddrAction, "NewExternalIPAddress"));
		}
	}

	wanComIfCfgService = mupnp_device_getservicebytype(dev, UPNPAVDUMP_IGD_WANCOMIFCFG_SERVICETYPE);
	if (wanComIfCfgService) {
		totalBytesSentAction = mupnp_service_getactionbyname(ipConService, "GetTotalBytesSent");
		if (totalBytesSentAction) {
			if (mupnp_action_post(totalBytesSentAction))
				printf("  GetTotalBytesSent = %s\n", mupnp_action_getargumentvaluebyname(totalBytesSentAction, "NewTotalBytesSent"));
		}
		totalBytesRecvAction = mupnp_service_getactionbyname(ipConService, "GetTotalBytesReceived");
		if (totalBytesRecvAction) {
			if (mupnp_action_post(totalBytesRecvAction))
				printf("  GetTotalBytesSent = %s\n", mupnp_action_getargumentvaluebyname(totalBytesRecvAction, "NewTotalBytesReceived"));
		}
	}
}
Пример #3
0
void ControlDeviceAlter(mUpnpControlPoint *ctrlPoint, int alteration_mask)
{
	mUpnpDevice *selDev;
	mUpnpService *selService;
	mUpnpAction *selAction;
	bool actionSuccess;
	mUpnpArgument *arg;
	char argValue[2048];
	
	printf("Control Device\n");
	
	selDev = SelectDevice(ctrlPoint);
	if (selDev == NULL)
		return;
	selService = SelectService(selDev);
	if (selService == NULL)
		return;
	selAction = SelectAction(selService);
	if (selAction == NULL)
		return;
	
	for (arg = mupnp_action_getarguments(selAction); arg; arg = mupnp_argument_next(arg)) {
		if (mupnp_argument_isindirection(arg) == true) {
			printf("%s : ", mupnp_argument_getname(arg));
			if (scanf("%s", argValue) == 1)
				mupnp_argument_setvalue(arg, argValue);
		}
	}

	/* NOTE: Go through selAction memory management... */
	if (alteration_mask & CMD_LOOP_ACTION_CALLS)
	{
		int loop_count, i;

		printf("\nHow many times action should be sent?");
		
		if ( 1 == scanf("%d", &loop_count) )
		{
			printf("\n");
			for (i=0; i<loop_count; i++)
			{
				actionSuccess = mupnp_action_post(selAction);
				printf("Control Result(%d)\n", (int)actionSuccess);
			}

			mupnp_sleep(3000);

			for (	arg = mupnp_action_getarguments(selAction); 
				arg; 
				arg = mupnp_argument_next(arg)) 
			{
				if (mupnp_argument_isoutdirection(arg) == true)
					printf(" %s = %s\n", 
							mupnp_argument_getname(arg), 
							mupnp_argument_getvalue(arg));
			}

			mupnp_sleep(2000);
		}
	}

	if ((alteration_mask & CMD_NO_ALTERATIONS) == CMD_NO_ALTERATIONS)
	{	
		actionSuccess = mupnp_action_post(selAction);
		
		printf("Control Result(%d)\n", (int)actionSuccess);
		for (arg = mupnp_action_getarguments(selAction); arg; arg = mupnp_argument_next(arg)) {
			if (mupnp_argument_isoutdirection(arg) == true)
				printf(" %s = %s\n", mupnp_argument_getname(arg), mupnp_argument_getvalue(arg));
		}
	}
}