Example #1
0
static int generate35( lua_State *L, uuid_fmt_t fmt, int ver, const char *ns, 
                       const char *name )
{
    uuid_rc_t rc = 0;
    uuid_t *uid = NULL;
    uuid_t *uid_ns = NULL;
    
    // create context
    if( ( rc = uuid_create( &uid ) ) == UUID_RC_OK && 
        ( rc = uuid_create( &uid_ns ) ) == UUID_RC_OK && 
        ( rc = uuid_load( uid_ns, ns ) ) == UUID_RC_OK && 
        ( rc = uuid_make( uid, ver, uid_ns, name ) ) == UUID_RC_OK ){
        uuid_export2lua( &rc, L );
        uuid_destroy( uid );
        uuid_destroy( uid_ns );
    }
    else if( uid )
    {
        uuid_destroy( uid );
        if( uid_ns ){
            uuid_destroy( uid_ns );
        }
    }
    
    return ( rc == UUID_RC_OK ) ? 1 : luaL_error( L, "%s", uuid_error( rc ) );
}
Example #2
0
int
cmd_pfs_create(const char *sel_path, const char *name,
	       uint8_t pfs_type, const char *uuid_str)
{
	hammer2_ioc_pfs_t pfs;
	int ecode = 0;
	int fd;
	uint32_t status;

	/*
	 * Default to MASTER if no uuid was specified.
	 * Default to SLAVE if a uuid was specified.
	 *
	 * When adding masters to a cluster, the new PFS must be added as
	 * a slave and then upgraded to ensure proper synchronization.
	 */
	if (pfs_type == HAMMER2_PFSTYPE_NONE) {
		if (uuid_str)
			pfs_type = HAMMER2_PFSTYPE_SLAVE;
		else
			pfs_type = HAMMER2_PFSTYPE_MASTER;
	}

	if ((fd = hammer2_ioctl_handle(sel_path)) < 0)
		return(1);
	bzero(&pfs, sizeof(pfs));
	snprintf(pfs.name, sizeof(pfs.name), "%s", name);
	pfs.pfs_type = pfs_type;
	if (uuid_str) {
		uuid_from_string(uuid_str, &pfs.pfs_clid, &status);
	} else {
		uuid_create(&pfs.pfs_clid, &status);
	}
	if (status == uuid_s_ok)
		uuid_create(&pfs.pfs_fsid, &status);
	if (status == uuid_s_ok) {
		if (ioctl(fd, HAMMER2IOC_PFS_CREATE, &pfs) < 0) {
			if (errno == EEXIST) {
				fprintf(stderr,
					"NOTE: Typically the same name is "
					"used for cluster elements on "
					"different mounts,\n"
					"      but cluster elements on the "
					"same mount require unique names.\n"
					"pfs-create %s: already present\n",
					name);
			} else {
				perror("ioctl");
			}
			ecode = 1;
		}
	} else {
		fprintf(stderr, "hammer2: pfs_create: badly formed uuid\n");
		ecode = 1;
	}
	close(fd);
	return (ecode);
}
Example #3
0
static void
init_pfsd(hammer_pseudofs_data_t pfsd, int is_slave)
{
	uint32_t status;

	pfsd->sync_beg_tid = 1;
	pfsd->sync_end_tid = 1;
	pfsd->sync_beg_ts = 0;
	pfsd->sync_end_ts = 0;
	uuid_create(&pfsd->shared_uuid, &status);
	uuid_create(&pfsd->unique_uuid, &status);
	if (is_slave)
		pfsd->mirror_flags |= HAMMER_PFSD_SLAVE;
}
Example #4
0
static int
lua_fn_uuid_create(lua_State *L) {
  uuid_t uuid;
  uuid_create(&uuid);
  lua_pushx_uuid(L, &uuid);
  return 1;
}
Example #5
0
static char *
_soap_addressing_generate_id(void)
{
  uuid_t uuid;
  uint32_t status;
  char *ret, *buf;

  uuid_create(&uuid, &status);
  if (status != uuid_s_ok)
  {
    log_error("uuidcreate failed (%s)", _soap_addressing_uuid_error(status));
    return NULL;
  }

  uuid_to_string(&uuid, &buf, &status);
  if (status != uuid_s_ok)
  {
    log_error("uuid_to_string failed (%s)", _soap_addressing_uuid_error(status));
    return NULL;
  }

  if (!(ret = (char *)malloc(128)))
  {
    log_error("malloc failed (%s)", strerror(errno));
    free(buf);
    return NULL;
  }

  sprintf(ret, "%s/%s", soap_server_get_name(), buf);

  free(buf);

  return ret;
}
Example #6
0
static void _uuuid_create(struct uuuid_t** uuuid, int* status, int nil)
{
	struct uuuid_t* u;
	uint32_t st;

	u = uuuid_new();

	if (!u) {
		*status = UUUID_ERR;
		return;
	}

	if (nil)
		uuid_create_nil(&u->uuid, &st);
	else
		uuid_create(&u->uuid, &st);

	if (st != uuid_s_ok) {
		uuuid_free(u);
		*status = UUUID_ERR;
		return;
	}

	*uuuid = u;
	*status = UUUID_OK;
}
Example #7
0
/* Simple driver for UUID generator */
void main(int argc, char **argv)
{
    uuid_t u;
    int f;

    if(argc > 1) { 

      uuid_create_sha1_from_name(&u, NameSpace_WS, argv[1], strlen(argv[1]));
      printf("s/$(UUID)/"); puid(u); printf("/\n");

      exit(0);

    } else {

      uuid_create(&u);
      printf("uuid_create(): "); puid(u); printf("\n");

      f = uuid_compare(&u, &u);
      printf("uuid_compare(u,u): %d\n", f);     /* should be 0 */
      f = uuid_compare(&u, &NameSpace_DNS);
      printf("uuid_compare(u, NameSpace_DNS): %d\n", f); /* s.b. 1 */
      f = uuid_compare(&NameSpace_DNS, &u);
      printf("uuid_compare(NameSpace_DNS, u): %d\n", f); /* s.b. -1 */
      uuid_create_md5_from_name(&u, NameSpace_DNS, "www.widgets.com", 15);
      printf("uuid_create_md5_from_name(): "); puid(u); printf("\n");

    }
}
Example #8
0
void FFEADContext::addBean(Bean& bean)
{
	StringUtil::trim(bean.name);
	if(bean.name=="") {
#ifdef HAVE_LIBUUID
		uuid_t idt;
		uuid_generate(idt);
		std::string ids;
		for(int i=0;i<16;i++){
			ids.push_back(idt[i]);
		}
		bean.name = ids;
#elif HAVE_BSDUUIDINC
		uuid_t idt;
		uint32_t status;
		uuid_create(&idt, &status);
		std::string ids((const char *) &idt, sizeof(idt));
		bean.name = ids;

#else
		bean.name = CastUtil::lexical_cast<std::string>(Timer::getCurrentTime());
#endif
	}
	if(bean.name!="" && beans.find(bean.appName+bean.name)==beans.end())
		beans[bean.appName+bean.name] = bean;
}
Example #9
0
HRESULT
PALAPI
CoCreateGuid(OUT GUID * pguid)
{
#if HAVE_BSD_UUID_H
    uuid_t uuid;
    uint32_t status;
    uuid_create(&uuid, &status);
    if (status != uuid_s_ok)
    {
        ASSERT("Unexpected uuid_create failure (status=%u)\n", status);
        PROCAbort();
    }

    // Encode the uuid with little endian.
    uuid_enc_le(pguid, &uuid);
#elif HAVE_LIBUUID_H
    uuid_generate_random(*(uuid_t*)pguid);

    // Change the byte order of the Data1, 2 and 3, since the uuid_generate_random
    // generates them with big endian while GUIDS need to have them in little endian.
    pguid->Data1 = SWAP32(pguid->Data1);
    pguid->Data2 = SWAP16(pguid->Data2);
    pguid->Data3 = SWAP16(pguid->Data3);
#else
    #error Don't know how to generate UUID on this platform
#endif
    return 0;
}
Example #10
0
string getUid()
{
	string myguid;
	
	uuid_tt u;
	int emsg = uuid_create(&u);
	
	if( emsg != 1 )
	{
		cout << "ERROR GENERATING UID" << endl;
		return "0";
	}
	
	char suid[64];
	
	sprintf(suid, "%8.8x-%4.4x-%4.4x-%2.2x%2.2x-", u.time_low, u.time_mid,
			u.time_hi_and_version, u.clock_seq_hi_and_reserved,
			u.clock_seq_low);
	
	for (int i = 0; i < 6; i++)
		sprintf(suid+strlen(suid),"%2.2x", u.node[i]);
	
	sprintf(suid+strlen(suid),"\0");
	
	myguid = suid;
	cout << "generated uid : " << myguid << endl;
	
	return myguid;
}
Example #11
0
/* export UUID to string representation */
void uuid_dce_to_string(uuid_dce_t *uuid_dce, char **str, int *status)
{
    ossp_uuid_t *uuid = NULL;
    size_t len;
    void *vp;

    /* initialize status */
    if (status != NULL)
        *status = uuid_s_error;

    /* sanity check argument(s) */
    if (str == NULL || uuid_dce == NULL)
        return;

    /* import binary representation and export string representation */
    if (uuid_create(&uuid) != UUID_RC_OK)
        goto leave;
    if (uuid_import(uuid, UUID_FMT_BIN, uuid_dce, UUID_LEN_BIN) != UUID_RC_OK)
        goto leave;
    vp  = str;
    len = UUID_LEN_STR;
    if (uuid_export(uuid, UUID_FMT_STR, &vp, &len) != UUID_RC_OK)
        goto leave;

    /* indicate successful operation */
    if (status != NULL)
        *status = uuid_s_ok;

    /* cleanup and return */
    leave:
    if (uuid != NULL)
        uuid_destroy(uuid);
    return;
}
Example #12
0
/* create a UUID (v1 only) */
void uuid_dce_create(uuid_dce_t *uuid_dce, int *status)
{
    ossp_uuid_t *uuid;
    size_t len;
    void *vp;

    /* initialize status */
    if (status != NULL)
        *status = uuid_s_error;

    /* sanity check argument(s) */
    if (uuid_dce == NULL)
        return;

    /* create UUID and export as binary representation */
    if (uuid_create(&uuid) != UUID_RC_OK)
        return;
    if (uuid_make(uuid, UUID_MAKE_V1) != UUID_RC_OK) {
        uuid_destroy(uuid);
        return;
    }
    vp  = uuid_dce;
    len = UUID_LEN_BIN;
    if (uuid_export(uuid, UUID_FMT_BIN, &vp, &len) != UUID_RC_OK) {
        uuid_destroy(uuid);
        return;
    }
    uuid_destroy(uuid);

    /* return successfully */
    if (status != NULL)
        *status = uuid_s_ok;
    return;
}
Example #13
0
File: util.c Project: tonyg/hop
int gen_uuid(unsigned char *uuid_buf) {
  uuid_rc_t result;
  uuid_t *uuid;
  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);
  UUID_CHECK("uuid_create");

  result = uuid_make(uuid, UUID_MAKE_V4);
  UUID_CHECK("uuid_make");

  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);
  UUID_CHECK("uuid_destroy");

  return UUID_RC_OK;
}
Example #14
0
static String make_uuid( unsigned int mode )
{
    String result;

    uuid_t * u = 0;

    if ( UUID_RC_OK == uuid_create( & u ) )
    {
        if ( UUID_RC_OK == uuid_make( u , mode ) )
        {
            char buffer[ UUID_LEN_STR + 1 ];

            size_t len = UUID_LEN_STR + 1;

            void * up = & buffer[0];

            if ( UUID_RC_OK == uuid_export( u , UUID_FMT_STR , & up , & len ) )
            {
                result = buffer;
            }
        }

        uuid_destroy( u );
    }

    return result;
}
ngx_int_t ngx_x_rid_header_get_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data) {
  u_char            *p         = NULL;
  ngx_table_elt_t   *header;
  ngx_str_t          hv;
  size_t             hlen      = 22;

  header = search_headers_in(r, ngx_x_rid_header_name.data, ngx_x_rid_header_name.len);

  if (header != NULL) {
      hv = header->value;

      if (hv.len >= 20 && hv.len <= 50) {
          // Reuse existing header
          hlen = hv.len;
          p = hv.data;
      }
  }

  if (p == NULL) {
      // Prepare 22 bytes to store the base58 string
      p = ngx_pnalloc(r->pool, 22);
      if (p == NULL) {
          return NGX_ERROR;
      }

#if (NGX_FREEBSD)
#error FreeBSD is not supported yet, sorry.
#elif (NGX_LINUX)
      uuid_t* uuid;

      // return of uuid_s_ok = 0
      if ( uuid_create(&uuid) ) {
        return -1;
      }
      if ( uuid_make(uuid, UUID_MAKE_V4) ) {
        uuid_destroy(uuid);
        return -1;
      }

      // at this point we have 16 bytes in "uuid", ready for conversion
      uuid_fmt22(uuid, p);
      uuid_destroy(uuid);
#elif (NGX_SOLARIS)
#error Solaris is not supported yet, sorry.
#elif (NGX_DARWIN)
      uuid_t uuid;
      uuid_generate(uuid);
      uuid_fmt22(uuid, p);
#endif
  }

  v->len = hlen;
  v->valid = 1;
  v->no_cacheable = 0;
  v->not_found = 0;
  v->data = p;

  return NGX_OK;
}
Example #16
0
void libxl_uuid_generate(libxl_uuid *uuid)
{
    uint32_t status;

    BUILD_BUG_ON(sizeof(libxl_uuid) != sizeof(uuid_t));
    uuid_create(&uuid->uuid, &status);
    assert(status == uuid_s_ok);
}
Example #17
0
zmq::uuid_t::uuid_t ()
{
    uint32_t status;
    uuid_create (&uuid, &status);
    zmq_assert (status == uuid_s_ok);
    uuid_to_string (&uuid, &uuid_str, &status);
    zmq_assert (status == uuid_s_ok);
}
Example #18
0
int main(int argc, char *argv[])
{
    uuid_t u;
    CWT_UNUSED2(argc, argv);
    uuid_create(&u);
    print_uuid(u);
    return 0;
}
Example #19
0
char* pn_i_genuuid(void) {
    char *generated;
    uuid_t uuid;
    uint32_t rc;
    uuid_create(&uuid, &rc);
    // Under FreeBSD the returned string is newly allocated from the heap
    uuid_to_string(&uuid, &generated, &rc);
    return generated;
}
Example #20
0
File: DBoid.c Project: high/PRiDe
dboid_t dboidCreate( char *name )
{
	uuid_t 	*uuid;
	uuid_t 	*uuid_ns;
	char 	*str;
	
	uuid_create( &uuid );
	uuid_create( &uuid_ns );
	
	uuid_load( uuid_ns, "ns:OID" );
	uuid_make( uuid, UUID_MAKE_V3, uuid_ns, name );
	
	str = NULL;
	
	uuid_export( uuid, UUID_FMT_STR, &str, NULL );
	uuid_destroy( uuid_ns );
	uuid_destroy( uuid );
	
	return str;
	
}
Example #21
0
File: guul.c Project: ovtn/gupnp
char *
guul_get_uuid()
{
        uuid_t uuid;
        uint32_t status;
        char *result = NULL;

        uuid_create (&uuid, &status);
        uuid_to_string (&uuid, &result, &status);

        return result;
}
Example #22
0
ib_status_t ib_uuid_initialize(void)
{
    ib_status_t rc;

    if (uuid_create(&g_ossp_uuid) != UUID_RC_OK) {
        return IB_EOTHER;
    }

    rc = ib_lock_init(&g_uuid_lock);

    return rc;
}
int
cmd_pfs_create(const char *sel_path, const char *name,
	       uint8_t pfs_type, const char *uuid_str)
{
	hammer2_ioc_pfs_t pfs;
	int ecode = 0;
	int fd;
	uint32_t status;

	/*
	 * Default to MASTER
	 */
	if (pfs_type == DMSG_PFSTYPE_NONE) {
		pfs_type = HAMMER2_PFSTYPE_MASTER;
	}

	if ((fd = hammer2_ioctl_handle(sel_path)) < 0)
		return(1);
	bzero(&pfs, sizeof(pfs));
	snprintf(pfs.name, sizeof(pfs.name), "%s", name);
	pfs.pfs_type = pfs_type;
	if (uuid_str) {
		uuid_from_string(uuid_str, &pfs.pfs_clid, &status);
	} else {
		uuid_create(&pfs.pfs_clid, &status);
	}
	if (status == uuid_s_ok)
		uuid_create(&pfs.pfs_fsid, &status);
	if (status == uuid_s_ok) {
		if (ioctl(fd, HAMMER2IOC_PFS_CREATE, &pfs) < 0) {
			perror("ioctl");
			ecode = 1;
		}
	} else {
		fprintf(stderr, "hammer2: pfs_create: badly formed uuid\n");
		ecode = 1;
	}
	close(fd);
	return (ecode);
}
Example #24
0
/* Simple driver for UUID generator */
void main(int argc, char **argv) {
	uuid_t u;
	int f;
	char *page = "XU";

	int i;
	for(i = 0; i < 10; i ++) {
		uuid_create(&u);
		char *p = puid2(u); //pmasterkong_code(page, u);
		printf("MasterKong: %7d -> %s\n", i, p);
		free(p);
	}
}
Example #25
0
const std::string uuid ()
{
  uuid_t id;
  uint32_t status;
  char *buffer (0);
  uuid_create (&id, &status);
  uuid_to_string (&id, &buffer, &status);

  std::string res (buffer);
  free (buffer);

  return res;
}
Example #26
0
char 
*uuid_v1(void) {
    uuid_t *uuid;
    char *str;

    uuid_create(&uuid);
    uuid_make(uuid, UUID_MAKE_V1);
    str = NULL;
    uuid_export(uuid, UUID_FMT_STR, &str, NULL);
    uuid_destroy(uuid);
    //debug("uuid: %s", str);
    return(str);
}
Example #27
0
static uint8_t att_read_group_req(struct bt_att *att, struct net_buf *buf)
{
	struct bt_conn *conn = att->chan.conn;
	struct bt_att_read_group_req *req;
	uint16_t start_handle, end_handle, err_handle;
	union {
		struct bt_uuid uuid;
		struct bt_uuid_16 u16;
		struct bt_uuid_128 u128;
	} u;

	/* Type can only be UUID16 or UUID128 */
	if (buf->len != sizeof(*req) + 2 && buf->len != sizeof(*req) + 16) {
		return BT_ATT_ERR_INVALID_PDU;
	}

	req = (void *)buf->data;

	start_handle = sys_le16_to_cpu(req->start_handle);
	end_handle = sys_le16_to_cpu(req->end_handle);
	net_buf_pull(buf, sizeof(*req));

	if (!uuid_create(&u.uuid, buf)) {
		return BT_ATT_ERR_UNLIKELY;
	}

	BT_DBG("start_handle 0x%04x end_handle 0x%04x type %s",
	       start_handle, end_handle, bt_uuid_str(&u.uuid));

	if (!range_is_valid(start_handle, end_handle, &err_handle)) {
		send_err_rsp(conn, BT_ATT_OP_READ_GROUP_REQ, err_handle,
			     BT_ATT_ERR_INVALID_HANDLE);
		return 0;
	}

	/* Core v4.2, Vol 3, sec 2.5.3 Attribute Grouping:
	 * Not all of the grouping attributes can be used in the ATT
	 * Read By Group Type Request. The «Primary Service» and «Secondary
	 * Service» grouping types may be used in the Read By Group Type
	 * Request. The «Characteristic» grouping type shall not be used in
	 * the ATT Read By Group Type Request.
	 */
	if (bt_uuid_cmp(&u.uuid, BT_UUID_GATT_PRIMARY) &&
	    bt_uuid_cmp(&u.uuid, BT_UUID_GATT_SECONDARY)) {
		send_err_rsp(conn, BT_ATT_OP_READ_GROUP_REQ, start_handle,
				     BT_ATT_ERR_UNSUPPORTED_GROUP_TYPE);
		return 0;
	}

	return att_read_group_rsp(att, &u.uuid, start_handle, end_handle);
}
Example #28
0
char* guac_generate_id(char prefix) {

    char* buffer;
    char* identifier;
    size_t identifier_length;

    uuid_t* uuid;

    /* Attempt to create UUID object */
    if (uuid_create(&uuid) != UUID_RC_OK) {
        guac_error = GUAC_STATUS_NO_MEMORY;
        guac_error_message = "Could not allocate memory for UUID";
        return NULL;
    }

    /* Generate random UUID */
    if (uuid_make(uuid, UUID_MAKE_V4) != UUID_RC_OK) {
        uuid_destroy(uuid);
        guac_error = GUAC_STATUS_NO_MEMORY;
        guac_error_message = "UUID generation failed";
        return NULL;
    }

    /* Allocate buffer for future formatted ID */
    buffer = malloc(UUID_LEN_STR + 2);
    if (buffer == NULL) {
        uuid_destroy(uuid);
        guac_error = GUAC_STATUS_NO_MEMORY;
        guac_error_message = "Could not allocate memory for connection ID";
        return NULL;
    }

    identifier = &(buffer[1]);
    identifier_length = UUID_LEN_STR + 1;

    /* Build connection ID from UUID */
    if (uuid_export(uuid, UUID_FMT_STR, &identifier, &identifier_length) != UUID_RC_OK) {
        free(buffer);
        uuid_destroy(uuid);
        guac_error = GUAC_STATUS_INTERNAL_ERROR;
        guac_error_message = "Conversion of UUID to connection ID failed";
        return NULL;
    }

    uuid_destroy(uuid);

    buffer[0] = prefix;
    buffer[UUID_LEN_STR + 1] = '\0';
    return buffer;

}
Example #29
0
/* compare two UUIDs */
int uuid_dce_compare(uuid_dce_t *uuid_dce1, uuid_dce_t *uuid_dce2, int *status)
{
    ossp_uuid_t *uuid1 = NULL;
    ossp_uuid_t *uuid2 = NULL;
    int result = 0;

    /* initialize status */
    if (status != NULL)
        *status = uuid_s_error;

    /* sanity check argument(s) */
    if (uuid_dce1 == NULL || uuid_dce2 == NULL)
        return 0;

    /* import both UUID binary representations and compare them */
    if (uuid_create(&uuid1) != UUID_RC_OK)
        goto leave;
    if (uuid_create(&uuid2) != UUID_RC_OK)
        goto leave;
    if (uuid_import(uuid1, UUID_FMT_BIN, uuid_dce1, UUID_LEN_BIN) != UUID_RC_OK)
        goto leave;
    if (uuid_import(uuid2, UUID_FMT_BIN, uuid_dce2, UUID_LEN_BIN) != UUID_RC_OK)
        goto leave;
    if (uuid_compare(uuid1, uuid2, &result) != UUID_RC_OK)
        goto leave;

    /* indicate successful operation */
    if (status != NULL)
        *status = uuid_s_ok;

    /* cleanup and return */
    leave:
    if (uuid1 != NULL)
        uuid_destroy(uuid1);
    if (uuid2 != NULL)
        uuid_destroy(uuid2);
    return result;
}
Example #30
0
int
main(int argc, char **argv)
{
    char str[1000];
    afsUUID u1, u2;

    uuid_create(&u1);

    uuid_to_string(&u1, str, sizeof(str));

    printf("u: %s\n", str);

    return 0;
}