Exemplo n.º 1
1
char* pn_i_genuuid(void) {
    char *generated = (char *) malloc(37*sizeof(char));
    uuid_t uuid;
    uuid_generate(uuid);
    uuid_unparse(uuid, generated);
    return generated;
}
Exemplo n.º 2
0
  void init(size_t arg, size_t padding)
  {
    _lengths.resize(arg);
    _keys.resize(arg);

    for (size_t x= 0; x < _keys.size(); x++)
    {
      libtest::vchar_t key_buffer;
      key_buffer.resize(padding +1);
      memset(&key_buffer[0], 'x', padding);

#if defined(HAVE_UUID_UUID_H) && HAVE_UUID_UUID_H
      if (HAVE_UUID_UUID_H)
      {
        uuid_t out;
        uuid_generate(out);

        uuid_unparse(out, &key_buffer[0]);
        _keys[x]= strdup(&key_buffer[0]);
        (_keys[x])[UUID_STRING_MAXLENGTH]= 'x';
      }
      else // We just use a number and pad the string if UUID is not available
#endif
      {
        char int_buffer[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH +1];
        int key_length= snprintf(int_buffer, sizeof(int_buffer), "%u", uint32_t(x));
        memcpy(&key_buffer[0], int_buffer, key_length);
        _keys[x]= strdup(&key_buffer[0]);
      }
      _lengths[x]= padding;
    }
  }
Exemplo n.º 3
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;
}
Exemplo n.º 4
0
client_t * init_new_client(agent_t *agent, uuid_t * uuid) 
{
	client_t *new_client; 	
	new_client = calloc(sizeof(client_t),1); 
   if(new_client == NULL) 
   { 
      printf("Malloc failed!\n"); 
      exit(1); 
   } 
   new_client->buffered_packet_table = NULL; 
   new_client->allowed_connections = 0; 
	new_client->agent_sock = calloc(sizeof(int) , agent->options.num_parallel_connections); 
	new_client->agent_side_event_info = calloc(sizeof(struct event_info_struct) ,agent->options.num_parallel_connections); 
   new_client->send_seq = 0; 
   new_client->recv_seq = 0; 


   new_client->agent_fd_poll = calloc(sizeof(char) , agent->options.num_parallel_connections); 
   new_client->num_parallel_connections = 0; 


   new_client->client_hash.client =  new_client; 
   gettimeofday(&new_client->client_hash.accept_start, NULL);
   if(uuid == NULL)
   {
      uuid_generate(new_client->client_hash.id);  
   } 
   else 
   {
      memcpy(new_client->client_hash.id, *uuid, sizeof(uuid_t)); 
   } 
      HASH_ADD_INT(agent->clients_hashes, id, (&new_client->client_hash)); 

	return new_client; 
}
Exemplo n.º 5
0
int jalls_create_record(enum jaldb_rec_type rec_type, struct jalls_thread_context *thread_ctx, struct jaldb_record **prec)
{
	if (!thread_ctx || !thread_ctx->ctx || !prec || *prec) {
		return -1;
	}

	char *timestamp = jaldb_gen_timestamp();
	if (!timestamp) {
		return -1;
	}

	struct jaldb_record *rec = jaldb_create_record();

	rec->type = rec_type;
	rec->pid = thread_ctx->peer_pid;
	rec->have_uid = 1;
	rec->uid = thread_ctx->peer_uid;
	rec->hostname = jal_strdup(thread_ctx->ctx->hostname);
	rec->timestamp = timestamp;
	rec->username = jalls_get_user_id_str(thread_ctx->peer_uid);
	rec->sec_lbl = jalls_get_security_label(thread_ctx->fd);
	uuid_copy(rec->host_uuid, thread_ctx->ctx->system_uuid);
	uuid_generate(rec->uuid);
	if (rec->username == NULL) {
		return -1;	
	}

	*prec = rec;
	return 0;
}
Exemplo n.º 6
0
static
void psivshmem_init_device_handle(ivshmem_pci_dev_t *dev){
/*
 * This function initiates all required parameters to handle the shared memory access.
 * The first byte of the shared memory is used as a simple mutex to let the verry first
 * process initialize a pthread spinlock which is inter-vm thread safe.
 */
    dev->first_byte = (volatile unsigned char*) dev->ivshmem_base;
    dev->spinlock = (volatile pthread_spinlock_t*)(dev->ivshmem_base + sizeof(char));
    dev->uuid = (volatile uuid_t*)(dev->ivshmem_base + sizeof(char) + sizeof(pthread_spinlock_t));
    dev->bitmap = dev->ivshmem_base + sizeof(char) + sizeof(pthread_spinlock_t) + sizeof(uuid_t);
    dev->frame_size = IVSHMEM_FRAME_SIZE;
    dev->num_of_frames = dev->mem_size_byte / IVSHMEM_FRAME_SIZE;
    dev->bitmap_length = dev->num_of_frames / (sizeof(char)*CHAR_BIT);
    dev->meta_data_size = (dev->bitmap - dev->ivshmem_base) + dev->bitmap_length * sizeof (char);
    unsigned long long n;

    // Assumption: unused device contains only zeros
    if (uuid_is_null(*((uuid_t*)dev->uuid)) && psivshmem_atomic_TestAndSet(dev->first_byte)){
    	pthread_spin_init(dev->spinlock, PTHREAD_PROCESS_SHARED);
        uuid_generate(*((uuid_t*)dev->uuid));
	for(n =0; n< dev->bitmap_length; n++) SET_BIT(dev->bitmap,n); //mark all used frames in bitmap
	*(dev->first_byte) = IVSHMEM_DEVICE_MAGIC; //indicate PCI device to be used by ivshmem plugin
    } else {
    /* active waiting until other process has initialized the shared meta data
     * otherwise a device collision will be detected psivshmem_init_uio_device()
     */
    psivshmem_init_wait(dev);
    }

    uuid_unparse_lower(*(uuid_t*)dev->uuid, dev->uuid_str);
    DPRINT(3,"ivshmem: my uuid: %s",dev->uuid_str);
}
Exemplo n.º 7
0
char* createGUID(char* uid){
	
#ifdef WIN32
	char buffer[GUID_LEN] = { 0 };
    GUID guid;
    if(CoCreateGuid(&guid))
    {
    	//printf(stderr, "create guid error\n");
    	return NULL;
    }
    _snprintf(buffer, sizeof(buffer),
    "%08X%04X%04x%02X%02X%02X%02X%02X%02X%02X%02X",
    guid.Data1, guid.Data2, guid.Data3,
    guid.Data4[0], guid.Data4[1], guid.Data4[2],
    guid.Data4[3], guid.Data4[4], guid.Data4[5],
    guid.Data4[6], guid.Data4[7]);
#endif
#ifndef CLIENTMAKE
	if(uid == NULL) return NULL;
	bzero(uid,32);
	uuid_t uu;
    uuid_generate(uu);
    //printf("{");
	int i = 0;
    for(i=0;i<15;i++)
        sprintf(uid,"%s%02X",uid,uu[i]);
	return uid;
	//TODO
    //printf("%02X}\n",uu[15]);
#endif	

}
Exemplo n.º 8
0
/**
 * Shallow wrapper around uuid, that comes up with some random pseudo
 * uuid if uuid is not available
 */
