static int command_patternexadd(struct plugin_handle* plugin, struct plugin_user* user, struct plugin_command* cmd) { struct patterns_data* pdata = (struct patterns_data*) plugin->ptr; struct cbuffer* buf = cbuf_create(128); struct plugin_command_arg_data* arg1 = (struct plugin_command_arg_data*) list_get_first(cmd->args); struct plugin_command_arg_data* arg2 = (struct plugin_command_arg_data*) list_get_next(cmd->args); struct plugin_command_arg_data* arg3 = (struct plugin_command_arg_data*) list_get_next(cmd->args); struct plugin_command_arg_data* arg4 = (struct plugin_command_arg_data*) list_get_next(cmd->args); int pattern_id = arg1->data.integer; enum auth_credentials mincred = arg2->data.credentials; enum auth_credentials maxcred = arg3->data.credentials; char* str = arg4->data.string; int rc = sql_execute(pdata, null_callback, NULL, "PRAGMA foreign_keys=ON; INSERT INTO pattern_exceptions VALUES(NULL, '%s', %d, '%s', '%s');", sql_escape_string(str), pattern_id, auth_cred_to_string(mincred), auth_cred_to_string(maxcred)); if (rc > 0) cbuf_append_format(buf, "*** %s: Added pattern exception \"%s\" to pattern ID %d.", cmd->prefix, str, pattern_id); else cbuf_append_format(buf, "*** %s: Unable to add pattern exception \"%s\" to pattern ID %d.", cmd->prefix, str, pattern_id); plugin->hub.send_message(plugin, user, cbuf_get(buf)); cbuf_destroy(buf); return 0; }
static int command_patternadd(struct plugin_handle* plugin, struct plugin_user* user, struct plugin_command* cmd) { struct patterns_data* pdata = (struct patterns_data*) plugin->ptr; struct cbuffer* buf = cbuf_create(128); struct plugin_command_arg_data* arg1 = (struct plugin_command_arg_data*) list_get_first(cmd->args); struct plugin_command_arg_data* arg2 = (struct plugin_command_arg_data*) list_get_next(cmd->args); struct plugin_command_arg_data* arg3 = (struct plugin_command_arg_data*) list_get_next(cmd->args); struct plugin_command_arg_data* arg4 = (struct plugin_command_arg_data*) list_get_next(cmd->args); char* t = arg1->data.string; enum pattern_types type; if (!pattern_string_to_type(t, &type)) { cbuf_append_format(buf, "*** %s: Wrong pattern type \"%s\". Available types are: MC, PM, NI, UA.", cmd->prefix, t); } else { enum auth_credentials mincred = arg2->data.credentials; enum auth_credentials maxcred = arg3->data.credentials; char* str = arg4->data.string; int rc = sql_execute(pdata, null_callback, NULL, "INSERT INTO patterns VALUES(NULL, '%s', %d, '%s', '%s');", sql_escape_string(str), type, auth_cred_to_string(mincred), auth_cred_to_string(maxcred)); if (rc > 0) cbuf_append_format(buf, "*** %s: Added pattern \"%s\" to %s group.", cmd->prefix, str, pattern_type_to_string(type)); else cbuf_append_format(buf, "*** %s: Unable to add pattern \"%s\".", cmd->prefix, str); } plugin->hub.send_message(plugin, user, cbuf_get(buf)); cbuf_destroy(buf); return 0; }
void fill_neighbours(Network *N,int s,int t,int direct,int *arr,int *arr_len) /* add all weakly connected nodes of s to arr, and return also arr_len */ /* direct - 1 if there is an edge from s to t. 0 if there is an edge from t to s don't add node t */ { list_item *tmp; list_item *tmp2; // add all incoming and outgoing edges from/to node s, except t tmp = list_get_next(N->mat->spr->m[s].to,NULL); tmp2 = list_get_next(N->mat->spr->m[s].from,NULL); while (tmp != NULL) { if (direct) { if (tmp->val!=t) { arr[*arr_len]=tmp->val; (*arr_len)=(*arr_len)+1; } } else { arr[*arr_len]=tmp->val; (*arr_len)=(*arr_len)+1; } tmp=list_get_next(N->mat->spr->m[s].to,tmp); } while (tmp2 != NULL) { if (!direct) { if (tmp2->val!=t) { arr[*arr_len]=tmp2->val; (*arr_len)=(*arr_len)+1; } } else { arr[*arr_len]=tmp2->val; (*arr_len)=(*arr_len)+1; } tmp2=list_get_next(N->mat->spr->m[s].from,tmp2); } }
int route_to_subscribers(struct hub_info* hub, struct adc_message* command) /* iterate users */ { int do_send; char* tmp; struct hub_user* user = (struct hub_user*) list_get_first(hub->users->list); while (user) { if (user->feature_cast) { do_send = 1; tmp = list_get_first(command->feature_cast_include); while (tmp) { if (!user_have_feature_cast_support(user, tmp)) { do_send = 0; break; } tmp = list_get_next(command->feature_cast_include);; } if (!do_send) { user = (struct hub_user*) list_get_next(hub->users->list); continue; } tmp = list_get_first(command->feature_cast_exclude); while (tmp) { if (user_have_feature_cast_support(user, tmp)) { do_send = 0; break; } tmp = list_get_next(command->feature_cast_exclude); } if (do_send) { route_to_user(hub, user, command); } } user = (struct hub_user*) list_get_next(hub->users->list); } return 0; }
void list_free_mem(list *L) { list_item *item,*tmp; if(L==NULL) return; for(item=list_get_next(L,NULL); item!=NULL;) { tmp=item; item=list_get_next(L,item); if(tmp->p !=NULL) free(tmp->p); free(tmp); } free((void*)L); }
/*! display active & ready threads info on console */ int kthread_info () { kthread_t *kthread; int i = 1; kprintf ( "Threads info\n" ); kprintf ( "[this]\tid=%d (desc. at %x) in process at %x, size=%d\n", active_thread->id, active_thread, active_thread->proc->m.start, active_thread->proc->m.size ); kprintf ( "\tprio=%d, state=%d, exit_status=%x\n", active_thread->sched_priority, active_thread->state.state, active_thread->state.exit_status ); kthread = list_get ( &all_threads, FIRST ); while ( kthread ) { kprintf ( "[%d]\tid=%d (desc. at %x) in process at %x, size=%d\n", i++, kthread->id, kthread, kthread->proc->m.start, kthread->proc->m.size ); kprintf ( "\tprio=%d, state=%d, exit_status=%x\n", kthread->sched_priority, kthread->state.state, kthread->state.exit_status ); kthread = list_get_next ( &kthread->all ); } return 0; }
/*! Display info on threads */ int k_thread_info () { kthread_t *kthr; int i = 1; kprint ( "Threads info\n" ); kprint ( "[this]\tid=%d in process at %x, size=%d\n", active_thread->id, active_thread->proc->m.start, active_thread->proc->m.size ); kprint ( "\tprio=%d, state=%d, ret_val=%d\n", active_thread->sched.prio, active_thread->state, active_thread->exit_status ); kthr = list_get ( &all_threads, FIRST ); while ( kthr ) { kprint ( "[%d]\tid=%d in process at %x, size=%d\n", i++, kthr->id, kthr->proc->m.start, kthr->proc->m.size ); kprint ( "\tprio=%d, state=%d, ret_val=%d\n", kthr->sched.prio, kthr->state, kthr->exit_status ); kthr = list_get_next ( &kthr->all ); } return 0; }
int uman_send_user_list(struct hub_info* hub, struct hub_user* target) { int ret = 1; struct hub_user* user; user_flag_set(target, flag_user_list); user = (struct hub_user*) list_get_first(hub->users->list); /* iterate users - only on INF or PAS msg */ while (user) { if (user_is_logged_in(user)) { ret = route_to_user(hub, target, user->info); if (!ret) break; } user = (struct hub_user*) list_get_next(hub->users->list); } #if 0 FIXME: FIXME FIXME handle send queue excess if (!target->send_queue_size) { user_flag_unset(target, flag_user_list); } #endif return ret; }
int route_info_message(struct hub_info* hub, struct hub_user* u) { if (!user_is_nat_override(u)) { return route_to_all(hub, u->info); } else { struct adc_message* cmd = adc_msg_copy(u->info); const char* address = user_get_address(u); struct hub_user* user = 0; adc_msg_remove_named_argument(cmd, ADC_INF_FLAG_IPV4_ADDR); adc_msg_add_named_argument(cmd, ADC_INF_FLAG_IPV4_ADDR, address); user = (struct hub_user*) list_get_first(hub->users->list); while (user) { if (user_is_nat_override(user)) route_to_user(hub, user, cmd); else route_to_user(hub, user, u->info); user = (struct hub_user*) list_get_next(hub->users->list); } adc_msg_free(cmd); } return 0; }
/*! Open device with 'name' (for exclusive use, if defined) */ kdevice_t *k_device_open ( char *name ) { kdevice_t *kdev; kdev = list_get ( &devices, FIRST ); while ( kdev ) { if ( !strcmp ( name, kdev->dev.dev_name ) ) { if ( kdev->dev.flags & DEV_TYPE_NOTSHARED ) { if ( kdev->open ) { return NULL; /* in use */ } else { kdev->open = TRUE; return kdev; } } else { kdev->open = TRUE; return kdev; } } kdev = list_get_next ( &kdev->list ); } return NULL; }
void jabber_mam_process(JabberStream *js, const char* after) { if (!js->mam) return; if (js->mam->current && js->mam->current->completed) { free(js->mam->current->start); free(js->mam->current->end); free(js->mam->current->with); memset(js->mam->last_timestamp, 0, 32); free(js->mam->current); js->mam->current = NULL; } if (!js->mam->current) { list_t *queue_item = list_get_first(js->mam->queue); if (queue_item) { js->mam->queue = list_delete(js->mam->queue, queue_item); js->mam->current = list_get_data(queue_item); js->mam->queue = list_get_next(js->mam->queue); } } if (js->mam->current) jabber_mam_request(js, after); }
/*! Process pending signals for thread (called from kthreads_schedule ()) */ int ksignal_process_pending ( kthread_t *kthread ) { ksignal_handling_t *sh; int retval = EXIT_SUCCESS; ksiginfo_t *ksig, *next; ASSERT ( kthread ); sh = kthread_get_sigparams ( kthread ); ksig = list_get ( &sh->pending_signals, FIRST ); while ( ksig ) { next = list_get_next ( &ksig->list ); if ( !sigtestset ( sh->mask, ksig->siginfo.si_signo ) ) { list_remove ( &sh->pending_signals, 0, &ksig->list ); retval = ksignal_queue ( kthread, &ksig->siginfo ); kfree ( ksig ); /* handle only first signal? * no, all of them - they will mask ... */ /*if ( retval == EXIT_SUCCESS ) break;*/ } ksig = next; } return retval; }
/*! * Give list of all programs * \param buffer Pointer to string where to save all programs names * \param buf_size Size of 'buffer' * \return 0 if successful, ENOMEM if buffer not big enough */ int k_list_programs ( char *buffer, size_t buf_size ) { size_t cur_size; kprog_t *prog; char hdr[] = "List of programs:\n"; buffer[0] = 0; /* set empty string */ cur_size = 0; prog = list_get ( &progs, FIRST ); if ( strlen ( hdr ) > buf_size ) return ENOMEM; strcpy ( buffer, hdr ); while ( prog ) { cur_size += strlen ( prog->prog_name ); if ( cur_size > buf_size ) return ENOMEM; strcat ( buffer, prog->prog_name ); strcat ( buffer, " " ); prog = list_get_next ( &prog->list ); } return EXIT_SUCCESS; }
/*! * "Forward" interrupt handling to registered handler * (called from interrupts.S) */ void arch_interrupt_handler ( int cpsr ) { struct ihndlr *ih; int irqn = arch_get_irqn ( cpsr & 0x001f ); /* retrieve handler number from interrupt controller for IRQ and FIQ */ if( irqn == INT_SRC_IRQ || irqn == INT_SRC_FIQ ) irqn = icdev->get_irq (); if( irqn > 0 && irqn < INTERRUPTS ) { if ( ( ih = list_get ( &ihandlers[irqn], FIRST) ) != NULL ) { /* Call registered handlers */ while ( ih ) { ih->ihandler ( irqn ); ih = list_get_next ( &ih->list ); } } else { LOG ( ERROR, "Unregistered interrupt: %d!\n(%s)\n", irqn, icdev->int_descr ( irqn ) ); halt (); } } else { LOG ( ERROR, "Unknown interrupt: %d !\n", irqn ); halt (); } }
/** * Obtain 'num' messages from the chat history and append them to outbuf. * * @return the number of messages added to the buffer. */ static size_t get_messages(struct chat_history_data* data, size_t num, struct cbuffer* outbuf) { struct linked_list* messages = data->chat_history; char* message; int skiplines = 0; size_t lines = 0; size_t total = list_size(messages); if (total == 0) return 0; if (num <= 0 || num > total) num = total; if (num != total) skiplines = total - num; cbuf_append(outbuf, "\n"); message = (char*) list_get_first(messages); while (message) { if (--skiplines < 0) { cbuf_append(outbuf, message); lines++; } message = (char*) list_get_next(messages); } cbuf_append(outbuf, "\n"); return lines; }
/*! * "Forward" interrupt handling to registered handler * (called from interrupts.S) */ void arch_interrupt_handler ( int irq_num ) { struct ihndlr *ih; if(irq_num < INTERRUPTS && (ih = list_get (&ihandlers[irq_num], FIRST))) { /* enable interrupts on PIC immediately since program may not * return here immediately */ if ( icdev->at_exit ) icdev->at_exit ( irq_num ); /* Call registered handlers */ while ( ih ) { ih->ihandler ( irq_num ); ih = list_get_next ( &ih->list ); } } else if ( irq_num < INTERRUPTS ) { LOG ( ERROR, "Unregistered interrupt: %d - %s!\n", irq_num, icdev->int_descr ( irq_num ) ); halt (); } else { LOG ( ERROR, "Unregistered interrupt: %d !\n", irq_num ); halt (); } }
void cpu_reset_all() { struct list_link *link = cpu_instances; struct cpu_instance *instance; while ((instance = list_get_next(&link))) if (instance->cpu->reset) instance->cpu->reset(instance); }
static int list_size(node_t *node) { int size; for (size = 0; node; node = list_get_next(node)) size++; return size; }
void cpu_interrupt(int irq) { struct cpu_instance *instance; struct list_link *link = cpu_instances; /* Interrupt first CPU only */ instance = list_get_next(&link); if (instance->cpu && instance->cpu->interrupt) instance->cpu->interrupt(instance, irq); }
void print_list(List *l) { ListNode *node = list_get_head(l); printf("\n----\n"); while (node) { printf("%d ", node->data); node = list_get_next(l, node); } printf("\n----\n\n"); }
void cpu_halt(bool halt) { struct cpu_instance *instance; struct list_link *link = cpu_instances; /* Halt first CPU only */ instance = list_get_next(&link); if (instance->cpu && instance->cpu->halt) instance->cpu->halt(instance, halt); }
ListNode* list_get_tail(List *l) { ListNode *node = list_get_head(l); if (!node) return NULL; while (node->next >= 0) node = list_get_next(l, node); ++l->total; return node; }
struct hub_user* uman_get_user_by_nick(struct hub_info* hub, const char* nick) { struct hub_user* user = (struct hub_user*) list_get_first(hub->users->list); /* iterate users - only on incoming INF msg */ while (user) { if (strcmp(user->id.nick, nick) == 0) return user; user = (struct hub_user*) list_get_next(hub->users->list); } return NULL; }
int route_to_all(struct hub_info* hub, struct adc_message* command) /* iterate users */ { struct hub_user* user = (struct hub_user*) list_get_first(hub->users->list); while (user) { route_to_user(hub, user, command); user = (struct hub_user*) list_get_next(hub->users->list); } return 0; }
void cpu_remove_all() { struct list_link *link = cpu_instances; struct cpu_instance *instance; while ((instance = list_get_next(&link))) if (instance->cpu->deinit) instance->cpu->deinit(instance); list_remove_all(&cpu_instances); }
struct bomb* search_bomb(struct map* map, int x, int y, int state) { struct list* bList = map_get_bombs(map); while(bList != NULL) { if(list_get_x(bList) == x && list_get_y(bList) == y) { struct bomb* bomb = list_get_data(bList); if(bomb->state == state) return list_get_data(bList); } bList = list_get_next(bList); } return NULL; }
void mamaStatsGenerator_generateStats (mamaStatsGenerator statsGenerator) { mamaStatsGeneratorImpl* impl = (mamaStatsGeneratorImpl*)statsGenerator; mamaStatsCollector* current; int wasLogged = 0; int logLast = 0; current = (mamaStatsCollector*)list_get_head (impl->mStatsCollectors); /* Stats are logged at WARN so that users don't have to enable NORMAL (or higher) logging, even though they aren't actually warnings...*/ if (impl->mLogStats) { mama_log (MAMA_LOG_LEVEL_WARN, LOG_SEPARATOR); mama_log (MAMA_LOG_LEVEL_WARN, LOG_HEADER); mama_log (MAMA_LOG_LEVEL_WARN, LOG_SEPARATOR); } while (current != NULL) { wasLogged = 0; mamaStatsCollector_populateMsg (*current, impl->mStatMsg, &wasLogged); if (impl->mStatsLogger && mamaStatsCollector_getPublish(*current)) { mamaStatsLogger_addStatMsg (impl->mStatsLogger, impl->mStatMsg); } if (wasLogged) { if (impl->mLogStats && mamaStatsCollector_getLog(*current)) { mama_log (MAMA_LOG_LEVEL_WARN, LOG_SEPARATOR); } } logLast = mamaStatsCollector_getLog(*current); current = (mamaStatsCollector*)list_get_next (impl->mStatsCollectors, current); } if (impl->mStatsLogger) { mamaStatsLogger_sendReport (impl->mStatsLogger); } /* If the last collector didn't give us any stats, still log a separator */ if (!wasLogged && impl->mLogStats && logLast) { mama_log (MAMA_LOG_LEVEL_WARN, LOG_SEPARATOR); } }
/*! * Wait for signal * \param set Signals thread is waiting for * \param info Where to save caught signal * \return signal number if signal is caught, * -1 otherwise and appropriate error number is set */ int sys__sigwaitinfo ( void *p ) { sigset_t *set; siginfo_t *info; kthread_t *kthread; ksignal_handling_t *sh; ksiginfo_t *ksig, *next; int retval; set = *( (sigset_t **) p ); p += sizeof (sigset_t *); info = *( (siginfo_t **) p ); ASSERT_ERRNO_AND_EXIT ( set, EINVAL ); set = U2K_GET_ADR ( set, kthread_get_process (NULL) ); ASSERT_ERRNO_AND_EXIT ( set, EINVAL ); if ( info ) info = U2K_GET_ADR ( info, kthread_get_process (NULL) ); kthread = kthread_get_active (); sh = kthread_get_sigparams ( kthread ); /* first, search for such signal in pending signals */ ksig = list_get ( &sh->pending_signals, FIRST ); while ( ksig ) { next = list_get_next ( &ksig->list ); if ( sigtestset ( set, ksig->siginfo.si_signo ) ) { retval = ksig->siginfo.si_signo; if ( info ) *info = ksig->siginfo; list_remove ( &sh->pending_signals, 0, &ksig->list ); kfree ( ksig ); EXIT2 ( EXIT_SUCCESS, retval ); } ksig = next; } /* * if no pending signal found that matches given mask * suspend thread until signal is received */ kthread_suspend ( kthread, ksignal_received_signal, NULL ); kthreads_schedule (); EXIT ( EINTR ); /* if other events wake thread */ }
void bomb_display(struct game* game, struct map* map) { assert(game); assert(map); struct list* bList = map_get_bombs(map); struct bomb* bomb = NULL; int x; int y; if(bList != NULL){ // if there is at least one bomb // Bomb Display And Event while(bList != NULL) { // For each bombs bomb = list_get_data(bList); if(!(bomb->state)){ // bomb who's waiting window_display_sprite( sprite_get_bombs(), sprite_get_rect_bomb_anim(7, ((bomb->anim)/4)%4), list_get_x(bList) * SIZE_BLOC, list_get_y(bList) * SIZE_BLOC); } else { // bomb who's exploding //printf("anim: %d, cal: %d\n", bomb->anim, bomb->anim/4); // Center window_display_sprite( sprite_get_bombs(), sprite_get_rect_bomb_anim(0, bomb->anim / 4), list_get_x(bList) * SIZE_BLOC, list_get_y(bList) * SIZE_BLOC); // Event bomb_event(game, map, bomb, list_get_x(bList), list_get_y(bList)); for(int d = 0; d < 4; d++){ // 0: SOUTH, 1: NORTH, 2: WEST, 3: EAST for(int r = 1; r <= bomb->range_dir[d]; r++){ /* d |dx |dy */ x = list_get_x(bList) + r * ((d / 2) * ((d * 2) - 5)); // + r * dx /* 0 | 0 | 1 */ y = list_get_y(bList) + r * ((d - 3) / 2 * ((d * 2) - 1)); // + r * dy /* 1 | 0 |-1 */ if(list_find(map_get_bombs(map), x, y) == NULL) { /* 2 |-1 | 0 */ if(r != bomb->range) { /* 3 | 1 | 0 */ window_display_sprite(sprite_get_bombs(), sprite_get_rect_bomb_anim(d/2 +1, bomb->anim/4), x * SIZE_BLOC, y * SIZE_BLOC); } else { window_display_sprite(sprite_get_bombs(), sprite_get_rect_bomb_anim(d+3, bomb->anim/4), x * SIZE_BLOC, y * SIZE_BLOC); } } // Event bomb_event(game, map, bomb, x, y); } // end for (range) } // end for (direction) } bList = list_get_next(bList); } } }
static void list_free(node_t **head) { node_t *node; if (!head || !*head) return; for (node = *head; node; node = *head) { *head = list_get_next(node); free(node); } }