如何制作动作?

时间:2010-12-16 10:00:49

标签: c++ c xml linux upnp

我想使用intel-upnp实现端口转发。 我得到了如下的XML数据:

Device found at location: http://192.168.10.1:49152/gatedesc.xml  
service urn:schemas-upnp-org:service:WANIPConnection:1  
controlurl /upnp/control/WANIPConn1  
eventsuburl : /upnp/control/WANIPConn1  
scpdurl : /gateconnSCPD.xml  

现在,我想做出行动。但是,我不知道如何制作它。 如果你在C中知道一些代码段或有用的URL,请告诉我。

char actionxml[250];  
IXML_Document *action = NULL;  
strcpy(actionxml, "<u:GetConnectionTypeInfo xmlns:u=\"urn:schemas-upnp- org:service:WANCommonInterfaceConfig:1\">");  
action = ixmlParseBuffer(actionxml);  
int ret = UpnpSendActionAsync( g_handle,
                    "http:192.168.10.1:49152/upnp/control/WANCommonIFC1",
                    "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1",
                    NULL,
                    action,
                    upnp_callback,
                    NULL);

1 个答案:

答案 0 :(得分:1)

我知道这是一个古老的问题,但可以保留以供参考。您可以在以下位置查看libupnp库中的示例代码:https://github.com/mrjimenez/pupnp/blob/master/upnp/sample/common/tv_ctrlpt.c

相关代码在函数TvCtrlPointSendAction()中:

const arr = ["foo", "bar", "foo", "bar", "bar", "bar", "zoom"];

const data = Object.assign({}, ...Array.from(new Set(arr), key => ({[key]: arr.filter(value => value === key).length})));

console.log(data);

解释是,如果没有参数,则应使用UpnpMakeAction()创建操作;如果有参数来创建操作,则应使用UpnpAddToAction()创建该操作,然后以同步或异步方式发送。

相关问题