summaryrefslogtreecommitdiff
path: root/misc/netware
diff options
context:
space:
mode:
authorbnicholes <bnicholes@13f79535-47bb-0310-9956-ffa450edef68>2002-01-31 18:49:51 +0000
committerbnicholes <bnicholes@13f79535-47bb-0310-9956-ffa450edef68>2002-01-31 18:49:51 +0000
commitdd3669e6bc5688711a3921819cbd7220b7bd2324 (patch)
treeebc92d60975a1ef834bfb16f9d0b9abd9ffa030c /misc/netware
parent88f97ea0a835378802dd8846478d1fa64be0b1d7 (diff)
downloadlibapr-dd3669e6bc5688711a3921819cbd7220b7bd2324.tar.gz
Added the necessary code to make APRLib into a real library NLM. Also
added support for application instance data since library NLMs do not support this by default. This allows us to get global variables separated by application instance. git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@62878 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'misc/netware')
-rw-r--r--misc/netware/libprews.c99
1 files changed, 97 insertions, 2 deletions
diff --git a/misc/netware/libprews.c b/misc/netware/libprews.c
index efa475fc6..c1181d470 100644
--- a/misc/netware/libprews.c
+++ b/misc/netware/libprews.c
@@ -9,9 +9,24 @@
provide.
------------------------------------------------------------------*/
#include <netware.h>
-//#include "stddef.h"
+#include <library.h>
+#include <nks/synch.h>
#include "ws2nlm.h"
+#include "apr_pools.h"
+
+typedef struct app_data {
+ int initialized;
+} APP_DATA;
+
+/* library-private data...*/
+int gLibId = -1;
+void *gLibHandle = (void *) NULL;
+NXMutex_t *gLibLock = (NXMutex_t *) NULL;
+
+/* internal library function prototypes...*/
+int DisposeLibraryData(void *);
+
int _NonAppStart
(
void *NLMHandle,
@@ -28,6 +43,8 @@ int _NonAppStart
const char **messages
)
{
+ NX_LOCK_INFO_ALLOC(liblock, "Per-Application Data Lock", 0);
+
#pragma unused(cmdLine)
#pragma unused(loadDirPath)
#pragma unused(uninitializedDataLength)
@@ -39,16 +56,94 @@ int _NonAppStart
#pragma unused(messages)
WSADATA wsaData;
+ apr_status_t status;
+ gLibId = register_library(DisposeLibraryData);
+
+ if (gLibId < -1)
+ {
+ OutputToScreen(errorScreen, "Unable to register library with kernel.\n");
+ return -1;
+ }
+
+ gLibHandle = NLMHandle;
+
+ gLibLock = NXMutexAlloc(0, 0, &liblock);
+
+ if (!gLibLock)
+ {
+ OutputToScreen(errorScreen, "Unable to allocate library data lock.\n");
+ return -1;
+ }
+
+ apr_netware_setup_time();
+
+ if ((status = apr_pool_initialize()) != APR_SUCCESS)
+ return status;
+
return WSAStartup((WORD) MAKEWORD(2, 0), &wsaData);
}
void _NonAppStop( void )
{
+ apr_pool_terminate();
+
WSACleanup();
+
+ unregister_library(gLibId);
+ NXMutexFree(gLibLock);
}
int _NonAppCheckUnload( void )
{
- return 0;
+ return 0;
+}
+
+int register_NLM(void *NLMHandle)
+{
+ APP_DATA *app_data = (APP_DATA*) get_app_data(gLibId);
+
+ NXLock(gLibLock);
+ if (!app_data) {
+ app_data = (APP_DATA*)library_malloc(gLibHandle, sizeof(APP_DATA));
+
+ if (app_data) {
+ memset (app_data, 0, sizeof(APP_DATA));
+ set_app_data(gLibId, app_data);
+ }
+ }
+
+ if (app_data && (!app_data->initialized)) {
+ app_data->initialized = 1;
+ NXUnlock(gLibLock);
+ return 0;
+ }
+
+ NXUnlock(gLibLock);
+ return 1;
}
+
+int unregister_NLM(void *NLMHandle)
+{
+ APP_DATA *app_data = (APP_DATA*) get_app_data(gLibId);
+
+ NXLock(gLibLock);
+ if (app_data) {
+ app_data->initialized = 0;
+ NXUnlock(gLibLock);
+ return 0;
+ }
+ NXUnlock(gLibLock);
+ return 1;
+}
+
+int DisposeLibraryData(void *data)
+{
+ if (data)
+ {
+ library_free(data);
+ }
+
+ return 0;
+}
+