コード例 #1
0
ファイル: tld.c プロジェクト: DarkSpiritNET/NeoStats
void ResetTLDStatistics( void ) 
{
	lnode_t *tn, *tn2;
	TLD *t;
	
	tn = list_first( tldstatlist );
	while( tn != NULL )
	{
		t = lnode_get( tn );
		ResetStatistic( &t->users );
		if( t->users.current == 0 )
		{
			/* don't delete the tld entry ??? as its our "unknown" entry */
			if( ircstrcasecmp( t->tld, UNKNOWN_COUNTRY_CODE ) )
			{
				tn2 = list_next( tldstatlist, tn );
				ns_free( t );
				list_delete_destroy_node( tldstatlist, tn );
				tn = tn2;
				continue;
			}
		}
		tn = list_next( tldstatlist, tn );
	}
}
コード例 #2
0
ファイル: ss_export.c プロジェクト: danopia/denora
/**
 * Export tld struct to xml file
 *
 * @param file is the name that will be used
 * @return void - no returend value
 *
 */
void xml_export_tld(char *file)
{
    FILE *ptr;
    TLD *t;
    lnode_t *tn;

    ptr = new_xml(file);

    SET_SEGV_LOCATION();

    if (ptr) {
        xml_write_header(ptr);
        xml_write_block_top(ptr, "tld");
        list_sort(Thead, sortusers);
        tn = list_first(Thead);
        while (tn) {
            t = lnode_get(tn);
            denora_cmd_pong(ServerName, ServerName);
            xml_write_block_top(ptr, "domain");
            xml_write_tag(ptr, "countrycode", t->countrycode);
            xml_write_tag(ptr, "country", t->country);
            xml_write_tag_int(ptr, "current", t->count);
            xml_write_tag_int(ptr, "overall", t->overall);
            xml_write_block_bottom(ptr, "domain");
            tn = list_next(Thead, tn);
        }
        xml_write_block_bottom(ptr, "tld");
        xml_write_footer(ptr);
    }
}
コード例 #3
0
ファイル: ss_export.c プロジェクト: danopia/denora
/**
 * Export ctcp struct to xml file
 *
 * @param file is the name that will be used
 * @return void - no returend value
 *
 */
