예제 #1
0
int
cli_cmd_uuid_reset_cbk (struct cli_state *state, struct cli_cmd_word *word,
                        const char **words, int wordcount)
{
        int                     ret = -1;
        rpc_clnt_procedure_t    *proc = NULL;
        call_frame_t            *frame = NULL;
        int                     sent = 0;
        int                     parse_error = 0;
        gf_answer_t             answer = GF_ANSWER_NO;
        char                    *question = NULL;
        cli_local_t             *local = NULL;
        dict_t                  *dict  = NULL;
        xlator_t                *this  = NULL;

        question = "Resetting uuid changes the uuid of local glusterd. "
                   "Do you want to continue?";

        if (wordcount != 3) {
                cli_usage_out (word->pattern);
                parse_error = 1;
                goto out;
        }

        proc = &cli_rpc_prog->proctable[GLUSTER_CLI_UUID_RESET];

        this = THIS;
        frame = create_frame (this, this->ctx->pool);
        if (!frame)
                goto out;

        dict = dict_new ();
        if (!dict) {
                ret = -1;
                goto out;
        }
        CLI_LOCAL_INIT (local, words, frame, dict);
        answer = cli_cmd_get_confirmation (state, question);

        if (GF_ANSWER_NO == answer) {
                ret = 0;
                goto out;
        }

        //send NULL as argument since no dictionary is sent to glusterd
        if (proc->fn) {
                ret = proc->fn (frame, this, dict);
        }

out:
        if (ret) {
                cli_cmd_sent_status_get (&sent);
                if ((sent == 0) && (parse_error == 0))
                        cli_out ("uuid reset failed");
        }

        CLI_STACK_DESTROY (frame);

        return ret;
}
예제 #2
0
파일: layout.c 프로젝트: schnorr/viva
void *layout_new (void)
{
  tp_layout *ret = (tp_layout*) malloc (sizeof(tp_layout));

  ret->k = 1.0;
  ret->K1 = 0.06;
  ret->K2 = 0.024;
  ret->force = 1.0;
  //viewZone = 5.0; calculated by the quality level
  ret->theta = 0.7;
  ret->quality = 0;
  ret->nodesPerCell = 10;
  ret->maxTreeDepth = 100;

  ret->stabilizationLimit = 0.9;

  tp_rect universe = tp_Rect (-100, -100, 200, 200);
  ret->box = box_new (ret->nodesPerCell, ret->maxTreeDepth, universe);

  ret->nodes = dict_new (10000);

  layout_reset_energies (ret);

  layout_set_quality (ret, ret->quality);
  pthread_mutex_init (&mutex, NULL);
  return ret;
}
예제 #3
0
static dict_t *pkgmk_confs_explode(dict_t * pkgmk_confs, list_t * ports)
{
	unsigned i, j;
	dict_t *exploded;
	char *key, *pkgmk_conf;
	list_t *list;
	port_t *port;

	exploded = dict_new();

	for (i = 0; i < pkgmk_confs->length; i++) {
		key = xstrdup(pkgmk_confs->elements[i]->key);
		pkgmk_conf = xstrdup(pkgmk_confs->elements[i]->value);
		if (!is_file(pkgmk_conf)) {
			warning("pkgmk's conf %s, not found!", pkgmk_conf);
			free(key);
			free(pkgmk_conf);
			continue;
		}
		list = list_query(ports, port_query_by_name, key);
		for (j = 0; j < list->length; j++) {
			port = list->elements[j];
			if (dict_get(exploded, port->name) == NULL)
				dict_add(exploded, port->name,
					 xstrdup(pkgmk_conf));
		}
		list_free(list, NULL);
		free(key);
		free(pkgmk_conf);
	}

	return exploded;
}
예제 #4
0
static dict_t *
make_seq_dict (int argc, char **argv)
{
        char index[] = "4294967296"; // 1<<32
        int i        = 0;
        int ret      = 0;
        dict_t *dict = dict_new ();

        if (!dict)
                return NULL;

        for (i = 0; i < argc; i++) {
                snprintf(index, sizeof(index), "%d", i);
                ret = dict_set_str (dict, index, argv[i]);
                if (ret == -1)
                        break;
        }

        if (ret) {
                dict_destroy (dict);
                dict = NULL;
        }

        return dict;
}
예제 #5
0
파일: dict.c 프로젝트: wongm168/PegDF
dict* dict_copy(dict *d)
{
    dict *out;
    if (!d)
        return 0;
    out = dict_new(d->n);
#if defined (HASHMAP)
    hash_map_entry *e;
    hash_map_iterator *i = hash_map_front(d->dict);

    while (!hash_map_iterator_at_end(i))
    {
        e = hash_map_iterator_get(i);
        dict_entry_copy(e->k, e->v, out);
        hash_map_iterator_next(i);
    }
    hash_map_iterator_free(i);
    return out;
#elif defined(TSTC)
    tstc_call(d->dict, 0, dict_entry_copy, out);
    return out;
#else
    return 0;
#endif
}
예제 #6
0
파일: class.c 프로젝트: renlexing/projects
PmReturn_t
class_method(pPmObj_t pinstance, pPmObj_t pfunc, pPmObj_t *r_pmeth)
{
    PmReturn_t retval = PM_RET_OK;
    uint8_t *pchunk;
    pPmMethod_t pmeth;
    pPmObj_t pattrs;
    uint8_t objid;

    /* Allocate a method */
    retval = heap_getChunk(sizeof(PmMethod_t), &pchunk);
    PM_RETURN_IF_ERROR(retval);
    OBJ_SET_TYPE(pchunk, OBJ_TYPE_MTH);

    /* Set method fields */
    pmeth = (pPmMethod_t)pchunk;
    pmeth->m_instance = (pPmInstance_t)pinstance;
    pmeth->m_func = (pPmFunc_t)pfunc;
    pmeth->m_attrs = C_NULL;

    /* Create the attributes dict */
    heap_gcPushTempRoot((pPmObj_t)pmeth, &objid);
    retval = dict_new(&pattrs);
    heap_gcPopTempRoot(objid);
    pmeth->m_attrs = (pPmDict_t)pattrs;

    *r_pmeth = (pPmObj_t)pmeth;
    return retval;
}
예제 #7
0
파일: class.c 프로젝트: renlexing/projects
/* Returns an instance of the class by reference */
PmReturn_t
class_instantiate(pPmObj_t pclass, pPmObj_t *r_pobj)
{
    PmReturn_t retval = PM_RET_OK;
    uint8_t *pchunk;
    pPmObj_t pobj;
    pPmObj_t pattrs;
    uint8_t objid;

    /* Allocate a class instance */
    retval = heap_getChunk(sizeof(PmInstance_t), &pchunk);
    PM_RETURN_IF_ERROR(retval);
    pobj = (pPmObj_t)pchunk;
    OBJ_SET_TYPE(pobj, OBJ_TYPE_CLI);

    /* Set the instance's fields */
    ((pPmInstance_t)pobj)->cli_class = (pPmClass_t)pclass;
    ((pPmInstance_t)pobj)->cli_attrs = C_NULL;

    /* Create the attributes dict */
    heap_gcPushTempRoot(pobj, &objid);
    retval = dict_new(&pattrs);
    heap_gcPopTempRoot(objid);
    ((pPmInstance_t)pobj)->cli_attrs = (pPmDict_t)pattrs;

    /* TODO: Store pclass in __class__ attr */

    *r_pobj = pobj;
    return retval;
}
예제 #8
0
파일: types.c 프로젝트: 8l/awl
awlenv* awlenv_new(void) {
    awlenv* e = safe_malloc(sizeof(awlenv));
    e->parent = NULL;
    e->internal_dict = dict_new(awlval_copy_proxy, awlval_del_proxy);
    e->top_level = false;
    e->references = 1;
    return e;
}
예제 #9
0
static void store_function(const char*name, value_t*value)
{
    ID id = rb_intern(name);
    if(!global->functions) {
        global->functions = dict_new(&ptr_type);
    }
    dict_put(global->functions, (void*)id, value);
}
예제 #10
0
파일: types.c 프로젝트: 8l/awl
awlval* awlval_dict(void) {
    awlval* v = safe_malloc(sizeof(awlval));
    v->type = AWLVAL_DICT;
    v->count = 0;
    v->length = 0;
    v->d = dict_new(awlval_copy_proxy, awlval_del_proxy);
    return v;
}
예제 #11
0
int main(){

	struct dictionary *d;
	int i;
	d = dict_new(1,0);
	int min;
	int nums[7];
	int keys[7];
	
	keys[0] = 9;
	nums[0] = 14; 
	
	keys[1] = 4;
	nums[1] = 7; 
	
	keys[2] = 12;
	nums[2] = 5; 
	
	keys[3] = 0;
	nums[3] = 15; 
	
	keys[4] = 2;
	nums[4] = 3; 
	
	keys[5] = 14;
	nums[5] = 4; 
	
	keys[6] = 5;
	nums[6] = 2; 
	
	printf("new\n");
	
	//~ printHash(d);
		
	for(i = 0; i < 7; i++){
		//~ printf("Inserting %d...\n",nums[i]);
		dict_set(d,keys[i],nums[i]);
		//~ printHash(d);
	}
	
	printHash(d);
	
	dict_set(d,2,8);
	printf("set key 2 con 8\n");
	printf("get key 2 = %d\n",dict_get(d,2));
	
	printf("delete key 2\n");
	dict_delete(d,2);
	printHash(d);
	
	printf("delete key 9\n");
	dict_delete(d,9);
	printHash(d);
	
	dict_free(d);


}
예제 #12
0
int
cli_cmd_peer_probe_cbk (struct cli_state *state, struct cli_cmd_word *word,
                   const char **words, int wordcount)
{
        int                     ret = -1;
        rpc_clnt_procedure_t    *proc = NULL;
        call_frame_t            *frame = NULL;
        dict_t                  *dict = NULL;
        int                     sent = 0;
        int                     parse_error = 0;

        if (!(wordcount == 3)) {
                cli_usage_out (word->pattern);
                parse_error = 1;
                goto out;
        }

        proc = &cli_rpc_prog->proctable[GLUSTER_CLI_PROBE];

        frame = create_frame (THIS, THIS->ctx->pool);
        if (!frame)
                goto out;

        dict = dict_new ();
        if (!dict)
                goto out;

        ret = dict_set_str (dict, "hostname", (char *)words[2]);
        if (ret)
                goto out;

        ret = valid_internet_address ((char *) words[2]);
        if (ret == 1) {
                ret = 0;
        } else {
                cli_usage_out (word->pattern);
                parse_error = 1;
                goto out;
        }
/*        if (words[3]) {
                ret = dict_set_str (dict, "port", (char *)words[3]);
                if (ret)
                        goto out;
        }
*/
        if (proc->fn) {
                ret = proc->fn (frame, THIS, dict);
        }

out:
        if (ret) {
                cli_cmd_sent_status_get (&sent);
                if ((sent == 0) && (parse_error == 0))
                        cli_out ("Peer probe failed");
        }
        return ret;
}
예제 #13
0
ini_t *ini_new(char *filepath)
{
	ini_t *self;

	self = xmalloc(sizeof(ini_t));
	self->filepath = xstrdup(filepath);
	self->sections = dict_new();
	return self;
}
예제 #14
0
int
qserver_init(void)
{
    qserver_log = log_register_type("QServer", "file:qserver.log");
    conf_register_reload(qserver_conf_read);
    qserver_dict = dict_new();
    reg_exit_func(qserver_cleanup, NULL);
    return 1;
}
예제 #15
0
void initialize_parser()
{
    global = rfx_calloc(sizeof(global_t));
    global->file = abc_file_new();
    global->file->flags &= ~ABCFILE_LAZY;
    global->file2token2info = dict_new();
    global->token2info = 0;
    global->classinit = abc_initscript(global->file);
}
예제 #16
0
파일: time.c 프로젝트: xupingmao/minipy
void time_mod_init() {
    Object time_mod = dict_new();
    reg_mod_func(time_mod, "time",  bf_time_time);
    reg_mod_func(time_mod, "clock", bf_time_clock);
    reg_mod_func(time_mod, "ctime", bf_time_ctime);
    reg_mod_func(time_mod, "sleep", bf_time_sleep);
    reg_mod_func(time_mod, "asctime", bf_time_asctime);
    dict_set_by_str(tm->modules, "time", time_mod);
}
예제 #17
0
int
cli_cmd_volume_rename_cbk (struct cli_state *state, struct cli_cmd_word *word,
                           const char **words, int wordcount)
{
        int                     ret = -1;
        rpc_clnt_procedure_t    *proc = NULL;
        call_frame_t            *frame = NULL;
        dict_t                  *dict = NULL;
        int                     sent = 0;
        int                     parse_error = 0;


        frame = create_frame (THIS, THIS->ctx->pool);
        if (!frame)
                goto out;

        dict = dict_new ();
        if (!dict)
                goto out;

        if (wordcount != 4) {
                cli_usage_out (word->pattern);
                parse_error = 1;
                goto out;
        }

        ret = dict_set_str (dict, "old-volname", (char *)words[2]);

        if (ret)
                goto out;

        ret = dict_set_str (dict, "new-volname", (char *)words[3]);

        if (ret)
                goto out;

        proc = &cli_rpc_prog->proctable[GLUSTER_CLI_RENAME_VOLUME];

        if (proc->fn) {
                ret = proc->fn (frame, THIS, dict);
        }

out:
        if (dict)
                dict_destroy (dict);

        if (ret) {
                cli_cmd_sent_status_get (&sent);
                if ((sent == 0) && (parse_error == 0))
                        cli_out ("Volume rename on '%s' failed", (char *)words[2]);
        }

        return ret;
}
예제 #18
0
파일: os.c 프로젝트: xupingmao/minipy
void os_mod_init() {
    Object os_mod = dict_new();
    dict_set_by_str(tm->modules, "os", os_mod);
    reg_mod_func(os_mod, "getcwd",  os_getcwd);
    reg_mod_func(os_mod, "listdir", os_listdir);
    reg_mod_func(os_mod, "chdir",   os_chdir);
    reg_mod_func(os_mod, "stat",    os_stat);
    reg_mod_func(os_mod, "exists",  os_exists);
    
    reg_builtin_func("exists", os_exists);
}
예제 #19
0
const char*register_string(const char*s)
{
    if(!stringpool) {
        stringpool = dict_new(&charptr_type);
    }
    char*stored_string = dict_lookup(stringpool, s);
    if(!stored_string) {
        stored_string = (char*)strdup(s);
        dict_put(stringpool, s, stored_string);
    }
    return stored_string;
}
예제 #20
0
int32_t
cli_cmd_log_locate_parse (const char **words, int wordcount, dict_t **options)
{
        dict_t  *dict = NULL;
        char    *volname = NULL;
        char    *str = NULL;
        int     ret = -1;
        char    *delimiter = NULL;

        GF_ASSERT (words);
        GF_ASSERT (options);

        GF_ASSERT ((strcmp (words[0], "volume")) == 0);
        GF_ASSERT ((strcmp (words[1], "log")) == 0);
        GF_ASSERT ((strcmp (words[2], "locate")) == 0);

        dict = dict_new ();
        if (!dict)
                goto out;

        volname = (char *)words[3];
        GF_ASSERT (volname);

        ret = dict_set_str (dict, "volname", volname);
        if (ret)
                goto out;

        if (words[4]) {
                delimiter = strchr (words[4], ':');
                if (!delimiter || delimiter == words[4]
                    || *(delimiter+1) != '/') {
                        cli_out ("wrong brick type: %s, use <HOSTNAME>:"
                                 "<export-dir-abs-path>", words[4]);
                        ret = -1;
                        goto out;
                } else {
                        cli_path_strip_trailing_slashes (delimiter + 1);
                }
                str = (char *)words[4];
                ret = dict_set_str (dict, "brick", str);
                if (ret)
                        goto out;
        }

        *options = dict;

out:
        if (ret && dict)
                dict_destroy (dict);

        return ret;
}
예제 #21
0
ini_t *ini_add(ini_t * self, char *section)
{
	assert(self && section);

	strlower(section);

	if (dict_get(self->sections, section))
		return self;

	dict_add(self->sections, section, dict_new());

	return self;
}
예제 #22
0
파일: dict.c 프로젝트: nrhtr/genesis-1
cDict *dict_new_empty(void)
{
    if (!generic_empty_dict) {
        cList *l1, *l2;

        l1 = list_new(0);
        l2 = list_new(0);
        generic_empty_dict = dict_new(l1, l2);
        list_discard(l1);
        list_discard(l2);
    }

    return dict_dup(generic_empty_dict);
}
예제 #23
0
파일: libxlator.c 프로젝트: 2510/glusterfs
static void
cluster_marker_unwind (call_frame_t *frame, char *key, void *value, size_t size,
                       dict_t *dict)
{
    xl_marker_local_t *local   = frame->local;
    int               ret      = 0;
    int32_t           op_ret   = 0;
    int32_t           op_errno = 0;
    gf_boolean_t      unref    = _gf_false;

    frame->local = local->xl_local;

    if (local->count[MCNT_FOUND]) {
        if (!dict) {
            dict = dict_new();
            if (dict) {
                unref = _gf_true;
            } else {
                op_ret = -1;
                op_errno = ENOMEM;
                goto out;
            }
        }

        ret = dict_set_static_bin (dict, key, value, size);
        if (ret) {
            op_ret = -1;
            op_errno = ENOMEM;
            goto out;
        }
    }

    op_errno = evaluate_marker_results (local->gauge, local->count);
    if (op_errno)
        op_ret = -1;

out:
    if (local->xl_specf_unwind) {
        local->xl_specf_unwind (frame, op_ret,
                                op_errno, dict, NULL);
    } else {
        STACK_UNWIND_STRICT (getxattr, frame, op_ret, op_errno,
                             dict, NULL);
    }

    GF_FREE (local);
    if (unref)
        dict_unref (dict);

}
예제 #24
0
/**
 * Test dict_new():
 *      retval is OK
 *      obj pointer is not C_NULL
 *      obj type must be DICT
 *      obj const bit must be clear
 *      dict length must be 0
 */
