mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-09-06 21:51:30 +00:00
reindenting a bunch of messy files
This commit is contained in:
@@ -46,29 +46,29 @@ int bind_to_unix_dgram(char *socket_name) {
|
||||
socklen_t len;
|
||||
|
||||
serverfd = socket(AF_UNIX, SOCK_DGRAM, 0);
|
||||
if (serverfd < 0) {
|
||||
uwsgi_error("socket()");
|
||||
uwsgi_nuclear_blast();
|
||||
}
|
||||
if (serverfd < 0) {
|
||||
uwsgi_error("socket()");
|
||||
uwsgi_nuclear_blast();
|
||||
}
|
||||
|
||||
if (unlink(socket_name) != 0 && errno != ENOENT) {
|
||||
uwsgi_error("unlink()");
|
||||
}
|
||||
uwsgi_error("unlink()");
|
||||
}
|
||||
|
||||
uws_addr = uwsgi_calloc(sizeof(struct sockaddr_un));
|
||||
uws_addr->sun_family = AF_UNIX;
|
||||
uws_addr->sun_family = AF_UNIX;
|
||||
|
||||
memcpy(uws_addr->sun_path, socket_name, UMIN(strlen(socket_name), 102));
|
||||
len = strlen(socket_name);
|
||||
len = strlen(socket_name);
|
||||
|
||||
#ifdef __HAIKU__
|
||||
if (bind(serverfd, (struct sockaddr *) uws_addr, sizeof(struct sockaddr_un))) {
|
||||
#ifdef __HAIKU__
|
||||
if (bind(serverfd, (struct sockaddr *) uws_addr, sizeof(struct sockaddr_un))) {
|
||||
#else
|
||||
if (bind(serverfd, (struct sockaddr *) uws_addr, len + ((void *) uws_addr->sun_path - (void *) uws_addr)) != 0) {
|
||||
if (bind(serverfd, (struct sockaddr *) uws_addr, len + ((void *) uws_addr->sun_path - (void *) uws_addr)) != 0) {
|
||||
#endif
|
||||
uwsgi_error("bind()");
|
||||
uwsgi_nuclear_blast();
|
||||
}
|
||||
uwsgi_error("bind()");
|
||||
uwsgi_nuclear_blast();
|
||||
}
|
||||
|
||||
return serverfd;
|
||||
}
|
||||
@@ -199,9 +199,9 @@ int bind_to_udp(char *socket_name, int multicast, int broadcast) {
|
||||
if (!broadcast && !multicast) {
|
||||
char quad[4];
|
||||
char *first_part = strchr(socket_name, '.');
|
||||
if (first_part && first_part-socket_name < 4) {
|
||||
if (first_part && first_part - socket_name < 4) {
|
||||
memset(quad, 0, 4);
|
||||
memcpy(quad, socket_name, first_part-socket_name);
|
||||
memcpy(quad, socket_name, first_part - socket_name);
|
||||
if (atoi(quad) >= 224 && atoi(quad) <= 239) {
|
||||
multicast = 1;
|
||||
}
|
||||
@@ -626,18 +626,18 @@ void uwsgi_socket_nb(int fd) {
|
||||
|
||||
// set blocking socket
|
||||
void uwsgi_socket_b(int fd) {
|
||||
int arg;
|
||||
int arg;
|
||||
|
||||
arg = fcntl(fd, F_GETFL, NULL);
|
||||
if (arg < 0) {
|
||||
uwsgi_error("fcntl()");
|
||||
return;
|
||||
}
|
||||
arg = fcntl(fd, F_GETFL, NULL);
|
||||
if (arg < 0) {
|
||||
uwsgi_error("fcntl()");
|
||||
return;
|
||||
}
|
||||
arg &= (~O_NONBLOCK);
|
||||
if (fcntl(fd, F_SETFL, arg) < 0) {
|
||||
uwsgi_error("fcntl()");
|
||||
return;
|
||||
}
|
||||
if (fcntl(fd, F_SETFL, arg) < 0) {
|
||||
uwsgi_error("fcntl()");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -832,7 +832,7 @@ struct uwsgi_socket *uwsgi_new_socket(char *name) {
|
||||
}
|
||||
|
||||
if (!uwsgi_startswith(name, "fd://", 5)) {
|
||||
uwsgi_add_socket_from_fd(uwsgi_sock, atoi(name+5));
|
||||
uwsgi_add_socket_from_fd(uwsgi_sock, atoi(name + 5));
|
||||
return uwsgi_sock;
|
||||
}
|
||||
|
||||
@@ -911,15 +911,15 @@ void uwsgi_add_socket_from_fd(struct uwsgi_socket *uwsgi_sock, int fd) {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!uwsgi_startswith(uwsgi_sock->name, "fd://", 5)) {
|
||||
if (atoi(uwsgi_sock->name+5) == fd) {
|
||||
uwsgi_sock->fd = fd;
|
||||
uwsgi_sock->family = AF_UNIX;
|
||||
uwsgi_sock->bound = 1;
|
||||
uwsgi_sock->name = uwsgi_str(usa.sa_un.sun_path + abstract);
|
||||
uwsgi_log("uwsgi socket %d inherited UNIX address %s fd %d\n", uwsgi_get_socket_num(uwsgi_sock), uwsgi_sock->name, uwsgi_sock->fd);
|
||||
}
|
||||
}
|
||||
if (!uwsgi_startswith(uwsgi_sock->name, "fd://", 5)) {
|
||||
if (atoi(uwsgi_sock->name + 5) == fd) {
|
||||
uwsgi_sock->fd = fd;
|
||||
uwsgi_sock->family = AF_UNIX;
|
||||
uwsgi_sock->bound = 1;
|
||||
uwsgi_sock->name = uwsgi_str(usa.sa_un.sun_path + abstract);
|
||||
uwsgi_log("uwsgi socket %d inherited UNIX address %s fd %d\n", uwsgi_get_socket_num(uwsgi_sock), uwsgi_sock->name, uwsgi_sock->fd);
|
||||
}
|
||||
}
|
||||
else if (!strcmp(usa.sa_un.sun_path + abstract, uwsgi_sock->name + abstract)) {
|
||||
uwsgi_sock->fd = fd;
|
||||
uwsgi_sock->family = AF_UNIX;
|
||||
@@ -969,19 +969,19 @@ void uwsgi_add_socket_from_fd(struct uwsgi_socket *uwsgi_sock, int fd) {
|
||||
asterisk[0] = '*';
|
||||
}
|
||||
else {
|
||||
if (!uwsgi_startswith(uwsgi_sock->name, "fd://", 5)) {
|
||||
if (atoi(uwsgi_sock->name+5) == fd) {
|
||||
uwsgi_sock->fd = fd;
|
||||
uwsgi_sock->family = AF_INET;
|
||||
uwsgi_sock->bound = 1;
|
||||
uwsgi_sock->name = uwsgi_str(computed_addr);
|
||||
uwsgi_log("uwsgi socket %d inherited INET address %s fd %d\n", uwsgi_get_socket_num(uwsgi_sock), uwsgi_sock->name, uwsgi_sock->fd);
|
||||
match = 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
match = strcmp(computed_addr, uwsgi_sock->name);
|
||||
}
|
||||
if (!uwsgi_startswith(uwsgi_sock->name, "fd://", 5)) {
|
||||
if (atoi(uwsgi_sock->name + 5) == fd) {
|
||||
uwsgi_sock->fd = fd;
|
||||
uwsgi_sock->family = AF_INET;
|
||||
uwsgi_sock->bound = 1;
|
||||
uwsgi_sock->name = uwsgi_str(computed_addr);
|
||||
uwsgi_log("uwsgi socket %d inherited INET address %s fd %d\n", uwsgi_get_socket_num(uwsgi_sock), uwsgi_sock->name, uwsgi_sock->fd);
|
||||
match = 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
match = strcmp(computed_addr, uwsgi_sock->name);
|
||||
}
|
||||
}
|
||||
if (!match) {
|
||||
uwsgi_sock->fd = fd;
|
||||
@@ -995,63 +995,63 @@ void uwsgi_add_socket_from_fd(struct uwsgi_socket *uwsgi_sock, int fd) {
|
||||
}
|
||||
#ifdef UWSGI_IPV6
|
||||
else if (gsa.sa->sa_family == AF_INET6) {
|
||||
char *computed_addr;
|
||||
char computed_port[6];
|
||||
isa.sa_in6 = (struct sockaddr_in6 *) &usa;
|
||||
char ipv6a[INET6_ADDRSTRLEN + 1];
|
||||
memset(ipv6a, 0, INET_ADDRSTRLEN + 1);
|
||||
memset(computed_port, 0, 6);
|
||||
char *computed_addr;
|
||||
char computed_port[6];
|
||||
isa.sa_in6 = (struct sockaddr_in6 *) &usa;
|
||||
char ipv6a[INET6_ADDRSTRLEN + 1];
|
||||
memset(ipv6a, 0, INET_ADDRSTRLEN + 1);
|
||||
memset(computed_port, 0, 6);
|
||||
int match = 0;
|
||||
|
||||
|
||||
if (snprintf(computed_port, 6, "%d", ntohs(isa.sa_in6->sin6_port)) > 0) {
|
||||
if (inet_ntop(AF_INET6, (const void *) &isa.sa_in6->sin6_addr.s6_addr, ipv6a, INET6_ADDRSTRLEN)) {
|
||||
if (snprintf(computed_port, 6, "%d", ntohs(isa.sa_in6->sin6_port)) > 0) {
|
||||
if (inet_ntop(AF_INET6, (const void *) &isa.sa_in6->sin6_addr.s6_addr, ipv6a, INET6_ADDRSTRLEN)) {
|
||||
uwsgi_log("ipv6a = %s\n", ipv6a);
|
||||
if (!strcmp("::", ipv6a)) {
|
||||
computed_addr = uwsgi_concat2("[::]:", computed_port);
|
||||
}
|
||||
else {
|
||||
computed_addr = uwsgi_concat4("[", ipv6a, "]:", computed_port);
|
||||
}
|
||||
// is it a zerg ?
|
||||
if (uwsgi_sock->name == NULL) {
|
||||
uwsgi_sock->fd = fd;
|
||||
uwsgi_sock->family = AF_INET6;
|
||||
uwsgi_sock->bound = 1;
|
||||
uwsgi_sock->name = uwsgi_concat2(computed_addr, "");
|
||||
if (uwsgi.zerg) {
|
||||
uwsgi_log("uwsgi zerg socket %d attached to INET6 address %s fd %d\n", uwsgi_get_socket_num(uwsgi_sock), computed_addr, uwsgi_sock->fd);
|
||||
}
|
||||
else {
|
||||
uwsgi_log("uwsgi socket %d attached to INET6 address %s fd %d\n", uwsgi_get_socket_num(uwsgi_sock), computed_addr, uwsgi_sock->fd);
|
||||
}
|
||||
free(computed_addr);
|
||||
return;
|
||||
}
|
||||
if (!strcmp("::", ipv6a)) {
|
||||
computed_addr = uwsgi_concat2("[::]:", computed_port);
|
||||
}
|
||||
else {
|
||||
computed_addr = uwsgi_concat4("[", ipv6a, "]:", computed_port);
|
||||
}
|
||||
// is it a zerg ?
|
||||
if (uwsgi_sock->name == NULL) {
|
||||
uwsgi_sock->fd = fd;
|
||||
uwsgi_sock->family = AF_INET6;
|
||||
uwsgi_sock->bound = 1;
|
||||
uwsgi_sock->name = uwsgi_concat2(computed_addr, "");
|
||||
if (uwsgi.zerg) {
|
||||
uwsgi_log("uwsgi zerg socket %d attached to INET6 address %s fd %d\n", uwsgi_get_socket_num(uwsgi_sock), computed_addr, uwsgi_sock->fd);
|
||||
}
|
||||
else {
|
||||
uwsgi_log("uwsgi socket %d attached to INET6 address %s fd %d\n", uwsgi_get_socket_num(uwsgi_sock), computed_addr, uwsgi_sock->fd);
|
||||
}
|
||||
free(computed_addr);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!uwsgi_startswith(uwsgi_sock->name, "fd://", 5)) {
|
||||
if (atoi(uwsgi_sock->name+5) == fd) {
|
||||
uwsgi_sock->fd = fd;
|
||||
uwsgi_sock->family = AF_INET6;
|
||||
uwsgi_sock->bound = 1;
|
||||
uwsgi_sock->name = uwsgi_str(computed_addr);
|
||||
uwsgi_log("uwsgi socket %d inherited INET address %s fd %d\n", uwsgi_get_socket_num(uwsgi_sock), uwsgi_sock->name, uwsgi_sock->fd);
|
||||
match = 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
match = strcmp(computed_addr, uwsgi_sock->name);
|
||||
}
|
||||
if (!uwsgi_startswith(uwsgi_sock->name, "fd://", 5)) {
|
||||
if (atoi(uwsgi_sock->name + 5) == fd) {
|
||||
uwsgi_sock->fd = fd;
|
||||
uwsgi_sock->family = AF_INET6;
|
||||
uwsgi_sock->bound = 1;
|
||||
uwsgi_sock->name = uwsgi_str(computed_addr);
|
||||
uwsgi_log("uwsgi socket %d inherited INET address %s fd %d\n", uwsgi_get_socket_num(uwsgi_sock), uwsgi_sock->name, uwsgi_sock->fd);
|
||||
match = 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
match = strcmp(computed_addr, uwsgi_sock->name);
|
||||
}
|
||||
|
||||
if (!match) {
|
||||
uwsgi_sock->fd = fd;
|
||||
uwsgi_sock->family = AF_INET;
|
||||
uwsgi_sock->bound = 1;
|
||||
uwsgi_log("uwsgi socket %d inherited INET6 address %s fd %d\n", uwsgi_get_socket_num(uwsgi_sock), uwsgi_sock->name, uwsgi_sock->fd);
|
||||
}
|
||||
free(computed_addr);
|
||||
}
|
||||
}
|
||||
if (!match) {
|
||||
uwsgi_sock->fd = fd;
|
||||
uwsgi_sock->family = AF_INET;
|
||||
uwsgi_sock->bound = 1;
|
||||
uwsgi_log("uwsgi socket %d inherited INET6 address %s fd %d\n", uwsgi_get_socket_num(uwsgi_sock), uwsgi_sock->name, uwsgi_sock->fd);
|
||||
}
|
||||
free(computed_addr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1181,7 +1181,8 @@ void uwsgi_del_sockets_from_queue(int queue) {
|
||||
|
||||
struct uwsgi_socket *uwsgi_sock = uwsgi.sockets;
|
||||
while (uwsgi_sock) {
|
||||
if (uwsgi_sock->fd == -1) goto nextsock;
|
||||
if (uwsgi_sock->fd == -1)
|
||||
goto nextsock;
|
||||
event_queue_del_fd(queue, uwsgi_sock->fd, event_queue_read());
|
||||
nextsock:
|
||||
uwsgi_sock = uwsgi_sock->next;
|
||||
@@ -1204,7 +1205,7 @@ int uwsgi_is_bad_connection(int fd) {
|
||||
|
||||
int uwsgi_socket_is_already_bound(char *name) {
|
||||
struct uwsgi_socket *uwsgi_sock = uwsgi.sockets;
|
||||
while(uwsgi_sock) {
|
||||
while (uwsgi_sock) {
|
||||
if (uwsgi_sock->name && !strcmp(uwsgi_sock->name, name) && uwsgi_sock->bound) {
|
||||
return 1;
|
||||
}
|
||||
@@ -1216,16 +1217,18 @@ int uwsgi_socket_is_already_bound(char *name) {
|
||||
int uwsgi_socket_uniq(struct uwsgi_socket *list, struct uwsgi_socket *item) {
|
||||
int found = 0;
|
||||
|
||||
if (list == item) return 0;
|
||||
if (list == item)
|
||||
return 0;
|
||||
struct uwsgi_socket *uwsgi_sock = list;
|
||||
while(uwsgi_sock && uwsgi_sock != item) {
|
||||
if (uwsgi_sock->fd == -1) goto nextsock;
|
||||
while (uwsgi_sock && uwsgi_sock != item) {
|
||||
if (uwsgi_sock->fd == -1)
|
||||
goto nextsock;
|
||||
if (!strcmp(uwsgi_sock->name, item->name)) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
nextsock:
|
||||
uwsgi_sock = uwsgi_sock->next;
|
||||
uwsgi_sock = uwsgi_sock->next;
|
||||
}
|
||||
return found;
|
||||
}
|
||||
@@ -1275,7 +1278,8 @@ void uwsgi_manage_zerg(int fd, int num_sockets, int *sockets) {
|
||||
struct uwsgi_socket *uwsgi_sock = uwsgi.sockets;
|
||||
int uniq_count = 0;
|
||||
while (uwsgi_sock) {
|
||||
if (uwsgi_sock->fd == -1) goto nextsock;
|
||||
if (uwsgi_sock->fd == -1)
|
||||
goto nextsock;
|
||||
if (!uwsgi_socket_uniq(uwsgi.sockets, uwsgi_sock)) {
|
||||
memcpy(zerg_fd_ptr, &uwsgi_sock->fd, sizeof(int));
|
||||
zerg_fd_ptr += sizeof(int);
|
||||
@@ -1305,117 +1309,117 @@ nextsock:
|
||||
#ifdef UWSGI_IPV6
|
||||
int bind_to_tcp6(char *socket_name, int listen_queue, char *tcp_port) {
|
||||
|
||||
int serverfd;
|
||||
struct sockaddr_in6 uws_addr;
|
||||
int reuse = 1;
|
||||
int serverfd;
|
||||
struct sockaddr_in6 uws_addr;
|
||||
int reuse = 1;
|
||||
|
||||
socket_to_in_addr6(socket_name, tcp_port, 0, &uws_addr);
|
||||
socket_to_in_addr6(socket_name, tcp_port, 0, &uws_addr);
|
||||
|
||||
serverfd = socket(AF_INET6, SOCK_STREAM, 0);
|
||||
if (serverfd < 0) {
|
||||
uwsgi_error("socket()");
|
||||
uwsgi_nuclear_blast();
|
||||
}
|
||||
serverfd = socket(AF_INET6, SOCK_STREAM, 0);
|
||||
if (serverfd < 0) {
|
||||
uwsgi_error("socket()");
|
||||
uwsgi_nuclear_blast();
|
||||
}
|
||||
|
||||
if (setsockopt(serverfd, SOL_SOCKET, SO_REUSEADDR, (const void *) &reuse, sizeof(int)) < 0) {
|
||||
uwsgi_error("setsockopt()");
|
||||
uwsgi_nuclear_blast();
|
||||
}
|
||||
if (setsockopt(serverfd, SOL_SOCKET, SO_REUSEADDR, (const void *) &reuse, sizeof(int)) < 0) {
|
||||
uwsgi_error("setsockopt()");
|
||||
uwsgi_nuclear_blast();
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
#ifdef IP_FREEBIND
|
||||
if (uwsgi.freebind) {
|
||||
if (setsockopt(serverfd, SOL_IP, IP_FREEBIND, (const void *) &uwsgi.freebind, sizeof(int)) < 0) {
|
||||
uwsgi_error("setsockopt()");
|
||||
uwsgi_nuclear_blast();
|
||||
}
|
||||
}
|
||||
if (uwsgi.freebind) {
|
||||
if (setsockopt(serverfd, SOL_IP, IP_FREEBIND, (const void *) &uwsgi.freebind, sizeof(int)) < 0) {
|
||||
uwsgi_error("setsockopt()");
|
||||
uwsgi_nuclear_blast();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (uwsgi.reuse_port) {
|
||||
if (uwsgi.reuse_port) {
|
||||
#ifdef SO_REUSEPORT
|
||||
if (setsockopt(serverfd, SOL_SOCKET, SO_REUSEPORT, (const void *) &uwsgi.reuse_port, sizeof(int)) < 0) {
|
||||
uwsgi_error("setsockopt()");
|
||||
uwsgi_nuclear_blast();
|
||||
}
|
||||
if (setsockopt(serverfd, SOL_SOCKET, SO_REUSEPORT, (const void *) &uwsgi.reuse_port, sizeof(int)) < 0) {
|
||||
uwsgi_error("setsockopt()");
|
||||
uwsgi_nuclear_blast();
|
||||
}
|
||||
#else
|
||||
uwsgi_log("!!! your system does not support SO_REUSEPORT !!!\n");
|
||||
uwsgi_log("!!! your system does not support SO_REUSEPORT !!!\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (!uwsgi.no_defer_accept) {
|
||||
if (!uwsgi.no_defer_accept) {
|
||||
|
||||
#ifdef __linux__
|
||||
if (setsockopt(serverfd, IPPROTO_TCP, TCP_DEFER_ACCEPT, &uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], sizeof(int))) {
|
||||
uwsgi_error("setsockopt()");
|
||||
}
|
||||
// OSX has no SO_ACCEPTFILTER !!!
|
||||
if (setsockopt(serverfd, IPPROTO_TCP, TCP_DEFER_ACCEPT, &uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], sizeof(int))) {
|
||||
uwsgi_error("setsockopt()");
|
||||
}
|
||||
// OSX has no SO_ACCEPTFILTER !!!
|
||||
#elif defined(__freebsd__)
|
||||
struct accept_filter_arg afa;
|
||||
strcpy(afa.af_name, "dataready");
|
||||
afa.af_arg[0] = 0;
|
||||
if (setsockopt(serverfd, SOL_SOCKET, SO_ACCEPTFILTER, &afa, sizeof(struct accept_filter_arg))) {
|
||||
uwsgi_error("setsockopt()");
|
||||
}
|
||||
struct accept_filter_arg afa;
|
||||
strcpy(afa.af_name, "dataready");
|
||||
afa.af_arg[0] = 0;
|
||||
if (setsockopt(serverfd, SOL_SOCKET, SO_ACCEPTFILTER, &afa, sizeof(struct accept_filter_arg))) {
|
||||
uwsgi_error("setsockopt()");
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (bind(serverfd, (struct sockaddr *) &uws_addr, sizeof(uws_addr)) != 0) {
|
||||
if (errno == EADDRINUSE) {
|
||||
uwsgi_log("probably another instance of uWSGI is running on the same address.\n");
|
||||
}
|
||||
uwsgi_error("bind()");
|
||||
uwsgi_nuclear_blast();
|
||||
}
|
||||
if (bind(serverfd, (struct sockaddr *) &uws_addr, sizeof(uws_addr)) != 0) {
|
||||
if (errno == EADDRINUSE) {
|
||||
uwsgi_log("probably another instance of uWSGI is running on the same address.\n");
|
||||
}
|
||||
uwsgi_error("bind()");
|
||||
uwsgi_nuclear_blast();
|
||||
}
|
||||
|
||||
if (listen(serverfd, listen_queue) != 0) {
|
||||
uwsgi_error("listen()");
|
||||
uwsgi_nuclear_blast();
|
||||
}
|
||||
if (listen(serverfd, listen_queue) != 0) {
|
||||
uwsgi_error("listen()");
|
||||
uwsgi_nuclear_blast();
|
||||
}
|
||||
|
||||
|
||||
if (tcp_port)
|
||||
tcp_port[0] = ':';
|
||||
if (tcp_port)
|
||||
tcp_port[0] = ':';
|
||||
|
||||
return serverfd;
|
||||
return serverfd;
|
||||
}
|
||||
|
||||
socklen_t socket_to_in_addr6(char *socket_name, char *port, int portn, struct sockaddr_in6 *sin_addr) {
|
||||
socklen_t socket_to_in_addr6(char *socket_name, char *port, int portn, struct sockaddr_in6 * sin_addr) {
|
||||
|
||||
memset(sin_addr, 0, sizeof(struct sockaddr_in6));
|
||||
memset(sin_addr, 0, sizeof(struct sockaddr_in6));
|
||||
|
||||
sin_addr->sin6_family = AF_INET6;
|
||||
if (port) {
|
||||
*port = 0;
|
||||
sin_addr->sin6_port = htons(atoi(port + 1));
|
||||
}
|
||||
else {
|
||||
sin_addr->sin6_port = htons(portn);
|
||||
}
|
||||
sin_addr->sin6_family = AF_INET6;
|
||||
if (port) {
|
||||
*port = 0;
|
||||
sin_addr->sin6_port = htons(atoi(port + 1));
|
||||
}
|
||||
else {
|
||||
sin_addr->sin6_port = htons(portn);
|
||||
}
|
||||
|
||||
if ( !strcmp(socket_name, "[::]") ) {
|
||||
sin_addr->sin6_addr = in6addr_any;
|
||||
}
|
||||
else {
|
||||
char *sanitized_sn = uwsgi_concat2n(socket_name+1, strlen(socket_name+1)-1, "", 0);
|
||||
char *resolved = uwsgi_resolve_ip(sanitized_sn);
|
||||
if (resolved) {
|
||||
if (!strcmp(socket_name, "[::]")) {
|
||||
sin_addr->sin6_addr = in6addr_any;
|
||||
}
|
||||
else {
|
||||
char *sanitized_sn = uwsgi_concat2n(socket_name + 1, strlen(socket_name + 1) - 1, "", 0);
|
||||
char *resolved = uwsgi_resolve_ip(sanitized_sn);
|
||||
if (resolved) {
|
||||
inet_pton(AF_INET6, resolved, sin_addr->sin6_addr.s6_addr);
|
||||
}
|
||||
else {
|
||||
}
|
||||
else {
|
||||
inet_pton(AF_INET6, sanitized_sn, sin_addr->sin6_addr.s6_addr);
|
||||
}
|
||||
}
|
||||
free(sanitized_sn);
|
||||
}
|
||||
}
|
||||
|
||||
if (port) {
|
||||
*port = ':';
|
||||
}
|
||||
if (port) {
|
||||
*port = ':';
|
||||
}
|
||||
|
||||
return sizeof(struct sockaddr_in6);
|
||||
return sizeof(struct sockaddr_in6);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -400,7 +400,7 @@ void internal_server_error(struct wsgi_request *wsgi_req, char *message) {
|
||||
|
||||
struct uwsgi_string_list *uwsgi_string_list_has_item(struct uwsgi_string_list *list, char *key, size_t keylen) {
|
||||
struct uwsgi_string_list *usl = list;
|
||||
while(usl) {
|
||||
while (usl) {
|
||||
if (keylen == usl->len) {
|
||||
if (!memcmp(key, usl->value, keylen)) {
|
||||
return usl;
|
||||
@@ -2271,9 +2271,9 @@ char *uwsgi_resolve_ip(char *domain) {
|
||||
he = gethostbyname(domain);
|
||||
if (!he || !*he->h_addr_list || (he->h_addrtype != AF_INET
|
||||
#ifdef UWSGI_IPV6
|
||||
&& he->h_addrtype != AF_INET6
|
||||
&& he->h_addrtype != AF_INET6
|
||||
#endif
|
||||
)) {
|
||||
)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -4388,7 +4388,7 @@ void uwsgi_ssl_info_cb(SSL const *ssl, int where, int ret) {
|
||||
}
|
||||
}
|
||||
|
||||
int uwsgi_ssl_verify_callback(int ok, X509_STORE_CTX *x509_store) {
|
||||
int uwsgi_ssl_verify_callback(int ok, X509_STORE_CTX * x509_store) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -4457,12 +4457,12 @@ SSL_CTX *uwsgi_ssl_new_server_context(char *name, char *crt, char *key, char *ci
|
||||
|
||||
// set session context (if possibile), this is required for client certificate authentication
|
||||
if (name) {
|
||||
SSL_CTX_set_session_id_context(ctx, (unsigned char *)name, strlen(name));
|
||||
SSL_CTX_set_session_id_context(ctx, (unsigned char *) name, strlen(name));
|
||||
}
|
||||
|
||||
if (client_ca) {
|
||||
if (client_ca[0] == '!') {
|
||||
SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT, uwsgi_ssl_verify_callback);
|
||||
SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, uwsgi_ssl_verify_callback);
|
||||
client_ca++;
|
||||
}
|
||||
else {
|
||||
@@ -4473,8 +4473,8 @@ SSL_CTX *uwsgi_ssl_new_server_context(char *name, char *crt, char *key, char *ci
|
||||
if (SSL_CTX_load_verify_locations(ctx, client_ca, NULL) == 0) {
|
||||
uwsgi_log("unable to set ssl verify locations for: %s\n", client_ca);
|
||||
exit(1);
|
||||
}
|
||||
STACK_OF(X509_NAME) *list = SSL_load_client_CA_file(client_ca);
|
||||
}
|
||||
STACK_OF(X509_NAME) * list = SSL_load_client_CA_file(client_ca);
|
||||
if (!list) {
|
||||
uwsgi_log("unable to load client CA certificate: %s\n", client_ca);
|
||||
exit(1);
|
||||
@@ -4507,8 +4507,8 @@ char *uwsgi_rsa_sign(char *algo_key, char *message, size_t message_len, unsigned
|
||||
|
||||
// openssl could not be initialized
|
||||
if (!uwsgi.ssl_initialized) {
|
||||
uwsgi_ssl_init();
|
||||
}
|
||||
uwsgi_ssl_init();
|
||||
}
|
||||
|
||||
*s_len = 0;
|
||||
EVP_PKEY *pk = NULL;
|
||||
@@ -4522,10 +4522,10 @@ char *uwsgi_rsa_sign(char *algo_key, char *message, size_t message_len, unsigned
|
||||
}
|
||||
|
||||
*colon = 0;
|
||||
char *keyfile = colon+1;
|
||||
char *keyfile = colon + 1;
|
||||
char *signature = NULL;
|
||||
|
||||
FILE *kf = fopen(keyfile,"r");
|
||||
FILE *kf = fopen(keyfile, "r");
|
||||
if (!kf) {
|
||||
uwsgi_error_open(keyfile);
|
||||
free(algo);
|
||||
@@ -4584,26 +4584,32 @@ char *uwsgi_rsa_sign(char *algo_key, char *message, size_t message_len, unsigned
|
||||
*s_len = 0;
|
||||
goto clear;
|
||||
}
|
||||
|
||||
|
||||
clear:
|
||||
free(algo);
|
||||
EVP_PKEY_free(pk);
|
||||
EVP_MD_CTX_destroy(ctx);
|
||||
return signature;
|
||||
|
||||
|
||||
}
|
||||
|
||||
char *uwsgi_sanitize_cert_filename(char *base, char *key, uint16_t keylen) {
|
||||
uint16_t i;
|
||||
char *filename = uwsgi_concat4n(base, strlen(base), "/", 1, key, keylen, ".pem\0", 5);
|
||||
|
||||
for(i=strlen(base)+1;i<(strlen(base)+1)+keylen;i++) {
|
||||
if (filename[i] >= '0' && filename[i] <= '9') continue;
|
||||
if (filename[i] >= 'A' && filename[i] <= 'Z') continue;
|
||||
if (filename[i] >= 'a' && filename[i] <= 'z') continue;
|
||||
if (filename[i] == '.') continue;
|
||||
if (filename[i] == '-') continue;
|
||||
if (filename[i] == '_') continue;
|
||||
for (i = strlen(base) + 1; i < (strlen(base) + 1) + keylen; i++) {
|
||||
if (filename[i] >= '0' && filename[i] <= '9')
|
||||
continue;
|
||||
if (filename[i] >= 'A' && filename[i] <= 'Z')
|
||||
continue;
|
||||
if (filename[i] >= 'a' && filename[i] <= 'z')
|
||||
continue;
|
||||
if (filename[i] == '.')
|
||||
continue;
|
||||
if (filename[i] == '-')
|
||||
continue;
|
||||
if (filename[i] == '_')
|
||||
continue;
|
||||
filename[i] = '_';
|
||||
}
|
||||
|
||||
|
||||
@@ -464,7 +464,8 @@ void show_config(void) {
|
||||
int uwsgi_manage_custom_option(struct uwsgi_custom_option *uco, char *key, char *value) {
|
||||
size_t i, count = 1;
|
||||
size_t value_len = 0;
|
||||
if (value) value_len = strlen(value);
|
||||
if (value)
|
||||
value_len = strlen(value);
|
||||
off_t pos = 0;
|
||||
char **opt_argv;
|
||||
char *tmp_val = NULL, *p = NULL;
|
||||
@@ -1517,7 +1518,7 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
|
||||
#ifdef UWSGI_SSL
|
||||
// 1 day of tolerance
|
||||
uwsgi.subscriptions_sign_check_tolerance = 3600 * 24 ;
|
||||
uwsgi.subscriptions_sign_check_tolerance = 3600 * 24;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1867,18 +1868,18 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
#ifdef UWSGI_IPV6
|
||||
if (shared_sock->name[0] == '[' && tcp_port[-1] == ']') {
|
||||
shared_sock->fd = bind_to_tcp6(shared_sock->name, uwsgi.listen_queue, tcp_port);
|
||||
shared_sock->family = AF_INET6;
|
||||
// fix socket name
|
||||
shared_sock->name = uwsgi_getsockname(shared_sock->fd);
|
||||
uwsgi_log("uwsgi shared socket %d bound to TCP6 address %s fd %d\n", uwsgi_get_shared_socket_num(shared_sock), shared_sock->name, shared_sock->fd);
|
||||
shared_sock->family = AF_INET6;
|
||||
// fix socket name
|
||||
shared_sock->name = uwsgi_getsockname(shared_sock->fd);
|
||||
uwsgi_log("uwsgi shared socket %d bound to TCP6 address %s fd %d\n", uwsgi_get_shared_socket_num(shared_sock), shared_sock->name, shared_sock->fd);
|
||||
}
|
||||
else {
|
||||
#endif
|
||||
shared_sock->fd = bind_to_tcp(shared_sock->name, uwsgi.listen_queue, tcp_port);
|
||||
shared_sock->family = AF_INET;
|
||||
// fix socket name
|
||||
shared_sock->name = uwsgi_getsockname(shared_sock->fd);
|
||||
uwsgi_log("uwsgi shared socket %d bound to TCP address %s fd %d\n", uwsgi_get_shared_socket_num(shared_sock), shared_sock->name, shared_sock->fd);
|
||||
shared_sock->fd = bind_to_tcp(shared_sock->name, uwsgi.listen_queue, tcp_port);
|
||||
shared_sock->family = AF_INET;
|
||||
// fix socket name
|
||||
shared_sock->name = uwsgi_getsockname(shared_sock->fd);
|
||||
uwsgi_log("uwsgi shared socket %d bound to TCP address %s fd %d\n", uwsgi_get_shared_socket_num(shared_sock), shared_sock->name, shared_sock->fd);
|
||||
#ifdef UWSGI_IPV6
|
||||
}
|
||||
#endif
|
||||
@@ -2503,9 +2504,9 @@ int uwsgi_start(void *v_argv) {
|
||||
}
|
||||
else {
|
||||
#endif
|
||||
uwsgi_sock->fd = bind_to_tcp(uwsgi_sock->name, uwsgi.listen_queue, tcp_port);
|
||||
uwsgi_log("uwsgi socket %d bound to TCP address %s fd %d\n", uwsgi_get_socket_num(uwsgi_sock), uwsgi_sock->name, uwsgi_sock->fd);
|
||||
uwsgi_sock->family = AF_INET;
|
||||
uwsgi_sock->fd = bind_to_tcp(uwsgi_sock->name, uwsgi.listen_queue, tcp_port);
|
||||
uwsgi_log("uwsgi socket %d bound to TCP address %s fd %d\n", uwsgi_get_socket_num(uwsgi_sock), uwsgi_sock->name, uwsgi_sock->fd);
|
||||
uwsgi_sock->family = AF_INET;
|
||||
#ifdef UWSGI_IPV6
|
||||
}
|
||||
#endif
|
||||
@@ -2588,7 +2589,7 @@ int uwsgi_start(void *v_argv) {
|
||||
}
|
||||
else {
|
||||
#endif
|
||||
uwsgi_log("uwsgi socket %d bound to TCP address %s (port auto-assigned) fd %d\n", uwsgi_get_socket_num(uwsgi_sock), uwsgi_sock->name, uwsgi_sock->fd);
|
||||
uwsgi_log("uwsgi socket %d bound to TCP address %s (port auto-assigned) fd %d\n", uwsgi_get_socket_num(uwsgi_sock), uwsgi_sock->name, uwsgi_sock->fd);
|
||||
#ifdef UWSGI_IPV6
|
||||
}
|
||||
#endif
|
||||
@@ -2986,7 +2987,7 @@ nextsock:
|
||||
|
||||
// check for request plugins, and eventually print a warning
|
||||
int rp_available = 0;
|
||||
for(i=0;i<256;i++) {
|
||||
for (i = 0; i < 256; i++) {
|
||||
if (uwsgi.p[i] != &unconfigured_plugin) {
|
||||
rp_available = 1;
|
||||
break;
|
||||
@@ -3555,7 +3556,7 @@ void build_options() {
|
||||
|
||||
// add custom options
|
||||
struct uwsgi_custom_option *uco = uwsgi.custom_options;
|
||||
while(uco) {
|
||||
while (uco) {
|
||||
options_count++;
|
||||
uco = uco->next;
|
||||
}
|
||||
@@ -3629,17 +3630,17 @@ void build_options() {
|
||||
pos++;
|
||||
}
|
||||
uco = uwsgi.custom_options;
|
||||
while(uco) {
|
||||
while (uco) {
|
||||
uwsgi.long_options[pos].name = uco->name;
|
||||
if (uco->has_args) {
|
||||
uwsgi.long_options[pos].has_arg = required_argument;
|
||||
uwsgi.long_options[pos].has_arg = required_argument;
|
||||
}
|
||||
else {
|
||||
uwsgi.long_options[pos].has_arg = no_argument;
|
||||
uwsgi.long_options[pos].has_arg = no_argument;
|
||||
}
|
||||
uwsgi.long_options[pos].flag = 0;
|
||||
// add 1000 to avoid short_options collision
|
||||
uwsgi.long_options[pos].val = 1000 + pos;
|
||||
uwsgi.long_options[pos].flag = 0;
|
||||
// add 1000 to avoid short_options collision
|
||||
uwsgi.long_options[pos].val = 1000 + pos;
|
||||
pos++;
|
||||
uco = uco->next;
|
||||
}
|
||||
@@ -3919,18 +3920,18 @@ void uwsgi_opt_set_placeholder(char *opt, char *value, void *none) {
|
||||
|
||||
#ifdef UWSGI_SSL
|
||||
void uwsgi_opt_scd(char *opt, char *value, void *foobar) {
|
||||
// openssl could not be initialized
|
||||
if (!uwsgi.ssl_initialized) {
|
||||
uwsgi_ssl_init();
|
||||
}
|
||||
// openssl could not be initialized
|
||||
if (!uwsgi.ssl_initialized) {
|
||||
uwsgi_ssl_init();
|
||||
}
|
||||
|
||||
char *colon = strchr(value, ':');
|
||||
if (!colon) {
|
||||
uwsgi_log("invalid syntax for '%s', must be: <digest>:<directory>\n", opt);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
char *algo = uwsgi_concat2n(value, (colon-value), "", 0);
|
||||
|
||||
char *algo = uwsgi_concat2n(value, (colon - value), "", 0);
|
||||
uwsgi.subscriptions_sign_check_md = EVP_get_digestbyname(algo);
|
||||
if (!uwsgi.subscriptions_sign_check_md) {
|
||||
uwsgi_log("unable to find digest algorithm: %s\n", algo);
|
||||
@@ -3938,7 +3939,7 @@ void uwsgi_opt_scd(char *opt, char *value, void *foobar) {
|
||||
}
|
||||
free(algo);
|
||||
|
||||
uwsgi.subscriptions_sign_check_dir = colon+1;
|
||||
uwsgi.subscriptions_sign_check_dir = colon + 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -4359,21 +4360,21 @@ void uwsgi_opt_load_ldap(char *opt, char *url, void *none) {
|
||||
|
||||
void uwsgi_opt_add_custom_option(char *opt, char *value, void *none) {
|
||||
|
||||
struct uwsgi_custom_option *uco = uwsgi.custom_options, *old_uco;
|
||||
struct uwsgi_custom_option *uco = uwsgi.custom_options, *old_uco;
|
||||
|
||||
if (!uco) {
|
||||
uwsgi.custom_options = uwsgi_malloc(sizeof(struct uwsgi_custom_option));
|
||||
uco = uwsgi.custom_options;
|
||||
}
|
||||
else {
|
||||
while (uco) {
|
||||
old_uco = uco;
|
||||
uco = uco->next;
|
||||
}
|
||||
if (!uco) {
|
||||
uwsgi.custom_options = uwsgi_malloc(sizeof(struct uwsgi_custom_option));
|
||||
uco = uwsgi.custom_options;
|
||||
}
|
||||
else {
|
||||
while (uco) {
|
||||
old_uco = uco;
|
||||
uco = uco->next;
|
||||
}
|
||||
|
||||
uco = uwsgi_malloc(sizeof(struct uwsgi_custom_option));
|
||||
old_uco->next = uco;
|
||||
}
|
||||
old_uco->next = uco;
|
||||
}
|
||||
|
||||
char *copy = uwsgi_str(value);
|
||||
char *equal = strchr(copy, '=');
|
||||
@@ -4383,14 +4384,14 @@ void uwsgi_opt_add_custom_option(char *opt, char *value, void *none) {
|
||||
}
|
||||
*equal = 0;
|
||||
|
||||
uco->name = copy;
|
||||
uco->value = equal+1;
|
||||
uco->name = copy;
|
||||
uco->value = equal + 1;
|
||||
uco->has_args = 0;
|
||||
// a little hack, we allow the user to skip the first 2 arguments (yes.. it is silly...but users tend to make silly things...)
|
||||
if (strstr(uco->value, "$1") || strstr(uco->value, "$2") || strstr(uco->value, "$3")) {
|
||||
uco->has_args = 1;
|
||||
}
|
||||
uco->next = NULL;
|
||||
uco->next = NULL;
|
||||
build_options();
|
||||
}
|
||||
|
||||
@@ -4429,15 +4430,15 @@ void uwsgi_opt_flock_wait(char *opt, char *filename, void *none) {
|
||||
void uwsgi_opt_cflags(char *opt, char *filename, void *foobar) {
|
||||
size_t len = sizeof(UWSGI_CFLAGS);
|
||||
char *src = UWSGI_CFLAGS;
|
||||
char *ptr = uwsgi_malloc(len/2);
|
||||
char *ptr = uwsgi_malloc(len / 2);
|
||||
char *base = ptr;
|
||||
size_t i;
|
||||
unsigned int u;
|
||||
for(i=0;i<len;i+=2) {
|
||||
sscanf(src+i,"%2x", &u);
|
||||
*ptr++= (char) u;
|
||||
}
|
||||
fprintf(stdout, "%.*s\n", (int) len/2, base);
|
||||
for (i = 0; i < len; i += 2) {
|
||||
sscanf(src + i, "%2x", &u);
|
||||
*ptr++ = (char) u;
|
||||
}
|
||||
fprintf(stdout, "%.*s\n", (int) len / 2, base);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@@ -4446,11 +4447,11 @@ void uwsgi_opt_connect_and_read(char *opt, char *address, void *foobar) {
|
||||
char buf[8192];
|
||||
|
||||
int fd = uwsgi_connect(address, -1, 0);
|
||||
for(;;) {
|
||||
for (;;) {
|
||||
int ret = uwsgi_waitfd(fd, -1);
|
||||
if (ret <= 0) {
|
||||
if (ret <= 0) {
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
ssize_t len = read(fd, buf, 8192);
|
||||
if (len <= 0) {
|
||||
exit(0);
|
||||
|
||||
Reference in New Issue
Block a user