void xml_export_ctcp(char *file)
{
    FILE *ptr;
    CTCPVerStats *c;
    lnode_t *tn;

    ptr = new_xml(file);

    SET_SEGV_LOCATION();

    if (ptr) {
        xml_write_header(ptr);

        xml_write_block_top(ptr, "ctcp");

        tn = list_first(CTCPhead);
        while (tn) {
            c = lnode_get(tn);
            xml_write_block_top(ptr, "client");
            xml_write_tag(ptr, "version", c->version);
            xml_write_tag_int(ptr, "current", c->count);
            xml_write_tag_int(ptr, "overall", c->overall);
            xml_write_block_bottom(ptr, "client");
            tn = list_next(CTCPhead, tn);
        }
        xml_write_block_bottom(ptr, "ctcp");
        xml_write_footer(ptr);
    }
}
コード例 #4
0
ファイル: html_ctcp.c プロジェクト: danopia/denora
void html_ctcp_table(FILE * ptr)
{
    CTCPVerStats *c;
    lnode_t *tn;
    char *tempc;
    int x = 0;

    if (ptr) {
        fprintf(ptr, "%s", getstring(NULL, HTML_CTCP_HEADER));
        list_sort(CTCPhead, sortctcp);
        tn = list_first(CTCPhead);
        while (tn) {
            c = lnode_get(tn);
            if (c->overall) {
                tempc = char_encode(c->version);
                dfprintf(ptr, getstring(NULL, HTML_CTCP_CONTENT),
                         tempc, c->overall);
                free(tempc);
                x++;
                if (x > 10) {
                    break;
                }
            }
            tn = list_next(CTCPhead, tn);
        }
        fprintf(ptr, "%s", getstring(NULL, HTML_CTCP_FOOTER));
    }
}
コード例 #5
0
ファイル: logging.c プロジェクト: 070499/xbmc
CP_C_API cp_status_t cp_register_logger(cp_context_t *context, cp_logger_func_t logger, void *user_data, cp_log_severity_t min_severity) {
	logger_t l;
	logger_t *lh = NULL;
	lnode_t *node = NULL;
	cp_status_t status = CP_OK;

	CHECK_NOT_NULL(context);
	CHECK_NOT_NULL(logger);
	cpi_lock_context(context);
	cpi_check_invocation(context, CPI_CF_LOGGER, __func__);
	do {
	
		// Check if logger already exists and allocate new holder if necessary
		l.logger = logger;
		if ((node = list_find(context->env->loggers, &l, comp_logger)) == NULL) {
			lh = malloc(sizeof(logger_t));
			node = lnode_create(lh);
			if (lh == NULL || node == NULL) {
				status = CP_ERR_RESOURCE;
				break;
			}
			lh->logger = logger;
			lh->plugin = context->plugin;
			list_append(context->env->loggers, node);
		} else {
			lh = lnode_get(node);
		}
		
		// Initialize or update the logger holder
		lh->user_data = user_data;
		lh->min_severity = min_severity;
		
		// Update global limits
		update_logging_limits(context);
		
	} while (0);

	// Report error
	if (status == CP_ERR_RESOURCE) {
		cpi_error(context, N_("Logger could not be registered due to insufficient memory."));		
	} else if (cpi_is_logged(context, CP_LOG_DEBUG)) {
		char owner[64];
		/* TRANSLATORS: %s is the context owner */
		cpi_debugf(context, N_("%s registered a logger."), cpi_context_owner(context, owner, sizeof(owner)));
	}
	cpi_unlock_context(context);

	// Release resources on error
	if (status != CP_OK) {
		if (node != NULL) {
			lnode_destroy(node);
		}
		if (lh != NULL) {
			free(lh);
		}
	}

	return status;
}
コード例 #6
0
int list_is_sorted(list_t *list, int compare(const void *, const void *))
{
    lnode_t *node, *next, *nil;

    next = nil = list_nil(list);
    node = list_first_priv(list);

    if (node != nil)
        next = lnode_next(node);

    for (; next != nil; node = next, next = lnode_next(next)) {
        if (compare(lnode_get(node), lnode_get(next)) > 0)
            return 0;
    }

    return 1;
}
コード例 #7
0
ファイル: logging.c プロジェクト: 070499/xbmc
static void process_unregister_logger(list_t *list, lnode_t *node, void *plugin) {
	logger_t *lh = lnode_get(node);
	if (plugin == NULL || lh->plugin == plugin) {
		list_delete(list, node);
		lnode_destroy(node);
		free(lh);
	}
}
コード例 #8
0
lnode_t *list_find(list_t *list, const void *key, int compare(const void *, const void *))
{
    lnode_t *node;

    for (node = list_first_priv(list); node != list_nil(list); node = node->next) {
        if (compare(lnode_get(node), key) == 0)
            return node;
    }

    return 0;
}
コード例 #9
0
ファイル: list.c プロジェクト: DarkSpiritNET/NeoStats
/*
 * Find list entry and return data pointer
 */
void *
lnode_find (const list_t * list, const void *key, int compare (const void *, const void *))
{
	lnode_t * ln;

	ln = list_find (list, key, compare);
	if (ln) {
		return lnode_get (ln);
	}
	return NULL;
}
コード例 #10
0
ファイル: routing_tests.c プロジェクト: bnoordhuis/mongrel2
int check_routing(list_t *found, Route *route, int expected_count, const char *route_data)
{
    check(list_count(found) == expected_count, "Didn't find right number of routes: got %d, expected %d.", 
            (int)list_count(found), expected_count);
    route = lnode_get(list_first(found));
    debug("Route returned: %s", (const char *)route->data);
    check(route->data == route_data, "Wrong data returned.");
    return 1;

error:
    return 0;
}
コード例 #11
0
ファイル: ast.c プロジェクト: 304471720/mongrel2
static int AST_destroy_list(list_t *data)
{
    lnode_t *n = NULL;

    for(n = list_first(data); n != NULL; n = list_next(data, n)) {
        AST_destroy_value((Value *)lnode_get(n));
    }

    list_destroy_nodes(data);
    list_destroy(data);
    return 0;
}
コード例 #12
0
ファイル: logging.c プロジェクト: 070499/xbmc
/**
 * Updates the context logging limits. The caller must have locked the
 * context.
 */
