From 215b357e55f53c98fac559e7e07d2e8f7bad4352 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Mon, 8 Dec 2014 17:23:29 +0100 Subject: [PATCH] miniupnpc-libevent: prevent several SOAP request at the same time. --- miniupnpc-libevent/miniupnpc-libevent.c | 7 ++++++- miniupnpc-libevent/miniupnpc-libevent.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/miniupnpc-libevent/miniupnpc-libevent.c b/miniupnpc-libevent/miniupnpc-libevent.c index c4b593c..995575c 100644 --- a/miniupnpc-libevent/miniupnpc-libevent.c +++ b/miniupnpc-libevent/miniupnpc-libevent.c @@ -427,6 +427,7 @@ static void upnpc_soap_response(struct evhttp_request * req, void * pvoid) ClearNameValueList(&d->soap_response_data); ParseNameValue((char *)data, (int)len, &d->soap_response_data); + d->state &= ~UPNPC_DEVICE_SOAP_REQ; if(d->state & UPNPC_DEVICE_READY) { d->parent->soap_cb(code, d->parent, d, d->parent->cb_data); } else if(d->state & UPNPC_DEVICE_GETSTATUS) { @@ -442,7 +443,6 @@ static void upnpc_soap_response(struct evhttp_request * req, void * pvoid) d->parent->ready_cb(UPNPC_ERR_NOT_CONNECTED, d->parent, d, d->parent->cb_data); } } - d->state &= ~UPNPC_DEVICE_SOAP_REQ; } static int upnpc_get_desc(upnpc_device_t * d, const char * url) @@ -538,6 +538,11 @@ static int upnpc_send_soap_request(upnpc_device_t * p, const char * url, struct evkeyvalq * headers; struct evbuffer * buffer; + if(p->state & UPNPC_DEVICE_SOAP_REQ) { + debug_printf("%s: another SOAP request in progress\n", __func__); + return UPNPC_ERR_REQ_IN_PROGRESS; + } + if(arg_count > 0) { int i; size_t l, n; diff --git a/miniupnpc-libevent/miniupnpc-libevent.h b/miniupnpc-libevent/miniupnpc-libevent.h index 9daebf7..dd15a5d 100644 --- a/miniupnpc-libevent/miniupnpc-libevent.h +++ b/miniupnpc-libevent/miniupnpc-libevent.h @@ -32,6 +32,7 @@ extern "C" { #define UPNPC_ERR_INVALID_ARGS (-1) #define UPNPC_ERR_SOCKET_FAILED (-2) #define UPNPC_ERR_BIND_FAILED (-3) +#define UPNPC_ERR_REQ_IN_PROGRESS (-4) #define UPNPC_ERR_NO_DEVICE_FOUND (-100) #define UPNPC_ERR_ROOT_DESC_ERROR (-101)