예제 #1
0
파일: bdb.c 프로젝트: lazywalker/memcacheq
void print_queue_stats(char *temp, int len_limit) {
    char *pos = temp;
    int remains = len_limit - 3;
    int res;
    int64_t set_hits,get_hits;
    pthread_rwlock_rdlock(&qlist_ht_lock);
    char *k;
    queue_t *q;
    struct hashtable_itr *itr = NULL;
    itr = hashtable_iterator(qlist_htp);
    assert(itr != NULL);
    if (hashtable_count(qlist_htp) > 0)
    {
        do {
            k = hashtable_iterator_key(itr);
            q = hashtable_iterator_value(itr);
            pthread_mutex_lock(&(q->lock));
            set_hits = q->set_hits;
            get_hits = q->get_hits;
            pthread_mutex_unlock(&(q->lock));
            if (remains > strlen(k) + 50) {
                res = sprintf(pos, "STAT %s %lld/%lld\r\n", k, set_hits, get_hits);
                remains -= res;
                pos += res;                
            } else {
                break;
            }
        } while (hashtable_iterator_advance(itr));
    }
    free(itr);
    pthread_rwlock_unlock(&qlist_ht_lock);
    sprintf(pos, "END");
    return;
}
/**
 * Use this function iterator-style to go through the entries
 * in the table of managed interfaces. You should call 
 * policy_table_iterator_reset before iterating over entries with 
 * this function.
 * 
 *
 * @return
 *      Pointer to policy table entry if successful, otherwise NULL.
 */
policy_table_entry_t *
policy_table_next(void)
{
    policy_table_entry_t *v;

    INSIST(if_table != NULL);
    if(hashtable_count(if_table) < 1)
        return NULL;

    if(itr_broken) {
        if(itr)
            free(itr);
        itr = hashtable_iterator(if_table); // mallocs
        INSIST(itr != NULL);
        itr_broken = FALSE;
        // now it's at the first element
    } else if (!hashtable_iterator_advance(itr)){
        // no more
        free(itr);
        itr = NULL;
        itr_broken = TRUE; // will reset next time around

        return NULL;
    }

    v = hashtable_iterator_value(itr);

    return v;
}
예제 #3
0
void destroy_shp_hash(void) {
    struct hashtable_itr *iterator=NULL;
    shpinfo *si;
    int ret;

    if (shp_hash) {
        // walk through the hashtable, free any pointers in the values
        // that aren't null, or we'll leak like a sieve.

        // the hashtable functions always attempt to dereference iterator,
        // and don't check if you give it a null, but will return null if
        // there's nothing in the table.  Grrrr.
        iterator=hashtable_iterator(shp_hash);
        do {
            ret=0;
            if (iterator) {
                si = hashtable_iterator_value(iterator);
                if (si) 
                    empty_shpinfo(si);
                ret=hashtable_iterator_advance(iterator);
            }
        } while (ret);
        hashtable_destroy(shp_hash, 1);  // destroy the hashtable, freeing
                                         // what's left of the entries
        shp_hash=NULL;
        if (iterator) free(iterator);
    }
}
예제 #4
0
파일: manifest.c 프로젝트: jrosdahl/ccache
static void
add_file_info_indexes(uint32_t *indexes, uint32_t size,
                      struct manifest *mf, struct hashtable *included_files)
{
	if (size == 0) {
		return;
	}

	// path --> index
	struct hashtable *mf_files =
		create_string_index_map(mf->files, mf->n_files);
	// struct file_info --> index
	struct hashtable *mf_file_infos =
		create_file_info_index_map(mf->file_infos, mf->n_file_infos);
	struct hashtable_itr *iter = hashtable_iterator(included_files);
	uint32_t i = 0;
	do {
		char *path = hashtable_iterator_key(iter);
		struct file_hash *file_hash = hashtable_iterator_value(iter);
		indexes[i] = get_file_hash_index(mf, path, file_hash, mf_files,
		                                 mf_file_infos);
		i++;
	} while (hashtable_iterator_advance(iter));
	assert(i == size);