static void update_logging_limits(cp_context_t *context) {
	lnode_t *node;
	int nms = CP_LOG_NONE;
	
	node = list_first(context->env->loggers);
	while (node != NULL) {
		logger_t *lh = lnode_get(node);
		if (lh->min_severity < nms) {
			nms = lh->min_severity;
		}
		node = list_next(context->env->loggers, node);
	}
	context->env->log_min_severity = nms;
}
コード例 #13
0
ファイル: list.c プロジェクト: DarkSpiritNET/NeoStats
/*
 * Destroy all nodes in list and free associated data pointer.
 */
void
list_destroy_auto (list_t * list)
{
	lnode_t *ln;

	ln = list_first (list);
	while (ln) {
		void *ptr =	( void * )lnode_get (ln);
		ns_free (ptr);
		ln = list_next (list, ln);
	}
	list_destroy_nodes (list);
	list_destroy (list);
}
コード例 #14
0
ファイル: tld.c プロジェクト: DarkSpiritNET/NeoStats
void GetTLDStats( const TLDStatHandler handler, const void *v )
{
	const TLD *t;
	lnode_t *tn;
	
	list_sort( tldstatlist, sortusers );
	tn = list_first( tldstatlist );
	while( tn != NULL )
	{
		t = lnode_get( tn );
		handler( t, v );
		tn = list_next( tldstatlist, tn );
	}
}
コード例 #15
0
ファイル: list.c プロジェクト: DarkSpiritNET/NeoStats
void
list_merge (list_t * dest, list_t * sour, int compare (const void *, const void *))
{
	lnode_t *dn, *sn, *tn;
	lnode_t *d_nil = list_nil (dest), *s_nil = list_nil (sour);

	/* Nothing to do if source and destination list are the same. */
	if (dest == sour)
		return;

	/* overflow check */
	nassert (list_count (sour) + list_count (dest) >= list_count (sour));

	/* lists must be sorted */
	nassert (list_is_sorted (sour, compare));
	nassert (list_is_sorted (dest, compare));

	dn = list_first_priv (dest);
	sn = list_first_priv (sour);

	while (dn != d_nil && sn != s_nil) {
		if (compare (lnode_get (dn), lnode_get (sn)) >= 0) {
			tn = lnode_next (sn);
			list_delete (sour, sn);
			list_ins_before (dest, sn, dn);
			sn = tn;
		} else {
			dn = lnode_next (dn);
		}
	}

	if (dn != d_nil)
		return;

	if (sn != s_nil)
		list_transfer (dest, sour, sn);
}
コード例 #16
0
ファイル: timer.c プロジェクト: DarkSpiritNET/NeoStats
Timer *FindTimer( const char *name )
{
	lnode_t *tn;
	Timer *t;

	tn = list_first(timerlist);
	while (tn != NULL) {
		t = lnode_get(tn);
		if (!ircstrcasecmp(t->name, name))
			return t;
		tn = list_next(timerlist, tn);
	}
	dlog( DEBUG3, "FindTimer: %s not found", name );
	return NULL;
}
コード例 #17
0
ファイル: context.c プロジェクト: hackereye/c-pluff
CP_HIDDEN void cpi_destroy_all_contexts(void) {
	cpi_lock_framework();
	if (contexts != NULL) {
		lnode_t *node;
		
		while ((node = list_last(contexts)) != NULL) {
			cpi_unlock_framework();
			cp_destroy_context(lnode_get(node));
			cpi_lock_framework();
		}
		list_destroy(contexts);
		contexts = NULL;
	}
	cpi_unlock_framework();
}
コード例 #18
0
ファイル: timer.c プロジェクト: DarkSpiritNET/NeoStats
static void NextSchedule() {
	lnode_t *CurNode;
	Timer *CurTimer;
	struct timeval tv;
	/* finally, update the Event Based Timers */
	update_time_now();
	CurNode = list_first(timerlist);
	if (CurNode) {
		CurTimer = lnode_get(CurNode);
		timerclear( &tv );
		tv.tv_sec = CurTimer->nextrun - me.now;;
		if (tv.tv_sec <= 0) {
			/* only run one timer at a time, so wake up in 10 seconds */
			tv.tv_sec = 10;
		}
		evtimer_add( evtimers, &tv );
		dlog(DEBUG3, "Timers will next run in %d Seconds (or around %s)", (int)tv.tv_sec, sftime(CurTimer->nextrun));
	} 
}
コード例 #19
0
ファイル: routing_tests.c プロジェクト: kashyapa/mongrel2
int check_routing(list_t *found, Route *route, int expected_count, const char *route_data)
{
    if(list_first(found)) {
        route = lnode_get(list_first(found));
    }

    check(list_count(found) == expected_count, "Didn't find right number of routes: got %d, expected %d.", 
            (int)list_count(found), expected_count);

    if(route_data == NULL) {
        check(route == NULL, "Should have no routes found.");
    } else {
        check(route->data == route_data, "Wrong data returned.");
    }
    return 1;

error:
    if(route) debug("Route returned: %s", (const char *)route->data);
    return 0;
}
コード例 #20
0
ファイル: file.c プロジェクト: thias42/dLabPro
INT16 CDlpFile_List(CDlpFile* _this)
{
    CFILE_FTYPE* lpType = NULL;
    lnode_t*      lpNode = NULL;

    printf("\n"); dlp_fprint_x_line(stdout,'-',80);
    printf(              "\n Name      \tClass     \tMode  \tDescription\n");
    dlp_fprint_x_line(stdout,'-',80); printf("\n");

    for(lpNode=list_first(_this->m_lpFtypes); lpNode; lpNode=list_next(_this->m_lpFtypes,lpNode))
    {
      lpType = (CFILE_FTYPE*)lnode_get(lpNode);
      DLPASSERT(lpType);
      printf( " %-10s\t%-10s\t%s\t%s\n",lpType->lpName,lpType->lpClassName,
             lpType->nMode==IMPORT_FILE?"Import":"Export",lpType->lpDescr);
    }

    dlp_fprint_x_line(stdout,'-',80); printf("\n");
	return O_K;
}
コード例 #21
0
ファイル: timer.c プロジェクト: DarkSpiritNET/NeoStats
int SetTimerInterval( const char *name, int interval )
{
	Timer *timer;
	lnode_t *tn;

	SET_SEGV_LOCATION();
	tn = list_first(timerlist);
	while (tn != NULL) {
		timer = lnode_get(tn);
		if (!ircstrcasecmp(timer->name, name)) {
			timer->interval = interval;
			dlog( DEBUG2, "SetTimerInterval: timer interval for %s (%s) set to %d", name, timer->moduleptr->info->name, interval );
			TimerCalcNextRun(timer, tn);
			return NS_SUCCESS;
		}
		tn = list_next(timerlist, tn);	
	}
	dlog(DEBUG2, "SetTimerInterval: timer %s not found", name);
	return NS_FAILURE;
}
コード例 #22
0
ファイル: c_queue.c プロジェクト: myeu/concurr_queue
void* dequeue(queue_t *q)
{
    lnode_t *n;
    pthread_mutex_lock(&q->lock);
    
    if (list_isempty(q->list)) {
        pthread_cond_wait(&q->notempty, &q->lock);
    }
    
    if (list_isfull(q->list)) {
        n = list_del_first(q->list);
        pthread_cond_broadcast(&q->notfull);
    }
    else {
        n = list_del_first(q->list);
    }
    
    pthread_mutex_unlock(&q->lock);
    
    return lnode_get(n);
}
コード例 #23
0
ファイル: ast.c プロジェクト: 304471720/mongrel2
int AST_walk_list(tst_t *settings, list_t *data, ast_walk_cb cb)
{
    lnode_t *n = NULL;
    int rc = 0;

    for(n = list_first(data); n != NULL; n = list_next(data, n)) {
        Value *ref = lnode_get(n);
        check(ref, "List got a NULL value in it. Huh?");

        Value *found = Value_resolve(settings, ref);

        check(found, "Invalid reference: %s", bdata(ref->as.ref->data));
        rc = cb(settings, found);
        check_debug(rc == 0, "Failure processing config file. Aborting.");
    }

    return 0;

error:
    return -1;
}
コード例 #24
0
ファイル: timer.c プロジェクト: DarkSpiritNET/NeoStats
int ns_cmd_timerlist( const CmdParams *cmdparams )
{
	Timer *timer = NULL;
	lnode_t *tn;

	SET_SEGV_LOCATION();
	irc_prefmsg( ns_botptr, cmdparams->source, __( "Timer List:", cmdparams->source ) );
	tn = list_first(timerlist);
	while( tn != NULL )
	{
		timer = lnode_get( tn );
		irc_prefmsg( ns_botptr, cmdparams->source, "%s:", timer->moduleptr->info->name );
		irc_prefmsg( ns_botptr, cmdparams->source, __( "Timer: %s", cmdparams->source ), timer->name );
		switch( timer->type )
		{
			case TIMER_TYPE_DAILY:
				irc_prefmsg( ns_botptr, cmdparams->source, "Timer Type: Daily");
				break;
			case TIMER_TYPE_WEEKLY:
				irc_prefmsg( ns_botptr, cmdparams->source, "Timer Type: Weekly");
				break;
			case TIMER_TYPE_MONTHLY:
				irc_prefmsg( ns_botptr, cmdparams->source, "Timer Type: Monthly");
				break;
			case TIMER_TYPE_INTERVAL:
				irc_prefmsg( ns_botptr, cmdparams->source, "Timer Type: Interval");
				irc_prefmsg( ns_botptr, cmdparams->source, __( "Interval: %ld", cmdparams->source ), ( long )timer->interval );
				break;
			case TIMER_TYPE_COUNTDOWN:
				irc_prefmsg( ns_botptr, cmdparams->source, "Timer Type: Countdown");
				irc_prefmsg( ns_botptr, cmdparams->source, __( "Interval: %ld", cmdparams->source ), ( long )timer->interval );
				break;
		}
		irc_prefmsg( ns_botptr, cmdparams->source, __( "Next run at: %s", cmdparams->source ), sftime(timer->nextrun));
		irc_prefmsg( ns_botptr, cmdparams->source, __( "Last run at: %s", cmdparams->source ), sftime(timer->lastrun));
		tn = list_next(timerlist, tn);
	}
	irc_prefmsg( ns_botptr, cmdparams->source, __( "End of list.", cmdparams->source ) );
	return 0;
}
コード例 #25
0
ファイル: timer.c プロジェクト: DarkSpiritNET/NeoStats
void CheckTimers_cb( int notused, short event, void *arg )
{
	Timer *timer = NULL;
	lnode_t *tn;

	SET_SEGV_LOCATION();

	update_time_now();
	/* We only run Timers one at a time */
	tn = list_first(timerlist);
	timer = lnode_get( tn );
	/* If a module is not yet synched, reset it's lastrun */
	if( !IsModuleSynched( timer->moduleptr ) ) {
		timer->lastrun = ( int ) me.now;
	} else if (timer->nextrun <= me.now) {
		if( setjmp( sigvbuf ) == 0 ) {
			dlog( DEBUG10, "run_mod_timers: Running timer %s for module %s", timer->name, timer->moduleptr->info->name );
			SET_RUN_LEVEL( timer->moduleptr );
			if( timer->handler( timer->userptr ) < 0 ) {
				dlog( DEBUG2, "run_mod_timers: Deleting Timer %s for Module %s as requested", timer->name, timer->moduleptr->info->name );
				list_delete_destroy_node(timerlist, tn);
				ns_free( timer );
				NextSchedule();
			} else {
				timer->lastrun = ( int ) me.now;
				TimerCalcNextRun(timer, tn);
			}
			RESET_RUN_LEVEL();
#if 0
			if( timer->type == TIMER_TYPE_COUNTDOWN ) {
					hash_scan_delete_destroy_node( timerlist, tn );
					ns_free( timer );
			}
#endif
		} else {
			nlog( LOG_CRITICAL, "run_mod_timers: setjmp() failed, can't call module %s", timer->moduleptr->info->name );
			NextSchedule();
		}
	}
}
コード例 #26
0
ファイル: logging.c プロジェクト: 070499/xbmc
static void do_log(cp_context_t *context, cp_log_severity_t severity, const char *msg) {
	lnode_t *node;
	const char *apid = NULL;

	assert(cpi_is_context_locked(context));	
	if (context->env->in_logger_invocation) {
		cpi_fatalf(_("Encountered a recursive logging request within a logger invocation."));
	}
	if (context->plugin != NULL) {
		apid = context->plugin->plugin->identifier;
	}
	context->env->in_logger_invocation++;
	node = list_first(context->env->loggers);
	while (node != NULL) {
		logger_t *lh = lnode_get(node);
		if (severity >= lh->min_severity) {
			lh->logger(severity, msg, apid, lh->user_data);
		}
		node = list_next(context->env->loggers, node);
	}
	context->env->in_logger_invocation--;
}
コード例 #27
0
ファイル: logging.c プロジェクト: 070499/xbmc
CP_C_API void cp_unregister_logger(cp_context_t *context, cp_logger_func_t logger) {
	logger_t l;
	lnode_t *node;
	
	CHECK_NOT_NULL(context);
	CHECK_NOT_NULL(logger);
	cpi_lock_context(context);
	cpi_check_invocation(context, CPI_CF_LOGGER, __func__);
	
	l.logger = logger;
	if ((node = list_find(context->env->loggers, &l, comp_logger)) != NULL) {
		logger_t *lh = lnode_get(node);
		list_delete(context->env->loggers, node);
		lnode_destroy(node);
		free(lh);
		update_logging_limits(context);
	}
	if (cpi_is_logged(context, CP_LOG_DEBUG)) {
		char owner[64];
		/* TRANSLATORS: %s is the context owner */
		cpi_debugf(context, N_("%s unregistered a logger."), cpi_context_owner(context, owner, sizeof(owner)));
	}
	cpi_unlock_context(context);
}
コード例 #28
0
ファイル: timer.c プロジェクト: DarkSpiritNET/NeoStats
void FiniTimers( void )
{
	lnode_t *tn;
	Timer *timer;
	
	evtimer_del( evtimers );
	os_free( evtimers );
	DelTimer("PingServers");
	DelTimer("FlushLogs");
	if (nsconfig.setservertimes > 0) 
		DelTimer("SetServersTime");
	DelTimer("ResetLogs");

	if (list_count(timerlist) > 0) {
		tn = list_first(timerlist);
		while( tn != NULL )
		{
			timer = lnode_get( tn );
			dlog( DEBUG3, "FiniTimers() BUG: Timer %s not deleted for module %s", timer->name, timer->moduleptr->info->name );
			tn = list_next(timerlist, tn);
		}
	}
	list_destroy( timerlist );
}
コード例 #29
0
ファイル: timer.c プロジェクト: DarkSpiritNET/NeoStats
int del_timers( const Module *mod_ptr )
{
	Timer *timer;
	lnode_t *tn, *tn2;

	tn = list_first(timerlist);
	while( tn != NULL )
	{
		tn2 = list_next(timerlist, tn);
		timer = lnode_get( tn );
		if( timer->moduleptr == mod_ptr )
		{
			dlog( DEBUG1, "del_timers: deleting timer %s from module %s.", timer->name, mod_ptr->info->name );
			list_delete_destroy_node(timerlist, tn);
#ifdef USE_PERL
			if( IS_PERL_MOD( timer->moduleptr ) )
				ns_free( timer->userptr );
#endif /* USE_PERL */
			ns_free( timer );
		}
		tn = tn2;
	}
	return NS_SUCCESS;
}
コード例 #30
0
ファイル: timer.c プロジェクト: DarkSpiritNET/NeoStats
int DelTimer( const char *name )
{
	Timer *timer;
	lnode_t *tn;

	SET_SEGV_LOCATION();
	tn = list_first(timerlist);
	while (tn != NULL) {
		timer = lnode_get(tn);
		if (!ircstrcasecmp(timer->name, name)) {
			dlog( DEBUG2, "DelTimer: removed timer %s for module %s", name, timer->moduleptr->info->name );
			list_delete_destroy_node(timerlist, tn);
#ifdef USE_PERL
			if( IS_PERL_MOD( timer->moduleptr ) )
				ns_free( timer->userptr );
#endif /* USE_PERL */
			ns_free( timer );
			return NS_SUCCESS;
		}
		tn = list_next(timerlist, tn);
	}
	dlog(DEBUG2, "DelTimer: Timer %s not found", name);
	return NS_FAILURE;
}