예제 #1
0
파일: graph.c 프로젝트: nikmikov/misc
GraphNode*
graph_lookup_node (Graph *graph,
		   const char *name)
{
     ENTRY e,*ep;
     e.key = (char*)name;
     GraphNode  *node = NULL;
     hsearch_r (e, FIND, &ep, &graph->htab);
     if (ep != NULL)
	  node = ep->data;

     if (node == NULL) {

	  /* create and insert node */
	  node = malloc (sizeof (GraphNode));
	  node->name = (unsigned int)strtoul (name, NULL, 10);
	  node->num_edges = 0;
	  node->edges = malloc ( sizeof (GraphEdge*) *MIN_INITIAL_SIZE);	

	  ENTRY nentry = {strdup (name), node};	  
	  hsearch_r (nentry, ENTER, &ep, &graph->htab);
	  
	  /* add to nodes array */
	  graph_insert_node (graph, node);
     }

     return node;
}
예제 #2
0
/**
 * connect if no connection available
 * */
lib_ctx_t *
cln_get_context(const char *host, int port)
{
    int ret;
    lib_ctx_t *ctx;
    ENTRY rinfo, *pinfo;

    if(ctx_count==0)
      ret = cln_init();

    rinfo.key  = (char*)host;
    rinfo.data = NULL;      //should be a pointer to local context!!!
    if(hsearch_r(rinfo, FIND, &pinfo, &ctx_hosts)) {
        ctx = (lib_ctx_t*)(pinfo->data);
        assert(ctx!=NULL);
        ctx->rfd_count++;
        return ctx;
    } else if(errno == ESRCH) {
        ctx = cln_ctx_init(host, port);
        rinfo.key  = (char*)host;
        rinfo.data = ctx;
        ret = hsearch_r(rinfo, ENTER, &pinfo, &ctx_hosts);
        ctx_count++;
        assert(ret == 0);
        return ctx;
    }
    return NULL;
}
예제 #3
0
void handle_client(int client)
{
  const int line_size = 1000;
  char * line = calloc(sizeof(char), line_size);
  const char *delim = " \n";
  char *command = NULL, *arg1 = NULL, *arg2 = NULL, *savptr = NULL;
  recv(client, line, line_size, 0);
  
  command = strtok_r(line, delim, &savptr);
  arg1 = strtok_r(NULL, delim, &savptr);
  if (strcmp("set", command) == 0)
    arg2 = strtok_r(NULL, delim, &savptr);

  if (strcmp("set", command) == 0) {
    ENTRY e, *ret = NULL;
    e.key = strdup(arg1);
    e.data = strdup(arg2);
    hsearch_r(e, ENTER, &ret, store);
  } else if (strcmp("get", command) == 0) {
    ENTRY *ret = NULL, e;
    e.key = strdup(arg1);
    hsearch_r(e, FIND, &ret, store);
    sprintf(line, "%s\n", (char *)ret->data);
    send(client, line, line_size, 0);
  }
  close(client);
}
예제 #4
0
void set_cgi(char *name, char *value)
{
	ENTRY e, *ep;

	//cprintf("\nIn set_cgi(), name = %s, value = %s\n", name, value);

#ifdef __UCLIBC__
	if (!htab.table)
		return NULL;
#else
	if (!htab.__tab)
		return NULL;
#endif

	e.key = name;
	hsearch_r(e, FIND, &ep, &htab);
	if (ep) {
		//cprintf("\nIn set_cgi(), ep = %s\n", ep);
		ep->data = value;
	} else {
		//cprintf("\nIn set_cgi(), ep = %s(NULL)\n", ep);
		e.data = value;
		hsearch_r(e, ENTER, &ep, &htab);
		htab_count++;
	}
	assert(ep);
}
예제 #5
0
void jrst_filter_init (void)
{
  char *filename = getenv ("JRST_FILTER");
  if (!filename) {
    return;
  }

  FILE *file = fopen (filename, "r");
  if (!file){
    return;
  }

  hcreate_r (1000, &classes);
  hcreate_r (1000, &methods);
  hash_initialized = 1;

  char p1[JRST_MAX_STRING];
  ParseState state = ParseStart;
  while (!feof(file)){
    fscanf (file, "%s", p1);
    switch (state){
    case ParseStart:
      switch (p1[0]){
      case 'C': state = ParseClass; break;
      case 'M': state = ParseMethod; break;
      }
      break;
    case ParseClass:
      {
        ENTRY e, *ep = NULL;
        e.key = p1;
        e.data = NULL;
        hsearch_r (e, FIND, &ep, &classes);
        if (ep == NULL){
          e.key = strdup (p1);
          e.data = NULL;
          hsearch_r (e, ENTER, &ep, &classes);
        }
      }
      state = ParseStart;
      break;
    case ParseMethod:
      {
        ENTRY e, *ep = NULL;
        e.key = p1;
        e.data = NULL;
        hsearch_r (e, FIND, &ep, &methods);
        if (ep == NULL){
          e.key = strdup (p1);
          e.data = NULL;
          hsearch_r (e, ENTER, &ep, &methods);
        }
      }
      state = ParseStart;
      break;
    }     
  }
  fclose(file);
}
예제 #6
0
static void
stat_add(char *name, TSMgmtInt amount, TSStatPersistence persist_type, TSMutex create_mutex)
{
int stat_id = -1;
ENTRY search, *result = NULL;
static __thread struct hsearch_data stat_cache;
static __thread bool hash_init = false;

if (unlikely(!hash_init)) {
    hcreate_r(TS_MAX_API_STATS << 1, &stat_cache);
    hash_init = true;
    TSDebug(DEBUG_TAG, "stat cache hash init");
}

search.key  = name;
search.data = 0;
hsearch_r(search, FIND, &result, &stat_cache);

if (unlikely(result == NULL)) {
    // This is an unlikely path because we most likely have the stat cached
    // so this mutex won't be much overhead and it fixes a race condition
    // in the RecCore. Hopefully this can be removed in the future.
    TSMutexLock(create_mutex);
    if (TS_ERROR == TSStatFindName((const char *)name, &stat_id)) {
        stat_id = TSStatCreate((const char *)name, TS_RECORDDATATYPE_INT, persist_type, TS_STAT_SYNC_SUM);
        if (stat_id == TS_ERROR) {
            TSDebug(DEBUG_TAG, "Error creating stat_name: %s", name);
        } else {
            TSDebug(DEBUG_TAG, "Created stat_name: %s stat_id: %d", name, stat_id);
        }
    }
    TSMutexUnlock(create_mutex);

    if (stat_id >= 0) {
        search.key  = TSstrdup(name);
        search.data = (void *)((intptr_t)stat_id);
        hsearch_r(search, ENTER, &result, &stat_cache);
        TSDebug(DEBUG_TAG, "Cached stat_name: %s stat_id: %d", name, stat_id);
    }
} else {
    stat_id = (int)((intptr_t)result->data);
}

if (likely(stat_id >= 0)) {
    TSStatIntIncrement(stat_id, amount);
} else {
    TSDebug(DEBUG_TAG, "stat error! stat_name: %s stat_id: %d", name, stat_id);
}
}
예제 #7
0
int hdelete_r(const char *key, struct hsearch_data *htab)
{
	ENTRY e, *ep;
	int idx;

	debug("hdelete: DELETE key \"%s\"\n", key);

	e.key = (char *)key;

	if ((idx = hsearch_r(e, FIND, &ep, htab)) == 0) {
		__set_errno(ESRCH);
		debug("hdelete: not found\n");
		return 0;	/* not found */
	}

	/* free used ENTRY */
	debug("hdelete: DELETING key \"%s\"\n", key);

	free(ep->key);
	free(ep->data);
	htab->table[idx].used = -1;

	--htab->filled;

	return 1;
}
예제 #8
0
파일: modules.c 프로젝트: jberaud/lttng2lxt
void modules_init(void)
{
	unsigned int modcnt;
	int i, status;
	ENTRY entry, *ret;

	status = hcreate_r(100, &table);
	assert(status);

    modcnt = &__modules_end-&__modules_begin-1;
	INFO("modules (%d):", modcnt);

	for (i = 0; i < modcnt; i++) {
		entry.key = mk_module_key(modtab[i].channel, modtab[i].name);
		entry.data = &modtab[i];
		status = hsearch_r(entry, ENTER, &ret, &table);
        assert(status);
		if (verbose) {
			fprintf(stderr, " %s.%s", modtab[i].channel, modtab[i].name);
		}
	}
	if (verbose) {
		fprintf(stderr,"\n");
	}
}
예제 #9
0
파일: cmd_nvedit.c 프로젝트: aosp/uboot
/*
 * Command interface: print one or all environment variables
 *
 * Returns 0 in case of error, or length of printed string
 */