	hashtable_destroy(mf_file_infos, 1);
	hashtable_destroy(mf_files, 1);
}
/**
 * first_name_htbl_element - return next element of the name hash table.
 * @ph_elt: the path hash table the name hash table belongs to
 * @itr: double pointer to a 'struct hashtable_itr' object where the
 *       information about further iterations is stored
 *
 * This function implements name hash table iteration together with
 * 'first_name_htbl_element()'. Returns the next name hash table element or
 * %NULL if there are no more elements.
 */
struct name_htbl_element *
next_name_htbl_element(struct path_htbl_element *ph_elt,
		       struct hashtable_itr **itr)
{
	if (!path_htbl || !ph_elt || !hashtable_iterator_advance(*itr))
		return NULL;

	return hashtable_iterator_value(*itr);
}
예제 #6
0
/*
 * matWrite - write signals from measurement structure to MAT file
 */
int matWrite(measurement_t *measurement, const char *outFileName)
{
  size_t dims[2];
  int err = 0;
  mat_t *mat;
  matvar_t *matvar;

  mat = Mat_Create(outFileName, NULL);
  if (mat != NULL) {

    /* loop over all time series */
    struct hashtable *timeSeriesHash = measurement->timeSeriesHash;

    /* Iterator constructor only returns a valid iterator if
     * the hashtable is not empty */
    if (hashtable_count(timeSeriesHash) > 0) {

      struct hashtable_itr *itr = hashtable_iterator(timeSeriesHash);
      do {
        char         *signalName = hashtable_iterator_key(itr);
        timeSeries_t *timeSeries = hashtable_iterator_value(itr);
        double *timeValue = (double *)malloc(sizeof(double)*2*timeSeries->n);
        unsigned int i;

        /*
         * build up a 1x2n array with time stamps in [0..n-1] and
         * values in [n..2n-1].
         */
        for(i=0;i<timeSeries->n;i++) {
          timeValue[i] = timeSeries->time[i];
        }
        for(i=0;i<timeSeries->n;i++) {
          timeValue[timeSeries->n + i] = timeSeries->value[i];
        }
        dims[0] = timeSeries->n;
        dims[1] = 2;

        /* output signal to mat structure and free up temp array. */
        matvar = Mat_VarCreate(signalName, MAT_C_DOUBLE, MAT_T_DOUBLE,
                               2, dims, timeValue, 0);
        Mat_VarWrite(mat, matvar, 0);
        Mat_VarFree(matvar);

        free(timeValue);
      } while (hashtable_iterator_advance(itr));
      free(itr);
    }

    Mat_Close(mat);
  } else {
    fprintf(stderr, "error: could not create MAT file %s\n", outFileName);
    err = 1;
  }

  return err;
}
예제 #7
0
void purge_shp_hash(time_t secs_now) {
    struct hashtable_itr *iterator=NULL;
    shpinfo *si;
    int ret;


    if (secs_now > purge_time) {  // Time to purge
        //time_now = localtime(&secs_now);
        //(void)strftime(timestring,100,"%a %b %d %H:%M:%S %Z %Y",time_now);
        //fprintf(stderr,"Purging...%s\n",timestring);

        purge_time += PURGE_PERIOD;

        if (shp_hash) {
            // walk through the hash table and kill entries that are old

            iterator=hashtable_iterator(shp_hash);
            do {
                ret=0;
                if (iterator) {  // must check this, because could be null
                                 // if the iterator malloc failed
                    si=hashtable_iterator_value(iterator);
                    
                    if (si) {
                        if (secs_now > si->last_access+PURGE_PERIOD) {
                            // this is stale, hasn't been accessed in a while
                            //fprintf(stderr,
                            // "found stale entry for %s, deleting it.\n",
                            // si->filename);
                            //fprintf(stderr,"    Destroying si=%lx\n",
                            //            (unsigned long int) si);
                            ret=hashtable_iterator_remove(iterator);
                            
                            // Important that we NOT do the
                            // destroy first, because we've used
                            // the filename pointer field of the
                            // structure as the key, and the
                            // remove function will free that.  If
                            // we clobber the struct first, we
                            // invite segfaults
                            destroy_shpinfo(si);
                            
                            //fprintf(stderr,"    removing from hashtable\n");
                        } else {
                            ret=hashtable_iterator_advance(iterator);
                        }
                    }
                }
            } while (ret);
            // we're now done with the iterator.  Free it to stop us from
            // leaking!
            if (iterator) free(iterator);
        }
        //fprintf(stderr,"   done Purging...\n");
    }
}
/**
 * first_name_htbl_element - return first element of the name hash table.
 * @ph_elt: the path hash table the name hash table belongs to
 * @itr: double pointer to a 'struct hashtable_itr' object where the
 *       information about further iterations is stored
 *
 * This function implements name hash table iteration together with
 * 'next_name_htbl_element()'. Returns the first name hash table element or
 * %NULL if the hash table is empty.
 */
