[Libwebsockets] lwsws without libwebsockets-test-server

Andy Green andy at warmcat.com
Tue Oct 20 12:05:11 CEST 2020



On 10/20/20 10:26 AM, Roman Nikiforov wrote:
> Hi Andy,
> I'm using your great lwsws server and have the following question:
> path to plugins of lws test server are hardcoded in main.c:82 of lwsws, 
> so if I remove test server directory 
> /usr/local/share/libwebsockets-test-server and its config 
> /ets/lwsws/test-server, then put my config inside /ets/lwsws and server 
> dir into /usr/local/share, then point to plugins in /etc/lwsws/conf 
> using "plugin-dir": 
> "/usr/local/share/libwebsockets-jasca-server/plugins" I get my plugins 
> loaded. But the problem is I cannot avoid error message because of 
> missing plugins libwebsockets-test-server directory:

Right it's hardcoded in lwsws as it is

#if defined(LWS_WITH_PLUGINS)
static const char * const plugin_dirs[] = {
	INSTALL_DATADIR"/libwebsockets-test-server/plugins/",
	NULL
};
#endif

... but it's not hardcoded in lws itself, the context accepts the array 
of plugin paths from lwsws.

If I understand it everything is there and happy, it's just lwsws has 
the idea it must collect plugins from the expected (and in your case, 
not existing) directory.

You should be able to work around it by just making the expected empty 
dir if so.

How about this, give -n to stop lwsws wanting to look in the lws plugins 
dir?

diff --git a/lwsws/main.c b/lwsws/main.c
index 7b2b663bc..d62f6fe99 100644
--- a/lwsws/main.c
+++ b/lwsws/main.c
@@ -57,7 +57,7 @@ int fork(void)

  static struct lws_context *context;
  static lws_sorted_usec_list_t sul_lwsws;
-static char config_dir[128];
+static char config_dir[128], default_plugin_path = 1;
  static int opts = 0, do_reload = 1;
  static uv_loop_t loop;
  static uv_signal_t signal_outer[2];
@@ -89,6 +89,7 @@ static struct option options[] = {
         { "help",       no_argument,            NULL, 'h' },
         { "debug",      required_argument,      NULL, 'd' },
         { "configdir",  required_argument,      NULL, 'c' },
+       { "no-default-plugins",  no_argument,   NULL, 'n' },
         { NULL, 0, 0, 0 }
  };
  #endif
@@ -153,7 +154,8 @@ context_creation(void)
                               LWS_SERVER_OPTION_LIBUV;

  #if defined(LWS_WITH_PLUGINS)
-       info.plugin_dirs = plugin_dirs;
+       if (default_plugin_path)
+               info.plugin_dirs = plugin_dirs;
  #endif
         lwsl_notice("Using config dir: \"%s\"\n", config_dir);

@@ -244,9 +246,9 @@ int main(int argc, char **argv)
         strcpy(config_dir, "/etc/lwsws");
         while (n >= 0) {
  #if defined(LWS_HAS_GETOPT_LONG) || defined(WIN32)
-               n = getopt_long(argc, argv, "hd:c:", options, NULL);
+               n = getopt_long(argc, argv, "hd:c:n", options, NULL);
  #else
-               n = getopt(argc, argv, "hd:c:");
+               n = getopt(argc, argv, "hd:c:n");
  #endif
                 if (n < 0)
                         continue;
@@ -254,12 +256,16 @@ int main(int argc, char **argv)
                 case 'd':
                         debug_level = atoi(optarg);
                         break;
+               case 'n':
+                       default_plugin_path = 0;
+                       break;
                 case 'c':
                         lws_strncpy(config_dir, optarg, 
sizeof(config_dir));
                         break;
                 case 'h':
                         fprintf(stderr, "Usage: lwsws [-c <config dir>] "
-                                       "[-d <log bitfield>] [--help]\n");
+                                       "[-d <log bitfield>] [--help] "
+                                       "[-n]\n");
                         exit(1);
                 }
         }


> lwsws libwebsockets web server - license CC0 + MIT
> (C) Copyright 2010-2020 Andy Green <andy at warmcat.com 
> <mailto:andy at warmcat.com>>
> Using config dir: "/etc/lwsws"
> LWS: 4.1.99-v4.1.0-69-ged1e558e, loglevel 2047
> NET CLI SRV H1 H2 WS IPv6-absent
> Scandir on '/usr/local/share/libwebsockets-test-server/plugins/' failed, 
> errno 2
>     /usr/local/share/libwebsockets-jasca-server/plugins/libjasca_vtr.so
>   Using foreign event loop...
> ...
> 
> Enabling -DLWS_WITH_LWSWS=1 sets LWS_WITH_PLUGINS 1 in 
> CMakeLists-implied-options.txt. Is LWS_WITH_PLUGINS required to use 
> plugins in lwsws or is it LWS_WITH_PLUGINS_API?

In v4.1+ the previously private plugin management apis were made generic 
and exposed publicly

https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-protocols-plugins.h#n197-307

... this lets user code "do plugins" easily for their own code.  Event 
lib support was also moved into their own plugins at that time as well, 
and protocol plugins and event lib plugins use these common apis to work.

LWS_WITH_PLUGINS_API == build (and make public) the platform-specific 
stuff to allow plugins to be used

LWS_WITH_PLUGINS == build the protocol plugins... implies 
LWS_WITH_PLUGINS_API

LWS_WITH_EVLIB_PLUGINS == build the event lib support as plugins, this 
lets you build all the event lib support cleanly and pick one at 
runtime, ideal for distro packaging... implies LWS_WITH_PLUGINS_API

-Andy


More information about the Libwebsockets mailing list