static int env_print(char *name)
{
	char *res = NULL;
	size_t len;

	if (name) {		/* print a single name */
		ENTRY e, *ep;

		e.key = name;
		e.data = NULL;
		hsearch_r(e, FIND, &ep, &env_htab);
		if (ep == NULL)
			return 0;
		len = printf("%s=%s\n", ep->key, ep->data);
		return len;
	}

	/* print whole list */
	len = hexport_r(&env_htab, '\n', &res, 0);

	if (len > 0) {
		puts(res);
		free(res);
		return len;
	}

	/* should never happen */
	return 0;
}
예제 #10
0
파일: ibc.c 프로젝트: vitovitolo/test
static const char *get_inotify_event_path(int wfd, const char *name) {
    static char buf[FILEPATH_BUF_SZ];

    int err;
    char *rv;
    ENTRY entry, *entry_rv;

    rv = NULL;
     entry.key = wfd2str(wfd);
     entry.data = NULL;

    err = hsearch_r(entry, FIND, &entry_rv, &ibc.htab);
    if (err == 0) {
        perror("hsearch_r");
        goto hsearch_r_err;
    }

    if (entry_rv != NULL) {
         snprintf(buf, FILEPATH_BUF_SZ, "%s/%s", (char *) entry_rv->data,
                 name);
         rv = buf;
    }

hsearch_r_err:
     free(entry.key);
     return rv;
}
예제 #11
0
int mod_static_init() {
    int i;
    int j;
    size_t size;
    ENTRY item, *ret;
    char **ext = NULL;

    size = sizeof(standard_types) / sizeof(standard_types[0]);

    bzero(&std_mime_type_hash, sizeof(struct hsearch_data));
    if (hcreate_r(size * 2, &std_mime_type_hash) == 0) {
        error("Error creating standard MIME type hash");
        return -1;
    }
    for (i = 0; i < size; i++) {
        for (ext = standard_types[i].exts, j = 0;
             *ext != NULL && j < FILE_TYPE_COUNT;
             ext++, j++) {
            item.key = *ext;
            item.data = standard_types[i].content_type;
            debug("Registering standard MIME type %s:%s",
                  *ext, standard_types[i].content_type);
            if (hsearch_r(item, ENTER, &ret, &std_mime_type_hash) == 0) {
                error("Error entering standard MIME type");
            }
        }
    }
    return 0;
}
예제 #12
0
파일: ibc.c 프로젝트: vitovitolo/test
static int nftw_callback(const char *fpath, const struct stat *sb,
        int typeflag, struct FTW *ftwbuf) {
    int wfd, err;
    ENTRY entry, *entry_rv;

    if (typeflag != FTW_D)
        return 0;

    err = wfd = inotify_add_watch(ibc.fd, fpath, IN_CLOSE_WRITE | IN_MOVED_TO);
    if (err == -1) {
        perror("inotify_add_watch");
         return -1;
    }

    /* TODO: Memory assigned but never free, only in start so it will not
     * cause problems */
    entry.key = wfd2str(wfd);
    entry.data = (void *) strdup(fpath);
    err = hsearch_r(entry, ENTER, &entry_rv, &ibc.htab);
    if (err == 0) {
        perror("hsearch_r");
        return -1;
    }
    return 0;
}
예제 #13
0
static void handle_content_type(response_t *resp, const char *filepath) {
    char  *content_type = NULL, ext[20];
    int   dot_pos = -1;
    int   i;
    size_t  len = strlen(filepath);
    ENTRY   item, *ret;

    for (i = len - 1; i > 0; i--) {
        if (filepath[i] == '.') {
            dot_pos = i;
            break;
        }
    }

    if (dot_pos < 0) {
        // No '.' found in the file name (no extension part)
        return;
    }

    strncpy(ext, filepath + 1 + dot_pos, 20);
    strlowercase(ext, ext, 20);
    debug("File extension: %s", ext);
    
    item.key = ext;
    if (hsearch_r(item, FIND, &ret, &std_mime_type_hash) == 0) {
        return;
    }
    content_type = (char*) ret->data;
    if (content_type != NULL) {
        debug("Content type: %s", content_type);
        response_set_header(resp, "Content-Type", content_type); 
    }
}
예제 #14
0
파일: hash.c 프로젝트: clflush/tty64
void hashtable_delete(hashtable *hash, char *key) {
	ENTRY e, *ep;

	e.key = key;

	/* CRITICAL SECTION */
	pthread_mutex_lock(&hash_mutex);
		
	if (!hash || hsearch_r(e, FIND, &ep, hash) < 1) {
		pthread_mutex_unlock(&hash_mutex);
		return ;
	}

	free(ep->key);

	if (ep->data) {
		free(ep->data);
		ep->data = NULL;
	}

	pthread_mutex_unlock(&hash_mutex);
	/* CRITICAL SECTION */

	return ;
}
예제 #15
0
// FIXME: what should we do with object_name?? The library names are obtained
// by parsing /proc/<pid>/maps, which may not be the same as object_name.
// What we need is a utility to map object_name to real file name, something
// dlopen() does by looking at LD_LIBRARY_PATH and /etc/ld.so.cache. For
// now, we just ignore object_name and do a global search for the symbol.
address lookup_symbol(pid_t pid, const char *object_name, 
                      const char *sym_name, int *sym_size) {
  lib_info *lib;

  lib = debuggee.libs;
  for (lib = debuggee.libs; lib; lib = lib->next) {
    ENTRY item;
    ENTRY *ret;

    // library does not have symbol table
    if (!lib->symtab || !lib->symtab->hash_table) continue;

    item.key = strdup(sym_name);
    hsearch_r(item, FIND, &ret, lib->symtab->hash_table);

    if (ret) {
      struct elf_symbol * sym = (struct elf_symbol *)(ret->data);
      address rslt = lib->base + sym->offset;
      if (sym_size) *sym_size = sym->size;
      free(item.key);
      return rslt;
    }

    free(item.key);
  }

  return NULL;
} 
예제 #16
0
/*
 * Call for each element in the list that associates variables to callbacks
 */