struct name_htbl_element *
first_name_htbl_element(struct path_htbl_element *ph_elt,
			struct hashtable_itr **itr)
{
	if (!path_htbl || !ph_elt || hashtable_count(ph_elt->name_htbl) == 0)
		return NULL;

	*itr = hashtable_iterator(ph_elt->name_htbl);
	return hashtable_iterator_value(*itr);
}
예제 #9
0
파일: symbols.c 프로젝트: davidar/iccsh
void provide_symbols(TCCState *tccs) {
    if(hashtable_count(symbol_table)) {
        struct hashtable_itr *itr = hashtable_iterator(symbol_table);
        do {
            struct symbol *s = hashtable_iterator_value(itr);
            tcc_add_symbol(tccs, s->name, s->addr);
        } while(hashtable_iterator_advance(itr));
        free(itr);
    }
}
예제 #10
0
파일: symbols.c 프로젝트: davidar/iccsh
void symbols_close(void) {
    if(hashtable_count(symbol_table)) {
        struct hashtable_itr *itr = hashtable_iterator(symbol_table);
        do {
            struct symbol *s = hashtable_iterator_value(itr);
            free((void *) s->decl);
            free(s);
        } while(hashtable_iterator_remove(itr));
        free(itr);
    }
    hashtable_destroy(symbol_table, 0);
}
예제 #11
0
파일: symbols.c 프로젝트: davidar/iccsh
char *symbol_declarations(void) {
    char *decls = strdup("");
    if(hashtable_count(symbol_table)) {
        struct hashtable_itr *itr = hashtable_iterator(symbol_table);
        do {
            struct symbol *s = hashtable_iterator_value(itr);
            asprintfa(&decls, "extern %s;\n", s->decl);
        } while(hashtable_iterator_advance(itr));
        free(itr);
    }
    return decls;
}
예제 #12
0
static void copy_table(zk_hashtable *from, watcher_object_list_t *to) {
    struct hashtable_itr *it;
    int hasMore;
    if(hashtable_count(from->ht)==0)
        return;
    it=hashtable_iterator(from->ht);
    do {
        watcher_object_list_t *w = hashtable_iterator_value(it);
        copy_watchers(w, to, 1);
        hasMore=hashtable_iterator_advance(it);
    } while(hasMore);
    free(it);
}
예제 #13
0
static void do_clean_hashtable(zk_hashtable* ht)
{
    struct hashtable_itr *it;
    int hasMore;
    if(hashtable_count(ht->ht)==0)
        return;
    it=hashtable_iterator(ht->ht);
    do {
        watcher_object_list_t* w=hashtable_iterator_value(it);
        destroy_watcher_object_list(w);
        hasMore=hashtable_iterator_remove(it);
    } while(hasMore);
    free(it);
}
예제 #14
0
파일: dsui.c 프로젝트: dillonhicks/ipymake
/** Enable all the instrumentation points DSUI knows about for
  * a particular datastream */
void dsui_enable_all_ips(dsui_stream_t ds)
{
	int ctr = 0;

	hashtable_itr_t itr;
	init_iterator(&itr, ip_names);

	do {
		struct datastream_ip *ip = hashtable_iterator_value(&itr);
		ctr++;
		__dsui_enable_ip(ds, ip, NULL);
	} while (hashtable_iterator_advance(&itr));
	dprintf("Enabled %d entities for datastream [%d]\n",
			ctr, ds);
}
예제 #15
0
파일: dsui.c 프로젝트: dillonhicks/ipymake
/* Write the DSUI header to an output file. This includes a timekeeping
 * event (to establish tsc-to-nanosecond correspondence) and then a
 * namespace event for each instrumentation point we know about */
