miniupnpc-libevent: add upnpc_get_status_info()

This commit is contained in:
Thomas Bernard 2014-11-18 10:31:59 +01:00
parent 3690785a79
commit d4bf4c7572
3 changed files with 23 additions and 7 deletions

View File

@ -1,4 +1,4 @@
/* $Id: miniupnpc-libevent.c,v 1.14 2014/11/17 19:20:45 nanard Exp $ */
/* $Id: miniupnpc-libevent.c,v 1.15 2014/11/18 09:10:16 nanard Exp $ */
/* miniupnpc-libevent
* Copyright (c) 2008-2014, Thomas BERNARD <miniupnp@free.fr>
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
@ -711,3 +711,9 @@ int upnpc_add_port_mapping(upnpc_t * p,
args, 8);
}
int upnpc_get_status_info(upnpc_t * p)
{
return upnpc_send_soap_request(p, p->control_conn_url,
p->conn_service_type/*"urn:schemas-upnp-org:service:WANIPConnection:1"*/,
"GetStatusInfo", NULL, 0);
}

View File

@ -1,4 +1,4 @@
/* $Id: miniupnpc-libevent.h,v 1.7 2014/11/17 10:14:16 nanard Exp $ */
/* $Id: miniupnpc-libevent.h,v 1.8 2014/11/18 09:10:16 nanard Exp $ */
/* miniupnpc-libevent
* Copyright (c) 2008-2014, Thomas BERNARD <miniupnp@free.fr>
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
@ -72,6 +72,8 @@ int upnpc_delete_port_mapping(upnpc_t * p,
const char * remote_host, unsigned short ext_port,
const char * proto);
int upnpc_get_status_info(upnpc_t * p);
#ifdef UPNPC_USE_SELECT
int upnpc_select_fds(upnpc_t * p, int * nfds, fd_set * readfds, fd_set * writefds);
#endif /* UPNPC_USE_SELECT */

View File

@ -1,4 +1,4 @@
/* $Id: upnpc-libevent.c,v 1.7 2014/11/14 11:37:45 nanard Exp $ */
/* $Id: upnpc-libevent.c,v 1.8 2014/11/18 09:10:16 nanard Exp $ */
/* miniupnpc-libevent
* Copyright (c) 2008-2014, Thomas BERNARD <miniupnp@free.fr>
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
@ -42,16 +42,17 @@ static void ready(int code, void * data)
upnpc_t * p = (upnpc_t *)data;
printf("READY ! %d %p\n", code, data);
/* 1st request */
upnpc_get_external_ip_address(p);
upnpc_get_status_info(p);
}
static enum {
EGetExtIp = 0,
EGetStatusInfo = 0,
EGetExtIp,
EGetMaxRate,
EAddPortMapping,
EDeletePortMapping,
EFinished
} state = EGetExtIp;
} state = EGetStatusInfo;
/* soap callback */
static void soap(int code, void * data)
@ -60,8 +61,15 @@ static void soap(int code, void * data)
printf("SOAP ! %d\n", code);
if(code == 200) {
switch(state) {
case EGetStatusInfo:
printf("ConnectionStatus=%s\n", GetValueFromNameValueList(&p->soap_response_data, "NewConnectionStatus"));
printf("LastConnectionError=%s\n", GetValueFromNameValueList(&p->soap_response_data, "NewLastConnectionError"));
printf("Uptime=%s\n", GetValueFromNameValueList(&p->soap_response_data, "NewUptime"));
upnpc_get_external_ip_address(p);
state = EGetExtIp;
break;
case EGetExtIp:
printf("ExternalIpAddres=%s\n", GetValueFromNameValueList(&p->soap_response_data, "NewExternalIPAddress"));
printf("ExternalIpAddress=%s\n", GetValueFromNameValueList(&p->soap_response_data, "NewExternalIPAddress"));
upnpc_get_link_layer_max_rate(p);
state = EGetMaxRate;
break;