/* * Assemble une transformation définie par l'utilisateur. * Calcule notamment le ret <x>, ou x est le nombre d'arguments. */ void asm_transformation(FILE* f,Transformation* t,linkedlist* lockeds) { int somme_probas=somme_proba_regles(&t->regles); fprintf(f,"; === Transformation %s\n",t->nom); fprintf(f,"; IN : "); cellule* a=ll_front(&t->arguments); while(a!=NULL) { char* arg=(char*)((Argument*)a->valeur)->nom; fprintf(f,"%s ",arg); a=ll_next(&t->arguments,a); } fprintf(f,"\nasm_%s: \n",t->nom); fprintf(f,"\tpush esi\n\tmov esi,esp\n"); cellule* cr=ll_front(&t->regles); int indice=0; while(cr!=NULL) { Regle* r=(Regle*)cr->valeur; asm_regle(f,t,r,indice,somme_probas,&t->arguments,lockeds); somme_probas-=r->proba; cr=ll_next(&t->regles,cr); if(!r->is_defaut) indice++; } fprintf(f,"%s_fin:\n",t->nom); fprintf(f,"\tpop esi\n"); fprintf(f,"\tret %d\n",ll_size(&t->arguments)*4); //fprintf(f,"asm_%s endp\n",t->nom); }
llist * ll_remove(llist * list){ llist * prev = NULL; llist * next = NULL; if (list == NULL) return NULL; prev = list->prev; next = list->next; if (prev){ prev->next = next; assert(ll_next(prev) == next); } if (next){ next->prev = prev; assert(ll_prev(next) == prev); } list->prev = NULL; list->next = NULL; assert(ll_prev(list) == NULL); assert(ll_next(list) == NULL); return prev ? prev : next; }
llist * ll_split(llist * list, ll_filter_f * f){ llist * iter = list; llist * aux = NULL; llist * newlist = NULL; llist * tail = NULL; assert(f != NULL); if (list == NULL || f == NULL) return NULL; while (iter){ if ((*f)(iter->val, iter->size)){ aux = iter; iter = ll_next(iter); list = ll_remove(aux); tail = tail != NULL? ll_appendl(tail, aux) : aux; } else { iter = ll_next(iter); } } newlist = ll_head(tail); return newlist; }
//----------------------------------------------------------------------------- // Look in the internal params list and return the value if the name exists. // If the name doesnt exist, then return NULL. const char * rq_http_param(rq_http_req_t *req, char *name) { param_t *param; char *value = NULL; assert(req); assert(name); if(req->param_list) { ll_start(req->param_list); param = ll_next(req->param_list); while (param) { assert(param->key); assert(param->value); if (strcmp(param->key, name) == 0) { value = param->value; param = NULL; } else { param = ll_next(req->param_list); } } ll_finish(req->param_list); } return(value); }
// This callback function is called when the CMD_EXECUTE command is received. // It should look at the data received so far, and figure out what operation // needs to be done on that data. static void cmdCheck(control_t *ptr) { entry_t *entry; int status = 0; assert(ptr); if (ptr->ip != 0) { assert(ptr->entries); assert(ptr->req); assert(ptr->reply); ll_start(ptr->entries); entry = ll_next(ptr->entries); while (entry) { assert(entry->start != 0 && entry->end != 0); assert(entry->end >= entry->start); // the entries are sorted, so if the entry is greater than what we are looking for, then it is not here. assert(status == 0); if (entry->start > ptr->ip) { entry = NULL; } else if (ptr->ip >= entry->start && ptr->ip <= entry->end) { status = 1; entry = NULL; } else { entry = ll_next(ptr->entries); } } ll_finish(ptr->entries); } assert(status == 0 || status == 1); assert(ptr->reply); assert(BUF_LENGTH(ptr->reply) == 0); if (status == 0) { // ip is not blocked. addCmd(ptr->reply, BL_CMD_CLEAR); addCmd(ptr->reply, BL_CMD_ACCEPT); } else { // ip is blocked. addCmd(ptr->reply, BL_CMD_CLEAR); addCmd(ptr->reply, BL_CMD_DENY); } }
int vlist_dereference(var_t *list, ...) { va_list ap; var_t *v; void **p; ll_t *ll; ll_entry_t *pos; va_start(ap, list); ll = list->v_data; pos = LL_START(ll); while ((v = ll_next(ll, &pos))) { p = va_arg(ap, void **); /* * Skip NULL Pointers. */ if (p == NULL) { continue; } *p = v->v_data; } va_end(ap); return 0; }
int preprocess(linkedlist* transformations) { lie_transfo_regle(transformations); cellule* ct=ll_front(transformations); while(ct!=NULL) { Transformation* t=(Transformation*)ct->valeur; cellule* cr=ll_front(&t->regles); while(cr!=NULL) { Regle* r=(Regle*)cr->valeur; r->minimum_taille=minimum_taille(&r->opcodes,ll_size(transformations),0); if(r->minimum_taille==NON_CALCULE) { snprintf(derniere_erreur,1024,"[ FATAL ] Recursion trop longue pour la transformation %s",t->nom); add_error(derniere_erreur); return 0; } r->nb_randint=0; r->nb_randmem=0; r->nb_randreg=0; r->nb_urandreg=0; r->nb_lab=0; r->nb_reg=0; r->nb_ureg=0; int i; for(i=0;i<10;i++) { r->randint_used[i]=0; r->randmem_used[i]=0; r->randreg_used[i]=0; r->urandreg_used[i]=0; r->reg_used[i]=0; r->ureg_used[i]=0; r->lab_used[i]=0; r->reg_locked[i]=0; r->randreg_locked[i]=0; r->randmem_locked[i]=0; } utilisation_rand_opcodes(&r->opcodes,r); cr=ll_next(&t->regles,cr); } ct=ll_next(transformations,ct); } return 1; }
void produit_lockeds_tasm(FILE* f,linkedlist* lockeds) { cellule* c=ll_front(lockeds); while(c!=NULL) { Locked* o=(Locked *)c->valeur; fprintf(f,"locked_%s dd 0 ;LOCKED\n",o->id); c=ll_next(lockeds,c); } }
void lie_transfo_regle(linkedlist* transformations) { cellule* ct=ll_front(transformations); while(ct!=NULL) { Transformation* t=(Transformation*)ct->valeur; cellule* cr=ll_front(&t->regles); while(cr!=NULL) { Regle* r=(Regle*)cr->valeur; if(r->is_defaut) { t->regledefaut=r; } lie_transfo_opcodes(&r->opcodes,transformations); cr=ll_next(&t->regles,cr); } ct=ll_next(transformations,ct); } }
var_t * vlist_record_from_table(var_t *scheme, var_t *table) { var_t *record = NULL, *vs, *vt; ll_t *ll; ll_entry_t *pos; void *data; var_type_t type; char *name; record = vlist_create(scheme->v_name, VF_KEEPNAME); if (record == NULL) { log_warning("vlist_record: vlist_create failed"); return NULL; } ll = scheme->v_data; pos = LL_START(ll); while ((vs = ll_next(ll, &pos))) { name = vs->v_name; vt = vtable_lookup(table, name); if (vt == NULL && vs->v_flags & VF_KEY) { log_error("vlist_record_from_table: \"%s\" is missing " "in vtable and declared as key", name); goto error; } data = vt == NULL ? NULL : vt->v_data; type = vt == NULL ? VT_NULL : vt->v_type; if (vlist_append_new(record, type, name, data, VF_COPY | vs->v_flags) == -1) { log_warning("vlist_record_from_table: vlist_append_new" " failed"); goto error; } } return record; error: if(record) { var_delete(record); } return NULL; }
/* * Permet juste le calcule de la somme des probabilités des regles * définie dans une transformation donnée. En effet, l'utilisateur * donne a la regle un numero d'importance, sa proba d'etre utilisée est donc * numero/somme_des_numéros */ int somme_proba_regles(linkedlist* l) { cellule* c=ll_front(l); int s=0; while(c!=NULL) { Regle* r=(Regle*)c->valeur; s+=r->proba; c=ll_next(l,c); } return s; }
void produit_table_opcodes_tasm(FILE* f,linkedlist* transfos) { fprintf(f,"jmp_table_opcodes:\n"); fprintf(f,"\tdd 0; OP_FIN_DECRYPTEUR\n"); cellule* c=ll_front(transfos); while(c!=NULL) { Transformation* t=(Transformation *)c->valeur; fprintf(f,"\tdd asm_%s; OP_%s\n",t->nom,t->nom); c=ll_next(transfos,c); } }
void sighup_handler(evutil_socket_t fd, short what, void *arg) { system_data_t *sysdata = (system_data_t *) arg; expbuf_t *buf; queue_t *q; assert(sysdata); assert(sysdata->bufpool); buf = expbuf_pool_new(sysdata->bufpool, 1024); expbuf_print(buf, "Complete data dump\n"); assert(sysdata->msg_list); expbuf_print(buf, "Messages:\n\tMax=%d\n\tActive=%d\n\n", sysdata->msg_max, sysdata->msg_used); assert(sysdata->in_buf); assert(sysdata->build_buf); expbuf_print(buf, "In Buffer size: %d\n", BUF_MAX(sysdata->in_buf)); expbuf_print(buf, "Build Buffer size: %d\n", BUF_MAX(sysdata->build_buf)); expbuf_print(buf, "\nEvents:\n"); expbuf_print(buf, "\tsigint: %s\n", sysdata->sigint_event ? "yes" : "no"); expbuf_print(buf, "\tsighup: %s\n", sysdata->sighup_event ? "yes" : "no"); expbuf_print(buf, "\tsigusr1: %s\n", sysdata->sigusr1_event ? "yes" : "no"); expbuf_print(buf, "\tsigusr2: %s\n", sysdata->sigusr2_event ? "yes" : "no"); // list_t *servers; // list_t *controllers; // list_t *nodelist; expbuf_print(buf, "\nQueues:\n"); assert(sysdata->queues); ll_start(sysdata->queues); while ((q = ll_next(sysdata->queues))) { queue_dump(q, buf); } ll_finish(sysdata->queues); assert(sysdata->logging); expbuf_print(buf, "\nLogging:\n"); expbuf_print(buf, "\tLog Level: %d\n", log_getlevel(sysdata->logging)); expbuf_print(buf, "\tDump string length: "); expbuf_print(buf, "%d\n", BUF_LENGTH(buf)); logger(sysdata->logging, 1, "%s", expbuf_string(buf)); expbuf_clear(buf); // return the buffer to the pool. expbuf_pool_return(sysdata->bufpool, buf); }
/* Free the memory allocated for the sk_list */ int sk_free() { SK_P FAR *sk_ptr; ll_access(&sk_list); while ((sk_ptr = (SK_P FAR *)ll_next(&sk_list)) != NULL) { MEM_UNLOCK(&sk_ptr->ptr->sk_val); FREE(&sk_ptr->ptr->sk_val); } ll_deaccess(&sk_list); ll_free(&sk_list); return( db_status ); }
int ll_each(llist * list, ll_eachf f, void * d){ int i = 0; int n = 0; if (list == NULL || f == NULL) return 0; for (i = 0; list != NULL; i++, list = ll_next(list)){ n += f(list->size, i, list->val, d); } return n; }
void produit_opcodes_tasm(FILE* f,linkedlist* transfos) { int op_cur=1; fprintf(f,"OP_FIN_DECRYPTEUR EQU 0\n\n");; cellule* c=ll_front(transfos); while(c!=NULL) { Transformation* t=(Transformation *)c->valeur; fprintf(f,"OP_%s EQU %d\n",t->nom,op_cur++); fprintf(f,"OP_%s_NB_ARGS EQU %d\n\n",t->nom,ll_size(&(t->arguments))); c=ll_next(transfos,c); } }
/* vpf relate structures. */ static int table_in_list( char *tablename, linked_list_type rlist ) { position_type p; vpf_relate_struct rcell; p = ll_first(rlist); while (!ll_end(p)) { ll_element(p,&rcell); if (strcmp(rcell.table1,tablename)==0) return 1; p = ll_next(p); } return 0; }
void produit_macros_tasm(FILE* f,linkedlist* transfos) { fprintf(f,"FIN_DECRYPTEUR macro \n"); fprintf(f,"\t db OP_FIN_DECRYPTEUR\n"); fprintf(f,"endm\n\n"); cellule* c=ll_front(transfos); while(c!=NULL) { Transformation* t=(Transformation *)c->valeur; fprintf(f,"%s macro ",t->nom); cellule* a=ll_front(&t->arguments); while(a!=NULL) { Argument* arg=(Argument*)a->valeur; fprintf(f,"%s",arg->nom); a=ll_next(&t->arguments,a); if(a!=NULL) fprintf(f,","); } fprintf(f,"\n\n"); fprintf(f,"\tdb OP_%s\n",t->nom); fprintf(f,"\tdb OP_%s_NB_ARGS\n",t->nom); a=ll_front(&t->arguments); int i=1; while(a!=NULL) { Argument* arg=(Argument*)a->valeur; fprintf(f,"\tdb %s\n",asm_types[arg->type]); fprintf(f,"\tdd %s\n",arg->nom); a=ll_next(&t->arguments,a); i++; } fprintf(f,"endm\n\n"); c=ll_next(transfos,c); } }
int minimum_taille(linkedlist* opcodes,int recursivite_max,int recursivite) { if(recursivite>recursivite_max) return NON_CALCULE; cellule* co=ll_front(opcodes); int taille=0; while(co!=NULL) { Opcode* o=(Opcode*)co->valeur; if(o->letype==ASMOPCODE) { taille+=o->operandes.opasm.taille; } else if(o->letype==CALLOPCODE) { if(o->operandes.opcall.transfo->regledefaut->minimum_taille!=NON_CALCULE) { taille+=o->operandes.opcall.transfo->regledefaut->minimum_taille; } else { int m=minimum_taille(&(o->operandes.opcall.transfo->regledefaut->opcodes),recursivite_max,recursivite+1); if(m==NON_CALCULE) return NON_CALCULE; taille+=m; } } else if(o->letype==WRITE) { taille+=o->operandes.opwrite.nboctets; } else if(o->letype==CONDITIONIF) { int m=minimum_taille(&o->operandes.opif.codeif,recursivite_max,recursivite); if(m==NON_CALCULE) return NON_CALCULE; taille+=m; } else if(o->letype==CONDITIONIFELSE) { int m1=minimum_taille(&o->operandes.opif.codeif,recursivite_max,recursivite); int m2=minimum_taille(&o->operandes.opif.codeelse,recursivite_max,recursivite); if(m1==NON_CALCULE || m2==NON_CALCULE) return NON_CALCULE; taille+=m1>m2?m1:m2; } co=ll_next(opcodes,co); } return taille; }
int cf_load_list(ll_t *list, char *key, var_type_t type) { var_t *v, *item; ll_entry_t *pos; v = vtable_lookup(cf_config, key); if (v == NULL) { log_error("cf_load_list: %s not found", key); return -1; } // Scalar if (v->v_type == type) { if (LL_INSERT(list, v->v_data) == -1) { log_error("cf_load_list: LL_INSERT failed"); return -1; } return 0; } // Unexpected type if (v->v_type != VT_LIST) { log_error("config error: unexpected value for %s", key); return -1; } pos = LL_START((ll_t *) v->v_data); while ((item = ll_next(v->v_data, &pos))) { if (item->v_type != type) { log_error("config error: unexpected value in %s", key); return -1; } if (LL_INSERT(list, item->v_data) == -1) { log_error("cf_load_list: LL_INSERT failed"); return -1; } } return 0; }
unsigned int ll_size(t_llist *l) { t_llist_node* next; t_llist_node* sentinel; int size=0; sentinel=ll_sentinel(l); next=ll_first(l); while(next!=sentinel) { next=ll_next(next); size++; } return size; }
llist * ll_filter(llist * list, ll_filter_f * f){ llist * iter = NULL; llist * result = NULL; assert(f != NULL); if (list == NULL || f == NULL) return NULL; for (iter = list; iter != NULL; iter = ll_next(iter)) if ((*f)(iter->val, iter->size)) result = result ? result : ll_insert(result, iter->val, iter->size); return result; }
var_t * vlist_record(var_t *scheme, ...) { va_list ap; var_t *record = NULL, *v; int flags; void *data; ll_t *ll; ll_entry_t *pos; va_start(ap, scheme); record = vlist_create(scheme->v_name, VF_KEEPNAME); if (record == NULL) { log_warning("vlist_record: vlist_create failed"); return NULL; } ll = scheme->v_data; pos = LL_START(ll); while ((v = ll_next(ll, &pos))) { flags = v->v_flags; flags |= VF_KEEPDATA | VF_KEEPNAME; flags &= ~(VF_COPYNAME | VF_COPYDATA); data = va_arg(ap, void *); if (vlist_append_new(record, v->v_type, v->v_name, data, flags) == -1) { log_warning("vlist_record: vlist_append_new failed"); var_delete(record); return NULL; } } va_end(ap); return record; }
var_t * exp_eval_in(var_t *needle, var_t *haystack) { var_t *v; ll_t *list; ll_entry_t *pos; int cmp; if (needle == NULL || haystack == NULL) { return EXP_EMPTY; } if (needle->v_data == NULL || haystack->v_data == NULL) { log_debug("exp_eval_in: empty value"); return EXP_EMPTY; } if (haystack->v_type != VT_LIST) { log_error("exp_eval_in: in operator only works on lists"); return NULL; } list = haystack->v_data; pos = LL_START(list); while ((v = ll_next(list, &pos))) { if (var_compare(&cmp, needle, v)) { log_error("exp_eval_in: var_compare failed"); } if (cmp == 0) { return EXP_TRUE; } } return EXP_FALSE; }
static void destroy (struct statistic *s) { struct box_whisker *bw = UP_CAST (s, struct box_whisker, parent.parent); struct order_stats *os = &bw->parent; struct ll *ll; for (ll = ll_head (&bw->outliers); ll != ll_null (&bw->outliers); ) { struct outlier *e = ll_data (ll, struct outlier, ll); ll = ll_next (ll); ds_destroy (&e->label); free (e); } free (os->k); free (s); };
smcp_node_t smcp_node_find( smcp_node_t node, const char* name, // Unescaped. int name_len ) { #if SMCP_NODE_ROUTER_USE_BTREE return (smcp_node_t)bt_find( (void*)&((smcp_node_t)node)->children, name, (bt_compare_func_t)&smcp_node_ncompare_cstr, (void*)(intptr_t)name_len ); #else // Ouch. Linear search. smcp_node_t ret = node->children; while(ret && smcp_node_ncompare_cstr(ret,name,name_len) != 0) ret = ll_next((void*)ret); return ret; #endif }
var_t * vlist_record_lookup(var_t *record, char *key) { ll_t *list = record->v_data; ll_entry_t *pos; var_t *item; /* * Bad search: but records usually only have less than 10 values. */ pos = LL_START(list); while ((item = ll_next(list, &pos))) { if (strcmp(item->v_name, key) == 0) { return item; } } return NULL; }
/* * Gere la génération du .asm. Celui-ci contiendra le moteur: la fonction * asm_opcode(edx=taille_max_code,edi->où assembler,esi->pseudo_opcode). * Il contient également le code assembleur des routines d'assemblage, * les transformations définies par l'utilisateur. * Enfin, il contient également quelques routines utiles, comme l'allocation * de registre, de mémoire, un gnpa, etc. */ void produit_asm(FILE* f,linkedlist* transfos,linkedlist* lockeds) { cellule* ct=ll_front(transfos); fprintf(f,"%s\n",poly_fonctions); fprintf(f,";========================== VARIABLES LOCKEDS ====================================\n"); produit_lockeds_tasm(f,lockeds); fprintf(f,";========================== TABLE DE SAUTS UTILISEE EN INTERNE ===================\n"); produit_table_opcodes_tasm(f,transfos); fprintf(f,"\n\n\n"); fprintf(f,";=========================== TRANSFORMATIONS UTILISATEUR =========================\n"); fprintf(f,"; Ceci est le code assembleur des transformations que vous avez définies.\n"); fprintf(f,";=================================================================================\n"); while(ct!=NULL) { Transformation* t=(Transformation*)ct->valeur; asm_transformation(f,t,lockeds); fprintf(f,"\n\n"); ct=ll_next(transfos,ct); } fprintf(f,"\n\n\n"); }
static var_t * exp_eval_list(exp_t *exp, var_t *mailspec) { ll_t *exp_list = exp->ex_data; ll_entry_t *pos; exp_t *exp_item; var_t *var_item, *var_list = NULL; var_list = vlist_create(NULL, VF_EXP_FREE); if (var_list == NULL) { log_sys_error("exp_eval_list: malloc"); goto error; } pos = LL_START(exp_list); while ((exp_item = ll_next(exp_list, &pos))) { var_item = exp_eval(exp_item, mailspec); if (vlist_append(var_list, var_item)) { log_sys_error("exp_eval_list: malloc"); goto error; } } return var_list; error: if (var_list) { var_delete(var_list); } return NULL; }
int nb_calls_restants(Regle* r,Opcode* lo) { cellule* co=ll_front(&r->opcodes); int s=0; int passe=0; while(co!=NULL) { Opcode* o=(Opcode*)co->valeur; if(o!=NULL) { if(o->letype==CALLOPCODE) { if(passe) s++; else passe=(lo==o); } co=ll_next(&r->opcodes,co); } } return s; }