Switch to hex representation of UUIDs for now

This commit is contained in:
Tony Garnock-Jones 2011-01-02 11:46:59 -05:00
parent e7fa9b1642
commit 0a0b458057
3 changed files with 22 additions and 12 deletions

View File

@ -19,7 +19,8 @@ static inline cmsg_bytes_t cmsg_cstring_bytes(char const *cstr) {
return result;
}
extern int gen_uuid(unsigned char *uuid_buf); /* must be 16 bytes long */
#define CMSG_UUID_BUF_SIZE 36
extern int gen_uuid(unsigned char *uuid_buf); /* must be exactly CMSG_UUID_BUF_SIZE bytes long */
extern cmsg_bytes_t cmsg_bytes_malloc_dup(cmsg_bytes_t src);
extern cmsg_bytes_t cmsg_bytes_malloc(size_t amount);

View File

@ -11,9 +11,6 @@
#include <ucontext.h>
/* OSSP UUID */
#include <uuid.h>
#include "cmsg_private.h"
#include "harness.h"
#include "ref.h"
@ -141,7 +138,7 @@ static void queue_handle_message(node_t *n, sexp_t *m) {
sexp_enqueue(q->backlog_q, sexp_listref(args, 1));
throck_shovel(q);
} else if ((msglen == 6) && !cmsg_bytes_cmp(selector, cmsg_cstring_bytes("subscribe"))) {
unsigned char uuid[UUID_LEN_BIN];
unsigned char uuid[CMSG_UUID_BUF_SIZE];
if (gen_uuid(uuid) != 0) {
warn("Could not generate UUID\n");
} else {

26
util.c
View File

@ -12,23 +12,35 @@
#include "cmsg_private.h"
#define UUID_CHECK(context) \
if (result != UUID_RC_OK) { \
warn("gen_uuid failed with %d at %s\n", result, context); \
return result; \
}
int gen_uuid(unsigned char *uuid_buf) {
uuid_rc_t result;
uuid_t *uuid;
size_t uuid_buf_len = UUID_LEN_BIN;
unsigned char temp_buf[UUID_LEN_STR + 1];
unsigned char *temp_buf_ptr = &temp_buf[0]; /* odd API */
size_t uuid_buf_len = UUID_LEN_STR + 1;
assert(CMSG_UUID_BUF_SIZE == UUID_LEN_STR);
result = uuid_create(&uuid);
if (result != UUID_RC_OK) return result;
UUID_CHECK("uuid_create");
result = uuid_make(uuid, UUID_MAKE_V4);
if (result != UUID_RC_OK) return result;
UUID_CHECK("uuid_make");
result = uuid_export(uuid, UUID_FMT_BIN, &uuid_buf, &uuid_buf_len);
if (result != UUID_RC_OK) return result;
assert(uuid_buf_len == UUID_LEN_BIN);
result = uuid_export(uuid, UUID_FMT_STR, &temp_buf_ptr, &uuid_buf_len);
UUID_CHECK("uuid_export");
assert(uuid_buf_len == (UUID_LEN_STR + 1));
memcpy(uuid_buf, temp_buf, CMSG_UUID_BUF_SIZE);
result = uuid_destroy(uuid);
if (result != UUID_RC_OK) return result;
UUID_CHECK("uuid_destroy");
return UUID_RC_OK;
}