示例#1
0
static void springfield_set_i(springfield_t *r, char *key, uint8_t *val, uint32_t vlen) {
    int klen = strlen(key) + 1;
    assert(klen < MAX_KLEN);
    assert(vlen < MAX_VLEN);

    uint32_t step = HEADER_SIZE + klen + vlen;
    springfield_header_v1 h = {0};
    h.klen = klen;
    h.vlen = vlen;
    h.version = 1;

    if (r->in_rewrite) {
        springfield_key_t *kobj = NULL;
        HASH_FIND(hh, r->rewrite_keys, key, klen, kobj);
        if (!kobj) {
            kobj = calloc(1, sizeof(springfield_key_t));
            kobj->key = strdup(key);
            HASH_ADD_KEYPTR(hh, r->rewrite_keys, key, klen, kobj);
        }
    }

    if (r->eof + step > r->mmap_alloc) {
        msync(r->map, r->mmap_alloc, MS_SYNC);
        int s = munmap(r->map, r->mmap_alloc);
        assert(!s);
        uint64_t new_size = r->mmap_alloc + ((r->eof + step) * 2);
        r->mmap_alloc = new_size;
        s = ftruncate(r->mapfd, (off_t)r->mmap_alloc);
        assert(!s);
        r->map = (uint8_t *)mmap(
            NULL, r->mmap_alloc, PROT_READ | PROT_WRITE, MAP_SHARED, r->mapfd, 0);
        /* TODO mremap() on linux */
        s = madvise(r->map, r->mmap_alloc, MADV_RANDOM);
        assert(!s);
    }

    h.last = springfield_index_keyval(r, key, r->eof);
    uint8_t *p = &r->map[r->eof];

    springfield_header_v1 *ph = (springfield_header_v1 *)p;

    *ph = h;

    memmove(p + HEADER_SIZE, key, klen);
    if (vlen)
        memmove(p + HEADER_SIZE + klen, val, vlen);

    ph->crc = crc32(0, p + 4, HEADER_SIZE_MINUS_CRC + klen + vlen);

    r->eof += step;
}
示例#2
0
void symbol_insert(const char* name, LLVMValueRef val, int isArg)
{
  struct symbol_info *si;

  if (head==NULL)
    return;

  si = (struct symbol_info*) malloc(sizeof(struct symbol_info));
  si->name = (char*)name;
  si->isArg = isArg;
  si->val = val;

  HASH_ADD_KEYPTR( hh, head->map, name, strlen(name), si );
}
示例#3
0
STATIC UByte PancakeAuthenticationNameConfiguration(UByte step, config_setting_t *setting, PancakeConfigurationScope **scope) {
	PancakeAuthenticationConfiguration *config = (PancakeAuthenticationConfiguration*) setting->parent->hook;

	if(step == PANCAKE_CONFIGURATION_INIT) {
		config->name.value = setting->value.sval;
		config->name.length = strlen(setting->value.sval);

		HASH_ADD_KEYPTR(hh, PancakeAuthenticationConfigurations, config->name.value, config->name.length, config);
	} else {
		HASH_DEL(PancakeAuthenticationConfigurations, config);
	}

	return 1;
}
示例#4
0
static void listen_device_if_not_present(const char *devnode)
{
	struct hash_element *same_elem = NULL;
	HASH_FIND_STR(fdhash, devnode, same_elem);
	if (same_elem) {
		return;
	}
	struct hash_element *elem = hash_element_from_devnode(devnode);
	if (!elem) {
		return;
	}
	HASH_ADD_KEYPTR(hh, fdhash, elem->devnode, strlen(elem->devnode), elem);
	FD_SET(elem->fd, &evdevfds);
}
olsr_db_ns_tuple_t* olsr_db_ns_gcneigh(uint8_t neighbor_main_addr[ETH_ALEN]) {
    olsr_db_ns_tuple_t* tuple;
    HASH_FIND(hh, neighbor_set, neighbor_main_addr, ETH_ALEN, tuple);

    if(tuple == NULL) {
        if(ntuple_create(&tuple, neighbor_main_addr) == false) {
            return false;
        }

        HASH_ADD_KEYPTR(hh, neighbor_set, tuple->neighbor_main_addr, ETH_ALEN, tuple);
    }

    return tuple;
}
示例#6
0
static FcitxHandlerKey*
fcitx_handler_table_key_struct(FcitxHandlerTable *table, size_t keysize,
                               const void *key, boolean create)
{
    FcitxHandlerKey *key_struct = NULL;
    HASH_FIND(hh, table->keys, key, keysize, key_struct);
    if (key_struct || !create)
        return key_struct;
    key_struct = malloc(sizeof(FcitxHandlerKey) + keysize);
    key_struct->first = key_struct->last = FCITX_OBJECT_POOL_INVALID_ID;
    memcpy(key_struct + 1, key, keysize);
    key = key_struct + 1;
    HASH_ADD_KEYPTR(hh, table->keys, key, keysize, key_struct);
    return key_struct;
}
struct document_frequencies_hash* frequencies_hash_to_bins(struct score_hash *scores) {
	struct score_hash *s;
	struct document_frequencies_hash *tmp, *bins_hash = NULL;
	int bin_index = 0;
	HASH_SORT(scores, ascending_score_sort);
	for(s=scores; s != NULL; s = s->hh.next) {
		if (s->score >= 10.5) { break; } // Filter >4 frequent words
		tmp = (struct document_frequencies_hash*)malloc(sizeof(struct document_frequencies_hash));
		tmp->word = strdup(s->word);
		tmp->count = ++bin_index;
		HASH_ADD_KEYPTR( hh, bins_hash, tmp->word, strlen(tmp->word), tmp );
	}
	fprintf(stderr, "Total bins: %d\n",bin_index);
	return bins_hash;
}
示例#8
0
文件: update.c 项目: renchap/pkg
static void
pkg_update_increment_item_new(struct pkg_increment_task_item **head, const char *origin,
		const char *digest, long offset)
{
	struct pkg_increment_task_item *item;

	item = calloc(1, sizeof(struct pkg_increment_task_item));
	item->origin = strdup(origin);
	if (digest == NULL)
		digest = "";
	item->digest = strdup(digest);
	item->offset = offset;

	HASH_ADD_KEYPTR(hh, *head, item->origin, strlen(item->origin), item);
}
示例#9
0
Texture* 
getTextureID(char* path)  {
    Texture *s;
    HASH_FIND_STR( pathToTexTable, path, s );  /* s: output pointer */
    if(s == NULL)  {
        s = (Texture*)malloc(sizeof(Texture));
        s->path = (char*)malloc(strlen(path)*sizeof(char));
        strcpy(s->path, path);
        s->textureID = ilutGLLoadImage(path);
        s->width = ilGetInteger(IL_IMAGE_WIDTH);
        s->height = ilGetInteger(IL_IMAGE_HEIGHT);
        HASH_ADD_KEYPTR( hh, pathToTexTable, s->path, strlen(s->path), s );
    }
    return s;
}
示例#10
0
Module load_module(char *mn) {
  char *modname = malloc(sizeof(char)*768);
  snprintf(modname, 767, "%s/%s.so", DPATH "/modules", mn);
  int (*mod_init)();
  void *modhand;
  struct loaded_module *mod = malloc(sizeof(struct loaded_module));
  modhand = mod->hand = dlopen(modname, RTLD_LAZY);
  mod->name = strdup(mn);
  if (modhand == NULL) exit(64);
  mod_init = (int (*)())dlsym(modhand, "mod_init");
  if (mod_init) (*mod_init)();
  else exit(65);
  HASH_ADD_KEYPTR(hh, mods, mod->name, strlen(mod->name), mod);
  return mod;
};
示例#11
0
文件: pkg_config.c 项目: dumbbell/pkg
static void
pkg_repo_overwrite(struct pkg_repo *r, const char *name, const char *url,
    const char *type)
{

	free(r->name);
	r->name = strdup(name);
	if (url != NULL) {
		free(r->url);
		r->url = strdup(url);
	}
	r->ops = pkg_repo_find_type(type);
	HASH_DEL(repos, r);
	HASH_ADD_KEYPTR(hh, repos, r->name, strlen(r->name), r);
}
示例#12
0
文件: punc.c 项目: adaptee/fcitx
/**
 * 加载标点词典
 * @param void
 * @return void
 * @note 文件中数据的格式为: 对应的英文符号 中文标点 <中文标点>
 * 加载标点词典。标点词典定义了一组标点转换,如输入‘.’就直接转换成‘。’
 */
