Example #1
0
static void
insert_uids_to_lit_id_map (op_meta *om, uint16_t mask)
{
  for (uint8_t i = 0; i < 3; i++)
  {
    if (is_possible_literal (mask, i))
    {
      if (get_uid (om, i) == LITERAL_TO_REWRITE)
      {
        JERRY_ASSERT (om->lit_id[i].packed_value != MEM_CP_NULL);
        lit_cpointer_t lit_id = om->lit_id[i];
        idx_t *uid = (idx_t *) hash_table_lookup (lit_id_to_uid, &lit_id);
        if (uid == NULL)
        {
          hash_table_insert (lit_id_to_uid, &lit_id, &next_uid);
          uid = (idx_t *) hash_table_lookup (lit_id_to_uid, &lit_id);
          JERRY_ASSERT (uid != NULL);
          JERRY_ASSERT (*uid == next_uid);
          next_uid++;
        }
      }
      else
      {
        JERRY_ASSERT (om->lit_id[i].packed_value == MEM_CP_NULL);
      }
    }
    else
    {
      JERRY_ASSERT (om->lit_id[i].packed_value == MEM_CP_NULL);
    }
  }
}
Example #2
0
/*
 * Check if host in Request URI is local
 */
int is_uri_host_local(struct sip_msg* _msg, char* _s1, char* _s2)
{
    str branch;
    qvalue_t q;
    struct sip_uri puri;
    struct attr_list *attrs;
    str did;

    if ( is_route_type(REQUEST_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE) ) {
	if (parse_sip_msg_uri(_msg) < 0) {
	    LM_ERR("error while parsing R-URI\n");
	    return -1;
	}
	return hash_table_lookup(&(_msg->parsed_uri.host), &did, &attrs);
    } else if (is_route_type(FAILURE_ROUTE)) {
	branch.s = get_branch(0, &branch.len, &q, 0, 0, 0, 0, 0, 0, 0);
	if (branch.s) {
	    if (parse_uri(branch.s, branch.len, &puri) < 0) {
		LM_ERR("error while parsing branch URI\n");
		return -1;
	    }
	    return hash_table_lookup(&(puri.host), &did, &attrs);
	} else {
	    LM_ERR("branch is missing, error in script\n");
	    return -1;
	}
    } else {
	LM_ERR("unsupported route type\n");
	return -1;
    }
}
Example #3
0
void test_hash_table_remove(void)
{
	HashTable *hash_table;
	char buf[10];

	hash_table = generate_hash_table();

	assert(hash_table_num_entries(hash_table) == NUM_TEST_VALUES);
	sprintf(buf, "%i", 5000);
	assert(hash_table_lookup(hash_table, buf) != NULL);

	/* Remove an entry */

	hash_table_remove(hash_table, buf);

	/* Check entry counter */

	assert(hash_table_num_entries(hash_table) == 9999);

	/* Check that NULL is returned now */

	assert(hash_table_lookup(hash_table, buf) == NULL);

	/* Try removing a non-existent entry */

	sprintf(buf, "%i", -1);
	hash_table_remove(hash_table, buf);

	assert(hash_table_num_entries(hash_table) == 9999);

	hash_table_free(hash_table);
}
static batch_job_id_t batch_job_wq_submit (struct batch_queue * q, const char *cmd, const char *extra_input_files, const char *extra_output_files, struct nvpair *envlist )
{
	struct work_queue_task *t;

	int caching_flag = WORK_QUEUE_CACHE;

	if(string_istrue(hash_table_lookup(q->options, "caching"))) {
		caching_flag = WORK_QUEUE_CACHE;
	} else {
		caching_flag = WORK_QUEUE_NOCACHE;
	}

	t = work_queue_task_create(cmd);

	specify_files(t, extra_input_files, extra_output_files, caching_flag);
	specify_envlist(t,envlist);

	struct rmsummary *resources = parse_batch_options_resources(hash_table_lookup(q->options, "batch-options"));
	if(resources)
	{
		work_queue_task_specify_resources(t, resources);
		free(resources);
	}

	work_queue_submit(q->data, t);

	return t->taskid;
}
Example #5
0
void test_hash_table_iterating_remove(void)
{
	HashTable *hash_table;
	HashTableIterator iterator;
	char buf[10];
	char *val;
	HashTablePair pair;
	int count;
	unsigned int removed;
	int i;

	hash_table = generate_hash_table();

	/* Iterate over all values in the table */

	count = 0;
	removed = 0;

	hash_table_iterate(hash_table, &iterator);

	while (hash_table_iter_has_more(&iterator)) {

		/* Read the next value */

		pair = hash_table_iter_next(&iterator);
		val = pair.value;

		/* Remove every hundredth entry */

		if ((atoi(val) % 100) == 0) {
			hash_table_remove(hash_table, val);
			++removed;
		}

		++count;
	}

	/* Check counts */

	assert(removed == 100);
	assert(count == NUM_TEST_VALUES);

	assert(hash_table_num_entries(hash_table)
	       == NUM_TEST_VALUES - removed);

	/* Check all entries divisible by 100 were really removed */

	for (i=0; i<NUM_TEST_VALUES; ++i) {
		sprintf(buf, "%i", i);

		if (i % 100 == 0) {
			assert(hash_table_lookup(hash_table, buf) == NULL);
		} else {
			assert(hash_table_lookup(hash_table, buf) != NULL);
		}
	}

	hash_table_free(hash_table);
}
Example #6
0
//traverse up the thing
struct symbol * scope_lookup(const char * name){
	struct hash_table *h_cursor = h;
	while(h_cursor){
		if(hash_table_lookup(h_cursor,name)){
			return hash_table_lookup(h_cursor,name);
		}
		// h_cursor = hash_table_lookup(h_cursor, "0prev");
		h_cursor = h_cursor->prev;
	}
	return NULL;
}
static int log_replay( struct nvpair_database *db, const char *filename, time_t snapshot)
{
	FILE *file = fopen(filename,"r");
	if(!file) return 0;
	
	time_t current = 0;
	struct nvpair *nv;

	char line[NVPAIR_LINE_MAX];
	char key[NVPAIR_LINE_MAX];
	char name[NVPAIR_LINE_MAX];
	char value[NVPAIR_LINE_MAX];
	char oper;
	
	while(fgets(line,sizeof(line),file)) {

		int n = sscanf(line,"%c %s %s %[^\n]",&oper,key,name,value);
		if(n<1) continue;

		switch(oper) {
			case 'C':
				nv = nvpair_create();
				nvpair_parse_stream(nv,file);
				nvpair_delete(hash_table_remove(db->table,name));
				hash_table_insert(db->table,key,nv);
				break;
			case 'D':
				nv = hash_table_remove(db->table,key);
				if(nv) nvpair_delete(nv);
				break;
			case 'U':
				nv = hash_table_lookup(db->table,key);
				if(nv) nvpair_insert_string(nv,name,value);
				break;
			case 'R':
				nv = hash_table_lookup(db->table,key);
				if(nv) nvpair_remove(nv,name);
				break;
			case 'T':
				current = atol(key);
				if(current>snapshot) break;
				break;
			default:
				debug(D_NOTICE,"corrupt log data in %s: %s",filename,line);
				break;
		}
	}
	
	fclose(file);

	return 1;
}
Example #8
0
/*
 * Check if domain is local
 */
