static void test_buffer_to_lower_upper(void) { buffer *psrc = buffer_init(); buffer_copy_string_len(psrc, CONST_STR_LEN("0123456789abcdefghijklmnopqrstuvwxyz")); buffer_to_lower(psrc); assert(buffer_is_equal_string(psrc, CONST_STR_LEN("0123456789abcdefghijklmnopqrstuvwxyz"))); buffer_to_upper(psrc); assert(buffer_is_equal_string(psrc, CONST_STR_LEN("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"))); buffer_to_upper(psrc); assert(buffer_is_equal_string(psrc, CONST_STR_LEN("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"))); buffer_to_lower(psrc); assert(buffer_is_equal_string(psrc, CONST_STR_LEN("0123456789abcdefghijklmnopqrstuvwxyz"))); buffer_free(psrc); }
int config_set_defaults(server *srv) { size_t i; specific_config *s = srv->config_storage[0]; struct stat st1, st2; struct ev_map { fdevent_handler_t et; const char *name; } event_handlers[] = { /* - poll is most reliable * - select works everywhere * - linux-* are experimental */ #ifdef USE_POLL { FDEVENT_HANDLER_POLL, "poll" }, #endif #ifdef USE_SELECT { FDEVENT_HANDLER_SELECT, "select" }, #endif #ifdef USE_LINUX_EPOLL { FDEVENT_HANDLER_LINUX_SYSEPOLL, "linux-sysepoll" }, #endif #ifdef USE_LINUX_SIGIO { FDEVENT_HANDLER_LINUX_RTSIG, "linux-rtsig" }, #endif #ifdef USE_SOLARIS_DEVPOLL { FDEVENT_HANDLER_SOLARIS_DEVPOLL,"solaris-devpoll" }, #endif #ifdef USE_FREEBSD_KQUEUE { FDEVENT_HANDLER_FREEBSD_KQUEUE, "freebsd-kqueue" }, { FDEVENT_HANDLER_FREEBSD_KQUEUE, "kqueue" }, #endif { FDEVENT_HANDLER_UNSET, NULL } }; if (buffer_is_empty(s->document_root)) { log_error_write(srv, __FILE__, __LINE__, "s", "a default document-root has to be set"); return -1; } if (buffer_is_empty(srv->srvconf.changeroot)) { if (-1 == stat(s->document_root->ptr, &st1)) { log_error_write(srv, __FILE__, __LINE__, "sb", "base-docroot doesn't exist:", s->document_root); return -1; } } else { buffer_copy_string_buffer(srv->tmp_buf, srv->srvconf.changeroot); buffer_append_string_buffer(srv->tmp_buf, s->document_root); if (-1 == stat(srv->tmp_buf->ptr, &st1)) { log_error_write(srv, __FILE__, __LINE__, "sb", "base-docroot doesn't exist:", srv->tmp_buf); return -1; } } buffer_copy_string_buffer(srv->tmp_buf, s->document_root); buffer_to_lower(srv->tmp_buf); if (0 == stat(srv->tmp_buf->ptr, &st1)) { int is_lower = 0; is_lower = buffer_is_equal(srv->tmp_buf, s->document_root); /* lower-case existed, check upper-case */ buffer_copy_string_buffer(srv->tmp_buf, s->document_root); buffer_to_upper(srv->tmp_buf); /* we have to handle the special case that upper and lower-casing results in the same filename * as in server.document-root = "/" or "/12345/" */ if (is_lower && buffer_is_equal(srv->tmp_buf, s->document_root)) { /* lower-casing and upper-casing didn't result in * an other filename, no need to stat(), * just assume it is case-sensitive. */ s->force_lowercase_filenames = 0; } else if (0 == stat(srv->tmp_buf->ptr, &st2)) { /* upper case exists too, doesn't the FS handle this ? */ /* upper and lower have the same inode -> case-insensitve FS */ if (st1.st_ino == st2.st_ino) { /* upper and lower have the same inode -> case-insensitve FS */ s->force_lowercase_filenames = 1; } } } if (srv->srvconf.port == 0) { srv->srvconf.port = s->is_ssl ? 443 : 80; } if (srv->srvconf.event_handler->used == 0) { /* choose a good default * * the event_handler list is sorted by 'goodness' * taking the first available should be the best solution */ srv->event_handler = event_handlers[0].et; if (FDEVENT_HANDLER_UNSET == srv->event_handler) { log_error_write(srv, __FILE__, __LINE__, "s", "sorry, there is no event handler for this system"); return -1; } } else { /* * User override */ for (i = 0; event_handlers[i].name; i++) { if (0 == strcmp(event_handlers[i].name, srv->srvconf.event_handler->ptr)) { srv->event_handler = event_handlers[i].et; break; } } if (FDEVENT_HANDLER_UNSET == srv->event_handler) { log_error_write(srv, __FILE__, __LINE__, "sb", "the selected event-handler in unknown or not supported:", srv->srvconf.event_handler ); return -1; } } if (s->is_ssl) { if (buffer_is_empty(s->ssl_pemfile)) { /* PEM file is require */ log_error_write(srv, __FILE__, __LINE__, "s", "ssl.pemfile has to be set"); return -1; } #ifndef USE_OPENSSL log_error_write(srv, __FILE__, __LINE__, "s", "ssl support is missing, recompile with --with-openssl"); return -1; #endif } return 0; }
int config_set_defaults(server *srv) { specific_config *s = &srv->config_storage[0]; #if 0 size_t i; struct stat st1, st2; #endif if (buffer_is_empty(s->document_root)) { log_error_write(srv, __FILE__, __LINE__, "s", "a default document-root has to be set"); return -1; } #if 0 buffer_copy_string_buffer(srv->tmp_buf, s->document_root); buffer_to_lower(srv->tmp_buf); if (0 == stat(srv->tmp_buf->ptr, &st1)) { int is_lower = 0; is_lower = buffer_is_equal(srv->tmp_buf, s->document_root); /* lower-case existed, check upper-case */ buffer_copy_string_buffer(srv->tmp_buf, s->document_root); buffer_to_upper(srv->tmp_buf); /* we have to handle the special case that upper and lower-casing results in the same filename * as in server.document-root = "/" or "/12345/" */ if (is_lower && buffer_is_equal(srv->tmp_buf, s->document_root)) { /* lower-casing and upper-casing didn't result in * an other filename, no need to stat(), * just assume it is case-sensitive. */ s->force_lowercase_filenames = 0; } else if (0 == stat(srv->tmp_buf->ptr, &st2)) { /* upper case exists too, doesn't the FS handle this ? */ /* upper and lower have the same inode -> case-insensitve FS */ if (st1.st_ino == st2.st_ino) { /* upper and lower have the same inode -> case-insensitve FS */ s->force_lowercase_filenames = 1; } } } #endif if (srv->srvconf.port == 0) { srv->srvconf.port = s->is_ssl ? 322 : 554; } if (srv->srvconf.max_conns == 0) srv->srvconf.max_conns = 100; if (srv->srvconf.first_udp_port == 0) srv->srvconf.first_udp_port = RTP_DEFAULT_PORT; if (srv->srvconf.buffered_frames == 0) srv->srvconf.buffered_frames = BUFFERED_FRAMES_DEFAULT; if (s->is_ssl) { if (buffer_is_empty(s->ssl_pemfile)) { /* PEM file is require */ log_error_write(srv, __FILE__, __LINE__, "s", "ssl.pemfile has to be set"); return -1; } #ifndef USE_OPENSSL log_error_write(srv, __FILE__, __LINE__, "s", "ssl support is missing, recompile with --with-openssl"); return -1; #endif } return 0; }
int config_set_defaults(server *srv) { specific_config *s = srv->config_storage[0]; const fdevent_handler_info_t *handler; const network_backend_info_t *backend; struct stat st1, st2; if (buffer_is_empty(s->document_root)) { log_error_write(srv, __FILE__, __LINE__, "s", "a default document-root has to be set"); return -1; } if (buffer_is_empty(srv->srvconf.changeroot)) { pathname_unix2local(s->document_root); if (-1 == stat(s->document_root->ptr, &st1)) { log_error_write(srv, __FILE__, __LINE__, "sbs", "base-docroot doesn't exist:", s->document_root, strerror(errno)); return -1; } } else { buffer_copy_string_buffer(srv->tmp_buf, srv->srvconf.changeroot); buffer_append_string_buffer(srv->tmp_buf, s->document_root); if (-1 == stat(srv->tmp_buf->ptr, &st1)) { log_error_write(srv, __FILE__, __LINE__, "sb", "base-docroot doesn't exist:", srv->tmp_buf); return -1; } } buffer_copy_string_buffer(srv->tmp_buf, s->document_root); buffer_to_lower(srv->tmp_buf); if (0 == stat(srv->tmp_buf->ptr, &st1)) { int is_lower = 0; is_lower = buffer_is_equal(srv->tmp_buf, s->document_root); /* lower-case existed, check upper-case */ buffer_copy_string_buffer(srv->tmp_buf, s->document_root); buffer_to_upper(srv->tmp_buf); /* we have to handle the special case that upper and lower-casing results in the same filename * as in server.document-root = "/" or "/12345/" */ if (is_lower && buffer_is_equal(srv->tmp_buf, s->document_root)) { /* lower-casing and upper-casing didn't result in * an other filename, no need to stat(), * just assume it is case-sensitive. */ s->force_lowercase_filenames = 0; } else if (0 == stat(srv->tmp_buf->ptr, &st2)) { /* upper case exists too, doesn't the FS handle this ? */ /* upper and lower have the same inode -> case-insensitve FS */ if (st1.st_ino == st2.st_ino) { /* upper and lower have the same inode -> case-insensitve FS */ s->force_lowercase_filenames = 1; } } } if (srv->srvconf.port == 0) { srv->srvconf.port = s->is_ssl ? 443 : 80; } if (srv->srvconf.event_handler->used == 0) { /* get a useful default */ handler = fdevent_get_defaulthandler(); if (!handler) { log_error_write(srv, __FILE__, __LINE__, "s", "sorry, there is no event handler for this system"); return -1; } } else { /* * User override */ handler = fdevent_get_handler_info_by_name(srv->srvconf.event_handler->ptr); if (!handler) { log_error_write(srv, __FILE__, __LINE__, "sb", "the selected event-handler is unknown:", srv->srvconf.event_handler ); return -1; } if (!handler->init) { log_error_write(srv, __FILE__, __LINE__, "sb", "the selected event-handler is known but not supported:", srv->srvconf.event_handler ); return -1; } } srv->event_handler = handler->type; if (buffer_is_empty(srv->srvconf.network_backend)) { /* get a useful default */ backend = network_get_defaultbackend(); if (!backend) { log_error_write(srv, __FILE__, __LINE__, "s", "sorry, there is no network backend for this system"); return -1; } } else { /* * User override */ backend = network_get_backend_info_by_name(srv->srvconf.network_backend->ptr); if (!backend) { /* we don't know it */ log_error_write(srv, __FILE__, __LINE__, "sb", "server.network-backend has a unknown value:", srv->srvconf.network_backend); return -1; } if (backend->write_handler == NULL) { /* we know it but not supported */ log_error_write(srv, __FILE__, __LINE__, "sb", "server.network-backend not supported:", srv->srvconf.network_backend); return -1; } } srv->network_backend = backend->type; if (s->is_ssl) { if (buffer_is_empty(s->ssl_pemfile)) { /* PEM file is require */ log_error_write(srv, __FILE__, __LINE__, "s", "ssl.pemfile has to be set"); return -1; } #ifndef USE_OPENSSL log_error_write(srv, __FILE__, __LINE__, "s", "ssl support is missing, recompile with --with-openssl"); return -1; #endif } return 0; }