char *
generateUUID(void)
{
#ifdef HAVE_UUID
# ifdef UUID_PRINTABLE_STRING_LENGTH
	/* Solaris */
	char out[UUID_PRINTABLE_STRING_LENGTH];
# else
	char out[37];
# endif
	uuid_t uuid;
	uuid_generate(uuid);
	uuid_unparse(uuid, out);
#else
	/* try to do some pseudo interesting stuff, and stash it in the
	 * format of an UUID to at least return some uniform answer */
	char out[37];
	char *p = out;

	/* generate something like this:
	 * cefa7a9c-1dd2-11b2-8350-880020adbeef ("%08x-%04x-%04x-%04x-%012x") */
	p += snprintf(p, 5, "%04x", rand() % 65536);
	p += snprintf(p, 6, "%04x-", rand() % 65536);
	p += snprintf(p, 6, "%04x-", rand() % 65536);
	p += snprintf(p, 6, "%04x-", rand() % 65536);
	p += snprintf(p, 6, "%04x-", rand() % 65536);
	p += snprintf(p, 5, "%04x", rand() % 65536);
	p += snprintf(p, 5, "%04x", rand() % 65536);
	p += snprintf(p, 5, "%04x", rand() % 65536);
#endif
	return(strdup(out));
}
Exemplo n.º 9
0
void gen_uuid_inplace (char *buf)
{
    uuid_t uuid;

    uuid_generate (uuid);
    uuid_unparse_lower (uuid, buf);
}
Exemplo n.º 10
0
REGISTRY_PERSON *registry_person_allocate(const char *person_guid, time_t when) {
    debug(D_REGISTRY, "Registry: registry_person_allocate('%s'): allocating new person, sizeof(PERSON)=%zu", (person_guid)?person_guid:"", sizeof(REGISTRY_PERSON));

    REGISTRY_PERSON *p = mallocz(sizeof(REGISTRY_PERSON));
    if(!person_guid) {
        for(;;) {
            uuid_t uuid;
            uuid_generate(uuid);
            uuid_unparse_lower(uuid, p->guid);

            debug(D_REGISTRY, "Registry: Checking if the generated person guid '%s' is unique", p->guid);
            if (!dictionary_get(registry.persons, p->guid)) {
                debug(D_REGISTRY, "Registry: generated person guid '%s' is unique", p->guid);
                break;
            }
            else
                info("Registry: generated person guid '%s' found in the registry. Retrying...", p->guid);
        }
    }
    else
        strncpyz(p->guid, person_guid, GUID_LEN);

    debug(D_REGISTRY, "Registry: registry_person_allocate('%s'): creating dictionary of urls", p->guid);
    avl_init(&p->person_urls, person_url_compare);

    p->first_t = p->last_t = (uint32_t)when;
    p->usages = 0;

    registry.persons_memory += sizeof(REGISTRY_PERSON);

    registry.persons_count++;
    dictionary_set(registry.persons, p->guid, p, sizeof(REGISTRY_PERSON));

    return p;
}
Exemplo n.º 11
0
int main(int argc, char **argv)
{
    Octstr *os;
    char id[UUID_STR_LEN + 1];
    uuid_t uid;

    gwlib_init();

    debug("uuid",0,"Creating UUID");
    uuid_generate(uid);
    debug("uuid",0,"Parse into char");
    uuid_unparse(uid, id);
    debug("uuid",0,"Create Octstr");
    os = octstr_create(id);
    debug("uuid",0,"UUID is: %s", octstr_get_cstr(os));
    debug("uuid",0,"Removing dashes");
    octstr_replace(os, octstr_imm("-"), octstr_imm(""));
    debug("uuid",0,"UUID is: %s", octstr_get_cstr(os));

    octstr_destroy(os);
    uuid_clear(uid);

    gwlib_shutdown();
    return 0;
}
Exemplo n.º 12
0
DWORD
LADSGetGUID(
    PSTR* ppszGUID
    )
{
    DWORD dwError = 0;
    PSTR  pszGUID = NULL;
    uuid_t uuid = {0};
    CHAR  szUUID[37] = "";

    uuid_generate(uuid);

    uuid_unparse(uuid, szUUID);

    dwError = LwAllocateString(
                       szUUID,
                       &pszGUID);
    BAIL_ON_LSA_ERROR(dwError);

    *ppszGUID = pszGUID;

cleanup:

    return dwError;

error:

    *ppszGUID = NULL;

    LW_SAFE_FREE_STRING(pszGUID);

    goto cleanup;
}
Exemplo n.º 13
0
	//
	// UUID
	std::string	GenRandUUID(void)
	{
		unsigned char uuid[16];
		char retstr[64] = { 0 };

#if defined _PLATFORM_WINDOWS_
		GUID guid;
		::CoCreateGuid(&guid);
		memcpy(uuid, &guid, sizeof(uuid));

		_snprintf_s(retstr, sizeof(retstr) - 1
			, "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X"
			, uuid[0], uuid[1], uuid[2], uuid[3]
			, uuid[4], uuid[5], uuid[6], uuid[7]
			, uuid[8], uuid[9], uuid[10], uuid[11]
			, uuid[12], uuid[13], uuid[14], uuid[15]
			);
#elif defined _PLATFORM_LINUX_
		uuid_t guid;
		uuid_generate(guid);
		memcpy(uuid, &guid, sizeof(uuid));

		snprintf(retstr, sizeof(retstr)-1
			, "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X"
			, uuid[0], uuid[1], uuid[2], uuid[3]
			, uuid[4], uuid[5], uuid[6], uuid[7]
			, uuid[8], uuid[9], uuid[10], uuid[11]
			, uuid[12], uuid[13], uuid[14], uuid[15]
			);
#endif
		return retstr;
	}