int is_domain_local(str* _host)
{
    str did;
    struct attr_list *attrs;

    return hash_table_lookup(_host, &did, &attrs);
}
Example #9
0
static int upload_input_files_to_s3(char* files,char* jobname){
	int success = 1;
	char* env_var = initialized_data.master_env_prefix;
	struct list* file_list = extract_file_names_from_list(files);
	debug(D_BATCH,"extra input files list: %s, len: %i",files, list_size(file_list));
	list_first_item(file_list);
	char* cur_file = NULL;
	while((cur_file = list_next_item(file_list)) != NULL){
		if(hash_table_lookup(submitted_files,cur_file) == &HAS_SUBMITTED_VALUE){
			continue;
		}
		debug(D_BATCH,"Submitting file: %s",cur_file);
		char* put_file_command = string_format("tar -cvf %s.txz %s && %s aws s3 cp %s.txz s3://%s/%s.txz ",cur_file,cur_file,env_var,cur_file,bucket_name,cur_file);
		int ret = sh_system(put_file_command);
		if(ret != 0){
			debug(D_BATCH,"File Submission: %s FAILURE return code: %i",cur_file,ret);
			success = 0;
		}else{
			debug(D_BATCH,"File Submission: %s SUCCESS return code: %i",cur_file,ret);
		}
		free(put_file_command);
		put_file_command = string_format("rm %s.txz",cur_file);
		sh_system(put_file_command);
		free(put_file_command);
		//assume everything went well?
		hash_table_insert(submitted_files,cur_file,&HAS_SUBMITTED_VALUE);
	}
	list_free(file_list);
	list_delete(file_list);
	return success;
}
Example #10
0
static void test_hash_random_pool(pool_t pool)
{
#define KEYMAX 100000
	HASH_TABLE(void *, void *) hash;
	unsigned int *keys;
	unsigned int i, key, keyidx, delidx;

	keys = i_new(unsigned int, KEYMAX); keyidx = 0;
	hash_table_create_direct(&hash, pool, 0);
	for (i = 0; i < KEYMAX; i++) {
		key = (rand() % KEYMAX) + 1;
		if (rand() % 5 > 0) {
			if (hash_table_lookup(hash, POINTER_CAST(key)) == NULL) {
				hash_table_insert(hash, POINTER_CAST(key),
						  POINTER_CAST(1));
				keys[keyidx++] = key;
			}
		} else if (keyidx > 0) {
			delidx = rand() % keyidx;
			hash_table_remove(hash, POINTER_CAST(keys[delidx]));
			memmove(&keys[delidx], &keys[delidx+1],
				(keyidx-delidx-1) * sizeof(*keys));
			keyidx--;
		}
	}
	for (i = 0; i < keyidx; i++)
		hash_table_remove(hash, POINTER_CAST(keys[i]));
	hash_table_destroy(&hash);
	i_free(keys);
}
Example #11
0
static int ast_do_simple( int line, int argc, char **argv, int fds[3], time_t stoptime )
{
	char *cmd;
	int length=0;
	int i;

	for( i=0; i<argc; i++ ) {
		length+=strlen(argv[i])+1;
	}

	cmd = xxmalloc(length+1);
	cmd[0] = 0;

	for( i=0; i<argc; i++ ) {
		strcat(cmd,argv[i]);
		strcat(cmd," ");
	}

	ftsh_error(FTSH_ERROR_COMMAND,line,"%s",cmd);

	free(cmd);

	if(hash_table_lookup(ftable,argv[0]) || builtin_lookup(argv[0]) ) {
		return ast_do_internal(line,argc,argv,fds,stoptime);
	} else {
		return ast_do_external(line,argc,argv,fds,stoptime);
	}
}
Example #12
0
static int ast_do_internal( int line, int argc, char **argv, int fds[3], time_t stoptime )
{
	struct ast_function *f;
	builtin_func_t b;
	int oldfds[3];
	int result=0;

	f = hash_table_lookup(ftable,argv[0]);
	b = builtin_lookup(argv[0]);

	if(f) ftsh_error(FTSH_ERROR_STRUCTURE,f->function_line,"FUNCTION %s",f->name->text);

	if(b || variable_frame_push(f->function_line,argc,argv)) {

		if(fds[0]!=0) {
			oldfds[0] = dup(0);
			if(oldfds[0]<0) ftsh_fatal(line,"out of file descriptors");
			dup2(fds[0],0);
		}

		if(fds[1]!=1) {
			oldfds[1] = dup(1);
			if(oldfds[1]<0) ftsh_fatal(line,"out of file descriptors");
			dup2(fds[1],1);
		}

		if(fds[2]!=2) {
			oldfds[2] = dup(2);
			if(oldfds[2]<0) ftsh_fatal(line,"out of file descriptors");
			dup2(fds[2],2);
		}

		if(f) {
			result = ast_group_execute(f->body,stoptime);
		} else {
			result = b(line,argc,argv,stoptime);
		}

		if(fds[2]!=2) {
			dup2(oldfds[2],2);
			close(oldfds[2]);
		}

		if(fds[1]!=1) {
			dup2(oldfds[1],1);
			close(oldfds[1]);
		}

		if(fds[0]!=0) {
			dup2(oldfds[0],0);
			close(oldfds[0]);
		}

		if(f) variable_frame_pop();
	}

	if(f) ftsh_error(FTSH_ERROR_STRUCTURE,f->end_line,"END");

	return result;
}
Example #13
0
int symbol_table_add(Symbol_Table *table, char *name, TTR_Node *node)
{
    Symbol_Entry_List *chain;
    Symbol_Entry *entry;

    assert(table != NULL);
    assert(name != NULL);
    assert(node != NULL);

    chain = hash_table_lookup(table->table, name);
    if (chain == NULL) {
        if (init_symbol_entry_list(&chain, name))
            return 1;
        hash_table_add(table->table, name, chain);
    }
    entry = malloc(sizeof(Symbol_Entry));
    if (entry == NULL)
        return 1; 
    entry->name = strdup(name);
    if (entry->name == NULL)
        return 1;
    entry->node = node;
    entry->scope = table->scope_stack[table->sp-1];
    entry->next = chain->first;
    chain->first = entry;
    return 0;
}
Example #14
0
static s3cipid_t
dict_ciphone_id(dict_t * d, const char *str)
{
    if (d->mdef)
        return mdef_ciphone_id(d->mdef, str);
    else {
	void *val;

        if (hash_table_lookup(d->pht, str, &val) < 0) {
	    s3cipid_t id;

            id = (d->n_ciphone)++;

            if (id >= MAX_S3CIPID)
                E_FATAL
                    ("Too many CIphones in dictionary; increase MAX_S3CIPID\n");
            d->ciphone_str[id] = (char *) ckd_salloc(str);      /* Freed in dict_free() */

            if (hash_table_enter(d->pht, d->ciphone_str[id], (void *)(long)id) != (void *)(long)id)
                E_FATAL("hash_table_enter(local-phonetable, %s) failed\n", str);
	    return id;
        }
	else
	    return (s3cipid_t)(long)val;
    }
}
Example #15
0
// Load seq content array
void init_chrome_seq(HashNode** hashTable, char* refSeqFile, char** chrSeqArray, int* chrLen)
{
	
	FILE* fPtr = fopen(refSeqFile, "r");
	if(!fPtr) { 
		// Check file existance
		printf("File %s open error.\n", refSeqFile);
		exit(1);
	}
	fclose(fPtr);
	
	char* readBuffer = chrSeqArray[0];
	int readBufferPtr = 0;
	int readSeqPtr = 0;
	int lines = 0;
	
	char* token;
	char seps[] = " \t\n\r";
	char chrName[50];
	
	fPtr = fopen(refSeqFile, "r");
	while(fgets(readBuffer + readBufferPtr, 500, fPtr)) {
		if(*(readBuffer + readBufferPtr) == '>') {
			if(lines > 0) {
				// Check old buffer
				if(readBufferPtr != chrLen[readSeqPtr] ) {
					printf("Length of seq %s error! %d vs %d!\n", chrName, readBufferPtr, chrLen[readSeqPtr]);
					exit(1);
				}
			}
			// Set new buffer
			token = strtok(readBuffer + readBufferPtr + 1, seps);	
			strcpy(chrName, token);
			readSeqPtr = hash_table_lookup(hashTable, chrName);
			if(readSeqPtr == -1) {
				printf("Error find sequence with name %s!\n", chrName);
				exit(1);
			}
			readBuffer = chrSeqArray[readSeqPtr];
			readBufferPtr = 0;	
		}
		else {
			// Substract \n
			readBufferPtr += strlen(readBuffer + readBufferPtr) - 1;
			// Check buffer boundary
			if(readBufferPtr > chrLen[readSeqPtr]) {
				printf("Length of seq %s error at line %d! %d vs %d!\n", chrName, lines, readBufferPtr, chrLen[readSeqPtr]);
				exit(1);
			}
		}
		
		lines++;
	}
	// Check old buffer
	if(readBufferPtr != chrLen[readSeqPtr] ) {
		printf("Length of seq %s error! %d vs %d!\n", chrName, readBufferPtr, chrLen[readSeqPtr]);
		exit(1);
	}
	fclose(fPtr);
}
Example #16
0
// Init chrome name array and length array
void init_chrome_name_len(HashNode** hashTable, char* chrLenFile, int chrCnt, char** chrName, int* chrLen)
{
	int i, j, seqPtr;
	
	FILE* fPtr = fopen(chrLenFile, "r");
	if(!fPtr) { 
		// Check file existance
		printf("File %s open error.\n", chrLenFile);
		exit(1);
	}
	fclose(fPtr);
	
	char* token = NULL;
	char readBuffer[500];
	char seps[] = " \t\n\r";

	fPtr = fopen(chrLenFile, "r");
	for(i = 0; i < chrCnt; i++) {
		fgets(readBuffer, 500, fPtr);
		
		token = strtok(readBuffer, seps);
		seqPtr = hash_table_lookup(hashTable, token);
		strcpy(chrName[seqPtr], token);
		
		token = strtok(NULL, seps);
		j = atoi(token);
		chrLen[seqPtr] = j;
	}
	fclose(fPtr);
}
Example #17
0
char * match(char * s, hash_table_t * ht, char a[][BUFSIZ], int * p) {
  uint32_t dist, mindst, minidx, i;
  mindst = INT_MAX;
  minidx = 0;
  for (i = 0; i < NUMA; i++) {
    dist = string_distance(s, a[i]);
    if (dist < mindst) {
      mindst = dist;
      minidx = i;
    }
  }
  hkey_t k;
  k.size = strlen(a[minidx])+1;
  k.key = a[minidx];
  void * addr = hash_table_lookup(ht, k);

  if (addr == NULL) {
    printf("match_str: lookup failure\n");
    exit(EXIT_FAILURE);
  }

  key_val_t kv = *(key_val_t*)addr;
  char * correct = kv.val.val;

  double len = MIN((double)strlen(s), (double)strlen(a[minidx]));
  double num = MAX(0.0, len - (double)mindst);
  double den = MAX((double)strlen(s), (double)strlen(a[minidx]));
  double match = num / den;
  uint32_t md = (int)(100 * match * match);
  *p = md;
  /* printf("matched %s (confidence: %d%%)\n", correct, md); */
  return correct;
}
Example #18
0
static batch_job_id_t batch_job_wq_submit (struct batch_queue * q, const char *cmd, const char *extra_input_files, const char *extra_output_files, struct jx *envlist, const struct rmsummary *resources)
{
	struct work_queue_task *t;

	int caching_flag = WORK_QUEUE_CACHE;

	if(string_istrue(hash_table_lookup(q->options, "caching"))) {
		caching_flag = WORK_QUEUE_CACHE;
	} else {
		caching_flag = WORK_QUEUE_NOCACHE;
	}

	t = work_queue_task_create(cmd);

	specify_files(t, extra_input_files, extra_output_files, caching_flag);
	specify_envlist(t,envlist);

	if(envlist) {
		const char *category = jx_lookup_string(envlist, "CATEGORY");
		if(category) {
			work_queue_task_specify_category(t, category);
		}
	}

	if(resources)
	{
		work_queue_task_specify_resources(t, resources);
	}

	work_queue_submit(q->data, t);

	return t->taskid;
}
static void stats_read(struct top_context *ctx)
{
	struct top_line *old_line, *line;
	unsigned int i;
	char **args;

	/* read lines */
	while ((args = p_read_next_line(ctx->cur_pool, ctx->input)) != NULL) {
		if (args[0] == NULL) {
			/* end of stats */
			return;
		}
		if (str_array_length((void *)args) != ctx->headers_count)
			i_fatal("read(%s): invalid stats line", ctx->path);

		line = p_new(ctx->cur_pool, struct top_line, 1);
		line->id = args[0];
		line->flip = ctx->flip;
		line->cur_values = p_new(ctx->cur_pool, const char *, ctx->headers_count);
		for (i = 0; i < ctx->headers_count; i++)
			line->cur_values[i] = args[i];

		old_line = hash_table_lookup(ctx->sessions, line->id);
		if (old_line != NULL) {
			stats_line_set_prev_values(ctx, old_line, line);
			array_append(&ctx->lines, &line, 1);
		}
		hash_table_insert(ctx->sessions, line->id, line);
	}

	if (ctx->input->stream_errno != 0)
		i_fatal("read(%s) failed: %m", ctx->path);
	i_fatal("read(%s): unexpected EOF", ctx->path);
}
static struct sieve_extension *_sieve_extension_register
(struct sieve_instance *svinst, const struct sieve_extension_def *extdef,
	bool load, bool required)
{
	struct sieve_extension_registry *ext_reg = svinst->ext_reg;
	struct sieve_extension *ext =
		hash_table_lookup(ext_reg->extension_index, extdef->name);

	/* Register extension if it is not registered already */
	if ( ext == NULL ) {
		struct sieve_extension **extr;

		int ext_id = (int)array_count(&ext_reg->extensions);

		/* Add extension to the registry */

		extr = array_append_space(&ext_reg->extensions);
		*extr = ext = p_new(svinst->pool, struct sieve_extension, 1);
		ext->id = ext_id;
		ext->def = extdef;
		ext->svinst = svinst;

		hash_table_insert(ext_reg->extension_index, extdef->name, ext);

	/* Re-register it if it were previously unregistered
	 * (not going to happen)
	 */
	} else if ( ext->def == NULL ) {
Example #21
0
static struct chirp_client * connect_to_host( const char *host, time_t stoptime )
{
	struct chirp_client *c;

	if(!table) {
		table = hash_table_create(0,0);
		if(!table) return 0;
	}

	c = hash_table_lookup(table,host);
	if(c) return c;
	
	if(!strncmp(host,"CONDOR",6)) {
		c = chirp_client_connect_condor(stoptime);
	} else {
		c = chirp_client_connect(host,1,stoptime);
	}

	if(c) {
		/*
		If a default replication factor was set earlier, then
		it must be re-applied when re-connecting after a failure.
		*/
		if(chirp_reli_default_nreps>0) {
			chirp_client_setrep(c,"@@@",chirp_reli_default_nreps,stoptime);
		}
		hash_table_insert(table,host,c);
		return c;
	} else {
		return 0;
	}
}
Example #22
0
/* Allocate a new ID. Disgusting method but it should work. */
static inline timer_id timer_alloc_id(void)
{
   while(hash_table_lookup(timer_id_hash,&timer_next_id))
      timer_next_id++;

   return(timer_next_id);
}
Example #23
0
static struct alloc_state *alloc_state_cache_exact(const char *path)
{
	struct alloc_state *a;
	char *d;
	char dirname[CHIRP_PATH_MAX];
	char statename[CHIRP_PATH_MAX];

	d = alloc_state_root_cached(path);
	if(!d)
		return 0;

	/*
	   Save a copy of dirname, because the following
	   alloc_table_load_cached may result in a flush of the alloc table root.
	 */

	strcpy(dirname, d);

	sprintf(statename, "%s/.__alloc", dirname);

	if(!alloc_table)
		alloc_table = hash_table_create(0, 0);

	a = hash_table_lookup(alloc_table, dirname);
	if(a)
		return a;

	a = alloc_state_load(dirname);
	if(!a)
		return a;

	hash_table_insert(alloc_table, dirname, a);

	return a;
}
static struct elasticsearch_result *
elasticsearch_result_get(struct elasticsearch_connection *conn, const char *box_id)
{
    struct elasticsearch_result *result = NULL;
    char *box_id_dup = NULL;

    /* check if the mailbox is cached first */ 
    result = hash_table_lookup(conn->ctx->mailboxes, box_id);

    if (result != NULL) {
        return result;
    } else {
        /* mailbox is not cached, we have to query it and then cache it */
    }

    box_id_dup = p_strdup(conn->ctx->result_pool, box_id);
    result = p_new(conn->ctx->result_pool, struct elasticsearch_result, 1);
    result->box_id = box_id_dup;

    p_array_init(&result->uids, conn->ctx->result_pool, 32);
    p_array_init(&result->scores, conn->ctx->result_pool, 32);
    hash_table_insert(conn->ctx->mailboxes, box_id_dup, result);
    array_append(&conn->ctx->results, &result, 1);

    return result;
}
static int
cmd_deduplicate_box(struct doveadm_mail_cmd_context *_ctx,
		    const struct mailbox_info *info,
		    struct mail_search_args *search_args)
{
	struct deduplicate_cmd_context *ctx =
		(struct deduplicate_cmd_context *)_ctx;
	struct doveadm_mail_iter *iter;
	struct mailbox *box;
	struct mail *mail;
	enum mail_error error;
	pool_t pool;
	HASH_TABLE(const char *, struct uidlist *) hash;
	const char *key, *errstr;
	struct uidlist *value;
	int ret = 0;

	if (doveadm_mail_iter_init(_ctx, info, search_args, 0, NULL,
				   &iter) < 0)
		return -1;

	pool = pool_alloconly_create("deduplicate", 10240);
	hash_table_create(&hash, pool, 0, str_hash, strcmp);
	while (doveadm_mail_iter_next(iter, &mail)) {
		if (ctx->by_msgid) {
			if (mail_get_first_header(mail, "Message-ID", &key) < 0) {
				errstr = mailbox_get_last_error(mail->box, &error);
				if (error == MAIL_ERROR_NOTFOUND)
					continue;
				i_error("Couldn't lookup Message-ID: for UID=%u: %s",
					mail->uid, errstr);
				doveadm_mail_failed_error(_ctx, error);
				ret = -1;
				break;
			}
		} else {
			if (mail_get_special(mail, MAIL_FETCH_GUID, &key) < 0) {
				errstr = mailbox_get_last_error(mail->box, &error);
				if (error == MAIL_ERROR_NOTFOUND)
					continue;
				i_error("Couldn't lookup GUID: for UID=%u: %s",
					mail->uid, errstr);
				doveadm_mail_failed_error(_ctx, error);
				ret = -1;
				break;
			}
		}
		if (key != NULL && *key != '\0') {
			value = p_new(pool, struct uidlist, 1);
			value->uid = mail->uid;
			value->next = hash_table_lookup(hash, key);

			if (value->next == NULL) {
				key = p_strdup(pool, key);
				hash_table_insert(hash, key, value);
			} else {
				hash_table_update(hash, key, value);
			}
		}
	}
Example #26
0
s3_cfg_id_t
s3_cfg_str2id(s3_cfg_t *_cfg, char *_name)
{
  void *id;
  char term[S3_CFG_MAX_ITEM_STR_LEN + 1];
  int start, end;

  assert(_cfg != NULL);
  assert(_name != NULL);

  for (start = 0; start < S3_CFG_MAX_ITEM_STR_LEN; start++) 
    if (strchr(" \t\r\n", _name[start]) == NULL)
      break;
  for (end = start; end < S3_CFG_MAX_ITEM_STR_LEN; end++) 
    if (strchr(" \t\r\n", _name[end]) != NULL)
      break;

  if (end - start >= (S3_CFG_MAX_ITEM_STR_LEN))
    return S3_CFG_INVALID_ID;
  strncpy(term, _name + start, end - start + 1);

  /* if hash lookup for item name succeeded, we return the id associated with
   * the name */
  if (hash_table_lookup(_cfg->name2id, term, &id) == 0)
    return (s3_cfg_id_t)id;
  else
    return add_item(_cfg, term)->id;
}
Example #27
0
int mail_session_connect_parse(const char *const *args, const char **error_r)
{
	struct mail_session *session;
	const char *session_id;
	pid_t pid;
	struct ip_addr ip;
	unsigned int i;

	/* <session id> <username> <service> <pid> [key=value ..] */
	if (str_array_length(args) < 4) {
		*error_r = "CONNECT: Too few parameters";
		return -1;
	}
	session_id = args[0];
	if (str_to_pid(args[3], &pid) < 0) {
		*error_r = t_strdup_printf("CONNECT: Invalid pid %s for session ID %s",
					   args[3], session_id);
		return -1;
	}

	session = hash_table_lookup(mail_sessions_hash, session_id);
	if (session != NULL) {
		*error_r = t_strdup_printf(
			"CONNECT: Duplicate session ID %s for user %s service %s",
			session_id, args[1], args[2]);
		return -1;
	}
	session = i_malloc(sizeof(struct mail_session) + stats_alloc_size());
	session->stats = (void *)(session + 1);
	session->refcount = 1; /* unrefed at disconnect */
	session->id = i_strdup(session_id);
	session->service = str_table_ref(services, args[2]);
	session->pid = pid;
	session->last_update = ioloop_timeval;
	session->to_idle = timeout_add(MAIL_SESSION_IDLE_TIMEOUT_MSECS,
				       mail_session_idle_timeout, session);

	session->user = mail_user_login(args[1]);
	for (i = 3; args[i] != NULL; i++) {
		if (strncmp(args[i], "rip=", 4) == 0 &&
		    net_addr2ip(args[i] + 4, &ip) == 0)
			session->ip = mail_ip_login(&ip);
	}

	hash_table_insert(mail_sessions_hash, session->id, session);
	DLLIST_PREPEND_FULL(&stable_mail_sessions, session,
			    stable_prev, stable_next);
	DLLIST2_APPEND_FULL(&mail_sessions_head, &mail_sessions_tail, session,
			    sorted_prev, sorted_next);
	DLLIST_PREPEND_FULL(&session->user->sessions, session,
			    user_prev, user_next);
	mail_user_ref(session->user);
	if (session->ip != NULL) {
		DLLIST_PREPEND_FULL(&session->ip->sessions, session,
				    ip_prev, ip_next);
		mail_ip_ref(session->ip);
	}
	global_memory_alloc(mail_session_memsize(session));
	return 0;
}
Example #28
0
/*
 * Check if domain given as value of pseudo variable parameter is local.
 */
int w_is_domain_local(struct sip_msg* _msg, char* _sp, char* _s2)
{
    pv_spec_t *sp;
    pv_value_t pv_val;
    struct attr_list *attrs;
    str did;

    sp = (pv_spec_t *)_sp;

    if (sp && (pv_get_spec_value(_msg, sp, &pv_val) == 0)) {
	if (pv_val.flags & PV_VAL_STR) {
	    if (pv_val.rs.len == 0 || pv_val.rs.s == NULL) {
		LM_DBG("missing domain name\n");
		return -1;
	    }
	    return hash_table_lookup(&(pv_val.rs), &did, &attrs);
	} else {
	   LM_DBG("domain pseudo variable value is not string\n");
	   return -1;
	}
    } else {
	LM_DBG("cannot get domain pseudo variable value\n");
	return -1;
    }
}
Example #29
0
struct sql_db *
sql_db_cache_new(struct sql_db_cache *cache,
		 const char *db_driver, const char *connect_string)
{
	struct sql_db_cache_context *ctx;
	struct sql_db *db;
	char *key;

	key = i_strdup_printf("%s\t%s", db_driver, connect_string);
	db = hash_table_lookup(cache->dbs, key);
	if (db != NULL) {
		ctx = SQL_DB_CACHE_CONTEXT(db);
		if (ctx->refcount == 0) {
			sql_db_cache_unlink(ctx);
			ctx->prev = ctx->next = NULL;
		}
		i_free(key);
	} else {
		sql_db_cache_drop_oldest(cache);

		ctx = i_new(struct sql_db_cache_context, 1);
		ctx->cache = cache;
		ctx->key = key;

		db = sql_init(db_driver, connect_string);
		ctx->orig_deinit = db->v.deinit;
		db->v.deinit = sql_db_cache_db_deinit;

		MODULE_CONTEXT_SET(db, sql_db_cache_module, ctx);
		hash_table_insert(cache->dbs, ctx->key, db);
	}

	ctx->refcount++;
	return db;
}
int verify()
{
  int j = 0;
  char str[512];
  node next_node;

  assert(node_list_length(thelist) == NUM_NODES);
  
  for (j = 0; j < NUM_NODES; j++) {
    snprintf(str, 512, "node(%d)", j);
    hash_table_lookup(thetable, str, (hash_data *)&next_node);
    if (next_node->data != j) {
      return 0;
    }
    if (node_list_head(thelist)->data != j) {
      return 0;
    }
    thelist = node_list_tail(thelist);
  }

  /* Try allocating something else */
  {
    node n = ralloc(newregion(), struct node_);
    n->next = NULL;
  }
  
  return 1;
}