static int set_callback(const char *name, const char *value, void *priv)
{
	ENTRY e, *ep;
	struct env_clbk_tbl *clbkp;

	e.key	= name;
	e.data	= NULL;
	e.callback = NULL;
	hsearch_r(e, FIND, &ep, &env_htab, 0);

	/* does the env variable actually exist? */
	if (ep != NULL) {
		/* the assocaition delares no callback, so remove the pointer */
		if (value == NULL || strlen(value) == 0)
			ep->callback = NULL;
		else {
			/* assign the requested callback */
			clbkp = find_env_callback(value);
			if (clbkp != NULL)
#if defined(CONFIG_NEEDS_MANUAL_RELOC)
				ep->callback = clbkp->callback + gd->reloc_off;
#else
				ep->callback = clbkp->callback;
#endif
		}
	}

	return 0;
}
예제 #17
0
파일: args.c 프로젝트: jkkm/latrace
static struct lt_enum* getenum(struct lt_config_shared *cfg, char *name)
{
	struct lt_enum *en;
	ENTRY e, *ep;

	PRINT_VERBOSE(cfg, 1, "request for <%s>\n", name);

	if (!enum_init) {
		PRINT_VERBOSE(cfg, 1, "no enum added so far\n", name);
		return NULL;
	}

	e.key = name;
	hsearch_r(e, FIND, &ep, &args_enum_tab);

