Ejemplo n.º 1
0
void *TA_DictGetValue_S2( TA_Dict *dict, const char *key1, const char *key2 )
{
   TA_PrivDictInfo *theDict;
   dnode_t *node;
   TA_PrivDictInfo *subDict;
   TA_Libc *libHandle;

   theDict = (TA_PrivDictInfo *)dict;

   if( (theDict == NULL) || (key1 == NULL) || (key2 == NULL))
      return NULL;
   libHandle = theDict->libHandle;

   /* Find the dictionary for key1. */
   node = dict_lookup( libHandle, &theDict->d, key1 );

   if( !node )
      return NULL;

   subDict = dnode_get(node);

   /* Find the key-value pair using key2. */
   node = dict_lookup( libHandle, &subDict->d, key2 );

   if( !node )
      return NULL;

   return dnode_get(node);
}
void history_processFlags(history_t* past)
// to be called after completely recording this history, before calculating any values.
{
    state_t* flagState = dict_lookup(past->states, "flags");
    state_t* nextState;
    U16 nextFlags, toggledFlags, currentFlags = (U16)flagState->value;
    while (flagState->next)
    {
    	nextState = flagState->next;
    	nextFlags = (U16)nextState->value;
    	toggledFlags = currentFlags ^ nextFlags;
    	if (toggledFlags & IF_FIXED_ALIGNMENT)
    	{ // the IF_FIXED_ALIGNMENT bit will change in the next state
    	    if (nextFlags & IF_FIXED_ALIGNMENT)
    	    { // the IF_FIXED_ALIGNMENT bit will be set
    	    	int onFrame = nextState->frame;
	    	state_t* rotations = dict_lookup(past->states, "rotate");
	    	nextState->params.instanceAngle = state_value(rotations, onFrame);
	    	state_t* resetRotate = state_new(onFrame, CF_JUMP, 0, 0);
	    	state_insert(rotations, resetRotate);
	    	if (onFrame == past->firstFrame)
	    	    onFrame++;
	    	state_t *x, *y;
	    	float dx, dy;
	    	do
	    	{
    	    	    x = dict_lookup(past->states, "x");
    	    	    dx = state_tangent(x, onFrame, T_SYMMETRIC);
    	    	    y = dict_lookup(past->states, "y");
    	    	    dy = state_tangent(y, onFrame, T_SYMMETRIC);
    	    	    onFrame++;
	    	}
	    	while (dx == 0 && dy == 0 && onFrame < past->lastFrame);
	    	if (onFrame == past->lastFrame)
    	    	    nextState->params.pathAngle = 0;
	    	else
    	    	    nextState->params.pathAngle = getAngle(dx, dy) / M_PI * 180;
    	    }
    	    else // the IF_FIXED_ALIGNMENT bit will be reset
    	    {
    	    	int offFrame = nextState->frame;
	    	state_t* rotations = dict_lookup(past->states, "rotate");
	    	state_t* setRotate = state_new(offFrame, CF_JUMP, flagState->params.instanceAngle + state_value(rotations, offFrame), 0);
	    	state_insert(rotations, setRotate);
    	    }
    	}
    	else // the IF_FIXED_ALIGNMENT bit will not change but some processing may be
    	     // required just the same
    	{
    	    if (nextFlags & IF_FIXED_ALIGNMENT)
    	    {
    	    	nextState->params.instanceAngle = flagState->params.instanceAngle;
    	    	nextState->params.pathAngle = flagState->params.pathAngle;
    	    }
    	}
// and so on for all the other bits.
    	flagState = nextState;
    	currentFlags = nextFlags;
	}
}
Ejemplo n.º 3
0
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;
    }
}
Ejemplo n.º 4
0
/*
 * Add a duplicate block record
 */
static void add_dupe(e2fsck_t ctx, ext2_ino_t ino, blk64_t cluster,
		     struct ext2_inode *inode)
{
	dnode_t	*n;
	struct dup_cluster	*db;
	struct dup_inode	*di;
	struct cluster_el	*cluster_el;
	struct inode_el 	*ino_el;

