mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-30 00:00:16 +01:00
plugins: iterate builtin plugins as if loaded
For plugins that handle PROTOCOL_INIT, we have to iterate any PLUGINS_BUILTIN plugins as if we had just discovered and loaded them from plugin files, so they bind to vhosts appropriately. Add some private helpers to keep the guts from duplication in plat.
This commit is contained in:
parent
12a3e09f40
commit
7c9f1ca0a6
6 changed files with 68 additions and 7 deletions
|
@ -27,6 +27,7 @@
|
|||
#cmakedefine LWS_AVOID_SIGPIPE_IGN
|
||||
#cmakedefine LWS_BUILD_HASH "${LWS_BUILD_HASH}"
|
||||
#cmakedefine LWS_BUILTIN_GETIFADDRS
|
||||
#cmakedefine LWS_BUILTIN_PLUGIN_NAMES "${LWS_BUILTIN_PLUGIN_NAMES}"
|
||||
#cmakedefine LWS_CLIENT_HTTP_PROXYING
|
||||
#cmakedefine LWS_DETECTED_PLAT_IOS
|
||||
#cmakedefine LWS_FALLBACK_GETHOSTBYNAME
|
||||
|
|
|
@ -1402,6 +1402,12 @@ lws_broadcast(struct lws_context_per_thread *pt, int reason, void *in, size_t le
|
|||
const char *
|
||||
lws_errno_describe(int en, char *result, size_t len);
|
||||
|
||||
struct lws_plugin *
|
||||
lws_plugin_alloc(struct lws_plugin **pplugin);
|
||||
|
||||
int
|
||||
lws_plugins_handle_builtin(struct lws_plugin **pplugin,
|
||||
each_plugin_cb_t each, void *each_user);
|
||||
|
||||
#if defined(LWS_WITH_PEER_LIMITS)
|
||||
void
|
||||
|
|
|
@ -286,6 +286,52 @@ lws_dir_rm_rf_cb(const char *dirpath, void *user, struct lws_dir_entry *lde)
|
|||
|
||||
#if defined(LWS_WITH_PLUGINS_API)
|
||||
|
||||
struct lws_plugin *
|
||||
lws_plugin_alloc(struct lws_plugin **pplugin)
|
||||
{
|
||||
struct lws_plugin *pin = lws_malloc(sizeof(*pin), __func__);
|
||||
|
||||
if (!pin)
|
||||
return NULL;
|
||||
|
||||
pin->list = *pplugin;
|
||||
*pplugin = pin;
|
||||
|
||||
return pin;
|
||||
}
|
||||
|
||||
#if defined(LWS_BUILTIN_PLUGIN_NAMES)
|
||||
|
||||
extern lws_plugin_protocol_t lws_sshd_demo, lws_ssh_base;
|
||||
|
||||
lws_plugin_protocol_t *builtin_pcols[] = {
|
||||
&lws_sshd_demo, &lws_ssh_base
|
||||
};
|
||||
|
||||
int
|
||||
lws_plugins_handle_builtin(struct lws_plugin **pplugin,
|
||||
each_plugin_cb_t each, void *each_user)
|
||||
{
|
||||
size_t n = 0;
|
||||
|
||||
while (n < LWS_ARRAY_SIZE(builtin_pcols)) {
|
||||
struct lws_plugin *pin = lws_plugin_alloc(pplugin);
|
||||
if (!pin)
|
||||
return 1;
|
||||
|
||||
pin->u.l = NULL;
|
||||
pin->hdr = &builtin_pcols[n]->hdr;
|
||||
|
||||
if (each)
|
||||
each(pin, each_user);
|
||||
|
||||
n++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
struct lws_plugins_args {
|
||||
struct lws_plugin **pplugin;
|
||||
const char *_class;
|
||||
|
@ -411,7 +457,8 @@ lws_plugins_destroy(struct lws_plugin **pplugin, each_plugin_cb_t each,
|
|||
while (p) {
|
||||
if (each)
|
||||
each(p, each_user);
|
||||
lws_plat_destroy_dl(p);
|
||||
if (p->u.l)
|
||||
lws_plat_destroy_dl(p);
|
||||
p1 = p->list;
|
||||
p->list = NULL;
|
||||
lws_free(p);
|
||||
|
|
|
@ -178,7 +178,7 @@ lws_plat_init(struct lws_context *context,
|
|||
return 1;
|
||||
}
|
||||
|
||||
#if defined(LWS_WITH_PLUGINS)
|
||||
#if defined(LWS_WITH_PLUGINS) && !defined(LWS_WITH_PLUGINS_BUILTIN)
|
||||
{
|
||||
char *ld_env = getenv("LD_LIBRARY_PATH");
|
||||
|
||||
|
@ -196,6 +196,11 @@ lws_plat_init(struct lws_context *context,
|
|||
"lws_protocol_plugin", NULL,
|
||||
protocol_plugin_cb, context);
|
||||
}
|
||||
|
||||
#endif
|
||||
#if defined(LWS_BUILTIN_PLUGIN_NAMES)
|
||||
lws_plugins_handle_builtin(&context->plugin_list,
|
||||
protocol_plugin_cb, context);
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -97,13 +97,10 @@ lws_plat_dlopen(struct lws_plugin **pplugin, const char *libpath,
|
|||
* OK let's bring it in
|
||||
*/
|
||||
|
||||
pin = lws_malloc(sizeof(*pin), __func__);
|
||||
pin = lws_plugin_alloc(pplugin);
|
||||
if (!pin)
|
||||
goto bail;
|
||||
|
||||
pin->list = *pplugin;
|
||||
*pplugin = pin;
|
||||
|
||||
pin->u.l = l;
|
||||
pin->hdr = hdr;
|
||||
|
||||
|
|
|
@ -121,12 +121,17 @@ lws_plat_init(struct lws_context *context,
|
|||
|
||||
context->fd_random = 0;
|
||||
|
||||
#if defined(LWS_WITH_PLUGINS)
|
||||
#if defined(LWS_WITH_PLUGINS) && !defined(LWS_WITH_PLUGINS_BUILTIN)
|
||||
if (info->plugin_dirs)
|
||||
lws_plat_plugins_init(&context->plugin_list, info->plugin_dirs,
|
||||
"lws_protocol_plugin",
|
||||
protocol_plugin_cb, context);
|
||||
#endif
|
||||
#if defined(LWS_BUILTIN_PLUGIN_NAMES)
|
||||
lws_plugins_handle_builtin(&context->plugin_list,
|
||||
protocol_plugin_cb, context);
|
||||
#endif
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue