int acl_init(char *x509, char *addr, uint16_t port) { journal_ftrace(__func__); acl_x509 = strdup(x509); acl_addr = strdup(addr); acl_port = port; event_register(EVENT_EXIT, "acl_fini", acl_fini, PRIO_AGNOSTIC); return 0; }
static void ready(struct connection *self, struct event_loop *loop, uint32_t mask) { char ip[16]; int port; if (mask & E_READABLE) { int fd = socket_accept(self->fd, ip, sizeof(ip), &port); logger(DEBUG, "accepted %s:%d", ip, port); struct connection *client = client_create(self->ctx, fd); event_register(loop, client); } }
void debugger_init( void ) { debugger_breakpoints = NULL; debugger_output_base = 16; debugger_memory_pool = mempool_register_pool(); debugger_breakpoint_event = event_register( debugger_breakpoint_time_fn, "Breakpoint" ); debugger_event_init(); debugger_variable_init(); debugger_reset(); }
static void servo_event(void *servo_) { struct servo *servo = servo_; static uint8_t phase = 0; phase = !phase; digitalWrite(SERVO, phase); // For our ESC 750ms is OK for arming, result in no rotation whatsoever. # define PULSE_MIN US_TO_TIMER1_TICKS(750U) # define PULSE_MAX US_TO_TIMER1_TICKS(2400U) # define PULSE_PERIOD US_TO_TIMER1_TICKS(20000U) uint16_t const pulse_len = PULSE_MIN + (((PULSE_MAX-PULSE_MIN)*speed)>>8U); event_register(phase ? pulse_len : PULSE_PERIOD - pulse_len, servo_slow); }
static int debugger_init( void *context ) { debugger_breakpoints = NULL; debugger_output_base = 16; debugger_memory_pool = mempool_register_pool(); debugger_breakpoint_event = event_register( debugger_breakpoint_time_fn, "Breakpoint" ); debugger_event_init(); debugger_system_variable_init(); debugger_variable_init(); debugger_reset(); return 0; }
int bridge_init(char *x509, char *addr, uint16_t port) { journal_ftrace(__func__); bridge_x509 = strdup(x509); bridge_addr = strdup(addr); bridge_port = port; if (set_context(bridge_x509)) { journal_notice("bridge]> set_context failed :: %s:%i\n", __FILE__, __LINE__); return -1; } event_register(EVENT_EXIT, "bridge_fini", bridge_fini, PRIO_AGNOSTIC); return 0; }
/* * Submit a request to read some data. Calls back with the given function * and arg when completed. */ static void bsd_stream_read( void * s, void (*fn)(void *, void *, ssize_t), void * arg) { struct sec_stream *bs = s; /* * Only one read request can be active per stream. */ if (bs->ev_read != NULL) event_release(bs->ev_read); bs->ev_read = event_register((event_id_t)bs->fd, EV_READFD, stream_read_callback, bs); bs->fn = fn; bs->arg = arg; }
static int analyzer_tftp_init(struct analyzer *analyzer) { struct analyzer_tftp_priv *priv = malloc(sizeof(struct analyzer_tftp_priv)); if (!priv) { pom_oom(sizeof(struct analyzer_tftp_priv)); return POM_ERR; } memset(priv, 0, sizeof(struct analyzer_tftp_priv)); analyzer->priv = priv; static struct data_item_reg evt_file_data_items[ANALYZER_TFTP_EVT_FILE_DATA_COUNT] = { { 0 } }; evt_file_data_items[analyzer_tftp_file_filename].name = "filename"; evt_file_data_items[analyzer_tftp_file_filename].value_type = ptype_get_type("string"); evt_file_data_items[analyzer_tftp_file_mode].name = "mode"; evt_file_data_items[analyzer_tftp_file_mode].value_type = ptype_get_type("string"); evt_file_data_items[analyzer_tftp_file_write].name = "write"; evt_file_data_items[analyzer_tftp_file_write].value_type = ptype_get_type("bool"); evt_file_data_items[analyzer_tftp_file_size].name = "size"; evt_file_data_items[analyzer_tftp_file_size].value_type = ptype_get_type("uint32"); static struct data_reg evt_file_data = { .items = evt_file_data_items, .data_count = ANALYZER_TFTP_EVT_FILE_DATA_COUNT }; static struct event_reg_info analyzer_tftp_evt_file = { 0 }; analyzer_tftp_evt_file.source_name = "analyzer_tftp"; analyzer_tftp_evt_file.source_obj = priv; analyzer_tftp_evt_file.name = "tftp_file"; analyzer_tftp_evt_file.description = "TFTP file"; analyzer_tftp_evt_file.flags = EVENT_REG_FLAG_PAYLOAD; analyzer_tftp_evt_file.data_reg = &evt_file_data; analyzer_tftp_evt_file.listeners_notify = analyzer_tftp_event_listeners_notify; priv->evt_file = event_register(&analyzer_tftp_evt_file); if (!priv->evt_file) { free(priv); return POM_ERR; } return POM_OK; }
int acl_init() { journal_ftrace(__func__); mem_fun.hook = hooklet_inherit(HOOKLET_ACL); if (mem_fun.hook == NULL) { journal_notice("%s :: %s:%i\n", "No hooklet available to inherit " "the ACL subsystem", __FILE__, __LINE__); return -1; } if (hooklet_map_cb(mem_fun.hook, acl_cb)) return -1; mem_fun.set_init(); muxia_register(&acl_demux, XIAMSG_ACL); event_register(EVENT_EXIT, "acl:acl_fini()", acl_fini, PRIO_AGNOSTIC); return 0; }
/** * Initialize the application: * - Initialize the debug console * - Initialize the Aion subsystem * - Initialize the chatlog engine * - Register events * * @param[in] argc Argument number (passed from main) -- not used * @param[in] argv Argument array (passed from main) -- not used * * @retval true On success * @retval false If it fails to initialize the aion sub-system * @retval false If it fails to initialize the chatlog engine */ bool apme_init(int argc, char* argv[]) { (void)argc; (void)argv; /* First initialize the debug console */ con_init(); /* Initialize events early, elevation is requested with events! */ event_register(apme_event_handler); /* Do the chatlog enable/disable stuff, warn user... */ apme_chatlog_check(); if (!aion_init()) { con_printf("Unable to initialize the Aion subsystem.\n"); return false; } if (!chatlog_init()) { con_printf("Error initializing the Chatlog parser.\n"); return false; } /* Initialize the configuration file */ if (!cfg_init()) { con_printf("Error initializing the config subsystem.\n"); /* Non-fatal for now -- we'll revert to defaults */ } else { /* Apply the loaded configuration */ apme_cfg_apply(); } return true; }
/* * Read a chunk of data to a stream. Blocks until completion. */ static ssize_t bsd_stream_read_sync( void * s, void ** buf) { struct sec_stream *bs = s; assert(bs != NULL); /* * Only one read request can be active per stream. */ if(bs->ev_read != NULL) { return -1; } sync_pktlen = 0; sync_pkt = NULL; bs->ev_read = event_register((event_id_t)bs->fd, EV_READFD, stream_read_sync_callback, bs); event_wait(bs->ev_read); *buf = sync_pkt; return (sync_pktlen); }
int main( int argc, char **argv ) { #ifdef __PSP__ callbacks_setup(); #endif // **************************************************************** printf ("\n----------- Extreme Tux Racer " VERSION " ----------------"); printf ("\n----------- (C) 2010 Extreme Tuxracer Team --------\n\n "); srand (time (NULL)); InitConfig (argv[0]); InitGame (argc, argv); Winsys.Init (); InitOpenglExtensions (); // for checking the joystick and the OpgenGL version (the info is // written on the console): // Winsys.PrintJoystickInfo (); // PrintGLInfo (); // register loop functions splash_screen_register(); regist_register (); intro_register(); racing_register(); game_over_register(); paused_register(); reset_register(); game_type_select_register(); RegisterGameConfig (); event_select_register(); event_register (); RaceSelectRegister(); credits_register(); loading_register(); RegisterKeyInfo (); RegisterToolFuncs (); NewPlayerRegister (); RegisterScoreFunctions (); RegisterTestFuncs (); // theses resources must or should be loaded before splashscreen starts Course.MakeStandardPolyhedrons (); Tex.LoadTextureList (); FT.LoadFontlist (); Winsys.SetFonttype (); Audio.Open (); Sound.LoadSoundList (); Music.LoadMusicList (); Music.SetVolume (param.music_volume); g_game.mode = NO_MODE; switch (g_game.argument) { case 0: Winsys.SetMode (SPLASH); break; case 4: g_game.toolmode = TUXSHAPE; Winsys.SetMode (TOOLS); break; case 9: Winsys.SetMode (OGLTEST); break; } Winsys.EventLoop (); return 0; }
static int analyzer_arp_init(struct analyzer *analyzer) { struct analyzer_arp_priv *priv = malloc(sizeof(struct analyzer_arp_priv)); if (!priv) { pom_oom(sizeof(struct analyzer_arp_priv)); return POM_ERR; } memset(priv, 0, sizeof(struct analyzer_arp_priv)); analyzer->priv = priv; if (pthread_mutex_init(&priv->lock, NULL)) { pomlog(POMLOG_ERR "Error while initializing table lock : %s", pom_strerror(errno)); free(priv); return POM_ERR; } priv->proto_vlan = proto_get("vlan"); if (!priv->proto_vlan) goto err; static struct data_item_reg evt_new_sta_data_items[ANALYZER_ARP_EVT_NEW_STA_DATA_COUNT] = { { 0 } }; evt_new_sta_data_items[analyzer_arp_new_sta_mac_addr].name = "mac_addr"; evt_new_sta_data_items[analyzer_arp_new_sta_mac_addr].value_type = ptype_get_type("mac"); evt_new_sta_data_items[analyzer_arp_new_sta_ip_addr].name = "ip_addr"; evt_new_sta_data_items[analyzer_arp_new_sta_ip_addr].value_type = ptype_get_type("ipv4"); evt_new_sta_data_items[analyzer_arp_new_sta_vlan].name = "vlan"; evt_new_sta_data_items[analyzer_arp_new_sta_vlan].value_type = ptype_get_type("uint16"); evt_new_sta_data_items[analyzer_arp_new_sta_input].name = "input"; evt_new_sta_data_items[analyzer_arp_new_sta_input].value_type = ptype_get_type("string"); static struct data_reg evt_new_sta_data = { .items = evt_new_sta_data_items, .data_count = ANALYZER_ARP_EVT_NEW_STA_DATA_COUNT }; static struct event_reg_info analyzer_arp_evt_new_sta = { 0 }; analyzer_arp_evt_new_sta.source_name = "analyzer_arp"; analyzer_arp_evt_new_sta.source_obj = analyzer; analyzer_arp_evt_new_sta.name = "arp_new_sta"; analyzer_arp_evt_new_sta.description = "New station found"; analyzer_arp_evt_new_sta.data_reg = &evt_new_sta_data; analyzer_arp_evt_new_sta.listeners_notify = analyzer_arp_event_listeners_notify; priv->evt_new_sta = event_register(&analyzer_arp_evt_new_sta); if (!priv->evt_new_sta) goto err; static struct data_item_reg evt_sta_changed_data_items[ANALYZER_ARP_EVT_STA_CHANGED_DATA_COUNT] = { { 0 } }; evt_sta_changed_data_items[analyzer_arp_sta_changed_old_mac_addr].name = "old_mac_addr"; evt_sta_changed_data_items[analyzer_arp_sta_changed_old_mac_addr].value_type = ptype_get_type("mac"); evt_sta_changed_data_items[analyzer_arp_sta_changed_new_mac_addr].name = "new_mac_addr"; evt_sta_changed_data_items[analyzer_arp_sta_changed_new_mac_addr].value_type = ptype_get_type("mac"); evt_sta_changed_data_items[analyzer_arp_sta_changed_ip_addr].name = "ip_addr"; evt_sta_changed_data_items[analyzer_arp_sta_changed_ip_addr].value_type = ptype_get_type("ipv4"); evt_sta_changed_data_items[analyzer_arp_sta_changed_vlan].name = "vlan"; evt_sta_changed_data_items[analyzer_arp_sta_changed_vlan].value_type = ptype_get_type("uint16"); evt_sta_changed_data_items[analyzer_arp_sta_changed_input].name = "input"; evt_sta_changed_data_items[analyzer_arp_sta_changed_input].value_type = ptype_get_type("string"); static struct data_reg evt_sta_changed_data = { .items = evt_sta_changed_data_items, .data_count = ANALYZER_ARP_EVT_STA_CHANGED_DATA_COUNT }; static struct event_reg_info analyzer_arp_evt_sta_changed = { 0 }; analyzer_arp_evt_sta_changed.source_name = "analyzer_arp"; analyzer_arp_evt_sta_changed.source_obj = analyzer; analyzer_arp_evt_sta_changed.name = "arp_sta_changed"; analyzer_arp_evt_sta_changed.description = "Station MAC address changed"; analyzer_arp_evt_sta_changed.data_reg = &evt_sta_changed_data; analyzer_arp_evt_sta_changed.listeners_notify = analyzer_arp_event_listeners_notify; priv->evt_sta_changed = event_register(&analyzer_arp_evt_sta_changed); if (!priv->evt_sta_changed) goto err; return POM_OK; err: analyzer_arp_cleanup(analyzer); return POM_ERR; }
/* * ssh version of a security handle allocator. Logically sets * up a network "connection". */ static void ssh_connect( const char * hostname, char * (*conf_fn)(char *, void *), void (*fn)(void *, security_handle_t *, security_status_t), void * arg, void * datap) { struct sec_handle *rh; char *amandad_path=NULL, *client_username=NULL, *ssh_keys=NULL; char *client_port = NULL; assert(fn != NULL); assert(hostname != NULL); auth_debug(1, "ssh_connect: %s\n", hostname); rh = g_new0(struct sec_handle, 1); security_handleinit(&rh->sech, &ssh_security_driver); rh->dle_hostname = g_strdup(hostname); rh->hostname = NULL; rh->rs = NULL; rh->ev_timeout = NULL; rh->rc = NULL; rh->hostname = g_strdup(hostname); rh->rs = tcpma_stream_client(rh, newhandle++); if (rh->rc == NULL) goto error; rh->rc->conf_fn = conf_fn; rh->rc->datap = datap; if (rh->rs == NULL) goto error; amfree(rh->hostname); rh->hostname = g_strdup(rh->rs->rc->hostname); /* * We need to open a new connection. * * XXX need to eventually limit number of outgoing connections here. */ if(conf_fn) { char *port_str; amandad_path = conf_fn("amandad_path", datap); client_username = conf_fn("client_username", datap); ssh_keys = conf_fn("ssh_keys", datap); port_str = conf_fn("client_port", datap); if (port_str && strlen(port_str) >= 1) { client_port = port_str; } } if(rh->rc->read == -1) { if (runssh(rh->rs->rc, amandad_path, client_username, ssh_keys, client_port) < 0) { security_seterror(&rh->sech, _("can't connect to %s: %s"), hostname, rh->rs->rc->errmsg); goto error; } rh->rc->refcnt++; } /* * The socket will be opened async so hosts that are down won't * block everything. We need to register a write event * so we will know when the socket comes alive. * * Overload rh->rs->ev_read to provide a write event handle. * We also register a timeout. */ rh->fn.connect = fn; rh->arg = arg; rh->rs->rc->ev_write = event_register((event_id_t)rh->rs->rc->write, EV_WRITEFD, sec_connect_callback, rh); rh->ev_timeout = event_register((event_id_t)CONNECT_TIMEOUT, EV_TIME, sec_connect_timeout, rh); return; error: (*fn)(arg, &rh->sech, S_ERROR); }
void buttons_init(void) { event_register(EV_PINCHANGE, pinChanged, pinChangedFilter, 0); buttonTimer = timer_create(buttonTimeout, 0); }
static int analyzer_smtp_init(struct analyzer *analyzer) { struct analyzer_smtp_priv *priv = malloc(sizeof(struct analyzer_smtp_priv)); if (!priv) { pom_oom(sizeof(struct analyzer_smtp_priv)); return POM_ERR; } memset(priv, 0, sizeof(struct analyzer_smtp_priv)); analyzer->priv = priv; priv->evt_cmd = event_find("smtp_cmd"); priv->evt_reply = event_find("smtp_reply"); if (!priv->evt_cmd || !priv->evt_reply) goto err; static struct data_item_reg evt_msg_data_items[ANALYZER_SMTP_EVT_MSG_DATA_COUNT] = { { 0 } }; evt_msg_data_items[analyzer_smtp_common_client_addr].name = "client_addr"; evt_msg_data_items[analyzer_smtp_common_client_addr].flags = DATA_REG_FLAG_NO_ALLOC; evt_msg_data_items[analyzer_smtp_common_server_addr].name = "server_addr"; evt_msg_data_items[analyzer_smtp_common_server_addr].flags = DATA_REG_FLAG_NO_ALLOC; evt_msg_data_items[analyzer_smtp_common_server_port].name = "server_port"; evt_msg_data_items[analyzer_smtp_common_server_port].value_type = ptype_get_type("uint16"); evt_msg_data_items[analyzer_smtp_common_server_host].name = "server_host"; evt_msg_data_items[analyzer_smtp_common_server_host].value_type = ptype_get_type("string"); evt_msg_data_items[analyzer_smtp_common_server_hello].name = "server_hello"; evt_msg_data_items[analyzer_smtp_common_server_hello].value_type = ptype_get_type("string"); evt_msg_data_items[analyzer_smtp_common_client_hello].name = "client_hello"; evt_msg_data_items[analyzer_smtp_common_client_hello].value_type = ptype_get_type("string"); evt_msg_data_items[analyzer_smtp_msg_from].name = "from"; evt_msg_data_items[analyzer_smtp_msg_from].value_type = ptype_get_type("string"); evt_msg_data_items[analyzer_smtp_msg_to].name = "to"; evt_msg_data_items[analyzer_smtp_msg_to].flags = DATA_REG_FLAG_LIST; evt_msg_data_items[analyzer_smtp_msg_result].name = "result"; evt_msg_data_items[analyzer_smtp_msg_result].value_type = ptype_get_type("uint16"); static struct data_reg evt_msg_data = { .items = evt_msg_data_items, .data_count = ANALYZER_SMTP_EVT_MSG_DATA_COUNT }; static struct event_reg_info analyzer_smtp_evt_msg = { 0 }; analyzer_smtp_evt_msg.source_name = "analyzer_smtp"; analyzer_smtp_evt_msg.source_obj = analyzer; analyzer_smtp_evt_msg.name = "smtp_msg"; analyzer_smtp_evt_msg.description = "message received over smtp"; analyzer_smtp_evt_msg.data_reg = &evt_msg_data; analyzer_smtp_evt_msg.listeners_notify = analyzer_smtp_event_listeners_notify; analyzer_smtp_evt_msg.cleanup = analyzer_smtp_evt_msg_cleanup; analyzer_smtp_evt_msg.flags = EVENT_REG_FLAG_PAYLOAD; priv->evt_msg = event_register(&analyzer_smtp_evt_msg); if (!priv->evt_msg) goto err; static struct data_item_reg evt_auth_data_items[ANALYZER_SMTP_EVT_AUTH_DATA_COUNT] = { { 0 } }; evt_auth_data_items[analyzer_smtp_common_client_addr].name = "client_addr"; evt_auth_data_items[analyzer_smtp_common_client_addr].flags = DATA_REG_FLAG_NO_ALLOC; evt_auth_data_items[analyzer_smtp_common_server_addr].name = "server_addr"; evt_auth_data_items[analyzer_smtp_common_server_addr].flags = DATA_REG_FLAG_NO_ALLOC; evt_auth_data_items[analyzer_smtp_common_server_port].name = "server_port"; evt_auth_data_items[analyzer_smtp_common_server_port].value_type = ptype_get_type("uint16"); evt_auth_data_items[analyzer_smtp_common_server_host].name = "server_host"; evt_auth_data_items[analyzer_smtp_common_server_host].value_type = ptype_get_type("string"); evt_auth_data_items[analyzer_smtp_common_server_hello].name = "server_hello"; evt_auth_data_items[analyzer_smtp_common_server_hello].value_type = ptype_get_type("string"); evt_auth_data_items[analyzer_smtp_common_client_hello].name = "client_hello"; evt_auth_data_items[analyzer_smtp_common_client_hello].value_type = ptype_get_type("string"); evt_auth_data_items[analyzer_smtp_auth_type].name = "type"; evt_auth_data_items[analyzer_smtp_auth_type].value_type = ptype_get_type("string"); evt_auth_data_items[analyzer_smtp_auth_params].name = "params"; evt_auth_data_items[analyzer_smtp_auth_params].flags = DATA_REG_FLAG_LIST; evt_auth_data_items[analyzer_smtp_auth_success].name = "success"; evt_auth_data_items[analyzer_smtp_auth_success].value_type = ptype_get_type("bool"); static struct data_reg evt_auth_data = { .items = evt_auth_data_items, .data_count = ANALYZER_SMTP_EVT_AUTH_DATA_COUNT }; static struct event_reg_info analyzer_smtp_evt_auth = { 0 }; analyzer_smtp_evt_auth.source_name = "analyzer_smtp"; analyzer_smtp_evt_auth.source_obj = analyzer; analyzer_smtp_evt_auth.name = "smtp_auth"; analyzer_smtp_evt_auth.description = "SMTP authentication attempts"; analyzer_smtp_evt_auth.data_reg = &evt_auth_data; analyzer_smtp_evt_auth.listeners_notify = analyzer_smtp_event_listeners_notify; priv->evt_auth = event_register(&analyzer_smtp_evt_auth); if (!priv->evt_auth) goto err; return POM_OK; err: analyzer_smtp_cleanup(analyzer); return POM_ERR; }
int analyzer_ppp_pap_init(struct analyzer *analyzer) { struct analyzer_ppp_pap_priv *priv = malloc(sizeof(struct analyzer_ppp_pap_priv)); if (!priv) { pom_oom(sizeof(struct analyzer_ppp_pap_priv)); return POM_ERR; } memset(priv, 0, sizeof(struct analyzer_ppp_pap_priv)); analyzer->priv = priv; priv->evt_request = event_find("ppp_pap_request"); priv->evt_ack_nack = event_find("ppp_pap_ack_nack"); if (!priv->evt_request || !priv->evt_ack_nack) goto err; static struct data_item_reg evt_auth_data_items[ANALYZER_PPP_PAP_AUTH_DATA_COUNT] = { { 0 } }; evt_auth_data_items[analyzer_ppp_pap_auth_client].name = "client"; evt_auth_data_items[analyzer_ppp_pap_auth_client].flags = DATA_REG_FLAG_NO_ALLOC; evt_auth_data_items[analyzer_ppp_pap_auth_server].name = "server"; evt_auth_data_items[analyzer_ppp_pap_auth_server].flags = DATA_REG_FLAG_NO_ALLOC; evt_auth_data_items[analyzer_ppp_pap_auth_top_proto].name = "top_proto"; evt_auth_data_items[analyzer_ppp_pap_auth_top_proto].value_type = ptype_get_type("string"); evt_auth_data_items[analyzer_ppp_pap_auth_vlan].name = "vlan"; evt_auth_data_items[analyzer_ppp_pap_auth_vlan].flags = DATA_REG_FLAG_NO_ALLOC; evt_auth_data_items[analyzer_ppp_pap_auth_identifier].name = "identifier"; evt_auth_data_items[analyzer_ppp_pap_auth_identifier].value_type = ptype_get_type("uint8"); evt_auth_data_items[analyzer_ppp_pap_auth_success].name = "success"; evt_auth_data_items[analyzer_ppp_pap_auth_success].value_type = ptype_get_type("bool"); evt_auth_data_items[analyzer_ppp_pap_auth_peer_id].name = "peer_id"; evt_auth_data_items[analyzer_ppp_pap_auth_peer_id].value_type = ptype_get_type("string"); evt_auth_data_items[analyzer_ppp_pap_auth_password].name = "password"; evt_auth_data_items[analyzer_ppp_pap_auth_password].value_type = ptype_get_type("string"); static struct data_reg evt_auth_data = { .items = evt_auth_data_items, .data_count = ANALYZER_PPP_PAP_AUTH_DATA_COUNT }; static struct event_reg_info analyzer_ppp_pap_evt_auth = { 0 }; analyzer_ppp_pap_evt_auth.source_name = "analyzer_ppp_pap"; analyzer_ppp_pap_evt_auth.source_obj = analyzer; analyzer_ppp_pap_evt_auth.name = "ppp_pap_auth"; analyzer_ppp_pap_evt_auth.description = "PPP PAP MD5 authentication"; analyzer_ppp_pap_evt_auth.data_reg = &evt_auth_data; analyzer_ppp_pap_evt_auth.listeners_notify = analyzer_ppp_pap_event_listeners_notify; priv->evt_auth = event_register(&analyzer_ppp_pap_evt_auth); if (!priv->evt_auth) goto err; return POM_OK; err: analyzer_ppp_pap_cleanup(analyzer); return POM_ERR; }
static int analyzer_docsis_init(struct analyzer *analyzer) { struct analyzer_docsis_priv *priv = malloc(sizeof(struct analyzer_docsis_priv)); if (!priv) { pom_oom(sizeof(struct analyzer_docsis_priv)); return POM_ERR; } memset(priv, 0, sizeof(struct analyzer_docsis_priv)); analyzer->priv = priv; if (pthread_mutex_init(&priv->lock, NULL)) { pomlog(POMLOG_ERR "Error while initializing table lock : %s", pom_strerror(errno)); free(priv); return POM_ERR; } static struct data_item_reg evt_cm_new_data_items[ANALYZER_DOCSIS_EVT_CM_NEW_DATA_COUNT] = { { 0 } }; evt_cm_new_data_items[analyzer_docsis_cm_new_mac].name = "mac", evt_cm_new_data_items[analyzer_docsis_cm_new_mac].value_type = ptype_get_type("mac"); evt_cm_new_data_items[analyzer_docsis_cm_new_input].name = "input", evt_cm_new_data_items[analyzer_docsis_cm_new_input].value_type = ptype_get_type("string"); static struct data_reg evt_cm_new_data = { .items = evt_cm_new_data_items, .data_count = ANALYZER_DOCSIS_EVT_CM_NEW_DATA_COUNT }; static struct event_reg_info analyzer_docsis_evt_cm_new = { 0 }; analyzer_docsis_evt_cm_new.source_name = "analyzer_docsis"; analyzer_docsis_evt_cm_new.source_obj = analyzer; analyzer_docsis_evt_cm_new.name = "docsis_cm_new"; analyzer_docsis_evt_cm_new.description = "New cable modem found"; analyzer_docsis_evt_cm_new.data_reg = &evt_cm_new_data; analyzer_docsis_evt_cm_new.listeners_notify = analyzer_docsis_event_listeners_notify; priv->evt_cm_new = event_register(&analyzer_docsis_evt_cm_new); if (!priv->evt_cm_new) goto err; static struct data_item_reg evt_cm_reg_status_data_items[ANALYZER_DOCSIS_EVT_CM_REG_STATUS_DATA_COUNT] = { { 0 } }; evt_cm_reg_status_data_items[analyzer_docsis_cm_reg_status_old].name = "old_status", evt_cm_reg_status_data_items[analyzer_docsis_cm_reg_status_old].value_type = ptype_get_type("uint8"); evt_cm_reg_status_data_items[analyzer_docsis_cm_reg_status_new].name = "new_status", evt_cm_reg_status_data_items[analyzer_docsis_cm_reg_status_new].value_type = ptype_get_type("uint8"); evt_cm_reg_status_data_items[analyzer_docsis_cm_reg_status_mac].name = "mac"; evt_cm_reg_status_data_items[analyzer_docsis_cm_reg_status_mac].value_type = ptype_get_type("mac"); evt_cm_reg_status_data_items[analyzer_docsis_cm_reg_status_timeout].name = "timeout", evt_cm_reg_status_data_items[analyzer_docsis_cm_reg_status_timeout].value_type = ptype_get_type("uint8"); static struct data_reg evt_cm_reg_status_data = { .items = evt_cm_reg_status_data_items, .data_count = ANALYZER_DOCSIS_EVT_CM_REG_STATUS_DATA_COUNT }; static struct event_reg_info analyzer_docsis_evt_cm_reg_status = { 0 }; analyzer_docsis_evt_cm_reg_status.source_name = "analyzer_docsis"; analyzer_docsis_evt_cm_reg_status.source_obj = analyzer; analyzer_docsis_evt_cm_reg_status.name = "docsis_cm_reg_status"; analyzer_docsis_evt_cm_reg_status.description = "Cable modem registration status changed"; analyzer_docsis_evt_cm_reg_status.data_reg = &evt_cm_reg_status_data; analyzer_docsis_evt_cm_reg_status.listeners_notify = analyzer_docsis_event_listeners_notify; priv->evt_cm_reg_status = event_register(&analyzer_docsis_evt_cm_reg_status); if (!priv->evt_cm_reg_status) goto err; return POM_OK; err: analyzer_docsis_cleanup(analyzer); return POM_ERR; }
/* * local version of a security handle allocator. Logically sets * up a network "connection". */ static void local_connect( const char * hostname, char * (*conf_fn)(char *, void *), void (*fn)(void *, security_handle_t *, security_status_t), void * arg, void * datap) { struct sec_handle *rh; char *amandad_path=NULL; char *client_username=NULL; char myhostname[MAX_HOSTNAME_LENGTH+1]; assert(fn != NULL); assert(hostname != NULL); auth_debug(1, _("local: local_connect: %s\n"), hostname); rh = g_new0(struct sec_handle, 1); security_handleinit(&rh->sech, &local_security_driver); rh->hostname = NULL; rh->rs = NULL; rh->ev_timeout = NULL; rh->rc = NULL; if (gethostname(myhostname, MAX_HOSTNAME_LENGTH) == -1) { security_seterror(&rh->sech, _("gethostname failed")); (*fn)(arg, &rh->sech, S_ERROR); return; } myhostname[SIZEOF(myhostname)-1] = '\0'; if (strcmp(hostname, myhostname) != 0 && match("^localhost(\\.localdomain)?$", hostname) == 0) { security_seterror(&rh->sech, _("%s: is not local"), hostname); (*fn)(arg, &rh->sech, S_ERROR); return; } rh->hostname = stralloc(hostname); rh->rs = tcpma_stream_client(rh, newhandle++); if (rh->rs == NULL) goto error; amfree(rh->hostname); rh->hostname = stralloc(rh->rs->rc->hostname); /* * We need to open a new connection. * * XXX need to eventually limit number of outgoing connections here. */ if(conf_fn) { amandad_path = conf_fn("amandad_path", datap); client_username = conf_fn("client_username", datap); } if(rh->rc->read == -1) { if (runlocal(rh->rs->rc, amandad_path, client_username) < 0) { security_seterror(&rh->sech, _("can't connect to %s: %s"), hostname, rh->rs->rc->errmsg); goto error; } rh->rc->refcnt++; } /* * The socket will be opened async so hosts that are down won't * block everything. We need to register a write event * so we will know when the socket comes alive. * * Overload rh->rs->ev_read to provide a write event handle. * We also register a timeout. */ rh->fn.connect = fn; rh->arg = arg; rh->rs->ev_read = event_register((event_id_t)rh->rs->rc->write, EV_WRITEFD, sec_connect_callback, rh); rh->ev_timeout = event_register((event_id_t)CONNECT_TIMEOUT, EV_TIME, sec_connect_timeout, rh); return; error: (*fn)(arg, &rh->sech, S_ERROR); amfree(rh->hostname); }
int main(int argc, char **argv) { address_tuple_t tuple; char *progname; char *server = NULL; char *port = NULL; char *myeid = NULL; char *pidfile = NULL; char *vnodeid = NULL; char buf[BUFSIZ], ipaddr[32]; char hostname[MAXHOSTNAMELEN]; struct hostent *he; int c; struct in_addr myip; FILE *fp; progname = argv[0]; while ((c = getopt(argc, argv, "ds:p:e:i:v:")) != -1) { switch (c) { case 'd': debug++; break; case 's': server = optarg; break; case 'p': port = optarg; break; case 'i': pidfile = optarg; break; case 'e': myeid = optarg; break; case 'v': vnodeid = optarg; break; default: usage(progname); } } argc -= optind; argv += optind; if (argc) usage(progname); if (! myeid) fatal("Must provide pid/eid"); if (debug) loginit(0, 0); else { loginit(1, "evproxy"); /* See below for daemonization */ } /* * Get our IP address. Thats how we name this host to the * event System. */ if (gethostname(hostname, MAXHOSTNAMELEN) == -1) { fatal("could not get hostname: %s\n", strerror(errno)); } if (! (he = gethostbyname(hostname))) { fatal("could not get IP address from hostname: %s", hostname); } memcpy((char *)&myip, he->h_addr, he->h_length); strcpy(ipaddr, inet_ntoa(myip)); /* * If server is not specified, then it defaults to EVENTSERVER. * This allows the client to work on either users.emulab.net * or on a client node. */ if (!server) server = "event-server"; /* * XXX Need to daemonize earlier or the threads go away. */ if (!debug) daemon(0, 0); /* * Convert server/port to elvin thing. * * XXX This elvin string stuff should be moved down a layer. */ snprintf(buf, sizeof(buf), "elvin://%s%s%s", server, (port ? ":" : ""), (port ? port : "")); server = buf; /* * Construct an address tuple for generating the event. */ tuple = address_tuple_alloc(); if (tuple == NULL) { fatal("could not allocate an address tuple"); } /* Register with the event system on boss */ bosshandle = event_register(server, 1); if (bosshandle == NULL) { fatal("could not register with remote event system"); } /* Register with the event system on the local node */ localhandle = event_register("elvin://localhost", 1); if (localhandle == NULL) { fatal("could not register with local event system"); } /* * Create a subscription to pass to the remote server. We want * all events for this node, or all events for the experiment * if the node is unspecified (we want to avoid getting events * that are directed at specific nodes that are not us!). */ sprintf(buf, "%s,%s", ADDRESSTUPLE_ALL, ipaddr); tuple->host = buf; tuple->expt = myeid; /* Subscribe to the test event: */ if (! event_subscribe(bosshandle, callback, tuple, "event received")) { fatal("could not subscribe to events on remote server"); } tuple->host = ADDRESSTUPLE_ALL; tuple->scheduler = 1; if (! event_subscribe(localhandle, sched_callback, tuple, NULL)) { fatal("could not subscribe to events on remote server"); } signal(SIGTERM, sigterm); /* * Stash the pid away. */ if (! pidfile) { sprintf(buf, "%s/evproxy.pid", _PATH_VARRUN); pidfile = buf; } fp = fopen(pidfile, "w"); if (fp != NULL) { fprintf(fp, "%d\n", getpid()); (void) fclose(fp); } /* Begin the event loop, waiting to receive event notifications */ while (! stop) { struct timeval tv = { 5, 0 }; select(0, NULL, NULL, NULL, &tv); } unlink(pidfile); /* Unregister with the remote event system: */ if (event_unregister(bosshandle) == 0) { fatal("could not unregister with remote event system"); } /* Unregister with the local event system: */ if (event_unregister(localhandle) == 0) { fatal("could not unregister with local event system"); } return 0; }
/* * ssl version of a security handle allocator. Logically sets * up a network "connection". */ static void ssl_connect( const char *hostname, char * (*conf_fn)(char *, void *), void (*fn)(void *, security_handle_t *, security_status_t), void * arg, void * datap) { struct sec_handle *rh; int result; char *canonname; char *service; in_port_t port; char *src_ip = NULL; char *ssl_dir = NULL; char *ssl_fingerprint_file = NULL; char *ssl_cert_file = NULL; char *ssl_key_file = NULL; char *ssl_ca_cert_file = NULL; char *ssl_cipher_list = NULL; int ssl_check_certificate_host = 1; assert(fn != NULL); assert(hostname != NULL); auth_debug(1, _("ssl: ssl_connect: %s\n"), hostname); rh = g_new0(struct sec_handle, 1); security_handleinit(&rh->sech, &ssl_security_driver); rh->hostname = NULL; rh->rs = NULL; rh->ev_timeout = NULL; rh->rc = NULL; result = resolve_hostname(hostname, 0, NULL, &canonname); if(result != 0) { g_debug(_("resolve_hostname(%s): %s"), hostname, gai_strerror(result)); security_seterror(&rh->sech, _("resolve_hostname(%s): %s\n"), hostname, gai_strerror(result)); (*fn)(arg, &rh->sech, S_ERROR); return; } if (canonname == NULL) { g_debug(_("resolve_hostname(%s) did not return a canonical name"), hostname); security_seterror(&rh->sech, _("resolve_hostname(%s) did not return a canonical name\n"), hostname); (*fn)(arg, &rh->sech, S_ERROR); return; } rh->hostname = canonname; /* will be replaced */ canonname = NULL; /* steal reference */ rh->rs = tcpma_stream_client(rh, newhandle++); rh->rc->recv_security_ok = &bsd_recv_security_ok; rh->rc->prefix_packet = &bsd_prefix_packet; rh->rc->need_priv_port = 0; if (rh->rs == NULL) goto error; amfree(rh->hostname); rh->hostname = g_strdup(rh->rs->rc->hostname); ssl_dir = getconf_str(CNF_SSL_DIR); if (conf_fn) { service = conf_fn("remote_port", datap); if (!service || strlen(service) <= 1) service = AMANDA_SERVICE_NAME; g_debug("Connecting to service '%s'", service); src_ip = conf_fn("src_ip", datap); ssl_fingerprint_file = g_strdup(conf_fn("ssl_fingerprint_file", datap)); ssl_cert_file = g_strdup(conf_fn("ssl_cert_file", datap)); ssl_key_file = g_strdup(conf_fn("ssl_key_file", datap)); ssl_ca_cert_file = g_strdup(conf_fn("ssl_ca_cert_file", datap)); ssl_cipher_list = conf_fn("ssl_cipher_list", datap); ssl_check_certificate_host = atoi(conf_fn("ssl_check_certificate_host", datap)); } else { service = AMANDA_SERVICE_NAME; } if (ssl_dir) { if (!ssl_cert_file || ssl_cert_file == '\0') { ssl_cert_file = g_strdup_printf("%s/me/crt.pem", ssl_dir); } if (!ssl_key_file || ssl_key_file == '\0') { ssl_key_file = g_strdup_printf("%s/me/private/key.pem", ssl_dir); } if (!ssl_ca_cert_file || ssl_ca_cert_file == '\0') { ssl_ca_cert_file = g_strdup_printf("%s/CA/crt.pem", ssl_dir); } if (!ssl_fingerprint_file || ssl_fingerprint_file == '\0') { struct stat statbuf; ssl_fingerprint_file = g_strdup_printf("%s/remote/%s/fingerprint", ssl_dir, rh->hostname); if (stat(ssl_fingerprint_file, &statbuf) == -1) { g_free(ssl_fingerprint_file); ssl_fingerprint_file = NULL; } } } port = find_port_for_service(service, "tcp"); if (port == 0) { security_seterror(&rh->sech, _("%s/tcp unknown protocol"), service); goto error; } /* * We need to open a new connection. */ if(rh->rc->read == -1) { if (runssl(rh, port, src_ip, ssl_fingerprint_file, ssl_cert_file, ssl_key_file, ssl_ca_cert_file, ssl_cipher_list, ssl_check_certificate_host) < 0) goto error; rh->rc->refcnt++; } g_free(ssl_fingerprint_file); g_free(ssl_cert_file); g_free(ssl_key_file); g_free(ssl_ca_cert_file); /* * The socket will be opened async so hosts that are down won't * block everything. We need to register a write event * so we will know when the socket comes alive. * * Overload rh->rs->ev_read to provide a write event handle. * We also register a timeout. */ rh->fn.connect = fn; rh->arg = arg; rh->rs->ev_read = event_register((event_id_t)(rh->rs->rc->write), EV_WRITEFD, sec_connect_callback, rh); rh->ev_timeout = event_register(CONNECT_TIMEOUT, EV_TIME, sec_connect_timeout, rh); return; error: (*fn)(arg, &rh->sech, S_ERROR); }
//-------------------------------------------------------------- void testApp::setup(){ ofSetCircleResolution(50); ofBackground(0,0,0); ofSetWindowTitle("glAss openFrameworks port"); ofSetFrameRate(100); _pd = (float *)malloc( 150*40*sizeof(float) ); _pu = (float *)malloc( 150*40*sizeof(float) ); _pv = (float *)malloc( 150*40*sizeof(float) ); _pu2 = (float *)malloc( 150*40*sizeof(float) ); _pv2 = (float *)malloc( 150*40*sizeof(float) ); music.loadSound( "intromusic.xm" ); music.setMultiPlay( false ); // undantag... UPLOADMACRO( GIF_FONT, gif_font ); event_init(); upload_images(); p_cubes_init(); p_greetings_init(); p_klask_init(); // initeringen kalas, glad påsk... Sleep( 100 ); glaCls(0.33f); // FÖRSTA TEXTEN I INTROT event_register( 5, 5.2f, p_tunnel_run, 1 ); event_register( 5.1f, 5.3f, p_wirelandscape_run, 0 ); event_register( 5.2f, 5.4f, p_sphere_run, 0 ); event_register( 2, 5.5f, p_fulintro_run, 0 ); // ANDRA TEXTEN I INTROT event_register( 9, 9.2f, p_cubes_run, 0 ); event_register( 9.1f, 9.3f, p_psyk_run, 0 ); event_register( 9.2f, 9.4f, p_twist3d_run, 0 ); event_register( 6, 9.5f, p_fulintro_run, 1 ); // TREDJE TEXTEN I INTROT event_register( 13, 13.2f, p_twist3d_run, 0 ); event_register( 13.1f, 13.3f, p_psyk_run, 0 ); event_register( 13.2f, 13.4f, p_tunnel_run, 1 ); event_register( 10, 13.5f, p_fulintro_run, 2 ); // FLIMMER I INTROT event_register( 1, 13.7f, p_static_run, 256 ); // FLASH Å SEN 64 SNURRA event_register( 14, 15, p_whiteflash_run, 0 ); event_register( 14, 29, p_wirelandscape_run, 0 ); // FLASH Å HANZON+PSYKSNURR (MUSIKEN KOMMER IGÅNG) event_register( 29, 30, p_whiteflash_run, 0 ); event_register( 29, 42, p_psyk_run, 0 ); event_register( 41, 58, p_title_run, 3 ); event_register( 29, 34, p_hanzon_run, 0 ); // VÅRA NAMN event_register( 32, 35, p_name_run, 0 ); event_register( 36, 39, p_name_run, 1 ); // TWISTERN SNURRAR IN... BÅDA TVÅ (2D OCH 3D) event_register( 42, 58, p_twist3d_run, 0 ); event_register( 42, 43, p_whiteflash_run, 0 ); event_register( 39, 52, p_twister_run, 0 ); // KUBERNA (MUSIKEN LUGNAR NER SIG) event_register( 58, 79, p_cubes_run, 0 ); event_register( 58, 59, p_whiteflash_run, 0 ); // TUNNELN EFTERÅT, MED BLOBSPHERE event_register( 79, 80, p_whiteflash_run, 0 ); event_register( 79, 85, p_tunnel_run, 512 ); event_register( 79, 85, p_sphere_run, 0 ); // FSOL PSYK event_register( 85, 141, p_klask_run, 264 ); // ÖVERGÅR I GREETS, SOM ÖVERGÅR I TUNNEL event_register( 85, 128, p_greetings_run, 0 ); event_register( 85, 86, p_whiteflash_run, 0 ); event_register( 100, 141, p_tunnel_run, 512 ); // TUNNELN ÖVERGÅR I '64' PLUS MASSOR AV EFFEKTER, COLOR DODGE'AT event_register( 114, 124.0f, p_wirelandscape_run, 0 ); event_register( 114, 124.0f, p_psyk_run, 2 ); event_register( 114, 115, p_whiteflash_run, 0 ); // event_register( 125, 126, p_whiteflash_run, 0 ); // LUGNARE MUSIK, EFTER UPPLADDNINGEN, BYT TILL FLUM MED FLASH event_register( 124.0f, 141, p_aftershit_run, 0 ); event_register( 138.5f, 141, p_fadeblack_run, 0 ); music.play(); }
/* * bsdtcp version of a security handle allocator. Logically sets * up a network "connection". */ static void bsdtcp_connect( const char *hostname, char * (*conf_fn)(char *, void *), void (*fn)(void *, security_handle_t *, security_status_t), void * arg, void * datap) { struct sec_handle *rh; int result; char *canonname; char *service; in_port_t port; assert(fn != NULL); assert(hostname != NULL); (void)conf_fn; /* Quiet unused parameter warning */ (void)datap; /* Quiet unused parameter warning */ auth_debug(1, _("bsdtcp: bsdtcp_connect: %s\n"), hostname); rh = alloc(sizeof(*rh)); security_handleinit(&rh->sech, &bsdtcp_security_driver); rh->hostname = NULL; rh->rs = NULL; rh->ev_timeout = NULL; rh->rc = NULL; result = resolve_hostname(hostname, 0, NULL, &canonname); if(result != 0) { dbprintf(_("resolve_hostname(%s): %s\n"), hostname, gai_strerror(result)); security_seterror(&rh->sech, _("resolve_hostname(%s): %s\n"), hostname, gai_strerror(result)); (*fn)(arg, &rh->sech, S_ERROR); return; } if (canonname == NULL) { dbprintf(_("resolve_hostname(%s) did not return a canonical name\n"), hostname); security_seterror(&rh->sech, _("resolve_hostname(%s) did not return a canonical name\n"), hostname); (*fn)(arg, &rh->sech, S_ERROR); return; } rh->hostname = canonname; /* will be replaced */ canonname = NULL; /* steal reference */ rh->rs = tcpma_stream_client(rh, newhandle++); rh->rc->recv_security_ok = &bsd_recv_security_ok; rh->rc->prefix_packet = &bsd_prefix_packet; if (rh->rs == NULL) goto error; amfree(rh->hostname); rh->hostname = stralloc(rh->rs->rc->hostname); if (conf_fn) { service = conf_fn("client_port", datap); if (strlen(service) <= 1) service = "amanda"; } else { service = "amanda"; } port = find_port_for_service(service, "tcp"); if (port == 0) { security_seterror(&rh->sech, _("%s/tcp unknown protocol"), service); goto error; } /* * We need to open a new connection. * * XXX need to eventually limit number of outgoing connections here. */ if(rh->rc->read == -1) { if (runbsdtcp(rh, port) < 0) goto error; rh->rc->refcnt++; } /* * The socket will be opened async so hosts that are down won't * block everything. We need to register a write event * so we will know when the socket comes alive. * * Overload rh->rs->ev_read to provide a write event handle. * We also register a timeout. */ rh->fn.connect = fn; rh->arg = arg; rh->rs->ev_read = event_register((event_id_t)(rh->rs->rc->write), EV_WRITEFD, sec_connect_callback, rh); rh->ev_timeout = event_register(CONNECT_TIMEOUT, EV_TIME, sec_connect_timeout, rh); return; error: (*fn)(arg, &rh->sech, S_ERROR); }
main(int argc, char *argv[]) { char *pgm; int ok, help, debug, verbose, query; char *what = "*", whatbuf[256] = { '\0' }; char *world; char *server; char *logger; char *host; int id, nc; int i, nmod; char argbuf[256]; MODULE_HOST modlocs[MAX_AGENT]; pgm = argv[0]; ++argv; --argc; ok = 1; help = 0; debug = 0; verbose = 0; query = 0; world = NULL; logger = NULL; host = NULL; while (argc && *argv[0] == '-') { char *opt; opt = argv[0] + 1; ++argv; --argc; if (streq(opt, "help")) ++help; else if (substr(opt, "debug")) ++debug; else if (substr(opt, "verbose"))++verbose; else if (substr(opt, "earlab")) { world = "Earlab*Master"; } else if (substr(opt, "search")) { if (!argc || argv[0][0] == '-') { fprintf(stderr, "%s: missing argument to -%s\n", pgm, opt); ok = 0; } else { world = argv[0]; ++argv; --argc; } } else if (substr(opt, "logserver")) { if (!argc || argv[0][0] == '-') { fprintf(stderr, "%s: missing argument to -%s\n", pgm, opt); ok = 0; } else { logger = argv[0]; ++argv; --argc; } } else if (substr(opt, "module")) { if (!argc || argv[0][0] == '-') { fprintf(stderr, "%s: missing argument to -%s\n", pgm, opt); ok = 0; } else { if (!whatbuf[0]) strcpy(whatbuf, "{"); else strcat(whatbuf, ","); strcat(whatbuf, argv[0]); what = whatbuf; ++argv; --argc; } } else if (substr(opt, "host")) { if (!argc || argv[0][0] == '-') { fprintf(stderr, "%s: missing argument to -%s\n", pgm, opt); ok = 0; } else { host = argv[0]; ++argv; --argc; } } else { fprintf(stderr, "%s: ignoring argument -%s\n", pgm, opt) ; help = 1; ok = 0; } } if (!ok || help || (argc == 0 && !world)) { usage(pgm, help); exit(!help); } event_verbose(verbose); if (world) { server = SearchWorld(NULL, world); if (!server) { fprintf(stderr, "%s: couldn't find earlab master server\n", pgm); exit(1); } } else if (argc) { server = argv[0]; ++argv; --argc; } else { usage(pgm, help); exit(1); } if (argc) { if (!whatbuf[0]) what = argv[0]; else { strcat(whatbuf, ","); strcat(whatbuf, argv[0]); strcat(whatbuf, "}"); } ++argv; --argc; } else if (!whatbuf[0]) { usage(pgm, 0); exit(1); } argbuf[0] = '\0'; while (argc) { strcat(argbuf, argv[0]); ++argv; --argc; if (argc) strcat(argbuf, " "); } printf("Module search is \"%s\"\n", what); /* local initialization */ agent_init(); id = event_join(server, &nc); if (!id) { fprintf(stderr, "%s: couldn't join server \"%s\"\n", server); exit(4); } printf("%s: joined %s as client id %d (%d clients)\n", pgm, server, id, nc); event_register("earlab", "control", pgm); event_select_type(0, 0, ET_MAX); event_select_type(1, ET_AGENTD_MIN, ET_AGENTD_MAX); nmod = LocateModule(what, modlocs, MAX_AGENT); for (i = 0; i < nmod; ++i) { printf("%s: module \"%s\" available on host %s\n", pgm, modlocs[i].module, modlocs[i].host); } if (query) { event_leave(); exit(0); } if (host) for (i = 0; i < nmod; ++i) { if (strmatch(host, modlocs[i].host)) break; } else i = 0; if (nmod == 0 || i == nmod) { printf("%s: module \"%s\" not available on host %s\n", pgm, what, host?host:"*"); event_leave(); exit(1); } StartModule(modlocs[i].clientid, logger, modlocs[i].module, argbuf); event_leave(); exit(0); }
/* * krb5 version of a security handle allocator. Logically sets * up a network "connection". */ static void krb5_connect( const char *hostname, char * (*conf_fn)(char *, void *), void (*fn)(void *, security_handle_t *, security_status_t), void * arg, void * datap) { struct sec_handle *rh; int result; char *canonname; assert(fn != NULL); assert(hostname != NULL); auth_debug(1, "krb5: krb5_connect: %s\n", hostname); krb5_init(); rh = alloc(sizeof(*rh)); security_handleinit(&rh->sech, &krb5_security_driver); rh->hostname = NULL; rh->rs = NULL; rh->ev_timeout = NULL; rh->rc = NULL; result = resolve_hostname(hostname, 0, NULL, &canonname); if(result != 0) { dbprintf(_("resolve_hostname(%s): %s\n"), hostname, gai_strerror(result)); security_seterror(&rh->sech, _("resolve_hostname(%s): %s\n"), hostname, gai_strerror(result)); (*fn)(arg, &rh->sech, S_ERROR); return; } if (canonname == NULL) { dbprintf(_("resolve_hostname(%s) did not return a canonical name\n"), hostname); security_seterror(&rh->sech, _("resolve_hostname(%s) did not return a canonical name\n"), hostname); (*fn)(arg, &rh->sech, S_ERROR); return; } rh->hostname = canonname; /* will be replaced */ canonname = NULL; /* steal reference */ rh->rs = tcpma_stream_client(rh, newhandle++); rh->rc->conf_fn = conf_fn; rh->rc->datap = datap; rh->rc->recv_security_ok = NULL; rh->rc->prefix_packet = NULL; if (rh->rs == NULL) goto error; amfree(rh->hostname); rh->hostname = stralloc(rh->rs->rc->hostname); #ifdef AMANDA_KEYTAB keytab_name = AMANDA_KEYTAB; #else if(conf_fn) { keytab_name = conf_fn("krb5keytab", datap); } #endif #ifdef AMANDA_PRINCIPAL principal_name = AMANDA_PRINCIPAL; #else if(conf_fn) { principal_name = conf_fn("krb5principal", datap); } #endif /* * We need to open a new connection. * * XXX need to eventually limit number of outgoing connections here. */ if(rh->rc->read == -1) { if (runkrb5(rh) < 0) goto error; rh->rc->refcnt++; } /* * The socket will be opened async so hosts that are down won't * block everything. We need to register a write event * so we will know when the socket comes alive. * * Overload rh->rs->ev_read to provide a write event handle. * We also register a timeout. */ rh->fn.connect = fn; rh->arg = arg; rh->rs->ev_read = event_register((event_id_t)(rh->rs->rc->write), EV_WRITEFD, sec_connect_callback, rh); rh->ev_timeout = event_register(CONNECT_TIMEOUT, EV_TIME, sec_connect_timeout, rh); amfree(canonname); return; error: amfree(canonname); (*fn)(arg, &rh->sech, S_ERROR); }
int EventInit(char *server) { char buf[BUFSIZ], ipbuf[BUFSIZ]; struct hostent *he; struct in_addr myip; char *ipaddr; address_tuple_t tuple; if (server == NULL) { warning("no event server specified"); return 1; } if (gethostname(buf, sizeof(buf)) < 0) { pwarning("could not get hostname"); return 1; } if ((he = gethostbyname(buf)) == NULL) { warning("could not get IP address from hostname"); return 1; } memcpy((char *)&myip, he->h_addr, he->h_length); strcpy(ipbuf, inet_ntoa(myip)); ipaddr = ipbuf; /* * Hideous Hack Alert! * * Assume our hostname is of the form 'c-<num>.<domain>' * and use <num> to determine our client number. * We use that number later to compare to the MAXCLIENTS * field to determine if we should process an event. */ if (sscanf(buf, "c-%d.", &clientnum) != 1) { warning("could not determine client number from hostname %s", buf); return 1; } else if (debug) log("client number %d for event handling", clientnum); /* * Convert server/port to elvin thing. */ snprintf(buf, sizeof(buf), "elvin://%s", server); server = buf; /* * Construct an address tuple for subscribing to events for * this node. */ tuple = address_tuple_alloc(); if (tuple == NULL) { warning("could not allocate an address tuple"); return 1; } tuple->host = ADDRESSTUPLE_ANY; /* ipaddr; */ tuple->site = ADDRESSTUPLE_ANY; tuple->group = ADDRESSTUPLE_ANY; tuple->expt = ADDRESSTUPLE_ANY; tuple->objtype = TBDB_OBJECTTYPE_FRISBEE; tuple->objname = ADDRESSTUPLE_ANY; tuple->eventtype = ADDRESSTUPLE_ANY; /* * Register with the event system. */ ehandle = event_register(server, 0); if (ehandle == NULL) { warning("could not register with event system"); address_tuple_free(tuple); return 1; } /* * Subscribe to the event we specified above. */ if (!event_subscribe(ehandle, callback, tuple, NULL)) { warning("could not subscribe to FRISBEE events"); address_tuple_free(tuple); return 1; } address_tuple_free(tuple); return 0; }
static int proto_eap_init(struct proto *proto, struct registry_instance *i) { if (proto_number_register("8021x", 0x0, proto) != POM_OK || proto_number_register("ppp", 0xc227, proto) != POM_OK) return POM_ERR; struct proto_eap_priv *priv = malloc(sizeof(struct proto_eap_priv)); if (!priv) { pom_oom(sizeof(struct proto_eap_priv)); return POM_ERR; } memset(priv, 0, sizeof(struct proto_eap_priv)); proto_set_priv(proto, priv); priv->p_timeout = ptype_alloc_unit("uint32", "seconds"); if (!priv->p_timeout) goto err; struct registry_param *p = registry_new_param("timeout", "60", priv->p_timeout, "Transaction timeout", 0); if (registry_instance_add_param(i, p) != POM_OK) { registry_cleanup_param(p); goto err; } static struct data_item_reg evt_identity_data_items[PROTO_EAP_EVT_IDENTITY_DATA_COUNT] = { { 0 } }; evt_identity_data_items[evt_eap_common_identifier].name = "identifier"; evt_identity_data_items[evt_eap_common_identifier].value_type = ptype_get_type("uint8"); evt_identity_data_items[evt_eap_common_code].name = "code"; evt_identity_data_items[evt_eap_common_code].value_type = ptype_get_type("uint8"); evt_identity_data_items[evt_eap_identity_identity].name = "identity"; evt_identity_data_items[evt_eap_identity_identity].value_type = ptype_get_type("string"); static struct data_reg evt_eap_identity_data = { .items = evt_identity_data_items, .data_count = PROTO_EAP_EVT_IDENTITY_DATA_COUNT }; static struct event_reg_info proto_eap_identity = { 0 }; proto_eap_identity.source_name = "proto_eap"; proto_eap_identity.source_obj = priv; proto_eap_identity.name = "eap_identity"; proto_eap_identity.description = "EAP Identity"; proto_eap_identity.data_reg = &evt_eap_identity_data; priv->evt_identity = event_register(&proto_eap_identity); if (!priv->evt_identity) goto err; static struct data_item_reg evt_md5_challenge_data_items[PROTO_EAP_EVT_MD5_CHALLENGE_DATA_COUNT] = { { 0 } }; evt_md5_challenge_data_items[evt_eap_common_identifier].name = "identifier"; evt_md5_challenge_data_items[evt_eap_common_identifier].value_type = ptype_get_type("uint8"); evt_md5_challenge_data_items[evt_eap_common_code].name = "code"; evt_md5_challenge_data_items[evt_eap_common_code].value_type = ptype_get_type("uint8"); evt_md5_challenge_data_items[evt_eap_md5_challenge_value].name = "value"; evt_md5_challenge_data_items[evt_eap_md5_challenge_value].value_type = ptype_get_type("bytes"); evt_md5_challenge_data_items[evt_eap_md5_challenge_name].name = "name"; evt_md5_challenge_data_items[evt_eap_md5_challenge_name].value_type = ptype_get_type("string"); static struct data_reg evt_eap_md5_challenge_data = { .items = evt_md5_challenge_data_items, .data_count = PROTO_EAP_EVT_MD5_CHALLENGE_DATA_COUNT }; static struct event_reg_info proto_eap_md5_challenge = { 0 }; proto_eap_md5_challenge.source_name = "proto_eap"; proto_eap_md5_challenge.source_obj = priv; proto_eap_md5_challenge.name = "eap_md5_challenge"; proto_eap_md5_challenge.description = "EAP MD5-Challenge"; proto_eap_md5_challenge.data_reg = &evt_eap_md5_challenge_data; priv->evt_md5_challenge = event_register(&proto_eap_md5_challenge); if (!priv->evt_md5_challenge) goto err; static struct data_item_reg evt_success_failure_data_items[PROTO_EAP_EVT_SUCCESS_FAILURE_DATA_COUNT] = { { 0 } }; evt_success_failure_data_items[evt_eap_common_identifier].name = "identifier"; evt_success_failure_data_items[evt_eap_common_identifier].value_type = ptype_get_type("uint8"); evt_success_failure_data_items[evt_eap_success_failure_success].name = "success"; evt_success_failure_data_items[evt_eap_success_failure_success].value_type = ptype_get_type("bool"); static struct data_reg evt_eap_success_failure_data = { .items = evt_success_failure_data_items, .data_count = PROTO_EAP_EVT_SUCCESS_FAILURE_DATA_COUNT }; static struct event_reg_info proto_eap_success_failure = { 0 }; proto_eap_success_failure.source_name = "proto_eap"; proto_eap_success_failure.source_obj = priv; proto_eap_success_failure.name = "eap_success_failure"; proto_eap_success_failure.description = "EAP Success/Failure"; proto_eap_success_failure.data_reg = &evt_eap_success_failure_data; priv->evt_success_failure = event_register(&proto_eap_success_failure); if (!priv->evt_success_failure) goto err; return POM_OK; err: proto_eap_cleanup(priv); return POM_ERR; }
static int proto_smtp_init(struct proto *proto, struct registry_instance *i) { if (proto_number_register("tcp", 25, proto) != POM_OK || proto_number_register("tcp", 587, proto) != POM_OK) return POM_ERR; struct proto_smtp_priv *priv = malloc(sizeof(struct proto_smtp_priv)); if (!priv) { pom_oom(sizeof(struct proto_smtp_priv)); return POM_ERR; } memset(priv, 0, sizeof(struct proto_smtp_priv)); proto_set_priv(proto, priv); // Register the smtp_cmd event static struct data_item_reg evt_cmd_data_items[PROTO_SMTP_EVT_CMD_DATA_COUNT] = { { 0 } }; evt_cmd_data_items[proto_smtp_cmd_name].name = "name"; evt_cmd_data_items[proto_smtp_cmd_name].value_type = ptype_get_type("string"); evt_cmd_data_items[proto_smtp_cmd_arg].name = "arg"; evt_cmd_data_items[proto_smtp_cmd_arg].value_type = ptype_get_type("string"); static struct data_reg evt_cmd_data = { .items = evt_cmd_data_items, .data_count = PROTO_SMTP_EVT_CMD_DATA_COUNT }; static struct event_reg_info proto_smtp_evt_cmd = { 0 }; proto_smtp_evt_cmd.source_name = "proto_smtp"; proto_smtp_evt_cmd.source_obj = proto; proto_smtp_evt_cmd.name = "smtp_cmd"; proto_smtp_evt_cmd.description = "SMTP command from the client"; proto_smtp_evt_cmd.data_reg = &evt_cmd_data; priv->evt_cmd = event_register(&proto_smtp_evt_cmd); if (!priv->evt_cmd) goto err; // Register the smtp_reply event static struct data_item_reg evt_reply_data_items[PROTO_SMTP_EVT_CMD_DATA_COUNT] = { { 0 } }; evt_reply_data_items[proto_smtp_reply_code].name = "code"; evt_reply_data_items[proto_smtp_reply_code].value_type = ptype_get_type("uint16"); evt_reply_data_items[proto_smtp_reply_text].name = "text"; evt_reply_data_items[proto_smtp_reply_text].flags = DATA_REG_FLAG_LIST; static struct data_reg evt_reply_data = { .items = evt_reply_data_items, .data_count = PROTO_SMTP_EVT_REPLY_DATA_COUNT }; static struct event_reg_info proto_smtp_evt_reply = { 0 }; proto_smtp_evt_reply.source_name = "proto_smtp"; proto_smtp_evt_reply.source_obj = proto; proto_smtp_evt_reply.name = "smtp_reply"; proto_smtp_evt_reply.description = "SMTP command from the client"; proto_smtp_evt_reply.data_reg = &evt_reply_data; priv->evt_reply = event_register(&proto_smtp_evt_reply); if (!priv->evt_reply) goto err; return POM_OK; err: proto_smtp_cleanup(priv); return POM_ERR; }
/* * ssh version of a security handle allocator. Logically sets * up a network "connection". */ static void ssh_connect( const char * hostname, char * (*conf_fn)(char *, void *), void (*fn)(void *, security_handle_t *, security_status_t), void * arg, void * datap) { int result; struct sec_handle *rh; char *amandad_path=NULL, *client_username=NULL, *ssh_keys=NULL; assert(fn != NULL); assert(hostname != NULL); auth_debug(1, "ssh_connect: %s\n", hostname); rh = alloc(SIZEOF(*rh)); security_handleinit(&rh->sech, &ssh_security_driver); rh->hostname = NULL; rh->rs = NULL; rh->ev_timeout = NULL; rh->rc = NULL; /* get the canonical hostname */ rh->hostname = NULL; if ((result = resolve_hostname(hostname, 0, NULL, &rh->hostname)) != 0 || rh->hostname == NULL) { security_seterror(&rh->sech, _("ssh_security could not find canonical name for '%s': %s"), hostname, gai_strerror(result)); (*fn)(arg, &rh->sech, S_ERROR); return; } rh->rs = tcpma_stream_client(rh, newhandle++); rh->rc->conf_fn = conf_fn; rh->rc->datap = datap; if (rh->rs == NULL) goto error; amfree(rh->hostname); rh->hostname = stralloc(rh->rs->rc->hostname); /* * We need to open a new connection. * * XXX need to eventually limit number of outgoing connections here. */ if(conf_fn) { amandad_path = conf_fn("amandad_path", datap); client_username = conf_fn("client_username", datap); ssh_keys = conf_fn("ssh_keys", datap); } if(rh->rc->read == -1) { if (runssh(rh->rs->rc, amandad_path, client_username, ssh_keys) < 0) { security_seterror(&rh->sech, _("can't connect to %s: %s"), hostname, rh->rs->rc->errmsg); goto error; } rh->rc->refcnt++; } /* * The socket will be opened async so hosts that are down won't * block everything. We need to register a write event * so we will know when the socket comes alive. * * Overload rh->rs->ev_read to provide a write event handle. * We also register a timeout. */ rh->fn.connect = fn; rh->arg = arg; rh->rs->ev_read = event_register((event_id_t)rh->rs->rc->write, EV_WRITEFD, sec_connect_callback, rh); rh->ev_timeout = event_register((event_id_t)CONNECT_TIMEOUT, EV_TIME, sec_connect_timeout, rh); return; error: (*fn)(arg, &rh->sech, S_ERROR); }
static int analyzer_rtp_init(struct analyzer *analyzer) { struct analyzer_rtp_priv *priv = malloc(sizeof(struct analyzer_rtp_priv)); if (!priv) { pom_oom(sizeof(struct analyzer_rtp_priv)); return POM_ERR; } memset(priv, 0, sizeof(struct analyzer_rtp_priv)); analyzer->priv = priv; priv->proto_rtp = proto_get("rtp"); if (!priv->proto_rtp) goto err; static struct data_item_reg evt_rtp_stream_data_items[ANALYZER_RTP_STREAM_DATA_COUNT] = { { 0 } }; evt_rtp_stream_data_items[analyzer_rtp_stream_src_addr].name = "src_addr"; evt_rtp_stream_data_items[analyzer_rtp_stream_src_addr].flags = DATA_REG_FLAG_NO_ALLOC; evt_rtp_stream_data_items[analyzer_rtp_stream_dst_addr].name = "dst_addr"; evt_rtp_stream_data_items[analyzer_rtp_stream_dst_addr].flags = DATA_REG_FLAG_NO_ALLOC; evt_rtp_stream_data_items[analyzer_rtp_stream_src_port].name = "src_port"; evt_rtp_stream_data_items[analyzer_rtp_stream_src_port].value_type = ptype_get_type("uint16"); evt_rtp_stream_data_items[analyzer_rtp_stream_dst_port].name = "dst_port"; evt_rtp_stream_data_items[analyzer_rtp_stream_dst_port].value_type = ptype_get_type("uint16"); evt_rtp_stream_data_items[analyzer_rtp_stream_sess_proto].name = "sess_proto"; evt_rtp_stream_data_items[analyzer_rtp_stream_sess_proto].value_type = ptype_get_type("string"); evt_rtp_stream_data_items[analyzer_rtp_stream_call_id].name = "call_id"; evt_rtp_stream_data_items[analyzer_rtp_stream_call_id].value_type = ptype_get_type("string"); evt_rtp_stream_data_items[analyzer_rtp_stream_ssrc].name = "ssrc"; evt_rtp_stream_data_items[analyzer_rtp_stream_ssrc].value_type = ptype_get_type("uint32"); static struct data_reg evt_rtp_stream_data = { .items = evt_rtp_stream_data_items, .data_count = ANALYZER_RTP_STREAM_DATA_COUNT }; static struct event_reg_info analyzer_rtp_evt_stream = { 0 }; analyzer_rtp_evt_stream.source_name = "analyzer_rtp"; analyzer_rtp_evt_stream.source_obj = analyzer; analyzer_rtp_evt_stream.name = "rtp_stream"; analyzer_rtp_evt_stream.description = "RTP stream in a single direction"; analyzer_rtp_evt_stream.data_reg = &evt_rtp_stream_data; analyzer_rtp_evt_stream.flags = EVENT_REG_FLAG_PAYLOAD; analyzer_rtp_evt_stream.listeners_notify = analyzer_rtp_event_listeners_notify; analyzer_rtp_evt_stream.cleanup = analyzer_rtp_stream_event_cleanup; priv->evt_rtp_stream = event_register(&analyzer_rtp_evt_stream); if (!priv->evt_rtp_stream) goto err; return POM_OK; err: analyzer_rtp_cleanup(analyzer); return POM_ERR; }