Exemplo n.º 14
0
int MakeUUID(char *location)
{
    uuid_t uuid;
    uuid_generate(uuid);
    memcpy((void *)location, (void *)&uuid, sizeof(uuid));
    return 1;
}
Exemplo n.º 15
0
static void
Object_init(sim_class_t *cls, void *obj, void *arg)
{
  sim_object_t *sobj = obj;
  uuid_generate(sobj->uuid);
  avl_insert(objects, sobj->uuid, sobj);
}
Exemplo n.º 16
0
static int uuid_init(const char *file)
{
	char uuid[37];
	uuid_t uu;
	FILE *f = NULL;
	int err = 0;

	f = fopen(file, "r");
	if (f) {
		err = 0;
		goto out;
	}

	f = fopen(file, "w");
	if (!f) {
		err = errno;
		DEBUG_WARNING("init: fopen() %s (%m)\n", file, err);
		goto out;
	}

	uuid_generate(uu);

	uuid_unparse(uu, uuid);

	re_fprintf(f, "%s", uuid);

	DEBUG_NOTICE("init: generated new UUID (%s)\n", uuid);

 out:
	if (f)
		fclose(f);

	return err;
}
Exemplo n.º 17
0
int
noit_poller_schedule(const char *target,
                     const char *module,
                     const char *name,
                     const char *filterset,
                     noit_hash_table *config,
                     u_int32_t period,
                     u_int32_t timeout,
                     const char *oncheck,
                     int flags,
                     uuid_t in,
                     uuid_t out) {
  noit_check_t *new_check;
  new_check = calloc(1, sizeof(*new_check));
  if(!new_check) return -1;

  /* The module and the UUID can never be changed */
  new_check->module = strdup(module);
  if(uuid_is_null(in))
    uuid_generate(new_check->checkid);
  else
    uuid_copy(new_check->checkid, in);

  noit_check_update(new_check, target, name, filterset, config,
                    period, timeout, oncheck, flags);
  assert(noit_hash_store(&polls,
                         (char *)new_check->checkid, UUID_SIZE,
                         new_check));
  uuid_copy(out, new_check->checkid);

  return 0;
}
Exemplo n.º 18
0
zmq::uuid_t::uuid_t ()
{
    uuid_generate (uuid);
    uuid_unparse (uuid, string_buf);

    create_blob ();
}
Exemplo n.º 19
0
Boolean XLinuxUUID::Generate (VUUIDBuffer* outUUID)
{
	xbox_assert(sizeof(outUUID->fBytes)==sizeof(uuid_t));
	//doesn't fail.
	uuid_generate(outUUID->fBytes);
	return true;
}
Exemplo n.º 20
0
string BeatBoard::SessionManager::createSessionId() {
    uuid_t uuid;
    char buff[1024];
    uuid_generate(uuid);
    uuid_unparse_upper(uuid, buff);
    return string(buff);
}
Exemplo n.º 21
0
struct sg_uuid_str sg_uuid_gen(enum sg_uuid_method method, int uppercase)
{
    uuid_t uu;
    struct sg_uuid_str us;