	n = dict_lookup(&clstr_dict, INT_TO_VOIDPTR(cluster));
	if (n)
		db = (struct dup_cluster *) dnode_get(n);
	else {
		db = (struct dup_cluster *) e2fsck_allocate_memory(ctx,
			sizeof(struct dup_cluster), "duplicate cluster header");
		db->num_bad = 0;
		db->inode_list = 0;
		dict_alloc_insert(&clstr_dict, INT_TO_VOIDPTR(cluster), db);
	}
	ino_el = (struct inode_el *) e2fsck_allocate_memory(ctx,
			 sizeof(struct inode_el), "inode element");
	ino_el->inode = ino;
	ino_el->next = db->inode_list;
	db->inode_list = ino_el;
	db->num_bad++;

	n = dict_lookup(&ino_dict, INT_TO_VOIDPTR(ino));
	if (n)
		di = (struct dup_inode *) dnode_get(n);
	else {
		di = (struct dup_inode *) e2fsck_allocate_memory(ctx,
			 sizeof(struct dup_inode), "duplicate inode header");
		if (ino == EXT2_ROOT_INO) {
			di->dir = EXT2_ROOT_INO;
			dup_inode_founddir++;
		} else
			di->dir = 0;

		di->num_dupblocks = 0;
		di->cluster_list = 0;
		di->inode = *inode;
		dict_alloc_insert(&ino_dict, INT_TO_VOIDPTR(ino), di);
	}
	cluster_el = (struct cluster_el *) e2fsck_allocate_memory(ctx,
			 sizeof(struct cluster_el), "cluster element");
	cluster_el->cluster = cluster;
	cluster_el->next = di->cluster_list;
	di->cluster_list = cluster_el;
	di->num_dupblocks++;
}
Ejemplo n.º 5
0
int
ddb_lookup (const dict_t *config,
	    const char *startup,
	    char name[HDL_GAME_NAME_MAX + 1],
	    compat_flags_t *flags)
{
  int result;
  const char *disc_db = dict_lookup (config, CONFIG_DISC_DATABASE_FILE);
  dict_t *list = disc_db != NULL ? dict_restore (NULL, disc_db) : NULL;
  *name = '\0'; *flags = 0;
  if (list != NULL)
    {
      const char *entry = dict_lookup (list, startup);
      if (entry != NULL)
	{ /* game info has been found */
	  size_t entry_len = strlen (entry);
	  char *pos = strrchr (entry, ';');

	  result = RET_OK;
	  if (pos != NULL && pos[1] != 'x')
	    { /* scan for compatibility flags */
	      compat_flags_t flags2 = 0;
	      if (strcmp (pos + 1, "0") != 0)
		flags2 = parse_compat_flags (pos + 1);
	      if (flags2 != COMPAT_FLAGS_INVALID)
		{ /* we have compatibility flags */
		  *flags = flags2;
		  entry_len = pos - entry;
		}
	    }
	  else if (pos != NULL && pos[1] == 'x')
	    { /* marked as incompatible; warn */
	      result = RET_DDB_INCOMPATIBLE;
	      entry_len = pos - entry;
	    }
	  /* entry has been found => fill game name */
	  memcpy (name, entry, (entry_len < HDL_GAME_NAME_MAX ?
				entry_len : HDL_GAME_NAME_MAX));
	  name[entry_len < HDL_GAME_NAME_MAX ? entry_len : HDL_GAME_NAME_MAX] = '\0';
	}
      else
	result = RET_NO_DDBENTRY;
      dict_free (list);
    }
  else
    result = RET_NO_DISC_DB;
  return (result);
}
Ejemplo n.º 6
0
int index_storage_attribute_get(struct mailbox *box,
				enum mail_attribute_type type, const char *key,
				struct mail_attribute_value *value_r,
				bool internal_attribute)
{
	struct dict *dict;
	const char *mailbox_prefix, *error;
	int ret;

	memset(value_r, 0, sizeof(*value_r));

	if (!internal_attribute &&
	    !MAILBOX_ATTRIBUTE_KEY_IS_USER_ACCESSIBLE(key))
		return 0;

	if (index_storage_get_dict(box, type, &dict, &mailbox_prefix) < 0)
		return -1;

	ret = dict_lookup(dict, pool_datastack_create(),
			  key_get_prefixed(type, mailbox_prefix, key),
			  &value_r->value, &error);
	if (ret < 0) {
		mail_storage_set_critical(box->storage,
			"Failed to set attribute %s: %s", key, error);
		return -1;
	}
	return ret;
}
Ejemplo n.º 7
0
int     match_string(int unused_flags, const char *string, const char *pattern)
{
    char   *myname = "match_string";
    int     match;
    char   *key;

    if (msg_verbose)
	msg_info("%s: %s ~? %s", myname, string, pattern);

    /*
     * Try dictionary lookup: exact match.
     */
    if (strchr(pattern, ':') != 0) {
	key = lowercase(mystrdup(string));
	match = (dict_lookup(pattern, key) != 0);
	myfree(key);
	if (match != 0)
	    return (1);
	if (dict_errno != 0)
	    msg_fatal("%s: table lookup problem", pattern);
	return (0);
    }

    /*
     * Try an exact string match.
     */
    if (strcasecmp(string, pattern) == 0) {
	return (1);
    }

    /*
     * No match found.
     */
    return (0);
}
Ejemplo n.º 8
0
static VALUE ruby_function_proxy(VALUE self, VALUE _args)
{
    ID id = rb_frame_last_func();

    value_t* value = dict_lookup(global->functions, (void*)id);

    if(!value) {
        language_error(global->li, "[ruby] couldn't retrieve constant %s", rb_id2name(id));
        return Qnil;
    }

    if(value->type == TYPE_FUNCTION) {
        log_dbg("[ruby] calling function %s", rb_id2name(id));
        value_t*args = ruby_to_value(_args);
        value_t*ret = value->call(value, args);
        value_destroy(args);
        volatile VALUE r = value_to_ruby(ret);
        value_destroy(ret);
        log_dbg("[rb] returning from callback");
        return r;
    } else {
        log_dbg("[ruby] retrieving constant %s (%s)", rb_id2name(id), type_to_string(value->type));
        volatile VALUE r = value_to_ruby(value);
        return r;
    }
    return Qnil;
}
Ejemplo n.º 9
0
int call_userflow_lookup_alloc(struct userflow **ufp,
			       bool *allocated,
			       struct call *call,
			       const char *userid, const char *username)
{
	struct userflow *uf = NULL;
	int err = 0;

	if (!ufp || !call)
		return EINVAL;

	uf = dict_lookup(call->users, userid);
	if (uf) {
		if (allocated)
			*allocated = false;
	}
	else {
		err = userflow_alloc(&uf, call, userid, username);
		if (err) {
			warning("flowmgr: call: userflow_alloc (%m)\n", err);
			goto out;
		}

		if (allocated)
			*allocated = true;
	}

 out:
	if (err == 0)
		*ufp = uf;

	return err;
}
Ejemplo n.º 10
0
dnode_t *
RP_mapping::is_presented(ea_t addr)
{ 
  if ( NULL == mapping )
   return (dnode_t *)NULL;
  return dict_lookup(mapping, (const void *)addr);  
}
Ejemplo n.º 11
0
static enum passdb_result
passdb_dict_lookup_key(struct auth_request *auth_request,
		       struct dict_passdb_module *module, const char *key)
{
	const char *value;
	int ret;