void
ut_dict_new_000(CuTest* tc)
{
    uint8_t heap[HEAP_SIZE];
    pPmObj_t pobj = C_NULL;
    PmReturn_t retval;

    retval = pm_init(heap, HEAP_SIZE, MEMSPACE_RAM, C_NULL);
    retval = dict_new(&pobj);

    CuAssertTrue(tc, retval == PM_RET_OK);
    CuAssertPtrNotNull(tc, pobj);
    CuAssertTrue(tc, OBJ_GET_TYPE(pobj) == OBJ_TYPE_DIC);
    CuAssertTrue(tc, ((pPmDict_t)pobj)->length == 0);
}
예제 #25
0
파일: state.c 프로젝트: DJwa163/swftools
void new_state()
{
    NEW(state_t, s);
    state_t*oldstate = state;
    if(state)
        memcpy(s, state, sizeof(state_t)); //shallow copy
    if(!s->imports) {
        s->imports = dict_new();
    }
    if(!s->import_toplevel_packages) {
        s->import_toplevel_packages = dict_new(); 
    }
    state = s;
    state->level++;
    state->has_own_imports = 0;    
    state->vars = dict_new(); 
    state->old = oldstate;
    state->new_vars = 0;

    state->namespaces = dict_new();
   
    if(oldstate)
        state->active_namespace_urls = list_clone(oldstate->active_namespace_urls);
}
예제 #26
0
/**
 * auth_cache_purge -- Purge the dict in the cache and create a new empty one.
 *
 * @cache: Cache to purge
 *
 */
