add context construction option to skip server hostname lookup
authorAndy Green <andy.green@linaro.org>
Mon, 22 Oct 2012 11:29:57 +0000 (12:29 +0100)
committerAndy Green <andy.green@linaro.org>
Mon, 22 Oct 2012 11:29:57 +0000 (12:29 +0100)
Signed-off-by: Andy Green <andy.green@linaro.org>
lib/libwebsockets.c
lib/libwebsockets.h
libwebsockets-api-doc.html

index ca41b04..9912aa5 100644 (file)
@@ -2596,34 +2596,42 @@ libwebsocket_create_context(int port, const char *interf,
        context->ssl_client_ctx = NULL;
        openssl_websocket_private_data_index = 0;
 #endif
-       /* find canonical hostname */
 
-       hostname[(sizeof hostname) - 1] = '\0';
-       memset(&sa, 0, sizeof(sa));
-       sa.sa_family = AF_INET;
-       sa.sa_data[(sizeof sa.sa_data) - 1] = '\0';
-       gethostname(hostname, (sizeof hostname) - 1);
+       if (options & LWS_SERVER_OPTION_SKIP_SERVER_CANONICAL_NAME) {
 
-       n = 0;
+               strcpy(context->canonical_hostname, "unknown");
 
-       if (strlen(hostname) < sizeof(sa.sa_data) - 1) {        
-               strcpy(sa.sa_data, hostname);
-//             fprintf(stderr, "my host name is %s\n", sa.sa_data);
-               n = getnameinfo(&sa, sizeof(sa), hostname,
-                       (sizeof hostname) - 1, NULL, 0, 0);
-       }
+       } else {
 
-       if (!n) {
-               strncpy(context->canonical_hostname, hostname,
-                                       sizeof context->canonical_hostname - 1);
-               context->canonical_hostname[
-                               sizeof context->canonical_hostname - 1] = '\0';
-       } else
-               strncpy(context->canonical_hostname, hostname,
-                                       sizeof context->canonical_hostname - 1);
+               /* find canonical hostname */
+
+               hostname[(sizeof hostname) - 1] = '\0';
+               memset(&sa, 0, sizeof(sa));
+               sa.sa_family = AF_INET;
+               sa.sa_data[(sizeof sa.sa_data) - 1] = '\0';
+               gethostname(hostname, (sizeof hostname) - 1);
+
+               n = 0;
+
+               if (strlen(hostname) < sizeof(sa.sa_data) - 1) {        
+                       strcpy(sa.sa_data, hostname);
+       //              fprintf(stderr, "my host name is %s\n", sa.sa_data);
+                       n = getnameinfo(&sa, sizeof(sa), hostname,
+                               (sizeof hostname) - 1, NULL, 0, 0);
+               }
 
-//     fprintf(stderr, "context->canonical_hostname = %s\n",
-//                                             context->canonical_hostname);
+               if (!n) {
+                       strncpy(context->canonical_hostname, hostname,
+                                               sizeof context->canonical_hostname - 1);
+                       context->canonical_hostname[
+                                       sizeof context->canonical_hostname - 1] = '\0';
+               } else
+                       strncpy(context->canonical_hostname, hostname,
+                                               sizeof context->canonical_hostname - 1);
+
+       //      fprintf(stderr, "context->canonical_hostname = %s\n",
+       //                                              context->canonical_hostname);
+       }
 
        /* split the proxy ads:port if given */
 
index 719b3cb..d0e96af 100644 (file)
@@ -65,6 +65,7 @@ typedef int ssize_t;
 enum libwebsocket_context_options {
        LWS_SERVER_OPTION_DEFEAT_CLIENT_MASK = 1,
        LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT = 2,
+       LWS_SERVER_OPTION_SKIP_SERVER_CANONICAL_NAME = 4,
 };
 
 enum libwebsocket_callback_reasons {
index 789871b..e908d14 100644 (file)
@@ -258,6 +258,9 @@ else ignored
 <dd>user id to change to after setting listen socket, or -1.
 <dt><b>options</b>
 <dd>0, or LWS_SERVER_OPTION_DEFEAT_CLIENT_MASK
+<dt><b>user</b>
+<dd>optional user pointer that can be recovered via the context
+pointer using libwebsocket_context_user 
 </dl>
 <h3>Description</h3>
 <blockquote>