boolean LoadPuncDict(FcitxPuncState* puncState)
{
    FcitxStringHashSet* puncfiles = FcitxXDGGetFiles("data", PUNC_DICT_FILENAME "." , NULL);
    FcitxStringHashSet *curpuncfile = puncfiles;
    FcitxPunc* punc;
    while (curpuncfile) {
        punc = LoadPuncFile(curpuncfile->name);
        if (punc)
            HASH_ADD_KEYPTR(hh, puncState->puncSet, punc->langCode, strlen(punc->langCode), punc);
        curpuncfile = curpuncfile->hh.next;
    }

    fcitx_utils_free_string_hash_set(puncfiles);
    return true;
}
示例#13
0
文件: skin.c 项目: niubenben/fcitx
SkinImage* LoadImage(FcitxSkin* sc, const char* name, boolean fallback)
{
    cairo_surface_t *png = NULL;
    SkinImage *image = NULL;

    HASH_FIND_STR(sc->imageTable, name, image);
    if (image != NULL) {
        return image;
    }
    if (strlen(name) > 0 && strcmp(name , "NONE") != 0) {
        char *skintype = strdup(*sc->skinType);
        char *filename;
        while (true) {
            char* buf = NULL;
            asprintf(&buf, "skin/%s", skintype);

            FILE* fp = FcitxXDGGetFileWithPrefix(buf, name, "r", &filename);
            free(buf);

            Bool flagNoFile = (fp == NULL);
            if (fp) {
                fclose(fp);

                png = cairo_image_surface_create_from_png(filename);
                break;
            }
            if (flagNoFile && (!fallback || strcmp(skintype, "default") == 0)) {
                png = NULL;
                break;
            }

            free(filename);
            free(skintype);
            skintype = strdup("default");
        }
        free(filename);
        free(skintype);
    }

    if (png != NULL) {
        image = fcitx_utils_malloc0(sizeof(SkinImage));
        image->name = strdup(name);
        image->image = png;
        HASH_ADD_KEYPTR(hh, sc->imageTable, image->name, strlen(image->name), image);
        return image;
    }
    return NULL;
}
示例#14
0
文件: skin.c 项目: areslp/fcitx
SkinImage* LoadImageWithText(FcitxClassicUI* classicui, FcitxSkin* sc, const char* name, const char* text, int w, int h, boolean active)
{
    if (!text || *text == '\0')
        return NULL;

    UnloadSingleImage(sc, name);

    int len = fcitx_utf8_char_len(text);
    if (len == 1 && text[len] && fcitx_utf8_char_len(text + len) == 1)
        len = 2;

    char* iconText = strndup(text, len);

    FcitxLog(DEBUG, "%s", iconText);

    cairo_surface_t* newsurface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h);
    cairo_t* c = cairo_create(newsurface);

    int min = w > h? h: w;
    min = min * 0.8;

    cairo_set_operator(c, CAIRO_OPERATOR_SOURCE);
    cairo_set_source_rgba(c ,1, 1, 1, 0.0);
    cairo_paint(c);

    FcitxConfigColor color;
    if (sc->skinMainBar.bUseCustomTextIconColor) {
        if (active)
            color = sc->skinMainBar.textIconColor[0];
        else
            color = sc->skinMainBar.textIconColor[1];
    }
    else
        color = sc->skinFont.menuFontColor[1];

    int textw, texth;
    StringSizeStrict(iconText, classicui->font, min, false, &textw, &texth);

    OutputString(c, iconText, classicui->font, min, false, (w - textw) * 0.5, 0, &color);

    cairo_destroy(c);
    SkinImage* image = fcitx_utils_malloc0(sizeof(SkinImage));
    image->name = strdup(name);
    image->image = newsurface;
    image->textIcon = true;
    HASH_ADD_KEYPTR(hh, sc->imageTable, image->name, strlen(image->name), image);
    return image;
}
示例#15
0
文件: search.c 项目: kdharsee/Search
void loadFile( FILE *fp ) { 
  char buf[BUFFER_SIZE];
  char *token;
  const char *delimeter_chars = " \n";
  frequencyListNode *ptr = NULL;
  hashNode *curr_hashNode = (hashNode *)malloc( sizeof( hashNode ) );
  
  while ( fgets( buf, BUFFER_SIZE, fp ) != NULL ) {

    token = strtok( buf, delimeter_chars ); /* Stores the first <list> */

    while ( token != NULL ) {

      if ( strcmp( token, "<list>" ) == 0 ) {
	token = strtok( NULL, delimeter_chars ); /* Stores the word in reference of the list */
	curr_hashNode->word = (char *)malloc( sizeof( char ) * strlen( token ) + 1 );
	strcpy( curr_hashNode->word, token );
      }

      else if ( strcmp( token, "</list>" ) == 0 ) {
	/* Add the built list to the hashtable */
	HASH_ADD_KEYPTR( hh, inverted_index, curr_hashNode->word, strlen( curr_hashNode->word ), curr_hashNode );

	curr_hashNode = (hashNode *)malloc( sizeof( hashNode ) );
      }
      else {
	ptr = (frequencyListNode *)malloc( sizeof( frequencyListNode ) );
	ptr->file_path  = (char *)malloc( sizeof( char ) * strlen( token ) + 1 );
	strcpy( ptr->file_path, token );

	token = strtok( NULL, delimeter_chars ); /*Now holds the frequency of the word in previous file */
	ptr->frequency = 0;

	ptr->next = curr_hashNode->head;
	curr_hashNode->head = ptr;

      }

      token = strtok( NULL, delimeter_chars );

    }

  }
  free( curr_hashNode );

}
示例#16
0
static struct pkg_repo *
pkg_repo_new(const char *name, const char *url)
{
	struct pkg_repo *r;

	r = calloc(1, sizeof(struct pkg_repo));
	r->type = REPO_BINARY_PKGS;
	r->update = repo_update_binary_pkgs;
	r->url = strdup(url);
	r->signature_type = SIG_NONE;
	r->mirror_type = NOMIRROR;
	r->enable = true;
	asprintf(&r->name, REPO_NAME_PREFIX"%s", name);
	HASH_ADD_KEYPTR(hh, repos, r->name, strlen(r->name), r);

	return (r);
}
示例#17
0
struct mod_function *add_cb(char *mod, char *cbn, char *cbsym) {
  Module modu = NULL;
  ModFunc modf = malloc(sizeof(struct mod_function));
  HASH_FIND_STR(mods, mod, modu);
  if (modu != NULL) {
    int (*func)() = dlsym(modu->hand, cbsym);
    if (!func) return NULL;
    HASH_FIND_STR(modu->funcs, cbn, modf);
    if (modf == NULL) {
      modf->cb = cbn;
      modf->func = &func;
      HASH_ADD_KEYPTR(hh, modu->funcs, modf->cb, strlen(modf->cb), modf);
      return modf;
    }
  }
  return NULL;
};
示例#18
0
文件: pkg_config.c 项目: dumbbell/pkg
static struct pkg_repo *
pkg_repo_new(const char *name, const char *url, const char *type)
{
	struct pkg_repo *r;

	r = calloc(1, sizeof(struct pkg_repo));
	r->ops = pkg_repo_find_type(type);
	r->url = strdup(url);
	r->signature_type = SIG_NONE;
	r->mirror_type = NOMIRROR;
	r->enable = true;
	r->meta = pkg_repo_meta_default();
	r->name = strdup(name);
	HASH_ADD_KEYPTR(hh, repos, r->name, strlen(r->name), r);

	return (r);
}
示例#19
0
文件: update.c 项目: zxombie/pkg
static void
pkg_repo_binary_update_item_new(struct pkg_increment_task_item **head, const char *origin,
		const char *digest, long offset, long length, const char *checksum)
{
	struct pkg_increment_task_item *item;

	item = calloc(1, sizeof(struct pkg_increment_task_item));
	item->origin = strdup(origin);
	if (digest == NULL)
		digest = "";
	item->digest = strdup(digest);
	item->offset = offset;
	item->length = length;
	if (checksum)
		item->checksum = strdup(checksum);

	HASH_ADD_KEYPTR(hh, *head, item->origin, strlen(item->origin), item);
}
示例#20
0
文件: string.c 项目: Custard7/robovm
/**
 * Adds a string to the cache of interned string. The string must not already be
 * interned.  The internedStringsLock MUST be held when calling this function.
 */
