Subject: Support to IPv6 on Windows
[platform/upstream/libwebsockets.git] / lib / server.c
index f442b94..a84f661 100644 (file)
@@ -308,6 +308,9 @@ lws_get_mimetype(const char *file, const struct lws_http_mount *m)
        if (!strcmp(&file[n - 4], ".ttf"))
                return "application/x-font-ttf";
 
+       if (!strcmp(&file[n - 4], ".otf"))
+               return "application/font-woff";
+
        if (!strcmp(&file[n - 5], ".woff"))
                return "application/font-woff";
 
@@ -1058,7 +1061,6 @@ lws_http_action(struct lws *wsi)
                        NULL, /* replace with cgi path */
                        NULL
                };
-               unsigned char *p, *end, buffer[1024];
 
                lwsl_debug("%s: cgi\n", __func__);
                cmd[0] = hit->origin;
@@ -1073,17 +1075,6 @@ lws_http_action(struct lws *wsi)
                        lwsl_err("%s: cgi failed\n", __func__);
                        return -1;
                }
-               p = buffer + LWS_PRE;
-               end = p + sizeof(buffer) - LWS_PRE;
-
-               if (lws_add_http_header_status(wsi, HTTP_STATUS_OK, &p, end))
-                       return 1;
-               if (lws_add_http_header_by_token(wsi, WSI_TOKEN_CONNECTION,
-                               (unsigned char *)"close", 5, &p, end))
-                       return 1;
-               n = lws_write(wsi, buffer + LWS_PRE,
-                             p - (buffer + LWS_PRE),
-                             LWS_WRITE_HTTP_HEADERS);
 
                goto deal_body;
        }
@@ -1456,7 +1447,7 @@ upgrade_ws:
                         */
                        lwsl_info("defaulting to prot handler %d\n",
                                wsi->vhost->default_protocol_index);
-                       n = 0;
+                       n = wsi->vhost->default_protocol_index;
                        wsi->protocol = &wsi->vhost->protocols[
                                      (int)wsi->vhost->default_protocol_index];
                }
@@ -1784,8 +1775,10 @@ lws_adopt_descriptor_vhost(struct lws_vhost *vh, lws_adoption_type type,
                                 vh_prot_name, new_wsi->vhost->name);
                        goto bail;
                }
-               if (lws_ensure_user_space(new_wsi))
+               if (lws_ensure_user_space(new_wsi)) {
+                       lwsl_notice("OOM trying to get user_space\n");
                        goto bail;
+               }
        } else
                if (type & LWS_ADOPT_HTTP) /* he will transition later */
                        new_wsi->protocol =
@@ -1872,9 +1865,13 @@ lws_adopt_descriptor_vhost(struct lws_vhost *vh, lws_adoption_type type,
                        new_wsi, n, new_wsi->user_space, NULL, 0))
                goto fail;
 
-       if (type & LWS_ADOPT_HTTP)
-               if (!lws_header_table_attach(new_wsi, 0))
+       if (type & LWS_ADOPT_HTTP) {
+               if (!lws_header_table_attach(new_wsi, 0)) {
                        lwsl_debug("Attached ah immediately\n");
+               } else {
+                       lwsl_notice("%s: waiting for ah\n", __func__);
+               }
+       }
 
        return new_wsi;
 
@@ -1885,11 +1882,13 @@ fail:
        return NULL;
 
 bail:
+       lwsl_notice("%s: exiting on bail\n", __func__);
        if (parent)
                parent->child_list = new_wsi->sibling_list;
        if (new_wsi->user_space)
                lws_free(new_wsi->user_space);
        lws_free(new_wsi);
+       compatible_close(fd.sockfd);
 
        return NULL;
 }
@@ -2010,7 +2009,7 @@ lws_server_socket_service(struct lws_context *context, struct lws *wsi,
        lws_sock_file_fd_type fd;
        int opts = LWS_ADOPT_SOCKET | LWS_ADOPT_ALLOW_SSL;
 #if LWS_POSIX
-       struct sockaddr_in cli_addr;
+       struct sockaddr_storage cli_addr;
        socklen_t clilen;
 #endif
        int n, len;
@@ -2296,8 +2295,17 @@ try_pollout:
 
                        lws_plat_set_socket_options(wsi->vhost, accept_fd);
 
-                       lwsl_debug("accepted new conn  port %u on fd=%d\n",
-                                         ntohs(cli_addr.sin_port), accept_fd);
+#if defined(LWS_USE_IPV6)
+                       lwsl_debug("accepted new conn port %u on fd=%d\n",
+                                         ((cli_addr.ss_family == AF_INET6) ?
+                                         ntohs(((struct sockaddr_in6 *) &cli_addr)->sin6_port) :
+                                         ntohs(((struct sockaddr_in *) &cli_addr)->sin_port)),
+                                         accept_fd);
+#else
+                       lwsl_debug("accepted new conn port %u on fd=%d\n",
+                                         ntohs(((struct sockaddr_in *) &cli_addr)->sin_port),
+                                         accept_fd);
+#endif
 
 #else
                        /* not very beautiful... */