void
auth_cache_purge (struct auth_cache *cache)
{
        dict_t *new_cache_dict = dict_new ();
        dict_t *old_cache_dict = cache->cache_dict;

        if (!cache)
                goto out;

        (void)__sync_lock_test_and_set (&cache->cache_dict, new_cache_dict);

        dict_unref (old_cache_dict);
out:
        return;
}
예제 #27
0
파일: ecma48.c 프로젝트: else/xelix
console_filter_t *console_filter_ecma48_init(console_filter_t *filter)
{
	if (buffer_dictionary == NULL)
		buffer_dictionary = dict_new();

	if (filter == NULL)
		filter = (console_filter_t *)kmalloc(sizeof(console_filter_t));

	filter->callback = NULL;
	filter->read_callback = NULL;
	filter->write_callback = console_filter_ecma48_writeCallback;

	filter->next = NULL;

	return filter;
}
예제 #28
0
/**
 * Test dict_setItem():
 *      Pass valid vals; expect retval is OK
 *      Pass valid vals, return dict must not be NULL
 *      Pass valid vals, return dict must be same addr
 */
void
ut_dict_setItem_000(CuTest* tc)
{
    uint8_t heap[HEAP_SIZE];
    pPmObj_t pobj = C_NULL;
    pPmObj_t pobj_orig;
    PmReturn_t retval;

    retval = pm_init(heap, HEAP_SIZE, MEMSPACE_RAM, C_NULL);
    retval = dict_new(&pobj);
    pobj_orig = pobj;

    retval = dict_setItem(pobj, PM_ZERO, PM_ONE);
    CuAssertTrue(tc, retval == PM_RET_OK);
    CuAssertPtrNotNull(tc, pobj);
    CuAssertPtrEquals(tc, pobj_orig, pobj);
}
예제 #29
0
int
cli_cmd_uuid_get_cbk (struct cli_state *state, struct cli_cmd_word *word,
                      const char **words, int wordcount)
{
        int                     ret = -1;
        int                     sent = 0;
        int                     parse_error = 0;
        dict_t                  *dict  = NULL;
        rpc_clnt_procedure_t    *proc = NULL;
        call_frame_t            *frame = NULL;
        cli_local_t             *local = NULL;
        xlator_t                *this  = NULL;

        this = THIS;
        if (wordcount != 3) {
                cli_usage_out (word->pattern);
                parse_error = 1;
                goto out;
        }

        proc = &cli_rpc_prog->proctable[GLUSTER_CLI_UUID_GET];
        frame = create_frame (this, this->ctx->pool);
        if (!frame)
                goto out;

        dict = dict_new ();
        if (!dict)
                goto out;

        CLI_LOCAL_INIT (local, words, frame, dict);
        if (proc->fn)
                ret = proc->fn (frame, this, dict);

out:
        if (ret) {
                cli_cmd_sent_status_get (&sent);
                if ((sent == 0) && (parse_error == 0))
                        cli_out ("uuid get failed");
        }

        if (dict)
                dict_unref (dict);

        CLI_STACK_DESTROY (frame);
        return ret;
}
예제 #30
0
/**
 * Clone dict object, using key_clone_fn and value_clone_fn, function pointers.
 *
 * If the clone function pointer for key/value is NULL, then it will simply do a
 * static copy of the pointer. Doing this on heap allocated memory may lead to
 * memory errors.
 *
 * @param   struct dict *to_clone
 * @param   void *(*key_clone_fn)(void *)
 * @param   void *(*value_clone_fn)(void *)
 * @return  struct dict *
 *
 * Returns NULL on error.
 **/
struct dict *dict_clone(struct dict *to_clone, void *(*key_clone_fn)(void *), void *(*value_clone_fn)(void *))
{
    size_t i;
    void *key_clone;
    void *value_clone;
    struct dict_node *cur;
    struct dict *clone = dict_new(
        to_clone->seed,
        to_clone->capacity,
        to_clone->key_free_fn,
        to_clone->value_free_fn
    );
    
    if (clone == NULL) {
        return NULL;
    }
    
    if (key_clone_fn == NULL) {
        key_clone_fn = _dummy_clone_fn;
    }

    if (value_clone_fn == NULL) {
        value_clone_fn = _dummy_clone_fn;
    }
    
    for (i = 0; i < to_clone->capacity; i++) {
        cur = &to_clone->table[i];
        while (cur && cur->key) {
            key_clone = key_clone_fn(cur->key);
            value_clone = value_clone_fn(cur->value);
        
            if (dict_set(clone, key_clone, value_clone) == 0) {
                // Make sure key/value gets freed
                clone->key_free_fn(key_clone);
                clone->value_free_fn(value_clone);
                
                dict_delete(clone);
                return NULL;
            }
            
            cur = cur->next;
        }
    }
    
    return clone;
}