	auth_request_log_debug(auth_request, "dict", "lookup %s", key);
	ret = dict_lookup(module->conn->dict, pool_datastack_create(),
			  key, &value);
	if (ret < 0) {
		auth_request_log_error(auth_request, "dict", "Lookup failed");
		return PASSDB_RESULT_INTERNAL_FAILURE;
	} else if (ret == 0) {
		auth_request_log_unknown_user(auth_request, "dict");
		return PASSDB_RESULT_USER_UNKNOWN;
	} else {
		auth_request_log_debug(auth_request, "dict",
				       "result: %s", value);
		if (dict_query_save_results(auth_request, module->conn, value) < 0)
			return PASSDB_RESULT_INTERNAL_FAILURE;

		if (auth_request->passdb_password == NULL &&
		    !auth_fields_exists(auth_request->extra_fields, "nopassword")) {
			auth_request_log_info(auth_request, "dict",
				"No password returned (and no nopassword)");
			return PASSDB_RESULT_PASSWORD_MISMATCH;
		} else {
			return PASSDB_RESULT_OK;
		}
	}
}
Ejemplo n.º 12
0
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);
}
Ejemplo n.º 13
0
int index_storage_attribute_get(struct mailbox_transaction_context *t,
				enum mail_attribute_type type, const char *key,
				struct mail_attribute_value *value_r)
{
	struct dict *dict;
	const char *mailbox_prefix;
	int ret;

	memset(value_r, 0, sizeof(*value_r));

	if (strncmp(key, MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT,
		    strlen(MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT)) == 0)
		return 0;

	if (index_storage_get_dict(t->box, type, &dict, &mailbox_prefix) < 0)
		return -1;

