static void dcc_connected(DCC_REC *dcc) { char *sender; g_return_if_fail(dcc != NULL); switch (dcc->type) { case DCC_TYPE_CHAT: sender = g_strconcat("=", dcc->nick, NULL); printformat(dcc->server, sender, MSGLEVEL_DCC, IRCTXT_DCC_CHAT_CONNECTED, dcc->nick, dcc->addrstr, dcc->port); if (query_find(NULL, sender) == NULL) query_create(dcc->server, sender, TRUE); g_free(sender); break; case DCC_TYPE_SEND: printformat(dcc->server, dcc->nick, MSGLEVEL_DCC, IRCTXT_DCC_SEND_CONNECTED, dcc->arg, dcc->nick, dcc->addrstr, dcc->port); break; case DCC_TYPE_GET: printformat(dcc->server, dcc->nick, MSGLEVEL_DCC, IRCTXT_DCC_GET_CONNECTED, dcc->arg, dcc->nick, dcc->addrstr, dcc->port); break; } }
void query_id(MPIRPC_Node caller, int unique, KDA_ID object_id) { NOTE_FX(object_id); KDA_Operate(object_id, NULL, NULL, NULL, query_create(caller, unique, return_query_id)); }
bool NxMocapMysql::CreateDatabase( const std::string & database ) { if( !mSql->mConnection) { return false; } if( mysql_select_db( mSql->mConnection, database.c_str() ) != 0 ) { // if database doesnt exist string query_create("create database "); query_create.append( database.c_str() ) ; query_create.append( " " ) ; if( mysql_query( mSql->mConnection, query_create.c_str() )!=0) { Log( "Mysql Create Database Failed for : " + database ); return false; } else { Log( "Mysql Database Created : " + database ); mysql_select_db( mSql->mConnection, database.c_str() ); // select the database for query } //if(mysql_query( mSql->mConnection , "CREATE TABLE `data` (`id` int(10) NOT NULL auto_increment,`values` text NOT NULL ,`TimeStamp` double(20,6) NOT NULL, KEY `id` (`id`)) TYPE=MyISAM;")!=0) //{ // return false; //} } else { Log( "Mysql Database Already exists :" + database ); return false; } return true ; }
static void cmd_query(gchar *data, IRC_SERVER_REC *server, WI_IRC_REC *item) { WINDOW_REC *window; QUERY_REC *query; g_return_if_fail(data != NULL); if (*data == '\0') { /* remove current query */ cmd_unquery("", server, item); return; } if (*data != '=' && (server == NULL || !server->connected)) cmd_return_error(CMDERR_NOT_CONNECTED); query = query_find(server, data); if (query != NULL) { /* query already existed - change to query window */ window = window_item_window((WI_ITEM_REC *) query); g_return_if_fail(window != NULL); window_set_active(window); window_item_set_active(window, (WI_ITEM_REC *) query); return; } query_create(server, data, FALSE); }
void query_id_k(MPIRPC_Node caller, int unique, KDA_ID object_id) { NOTE_F; // NOTE_X("oid: ", object_id); KDA_Operate(object_id, NULL, NULL, NULL, query_create(caller, unique, return_query_id_k)); }
/* Return query where to put the private message. */ QUERY_REC *privmsg_get_query(IRC_SERVER_REC *server, const char *nick, int own) { QUERY_REC *query; query = query_find(server, nick); if (query == NULL && settings_get_bool("autocreate_query") && (!own || settings_get_bool("autocreate_own_query"))) query = query_create(server, nick, TRUE); return query; }
/** * Create dns handler. * */ dnshandler_type* dnshandler_create(allocator_type* allocator, listener_type* interfaces) { dnshandler_type* dnsh = NULL; if (!allocator || !interfaces || interfaces->count <= 0) { return NULL; } dnsh = (dnshandler_type*) allocator_alloc(allocator, sizeof(dnshandler_type)); if (!dnsh) { ods_log_error("[%s] unable to create dnshandler: " "allocator_alloc() failed", dnsh_str); return NULL; } dnsh->allocator = allocator; dnsh->need_to_exit = 0; dnsh->engine = NULL; dnsh->interfaces = interfaces; dnsh->socklist = NULL; dnsh->netio = NULL; dnsh->query = NULL; /* setup */ dnsh->socklist = (socklist_type*) allocator_alloc(allocator, sizeof(socklist_type)); if (!dnsh->socklist) { ods_log_error("[%s] unable to create socklist: " "allocator_alloc() failed", dnsh_str); dnshandler_cleanup(dnsh); return NULL; } dnsh->netio = netio_create(allocator); if (!dnsh->netio) { ods_log_error("[%s] unable to create dnshandler: " "netio_create() failed", dnsh_str); dnshandler_cleanup(dnsh); return NULL; } dnsh->query = query_create(); if (!dnsh->query) { ods_log_error("[%s] unable to create dnshandler: " "query_create() failed", dnsh_str); dnshandler_cleanup(dnsh); return NULL; } dnsh->xfrhandler.fd = -1; dnsh->xfrhandler.user_data = (void*) dnsh; dnsh->xfrhandler.timeout = 0; dnsh->xfrhandler.event_types = NETIO_EVENT_READ; dnsh->xfrhandler.event_handler = dnshandler_handle_xfr; return dnsh; }
bool NxMocapMysql::DeleteDatabase( const std::string & database ) { if( !mSql->mConnection) { return false ; } string query_create("drop database "); query_create.append( database.c_str() ) ; query_create.append( " " ) ; if(!mysql_query( mSql->mConnection, query_create.c_str() ) ) { Log( "Mysql Delete Database Failed : " + database ); return false ; } Log( "Mysql Deleted Database : " + database ); return true ; }
extern int bits_va_lock_account(const char *name) { t_account * ac; t_packet * p; t_query * q; if (!name) { eventlog(eventlog_level_error,"bits_va_lock_account","got NULL name"); return -1; } if ((ac = accountlist_find_account(name))) { if (account_get_bits_state(ac)!=account_state_unknown) { eventlog(eventlog_level_warn,"bits_va_lock_account","tried to lock an account which is already locked"); return 0; } } else { /* create a dummy account */ ac = create_vaccount(name,0); if (!ac) { eventlog(eventlog_level_error,"bits_va_lock_account","could not create dummy vaccount"); return -1; } } p = packet_create(packet_class_bits); packet_set_size(p, sizeof(t_bits_va_lock)); packet_set_type(p, BITS_VA_LOCK); bits_packet_generic(p, BITS_ADDR_PEER); q = query_create(bits_query_type_bits_va_lock); if (!q) { eventlog(eventlog_level_error,"bits_va_lock_account","bits_query_push failed."); packet_destroy(p); return -1; } /*bits_query_set_processed(q,-1);*/ bn_int_set(&p->u.bits_va_lock.qid,q->qid); packet_append_string(p,name); query_attach_account(q,"account",ac); send_bits_packet_up(p); packet_del_ref(p); account_set_bits_state(ac,account_state_pending); /* request sent */ accountlist_add_account(ac); return 0; }
static int parse_name(const char *value, list *queries, const query_t *conf) { char *reverse = get_reverse_name(value); char *fqd_name = NULL; query_t *query; // If name is not FQDN, append trailing dot. fqd_name = get_fqd_name(value); // RR type is known. if (conf->type_num >= 0) { if (conf->type_num == KNOT_RRTYPE_PTR) { free(fqd_name); // Check for correct address. if (reverse == NULL) { ERR("invalid IPv4 or IPv6 address %s\n", value); return KNOT_EINVAL; } // Add reverse query for address. query = query_create(reverse, conf); free(reverse); if (query == NULL) { return KNOT_ENOMEM; } add_tail(queries, (node *)query); } else { free(reverse); // Add query for name and specified type. query = query_create(fqd_name, conf); free(fqd_name); if (query == NULL) { return KNOT_ENOMEM; } add_tail(queries, (node *)query); } // RR type is unknown, use defaults. } else { if (reverse == NULL) { // Add query for name and type A. query = query_create(fqd_name, conf); if (query == NULL) { free(fqd_name); return KNOT_ENOMEM; } query->type_num = KNOT_RRTYPE_A; add_tail(queries, (node *)query); // Add query for name and type AAAA. query = query_create(fqd_name, conf); if (query == NULL) { free(fqd_name); return KNOT_ENOMEM; } query->type_num = KNOT_RRTYPE_AAAA; add_tail(queries, (node *)query); // Add query for name and type MX. query = query_create(fqd_name, conf); if (query == NULL) { free(fqd_name); return KNOT_ENOMEM; } free(fqd_name); query->type_num = KNOT_RRTYPE_MX; add_tail(queries, (node *)query); } else { free(fqd_name); // Add reverse query for address. query = query_create(reverse, conf); free(reverse); if (query == NULL) { return KNOT_ENOMEM; } query->type_num = KNOT_RRTYPE_PTR; add_tail(queries, (node *)query); } } return KNOT_EOK; }
/* * Serve DNS requests. */ void server_child(struct nsd *nsd) { size_t i; region_type *server_region = region_create(xalloc, free); netio_type *netio = netio_create(server_region); netio_handler_type *tcp_accept_handlers; query_type *udp_query; sig_atomic_t mode; assert(nsd->server_kind != NSD_SERVER_MAIN); DEBUG(DEBUG_IPC, 2, (LOG_INFO, "child process started")); if (!(nsd->server_kind & NSD_SERVER_TCP)) { close_all_sockets(nsd->tcp, nsd->ifs); } if (!(nsd->server_kind & NSD_SERVER_UDP)) { close_all_sockets(nsd->udp, nsd->ifs); } if (nsd->this_child && nsd->this_child->parent_fd != -1) { netio_handler_type *handler; handler = (netio_handler_type *) region_alloc( server_region, sizeof(netio_handler_type)); handler->fd = nsd->this_child->parent_fd; handler->timeout = NULL; handler->user_data = (struct ipc_handler_conn_data*)region_alloc( server_region, sizeof(struct ipc_handler_conn_data)); ((struct ipc_handler_conn_data*)handler->user_data)->nsd = nsd; ((struct ipc_handler_conn_data*)handler->user_data)->conn = xfrd_tcp_create(server_region); handler->event_types = NETIO_EVENT_READ; handler->event_handler = child_handle_parent_command; netio_add_handler(netio, handler); } if (nsd->server_kind & NSD_SERVER_UDP) { udp_query = query_create(server_region, compressed_dname_offsets, compression_table_size); for (i = 0; i < nsd->ifs; ++i) { struct udp_handler_data *data; netio_handler_type *handler; data = (struct udp_handler_data *) region_alloc( server_region, sizeof(struct udp_handler_data)); data->query = udp_query; data->nsd = nsd; data->socket = &nsd->udp[i]; handler = (netio_handler_type *) region_alloc( server_region, sizeof(netio_handler_type)); handler->fd = nsd->udp[i].s; handler->timeout = NULL; handler->user_data = data; handler->event_types = NETIO_EVENT_READ; handler->event_handler = handle_udp; netio_add_handler(netio, handler); } } /* * Keep track of all the TCP accept handlers so we can enable * and disable them based on the current number of active TCP * connections. */ tcp_accept_handlers = (netio_handler_type *) region_alloc( server_region, nsd->ifs * sizeof(netio_handler_type)); if (nsd->server_kind & NSD_SERVER_TCP) { for (i = 0; i < nsd->ifs; ++i) { struct tcp_accept_handler_data *data; netio_handler_type *handler; data = (struct tcp_accept_handler_data *) region_alloc( server_region, sizeof(struct tcp_accept_handler_data)); data->nsd = nsd; data->socket = &nsd->tcp[i]; data->tcp_accept_handler_count = nsd->ifs; data->tcp_accept_handlers = tcp_accept_handlers; handler = &tcp_accept_handlers[i]; handler->fd = nsd->tcp[i].s; handler->timeout = NULL; handler->user_data = data; handler->event_types = NETIO_EVENT_READ | NETIO_EVENT_ACCEPT; handler->event_handler = handle_tcp_accept; netio_add_handler(netio, handler); } } /* The main loop... */ while ((mode = nsd->mode) != NSD_QUIT) { if(mode == NSD_RUN) nsd->mode = mode = server_signal_mode(nsd); /* Do we need to do the statistics... */ if (mode == NSD_STATS) { #ifdef BIND8_STATS /* Dump the statistics */ bind8_stats(nsd); #else /* !BIND8_STATS */ log_msg(LOG_NOTICE, "Statistics support not enabled at compile time."); #endif /* BIND8_STATS */ nsd->mode = NSD_RUN; } else if (mode == NSD_REAP_CHILDREN) { /* got signal, notify parent. parent reaps terminated children. */ if (nsd->this_child->parent_fd != -1) { sig_atomic_t parent_notify = NSD_REAP_CHILDREN; if (write(nsd->this_child->parent_fd, &parent_notify, sizeof(parent_notify)) == -1) { log_msg(LOG_ERR, "problems sending command from %d to parent: %s", (int) nsd->this_child->pid, strerror(errno)); } } else /* no parent, so reap 'em */ while (waitpid(0, NULL, WNOHANG) > 0) ; nsd->mode = NSD_RUN; } else if(mode == NSD_RUN) { /* Wait for a query... */ if (netio_dispatch(netio, NULL, NULL) == -1) { if (errno != EINTR) { log_msg(LOG_ERR, "netio_dispatch failed: %s", strerror(errno)); break; } } } else if(mode == NSD_QUIT) { /* ignore here, quit */ } else { log_msg(LOG_ERR, "mode bad value %d, back to service.", mode); nsd->mode = NSD_RUN; } } #ifdef BIND8_STATS bind8_stats(nsd); #endif /* BIND8_STATS */ namedb_fd_close(nsd->db); region_destroy(server_region); server_shutdown(nsd); }
/* * Handle an incoming TCP connection. The connection is accepted and * a new TCP reader event handler is added to NETIO. The TCP handler * is responsible for cleanup when the connection is closed. */ static void handle_tcp_accept(netio_type *netio, netio_handler_type *handler, netio_event_types_type event_types) { struct tcp_accept_handler_data *data = (struct tcp_accept_handler_data *) handler->user_data; int s; struct tcp_handler_data *tcp_data; region_type *tcp_region; netio_handler_type *tcp_handler; #ifdef INET6 struct sockaddr_storage addr; #else struct sockaddr_in addr; #endif socklen_t addrlen; if (!(event_types & NETIO_EVENT_READ)) { return; } if (data->nsd->current_tcp_count >= data->nsd->maximum_tcp_count) { return; } /* Accept it... */ addrlen = sizeof(addr); s = accept(handler->fd, (struct sockaddr *) &addr, &addrlen); if (s == -1) { /** * EMFILE and ENFILE is a signal that the limit of open * file descriptors has been reached. Pause accept(). * EINTR is a signal interrupt. The others are various OS ways * of saying that the client has closed the connection. */ if (errno == EMFILE || errno == ENFILE) { if (!slowaccept) { slowaccept_timeout.tv_sec = NETIO_SLOW_ACCEPT_TIMEOUT; slowaccept_timeout.tv_nsec = 0L; timespec_add(&slowaccept_timeout, netio_current_time(netio)); slowaccept = 1; /* We don't want to spam the logs here */ } } else if (errno != EINTR && errno != EWOULDBLOCK #ifdef ECONNABORTED && errno != ECONNABORTED #endif /* ECONNABORTED */ #ifdef EPROTO && errno != EPROTO #endif /* EPROTO */ ) { log_msg(LOG_ERR, "accept failed: %s", strerror(errno)); } return; } if (fcntl(s, F_SETFL, O_NONBLOCK) == -1) { log_msg(LOG_ERR, "fcntl failed: %s", strerror(errno)); close(s); return; } /* * This region is deallocated when the TCP connection is * closed by the TCP handler. */ tcp_region = region_create(xalloc, free); tcp_data = (struct tcp_handler_data *) region_alloc( tcp_region, sizeof(struct tcp_handler_data)); tcp_data->region = tcp_region; tcp_data->query = query_create(tcp_region, compressed_dname_offsets, compression_table_size); tcp_data->nsd = data->nsd; tcp_data->query_count = 0; tcp_data->tcp_accept_handler_count = data->tcp_accept_handler_count; tcp_data->tcp_accept_handlers = data->tcp_accept_handlers; tcp_data->query_state = QUERY_PROCESSED; tcp_data->bytes_transmitted = 0; memcpy(&tcp_data->query->addr, &addr, addrlen); tcp_data->query->addrlen = addrlen; tcp_handler = (netio_handler_type *) region_alloc( tcp_region, sizeof(netio_handler_type)); tcp_handler->fd = s; tcp_handler->timeout = (struct timespec *) region_alloc( tcp_region, sizeof(struct timespec)); tcp_handler->timeout->tv_sec = data->nsd->tcp_timeout; tcp_handler->timeout->tv_nsec = 0L; timespec_add(tcp_handler->timeout, netio_current_time(netio)); tcp_handler->user_data = tcp_data; tcp_handler->event_types = NETIO_EVENT_READ | NETIO_EVENT_TIMEOUT; tcp_handler->event_handler = handle_tcp_reading; netio_add_handler(netio, tcp_handler); /* * Keep track of the total number of TCP handlers installed so * we can stop accepting connections when the maximum number * of simultaneous TCP connections is reached. */ ++data->nsd->current_tcp_count; if (data->nsd->current_tcp_count == data->nsd->maximum_tcp_count) { configure_handler_event_types(data->tcp_accept_handler_count, data->tcp_accept_handlers, NETIO_EVENT_NONE); } }