use Linux libuuid uuid_generate() / BSD uuid_create() API
This commit is contained in:
parent
19211d20d1
commit
6059f000f7
|
@ -1,4 +1,7 @@
|
|||
$Id: Changelog.txt,v 1.416 2016/01/19 10:03:28 nanard Exp $
|
||||
$Id: Changelog.txt,v 1.418 2016/02/11 10:35:11 nanard Exp $
|
||||
|
||||
2016/02/11:
|
||||
use Linux libuuid uuid_generate() / BSD uuid_create() API
|
||||
|
||||
2016/01/28:
|
||||
renamed iptables chain MINIUPNPD-PCP-PEER to MINIUPNPD-POSTROUTING
|
||||
|
|
|
@ -148,6 +148,7 @@ LDLIBS += $(shell $(PKG_CONFIG) --static --libs-only-l libnetfilter_conntrack)
|
|||
endif # ($(TEST),1)
|
||||
|
||||
LDLIBS += $(shell $(PKG_CONFIG) --static --libs-only-l libssl)
|
||||
LDLIBS += $(shell $(PKG_CONFIG) --static --libs-only-l uuid)
|
||||
|
||||
TESTUPNPDESCGENOBJS = testupnpdescgen.o upnpdescgen.o
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#! /bin/sh
|
||||
# $Id: genconfig.sh,v 1.81 2015/07/16 15:00:21 nanard Exp $
|
||||
# $Id: genconfig.sh,v 1.90 2016/02/11 10:35:12 nanard Exp $
|
||||
# miniupnp daemon
|
||||
# http://miniupnp.free.fr or http://miniupnp.tuxfamily.org/
|
||||
# (c) 2006-2016 Thomas Bernard
|
||||
|
@ -366,7 +366,15 @@ case $FW in
|
|||
;;
|
||||
esac
|
||||
|
||||
# set V6SOCKETS_ARE_V6ONLY to 0 if it was not set above
|
||||
# UUID API
|
||||
if grep uuid_create /usr/include/uuid.h > /dev/null 2>&1 ; then
|
||||
echo "#define BSD_UUID" >> ${CONFIGFILE}
|
||||
fi
|
||||
if grep uuid_generate /usr/include/uuid/uuid.h > /dev/null 2>&1 ; then
|
||||
echo "#define LIB_UUID" >> ${CONFIGFILE}
|
||||
fi
|
||||
|
||||
# set V6SOCKETS_ARE_V6ONLY to 0 if it was not set above
|
||||
if [ -z "$V6SOCKETS_ARE_V6ONLY" ] ; then
|
||||
V6SOCKETS_ARE_V6ONLY=0
|
||||
fi
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* $Id: upnpevents.c,v 1.31 2015/12/12 09:36:22 nanard Exp $ */
|
||||
/* $Id: upnpevents.c,v 1.34 2016/02/11 10:35:13 nanard Exp $ */
|
||||
/* MiniUPnP project
|
||||
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||
* (c) 2008-2015 Thomas Bernard
|
||||
* (c) 2008-2016 Thomas Bernard
|
||||
* This software is subject to the conditions detailed
|
||||
* in the LICENCE file provided within the distribution */
|
||||
|
||||
|
@ -18,6 +18,12 @@
|
|||
#include <arpa/inet.h>
|
||||
#include <errno.h>
|
||||
#include "config.h"
|
||||
#if defined(LIB_UUID)
|
||||
/* as found on linux */
|
||||
#include <uuid/uuid.h>
|
||||
#elif defined(BSD_UUID)
|
||||
#include <uuid.h>
|
||||
#endif /* LIB_UUID / BSD_UUID */
|
||||
#include "upnpevents.h"
|
||||
#include "miniupnpdpath.h"
|
||||
#include "upnpglobalvars.h"
|
||||
|
@ -108,11 +114,50 @@ newSubscriber(const char * eventurl, const char * callback, int callbacklen)
|
|||
}
|
||||
memcpy(tmp->callback, callback, callbacklen);
|
||||
tmp->callback[callbacklen] = '\0';
|
||||
#if defined(LIB_UUID)
|
||||
{
|
||||
uuid_t uuid;
|
||||
uuid_generate(uuid);
|
||||
memcpy(tmp->uuid, "uuid:", 5);
|
||||
uuid_unparse(uuid, tmp->uuid + 5);
|
||||
}
|
||||
#elif defined(BSD_UUID)
|
||||
{
|
||||
uuid_t uuid;
|
||||
uint32_t status;
|
||||
uuid_create(&uuid, &status);
|
||||
if(status != uuid_s_ok) {
|
||||
syslog(LOG_ERR, "uuid_create() failed (%u)", status);
|
||||
} else {
|
||||
char * uuid_str;
|
||||
uuid_to_string(&uuid, &uuid_str, &status);
|
||||
if(status != uuid_s_ok) {
|
||||
syslog(LOG_ERR, "uuid_to_string() failed (%u)", status);
|
||||
} else {
|
||||
if(strlen(uuid_str) != 36) {
|
||||
syslog(LOG_ERR, "uuid_to_string() returned %s", uuid_str);
|
||||
status = (uint32_t)-1;
|
||||
} else {
|
||||
memcpy(tmp->uuid, "uuid:", 5);
|
||||
memcpy(tmp->uuid + 5, uuid_str, 36)
|
||||
tmp->uuid[sizeof(tmp->uuid)-1] = '\0';
|
||||
}
|
||||
free(uuid_str);
|
||||
}
|
||||
}
|
||||
if(status != uuid_s_ok) {
|
||||
/* make a dummy uuid */
|
||||
strncpy(tmp->uuid, uuidvalue_igd, sizeof(tmp->uuid));
|
||||
tmp->uuid[sizeof(tmp->uuid)-1] = '\0';
|
||||
snprintf(tmp->uuid+sizeof(tmp->uuid)-5, 5, "%04lx", random() & 0xffff);
|
||||
}
|
||||
}
|
||||
#else
|
||||
/* make a dummy uuid */
|
||||
/* TODO: improve that */
|
||||
strncpy(tmp->uuid, uuidvalue_igd, sizeof(tmp->uuid));
|
||||
tmp->uuid[sizeof(tmp->uuid)-1] = '\0';
|
||||
snprintf(tmp->uuid+sizeof(tmp->uuid)-5, 5, "%04lx", random() & 0xffff);
|
||||
#endif
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue