Esempio n. 1
0
int hash_search(int *array, struct hashtable_s *hash_table) {
  int sum, i, count;
  long y;
  count = 0;
  
  for (sum = -10000; sum <= 10000; sum++) {
    printf("Current sum: %d\n", sum);
    for (i = 0; i < LEN; i++) {
      //printf("Current x: %d\n", array[i]);
      y = sum - array[i];
      //printf("Current y: %ld\n", y);
      if (array[i] == y) {
	if (hash_count(y, hash_table) > 1) {
	  count++;
	  printf("x: %d, y: %ld, sum: %d, count: %d\n", array[i], y, sum, count);
	  break;
	}
      }
      else if (hash_count(y, hash_table) > 0) {  
	count++;
	printf("%d\n", count);
	break;
      }
    }
  }
  return count;
}
Esempio n. 2
0
/// Finalizer - releases all allocated memory for object.
/// If object is a null pointer, no action occurs.
/// @param[in] ca       the object pointer
void
ca_destroy(ca_o ca)
{
    hash_t *hash;

    if (!ca) {
        return;
    }

    if ((hash = ca->ca_group_hash)) {
        if (hash_count(hash)) {
            putil_warn("group destroyed with %d audits left",
                       (int)hash_count(hash));
        }
        hash_destroy(ca->ca_group_hash);
        ca->ca_group_hash = NULL;
    }

    ca_clear_pa(ca);

    dict_destroy(ca->ca_raw_pa_dict);

    putil_free(ca->ca_prog);
    putil_free(ca->ca_host);
    putil_free(ca->ca_recycled);
    putil_free(ca->ca_rwd);
    putil_free(ca->ca_pccode);
    putil_free(ca->ca_ccode);
    putil_free(ca->ca_pathcode);
    putil_free(ca->ca_subs);
    putil_free(ca->ca_freetext);
    putil_free(ca->ca_line);
    memset(ca, 0, sizeof(*ca));
    putil_free(ca);
}
Esempio n. 3
0
int main(void)
{
	hash_t *hash = hash_make();
	char *key = NULL;
	int n = 100,*val;
	unsigned int count;

	hash_index_t *hi;
	unsigned int sum = 0;
	int i;

	for(i = 0;i<100000;++i)
	{
		key = malloc(sizeof(char) * 256);
		memset(key,0,256);

		val = malloc(sizeof(int));
		*val = i;

		sprintf(key,"char%10d",i);
		hash_set(hash,key,HASH_KEY_STRING,val);

		void *entry_key;
		val = hash_get(hash,key,HASH_KEY_STRING,&entry_key);
		if(entry_key)
		{
		    printf("key:%s\n",(char*)entry_key);
		}

	//	if(val)
	//	printf("val:%d\n",*val);
	}

	for (hi = hash_first(hash); hi ; hi = hash_next(hi)){
		hash_this(hi,(const void **)&key,NULL,(void **)&val);
		hash_set(hash,key,HASH_KEY_STRING,NULL);
		printf("val:%d\n",*(int *)val);
		sum += *(int *)val;
		free(key);
		free(val);
	}
	
	printf("sum:%d\n",sum);

	count = hash_count(hash);
	printf("count:%u\n",count);

	hash_clear(hash);

	count = hash_count(hash);
	printf("count after clear:%u\n",count);

	hash_destroy(hash);

	return 0;
}
Esempio n. 4
0
static list_t *
set_vendor_namespaces(void) 
{
  hscan_t hs;
  hnode_t *hn;
  int i;

  list_t *l = list_create(LISTCOUNT_T_MAX);
  for (i = 0; CimResource_Namespaces[i].ns != NULL; i++) {
    WsSupportedNamespaces *ns =
          (WsSupportedNamespaces *)u_malloc(sizeof(WsSupportedNamespaces));
    ns->class_prefix = CimResource_Namespaces[i].class_prefix;
    ns->ns = (char*) CimResource_Namespaces[i].ns;
    lnode_t *node = lnode_create(ns);
    list_append(l, node);
  }

  if (vendor_namespaces && hash_count(vendor_namespaces) > 0 ) {
    hash_scan_begin(&hs, vendor_namespaces);
    while ((hn = hash_scan_next(&hs))) {
      WsSupportedNamespaces *ns =
           (WsSupportedNamespaces *)u_malloc(sizeof(WsSupportedNamespaces));
      ns->class_prefix = (char*)hnode_getkey(hn);
      ns->ns = (char*) hnode_get(hn);
      lnode_t *node = lnode_create(ns);
      list_append(l, node);
    }
  }
  return l;
}
Esempio n. 5
0
void
test_string(int nelts) {
    hash_t h;
    hash_node_t *node;
    char key[KEY_MAX], val[VAL_MAX];
    int i, j; //, t;

    hash_init(&h, hash_hash_str, hash_cmp_str, KEY_MAX, VAL_MAX, 1);
    for(i=0; i<nelts; i++) {
	sprintf(key, "%dk%d", i, i);
	sprintf(val, "%dv%d", i, i);
	node = hash_put(&h, key, val);

	//t = 1;
	for(j=0; j<hash_count(&h); j++) {
	    sprintf(key, "%dk%d", j, j);
	    sprintf(val, "%dv%d", j, j);
	    node = hash_get(&h, key);
	    if( !node ) {
		fprintf(stderr, "error: i=%d j=%d key=%s not found\n", 
			i, j, key);
	    }
	    else if( strcmp(key, node->node_key)
		     || strcmp(val, node->node_val) ) {
		fprintf(stderr, "error: key=%s val=%s node=[%s %s]\n",
			key, val, (char*)node->node_key, (char*)node->node_val);
		//t = 0;
	    }
	}
    }
}
Esempio n. 6
0
int kerfs_icache_report(int direction, void *param, size_t size, size_t offset, size_t length, unsigned char *buf)
{
	size_t current = 0;
	KERFS_PRINTF(offset, length, buf, current,
			"icache load: %d%%\n", (100 * hash_count(icache)) / hash_length(icache));
	KERFS_PRINTF(offset, length, buf, current,
			"IN USE %d, DIRTY %d, LRU LEN %d, TOTAL CACHED %d\n",
			ic_inuse->count, ic_dirty->count, ic_lru->count, icache->count);
	return current;
}
Esempio n. 7
0
void hash_set_allocator(hash_t *hash, hnode_alloc_t al,
                        hnode_free_t fr, void *context)
{
    assert (hash_count(hash) == 0);
    assert ((al == 0 && fr == 0) || (al != 0 && fr != 0));

    hash->allocnode = al ? al : hnode_alloc;
    hash->freenode = fr ? fr : hnode_free;
    hash->context = context;
}
Esempio n. 8
0
int
verify(hash_t *hash, elt *elts, int nelts, char *msg) {
    int i, err;
    hash_node_t *node=0, tmp;
    elt *p;

    memset(&tmp, 0, sizeof(tmp));

    printf("%s: ", msg);

    err = 0;
    for(i=0, p=elts; i<nelts; i++, p++) {
	p->got_foreach = 0;
	node = hash_get(hash, p);
	if( !p->in_hash && node ) {
	    printf("error: p found in hash"
		   " at %d: p=%p, in_hash=%d, key=%p val=%p",
		   i, p, p->in_hash, node->node_key, node->node_val);
	    err = 1;
	}
	if( p->in_hash && (!node || node->node_val != p) ) {
	    node = &tmp;
	    err = 1;
	    printf("error: p not found in hash"
		   " at %d: p=%p, in_hash=%d, key=%p val=%p\n",
		   i, p, p->in_hash, node->node_key, node->node_val);
	}
    }
    
    hash_foreach(hash, verify_foreach, elts);
    for(i=0, p=elts; i<nelts; i++, p++) {
	if( p->in_hash && !p->got_foreach ) {
	    printf("error in foreach: elt missed"
		   " at i=%d, key=%p, val=%p, got_foreach=%d\n",
		   i, node->node_key, node->node_val, 
		   p->got_foreach);
	    err = 1;
	}
    }

    if( !err ) {
	hash_stat_t st;
	i = hash_stat(hash, &st);
	printf("ok\n  count=%d buckets=%d used=%d(%0.1f%%) max=%d avg=%.1f",
	       hash_count(hash), st.count, st.used, 
	       (float)100.0*st.used/st.count, 
	       st.max, st.avg);
    }
    printf("\n");

    return err;
}
Esempio n. 9
0
void CGEN_PRIVATE CFst_Cps_HashPrint(CFst* _this)
{
  hscan_t  hs;
  hnode_t* hn;
  FST_ITYPE nS;

  printf("\n -- CFst_Cps_HashPrint: %ld entries --",(long)hash_count((hash_t*)_this->m_lpCpsHash));
  hash_scan_begin(&hs,(hash_t*)_this->m_lpCpsHash);
  while ((hn = hash_scan_next(&hs))!=NULL)
  {
  	nS = (FST_ITYPE)((int)((UINT64)hnode_get(hn)&0xffffffff));
  	printf("\n   %ld",nS);
  }
  printf("\n -------------------------------------");

}
Esempio n. 10
0
void
wsmc_add_selector_from_options(WsXmlDocH doc, client_opt_t *options)
{
	WsXmlNodeH      header;
	hnode_t        *hn;
	hscan_t         hs;
	if (!options->selectors || hash_count(options->selectors) == 0)
		return;
	header = ws_xml_get_soap_header(doc);
	hash_scan_begin(&hs, options->selectors);
	while ((hn = hash_scan_next(&hs))) {
		wsman_add_selector(header,
				(char *) hnode_getkey(hn), (char *) hnode_get(hn));
		debug("key = %s value=%s",
				(char *) hnode_getkey(hn), (char *) hnode_get(hn));
	}
}
Esempio n. 11
0
static int AccessList( const CmdParams *cmdparams )
{
	hscan_t accessscan;
	hnode_t *node;
	AccessEntry *access;

	SET_SEGV_LOCATION();	
	irc_prefmsg( NULL, cmdparams->source, "Access List (%d):", ( int )hash_count( accesshash ) );
	hash_scan_begin( &accessscan, accesshash );
	while( ( node = hash_scan_next( &accessscan ) ) != NULL) 
	{
		access = hnode_get( node );
		irc_prefmsg( NULL, cmdparams->source, "%s %s (%d)", access->nick, access->mask, access->level );
	}
	irc_prefmsg( NULL, cmdparams->source, "End of list." );
	return NS_SUCCESS;
}
Esempio n. 12
0
epr_t *epr_create(const char *uri, hash_t * selectors, const char *address)
{
	epr_t *epr = NULL;
	epr = u_malloc(sizeof(epr_t));
	if (address == NULL)
		epr->address = u_strdup(WSA_TO_ANONYMOUS);
	else
		epr->address = u_strdup(address);

	epr->refparams.uri = u_strdup(uri);

	if (selectors) {
		hnode_t        *hn;
		hscan_t         hs;
		Selector *p;
		selector_entry *entry;
		epr->refparams.selectorset.count = hash_count(selectors);
		epr->refparams.selectorset.selectors = u_malloc(sizeof(Selector)*
			epr->refparams.selectorset.count);

		p = epr->refparams.selectorset.selectors;
		hash_scan_begin(&hs, selectors);
		while ((hn = hash_scan_next(&hs))) {
			p->name = u_strdup((char *)hnode_getkey(hn));
			entry = (selector_entry *)hnode_get(hn);
			if(entry->type == 0) {
				p->type = 0;
				p->value = u_strdup(entry->entry.text);
				debug("key = %s value=%s",
					(char *) hnode_getkey(hn), p->value);
			}
			else {
				p->type = 1;
				p->value = (char *)epr_copy(entry->entry.eprp);
				debug("key = %s value=%p(nested epr)",
					(char *) hnode_getkey(hn), p->value);
			}
			p++;
		}
	} else {
		epr->refparams.selectorset.count  = 0;
		epr->refparams.selectorset.selectors  = NULL;
	}
	return epr;
}
Esempio n. 13
0
int 
wrap_hash_count(WRAPPERS_ARGS, hash_t h)
{
  int rv;

  assert(file && function);

  if (!h)
    WRAPPERS_ERR_INVALID_PARAMETERS("hash_count");

  if (!(rv = hash_count(h)))
    {
      if (errno != 0)
        WRAPPERS_ERR_ERRNO("hash_count");
    }

  return rv;
}
Esempio n. 14
0
void lease_remove(Lease *lease) {
    assert(null(lease->wavefront));
    assert(lease->fids == NULL || hash_count(lease->fids) == 0);
    assert(null(lease->changeexits));
    assert(null(lease->changefids));

    if (lease->isexit) {
        lease_unlink_exit(lease);
    } else {
        claim_clear_descendents(lease->claim);
        lease_clear_dir_cache(lease);
    }

    hash_remove(lease_by_root_pathname, lease->pathname);
    lease->pathname = NULL;
    lease->addr = NULL;
    lease->claim = NULL;
    lease->lastchange = now_double();
}
Esempio n. 15
0
void Register_connect(int fd, int conn_type)
{
    assert(registrations && "Call Register_init.");

    debug("Registering %d ident.", fd);

    hnode_t *hn = hash_lookup(registrations, (void *)(intptr_t)fd);

    if(hn) hash_delete_free(registrations, hn);

    check(hash_alloc_insert(registrations, (void *)(intptr_t)fd, 
                (void *)(intptr_t)conn_type), "Cannot register fd, out of space.");

    debug("Currently registered idents: %d", (int)hash_count(registrations));

    return;

error:
    taskexitall(1);
}
Esempio n. 16
0
static errno_t find_ipa_ext_memberships(TALLOC_CTX *mem_ctx,
                                        const char *user_name,
                                        struct sss_domain_info *user_dom,
                                        hash_table_t *ext_group_hash,
                                        struct ldb_dn **_user_dn,
                                        char ***_groups)
{
    int ret;
    TALLOC_CTX *tmp_ctx = NULL;
    struct ldb_result *result;
    char **groups = NULL;
    size_t c;
    const char *sid;
    hash_key_t key;
    hash_value_t value;
    hash_entry_t *entry;
    struct hash_iter_context_t *iter;
    hash_table_t *group_hash;
    size_t g_count;
    struct ldb_dn *user_dn = NULL;

    tmp_ctx = talloc_new(NULL);
    if (tmp_ctx == NULL) {
        return ENOMEM;
    }

    ret = sysdb_initgroups(tmp_ctx, user_dom, user_name, &result);
    if (ret != EOK) {
        DEBUG(SSSDBG_OP_FAILURE, "sysdb_initgroups failed.\n");
        goto done;
    }

    if (result->count == 0) {
        DEBUG(SSSDBG_MINOR_FAILURE, "User [%s] not found in cache.\n",
                                     user_name);
        ret = EOK;
        goto done;
    }

    ret = sss_hash_create(tmp_ctx, 10, &group_hash);
    if (ret != HASH_SUCCESS) {
        DEBUG(SSSDBG_OP_FAILURE, "sss_hash_create failed.\n");
        goto done;
    }

    key.type = HASH_KEY_STRING;

    /* The IPA external domains can have references to group and user SIDs.
     * This means that we not only want to look up the group SIDs but the SID
     * of the user (first element of result) as well. */
    for (c = 0; c < result->count; c++) {
        sid = ldb_msg_find_attr_as_string(result->msgs[c], SYSDB_SID_STR,
                                          NULL);
        if (sid == NULL) {
            DEBUG(SSSDBG_MINOR_FAILURE, "Group [%s] does not have a SID.\n",
                  ldb_dn_get_linearized(result->msgs[c]->dn));
            continue;
        }

        key.str = discard_const(sid);
        ret = hash_lookup(ext_group_hash, &key, &value);
        if (ret == HASH_ERROR_KEY_NOT_FOUND) {
            DEBUG(SSSDBG_TRACE_ALL, "SID [%s] not found in ext group hash.\n",
                                     sid);
        } else if (ret == HASH_SUCCESS) {
            iter = new_hash_iter_context(value.ptr);
            if (iter == NULL) {
                DEBUG(SSSDBG_OP_FAILURE, "new_hash_iter_context failed.\n");
                ret = EINVAL;
                goto done;
            }

            while ((entry = iter->next(iter)) != NULL) {
                ret = hash_enter(group_hash, &entry->key, &entry->value);
                if (ret != HASH_SUCCESS) {
                    DEBUG(SSSDBG_OP_FAILURE, "Failed to add group [%s].\n",
                                              entry->key.str);
                }
            }

            talloc_free(iter);
        } else {
            DEBUG(SSSDBG_OP_FAILURE, "hash_lookup failed for SID [%s].\n",
                                      sid);
        }
    }

    g_count = hash_count(group_hash);
    if (g_count == 0) {
        DEBUG(SSSDBG_TRACE_FUNC, "No external groupmemberships found.\n");
        ret = EOK;
        goto done;
    }

    groups = talloc_zero_array(mem_ctx, char *, g_count + 1);
    if (groups == NULL) {
        DEBUG(SSSDBG_OP_FAILURE, "talloc_array failed.\n");
        ret = ENOMEM;
        goto done;
    }

    iter = new_hash_iter_context(group_hash);
    if (iter == NULL) {
        DEBUG(SSSDBG_OP_FAILURE, "new_hash_iter_context failed.\n");
        ret = EINVAL;
        goto done;
    }

    c = 0;
    while ((entry = iter->next(iter)) != NULL) {
        groups[c] = talloc_strdup(groups, entry->key.str);
        if (groups[c] == NULL) {
            DEBUG(SSSDBG_OP_FAILURE, "talloc_strdup failed.\n");
            ret = ENOMEM;
            goto done;
        }
        c++;
    }

    user_dn = ldb_dn_copy(mem_ctx, result->msgs[0]->dn);
    if (user_dn == NULL) {
        DEBUG(SSSDBG_OP_FAILURE, "ldb_dn_copy failed.\n");
        ret = ENOMEM;
        goto done;
    }

    ret = EOK;
done:
    *_user_dn = user_dn;
    *_groups = groups;

    talloc_free(tmp_ctx);

    return ret;
}
Esempio n. 17
0
bool
ipa_sudo_conv_has_cmds(struct ipa_sudo_conv *conv)
{
    return hash_count(conv->cmds) == 0;
}
Esempio n. 18
0
static int fdfs_dump_global_vars(char *buff, const int buffSize)
{
	char szStorageJoinTime[32];
	char szSyncUntilTimestamp[32];
	char szUptime[32];
	char reserved_space_str[32];
	int total_len;
	int i;

	total_len = snprintf(buff, buffSize,
		"g_fdfs_connect_timeout=%ds\n"
		"g_fdfs_network_timeout=%ds\n"
		"g_fdfs_base_path=%s\n"
		"g_fdfs_version=%d.%02d\n"
		"g_continue_flag=%d\n"
		"g_schedule_flag=%d\n"
		"g_server_port=%d\n"
		"g_max_connections=%d\n"
		"g_storage_thread_count=%d\n"
		"g_group_name=%s\n"
		"g_sync_log_buff_interval=%d\n"
		"g_subdir_count_per_path=%d\n"
		"g_http_port=%d\n"
		"g_last_server_port=%d\n"
		"g_last_http_port=%d\n"
		"g_allow_ip_count=%d\n"
		"g_run_by_group=%s\n"
		"g_run_by_user=%s\n"
		"g_http_domain=%s\n"
		"g_file_distribute_path_mode=%d\n"
		"g_file_distribute_rotate_count=%d\n"
		"g_fsync_after_written_bytes=%d\n"
		"g_dist_path_index_high=%d\n"
		"g_dist_path_index_low=%d\n"
		"g_dist_write_file_count=%d\n"
		"g_disk_rw_direct=%d\n"
		"g_disk_rw_separated=%d\n"
		"g_disk_reader_threads=%d\n"
		"g_disk_writer_threads=%d\n"
		"g_extra_open_file_flags=%d\n"
		"g_tracker_reporter_count=%d\n"
		"g_heart_beat_interval=%d\n"
		"g_stat_report_interval=%d\n"
		"g_sync_wait_usec=%dms\n"
		"g_sync_interval=%dms\n"
		"g_sync_start_time=%d:%d\n"
		"g_sync_end_time=%d:%d\n"
		"g_sync_part_time=%d\n"
		"g_sync_log_buff_interval=%ds\n"
		"g_sync_binlog_buff_interval=%ds\n"
		"g_write_mark_file_freq=%d\n"
		"g_sync_stat_file_interval=%ds\n"
		"g_storage_join_time=%s\n"
		"g_sync_old_done=%d\n"
		"g_sync_src_id=%s\n"
		"g_sync_until_timestamp=%s\n"
		"g_my_server_id_str=%s\n"
		"g_tracker_client_ip=%s\n"
		"g_last_storage_ip=%s\n"
		"g_check_file_duplicate=%d\n"
		"g_key_namespace=%s\n"
		"g_namespace_len=%d\n"
		"g_bind_addr=%s\n"
		"g_client_bind_addr=%d\n"
		"g_storage_ip_changed_auto_adjust=%d\n"
		"g_thread_kill_done=%d\n"
		"g_thread_stack_size=%d\n"
		"g_upload_priority=%d\n"
		"g_up_time=%s\n"
		"g_if_alias_prefix=%s\n"
		"g_binlog_fd=%d\n"
		"g_binlog_index=%d\n"
		"g_storage_sync_thread_count=%d\n"
		"g_use_storage_id=%d\n"
		"g_if_use_trunk_file=%d\n"
		"g_if_trunker_self=%d\n"
		"g_slot_min_size=%d\n"
		"g_trunk_file_size=%d\n"
		"g_store_path_mode=%d\n"
		"storage_reserved_mb=%s\n"
		"g_avg_storage_reserved_mb=%d\n"
		"g_store_path_index=%d\n"
		"g_current_trunk_file_id=%d\n"
		"g_trunk_sync_thread_count=%d\n"
		"g_trunk_server=%s:%d\n"
		"g_trunk_total_free_space=%"PRId64"\n"
		"g_use_connection_pool=%d\n"
		"g_connection_pool_max_idle_time=%d\n"
		"connection_pool_conn_count=%d\n"
	#ifdef WITH_HTTPD
		"g_http_params.disabled=%d\n"
		"g_http_params.anti_steal_token=%d\n"
		"g_http_params.server_port=%d\n"
		"g_http_params.content_type_hash item count=%d\n"
		"g_http_params.anti_steal_secret_key length=%d\n"
		"g_http_params.token_check_fail_buff length=%d\n"
		"g_http_params.default_content_type=%s\n"
		"g_http_params.token_check_fail_content_type=%s\n"
		"g_http_params.token_ttl=%d\n"
		"g_http_trunk_size=%d\n"
	#endif
	#if defined(DEBUG_FLAG) && defined(OS_LINUX)
		"g_exe_name=%s\n"
	#endif
		, g_fdfs_connect_timeout
		, g_fdfs_network_timeout
		, g_fdfs_base_path
		, g_fdfs_version.major, g_fdfs_version.minor
		, g_continue_flag
		, g_schedule_flag
		, g_server_port
		, g_max_connections
		, g_storage_thread_count
		, g_group_name
		, g_sync_log_buff_interval
		, g_subdir_count_per_path 
		, g_http_port 
		, g_last_server_port 
		, g_last_http_port
		, g_allow_ip_count
		, g_run_by_group
		, g_run_by_user
		, g_http_domain
		, g_file_distribute_path_mode
		, g_file_distribute_rotate_count
		, g_fsync_after_written_bytes
		, g_dist_path_index_high
		, g_dist_path_index_low
		, g_dist_write_file_count
		, g_disk_rw_direct
		, g_disk_rw_separated
		, g_disk_reader_threads
		, g_disk_writer_threads
		, g_extra_open_file_flags
		, g_tracker_reporter_count
		, g_heart_beat_interval
		, g_stat_report_interval
		, g_sync_wait_usec / 1000
		, g_sync_interval
		, g_sync_start_time.hour, g_sync_start_time.minute
		, g_sync_end_time.hour, g_sync_end_time.minute
		, g_sync_part_time
		, g_sync_log_buff_interval
		, g_sync_binlog_buff_interval
		, g_write_mark_file_freq
		, g_sync_stat_file_interval
		, formatDatetime(g_storage_join_time, "%Y-%m-%d %H:%M:%S", 
			szStorageJoinTime, sizeof(szStorageJoinTime))
		, g_sync_old_done
		, g_sync_src_id
		, formatDatetime(g_sync_until_timestamp, "%Y-%m-%d %H:%M:%S", 
			szSyncUntilTimestamp, sizeof(szSyncUntilTimestamp))
                , g_my_server_id_str
		, g_tracker_client_ip
		, g_last_storage_ip
		, g_check_file_duplicate
		, g_key_namespace
		, g_namespace_len
		, g_bind_addr
		, g_client_bind_addr
		, g_storage_ip_changed_auto_adjust
		, g_thread_kill_done
		, g_thread_stack_size
		, g_upload_priority
		, formatDatetime(g_up_time, "%Y-%m-%d %H:%M:%S", 
			szUptime, sizeof(szUptime))
		, g_if_alias_prefix
		, g_binlog_fd
		, g_binlog_index
		, g_storage_sync_thread_count
		, g_use_storage_id
		, g_if_use_trunk_file
		, g_if_trunker_self
		, g_slot_min_size
		, g_trunk_file_size
		, g_store_path_mode
		, fdfs_storage_reserved_space_to_string( \
			&g_storage_reserved_space, reserved_space_str) \
		, g_avg_storage_reserved_mb
		, g_store_path_index
		, g_current_trunk_file_id
		, g_trunk_sync_thread_count
		, g_trunk_server.ip_addr, g_trunk_server.port
		, g_trunk_total_free_space
		, g_use_connection_pool
		, g_connection_pool_max_idle_time
		, g_use_connection_pool ? conn_pool_get_connection_count( \
			&g_connection_pool) : 0
	#ifdef WITH_HTTPD
		, g_http_params.disabled
		, g_http_params.anti_steal_token
		, g_http_params.server_port
		, hash_count(&(g_http_params.content_type_hash))
		, g_http_params.anti_steal_secret_key.length
		, g_http_params.token_check_fail_buff.length
		, g_http_params.default_content_type
		, g_http_params.token_check_fail_content_type
		, g_http_params.token_ttl
		, g_http_trunk_size
	#endif
		
	#if defined(DEBUG_FLAG) && defined(OS_LINUX)
		, g_exe_name
	#endif
	);

	total_len += snprintf(buff + total_len, buffSize - total_len,
			"\ng_fdfs_store_paths.count=%d\n", g_fdfs_store_paths.count);
	for (i=0; i<g_fdfs_store_paths.count; i++)
	{
		total_len += snprintf(buff + total_len, buffSize - total_len,
				"\tg_fdfs_store_paths.paths[%d]=%s, " \
				"total=%d MB, free=%d MB\n", i, \
				g_fdfs_store_paths.paths[i], \
				g_path_space_list[i].total_mb, \
				g_path_space_list[i].free_mb);
	}

	total_len += snprintf(buff + total_len, buffSize - total_len,
			"\ng_local_host_ip_count=%d\n", g_local_host_ip_count);
	for (i=0; i<g_local_host_ip_count; i++)
	{
		total_len += snprintf(buff + total_len, buffSize - total_len,
				"\tg_local_host_ip_addrs[%d]=%s\n", i, 
				g_local_host_ip_addrs + i * IP_ADDRESS_SIZE);
	}

	return total_len;
}
Esempio n. 19
0
/* mutator_count */
size_t mutator_count(Mutator * mutator)
{
	return hash_count(mutator);
}
Esempio n. 20
0
int main(int argc, char **argv)
{
    static hash_table_t *table = NULL;
    hash_key_t key, *keys;
    hash_value_t value;
    struct hash_iter_context_t *iter;
    hash_entry_t *entry;
    unsigned long i, n_entries;
    int error;
    struct my_data_t *my_data = new_data(1024, "Hello World!");
    unsigned long count;

    /* Create a hash table */
    error = hash_create(10, &table, delete_callback,  NULL);
    if (error != HASH_SUCCESS) {
        fprintf(stderr, "cannot create hash table (%s)\n", hash_error_string(error));
        return error;
    }

    /* Enter a key named "My Data" and specify it's value as a pointer to my_data */
    key.type = HASH_KEY_STRING;
    key.str = strdup("My Data");
    value.type = HASH_VALUE_PTR;
    value.ptr = my_data;

    if ((error = hash_enter(table, &key, &value)) != HASH_SUCCESS) {
        fprintf(stderr, "cannot add to table \"%s\" (%s)\n", key.str, hash_error_string(error));
        return error;
    }
    free(key.str);

    /* Get a list of keys and print them out, free the list when we're done */
    if ((error = hash_keys(table, &count, &keys)) != HASH_SUCCESS) {
        fprintf(stderr, "cannot get key list (%s)\n", hash_error_string(error));
        return error;
    }

    for (i = 0; i < count; i++)
        printf("key: %s\n", keys[i].str);
    free(keys);

    /* Lookup the key named "My Data" */
    key.type = HASH_KEY_STRING;
    key.str = strdup("My Data");
    if ((error = hash_lookup(table, &key, &value)) != HASH_SUCCESS) {
        fprintf(stderr, "cannot find key \"%s\" (%s)\n", key.str, hash_error_string(error));
    }
    free(key.str);

    /* Visit each entry in the table, callback will increment count on each visit */
    printf("Iterate using callback\n");
    count = 0;
    hash_iterate(table, visit_callback, &count);

    /* Assure number of visits equal the table size */
    assert(count == hash_count(table));

    /* Visit each entry using iterator object */
    printf("Iterate using iterator\n");
    n_entries = 0;
    iter = new_hash_iter_context(table);
    while ((entry = iter->next(iter)) != NULL) {
        struct my_data_t *data = (struct my_data_t *) entry->value.ptr;

        printf("%s = [foo=%d bar=%s]\n", entry->key.str, data->foo, data->bar);
        n_entries++;
    }
    free(iter);
    /* Assure number of visits equal the table size */
    assert(n_entries == hash_count(table));

    /* Remove the entry, deletion callback will be invoked */
    key.type = HASH_KEY_STRING;
    key.str = strdup("My Data");
    if ((error = hash_delete(table, &key)) != HASH_SUCCESS) {
        fprintf(stderr, "cannot delete from table (%s)\n", hash_error_string(error));
    }

    /* Assure key is no longer in table */
    assert (!hash_has_key(table, &key));
    free(key.str);

    /* Free the table */
    hash_destroy(table);

    return 0;
}
Esempio n. 21
0
int get_num_defines () {
	return hash_count (define_table);
}
Esempio n. 22
0
int get_num_labels () {
	return hash_count (label_table);
}
Esempio n. 23
0
static int fdfs_dump_global_vars(char *buff, const int buffSize)
{
	int total_len;
	char reserved_space_str[32];
	
	total_len = snprintf(buff, buffSize,
		"g_fdfs_connect_timeout=%ds\n"
		"g_fdfs_network_timeout=%ds\n"
		"g_fdfs_base_path=%s\n"
		"g_fdfs_version=%d.%02d\n"
		"g_continue_flag=%d\n"
		"g_schedule_flag=%d\n"
		"g_server_port=%d\n"
		"g_max_connections=%d\n"
		"g_tracker_thread_count=%d\n"
		"g_sync_log_buff_interval=%ds\n"
		"g_check_active_interval=%ds\n"
		"g_storage_stat_chg_count=%d\n"
		"g_storage_sync_time_chg_count=%d\n"
		"g_storage_reserved_space=%s\n"
		"g_allow_ip_count=%d\n"
		"g_run_by_group=%s\n"
		"g_run_by_user=%s\n"
		"g_storage_ip_changed_auto_adjust=%d\n"
		"g_thread_stack_size=%d\n"
		"if_use_trunk_file=%d\n"
		"slot_min_size=%d\n"
		"slot_max_size=%d MB\n"
		"trunk_file_size=%d MB\n"
		"g_changelog_fsize="INT64_PRINTF_FORMAT"\n"
		"g_storage_sync_file_max_delay=%ds\n"
		"g_storage_sync_file_max_time=%ds\n"
		"g_up_time=%d\n"
		"g_tracker_last_status.up_time=%d\n"
		"g_tracker_last_status.last_check_time=%d\n"
		"g_if_leader_self=%d\n"
		"g_next_leader_index=%d\n"
		"g_tracker_leader_chg_count=%d\n"
		"g_trunk_server_chg_count=%d\n"
		"g_use_connection_pool=%d\n"
		"g_connection_pool_max_idle_time=%d\n"
		"connection_pool_conn_count=%d\n"
	#ifdef WITH_HTTPD
		"g_http_params.disabled=%d\n"
		"g_http_params.anti_steal_token=%d\n"
		"g_http_params.server_port=%d\n"
		"g_http_params.content_type_hash item count=%d\n"
		"g_http_params.anti_steal_secret_key length=%d\n"
		"g_http_params.token_check_fail_buff length=%d\n"
		"g_http_params.default_content_type=%s\n"
		"g_http_params.token_check_fail_content_type=%s\n"
		"g_http_params.token_ttl=%d\n"
		"g_http_check_interval=%d\n"
		"g_http_check_type=%d\n"
		"g_http_check_uri=%s\n"
		"g_http_servers_dirty=%d\n"
	#endif
	#if defined(DEBUG_FLAG) && defined(OS_LINUX)
		"g_exe_name=%s\n"
	#endif
		, g_fdfs_connect_timeout
		, g_fdfs_network_timeout
		, g_fdfs_base_path
		, g_fdfs_version.major, g_fdfs_version.minor
		, g_continue_flag
		, g_schedule_flag
		, g_server_port
		, g_max_connections
		, g_tracker_thread_count
		, g_sync_log_buff_interval
		, g_check_active_interval
		, g_storage_stat_chg_count
		, g_storage_sync_time_chg_count
		, fdfs_storage_reserved_space_to_string( \
		    &g_storage_reserved_space, reserved_space_str) \
		, g_allow_ip_count
		, g_run_by_group
		, g_run_by_user
		, g_storage_ip_changed_auto_adjust
		, g_thread_stack_size
		, g_if_use_trunk_file
		, g_slot_min_size
		, g_slot_max_size / FDFS_ONE_MB
		, g_trunk_file_size / FDFS_ONE_MB
		, g_changelog_fsize
		, g_storage_sync_file_max_delay
		, g_storage_sync_file_max_time
		, (int)g_up_time
		, (int)g_tracker_last_status.up_time
		, (int)g_tracker_last_status.last_check_time
		, g_if_leader_self
		, g_next_leader_index
		, g_tracker_leader_chg_count
		, g_trunk_server_chg_count
		, g_use_connection_pool
		, g_connection_pool_max_idle_time
		, g_use_connection_pool ? conn_pool_get_connection_count( \
			&g_connection_pool) : 0
	#ifdef WITH_HTTPD
		, g_http_params.disabled
		, g_http_params.anti_steal_token
		, g_http_params.server_port
		, hash_count(&(g_http_params.content_type_hash))
		, g_http_params.anti_steal_secret_key.length
		, g_http_params.token_check_fail_buff.length
		, g_http_params.default_content_type
		, g_http_params.token_check_fail_content_type
		, g_http_params.token_ttl
		, g_http_check_interval
		, g_http_check_type
		, g_http_check_uri
		, g_http_servers_dirty
	#endif
		
	#if defined(DEBUG_FLAG) && defined(OS_LINUX)
		, g_exe_name
	#endif
	);

	return total_len;
}
Esempio n. 24
0
int
IpConnTrack_conn_count(IpConnTrack *self) {
    return hash_count(&self->m_conn_hash);
}