static void write_header(struct logging_thread *log)
{
	hashtable_itr_t itr;

	log_time_state(log);
	if (!hashtable_count(ip_names))
		return;

	init_iterator(&itr, ip_names);

	do {
		struct datastream_ip *ip = hashtable_iterator_value(&itr);
		write_namespace_event(ip->ip, log);
	} while (hashtable_iterator_advance(&itr));
}
예제 #16
0
파일: dsui.c 프로젝트: dillonhicks/ipymake
/** Register an instrumentation point with DSUI. This accomplishes
 * several things:
 * 1) The IP is inserted into the global instrumentation point
 *    hash table so it can be looked up by name
 * 2) The numerical ID of the instrumentation point is assigned.
 *    Entities are logged by ID, with the name and other metadata
 *    stored in the previously logged namespace information.
 *
 * If DSUI dicovers that an instrumentation point is already registered
 * under the same name, then it assumes that this IP is another instance
 * of the same point, and modifies the IP's pointers so that it refers
 * to the same namespace/state information as the previous IP.
 *
 * If there are any open log files, a namespace event for this IP
 * will be written to each of them.
 *
 * You must hold the DSUI write-lock when calling this function */
static void __dsui_register_ip(struct datastream_ip *ip)
{
	struct datastream_ip_data *ipdata = ip->ip;
	char *ipname;
	struct datastream_ip *v;
	hashtable_itr_t itr;

	if (ipdata->id) {
		bprintf("Already Registered %s/%s/%d\n", ipdata->group,
			ipdata->name, ipdata->id);
		return;
	}

	ipname = malloc(strlen(ipdata->group) + strlen(ipdata->name) + 2);
	sprintf(ipname, "%s/%s", ipdata->group, ipdata->name);
	v = hashtable_search(ip_names, ipname);
	if (v) {
		//dprintf("%s encountered more than once mapping %p->%p\n",
		//		ipname, ip, v);
		ip->ip = v->ip;
		ip->next = &v->ip->next;
		ip->id = &v->ip->id;
		v->ip->line = -1;
		free(ipname);
		return;
	}

	ipdata->id = starting_id++;
	hashtable_insert(ip_names, ipname, ip);
	//dprintf("Registered %s/%s/%d \n", ipdata->group,
	//		ipdata->name, ipdata->id);

	/* if this ip was registered when there are already active
	 * logging threads, we need to write namespace information
	 * for this ip */

	if (!hashtable_count(logging_threads)) {
		return;
	}
	init_iterator(&itr, logging_threads);
	do {
		struct logging_thread *log;
		log = hashtable_iterator_value(&itr);
		write_namespace_event(ipdata, log);
	} while (hashtable_iterator_advance(&itr));
}
/**
 * Mark all policies in the table UNVERIFIED. Since we can't delete routes or
 * filters, all that are left unverified (i.e. they don't get 
 * added again) when calling policy_table_clean() get removed.
 * 
 * @return
 *      TRUE upon success;
 *      FALSE if aborted because there's still changes pending 
 *            in which case all route statuses stay the same
 */
