コード例 #1
0
ファイル: poly.c プロジェクト: ggjjlldd/swftools
char gfxpoly_check(gfxpoly_t*poly)
{
    dict_t*d = dict_new2(&point_type);
    int s,t;
    gfxpolystroke_t*stroke = poly->strokes;
    for(;stroke;stroke=stroke->next) {
	for(s=0;s<stroke->num_points;s++) {
	    point_t p = stroke->points[s];
	    int num = (s>=1 && s<stroke->num_points-1)?2:1; // mid points are two points (start+end)
	    if(!dict_contains(d, &p)) {
		dict_put(d, &p, (void*)(ptroff_t)num);
	    } else {
		int count = (ptroff_t)dict_lookup(d, &p);
		dict_del(d, &p);
		count+=num;
		dict_put(d, &p, (void*)(ptroff_t)count);
	    }
	}
    }
    DICT_ITERATE_ITEMS(d, point_t*, p, void*, c) {
        int count = (ptroff_t)c;
        if(count&1) {
            fprintf(stderr, "Point (%f,%f) occurs %d times\n", p->x*poly->gridsize, p->y*poly->gridsize, count);
            dict_destroy(d);
            return 0;
        }
    }
コード例 #2
0
ファイル: parser_help.c プロジェクト: DJwa163/swftools
void initialize_file(char*filename)
{
    if(state) {
        syntaxerror("invalid call to initialize_file during parsing of another file");
    }
    
    new_state();
    state->package = internal_filename_package = strdup(filename);
    
    global->token2info = dict_lookup(global->file2token2info, 
                                     current_filename // use long version
                                    );
    if(!global->token2info) {
        global->token2info = dict_new2(&ptr_type);
        dict_put(global->file2token2info, current_filename, global->token2info);
    }
  
    if(as3_pass==1) {
        state->method = rfx_calloc(sizeof(methodstate_t));
        dict_put(global->token2info, (void*)(ptroff_t)as3_tokencount, state->method);
        state->method->late_binding = 1; // init scripts use getglobalscope, so we need a getlocal0/pushscope
	state->method->allvars = dict_new();
    } else {
        state->method = dict_lookup(global->token2info, (void*)(ptroff_t)as3_tokencount);
        state->method->variable_count = 0;
        if(!state->method)
            syntaxerror("internal error: skewed tokencount");
        function_initvars(state->method, 0, 0, 0, 1);
        global->init = 0;
    }
}
コード例 #3
0
ファイル: common.c プロジェクト: dyzz/hdldumb
void
set_config_defaults (dict_t *config)
{
  char disc_database[256], *p;

#if defined (_BUILD_WIN32)
  /* disable ASPI by default */
  dict_put_flag (config, CONFIG_ENABLE_ASPI_FLAG, 0);
#endif

  /* decide where disc compatibility database would be kept */
  strcpy (disc_database, "./hdl_dump.list"); /* default */
#if defined (_BUILD_WIN32) && !defined (_BUILD_WINE)
  p = getenv ("USERPROFILE");
  if (p != NULL)
    {
      strcpy (disc_database, p);
      strcat (disc_database, "\\Application Data\\hdl_dump.list");
    }
#else
  /* Unix/Linux/WineLib */
  p = getenv ("HOME");
  if (p != NULL)
    {
      strcpy (disc_database, p);
      strcat (disc_database, "/.hdl_dump.list");
    }
#endif
  (void) dict_put (config, CONFIG_DISC_DATABASE_FILE, disc_database);

  (void) dict_put (config, CONFIG_TARGET_KBPS, "2300");
  (void) dict_put (config, CONFIG_AUTO_THROTTLE, "0");
}
コード例 #4
0
ファイル: cpp.c プロジェクト: rui314/8cc-old
/*
 * Reads function-like macro arguments.  Returns true if the argument list ends
 * with "...".  Otherwise false.
 */
static bool read_funclike_define_args(CppContext *ctx, Dict *param) {
    for (;;) {
        Token *tok = read_cpp_token(ctx);
        if (is_punct(tok, ')'))
            return false;
        if (dict_size(param)) {
            if (!is_punct(tok, ','))
                error_token(tok, "',' expected, but got '%s'", token_to_string(tok));
            tok = read_cpp_token(ctx);
        }
        if (!tok || tok->toktype == TOKTYPE_NEWLINE)
            error_token(tok, "missing ')' in macro parameter list");
        if (is_punct(tok, KEYWORD_THREEDOTS)) {
            Token *subst = make_token(ctx, TOKTYPE_MACRO_PARAM, (TokenValue)dict_size(param));
            dict_put(param, to_string("__VA_ARGS__"), subst);
            Token *tok1 = read_cpp_token(ctx);
            if (!is_punct(tok1, ')'))
                error_token(tok1, "')' expected, but got '%s'", token_to_string(tok1));
            return true;
        }
        if (tok->toktype != TOKTYPE_IDENT)
            error_token(tok, "identifier expected, but got '%s'", token_to_string(tok));
        Token *subst = make_token(ctx, TOKTYPE_MACRO_PARAM, (TokenValue)dict_size(param));
        dict_put(param, tok->val.str, subst);
    }
}
コード例 #5
0
ファイル: utiltest.c プロジェクト: shin1hi/8cc
static void test_dict(void) {
    Dict *dict = make_dict();
    assert_null(dict_get(dict, "abc"));
    dict_put(dict, "abc", (void *)50);
    dict_put(dict, "xyz", (void *)70);
    assert_int(50, (long)dict_get(dict, "abc"));
    assert_int(70, (long)dict_get(dict, "xyz"));
    assert_int(2, list_len(dict_keys(dict)));
}
コード例 #6
0
ファイル: cfg.c プロジェクト: LeeVidor/kannel-mongodb
static int add_group(Cfg *cfg, CfgGroup *grp)
{
    Octstr *groupname;
    Octstr *name;
    List *names;
    List *list;
    
    groupname = cfg_get(grp, octstr_imm("group"));
    if (groupname == NULL) {
        error(0, "Group does not contain variable 'group'.");
        return -1;
    }
    set_group_name(grp, groupname);

    names = dict_keys(grp->vars);

    while ((name = gwlist_extract_first(names)) != NULL) {
        int a = is_allowed_in_group(groupname, name);
        switch (a) {
            case 0:
                error(0, "Group '%s' may not contain field '%s'.",
                      octstr_get_cstr(groupname), octstr_get_cstr(name));
                octstr_destroy(name);
                octstr_destroy(groupname);
                gwlist_destroy(names, octstr_destroy_item);
                return -1;
                break;
            case -1:
                error(0, "Group '%s' is no valid group identifier.",
                      octstr_get_cstr(groupname));
                octstr_destroy(name);
                octstr_destroy(groupname);
                gwlist_destroy(names, octstr_destroy_item);
                return -1;
                break;
            default:
                octstr_destroy(name);
                break;
        }
    }
    gwlist_destroy(names, NULL);

    if (is_single_group(groupname)) {
        dict_put(cfg->single_groups, groupname, grp);
    } else {
        list = dict_get(cfg->multi_groups, groupname);
        if (list == NULL) {
            list = gwlist_create();
            dict_put(cfg->multi_groups, groupname, list);
        }
        gwlist_append(list, grp);
    }

    octstr_destroy(groupname);
    return 0;
}
コード例 #7
0
ファイル: common.c プロジェクト: dyzz/hdldumb
int
ddb_update (const dict_t *config,
	    const char *startup,
	    const char *name,
	    compat_flags_t flags)
{
  int result = RET_OK;
  const char *disc_db = dict_lookup (config, CONFIG_DISC_DATABASE_FILE);
  dict_t *list = dict_restore (NULL, disc_db);
  if (list != NULL)
    {
      char tmp[500];
      compat_flags_t dummy;
      result = ddb_lookup (config, startup, tmp, &dummy);
      if (result != RET_DDB_INCOMPATIBLE)
	{ /* do not overwrite entries, marked as incompatible */
	  sprintf (tmp, "%s;0x%02x", name, flags);
	  (void) dict_put (list, startup, tmp);

	  result = dict_store (list, disc_db);
	}
      dict_free (list), list = NULL;
    }
  else
    result = RET_NO_DISC_DB;
  return (result);
}
コード例 #8
0
ファイル: test_dict.c プロジェクト: silkentrance/nss-pam-ldap
/* Test to insert a large number of elements in the dict. */
static void test_readelements(const char *fname)
{
  DICT *dict;
  char buf[80];
  FILE *fp;
  void *val;
  const char **keys;
  int i;
  /* initialize */
  dict=dict_new();
  /* read file and insert all entries */
  fp=fopen(fname,"r");
  assert(fp!=NULL);
  while (fgets(buf,sizeof(buf),fp)!=NULL)
  {
    /* strip newline */
    buf[strlen(buf)-1]='\0';
    dict_put(dict,buf,&buf);
  }
  fclose(fp);
  /* loop over dictionary contents */
  keys=dict_keys(dict);
  for (i=0;keys[i]!=NULL;i++)
  {
    val=dict_get(dict,keys[i]);
    assert(val==buf);
  }
  /* free stuff */
  dict_free(dict);
  free(keys);
}
コード例 #9
0
ファイル: brunet.c プロジェクト: tphipps/kannel
/*
 * Parse a line in the format: <name=value name=value ...>
 * and return a Dict with the name as key and the value as value,
 * otherwise return NULL if a parsing error occures.
 */
static Dict *brunet_parse_body(Octstr *body)
{
    Dict *param = NULL;
    List *words = NULL;
    long len;
    Octstr *word;

    words = octstr_split_words(body);
    if ((len = gwlist_len(words)) > 0) {
        param = dict_create(4, (void(*)(void *)) octstr_destroy);
        while ((word = gwlist_extract_first(words)) != NULL) {
            List *l = octstr_split(word, octstr_imm("="));
            Octstr *key = gwlist_extract_first(l);
            Octstr *value = gwlist_extract_first(l);
            if (octstr_len(key))
                dict_put(param, key, value);
            octstr_destroy(key);
            octstr_destroy(word);
            gwlist_destroy(l, (void(*)(void *)) octstr_destroy);
        }
    }
    gwlist_destroy(words, (void(*)(void *)) octstr_destroy);

    return param;
}
コード例 #10
0
ファイル: mkmap_open.c プロジェクト: ajinkya93/netbsd-src
void    mkmap_append(MKMAP *mkmap, const char *key, const char *value)
{
    DICT   *dict = mkmap->dict;

    if (dict_put(dict, key, value) != 0 && dict->error != 0)
	msg_fatal("%s:%s: update failed", dict->type, dict->name);
}
コード例 #11
0
ファイル: parser_help.c プロジェクト: DJwa163/swftools
void unknown_variable(char*name) 
{
    if(!state->method->unresolved_variables)
        state->method->unresolved_variables = dict_new();
    if(!dict_contains(state->method->unresolved_variables, name))
        dict_put(state->method->unresolved_variables, name, 0);
}
コード例 #12
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);
}
コード例 #13
0
/* Implementation for getting parameters to a dictionary. */
static int
dict_param_write(iparam_list * plist, const ref * pkey, const ref * pvalue)
{
    int code =
	dict_put(&((dict_param_list *) plist)->dict, pkey, pvalue, NULL);

    return min(code, 0);
}
コード例 #14
0
ファイル: test_dict.c プロジェクト: armic/erpts
int main(void)
{
    Dict *dict;
    Octstr *foo, *bar;
    unsigned long i;

    gwlib_init();

    foo = octstr_imm("foo");
    bar = octstr_imm("bar");

    debug("",0,"Dict simple test.");
    dict = dict_create(10, NULL);
    dict_put(dict, foo, bar);
    info(0, "foo gives %s", octstr_get_cstr(dict_get(dict, foo)));
    if (dict_key_count(dict) == 1)
        info(0, "there is but one foo.");
    else
        error(0, "key count is %ld, should be 1.", dict_key_count(dict));
    dict_destroy(dict);

    debug("",0,"Dict extended/huge test.");
    dict = dict_create(HUGE_SIZE, (void (*)(void *))octstr_destroy);
    for (i = 1; i <= HUGE_SIZE; i++) {
        unsigned long val;
        Octstr *okey, *oval;
        uuid_t id;
        char key[UUID_STR_LEN + 1];
        uuid_generate(id);
        uuid_unparse(id, key);
        val = gw_rand();
        okey = octstr_create(key);
        oval = octstr_format("%ld", val);
        dict_put(dict, okey, oval);
    }
    gwthread_sleep(5); /* give hash table some time */
    if (dict_key_count(dict) == HUGE_SIZE)
        info(0, "ok, got %d entries in the dictionary.", HUGE_SIZE);
    else
        error(0, "key count is %ld, should be %d.", dict_key_count(dict), HUGE_SIZE);
    dict_destroy(dict);

    gwlib_shutdown();
    return 0;
}
コード例 #15
0
ファイル: urltrans.c プロジェクト: armic/erpts
int urltrans_add_one(URLTranslationList *trans, CfgGroup *grp)
{
    URLTranslation *ot;
    long i;
    List *list, *list2;
    Octstr *alias;
    
    ot = create_onetrans(grp);
    if (ot == NULL)
	return -1;
		
    list_append(trans->list, ot);
    
    list2 = dict_get(trans->names, ot->name);
    if (list2 == NULL) {
    	list2 = list_create();
	dict_put(trans->names, ot->name, list2);
    }
    list_append(list2, ot);

    if (ot->keyword == NULL || ot->type == TRANSTYPE_SENDSMS)
    	return 0;

    list = dict_get(trans->dict, ot->keyword);
    if (list == NULL) {
    	list = list_create();
	dict_put(trans->dict, ot->keyword, list);
    }
    list_append(list, ot);

    for (i = 0; i < list_len(ot->aliases); ++i) {
	alias = list_get(ot->aliases, i);
	list = dict_get(trans->dict, alias);
	if (list == NULL) {
	    list = list_create();
	    dict_put(trans->dict, alias, list);
	}
	list_append(list, ot);
    }


    return 0;
}
コード例 #16
0
ファイル: datacache.c プロジェクト: JackieXie168/mrscake
void datacache_store(datacache_t*cache, dataset_t*dataset)
{
    dict_put(cache->dict, dataset->hash, dataset);

    char*filename = dataset_filename(dataset->hash);
    struct stat sb;
    if(stat(filename, &sb)!=0) {
        dataset_save(dataset, filename);
    }
}
コード例 #17
0
ファイル: test_dict.c プロジェクト: silkentrance/nss-pam-ldap
/* Simple test that adds a few key/value pairs to the dict and the does
   most operations. */