static jboolean addInternedString(Env* env, const char* s,  Object* string) {
    CacheEntry* cacheEntry = allocateMemoryOfKind(env, sizeof(CacheEntry), cacheEntryGCKind);
    if (!cacheEntry) {
        return FALSE;
    }

    cacheEntry->key = s;
    cacheEntry->string = string;
    HASH_ADD_KEYPTR(hh, internedStrings, cacheEntry->key, strlen(cacheEntry->key), cacheEntry);

    // prune the cache to MAX_CACHE_SIZE
    if (HASH_COUNT(internedStrings) >= MAX_CACHE_SIZE) {
        CacheEntry* tmpEntry;
        HASH_ITER(hh, internedStrings, cacheEntry, tmpEntry) {
            // prune the first entry (loop is based on insertion order so this deletes the oldest item)
            HASH_DELETE(hh, internedStrings, cacheEntry);
            break;
        }
示例#21
0
CloudPinyinCache* CloudPinyinAddToCache(FcitxCloudPinyin* cloudpinyin, const char* pinyin, char* string)
{
    CloudPinyinCache* cacheEntry = fcitx_utils_malloc0(sizeof(CloudPinyinCache));
    cacheEntry->pinyin = strdup(pinyin);
    cacheEntry->str = strdup(string);
    HASH_ADD_KEYPTR(hh, cloudpinyin->cache, cacheEntry->pinyin, strlen(cacheEntry->pinyin), cacheEntry);

    /* if there is too much cached, remove the first one, though LRU might be a better algorithm */
    if (HASH_COUNT(cloudpinyin->cache) > MAX_CACHE_ENTRY)
    {
        CloudPinyinCache* head = cloudpinyin->cache;
        HASH_DEL(cloudpinyin->cache, cloudpinyin->cache);
        free(head->pinyin);
        free(head->str);
        free(head);
    }
    return cacheEntry;
}
示例#22
0
文件: dump.c 项目: JulienPalard/Mine
static void kick_all_uniques(struct node *node, struct node **uniq)
{
    struct node *search;

    while (HASH_COUNT(node->childs) == 1)
    {
        HASH_FIND_STR(*uniq, node->childs->word, search);
        if (search == NULL)
        {
            search = malloc(sizeof(*search));
            search->childs = NULL;
            search->word = node->childs->word;
            HASH_ADD_KEYPTR(hh, *uniq, search->word, strlen(search->word),
                            search);
        }
        node = node->childs;
    }
}
示例#23
0
LightUIImage* LoadImage(struct _FcitxLightUI* lightui, const char* name)
{
    XImage* xpm = NULL, *mask = NULL;
    LightUIImage *image = NULL;

    HASH_FIND_STR(lightui->imageTable, name, image);
    if (image != NULL)
        return image;
    if ( strlen(name) > 0 )
    {
        int i = 0;
        while (builtInImage[i].name != NULL)
        {
            if (strcmp(builtInImage[i].name, name) == 0)
            {
                XpmAttributes   attrib;

                attrib.valuemask = 0;

                XpmCreateImageFromData (lightui->dpy, builtInImage[i].data , &xpm, &mask, &attrib);
                break;
            }
            i ++;
        }
    }

    if (xpm != NULL)
    {
        image = fcitx_malloc0(sizeof(LightUIImage));
        image->name = strdup(name);
        image->image = xpm;
        image->mask = mask;
        image->pixmask = XCreatePixmap(lightui->dpy, DefaultRootWindow(lightui->dpy), mask->width, mask->height, mask->depth);
        GC gc = XCreateGC (lightui->dpy, image->pixmask, 0, NULL);
        XPutImage(lightui->dpy, image->pixmask, gc, image->mask, 0, 0, 0, 0, mask->width, mask->height);
        XFreeGC(lightui->dpy, gc);

        HASH_ADD_KEYPTR(hh, lightui->imageTable, image->name, strlen(image->name), image);
        return image;
    }
    return NULL;
}
示例#24
0
文件: app.c 项目: stoni/luarest
static luarest_status verify_application(application** apps, const char* appName, UT_string* path)
{
	int ret;
	lua_State* ls = luaL_newstate();
	application* app;
	
	luaL_openlibs(ls);
	luaopen_luarestlibs(ls);
        
    ret = luaL_loadfile(ls, utstring_body(path));
    if (ret != 0) {
		printf("Couldn't load file: %s\n", lua_tostring(ls, -1));
		lua_close(ls);
		return(LUAREST_ERROR);
    }
	ret = lua_pcall(ls, 0, 0, 0);
    if (ret != 0) {
        printf("Couldn't execute LUA Script %s\n", lua_tostring(ls, -1));
		lua_close(ls);
		return(LUAREST_ERROR);
    }
	lua_getglobal(ls, "luarest_init");
    if (lua_isfunction(ls, -1) == 0) {
		printf("Couln'd find 'luarest_init' table in LUA script!\n");
		lua_close(ls);
		return(LUAREST_ERROR);
	}
	app = (application*)lua_newuserdata(ls, sizeof(application));
	luaL_getmetatable(ls, LUA_USERDATA_APPLICATION);
	lua_setmetatable(ls, -2);
	app->s = NULL;
	utstring_new(app->name);
	utstring_printf(app->name, appName);
	if (lua_pcall(ls, 1, 0, 0) != 0) {
		printf("Error calling luarest_init: %s\n!", lua_tostring(ls, -1));
		lua_close(ls);
		return(LUAREST_ERROR);
	}
	app->lua_state = ls;
	HASH_ADD_KEYPTR(hh, *apps, utstring_body(app->name), utstring_len(app->name), app);
	return(LUAREST_SUCCESS);
}
示例#25
0
文件: Sinproc.c 项目: bumptech/nitro
void Sinproc_socket_bound_add_conn(nitro_inproc_socket_t *b,
                                   nitro_inproc_socket_t *c) {

    pthread_rwlock_wrlock(&b->link_lock);

    HASH_ADD_KEYPTR(bound_hh,
                    b->registry, c->opt->ident,
                    SOCKET_IDENT_LENGTH, c);

    CDL_PREPEND(b->links, c);
    ++b->num_links;

    if (!b->current) {
        b->current = c;
    }

    c->links = b;
    nitro_counted_buffer_incref(b->bind_counter);
    pthread_rwlock_unlock(&b->link_lock);
}
示例#26
0
int register_creature_type(const char *id, const char *name, const char *desc,
                           enum sprite_ids sprite_id) {
    struct CreatureType *new_type;

    HASH_FIND(hh, creature_list, id, strlen(id), new_type);
    if (new_type == NULL) {
        DEBUG("registering new creature type with id %s\n", id);
        new_type = (struct CreatureType *)malloc(sizeof(struct CreatureType));
        new_type->creature_type_id = strdup(id);
        new_type->description = strdup(desc);
        new_type->name = strdup(name);
        new_type->sprite_id = sprite_id;

        HASH_ADD_KEYPTR(hh, creature_list, id, strlen(id), new_type);
    } else {
        ERROR("Attempted to register duplicate creature type %s\n", id);
        return -1;
    }
    return 0;
}
示例#27
0
文件: plugin.c 项目: buhman/prc
static int
plugin_register(const char *key, prc_plugin_cmd_t *func)
{
  plugin_ht_t *item, *_item;

  item = malloc(sizeof(plugin_ht_t));
  item->func = func;
  _item = item;

  HASH_ADD_KEYPTR(hh, plugin_head, key, strlen(key), item);

  HASH_FIND(hh, plugin_head, key, strlen(key), item);

  if (!item) {
    free(_item);
    return -1;
  }

  return 0;
}
示例#28
0
void sol_event_listener_add(SolObject object, char* type, SolFunction callback) {
    listener_count++;
    struct sol_event_listener* new_listener;
    // check if already exists
    HASH_FIND_STR(object->listeners, type, new_listener);
    if (new_listener == NULL) {
        new_listener = malloc(sizeof(*new_listener));
        new_listener->type = strdup(type);
        new_listener->listeners = NULL;
        HASH_ADD_KEYPTR(hh, object->listeners, new_listener->type, strlen(new_listener->type), new_listener);
    }
    if (new_listener->listeners == NULL) {
        new_listener->listeners = new_listener->listeners_end = malloc(sizeof(*new_listener->listeners_end));
    } else {
        new_listener->listeners_end->next = malloc(sizeof(*new_listener->listeners_end));
        new_listener->listeners_end = new_listener->listeners_end->next;
    }
    new_listener->listeners_end->callback = (SolFunction) sol_obj_retain((SolObject) callback);
    new_listener->listeners_end->next = NULL;
}
示例#29
0
void add_to_cache(char *key, char *value)
{
    struct CacheEntry *entry, *tmp_entry;
    entry = malloc(sizeof(struct CacheEntry));
    entry->key = strdup(key);
    entry->value = strdup(value);
    HASH_ADD_KEYPTR(hh, cache, entry->key, strlen(entry->key), entry);
    
    // prune the cache to MAX_CACHE_SIZE
    if (HASH_COUNT(cache) >= MAX_CACHE_SIZE) {
        while (HASH_ITER(hh, cache, entry, tmp_entry)) {
            // prune the first entry (loop is based on insertion order so this deletes the oldest item)
            HASH_DELETE(hh, cache, entry);
            free(entry->key);
            free(entry->value);
            free(entry);
            break;
        }
    }
}
示例#30
0
/** Send PANT for route maintenance
 *
 * Send a (Periodic) ANT if a packet was received from a dst the host has not sent a packet
 * to for ara_pant_interval seconds.
 */
int ara_maintainroute_pant(dessert_msg_t* msg, size_t len, dessert_msg_proc_t* proc, dessert_meshif_t* iface_in, dessert_frameid_t id) {
    ara_proc_t* ap = ara_proc_get(proc);
    assert(ap != 0);

    // a value of zero disables PANTs
    if(ara_pant_interval == 0
       || !(ap->flags & proc->lflags & DESSERT_RX_FLAG_L25_DST)) {
        return DESSERT_MSG_KEEP;
    }

    struct timeval now;

    ara_usage_t* last;

    gettimeofday(&now, NULL);

    pthread_rwlock_rdlock(&ullock);

    HASH_FIND(hh, ut, &(ap->src), sizeof(ara_address_t), last);

    if(last == NULL) {
        last = malloc(sizeof(ara_usage_t));
        memcpy(&(last->dst), &(ap->src), sizeof(ara_address_t));
        HASH_ADD_KEYPTR(hh, ut, &(last->dst), sizeof(ara_address_t), last);
        last->t.tv_sec = 0;
        last->t.tv_usec = 0;
    }

    /* need to send pant ?*/
    if((last->t.tv_sec) + ara_pant_interval < now.tv_sec) {
        last->t.tv_sec = now.tv_sec;
        last->t.tv_usec = now.tv_usec;

        _ara_sendbant(ap->src);
        dessert_info("the last BANT was a PANT");
    }

    pthread_rwlock_unlock(&ullock);

    return DESSERT_MSG_KEEP;
}