miniupnpc-libevent: handle error cases
This commit is contained in:
parent
b642e74124
commit
8325b715d3
|
@ -194,7 +194,9 @@ static void upnpc_receive_and_parse_ssdp(evutil_socket_t s, short events, upnpc_
|
||||||
/* we already have found a device */
|
/* we already have found a device */
|
||||||
} else if(!devices_to_search[p->device_index]) {
|
} else if(!devices_to_search[p->device_index]) {
|
||||||
debug_printf("*** NO MORE DEVICES TO SEARCH ***\n");
|
debug_printf("*** NO MORE DEVICES TO SEARCH ***\n");
|
||||||
/* no device found : set error */
|
event_del(p->ev_ssdp_recv);
|
||||||
|
/* no device found : report error */
|
||||||
|
p->ready_cb(UPNPC_ERR_NO_DEVICE_FOUND, p->cb_data);
|
||||||
} else {
|
} else {
|
||||||
/* send another SSDP M-SEARCH packet */
|
/* send another SSDP M-SEARCH packet */
|
||||||
if(event_add(p->ev_ssdp_writable, NULL)) {
|
if(event_add(p->ev_ssdp_writable, NULL)) {
|
||||||
|
@ -223,8 +225,10 @@ static void upnpc_receive_and_parse_ssdp(evutil_socket_t s, short events, upnpc_
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
upnpc_get_desc(p, p->root_desc_location);
|
upnpc_get_desc(p, p->root_desc_location);
|
||||||
|
event_del(p->ev_ssdp_recv); /* stop receiving SSDP responses */
|
||||||
} else {
|
} else {
|
||||||
/* or do nothing ? */
|
/* or do nothing ? */
|
||||||
|
debug_printf("no location\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -337,9 +341,15 @@ static void upnpc_desc_received(struct evhttp_request * req, void * pvoid)
|
||||||
len = evbuffer_get_length(input_buffer);
|
len = evbuffer_get_length(input_buffer);
|
||||||
data = evbuffer_pullup(input_buffer, len);
|
data = evbuffer_pullup(input_buffer, len);
|
||||||
debug_printf("upnpc_desc_received %d (%d bytes)\n", evhttp_request_get_response_code(req), (int)len);
|
debug_printf("upnpc_desc_received %d (%d bytes)\n", evhttp_request_get_response_code(req), (int)len);
|
||||||
debug_printf("%.*s\n", (int)len, (char *)data);
|
if(evhttp_request_get_response_code(req) != HTTP_OK) {
|
||||||
if(data == NULL)
|
p->ready_cb(evhttp_request_get_response_code(req), p->cb_data);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
if(data == NULL) {
|
||||||
|
p->ready_cb(UPNPC_ERR_ROOT_DESC_ERROR, p->cb_data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
debug_printf("%.*s\n", (int)len, (char *)data);
|
||||||
|
|
||||||
memset(&igd, 0, sizeof(struct IGDdatas));
|
memset(&igd, 0, sizeof(struct IGDdatas));
|
||||||
memset(&parser, 0, sizeof(struct xmlparser));
|
memset(&parser, 0, sizeof(struct xmlparser));
|
||||||
|
@ -559,6 +569,7 @@ int upnpc_init(upnpc_t * p, struct event_base * base, const char * multicastif,
|
||||||
if(setsockopt(p->ssdp_socket, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) {
|
if(setsockopt(p->ssdp_socket, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) {
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
/* non fatal error ! */
|
/* non fatal error ! */
|
||||||
|
debug_printf("setsockopt(%d, SOL_SOCKET, SO_REUSEADDR, ...) FAILED\n", p->ssdp_socket);
|
||||||
}
|
}
|
||||||
if(evutil_make_socket_nonblocking(p->ssdp_socket) < 0) {
|
if(evutil_make_socket_nonblocking(p->ssdp_socket) < 0) {
|
||||||
debug_printf("evutil_make_socket_nonblocking FAILED\n");
|
debug_printf("evutil_make_socket_nonblocking FAILED\n");
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: miniupnpc-libevent.h,v 1.8 2014/11/18 09:10:16 nanard Exp $ */
|
/* $Id: miniupnpc-libevent.h,v 1.9 2014/11/25 22:49:19 nanard Exp $ */
|
||||||
/* miniupnpc-libevent
|
/* miniupnpc-libevent
|
||||||
* Copyright (c) 2008-2014, Thomas BERNARD <miniupnp@free.fr>
|
* Copyright (c) 2008-2014, Thomas BERNARD <miniupnp@free.fr>
|
||||||
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||||
|
@ -30,7 +30,9 @@ extern "C" {
|
||||||
#define UPNPC_ERR_INVALID_ARGS (-1)
|
#define UPNPC_ERR_INVALID_ARGS (-1)
|
||||||
#define UPNPC_ERR_SOCKET_FAILED (-2)
|
#define UPNPC_ERR_SOCKET_FAILED (-2)
|
||||||
#define UPNPC_ERR_BIND_FAILED (-3)
|
#define UPNPC_ERR_BIND_FAILED (-3)
|
||||||
#define UPNPC_ERR_UNKNOWN_STATE (-4)
|
|
||||||
|
#define UPNPC_ERR_NO_DEVICE_FOUND (-100)
|
||||||
|
#define UPNPC_ERR_ROOT_DESC_ERROR (-101)
|
||||||
|
|
||||||
typedef void(* upnpc_callback_fn)(int, void *);
|
typedef void(* upnpc_callback_fn)(int, void *);
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* $Id: upnpc-libevent.c,v 1.8 2014/11/18 09:10:16 nanard Exp $ */
|
/* $Id: upnpc-libevent.c,v 1.9 2014/11/25 22:49:19 nanard Exp $ */
|
||||||
/* miniupnpc-libevent
|
/* miniupnpc-libevent
|
||||||
* Copyright (c) 2008-2014, Thomas BERNARD <miniupnp@free.fr>
|
* Copyright (c) 2008-2014, Thomas BERNARD <miniupnp@free.fr>
|
||||||
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||||
|
@ -40,9 +40,26 @@ static void sighandler(int signal)
|
||||||
static void ready(int code, void * data)
|
static void ready(int code, void * data)
|
||||||
{
|
{
|
||||||
upnpc_t * p = (upnpc_t *)data;
|
upnpc_t * p = (upnpc_t *)data;
|
||||||
printf("READY ! %d %p\n", code, data);
|
if(code == 200) {
|
||||||
|
printf("READY ! %d\n", code);
|
||||||
/* 1st request */
|
/* 1st request */
|
||||||
upnpc_get_status_info(p);
|
upnpc_get_status_info(p);
|
||||||
|
} else {
|
||||||
|
printf("DISCOVER ERROR : %d\n", code);
|
||||||
|
switch(code) {
|
||||||
|
case UPNPC_ERR_NO_DEVICE_FOUND:
|
||||||
|
printf("UPNPC_ERR_NO_DEVICE_FOUND\n");
|
||||||
|
break;
|
||||||
|
case UPNPC_ERR_ROOT_DESC_ERROR:
|
||||||
|
printf("UPNPC_ERR_ROOT_DESC_ERROR\n");
|
||||||
|
break;
|
||||||
|
case 404:
|
||||||
|
printf("Root desc not found (404)\n");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf("unknown error\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum {
|
static enum {
|
||||||
|
@ -87,8 +104,8 @@ static void soap(int code, void * data)
|
||||||
case EDeletePortMapping:
|
case EDeletePortMapping:
|
||||||
printf("OK!\n");
|
printf("OK!\n");
|
||||||
state = EFinished;
|
state = EFinished;
|
||||||
default:
|
/*default:
|
||||||
event_base_loopbreak(base);
|
event_base_loopbreak(base);*/
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
printf("SOAP error :\n");
|
printf("SOAP error :\n");
|
||||||
|
|
Loading…
Reference in New Issue