void sys_free(struct sys *sys) { int i; for (i = 0; i < sys_get_frame_count(sys); i++) atoms_free(sys->frames[i].atoms); sel_free(sys->sel); sel_free(sys->visible); graph_free(sys->graph); free(sys->frames); free(sys); }
int status_client_ncurses(struct conf **confs) { int ret=-1; int csin=-1; int csout=-1; pid_t childpid=-1; struct async *as=NULL; const char *monitor_logfile=get_string(confs[OPT_MONITOR_LOGFILE]); struct asfd *so_asfd=NULL; struct sel *sel=NULL; if(!(sel=sel_alloc())) goto end; setup_signals(); // Fork a burp child process that will contact the server over SSL. // We will read and write from and to its stdout and stdin. if((childpid=fork_monitor(&csin, &csout, confs))<0) goto end; //printf("childpid: %d\n", childpid); if(!(as=async_alloc()) || as->init(as, 0) || !setup_asfd_linebuf_write(as, "monitor stdin", &csin) || !setup_asfd_linebuf_read(as, "monitor stdout", &csout)) goto end; //printf("ml: %s\n", monitor_logfile); #ifdef HAVE_NCURSES if(actg==ACTION_STATUS) { if(!setup_asfd_ncurses_stdin(as)) goto end; ncurses_init(); } #endif if(!(so_asfd=setup_asfd_stdout(as))) goto end; if(monitor_logfile && !(lfzp=fzp_open(monitor_logfile, "wb"))) goto end; log_fzp_set_direct(lfzp); ret=status_client_ncurses_main_loop(as, so_asfd, sel, get_string(confs[OPT_ORIG_CLIENT])); end: #ifdef HAVE_NCURSES if(actg==ACTION_STATUS) ncurses_free(); #endif if(ret) logp("%s exiting with error: %d\n", __func__, ret); fzp_close(&lfzp); async_asfd_free_all(&as); close_fd(&csin); close_fd(&csout); sel_free(&sel); return ret; }
static void do_snapshot_test( const char *orig_client, int expected_ret, void setup_callback( struct asfd *csin, struct asfd *csout, struct asfd *so_asfd ) ) { struct asfd *csin; struct asfd *csout; struct asfd *so_asfd; struct async *as; struct sel *sel; as=setup_async(); csin=asfd_mock_setup(&reads_csin, &writes_csin); csout=asfd_mock_setup(&reads_csout, &writes_csout); so_asfd=asfd_mock_setup(&reads_so, &writes_so); fail_unless((csin->desc=strdup_w("csin", __func__))!=NULL); fail_unless((csout->desc=strdup_w("csout", __func__))!=NULL); fail_unless((so_asfd->desc=strdup_w("so_asfd", __func__))!=NULL); as->asfd_add(as, csin); as->asfd_add(as, csout); as->asfd_add(as, so_asfd); as->read_write=async_rw_simple; as->write=async_write_simple; setup_callback(csin, csout, so_asfd); fail_unless((sel=sel_alloc())!=NULL); fail_unless(!status_client_ncurses_init(ACTION_STATUS_SNAPSHOT)); fail_unless(status_client_ncurses_main_loop( as, so_asfd, sel, orig_client )==expected_ret); sel_free(&sel); asfd_free(&csin); asfd_free(&csout); asfd_free(&so_asfd); asfd_mock_teardown(&reads_csin, &writes_csin); asfd_mock_teardown(&reads_csout, &writes_csout); asfd_mock_teardown(&reads_so, &writes_so); async_free(&as); alloc_check(); }
void sounddata_clear_selection (sw_sounddata * sounddata) { GList * gl; sw_sel * sel; for (gl = sounddata->sels; gl; gl = gl->next){ sel = (sw_sel*)gl->data; sel_free(sel); } g_list_free(sounddata->sels); sounddata->sels = NULL; };
void sel_end (void) { sel_free (selmobj) ; }
void sel_mark (void) { struct sel *sl ; struct node *n ; struct eq *eq ; struct vlan *vlantab ; struct network *net ; int i ; MOBJ *tmobj ; /* temporary mobj to reverse list */ /* * Create temporary list, ordered */ tmobj = mobj_init (sizeof (struct sel), MOBJ_MALLOC) ; for (sl = mobj_head (selmobj) ; sl != NULL ; sl = sl->next) { struct sel *tsl ; MOBJ_ALLOC_INSERT (tsl, tmobj) ; tsl->crittype = sl->crittype ; tsl->u = sl->u ; } /* * Initialize graph : everything must be clear */ vlantab = mobj_data (vlanmobj) ; for (n = mobj_head (nodemobj) ; n != NULL ; n = n->next) { n->mark = 0 ; vlan_zero (n->vlanset) ; } for (eq = mobj_head (eqmobj) ; eq != NULL ; eq = eq->next) eq->mark = 0 ; for (i = 0 ; i < MAXVLAN ; i++) vlantab [i].mark = 0 ; for (net = mobj_head (netmobj) ; net != NULL ; net = net->next) net->mark = 0 ; /* * Traverse the selection criteria mobj */ for (sl = mobj_head (tmobj) ; sl != NULL ; sl = sl->next) { switch (sl->crittype) { case CT_ALL : /* * Select all objects in the graph */ for (n = mobj_head (nodemobj) ; n != NULL ; n = n->next) n->mark = MK_SELECTED ; for (eq = mobj_head (eqmobj) ; eq != NULL ; eq = eq->next) eq->mark = MK_SELECTED ; for (i = 0 ; i < MAXVLAN ; i++) vlantab [i].mark = MK_SELECTED ; for (net = mobj_head (netmobj) ; net != NULL ; net = net->next) net->mark = MK_SELECTED ; break ; case CT_NET : /* * Select nodes based on network cidr * Select routed networks based on network cidr */ sel_mark_net (&sl->u.net.addr) ; break ; case CT_REX : /* * Select equipements based on regexp */ sel_mark_regexp (&sl->u.rex.rc, sl->u.rex.allow_deny) ; break ; case CT_VLAN : /* * Select nodes based on vlan id */ sel_mark_vlan (sl->u.vlan.id) ; break ; case CT_TERM : /* * Keep only terminal interfaces */ sel_unmark_nonterminal () ; break ; case CT_OWN : /* * Keep only "my" interfaces : those which transport * only "my" networks/Vlans */ sel_unmark_notmine () ; break ; default : break ; } } /* * Selects all equipements where at least one L1 interface is marked */ for (n = mobj_head (nodemobj) ; n != NULL ; n = n->next) if (n->nodetype == NT_L1 && MK_ISSELECTED (n)) MK_SELECT (n->eq) ; /* * Select Vlans where L2 node have been selected in the * L2 traversal. */ for (n = mobj_head (nodemobj) ; n != NULL ; n = n->next) if (n->nodetype == NT_L2 && MK_ISSET (n, MK_L2TRANSPORT)) MK_SELECT (&vlantab [n->u.l2.vlan]) ; /* * Close the temporary mobj */ sel_free (tmobj) ; }
END_TEST static void do_status_test( const char *orig_client, int expected_ret, void setup_callback( struct asfd *csin, struct asfd *csout, struct asfd *nin, struct asfd *so_asfd ), void check_sel_callback( struct sel *sel ) ) { struct asfd *csin; struct asfd *csout; struct asfd *nin; struct asfd *so_asfd; struct async *as; struct sel *sel; as=setup_async(); csin=asfd_mock_setup(&reads_csin, &writes_csin); csout=asfd_mock_setup(&reads_csout, &writes_csout); nin=asfd_mock_setup(&reads_nin, &writes_nin); so_asfd=asfd_mock_setup(&reads_so, &writes_so); fail_unless((csin->desc=strdup_w("csin", __func__))!=NULL); fail_unless((csout->desc=strdup_w("csout", __func__))!=NULL); fail_unless((nin->desc=strdup_w("nin", __func__))!=NULL); fail_unless((so_asfd->desc=strdup_w("so_asfd", __func__))!=NULL); nin->streamtype=ASFD_STREAM_NCURSES_STDIN; as->asfd_add(as, csin); as->asfd_add(as, csout); as->asfd_add(as, nin); as->asfd_add(as, so_asfd); as->read_write=async_rw_both; as->write=async_write_simple; setup_callback(csin, csout, nin, so_asfd); fail_unless((sel=sel_alloc())!=NULL); fail_unless(!status_client_ncurses_init(ACTION_STATUS)); fail_unless(status_client_ncurses_main_loop( as, so_asfd, sel, orig_client )==expected_ret); if(check_sel_callback) check_sel_callback(sel); sel_free(&sel); asfd_free(&csin); asfd_free(&csout); asfd_free(&nin); asfd_free(&so_asfd); asfd_mock_teardown(&reads_csin, &writes_csin); asfd_mock_teardown(&reads_csout, &writes_csout); asfd_mock_teardown(&reads_nin, &writes_nin); asfd_mock_teardown(&reads_so, &writes_so); async_free(&as); alloc_check(); }