	if (!ep) {
		PRINT_VERBOSE(cfg, 1, "failed to find enum <%s>\n", name);
		return NULL;
	}

	en = (struct lt_enum*) ep->data;

	PRINT_VERBOSE(cfg, 1, "found %p <%s>\n", en, en->name);
	return en;
}
예제 #18
0
static struct entity *
add_ent (char *name)
{
    struct entity *e = malloc (sizeof (*e));
    e->entity_name = malloc (strlen (name) + 1);
    if (e->entity_name == 0)
    {
        perror ("Unable to allocate memory for name\n");
        exit (2);

    }
    strcpy (e->entity_name, name);
    e->num_links = -1;
    e->links = (void *) 0;

    ENTRY *ent;
    ent = malloc (sizeof (*ent));
    if (ent == NULL)
    {
        perror ("cannot allocate entry");
        exit (2);
    }
    ent->key = e->entity_name;
    ent->data = e;
    if (hsearch_r (name, ENTER, &ent, &htab) != 0)
    {
        perror ("failed to add word ");
        exit (4);
    }
    return e;
}
예제 #19
0
파일: hsearch.c 프로젝트: 16rd/rt-n56u
/* Define the non-reentrant function using the reentrant counterparts.  */
ENTRY *hsearch (ENTRY item, ACTION action)
{
  ENTRY *result;

  (void) hsearch_r (item, action, &result, &htab);

  return result;
}
예제 #20
0
파일: pcflib.c 프로젝트: bt3ze/lccyao
PCFOP * read_label(const char * line, struct PCFState * st, uint32_t iptr)
{
  ENTRY * newent, * r;
  char buf[LINE_MAX], *bitr;
  PCFOP * ret = malloc(sizeof(struct PCFOP));
  check_alloc(ret);

  ret->op = nop;

  bitr = buf;
  
  line = skip_to_colon(line);

  // Skip over the ':'
  line++;

  line = assert_token(line, buf, bitr, "STR");

  while((line[0] == ' ') || (line[0] == '"'))
    {
      assert(line[0] != '\0');
      line++;
    }

  bitr = buf;

  while((line[0] != ' ') && (line[0] != '"') && (line[0] != ')'))
    {
      assert(line[0] != '\0');
      bitr[0] = line[0];
      line++;
      bitr++;
    }
  bitr[0] = '\0';

  newent = (ENTRY*)malloc(sizeof(ENTRY));
  check_alloc(newent);

  newent->key = malloc(strlen(buf)+1);
  check_alloc(newent->key);
  strcpy(newent->key, buf);

  newent->data = malloc(sizeof(uint32_t));
  check_alloc(newent->data);
  *((uint32_t*)newent->data) = iptr;

  //hsearch_r(*newent, ENTER, &r, st->labels);

  if(hsearch_r(*newent, ENTER, &r, st->labels) == 0)
    {
      fprintf(stderr, "Problem inserting hash table for %s %d: %s\n", newent->key, *((uint32_t*)newent->data), strerror(errno));
      abort();
    }


  return ret;
}
예제 #21
0
void webcgi_set(char *name, char *value)
{
       ENTRY e, *ep;
 
       if (!htab.table) {
               hcreate_r(16, &htab);
       }
 
       e.key = name;
       hsearch_r(e, FIND, &ep, &htab);
       if (ep) {
               ep->data = value;
       }
       else {
               e.data = value;
               hsearch_r(e, ENTER, &ep, &htab);
       }
}
예제 #22
0
void
set_cgi(char *name, char *value)
{
	ENTRY e, *ep;

	if (!htab.table)
		return;

	e.key = name;
	hsearch_r(e, FIND, &ep, &htab);
	if (ep)
		ep->data = value;
	else {
		e.data = value;
		hsearch_r(e, ENTER, &ep, &htab);
	}
	assert(ep);
}
예제 #23
0
/*
 * Find a fs handle for the given key. Returns a fs handle, 
 * or NULL if there is no fs for the given key.
 */