boolean
policy_table_unverify_all(void)
{
    policy_table_entry_t * pol = NULL;
    ped_policy_route_t * route = NULL;
    struct hashtable_itr * iterator = NULL;
    
    if(hashtable_count(if_table) < 1)
        return TRUE; // nothing to do
        
    if(changes_pending > 0)
        return FALSE; // don't do anything if there's still changes pending

    junos_trace(PED_TRACEFLAG_HT, "%s", __func__);

    iterator = hashtable_iterator(if_table); // mallocs
    INSIST(iterator != NULL);

    // go through all policies
    do {
        pol = hashtable_iterator_value(iterator);
        
        // for all filters and routes in route lists set status to UNVERIFIED
        
        if(!pol->broken) {
            if(pol->filter) {
                pol->filter->status = FILTER_UNVERIFIED;
            }
            if((route = pol->route)) {
                while(route) {
                    // changes_pending is wrong if this fails
                    INSIST(route->status != ROUTE_PENDING);
                    route->status = ROUTE_UNVERIFIED;
                    route = route->next;
                }
            }
        }
        
    } while (hashtable_iterator_advance(iterator));

    free(iterator);
    
    clean_table = TRUE;
    
    return TRUE;
}
예제 #18
0
void
reclose_cache(void)
{
	struct reformat *re;
        struct hashtable_itr *itr;
	char *filesname;

	#ifdef DEBUG_TIME
	        struct timeval start_time, end_time;
	        gettimeofday(&start_time, NULL);
	#endif

      	//itererer over hash, frigjør alle elementer
        if (lots_cache!= NULL && hashtable_count(lots_cache) > 0)
        {

                itr = hashtable_iterator(lots_cache);

                do {
                	filesname = hashtable_iterator_key(itr);
                        re = hashtable_iterator_value(itr);

			#ifdef DEBUG
			printf("reclose_cache: closing \"%s\"\n",filesname);
			#endif

			if (re != NULL) {
				reclose(re);
			}

             	} while (hashtable_iterator_remove(itr));

                free(itr);
	}
	#ifdef DEBUG_TIME
	        gettimeofday(&end_time, NULL);
	        printf("Time debug: reclose_cache %f\n",getTimeDifference(&start_time,&end_time));
	#endif


	return; 
}
예제 #19
0
cinv_status_t cinv_structure_delete(CInvContext *context,
	CInvStructure *structure) {

	if (hashtable_count(structure->members) > 0) {
		struct hashtable_itr it;
		hashtable_iterator(structure->members, &it);

		do {
			free(hashtable_iterator_key(&it));
			free(hashtable_iterator_value(&it));
		} while (hashtable_iterator_remove(&it));
	}

	hashtable_destroy(structure->members, 0);

	free(structure);

	context_clear_error(context);
	return CINV_SUCCESS;
}
예제 #20
0
파일: statsobj.c 프로젝트: Whissi/rsyslog
/* this function obtains all sender stats. hlper to getAllStatsLines()
 * We need to keep this looked to avoid resizing of the hash table
 * (what could otherwise cause a segfault).
 */
static void
getSenderStats(rsRetVal(*cb)(void*, const char*),
	void *usrptr,
	statsFmtType_t fmt,
	const int8_t bResetCtrs)
{
	struct hashtable_itr *itr = NULL;
	struct sender_stats *stat;
	char fmtbuf[2048];

	pthread_mutex_lock(&mutSenders);

	/* Iterator constructor only returns a valid iterator if
	 * the hashtable is not empty
	 */
	if(hashtable_count(stats_senders) > 0) {
		itr = hashtable_iterator(stats_senders);
		do {
			stat = (struct sender_stats*)hashtable_iterator_value(itr);
			if(fmt == statsFmt_Legacy) {
				snprintf(fmtbuf, sizeof(fmtbuf),
					"_sender_stat: sender=%s messages=%"
					PRIu64,
					stat->sender, stat->nMsgs);
			} else {
				snprintf(fmtbuf, sizeof(fmtbuf),
					"{ \"name\":\"_sender_stat\", "
					"\"sender\":\"%s\", \"messages\":\"%"
					PRIu64 "\"}",
					stat->sender, stat->nMsgs);
			}
			fmtbuf[sizeof(fmtbuf)-1] = '\0';
			cb(usrptr, fmtbuf);
			if(bResetCtrs)
				stat->nMsgs = 0;
		} while (hashtable_iterator_advance(itr));
	}

	free(itr);
	pthread_mutex_unlock(&mutSenders);
}
예제 #21
0
/**
 * Free a value_t pointer, as well as any data stored within it. Container types
 * will be recursively freed.
 * @param value	value_t pointer to free
 */
