Rename uuid_t --> serval_uuid_t

To avoid compile errors on OSX
This commit is contained in:
Andrew Bettison 2014-02-17 13:26:03 +10:30
parent 800d3c6120
commit a77b0702b1
5 changed files with 29 additions and 27 deletions

View File

@ -408,7 +408,7 @@ int create_rhizome_datastore_dir();
#define FORM_RHIZOME_IMPORT_PATH(buf,fmt,...) (form_rhizome_import_path((buf), sizeof(buf), (fmt), ##__VA_ARGS__))
extern sqlite3 *rhizome_db;
uuid_t rhizome_db_uuid;
serval_uuid_t rhizome_db_uuid;
int rhizome_opendb();
int rhizome_close_db();
@ -540,7 +540,7 @@ enum sqlbind_type {
TOHEX, // const unsigned char *binary, unsigned bytes
TEXT_TOUPPER, // const char *text,
TEXT_LEN_TOUPPER, // const char *text, unsigned bytes
UUID_T, // const uuid_t *uuidp
SERVAL_UUID_T, // const serval_uuid_t *uuidp
NUL = 1 << 15, // NUL (no arg) ; NUL|INT, ...
INDEX = 0xfade0000, // INDEX|INT, int index, ...
NAMED = 0xdead0000 // NAMED|INT, const char *label, ...

View File

@ -77,7 +77,7 @@ int create_rhizome_datastore_dir()
}
sqlite3 *rhizome_db = NULL;
uuid_t rhizome_db_uuid;
serval_uuid_t rhizome_db_uuid;
/* XXX Requires a messy join that might be slow. */
int rhizome_manifest_priority(sqlite_retry_state *retry, const rhizome_bid_t *bidp)
@ -321,7 +321,7 @@ int rhizome_opendb()
WHYF("IDENTITY table contains malformed UUID %s -- overwriting", alloca_str_toprint(buf));
if (uuid_generate_random(&rhizome_db_uuid) == -1)
RETURN(WHY("Cannot generate new UUID for Rhizome database"));
if (sqlite_exec_void_retry(&retry, "UPDATE IDENTITY SET uuid = ? LIMIT 1;", UUID_T, &rhizome_db_uuid, END) == -1)
if (sqlite_exec_void_retry(&retry, "UPDATE IDENTITY SET uuid = ? LIMIT 1;", SERVAL_UUID_T, &rhizome_db_uuid, END) == -1)
RETURN(WHY("Failed to update new UUID in Rhizome database"));
if (config.debug.rhizome)
DEBUGF("Updated Rhizome database UUID to %s", alloca_uuid_str(rhizome_db_uuid));
@ -329,7 +329,7 @@ int rhizome_opendb()
} else if (r == 0) {
if (uuid_generate_random(&rhizome_db_uuid) == -1)
RETURN(WHY("Cannot generate UUID for Rhizome database"));
if (sqlite_exec_void_retry(&retry, "INSERT INTO IDENTITY (uuid) VALUES (?);", UUID_T, &rhizome_db_uuid, END) == -1)
if (sqlite_exec_void_retry(&retry, "INSERT INTO IDENTITY (uuid) VALUES (?);", SERVAL_UUID_T, &rhizome_db_uuid, END) == -1)
RETURN(WHY("Failed to insert UUID into Rhizome database"));
if (config.debug.rhizome)
DEBUGF("Set Rhizome database UUID to %s", alloca_uuid_str(rhizome_db_uuid));
@ -793,15 +793,15 @@ int _sqlite_vbind(struct __sourceloc __whence, int log_level, sqlite_retry_state
}
}
break;
case UUID_T: {
const uuid_t *uuidp = va_arg(ap, const uuid_t *);
case SERVAL_UUID_T: {
const serval_uuid_t *uuidp = va_arg(ap, const serval_uuid_t *);
++argnum;
if (uuidp == NULL) {
BIND_NULL(UUID_T);
BIND_NULL(SERVAL_UUID_T);
} else {
char uuid_str[UUID_STRLEN + 1];
uuid_to_str(uuidp, uuid_str);
BIND_DEBUG(UUID_T, sqlite3_bind_text, "%s,%u,SQLITE_TRANSIENT", uuid_str, UUID_STRLEN);
BIND_DEBUG(SERVAL_UUID_T, sqlite3_bind_text, "%s,%u,SQLITE_TRANSIENT", uuid_str, UUID_STRLEN);
BIND_RETRY(sqlite3_bind_text, uuid_str, UUID_STRLEN, SQLITE_TRANSIENT);
}
}

View File

@ -36,7 +36,7 @@ static void finalise_union_rhizome_insert(httpd_request *r)
rhizome_fail_write(&r->u.insert.write);
}
#define LIST_TOKEN_STRLEN (BASE64_ENCODED_LEN(sizeof(uuid_t) + 8))
#define LIST_TOKEN_STRLEN (BASE64_ENCODED_LEN(sizeof(serval_uuid_t) + 8))
#define alloca_list_token(rowid) list_token_to_str(alloca(LIST_TOKEN_STRLEN + 1), (rowid))
static char *list_token_to_str(char *buf, uint64_t rowid)
@ -57,7 +57,7 @@ static int strn_to_list_token(const char *str, uint64_t *rowidp, const char **af
unsigned char token[sizeof rhizome_db_uuid.u.binary + sizeof *rowidp];
if (base64url_decode(token, sizeof token, str, 0, afterp, 0, NULL) != sizeof token)
return 0;
if (cmp_uuid_t(&rhizome_db_uuid, (uuid_t *) &token) != 0)
if (cmp_uuid_t(&rhizome_db_uuid, (serval_uuid_t *) &token) != 0)
return 0;
memcpy(rowidp, token + sizeof rhizome_db_uuid.u.binary, sizeof *rowidp);
return 1;

12
uuid.c
View File

@ -27,7 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# include <arpa/inet.h>
#endif
enum uuid_version uuid_get_version(const uuid_t *uuid)
enum uuid_version uuid_get_version(const serval_uuid_t *uuid)
{
assert(uuid_is_valid(uuid));
switch (ntohs(uuid->u.record.time_hi_and_version) & 0xf000) {
@ -40,7 +40,7 @@ enum uuid_version uuid_get_version(const uuid_t *uuid)
return UUID_VERSION_UNSUPPORTED;
}
void uuid_set_version(uuid_t *uuid, enum uuid_version version)
void uuid_set_version(serval_uuid_t *uuid, enum uuid_version version)
{
uint16_t version_bits;
switch (version) {
@ -55,7 +55,7 @@ void uuid_set_version(uuid_t *uuid, enum uuid_version version)
uuid->u.record.time_hi_and_version = htons((ntohs(uuid->u.record.time_hi_and_version) & 0xfff) | version_bits);
}
int uuid_generate_random(uuid_t *uuid)
int uuid_generate_random(serval_uuid_t *uuid)
{
if (urandombytes(uuid->u.binary, sizeof uuid->u.binary) == -1)
return -1;
@ -66,7 +66,7 @@ int uuid_generate_random(uuid_t *uuid)
return 0;
}
strbuf strbuf_uuid(strbuf sb, const uuid_t *uuid)
strbuf strbuf_uuid(strbuf sb, const serval_uuid_t *uuid)
{
assert(uuid_is_valid(uuid));
unsigned i;
@ -82,7 +82,7 @@ strbuf strbuf_uuid(strbuf sb, const uuid_t *uuid)
return sb;
}
char *uuid_to_str(const uuid_t *uuid, char *const dst)
char *uuid_to_str(const serval_uuid_t *uuid, char *const dst)
{
strbuf b = strbuf_local(dst, UUID_STRLEN + 1);
strbuf_uuid(b, uuid);
@ -90,7 +90,7 @@ char *uuid_to_str(const uuid_t *uuid, char *const dst)
return dst;
}
int str_to_uuid(const char *const str, uuid_t *uuid, const char **afterp)
int str_to_uuid(const char *const str, serval_uuid_t *uuid, const char **afterp)
{
const char *end = str;
int ret = 0;

22
uuid.h
View File

@ -49,9 +49,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* so code wishing to make use of the record structure must use ntohl(3) and
* ntohs(3) to read values, and htonl(3) and htons(3) to assign values.
*
* OS-X already defines a "uuid_t" typedef, so we use a different symbol.
*
* @author Andrew Bettison <andrew@servalproject.com>
*/
typedef struct uuid {
typedef struct serval_uuid {
union {
struct {
uint32_t time_low;
@ -63,7 +65,7 @@ typedef struct uuid {
} record;
unsigned char binary[16];
} u;
} uuid_t;
} serval_uuid_t;
enum uuid_version {
UUID_VERSION_UNSUPPORTED = 0,
@ -74,20 +76,20 @@ enum uuid_version {
UUID_VERSION_NAME_SHA1 = 5
};
__SERVAL_DNA__UUID_H_INLINE int cmp_uuid_t(const uuid_t *a, const uuid_t *b) {
__SERVAL_DNA__UUID_H_INLINE int cmp_uuid_t(const serval_uuid_t *a, const serval_uuid_t *b) {
return memcmp(a->u.binary, b->u.binary, sizeof a->u.binary);
}
__SERVAL_DNA__UUID_H_INLINE int uuid_is_valid(const uuid_t *any_uuid) {
__SERVAL_DNA__UUID_H_INLINE int uuid_is_valid(const serval_uuid_t *any_uuid) {
return (any_uuid->u.record.clock_seq_hi_and_reserved & 0xc0) == 0x80;
}
enum uuid_version uuid_get_version(const uuid_t *valid_uuid);
void uuid_set_version(uuid_t *valid_uuid, enum uuid_version);
enum uuid_version uuid_get_version(const serval_uuid_t *valid_uuid);
void uuid_set_version(serval_uuid_t *valid_uuid, enum uuid_version);
/* Returns -1 if error (eg, cannot open /dev/urandom), 0 if successful.
*/
int uuid_generate_random(uuid_t *dest_uuid);
int uuid_generate_random(serval_uuid_t *dest_uuid);
/* Formats the given valid UUID in its canonical string representation:
* XXXXXXXX-VXXX-MXXX-XXXXXXXXXXXX
@ -104,13 +106,13 @@ int uuid_generate_random(uuid_t *dest_uuid);
*
* @author Andrew Bettison <andrew@servalproject.com>
*/
char *uuid_to_str(const uuid_t *valid_uuid, char *dst);
char *uuid_to_str(const serval_uuid_t *valid_uuid, char *dst);
#define UUID_STRLEN 36
#define alloca_uuid_str(uuid) uuid_to_str(&(uuid), alloca(UUID_STRLEN + 1))
/* Append a UUID to the given strbuf, formatted as per the uuid_to_str() function.
*/
strbuf strbuf_uuid(strbuf, const uuid_t *valid_uuid);
strbuf strbuf_uuid(strbuf, const serval_uuid_t *valid_uuid);
/* Parse a canonical UUID string (as generated by uuid_to_str()) into a valid
* UUID, which may or not be supported.
@ -123,6 +125,6 @@ strbuf strbuf_uuid(strbuf, const uuid_t *valid_uuid);
*
* @author Andrew Bettison <andrew@servalproject.com>
*/
int str_to_uuid(const char *str, uuid_t *result, const char **afterp);
int str_to_uuid(const char *str, serval_uuid_t *result, const char **afterp);
#endif //__SERVAL_DNA__OS_H