static hdfsFS findFs(char *key) {
  ENTRY entry;
  ENTRY *entryP = NULL;
  entry.key = key;
  if (0 == hsearch_r(entry, FIND, &entryP, fsTable)) {
    return NULL;
  }
  assert(NULL != entryP->data);
  return (hdfsFS)entryP->data;
}
예제 #24
0
///////////vvvvvvvvvvvvvvvvvvv//////////////////Viz add 2010.08
char *webcgi_get(const char *name)
{
       ENTRY e, *ep;
 
       if (!htab.table) return NULL;
 
       e.key = (char *)name;
       hsearch_r(e, FIND, &ep, &htab); 
       return ep ? ep->data : NULL;
}
예제 #25
0
static struct entity *
find_entity (struct entity *e, int max, char *word)
{
    ENTRY *ent;
    struct entity *ret = NULL;
    if (hsearch_r (word, FIND, &ent, &htab) != 0)
    {
        ret = ent->data;
    }
    return ret;
}
예제 #26
0
void
hash_put_element(struct hsearch_data * table, char * key, void * data)
{
    ENTRY new_entry = { key, data };
    ENTRY *ret_entry = &new_entry;
    check(table, "hash_put_element: table is NULL -> fail to insert a key");
    check(key, "hash_put_element: key is NULL -> fail to insert a key");
    check(hsearch_r(new_entry, ENTER, &ret_entry, table), "hash_put_element: fail to insert a key");
    ret_entry->data = data;
    error:
    return;
}
예제 #27
0
void* hook_find(const char *func_name)
{
    ENTRY e, *ep=NULL;
    e.key = func_name;
    int rv = hsearch_r(e, FIND, &ep, htab);
    if (!rv) {
        return NULL;
    }

    LOGD("FOUND:%s",func_name,ep->data);
    return ep->data;
}
예제 #28
0
파일: cgi.c 프로젝트: Lvlynn/android
//获取ajax 传递过来的变量名对应的参数"
char *
get_cgi(char *name)
{
	ENTRY e, *ep;

	if (!htab.table)
		return NULL;

	e.key = name;
	hsearch_r(e, FIND, &ep, &htab);

	return ep ? ep->data : NULL;
}
예제 #29
0
void handle_client(int client)
{
    const int line_size = 1000;
    char * line = calloc(sizeof(char), line_size);
    const char *delim = " \n";
    char *command = NULL, *arg1 = NULL, *arg2 = NULL, *savptr = NULL;

    while (1) {
        kitsune_update("client");

        memset(line, 0, line_size);
        recv(client, line, line_size, 0);

        /* parse command */
        command = strtok_r(line, delim, &savptr);
        if (command == NULL)        /* client sent EOF */
            break;
        arg1 = strtok_r(NULL, delim, &savptr);
        if (strcmp("set", command) == 0)
            arg2 = strtok_r(NULL, delim, &savptr);

        /* handle */
        if (strcmp("set", command) == 0) {
            ENTRY e, *ret = NULL;
            e.key = strdup(arg1);
            e.data = strdup(arg2);
            hsearch_r(e, ENTER, &ret, store);
        } else if (strcmp("get", command) == 0) {
            ENTRY *ret = NULL, e;
            e.key = strdup(arg1);
            hsearch_r(e, FIND, &ret, store);
            if (ret == NULL)
                continue;
            sprintf(line, "%s\n", (char *)ret->data);
            send(client, line, strlen(line) + 1, 0);
        }
    }
    close(client);
}
예제 #30
0
///////////vvvvvvvvvvvvvvvvvvv//////////////////Viz add 2010.08
char *webcgi_get(const char *name)
{
       ENTRY e, *ep;
 
       if (!htab.table) return NULL;
 
       e.key = (char *)name;
       hsearch_r(e, FIND, &ep, &htab);
 
//    cprintf("%s=%s\n", name, ep ? ep->data : "(null)");
 
       return ep ? ep->data : NULL;
}