static int _parse_listen_sock (xmlNodePtr node, void *arg) { ice_config_t *config = arg; listener_t *listener = calloc (1, sizeof(listener_t)); struct cfg_tag icecast_tags[] = { { "port", config_get_int, &listener->port }, { "shoutcast-compat", config_get_bool, &listener->shoutcast_compat }, { "bind-address", config_get_str, &listener->bind_address }, { "queue-len", config_get_int, &listener->qlen }, { "so-sndbuf", config_get_int, &listener->so_sndbuf }, { "ssl", config_get_bool, &listener->ssl }, { "shoutcast-mount", config_get_str, &listener->shoutcast_mount }, { NULL, NULL, NULL }, }; listener->refcount = 1; listener->port = 8000; listener->qlen = ICE_LISTEN_QUEUE; if (parse_xml_tags (node, icecast_tags)) { config_clear_listener (listener); return -1; } if (listener->qlen < 1) listener->qlen = ICE_LISTEN_QUEUE; listener->next = config->listen_sock; config->listen_sock = listener; config->listen_sock_count++; if (listener->shoutcast_mount) { listener_t *sc_port = calloc (1, sizeof (listener_t)); sc_port->refcount = 1; sc_port->port = listener->port+1; sc_port->qlen = listener->qlen; sc_port->shoutcast_compat = 1; sc_port->shoutcast_mount = (char*)xmlStrdup (XMLSTR(listener->shoutcast_mount)); if (listener->bind_address) sc_port->bind_address = (char*)xmlStrdup (XMLSTR(listener->bind_address)); sc_port->next = config->listen_sock; config->listen_sock = sc_port; config->listen_sock_count++; } else listener->shoutcast_mount = (char*)xmlStrdup (XMLSTR(config->shoutcast_mount)); if (config->port == 0) config->port = listener->port; return 0; }
void client_destroy(client_t *client) { if (client == NULL) return; if (client->worker) { WARN0 ("client still on worker thread"); return; } /* release the buffer now, as the buffer could be on the source queue * and may of disappeared after auth completes */ if (client->refbuf) { refbuf_release (client->refbuf); client->refbuf = NULL; } if (client->flags & CLIENT_AUTHENTICATED) DEBUG1 ("client still in auth \"%s\"", httpp_getvar (client->parser, HTTPP_VAR_URI)); /* write log entry if ip is set (some things don't set it, like outgoing * slave requests */ if (client->respcode > 0 && client->parser) logging_access(client); if (client->flags & CLIENT_IP_BAN_LIFT) { INFO1 ("lifting IP ban on client at %s", client->connection.ip); connection_release_banned_ip (client->connection.ip); client->flags &= ~CLIENT_IP_BAN_LIFT; } connection_close (&client->connection); if (client->parser) httpp_destroy (client->parser); global_lock (); global.clients--; stats_event_args (NULL, "clients", "%d", global.clients); config_clear_listener (client->server_conn); global_unlock (); /* we need to free client specific format data (if any) */ if (client->free_client_data) client->free_client_data (client); free(client->username); free(client->password); free(client); }
void client_destroy(client_t *client) { if (client == NULL) return; if (client->worker) { WARN0 ("client still on worker thread"); return; } /* release the buffer now, as the buffer could be on the source queue * and may of disappeared after auth completes */ if (client->refbuf) { refbuf_release (client->refbuf); client->refbuf = NULL; } if (client->flags & CLIENT_AUTHENTICATED) DEBUG1 ("client still in auth \"%s\"", httpp_getvar (client->parser, HTTPP_VAR_URI)); /* write log entry if ip is set (some things don't set it, like outgoing * slave requests */ if (client->respcode > 0 && client->parser) logging_access(client); if (client->flags & CLIENT_IP_BAN_LIFT) { INFO1 ("lifting IP ban on client at %s", client->connection.ip); connection_release_banned_ip (client->connection.ip); client->flags &= ~CLIENT_IP_BAN_LIFT; } if (client->parser) httpp_destroy (client->parser); /* we need to free client specific format data (if any) */ if (client->free_client_data) client->free_client_data (client); free(client->username); free(client->password); client->username = NULL; client->password = NULL; client->parser = NULL; client->respcode = 0; client->free_client_data = NULL; global_lock (); if (global.running != ICE_RUNNING || client->connection.error || (client->flags & CLIENT_KEEPALIVE) == 0 || client_connected (client) == 0) { global.clients--; stats_event_args (NULL, "clients", "%d", global.clients); config_clear_listener (client->server_conn); global_unlock (); connection_close (&client->connection); free(client); return; } global_unlock (); DEBUG0 ("keepalive detected, placing back onto worker"); client->counter = client->schedule_ms = timing_get_time(); client->connection.con_time = client->schedule_ms/1000; client->connection.discon.time = client->connection.con_time + 7; client->ops = &http_request_ops; client->flags = CLIENT_ACTIVE; client->shared_data = NULL; client->refbuf = NULL; client->pos = 0; client->intro_offset = client->connection.sent_bytes = 0; client_add_worker (client); }
void config_clear(ice_config_t *c) { ice_config_dir_t *dirnode, *nextdirnode; aliases *alias, *nextalias; int i; free(c->config_filename); xmlFree (c->server_id); if (c->location) xmlFree(c->location); if (c->admin) xmlFree(c->admin); if (c->source_password) xmlFree(c->source_password); if (c->admin_username) xmlFree(c->admin_username); if (c->admin_password) xmlFree(c->admin_password); if (c->relay_username) xmlFree(c->relay_username); if (c->relay_password) xmlFree(c->relay_password); if (c->hostname) xmlFree(c->hostname); if (c->base_dir) xmlFree(c->base_dir); if (c->log_dir) xmlFree(c->log_dir); if (c->webroot_dir) xmlFree(c->webroot_dir); if (c->adminroot_dir) xmlFree(c->adminroot_dir); if (c->cert_file) xmlFree(c->cert_file); if (c->pidfile) xmlFree(c->pidfile); if (c->banfile) xmlFree(c->banfile); if (c->allowfile) xmlFree (c->allowfile); if (c->agentfile) xmlFree (c->agentfile); if (c->playlist_log.name) xmlFree(c->playlist_log.name); if (c->access_log.name) xmlFree(c->access_log.name); if (c->error_log.name) xmlFree(c->error_log.name); if (c->access_log.exclude_ext) xmlFree (c->access_log.exclude_ext); if (c->shoutcast_mount) xmlFree(c->shoutcast_mount); global_lock(); while ((c->listen_sock = config_clear_listener (c->listen_sock))) ; global_unlock(); if (c->master_server) xmlFree(c->master_server); if (c->master_username) xmlFree(c->master_username); if (c->master_password) xmlFree(c->master_password); if (c->master_bind) xmlFree(c->master_bind); if (c->user) xmlFree(c->user); if (c->group) xmlFree(c->group); if (c->mimetypes_fn) xmlFree (c->mimetypes_fn); while (c->relay) c->relay = config_clear_relay (c->relay); while (c->redirect_hosts) c->redirect_hosts = config_clear_redirect (c->redirect_hosts); while (c->mounts) { mount_proxy *to_go = c->mounts; c->mounts = to_go->next; config_clear_mount (to_go); } alias = c->aliases; while(alias) { nextalias = alias->next; if (alias->source) xmlFree(alias->source); if (alias->destination) xmlFree(alias->destination); if (alias->bind_address) xmlFree(alias->bind_address); free(alias); alias = nextalias; } dirnode = c->dir_list; while(dirnode) { nextdirnode = dirnode->next; if (dirnode->host) xmlFree(dirnode->host); free(dirnode); dirnode = nextdirnode; } #ifdef USE_YP i = 0; while (i < c->num_yp_directories) { if (c->yp_url[i]) xmlFree (c->yp_url[i]); i++; } #endif memset(c, 0, sizeof(ice_config_t)); }
/* called when listening thread is not checking for incoming connections */ int connection_setup_sockets (ice_config_t *config) { int count = 0; listener_t *listener, **prev; free (banned_ip.filename); banned_ip.filename = NULL; free (allowed_ip.filename); allowed_ip.filename = NULL; global_lock(); if (global.serversock) { for (; count < global.server_sockets; count++) sock_close (global.serversock [count]); free (global.serversock); global.serversock = NULL; } if (config == NULL) { global_unlock(); return 0; } /* setup the banned/allowed IP filenames from the xml */ if (config->banfile) banned_ip.filename = strdup (config->banfile); if (config->allowfile) allowed_ip.filename = strdup (config->allowfile); count = 0; global.serversock = calloc (config->listen_sock_count, sizeof (sock_t)); listener = config->listen_sock; prev = &config->listen_sock; while (listener) { int successful = 0; do { sock_t sock = sock_get_server_socket (listener->port, listener->bind_address); if (sock == SOCK_ERROR) break; if (sock_listen (sock, ICE_LISTEN_QUEUE) == SOCK_ERROR) { sock_close (sock); break; } /* some win32 setups do not do TCP win scaling well, so allow an override */ if (listener->so_sndbuf) sock_set_send_buffer (sock, listener->so_sndbuf); sock_set_blocking (sock, 0); successful = 1; global.serversock [count] = sock; count++; } while(0); if (successful == 0) { if (listener->bind_address) ERROR2 ("Could not create listener socket on port %d bind %s", listener->port, listener->bind_address); else ERROR1 ("Could not create listener socket on port %d", listener->port); /* remove failed connection */ *prev = config_clear_listener (listener); listener = *prev; continue; } if (listener->bind_address) INFO2 ("listener socket on port %d address %s", listener->port, listener->bind_address); else INFO1 ("listener socket on port %d", listener->port); prev = &listener->next; listener = listener->next; } global.server_sockets = count; global_unlock(); if (count == 0) ERROR0 ("No listening sockets established"); return count; }
static void _parse_root(xmlDocPtr doc, xmlNodePtr node, ice_config_t *configuration) { char *tmp; configuration->listen_sock = acalloc (1, sizeof (*configuration->listen_sock)); configuration->listen_sock->port = 8000; configuration->listen_sock_count = 1; do { if (node == NULL) break; if (xmlIsBlankNode(node)) continue; if (xmlStrcmp (node->name, XMLSTR("location")) == 0) { if (configuration->location) xmlFree(configuration->location); configuration->location = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); } else if (xmlStrcmp (node->name, XMLSTR("admin")) == 0) { if (configuration->admin) xmlFree(configuration->admin); configuration->admin = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); } else if (xmlStrcmp (node->name, XMLSTR("server-id")) == 0) { xmlFree (configuration->server_id); configuration->server_id = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); } else if(xmlStrcmp (node->name, XMLSTR("authentication")) == 0) { _parse_authentication(doc, node->xmlChildrenNode, configuration); } else if (xmlStrcmp (node->name, XMLSTR("source-password")) == 0) { /* TODO: This is the backwards-compatibility location */ char *mount, *pass; if ((mount = (char *)xmlGetProp(node, XMLSTR("mount"))) != NULL) { pass = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); /* FIXME: This is a placeholder for per-mount passwords */ } else { if (configuration->source_password) xmlFree(configuration->source_password); configuration->source_password = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); } } else if (xmlStrcmp (node->name, XMLSTR("icelogin")) == 0) { tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); configuration->ice_login = atoi(tmp); if (tmp) xmlFree(tmp); } else if (xmlStrcmp (node->name, XMLSTR("fileserve")) == 0) { tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); configuration->fileserve = atoi(tmp); if (tmp) xmlFree(tmp); } else if (xmlStrcmp (node->name, XMLSTR("relays-on-demand")) == 0) { tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); configuration->on_demand = atoi(tmp); if (tmp) xmlFree(tmp); } else if (xmlStrcmp (node->name, XMLSTR("hostname")) == 0) { if (configuration->hostname) xmlFree(configuration->hostname); configuration->hostname = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); } else if (xmlStrcmp (node->name, XMLSTR("mime-types")) == 0) { if (configuration->mimetypes_fn) xmlFree(configuration->mimetypes_fn); configuration->mimetypes_fn = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); } else if (xmlStrcmp (node->name, XMLSTR("listen-socket")) == 0) { _parse_listen_socket(doc, node->xmlChildrenNode, configuration); } else if (xmlStrcmp (node->name, XMLSTR("port")) == 0) { tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); configuration->port = atoi(tmp); configuration->listen_sock->port = atoi(tmp); if (tmp) xmlFree(tmp); } else if (xmlStrcmp (node->name, XMLSTR("bind-address")) == 0) { if (configuration->listen_sock->bind_address) xmlFree(configuration->listen_sock->bind_address); configuration->listen_sock->bind_address = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); } else if (xmlStrcmp (node->name, XMLSTR("master-server")) == 0) { if (configuration->master_server) xmlFree(configuration->master_server); configuration->master_server = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); } else if (xmlStrcmp (node->name, XMLSTR("master-username")) == 0) { if (configuration->master_username) xmlFree(configuration->master_username); configuration->master_username = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); } else if (xmlStrcmp (node->name, XMLSTR("master-password")) == 0) { if (configuration->master_password) xmlFree(configuration->master_password); configuration->master_password = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); } else if (xmlStrcmp (node->name, XMLSTR("master-server-port")) == 0) { tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); configuration->master_server_port = atoi(tmp); xmlFree (tmp); } else if (xmlStrcmp (node->name, XMLSTR("master-update-interval")) == 0) { tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); configuration->master_update_interval = atoi(tmp); xmlFree (tmp); } else if (xmlStrcmp (node->name, XMLSTR("shoutcast-mount")) == 0) { if (configuration->shoutcast_mount) xmlFree(configuration->shoutcast_mount); configuration->shoutcast_mount = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); } else if (xmlStrcmp (node->name, XMLSTR("limits")) == 0) { _parse_limits(doc, node->xmlChildrenNode, configuration); } else if (xmlStrcmp (node->name, XMLSTR("relay")) == 0) { _parse_relay(doc, node->xmlChildrenNode, configuration); } else if (xmlStrcmp (node->name, XMLSTR("mount")) == 0) { _parse_mount(doc, node->xmlChildrenNode, configuration); } else if (xmlStrcmp (node->name, XMLSTR("directory")) == 0) { _parse_directory(doc, node->xmlChildrenNode, configuration); } else if (xmlStrcmp (node->name, XMLSTR("paths")) == 0) { _parse_paths(doc, node->xmlChildrenNode, configuration); } else if (xmlStrcmp (node->name, XMLSTR("logging")) == 0) { _parse_logging(doc, node->xmlChildrenNode, configuration); } else if (xmlStrcmp (node->name, XMLSTR("security")) == 0) { _parse_security(doc, node->xmlChildrenNode, configuration); } } while ((node = node->next)); /* drop the first listening socket details if more than one is defined, as we only * have port or listen-socket not both */ if (configuration->listen_sock_count > 1) { configuration->listen_sock = config_clear_listener (configuration->listen_sock); configuration->listen_sock_count--; } if (configuration->port == 0) configuration->port = 8000; }
void config_clear(ice_config_t *c) { ice_config_dir_t *dirnode, *nextdirnode; relay_server *relay, *nextrelay; mount_proxy *mount, *nextmount; aliases *alias, *nextalias; int i; free(c->config_filename); xmlFree (c->server_id); if (c->location) xmlFree(c->location); if (c->admin) xmlFree(c->admin); if (c->source_password) xmlFree(c->source_password); if (c->admin_username) xmlFree(c->admin_username); if (c->admin_password) xmlFree(c->admin_password); if (c->relay_username) xmlFree(c->relay_username); if (c->relay_password) xmlFree(c->relay_password); if (c->hostname) xmlFree(c->hostname); if (c->base_dir) xmlFree(c->base_dir); if (c->log_dir) xmlFree(c->log_dir); if (c->webroot_dir) xmlFree(c->webroot_dir); if (c->adminroot_dir) xmlFree(c->adminroot_dir); if (c->cert_file) xmlFree(c->cert_file); if (c->pidfile) xmlFree(c->pidfile); if (c->banfile) xmlFree(c->banfile); if (c->allowfile) xmlFree(c->allowfile); if (c->playlist_log) xmlFree(c->playlist_log); if (c->access_log) xmlFree(c->access_log); if (c->error_log) xmlFree(c->error_log); if (c->shoutcast_mount) xmlFree(c->shoutcast_mount); if (c->master_server) xmlFree(c->master_server); if (c->master_username) xmlFree(c->master_username); if (c->master_password) xmlFree(c->master_password); if (c->user) xmlFree(c->user); if (c->group) xmlFree(c->group); if (c->mimetypes_fn) xmlFree (c->mimetypes_fn); while ((c->listen_sock = config_clear_listener (c->listen_sock))) ; thread_mutex_lock(&(_locks.relay_lock)); relay = c->relay; while(relay) { nextrelay = relay->next; xmlFree(relay->server); xmlFree(relay->mount); xmlFree(relay->localmount); free(relay); relay = nextrelay; } thread_mutex_unlock(&(_locks.relay_lock)); mount = c->mounts; while(mount) { nextmount = mount->next; config_clear_mount (mount); mount = nextmount; } alias = c->aliases; while(alias) { nextalias = alias->next; xmlFree(alias->source); xmlFree(alias->destination); xmlFree(alias->bind_address); free(alias); alias = nextalias; } dirnode = c->dir_list; while(dirnode) { nextdirnode = dirnode->next; xmlFree(dirnode->host); free(dirnode); dirnode = nextdirnode; } #ifdef USE_YP i = 0; while (i < c->num_yp_directories) { xmlFree (c->yp_url[i]); i++; } #endif memset(c, 0, sizeof(ice_config_t)); }