static void test_simple(void)
{
  DICT *dict;
  void *val;
  static char *value1="value1";
  static char *value2="value2";
  static char *replace2="replace2";
  const char **keys;
  int i;
  /* initialize */
  dict=dict_new();
  /* store some entries */
  dict_put(dict,"key1",value1);
  dict_put(dict,"key2",value2);
  dict_put(dict,"key3",dict);
  dict_put(dict,"key2",replace2);
  /* check dictionary contents */
  val=dict_get(dict,"key1");
  assert(val==value1);
  val=dict_get(dict,"key2");
  assert(val==replace2);
  val=dict_get(dict,"key3");
  assert(val==dict);
  val=dict_get(dict,"key4");
  assert(val==NULL);
  val=dict_get(dict,"KEY1");
  assert(val==NULL);
  /* remove a key */
  dict_put(dict,"key3",NULL);
  val=dict_get(dict,"key3");
  assert(val==NULL);
  /* loop over dictionary contents */
  keys=dict_keys(dict);
  for (i=0;keys[i]!=NULL;i++)
  {
    val=dict_get(dict,keys[i]);
    assert(((val==value1)||(val==replace2)));
  }
  /* free stuff */
  dict_free(dict);
  free(keys);
}
コード例 #18
0
ファイル: test_dict.c プロジェクト: silkentrance/nss-pam-ldap
/* Test to insert a large number of elements in the dict. */
static void test_lotsofelements(void)
{
  DICT *dict;
  char buf[80];
  int i,r;
  void *val;
  const char **keys;
  /* initialize */
  dict=dict_new();
  /* insert a number of entries */
  for (i=0;i<1024;i++)
  {
    r=1+(int)(10000.0*(rand()/(RAND_MAX+1.0)));
    sprintf(buf,"test%04d",r);
    dict_put(dict,buf,&buf);
  }
  /* remove a number of entries */
  for (i=0;i<100;i++)
  {
    r=1+(int)(10000.0*(rand()/(RAND_MAX+1.0)));
    sprintf(buf,"test%04d",r);
    dict_put(dict,buf,NULL);
  }
  /* add some more entries */
  for (i=0;i<1024;i++)
  {
    r=1+(int)(10000.0*(rand()/(RAND_MAX+1.0)));
    sprintf(buf,"test%04d",r);
    dict_put(dict,buf,&buf);
  }
  /* loop over dictionary contents */
  keys=dict_keys(dict);
  for (i=0;keys[i]!=NULL;i++)
  {
    val=dict_get(dict,keys[i]);
    assert(val==buf);
  }
  /* free stuff */
  dict_free(dict);
  free(keys);
}
コード例 #19
0
ファイル: stringpool.c プロジェクト: bakineggs/mrscake
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
ファイル: tr.c プロジェクト: litcave/neatroff
void cmap_add(char *c1, char *c2)
{
	int i = dict_get(cmap, c1);
	if (i >= 0) {
		strcpy(cmap_dst[i], c2);
	} else if (cmap_n < NCMAPS) {
		strcpy(cmap_src[cmap_n], c1);
		strcpy(cmap_dst[cmap_n], c2);
		dict_put(cmap, cmap_src[cmap_n], cmap_n);
		cmap_n++;
	}
}
コード例 #21
0
ファイル: hyph.c プロジェクト: litcave/neatroff
static void hcode_add(char *c1, char *c2)
{
	int i = dict_get(hcodedict, c1);
	if (i >= 0) {
		strcpy(hcodedst[i], c2);
	} else if (hcode_n < NHCODES) {
		strcpy(hcodesrc[hcode_n], c1);
		strcpy(hcodedst[hcode_n], c2);
		dict_put(hcodedict, hcodesrc[hcode_n], hcode_n);
		hcode_n++;
	}
}
コード例 #22
0
ファイル: idict.c プロジェクト: computersforpeace/ghostpdl
/*
 * Enter a key-value pair where the key is a (constant) C string.
 */