    assert(method >= SGUUIDMETHOD_DEFAULT && method <= SGUUIDMETHOD_TIME_MAC);

    memset(&us, 0, sizeof(struct sg_uuid_str));

    switch (method) {
    case SGUUIDMETHOD_DEFAULT:
        uuid_generate(uu);
        break;
    case SGUUIDMETHOD_RANDOM:
        uuid_generate_random(uu);
        break;
    case SGUUIDMETHOD_TIME_MAC:
        uuid_generate_time(uu);
        break;
    case SGUUIDMETHOD_TIME_MAC_SAFE:
        uuid_generate_time_safe(uu);
        break;
    default:
        sg_log_err("UUID method error.");
        return us;
    }

    if (uppercase == 0)
        uuid_unparse_lower(uu, us.buf);
    else
        uuid_unparse_upper(uu, us.buf);

    return us;
}
Exemplo n.º 22
0
static int
cont_create(test_arg_t *arg, uuid_t uuid)
{
	uuid_generate(uuid);
	print_message("creating container "DF_UUIDF"\n", DP_UUID(uuid));
	return daos_cont_create(arg->pool.poh, uuid, NULL, NULL);
}
Exemplo n.º 23
0
static void
smd_ut_add_and_fetch_ptab(void **state)
{
	int				rc;
	uuid_t				pool_uuid;
	int				stream;
	uint64_t			blob_id = 32;
	struct smd_nvme_pool_info	info;

	uuid_generate(pool_uuid);
	stream = 4;

	smd_nvme_set_pool_info(pool_uuid, stream, blob_id, &info);
	rc = smd_nvme_add_pool(&info);
	assert_int_equal(rc, 0);
	memset(&info, '0', sizeof(info));

	rc = smd_nvme_get_pool(pool_uuid, stream, &info);
	if (rc) {
		print_error("NVME get pool failed :%d\n", rc);
		assert_int_equal(rc, 0);
	}

	rc = uuid_compare(pool_uuid, info.npi_pool_uuid);
	assert_int_equal(rc, 0);
	assert_true(info.npi_stream_id == stream);
	assert_true(info.npi_blob_id == blob_id);
}
Exemplo n.º 24
0
// Create a new session
// FIXME - This is currently open to a DoS attack.
//         but since we have a session limit, just for opendias.
char *create_session() {
  char *session_id;

  // Check upper session count limit
  int current_session_count = sll_count( sll_findFirstElement( sessions ) );
  o_log( DEBUGM, "There are currently %d active sessions", current_session_count);
  if( current_session_count > MAX_SESSIONS ) {
    return NULL;
  }

  // Generate session key
  uuid_t uu;
  char *sid = malloc(36+1);
  uuid_generate(uu);
  uuid_unparse(uu, sid);
  session_id = o_strdup(sid);
  free(sid);
  o_log(DEBUGM, "Generated new session: %s", session_id );

  // Create new session structure
  struct session_data *session_element = malloc( sizeof(struct session_data) );
  session_element->last_accessed = time(NULL);
  session_element->session_container = sll_init();

  // Save and return
  sll_insert( sessions, o_strdup(session_id), session_element );
  return session_id;
}
Exemplo n.º 25
0
static int
init_device(struct sbd_context *st)
{
	struct sector_header_s	*s_header;
	struct sector_node_s	*s_node;
	struct sector_mbox_s	*s_mbox;
	struct stat 		s;
	char			uuid[37];
	int			i;
	int			rc = 0;

	s_header = sector_alloc();
	s_node = sector_alloc();
	s_mbox = sector_alloc();
	memcpy(s_header->magic, sbd_magic, sizeof(s_header->magic));
	s_header->version = sbd_version;
	s_header->slots = 255;
	s_header->sector_size = sector_size;
	s_header->timeout_watchdog = timeout_watchdog;
	s_header->timeout_allocate = timeout_allocate;
	s_header->timeout_loop = timeout_loop;
	s_header->timeout_msgwait = timeout_msgwait;

	s_header->minor_version = 1;
	uuid_generate(s_header->uuid);
	uuid_unparse_lower(s_header->uuid, uuid);

	fstat(st->devfd, &s);
	/* printf("st_size = %ld, st_blksize = %ld, st_blocks = %ld\n",
			s.st_size, s.st_blksize, s.st_blocks); */

	cl_log(LOG_INFO, "Creating version %d.%d header on device %d (uuid: %s)",
			s_header->version, s_header->minor_version,
			st->devfd, uuid);
	fprintf(stdout, "Creating version %d.%d header on device %d (uuid: %s)\n",
			s_header->version, s_header->minor_version,
			st->devfd, uuid);
	if (header_write(st, s_header) < 0) {
		rc = -1; goto out;
	}
	cl_log(LOG_INFO, "Initializing %d slots on device %d",
			s_header->slots,
			st->devfd);
	fprintf(stdout, "Initializing %d slots on device %d\n",
			s_header->slots,
			st->devfd);
	for (i=0;i < s_header->slots;i++) {
		if (slot_write(st, i, s_node) < 0) {
			rc = -1; goto out;
		}
		if (mbox_write(st, i, s_mbox) < 0) {
			rc = -1; goto out;
		}
	}

out:	free(s_node);
	free(s_header);
	free(s_mbox);
	return(rc);
}
Exemplo n.º 26
0
int main(int argc, char *argv[]) {
  FILE *secret, *pub, *out;
  int len = 0;
  uuid_t uuid;

  if( argc != 4 ) {
    printf( "Usage: catkeys <secret key file> <pubkey file> <outputfile>\n" );
  }
  secret = fopen(argv[1], "rb");
  if( secret == NULL ) {
    printf( "Can't open secret key file %s, failing.\n", argv[1] );
    exit(0);
  }
  pub = fopen( argv[2], "r" );
  if( pub == NULL ) {
    printf( "Can't open public key file %s, failing.\n", argv[2] );
    exit(0);
  }
  out = fopen( argv[3], "wb" );
  if( out == NULL ) {
    printf( "Can't open binary output file %s, failing.\n", argv[3] );
    exit(0);
  }

  len = 0;
  while( !feof(secret) ){
    len ++;
    fputc(fgetc(secret), out);
  }
  if( len >= SECLEN ) {
    printf( "Warning! Secret key input larger than 2k.\n" );
  }
  while( len < SECLEN ) {
    len++;
    fputc(0, out); // pad 0's to 2k length
  }
  
  while( !feof(pub) ) {
    len++;
    fputc(fgetc(pub), out);
  }
  if( len >= (SECLEN + PUBLEN)) {
    printf( "Warning! public key length too long.\n" );
  }
  while( len < (SECLEN + PUBLEN) ) {
    len++;
    fputc(0, out); // pad 0's to almost 4k length
  }
  
  uuid_generate(uuid);

  fwrite( uuid, sizeof(uuid), 1, out );
  
  print_uuid(&uuid);

  fclose(out);
  fclose(secret);
  fclose(pub);
}
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;
}
Exemplo n.º 28
0
void on_connect(EV_P_ struct ev_io *io, int revents) {
    while (1) {
        struct sockaddr_in client_addr;
        socklen_t len = sizeof (struct sockaddr_in);
        int client_sock = accept(io->fd, (struct sockaddr *) &client_addr, &len);
        if (client_sock >= 0) {

            if (set_nonblock(client_sock) == -1) {
                shutdown_printerr(client_sock, "can't set the socket mode O_NONBLOCK for client\n");
                return;
            }

            if (set_linger(client_sock) == -1) {
                shutdown_printerr(client_sock, "can't set SO_LINGER sock option for client\n");
                return;
            }

            if (set_keepalive(client_sock) == -1) {
                shutdown_printerr(client_sock, "can't set SO_KEEPALIVE sock option for client\n");
                return;
            }

            server_ctx_t *srv_ctx = (server_ctx_t *) ev_userdata(loop);
            client_ctx_t* cli_ctx = get_client_ctx(srv_ctx);
            cli_ctx->io.ctx = cli_ctx;
            cli_ctx->connected_at = time(NULL);
            uuid_generate(cli_ctx->uuid);
            memcpy(&cli_ctx->client_addr, &client_addr, sizeof (struct sockaddr_in));
            ev_io_init((ev_io *) & cli_ctx->io, client_read_write, client_sock, EV_READ);
            ev_io_start(loop, (ev_io *) & cli_ctx->io);
            char time_buff[32];
            strftime(time_buff, sizeof (time_buff), "%Y-%m-%d %H:%M:%S %Z", localtime(&cli_ctx->connected_at));
            char *addr = inet_ntoa(cli_ctx->client_addr.sin_addr);
            char uuid_buff[37];
            uuid_unparse_lower(cli_ctx->uuid, (char *) &uuid_buff);
            printf("client accepted %s:%hu %s at %s\n", addr, client_addr.sin_port, &uuid_buff, &time_buff);
            char *welcome_msg = server_welcome(srv_ctx, cli_ctx);
            send_message(loop, cli_ctx->uuid, welcome_msg, strlen(welcome_msg));
            free(welcome_msg);
            char *new_client_msg = server_client_connected(cli_ctx);
            for (ssize_t i = 0; i < srv_ctx->clients_count; i++) {
                if (uuid_compare(srv_ctx->clients[i]->uuid, cli_ctx->uuid) != 0) {
                    send_message(loop, srv_ctx->clients[i]->uuid, new_client_msg, strlen(new_client_msg));
                }
            }
            free(new_client_msg);
        } else {
            if (errno == EAGAIN)
                return;
            if (errno == EMFILE || errno == ENFILE) {
                fprintf(stderr, "out of file descriptors\n");
                return;
            } else if (errno != EINTR) {
                fprintf(stderr, "accept connections error\n");
                return;
            }
        }
    }
}
Exemplo n.º 29
0
int
uuidgen(struct uuid *store, int count)
{

	while (--count > 0)
		uuid_generate(store++);
	return 0;
}
Exemplo n.º 30
0
/*
*获取随机数UUID
*author  mleaf_hexi
*mail:[email protected]
*/
static unsigned char* uuidget(char str[36])
{
    uuid_t uuid;
    uuid_generate(uuid);
    uuid_unparse(uuid, str);
    printf("%s\n", str);
    return str;
}