Subject: Support to bind accepted socket to device on Linux
[platform/upstream/libwebsockets.git] / lib / context.c
index f791ca6..9bf5465 100644 (file)
@@ -241,7 +241,10 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason,
                        if (lws_cgi_write_split_stdout_headers(wsi) < 0)
                                return -1;
 
-                       wsi->reason_bf &= ~1;
+                       if (wsi->reason_bf & 8)
+                               wsi->reason_bf &= ~8;
+                       else
+                               wsi->reason_bf &= ~1;
                        break;
                }
 #endif
@@ -352,6 +355,10 @@ lws_create_vhost(struct lws_context *context,
                vh->name = info->vhost_name;
 
        vh->iface = info->iface;
+#if !defined(LWS_WITH_ESP8266) && !defined(LWS_WITH_ESP32) && !defined(OPTEE_TA) && !defined(WIN32)
+       vh->bind_iface = info->bind_iface;
+#endif
+
        for (vh->count_protocols = 0;
             info->protocols[vh->count_protocols].callback;
             vh->count_protocols++)
@@ -497,9 +504,14 @@ lws_create_vhost(struct lws_context *context,
 #if !defined(LWS_WITH_ESP8266)
        vh->http_proxy_port = 0;
        vh->http_proxy_address[0] = '\0';
+#if defined(LWS_WITH_SOCKS5)
+       vh->socks_proxy_port = 0;
+       vh->socks_proxy_address[0] = '\0';
+#endif
 
        /* either use proxy from info, or try get it from env var */
 
+       /* http proxy */
        if (info->http_proxy_address) {
                /* override for backwards compatibility */
                if (info->http_proxy_port)
@@ -512,7 +524,23 @@ lws_create_vhost(struct lws_context *context,
                        lws_set_proxy(vh, p);
 #endif
        }
+#if defined(LWS_WITH_SOCKS5)
+       /* socks proxy */
+       if (info->socks_proxy_address) {
+               /* override for backwards compatibility */
+               if (info->socks_proxy_port)
+                       vh->socks_proxy_port = info->socks_proxy_port;
+               lws_set_socks(vh, info->socks_proxy_address);
+       } else {
+#ifdef LWS_HAVE_GETENV
+               p = getenv("socks_proxy");
+               if (p)
+                       lws_set_socks(vh, p);
 #endif
+       }
+#endif
+#endif
+
        vh->ka_time = info->ka_time;
        vh->ka_interval = info->ka_interval;
        vh->ka_probes = info->ka_probes;
@@ -868,6 +896,11 @@ lws_create_context(struct lws_context_creation_info *info)
        context->uid = info->uid;
        context->gid = info->gid;
 
+#if defined(LWS_HAVE_SYS_CAPABILITY_H) && defined(LWS_HAVE_LIBCAP)
+       memcpy(context->caps, info->caps, sizeof(context->caps));
+       context->count_caps = info->count_caps;
+#endif
+
        /*
         * drop any root privs for this process
         * to listen on port < 1023 we would have needed root, but now we are