int
dict_put_string(ref * pdref, const char *kstr, const ref * pvalue,
                dict_stack_t *pds)
{
    int code;
    ref kname;
    dict *pdict = pdref->value.pdict;

    if ((code = name_ref(dict_mem(pdict),
                         (const byte *)kstr, strlen(kstr), &kname, 0)) < 0)
        return code;
    return dict_put(pdref, &kname, pvalue, pds);
}
コード例 #23
0
ファイル: proxymap.c プロジェクト: KKcorps/postfix
static void proxymap_update_service(VSTREAM *client_stream)
{
    int     request_flags;
    DICT   *dict;
    int     dict_status;
    int     reply_status;

    /*
     * Process the request.
     *
     * XXX We don't close maps, so we must turn on synchronous update to ensure
     * that the on-disk data is in a consistent state between updates.
     *
     * XXX We ignore duplicates, because the proxymap server would abort
     * otherwise.
     */
    if (attr_scan(client_stream, ATTR_FLAG_STRICT,
                  ATTR_TYPE_STR, MAIL_ATTR_TABLE, request_map,
                  ATTR_TYPE_INT, MAIL_ATTR_FLAGS, &request_flags,
                  ATTR_TYPE_STR, MAIL_ATTR_KEY, request_key,
                  ATTR_TYPE_STR, MAIL_ATTR_VALUE, request_value,
                  ATTR_TYPE_END) != 4) {
        reply_status = PROXY_STAT_BAD;
    } else if (proxy_writer == 0) {
        msg_warn("refusing %s update request on non-%s service",
                 STR(request_map), MAIL_SERVICE_PROXYWRITE);
        reply_status = PROXY_STAT_DENY;
    } else if ((dict = proxy_map_find(STR(request_map), request_flags,
                                      &reply_status)) == 0) {
        /* void */ ;
    } else {
        dict->flags = ((dict->flags & ~DICT_FLAG_RQST_MASK)
                       | (request_flags & DICT_FLAG_RQST_MASK)
                       | DICT_FLAG_SYNC_UPDATE | DICT_FLAG_DUP_REPLACE);
        dict_status = dict_put(dict, STR(request_key), STR(request_value));
        if (dict_status == 0) {
            reply_status = PROXY_STAT_OK;
        } else if (dict->error == 0) {
            reply_status = PROXY_STAT_NOKEY;
        } else {
            reply_status = PROXY_STAT_RETRY;
        }
    }

    /*
     * Respond to the client.
     */
    attr_print(client_stream, ATTR_FLAG_NONE,
               ATTR_TYPE_INT, MAIL_ATTR_STATUS, reply_status,
               ATTR_TYPE_END);
}
コード例 #24
0
ファイル: wap-maps.c プロジェクト: tphipps/kannel
void wap_map_add_user(Octstr *name, Octstr *user, Octstr *pass,
                      Octstr *msisdn) {
    struct user_map_struct *entry;

    if (user_map == NULL) 
        user_map = dict_create(32, wap_user_map_destroy);

    entry = gw_malloc(sizeof(*entry));
    entry->name = name;
    entry->user = user;
    entry->pass = pass;
    entry->msisdn = msisdn;
    dict_put(user_map, entry->user, entry);
}
コード例 #25
0
ファイル: bb_boxc.c プロジェクト: Phonebooth/kannel
static void boxc_sent_push(Boxc *conn, Msg *m)
{
    Octstr *os;
    char id[UUID_STR_LEN + 1];
    
    if (conn->is_wap || !conn->sent || !m || msg_type(m) != sms)
        return;
    
    uuid_unparse(m->sms.id, id);
    os = octstr_create(id);
    dict_put(conn->sent, os, msg_duplicate(m));
    semaphore_down(conn->pending);
    octstr_destroy(os);
}
コード例 #26
0
ファイル: parser_help.c プロジェクト: DJwa163/swftools
variable_t* new_variable2(methodstate_t*method, const char*name, classinfo_t*type, char init, char maybeslot)
{
    if(maybeslot) {
        variable_t*v = find_slot(method, name);
        if(v) {
            alloc_local(); 
            return v;
        }
    }

    NEW(variable_t, v);
    v->type = type;
    v->init = v->kill = init;
 
    if(name) {
        if(!method->no_variable_scoping) {
            if(dict_contains(state->vars, name)) {
                syntaxerror("variable %s already defined", name);
            }
	    v->index = alloc_local();
            dict_put(state->vars, name, v);
        } else {
	    if(as3_pass==2 && dict_contains(state->method->allvars, name)) {
		variable_t*v = dict_lookup(state->method->allvars, name);
		if(v->type != type && (!v->type || v->type->kind!=INFOTYPE_UNRESOLVED)) {
		    syntaxerror("variable %s already defined.", name);
		}
		return v;
	    }
	    v->index = alloc_local();
	}
        dict_put(state->method->allvars, name, v);
    } else {
	v->index = alloc_local();
    }
    return v;
}
コード例 #27
0
void    smtp_sasl_auth_cache_store(SMTP_SASL_AUTH_CACHE *auth_cache,
				           const SMTP_SESSION *session,
				           const SMTP_RESP *resp)
{
    char   *key;
    char   *value;

    key = smtp_sasl_auth_cache_make_key(session->host, session->sasl_username);
    value = smtp_sasl_auth_cache_make_value(session->sasl_passwd,
					    resp->dsn, resp->str);
    dict_put(auth_cache->dict, key, value);

    myfree(value);
    myfree(key);
}
コード例 #28
0
ファイル: idict.c プロジェクト: computersforpeace/ghostpdl
static int
dict_copy_elements(const ref * pdrfrom /* t_dictionary */ ,
                  ref * pdrto /* t_dictionary */ , int options,
                  dict_stack_t *pds)
{
    int space = r_space(pdrto);
    int index;
    ref elt[2];
    ref *pvslot;
    int code;

    if (space != avm_max) {
        /* Do the store check before starting the copy. */
        index = dict_first(pdrfrom);
        while ((index = dict_next(pdrfrom, index, elt)) >= 0)
            if (!(options & COPY_NEW_ONLY) ||
                dict_find(pdrto, &elt[0], &pvslot) <= 0
                ) {
                store_check_space(space, &elt[0]);
                store_check_space(space, &elt[1]);
            }
    }
    /* Now copy the contents. */
    index = dict_first(pdrfrom);
    while ((index = dict_next(pdrfrom, index, elt)) >= 0) {
        ref *pvalue = pv_no_defn;

        if ((options & COPY_NEW_ONLY) &&
            dict_find(pdrto, &elt[0], &pvslot) > 0
            )
            continue;
        if ((options & COPY_FOR_RESIZE) &&
            r_has_type(&elt[0], t_name) &&
            (pvalue = elt[0].value.pname->pvalue, pv_valid(pvalue))
            )
            elt[0].value.pname->pvalue = pv_no_defn;
        if ((code = dict_put(pdrto, &elt[0], &elt[1], pds)) < 0) {
            /*
             * If COPY_FOR_RESIZE is set, the dict_put isn't supposed to
             * be able to fail, but we don't want to depend on this.
             */
            if (pvalue != pv_no_defn)
                elt[0].value.pname->pvalue = pvalue;
            return code;
        }
    }
    return 0;
}
コード例 #29
0
ファイル: smpp_listener.c プロジェクト: kneodev/ksmppd
 void smpp_listener_auth_failed(SMPPServer *smpp_server, Octstr *ip) {
    if (octstr_len(smpp_server->ip_blocklist_exempt_ips) && (octstr_search(smpp_server->ip_blocklist_exempt_ips, ip, 0) > -1)) {
       debug("smpp.listener.auth.failed", 0, "IP address %s is exempt from the IP block list", octstr_get_cstr(ip));
       return;
    }
    gw_rwlock_wrlock(smpp_server->ip_blocklist_lock);
    SMPPBlockedIp *smpp_blocked_ip = dict_get(smpp_server->ip_blocklist, ip);
    if(smpp_blocked_ip == NULL) {
        smpp_blocked_ip = smpp_blocked_ip_create();
        dict_put(smpp_server->ip_blocklist, ip, smpp_blocked_ip);
    }
    smpp_blocked_ip->attempts++;
    smpp_blocked_ip->time_blocked = time(NULL);
    debug("smpp.listener.auth.failed", 0, "IP address %s, attempts %ld have failed", octstr_get_cstr(ip), smpp_blocked_ip->attempts);
    gw_rwlock_unlock(smpp_server->ip_blocklist_lock);
 }
コード例 #30
0
gfxfilterchain_t* gfxfilterchain_parse(const char*_filterexpr)
{
    char*filterexpr = strdup(_filterexpr);
    char*f = filterexpr;
    char*end = filterexpr+strlen(filterexpr);
    dict_t* params = dict_new2(&charptr_type);
    char*cmd = 0;

    gfxfilterchain_t*chain = 0;
    gfxfilterchain_t*next = 0;

    while(*f) {
	char* eq = strchr(f, '=');
	char* colon = strchr(f, ':');
	if(!colon) {
	    colon = end;
	}
	*colon = 0;

	if(eq && eq < colon) { // parameter
	    *eq = 0;
	    if(!cmd) {
		fprintf(stderr, "Error: need a filter before specifying parameters (%s=%s)\n", f, eq+1);
		return 0;
	    }
	    dict_put(params, f, strdup(eq+1));
	} else {
            if(cmd) {
                add_to_chain(cmd, params, &chain, &next);
                cmd = 0;
            }
            cmd = f;
        }
        if(colon == end)
            break;
	f = colon+1;
    }
    if(cmd) {
        add_to_chain(cmd, params, &chain, &next);
    }
    free(filterexpr);

    dict_destroy(params);
    return chain;
}