From d4bf4c7572e28f4d66845518deff4b0063c692d0 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Tue, 18 Nov 2014 10:31:59 +0100 Subject: [PATCH] miniupnpc-libevent: add upnpc_get_status_info() --- miniupnpc-libevent/miniupnpc-libevent.c | 8 +++++++- miniupnpc-libevent/miniupnpc-libevent.h | 4 +++- miniupnpc-libevent/upnpc-libevent.c | 18 +++++++++++++----- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/miniupnpc-libevent/miniupnpc-libevent.c b/miniupnpc-libevent/miniupnpc-libevent.c index 5274a82..b6fa275 100644 --- a/miniupnpc-libevent/miniupnpc-libevent.c +++ b/miniupnpc-libevent/miniupnpc-libevent.c @@ -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 * 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); +} diff --git a/miniupnpc-libevent/miniupnpc-libevent.h b/miniupnpc-libevent/miniupnpc-libevent.h index 07d8f33..16c80b8 100644 --- a/miniupnpc-libevent/miniupnpc-libevent.h +++ b/miniupnpc-libevent/miniupnpc-libevent.h @@ -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 * 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 */ diff --git a/miniupnpc-libevent/upnpc-libevent.c b/miniupnpc-libevent/upnpc-libevent.c index 104ad5f..6f5af5f 100644 --- a/miniupnpc-libevent/upnpc-libevent.c +++ b/miniupnpc-libevent/upnpc-libevent.c @@ -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 * 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;