Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hook for other apache plugins #32

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions mod_websocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "util_varbuf.h"

#include "websocket_plugin.h"
#include "mod_websocket_hook_export.h"
#include "validate_utf8.h"

#define CORE_PRIVATE
Expand Down Expand Up @@ -130,6 +131,10 @@ static int supported_versions[] = { 13, 8, 7 };
static int supported_versions_len = sizeof(supported_versions) /
sizeof(supported_versions[0]);

/* Provided hooks */
/* We want to stop if one plugin accepts, but *_RUN_FIRST does not exist for optional hooks, so set both ok and declined to DECLINED */
AP_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(int,websocket_plugin_init,(const char* name, struct _WebSocketPlugin** plugin),(name, plugin),DECLINED,DECLINED)

/*
* Configuration
*/
Expand Down Expand Up @@ -196,22 +201,27 @@ static const char *mod_websocket_conf_handler(cmd_parms *cmd, void *confv,
}

if (apr_dso_load(&res_handle, ap_server_root_relative(cmd->pool, path),
cmd->pool) != APR_SUCCESS) {
char err[256];
return apr_pstrcat(cmd->pool, "Could not load WebSocketHandler ", path,
": ", apr_dso_error(res_handle, err, sizeof(err)),
NULL);
}

if ((apr_dso_sym(&sym, res_handle, name) != APR_SUCCESS) || !sym) {
apr_dso_unload(res_handle);
return apr_psprintf(cmd->pool, "Could not find initialization function "
"\"%s\" for WebSocketHandler %s", name, path);
cmd->pool) == APR_SUCCESS) {
if ((apr_dso_sym(&sym, res_handle, name) != APR_SUCCESS) || !sym) {
apr_dso_unload(res_handle);
return apr_psprintf(cmd->pool, "Could not find initialization function "
"\"%s\" for WebSocketHandler %s", name, path);
} else {
/* Get the plugin struct from the module. */
plugin = ((WS_Init) sym) ();
}
} else {
/* dso could not be loaded, check if it is a apache plugin */
if(strcmp(path, "internal")
|| ap_run_websocket_plugin_init(name, &plugin) != OK) {
char err[256];
return apr_pstrcat(cmd->pool, "Could not load WebSocketHandler ", path,
": ", apr_dso_error(res_handle, err, sizeof(err)),
NULL);
}
}

/* Get the plugin struct from the module and sanity-check. */
plugin = ((WS_Init) sym) ();

/* Do a sanity check on the returned plugin struct */
if (!plugin) {
errmsg = "returned NULL";
}
Expand Down
18 changes: 18 additions & 0 deletions mod_websocket_hook_export.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#if !defined(_MOD_WEBSOCKET_HOOK_EXPORT_H_)
#define _MOD_WEBSOCKET_HOOK_EXPORT_H_

#include "websocket_plugin.h"
#include "ap_config.h"

#if defined(__cplusplus)
extern "C"
{
#endif

AP_DECLARE_HOOK(int,websocket_plugin_init,(const char*, struct _WebSocketPlugin**))

#if defined(__cplusplus)
}
#endif

#endif