void free_value(value_t *value) {
	list_t *listval, *cur, *temp;
	hashtable_t *hashval;
	hashtable_itr_t *itr;
	value_t *tempv;

	switch(value->type) {
	case INTTYPE:
	case BOOLTYPE:
	case LONGTYPE:
	case DOUBLETYPE:
		break;
	case STRINGTYPE:
	case REFTYPE:
		free(value->value.s);
		break;
	case INVOTYPE:
		free(value->value.v->name);
		tempv = encap_hash(value->value.v->params);
		free_value(tempv);
		break;
	case LISTTYPE:
		listval = value->value.l;
		list_for_each_safe(cur, temp, listval) {
			free_value((value_t*)cur->item);
			free(cur);
		}
		free(listval);
		break;
	case DICTTYPE:
		hashval = value->value.h;
		if (hashtable_count(hashval) > 0) {
			itr = hashtable_iterator(hashval);
			do {
				free_value((value_t*)hashtable_iterator_value(itr));
			} while (hashtable_iterator_advance(itr));
			free(itr);
		}
		hashtable_destroy(hashval, 0);
		break;
	}
예제 #22
0
파일: dsui.c 프로젝트: dillonhicks/ipymake
/** returns a configfile linked list of active logging thread filenames.
 * These are the keys in the logging_threads hashtable. */
list_t *get_dsui_output_filenames()
{
	list_t *f = create_list();
	struct logging_thread *log;
	hashtable_itr_t itr;

	km_rdwr_rlock(&dsui_rwlock);

	if (!hashtable_count(logging_threads)) {
		goto out;
	}

	init_iterator(&itr, logging_threads);
	do {
		log = hashtable_iterator_value(&itr);
		list_append(f, encap_string(log->filename));
	} while (hashtable_iterator_advance(&itr));
out:
	km_rdwr_runlock(&dsui_rwlock);
	return f;
}
예제 #23
0
파일: dsui.c 프로젝트: dillonhicks/ipymake
static void __dsui_cleanup() {
	int i;
	hashtable_itr_t itr;

	dprintf("called\n");
	for(i=0; i < MAX_DS; i++) {
		__dsui_close_datastream(i);
	}

	if (!hashtable_count(logging_threads)) {
		return;
	}
	init_iterator(&itr, logging_threads);
	do {
		struct logging_thread *log;
		log = hashtable_iterator_value(&itr);
		close_logging_thread(log);
		free(log);

	} while (hashtable_iterator_remove(&itr));
}
예제 #24
0
void
cache_indexes_empty(void)
{
	size_t *cached;
	struct hashtable_itr *itr;

	cached = indexcachescached;
	itr = hashtable_iterator(indexcachehash);
	if (hashtable_count(indexcachehash) > 0) {
		do {
			indexcache_t *ic;

			ic = hashtable_iterator_value(itr);
			if (ic == NULL)
				continue;
			munmap(ic->ptr, ic->size);
		} while (hashtable_iterator_advance(itr));
	}

	hashtable_destroy(indexcachehash, 1);
}
예제 #25
0
파일: bdb.c 프로젝트: lazywalker/memcacheq
void bdb_qlist_db_close(void){
    dump_qstats_to_db();
    
    struct hashtable_itr *itr = NULL;
    queue_t *q;
    itr = hashtable_iterator(qlist_htp);
    assert(itr != NULL);
    if (hashtable_count(qlist_htp) > 0)
    {
        do {
            q = hashtable_iterator_value(itr);
            q->dbp->close(q->dbp, 0);
            pthread_mutex_destroy(&(q->lock));
        } while (hashtable_iterator_advance(itr));
    }
    free(itr);
    if (qlist_dbp != NULL) {
        qlist_dbp->close(qlist_dbp, 0);        
    }
    fprintf(stderr, "qlist_dbp->close: OK\n");
}
예제 #26
0
파일: LTencoderFLY.c 프로젝트: day7th/libLT
void reseedEncoderFLY(LTencoderFLY *encoder, unsigned long newSeed) {

    // Reinit the totGenSymbols and the refRandomSeed
    encoder->totGenSymbols = 0;
    unsigned long oldSeed = encoder->refRandomSeed;
    encoder->refRandomSeed = newSeed;
    unsigned long oldConfSeed;
    struct hashtable *h = encoder->DistributionsTable;

#ifdef DEBUGencoderPrintBucketRandomSeed
    printf("Encoder[reseed()] - Seed: %lu\n", encoder->refRandomSeed);
#endif

    struct hashtable_itr *itr;
    struct key *k;
    struct value *v;

    // Update all the configurations, if any
    itr = hashtable_iterator(h);
    if (hashtable_count(h) > 0) {
        do {
            k = hashtable_iterator_key(itr);
            v = hashtable_iterator_value(itr);

            // Update the confSeed
            oldConfSeed = v->confSeed;
            v->confSeed = newSeed + (oldConfSeed-oldSeed);

            // Reinit the random generator
            initRandom(&v->randomGenerator, v->confSeed);

            // Erase the number of generated symbols
            v->genSymbols = 0;
        } while (hashtable_iterator_advance(itr));
    }
    free(itr);
    itr = NULL;
    return;
}
/**
 * free_devtable_info - free device table information.
 *
 * This function frees the path hash table and the name hash tables.
 */
void free_devtable_info(void)
{
	struct hashtable_itr *ph_itr;
	struct path_htbl_element *ph_elt;

	if (!path_htbl)
		return;

	if (hashtable_count(path_htbl) > 0) {
		ph_itr = hashtable_iterator(path_htbl);
		do {
			ph_elt = hashtable_iterator_value(ph_itr);
			/*
			 * Note, since we use the same string for the key and
			 * @name in the name hash table elements, we do not
			 * have to iterate name hash table because @name memory
			 * will be freed when freeing the key.
			 */
			hashtable_destroy(ph_elt->name_htbl, 1);
		} while (hashtable_iterator_advance(ph_itr));
	}
	hashtable_destroy(path_htbl, 1);
}
예제 #28
0
void ht_to_perl_ht(HV *perl_ht, struct hashtable *params) {
    if (!hashtable_count(params)) return;

    struct hashtable_itr *itr;
    itr = hashtable_iterator(params);


    do {
        char *param = hashtable_iterator_key(itr);
        char *value = hashtable_iterator_value(itr);
        
        // check if key already exists
        if (hv_exists(perl_ht, param, strlen(param))) {
            fprintf(stderr, "Parameter '%s' is already defined. Ignoring.\n", param);
            continue;
        }

        hv_store(perl_ht, param, strlen(param),
            sv_2mortal(newSVpv(value, 0)), 0);
        
    } while (hashtable_iterator_advance(itr));
    free(itr);
}
예제 #29
0
파일: statsobj.c 프로젝트: Whissi/rsyslog
/* check if a sender has not sent info to us for an extended period
 * of time.
 */
void
checkGoneAwaySenders(const time_t tCurr)
{
	struct hashtable_itr *itr = NULL;
	struct sender_stats *stat;
	const time_t rqdLast = tCurr - glblSenderStatsTimeout;
	struct tm tm;

	pthread_mutex_lock(&mutSenders);

	/* Iterator constructor only returns a valid iterator if
	 * the hashtable is not empty
	 */
	if(hashtable_count(stats_senders) > 0) {
		itr = hashtable_iterator(stats_senders);
		do {
			stat = (struct sender_stats*)hashtable_iterator_value(itr);
			if(stat->lastSeen < rqdLast) {
				if(glblReportGoneAwaySenders) {
					localtime_r(&stat->lastSeen, &tm);
					LogMsg(0, RS_RET_SENDER_GONE_AWAY,
						LOG_WARNING,
						"removing sender '%s' from connection "
						"table, last seen at "
						"%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d",
						stat->sender,
						tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
						tm.tm_hour, tm.tm_min, tm.tm_sec);
				}
				hashtable_remove(stats_senders, (void*)stat->sender);
			}
		} while (hashtable_iterator_advance(itr));
	}

	pthread_mutex_unlock(&mutSenders);
	free(itr);
}
예제 #30
0
void *
cache_free(cache_t *c)
{

    	cache_value_t *v;

    struct hashtable_itr *itr;
    if (hashtable_count(c->c_data) > 0)
    {
        itr = hashtable_iterator(c->c_data);
        do {
            v = hashtable_iterator_value(itr);

	    c->c_freevalue(v->p);
	    free(v);
        } while (hashtable_iterator_advance(itr));

     	free(itr);

    }

    hashtable_destroy(c->c_data,0); /* second arg indicates "free(value)" */

}