/* * put client socket in non blocking mode and * create a prelude_io object for IO abstraction. * * Tell server-logic to handle event on the newly accepted client. */ static int setup_client_socket(server_generic_t *server, server_generic_client_t *cdata, int client) { int ret; #ifdef HAVE_TCP_WRAPPERS if ( server->sa->sa_family != AF_UNIX ) { ret = tcpd_auth(cdata, client); if ( ret < 0 ) return -1; } #endif /* * set client socket non blocking. */ #if ! ((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__) ret = fcntl(client, F_SETFL, O_NONBLOCK); if ( ret < 0 ) return prelude_error_verbose(PRELUDE_ERROR_GENERIC, "could not set non blocking mode for client: %s", strerror(errno)); fcntl(client, F_SETFD, fcntl(client, F_GETFD) | FD_CLOEXEC); #endif ret = prelude_io_new(&cdata->fd); if ( ret < 0 ) return ret; prelude_io_set_sys_io(cdata->fd, client); cdata->msg = NULL; cdata->state = 0; return 0; }
void prelude_idmef_debug(idmef_message_t *idmef) { prelude_io_t *pio; prelude_io_new(&pio); prelude_io_set_file_io(pio, stderr); idmef_message_print(idmef, pio); prelude_io_destroy(pio); }
static int wait_connection(prelude_client_profile_t *cp, int sock, struct pollfd *pfd, size_t size, int keepalive, gnutls_x509_privkey_t key, gnutls_x509_crt_t cacrt, gnutls_x509_crt_t crt) { size_t i; prelude_io_t *fd; int ret, active_fd; ret = prelude_io_new(&fd); if ( ret < 0 ) { fprintf(stderr, "%s: error creating a new IO object: %s.\n", prelude_strsource(ret), prelude_strerror(ret)); return -1; } do { active_fd = poll(pfd, size, -1); if ( active_fd < 0 ) { if ( errno != EINTR ) fprintf(stderr, "poll error : %s.\n", strerror(errno)); return -1; } for ( i = 0; i < size && active_fd > 0; i++ ) { if ( pfd[i].revents & POLLIN ) { active_fd--; ret = process_event(cp, pfd[i].fd, fd, key, cacrt, crt); } } } while ( keepalive || ret < 0 ); prelude_io_destroy(fd); return ret; }