	ret = dict_lookup(dict, pool_datastack_create(),
			  key_get_prefixed(type, mailbox_prefix, key),
			  &value_r->value);
	if (ret < 0) {
		mail_storage_set_internal_error(t->box->storage);
		return -1;
	}
	return ret;
}
Ejemplo n.º 14
0
variable_t* find_variable(state_t*s, const char*name)
{
    if(s->method->no_variable_scoping) {
        return dict_lookup(s->method->allvars, name);
    } else {
        state_t*top = s;
        while(s) {
            variable_t*v = 0;
            v = dict_lookup(s->vars, name);
            if(v) return v;
            if(s->new_vars) break;
            s = s->old;
        }
        return 0;
    }
}
Ejemplo n.º 15
0
TA_RetCode TA_DictDeletePair_S( TA_Dict *dict, const char *key )
{
   TA_PrivDictInfo *theDict;
   TA_String *stringToDelete;
   void      *valueToDelete;
   dnode_t   *node;
   TA_Libc   *libHandle;
   dict_t    *kazlibDict;

   theDict = (TA_PrivDictInfo *)dict;

   if( (theDict == NULL) || (key == NULL) )
      return TA_BAD_PARAM;
   kazlibDict = &theDict->d;
   libHandle  = theDict->libHandle;

   /* Find the key-value pair. */
   node = dict_lookup( libHandle, kazlibDict, key );

   if( node )
   {
      /* Free the 'node', the 'key' string and the 'value'. */
      stringToDelete = TA_StringFromChar( dnode_getkey(node) );
      valueToDelete  = dnode_get(node);
      dict_delete_free( libHandle, kazlibDict, node );
      TA_StringFree( TA_GetGlobalStringCache( libHandle ), stringToDelete );
      if( theDict->freeValueFunc )
         theDict->freeValueFunc( libHandle, valueToDelete );
   }
   else
      return TA_KEY_NOT_FOUND;

   return TA_SUCCESS;
}
Ejemplo n.º 16
0
/// Remove the specified PTX from the DB via its index.
/// @param[in] key      the key associated with a given PTX
/// return zero iff the node was found and successfully removed
static int
_shop_ptx_invalidate(shopping_state_s *ssp, CCS key, CCS msg, int ignored)
{
    dnode_t *dnp;
    CCS id;

    dnp = dict_lookup(ssp->ptx_dict, key);

    if (ignored && dnp) {
	id = (CCS)dnode_get(dnp);
	vb_printf(VB_WHY, "WOULD INVALIDATE %s (%s) due to '%s'", id, key, msg);
	return 0;
    }

    if (dnp) {
	id = (CCS)dnode_get(dnp);
	key = (CCS)dnode_getkey(dnp);
	vb_printf(VB_WHY, "PTX %s invalidated due to '%s'", id, msg);
	dict_delete_free(ssp->ptx_dict, dnp);
	putil_free(id);
	putil_free(key);
	return 0;
    } else {
	putil_warn("invalidated PTX %s twice", key);
	return 1;
    }
}
Ejemplo n.º 17
0
TA_RetCode TA_DictDeletePair_I( TA_Dict *dict, int key )
{
   TA_PrivDictInfo *theDict;
   void      *valueToDelete;
   dnode_t   *node;
   TA_Libc   *libHandle;
   dict_t    *kazlibDict;

   theDict = (TA_PrivDictInfo *)dict;

   if( theDict == NULL )
      return TA_BAD_PARAM;
   kazlibDict = &theDict->d;
   libHandle  = theDict->libHandle;

   /* Find the key-value pair. */
   node = dict_lookup( libHandle, kazlibDict, (void *)key );

   if( node )
   {
      /* Free the 'node' and the 'value'. */
      valueToDelete  = dnode_get(node);
      dict_delete_free( libHandle, kazlibDict, node );
      if( theDict->freeValueFunc )
         theDict->freeValueFunc( libHandle, valueToDelete );
   }
   else
      return TA_KEY_NOT_FOUND;

   return TA_SUCCESS;
}
Ejemplo n.º 18
0
int enode_eval(struct enode *n, const struct dictionary *constants) {
  if (n->type == '*') {
    int left = enode_eval(n->left,constants);
    int right = enode_eval(n->right,constants);
    int result = left * right;
    return result;
  }
  if (n->type == '+') {
    int left = enode_eval(n->left,constants);
    int right = enode_eval(n->right,constants);
    int result = left + right;
    return result;
  }
  if (n->type == '-') {
    int left = enode_eval(n->left,constants);
    int right = enode_eval(n->right,constants);
    int result = left - right;
    return result;
  } 
  if (n->type == '/') {
    int left = enode_eval(n->left,constants);
    int right = enode_eval(n->right,constants);
    int result = left / right;
    return result;
  }
  if (n->type == 'n') {
    int result = n->number;
    return result;
  }
  if (n->type == 'v') {
    int result = dict_lookup(n->id,constants);
    return result;
  }
  return 0;
}
Ejemplo n.º 19
0
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;
        }
    }
