int AddTimer( TIMER_TYPE type, timer_handler handler, const char *name, int interval, void *userptr ) { Timer *timer; Module *moduleptr; SET_SEGV_LOCATION(); moduleptr = GET_CUR_MODULE(); if( handler == NULL ) { nlog( LOG_WARNING, "Module %s timer %s does not exist", moduleptr->info->name, name ); return NS_FAILURE; } if( FindTimer( name ) ) { nlog( LOG_WARNING, "Module %s timer %s already exists. Not adding.", moduleptr->info->name, name ); return NS_FAILURE; } timer = new_timer( name ); if( timer ) { timer->type = type; timer->interval = interval; timer->lastrun = me.now; timer->moduleptr = moduleptr; timer->handler = handler; timer->userptr = userptr; TimerCalcNextRun(timer, NULL); dlog( DEBUG2, "AddTimer: Module %s added timer %s", moduleptr->info->name, name ); return NS_SUCCESS; } return NS_FAILURE; }
/* * This function is called when we are no longer interested in receiving * notification from state changes on a link. */ void nwamd_dlpi_delete_link(nwamd_object_t obj) { nwamd_ncu_t *ncu = obj->nwamd_object_data; nlog(LOG_DEBUG, "nwamd_dlpi_delete_link: ncu %p (%s) type %d", ncu, obj->nwamd_object_name, ncu != NULL ? ncu->ncu_type : -1); if (ncu->ncu_link.nwamd_link_dlpi_thread != 0) { (void) pthread_cancel( ncu->ncu_link.nwamd_link_dlpi_thread); (void) pthread_join(ncu->ncu_link.nwamd_link_dlpi_thread, NULL); ncu->ncu_link.nwamd_link_dlpi_thread = 0; /* Unset properties before closing. Wifi links do not support * setting/unsetting these properties */ if (dladm_wlan_validate(dld_handle, ncu->ncu_link.nwamd_link_id, NULL, NULL) == DLADM_STATUS_OK) { nlog(LOG_DEBUG, "nwamd_dlpi_delete_link(%s): skipping " "wifi link properties de-initialization", ncu->ncu_name); } else nwamd_set_unset_link_properties(ncu, B_FALSE); } dlpi_close(ncu->ncu_link.nwamd_link_dhp); ncu->ncu_link.nwamd_link_dhp = NULL; }
int InitTLDStatistics( void ) { TLD *t; SET_SEGV_LOCATION(); tldstatlist = nv_list_create( LISTCOUNT_T_MAX, "StatServ-TLD", nv_ss_tld, NV_FLAGS_RO, NULL ); if( !tldstatlist ) { nlog( LOG_CRITICAL, "Unable to create TLD list" ); return NS_FAILURE; } gi = NULL; /* now open the various DB's */ if( GeoIP_db_avail( GEOIP_COUNTRY_EDITION ) ) { gi = GeoIP_open_type( GEOIP_COUNTRY_EDITION, GEOIP_STANDARD ); if( gi != NULL ) nlog( LOG_NOTICE, "Loaded %s GeoIP Database", GeoIPDBDescription[GEOIP_COUNTRY_EDITION] ); else nlog( LOG_WARNING, "%s Database may be corrupt", GeoIPDBDescription[GEOIP_COUNTRY_EDITION] ); } else { nlog( LOG_WARNING, "GeoIP Database is not available. TLD stats will not be available" ); } t = ns_calloc( sizeof( TLD ) ); ircsnprintf( t->tld, 5, UNKNOWN_COUNTRY_CODE ); strlcpy( t->country, "Unknown", 8 ); lnode_create_append( tldstatlist, t ); DBAOpenTable( TLD_TABLE ); LoadTLDStats(); return NS_SUCCESS; }
void ls_switch_file( ChannelLog *cl ) { static char tmbuf[MAXPATH]; static char newfname[MAXPATH]; static char oldfname[MAXPATH]; int res; /* no need to switch, its not opened */ if( cl->logfile == NULL ) return; ls_close_log( cl ); /* check if the target directory exists */ if( os_create_dir( LogServ.savedir ) != NS_SUCCESS ) { return; } os_strftime( tmbuf, MAXPATH, "%d%m%Y%H%M%S", os_localtime( &me.now ) ); ircsnprintf( newfname, MAXPATH, "%s/%s-%s.log", LogServ.savedir, cl->filename, tmbuf ); ircsnprintf( oldfname, MAXPATH, "%s/%s.log", LogServ.logdir, cl->filename ); res = os_rename( oldfname, newfname ); if( res != 0 ) { nlog( LOG_CRITICAL, "Couldn't rename file %s: %s", oldfname, os_strerror() ); return; } nlog( LOG_NORMAL, "Switched Logfile for %s from %s to %s", cl->channame, oldfname, newfname ); }
void AddEvent( ModuleEvent *eventptr ) { Module *mod_ptr; if( !eventptr ) { nlog( LOG_ERROR, "AddEvent: eventptr passed as NULL" ); return; } mod_ptr = GET_CUR_MODULE(); dlog( DEBUG9, "AddEvent: adding %s to %s", EventStrings[eventptr->event], mod_ptr->info->name ); #ifdef USE_PERL if( ( eventptr->flags & EVENT_FLAG_PERLCALL ) ) { if( ( mod_ptr->pm && !mod_ptr->pm->event_list ) ) mod_ptr->pm->event_list = ns_calloc( sizeof( ModuleEvent * ) * EVENT_COUNT ); mod_ptr->pm->event_list[eventptr->event] = eventptr; } else #endif /* USE_PERL */ { if( !eventptr->handler ) { nlog( LOG_ERROR, "AddEvent: missing handler for %s in module %s", EventStrings[eventptr->event], mod_ptr->info->name ); return; } if( !mod_ptr->event_list ) mod_ptr->event_list = ns_calloc( sizeof( ModuleEvent * ) * EVENT_COUNT ); mod_ptr->event_list[eventptr->event] = eventptr; } if( eventptr->event == EVENT_NICKIP ) me.want_nickip = 1; }
void signal_fatal(int sig) { signal(sig,SIG_DFL); nlog("A fatal signal (%d) was caught.", sig); if(crash_save){ close_sockets(0); nlog("All sockets were closed."); kill(getpid(),SIGABRT); } /*return SIG_RET_VAL;*/ }
HV *perl_encode_namedvars(nv_list *nv, void *data) { HV *ret; int i =0; ret = newHV(); while (nv->format[i].fldname != NULL) { switch(nv->format[i].type) { case NV_PSTR: case NV_STR: hv_store(ret, nv->format[i].fldname, strlen(nv->format[i].fldname), newSVpv(nv_gf_string(data, nv, i), strlen(nv_gf_string(data, nv, i))), 0); break; case NV_INT: case NV_LONG: hv_store(ret, nv->format[i].fldname, strlen(nv->format[i].fldname), newSViv(nv_gf_int(data, nv, i)), 0); break; case NV_VOID: case NV_PSTRA: nlog(LOG_WARNING, "perl_encode_namedvars: void/string todo!"); break; } i++; } return ret; }
int ss_cmd_forcehtml( const CmdParams *cmdparams ) { nlog( LOG_NOTICE, "%s!%s@%s forced an update of the HTML file.", cmdparams->source->name, cmdparams->source->user->username, cmdparams->source->user->hostname ); HTMLOutput(); return NS_SUCCESS; }
static void SendEvent( const ModuleEvent *eventptr, Event event, const CmdParams *cmdparams, Module *module_ptr ) { if( !eventptr ) { dlog( DEBUG9, "SendEvent: %s has no event handler for %s", module_ptr->info->name, EventStrings[event] ); return; } /* If we are not yet synched, check that the module supports * the event before we are synched. */ if( !IsModuleSynched( module_ptr ) && !( eventptr->flags & EVENT_FLAG_IGNORE_SYNCH ) ) { dlog( DEBUG9, "Skipping module %s for %s since module is not yet synched", module_ptr->info->name, EventStrings[event] ); return; } if( ( eventptr->flags & EVENT_FLAG_DISABLED ) ) { dlog( DEBUG9, "Skipping module %s for %s since it is disabled", module_ptr->info->name, EventStrings[event] ); return; } if( ( eventptr->flags & EVENT_FLAG_EXCLUDE_ME ) && IsMe( cmdparams->source ) ) { dlog( DEBUG9, "Skipping module %s for %s since %s is excluded as a NeoStats client", module_ptr->info->name, EventStrings[event], cmdparams->source->name ); return; } if( eventptr->flags & EVENT_FLAG_EXCLUDE_MODME ) { if( cmdparams->source && cmdparams->source->user && cmdparams->source->user->bot && cmdparams->source->user->bot->moduleptr == module_ptr ) { dlog( DEBUG9, "Skipping module %s for %s since %s is excluded as a Module client", module_ptr->info->name, EventStrings[event], cmdparams->source->name ); return; } } if( ( eventptr->flags & EVENT_FLAG_USE_EXCLUDE ) && IsExcluded( cmdparams->source ) ) { dlog( DEBUG9, "Skipping module %s for %s since %s is excluded", module_ptr->info->name, EventStrings[event], cmdparams->source->name ); return; } dlog( DEBUG9, "Running module %s with %s", module_ptr->info->name, EventStrings[event] ); SET_SEGV_LOCATION(); #ifdef USE_PERL if( ( eventptr->flags & EVENT_FLAG_PERLCALL ) ) { SET_RUN_LEVEL( module_ptr ); perl_event_cb( event, cmdparams, module_ptr ); RESET_RUN_LEVEL(); return; } #endif /* USE_PERL */ if( setjmp( sigvbuf ) == 0 ) { SET_RUN_LEVEL( module_ptr ); ( void )module_ptr->event_list[event]->handler( cmdparams ); RESET_RUN_LEVEL(); } else { nlog( LOG_CRITICAL, "SendEvent: setjmp() failed, not calling module %s", module_ptr->info->name ); } }
void DisableEvent( Event event ) { ModuleEvent **eventlistptr; eventlistptr = GET_CUR_MODULE()->event_list; if( !eventlistptr ) { nlog( LOG_ERROR, "DisableEvent: %s has no eventlist", GET_CUR_MODULE()->info->name ); return; } if( !eventlistptr[event] ) { nlog( LOG_ERROR, "DisableEvent: %s has no event %s", GET_CUR_MODULE()->info->name, EventStrings[event] ); return; } eventlistptr[event]->flags |= EVENT_FLAG_DISABLED; }
void open_player_log() { player_log=fopen("PLAYER.LOG","a+"); if (!player_log) { nlog("Error, could not open PLAYER.LOG"); exit(1); } }
/* Handle loc finish event */ void nwamd_loc_handle_fini_event(nwamd_event_t event) { nwamd_object_t object; nlog(LOG_DEBUG, "nwamd_loc_handle_fini_event(%s)", event->event_object); /* Don't disable the location, as this can enable the Automatic loc */ if ((object = nwamd_object_find(NWAM_OBJECT_TYPE_LOC, event->event_object)) == NULL) { nlog(LOG_INFO, "nwamd_loc_handle_fini_event: " "loc %s not found", event->event_object); nwamd_event_do_not_send(event); return; } nwamd_object_release_and_destroy(object); }
static int doc_gc(lua_State *L) { struct xmlwrap_object *xml2 = lua_touserdata(L, 1); nlog(NLOG_TRACE, "GC XML document %p", (void *) xml2->doc); if (xml2->doc != NULL) xmlFreeDoc(xml2->doc); return 0; }
void ModuleConfig( bot_setting* set_ptr ) { SET_SEGV_LOCATION(); DBAOpenTable( CONFIG_TABLE_NAME ); while( set_ptr->option != NULL ) { switch( set_ptr->type ) { case SET_TYPE_BOOLEAN: if( DBAFetchConfigBool( set_ptr->option, set_ptr->varptr ) != NS_SUCCESS ) { *( int * )set_ptr->varptr = ( int )set_ptr->defaultval; DBAStoreConfigBool( set_ptr->option, set_ptr->varptr ); } if( set_ptr->handler ) { set_ptr->handler( NULL, SET_LOAD ); } break; case SET_TYPE_INT: if( DBAFetchConfigInt( set_ptr->option, set_ptr->varptr ) != NS_SUCCESS ) { *( int * )set_ptr->varptr = ( int )set_ptr->defaultval; DBAStoreConfigInt( set_ptr->option, set_ptr->varptr ); } if( set_ptr->handler ) { set_ptr->handler( NULL, SET_LOAD ); } break; case SET_TYPE_STRING: case SET_TYPE_CHANNEL: case SET_TYPE_MSG: case SET_TYPE_NICK: case SET_TYPE_USER: case SET_TYPE_HOST: case SET_TYPE_REALNAME: case SET_TYPE_IPV4: if( DBAFetchConfigStr( set_ptr->option, set_ptr->varptr, set_ptr->max ) != NS_SUCCESS ) { if( set_ptr->defaultval ) { strlcpy( set_ptr->varptr, set_ptr->defaultval, set_ptr->max ); } DBAStoreConfigStr( set_ptr->option, set_ptr->varptr, set_ptr->max ); } if( set_ptr->handler ) { set_ptr->handler( NULL, SET_LOAD ); } break; case SET_TYPE_CUSTOM: if( set_ptr->handler ) { set_ptr->handler( NULL, SET_LOAD ); } break; default: nlog( LOG_WARNING, "Unsupported SET type %d in ModuleConfig %s", set_ptr->type, set_ptr->option ); break; } set_ptr++; } DBACloseTable( CONFIG_TABLE_NAME ); }
unsigned int hrand( const unsigned int upperbound, const unsigned int lowerbound ) { if( upperbound < 1 ) { nlog( LOG_WARNING, "hrand() invalid value for upperbound" ); return 0; } return( ( unsigned )( rand()%( ( int )( ( upperbound - lowerbound ) + 1 ) )-( ( int )( lowerbound - 1 ) ) ) ); }
int InitModules( void ) { SET_SEGV_LOCATION(); modulehash = nv_hash_create( NUM_MODULES, 0, 0, "Modules", nv_modules, NV_FLAGS_RO, NULL); if( !modulehash ) { nlog( LOG_CRITICAL, "Unable to create module hash" ); return NS_FAILURE; } return NS_SUCCESS; }
void HTMLOutput( void ) { #define HTMLREADBUFSIZE 512 static char buf[HTMLREADBUFSIZE]; FILE *tpl; char *buftemp; char *bufptr; htmlfunc* htmlfuncptr; tpl = os_fopen( html_template, "rt" ); if( !tpl ) { nlog( LOG_WARNING, "Failed to open StatServ HTML template %s.", html_template ); irc_chanalert( statbot, "Failed to open StatServ HTML template %s.", html_template ); return; } opf = os_fopen( StatServ.htmlpath, "wt" ); if( !opf ) { nlog( LOG_WARNING, "Failed to open HTML output file %s. Check file permissions.", StatServ.htmlpath ); irc_chanalert( statbot, "Failed to open HTML output file %s. Check file permissions.", StatServ.htmlpath ); return; } while( os_fgets( buf, HTMLREADBUFSIZE, tpl ) != NULL ) { bufptr = buf; htmlfuncptr = htmlfuncs; while( htmlfuncptr->directive != NULL ) { buftemp = strstr( bufptr, htmlfuncptr->directive ); if( buftemp ) { os_fwrite( bufptr, ( int )buftemp -( int )bufptr, 1, opf ); htmlfuncptr->handler(); bufptr = buftemp + strlen( htmlfuncptr->directive ); } htmlfuncptr++; } os_fputs( bufptr, opf ); } os_fclose( tpl ); os_fclose( opf ); /* update the umode so others can read it and owner can overwrite it */ os_chmod( StatServ.htmlpath, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH ); }
static int LoadAccessList( void ) { accesshash = nv_hash_create( HASHCOUNT_T_MAX, 0, 0, "ExtAuth", nv_extauth, NV_FLAGS_RO, NULL); if( !accesshash ) { nlog( LOG_CRITICAL, "Unable to create accesslist hash" ); return NS_FAILURE; } DBAFetchRows( "AccessList", LoadAccessListEntry ); return NS_SUCCESS; }
void SetEventFlags( Event event, unsigned int flag, unsigned int enable ) { ModuleEvent **eventlistptr; eventlistptr = GET_CUR_MODULE()->event_list; if( !eventlistptr ) { nlog( LOG_ERROR, "SetEventFlags: %s has no eventlist", GET_CUR_MODULE()->info->name ); return; } if( !eventlistptr[event] ) { nlog( LOG_ERROR, "SetEventFlags: %s has no event %s", GET_CUR_MODULE()->info->name, EventStrings[event] ); return; } if( enable ) eventlistptr[event]->flags |= flag; else eventlistptr[event]->flags &= ~flag; }
/* * We are only intested in DL_NOTE_LINK_UP events which we've registered for * in nwamd_dlpi_add_link(). But we have to keep calling dlpi_recv() to * force the notification callback to be executed. */ static void * nwamd_dlpi_thread(void *arg) { int rc; dlpi_handle_t *dh = arg; do { rc = dlpi_recv(*dh, NULL, NULL, NULL, NULL, -1, NULL); } while (rc == DLPI_SUCCESS); nlog(LOG_ERR, "dlpi_recv failed: %s", dlpi_strerror(rc)); return (NULL); }
void load_module_error( const Client *target, const char *module_name, const char *fmt, ... ) { static char buf[BUFSIZE]; va_list ap; va_start( ap, fmt ); ircvsnprintf( buf, BUFSIZE, fmt, ap ); va_end( ap ); if( target ) { irc_prefmsg( ns_botptr, target, __( "Unable to load module %s: %s", u ), module_name, buf ); } nlog( LOG_WARNING, buf ); }
void AddEventList( ModuleEvent *eventlistptr ) { if( !eventlistptr ) { nlog( LOG_ERROR, "AddEventList: eventlistptr passed as NULL" ); return; } while( eventlistptr->event != EVENT_NULL ) { AddEvent( eventlistptr ); eventlistptr ++; } }
void DeleteEventList( const ModuleEvent *eventlistptr ) { if( !eventlistptr ) { nlog( LOG_ERROR, "DeleteEventList: eventlistptr passed as NULL" ); return; } while( eventlistptr->event != EVENT_NULL ) { DeleteEvent( eventlistptr->event ); eventlistptr++; } }
static boolean_t loc_is_enabled(nwam_loc_handle_t loch) { nwam_value_t enabledval; boolean_t enabled = B_FALSE; if (nwam_loc_get_prop_value(loch, NWAM_LOC_PROP_ENABLED, &enabledval) != NWAM_SUCCESS) { nlog(LOG_ERR, "loc_is_enabled: could not retrieve " "enabled value"); return (B_FALSE); } if (nwam_value_get_boolean(enabledval, &enabled) != NWAM_SUCCESS) { nlog(LOG_ERR, "loc_is_enabled: could not retrieve " "enabled value"); nwam_value_free(enabledval); return (B_FALSE); } nwam_value_free(enabledval); return (enabled); }
void Filter_4::setup() { cutoff = nlog(60, param[22]+1.0) ; // printf("\n%f", cutoff); resonance = param[23]; q = 1.0f - cutoff; p = cutoff + 0.8f * cutoff * q; f = p + p - 1.0f; q = resonance * (1.0f + 0.5f * q * (1.0f - q + 5.6f * q * q)); }
static int64_t loc_get_activation_mode(nwam_loc_handle_t loch) { nwam_error_t err; uint64_t activation; nwam_value_t activationval; if (nwam_loc_get_prop_value(loch, NWAM_LOC_PROP_ACTIVATION_MODE, &activationval) != NWAM_SUCCESS) { nlog(LOG_ERR, "loc_get_activation_mode: could not retrieve " "activation mode value"); return (-1); } err = nwam_value_get_uint64(activationval, &activation); nwam_value_free(activationval); if (err != NWAM_SUCCESS) { nlog(LOG_ERR, "loc_get_activation_mode: could not retrieve " "activation mode value"); return (-1); } return ((int64_t)activation); }
static int new_tld( void *data, int size ) { TLD *t; if( size != sizeof( TLD ) ) { nlog( LOG_CRITICAL, "TLD data size invalid" ); return NS_FALSE; } t = ns_calloc( sizeof( TLD ) ); os_memcpy( t, data, sizeof( TLD ) ); lnode_create_append( tldstatlist, t ); return NS_FALSE; }
/* * This is called when we want to start receiving notifications from state * changes on a link. */ void nwamd_dlpi_add_link(nwamd_object_t obj) { nwamd_ncu_t *ncu = obj->nwamd_object_data; nwamd_link_t *link; dlpi_notifyid_t id; int rc; nlog(LOG_DEBUG, "nwamd_dlpi_add_link: ncu %p (%s) type %d", ncu, obj->nwamd_object_name, ncu != NULL ? ncu->ncu_type : -1); assert(ncu != NULL && ncu->ncu_type == NWAM_NCU_TYPE_LINK); link = &ncu->ncu_link; /* Already running? */ if (link->nwamd_link_dlpi_thread != 0) { nlog(LOG_DEBUG, "nwamd_dlpi_add_link(%s) already running", obj->nwamd_object_name); return; } rc = dlpi_open(ncu->ncu_name, &link->nwamd_link_dhp, 0); if (rc != DLPI_SUCCESS) { nlog(LOG_ERR, "nwamd_dlpi_add_link: dlpi_open(%s) = %s", ncu->ncu_name, dlpi_strerror(rc)); return; } /* Wifi links do not support setting/unsetting these properties */ if (dladm_wlan_validate(dld_handle, ncu->ncu_link.nwamd_link_id, NULL, NULL) == DLADM_STATUS_OK) { nlog(LOG_DEBUG, "nwamd_dlpi_add_link(%s): skipping " "wifi link properties initialization", ncu->ncu_name); } else nwamd_set_unset_link_properties(ncu, B_TRUE); rc = dlpi_enabnotify(link->nwamd_link_dhp, DL_NOTE_LINK_UP | DL_NOTE_LINK_DOWN, nwamd_dlpi_notify, ncu->ncu_name, &id); if (rc != DLPI_SUCCESS) { nlog(LOG_ERR, "nwamd_dlpi_add_link: dlpi_enabnotify(%s) = %s", obj->nwamd_object_name, dlpi_strerror(rc)); dlpi_close(link->nwamd_link_dhp); return; } rc = pthread_create(&link->nwamd_link_dlpi_thread, NULL, nwamd_dlpi_thread, &link->nwamd_link_dhp); if (rc != 0) { nlog(LOG_ERR, "nwamd_dlpi_add_link: couldn't create " "dlpi thread for %s: %s", obj->nwamd_object_name, strerror(rc)); dlpi_close(link->nwamd_link_dhp); } }
static Timer *new_timer( const char *name ) { Timer *timer; SET_SEGV_LOCATION(); if( list_isfull( timerlist ) ) { nlog( LOG_WARNING, "new_timer: timer hash is full" ); return NULL; } dlog( DEBUG2, "new_timer: %s", name ); timer = ns_calloc( sizeof( Timer ) ); strlcpy( timer->name, name, MAX_MOD_NAME ); return timer; }
char *sstrdup( const char *s ) { char *t; if( s == NULL ) return NULL; t = ns_malloc( strlen( s ) + 1 ); strlcpy( t, s, strlen( s ) + 1 ); if( t == NULL ) { nlog( LOG_CRITICAL, "sstrdup(): out of memory." ); do_exit( NS_EXIT_ERROR, "Out of memory" ); } return t; }