int history_changeFilter(history_t* past, U16 frame)
{
    filterState_t* first = dict_lookup(past->states, "filter");
    if (first)	//should always be true.
	return filterState_differs(first, frame);
    syntaxerror("no history found to predict changes for parameter filter.\n");
    return 0;
}
int history_change(history_t* past, U16 frame, char* parameter)
{
    state_t* first = dict_lookup(past->states, parameter);
    if (first)	//should always be true.
	return state_differs(first, frame);
    syntaxerror("no history found to predict changes for parameter %s.\n", parameter);
    return 0;
}
float history_value(history_t* past, U16 frame, char* parameter)
{
    state_t* state = dict_lookup(past->states, parameter);
    if (state)	//should always be true.
	return state_value(state, frame);
    syntaxerror("no history found to get a value for parameter %s.\n", parameter);
    return 0;
}
FILTERLIST* history_filterValue(history_t* past, U16 frame)
{
    filterState_t* first = dict_lookup(past->states, "filter");
	if (first)	//should always be true.
	return filterState_value(first, frame);
    syntaxerror("no history found to get a value for parameter filter.\n");
	return 0;
}
Ejemplo n.º 24
0
/// Store a new PTX id in the internal database.
static void
_shop_ptx_insert(shopping_state_s *ssp, CCS key, CCS id)
{
    if (!dict_lookup(ssp->ptx_dict, key)) {
	if (!dict_alloc_insert(ssp->ptx_dict,
			       putil_strdup(key), putil_strdup(id))) {
	    putil_syserr(2, "dict_alloc_insert(ptx_dict)");
	}
    }
}
Ejemplo n.º 25
0
const char *mail_conf_lookup_eval(const char *name)
{
    const char *value;

#define RECURSIVE	1

    if ((value = dict_lookup(CONFIG_DICT, name)) != 0)
	value = dict_eval(CONFIG_DICT, value, RECURSIVE);
    return (value);
}
Ejemplo n.º 26
0
int     match_hostaddr(int unused_flags, const char *addr, const char *pattern)
{
    char   *myname = "match_hostaddr";
    unsigned int mask_shift;
    unsigned long mask_bits;
    unsigned long net_bits;
    unsigned long addr_bits;
    struct in_addr net_addr;

    if (msg_verbose)
	msg_info("%s: %s ~? %s", myname, addr, pattern);

    if (addr[strspn(addr, "01234567890./:")] != 0)
	return (0);

    /*
     * Try dictionary lookup. This can be case insensitive. XXX Probably
     * should also try again after stripping least significant octets.
     */
    if (strchr(pattern, ':') != 0) {
	if (dict_lookup(pattern, addr) != 0)
	    return (1);
	if (dict_errno != 0)
	    msg_fatal("%s: table lookup problem", pattern);
	return (0);
    }

    /*
     * Try an exact match with the host address.
     */
    if (strcasecmp(addr, pattern) == 0) {
	return (1);
    }

    /*
     * In a net/mask pattern, the mask is specified as the number of bits of
     * the network part.
     */
    if (match_parse_mask(pattern, &net_bits, &mask_shift)) {
	addr_bits = inet_addr(addr);
	if (addr_bits == INADDR_NONE)
	    msg_fatal("%s: bad address argument: %s", myname, addr);
	mask_bits = mask_shift > 0 ?
	    htonl((0xffffffff) << (BITS_PER_ADDR - mask_shift)) : 0;
	if ((addr_bits & mask_bits) == net_bits)
	    return (1);
	if (net_bits & ~mask_bits) {
	    net_addr.s_addr = (net_bits & mask_bits);
	    msg_fatal("net/mask pattern %s has a non-null host portion; "
		      "specify %s/%d if this is really what you want",
		      pattern, inet_ntoa(net_addr), mask_shift);
	}
    }
    return (0);
}
Ejemplo n.º 27
0
TA_RetCode TA_DictAddPair_S2( TA_Dict *dict,
                              TA_String *key1,
                              TA_String *key2,
                              void *value )
{
   TA_PrivDictInfo *theDict;
   dnode_t *node;
   TA_String *dupKey;
   TA_Dict *subDict;
   TA_Libc *libHandle;
   dict_t  *kazlibDict;

   theDict = (TA_PrivDictInfo *)dict;

   if( (theDict == NULL) ||
       (key1 == NULL) || (key2 == NULL) || (value == NULL) )
      return TA_BAD_PARAM;
   kazlibDict = &theDict->d;
   libHandle  = theDict->libHandle;

   /* Verify if a a dictionary already exist for key1. */
   node = dict_lookup( libHandle, kazlibDict, TA_StringToChar(key1) );

   if( node )
   {
      /* A dictionary already exist with the same key1... re-use it. */
      subDict = (TA_Dict *)dnode_get( node );
   }
   else
   {
      /* Alloc a new directory corresponding to key1. */
      subDict = TA_DictAlloc( libHandle, TA_DICT_KEY_ONE_STRING, theDict->freeValueFunc );

      if( !subDict )
         return TA_ALLOC_ERR;

      dupKey = TA_StringDup( TA_GetGlobalStringCache( libHandle ), key1 );

      if( !dupKey )
      {
         TA_DictFree( subDict );
         return TA_ALLOC_ERR;
      }

      if( !dict_alloc_insert( libHandle, kazlibDict, TA_StringToChar(dupKey), subDict ) )
      {
         TA_DictFree( subDict );
         TA_StringFree( TA_GetGlobalStringCache( libHandle ), dupKey );
         return TA_ALLOC_ERR;
      }
   }

   /* Insert the string in the subDict using key2 */
   return TA_DictAddPair_S( subDict, key2, value );
}
Ejemplo n.º 28
0
int     match_hostname(int flags, const char *name, const char *pattern)
{
    char   *myname = "match_hostname";
    const char *pd;
    const char *entry;
    char   *next;
    char   *temp;
    int     match;

    if (msg_verbose)
	msg_info("%s: %s ~? %s", myname, name, pattern);

    /*
     * Try dictionary lookup: exact match and parent domains.
     */
    if (strchr(pattern, ':') != 0) {
	temp = lowercase(mystrdup(name));
	match = 0;
	for (entry = temp; *entry != 0; entry = next) {
	    if ((match = (dict_lookup(pattern, entry) != 0)) != 0)
		break;
	    if (dict_errno != 0)
		msg_fatal("%s: table lookup problem", pattern);
	    if ((next = strchr(entry + 1, '.')) == 0)
		break;
	    if (flags & MATCH_FLAG_PARENT)
		next += 1;
	}
	myfree(temp);
	return (match);
    }

    /*
     * Try an exact match with the host name.
     */
    if (strcasecmp(name, pattern) == 0) {
	return (1);
    }

    /*
     * See if the pattern is a parent domain of the hostname.
     */
    else {
	if (flags & MATCH_FLAG_PARENT) {
	    pd = name + strlen(name) - strlen(pattern);
	    if (pd > name && pd[-1] == '.' && strcasecmp(pd, pattern) == 0)
		return (1);
	} else if (pattern[0] == '.') {
	    pd = name + strlen(name) - strlen(pattern);
	    if (pd > name && strcasecmp(pd, pattern) == 0)
		return (1);
	}
    }
    return (0);
}
Ejemplo n.º 29
0
ledger_topic *ledger_lookup_topic(ledger_ctx *ctx, const char *name) {
    ledger_topic *topic = NULL;
    dnode_t *dtopic;

    dtopic = dict_lookup(&ctx->topics, name);
    if(dtopic != NULL) {
        topic = dnode_get(dtopic);
        return topic;
    }
    return NULL;
}
Ejemplo n.º 30
0
void ledger_close_topic(ledger_ctx *ctx, const char *name) {
    ledger_topic *topic = NULL;
    dnode_t *dtopic;

    dtopic = dict_lookup(&ctx->topics, name);
    if(dtopic != NULL) {
        topic = dnode_get(dtopic);
        ledger_topic_close(topic);
        dict_delete_free(&ctx->topics, dtopic);
    }
}