1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
18
#include "apr_general.h"
19
#include "apr_pools.h"
20
#include "apr_signal.h"
22
#include "apr_arch_misc.h" /* for WSAHighByte / WSALowByte */
23
#include "apr_arch_proc_mutex.h" /* for apr_proc_mutex_unix_setup_lock() */
24
#include "apr_arch_internal_time.h"
28
** Resource tag signatures for using NetWare WinSock 2. These will no longer
29
** be needed by anyone once the new WSAStartupWithNlmHandle() is available
30
** since WinSock will make the calls to AllocateResourceTag().
32
#define WS_LOAD_ENTRY_SIGNATURE (*(unsigned long *) "WLDE")
33
#define WS_SKT_SIGNATURE (*(unsigned long *) "WSKT")
34
#define WS_LOOKUP_SERVICE_SIGNATURE (*(unsigned long *) "WLUP")
35
#define WS_WSAEVENT_SIGNATURE (*(unsigned long *) "WEVT")
36
#define WS_CPORT_SIGNATURE (*(unsigned long *) "WCPT")
39
int (*WSAStartupWithNLMHandle)( WORD version, LPWSADATA data, void *handle ) = NULL;
40
int (*WSACleanupWithNLMHandle)( void *handle ) = NULL;
42
static int wsa_startup_with_handle (WORD wVersionRequested, LPWSADATA data, void *handle)
46
if (!(app_data = (APP_DATA*) get_app_data(gLibId)))
49
app_data->gs_startup_rtag = AllocateResourceTag(handle, "WinSock Start-up", WS_LOAD_ENTRY_SIGNATURE);
50
app_data->gs_socket_rtag = AllocateResourceTag(handle, "WinSock socket()", WS_SKT_SIGNATURE);
51
app_data->gs_lookup_rtag = AllocateResourceTag(handle, "WinSock Look-up", WS_LOOKUP_SERVICE_SIGNATURE);
52
app_data->gs_event_rtag = AllocateResourceTag(handle, "WinSock Event", WS_WSAEVENT_SIGNATURE);
53
app_data->gs_pcp_rtag = AllocateResourceTag(handle, "WinSock C-Port", WS_CPORT_SIGNATURE);
55
return WSAStartupRTags(wVersionRequested, data,
56
app_data->gs_startup_rtag,
57
app_data->gs_socket_rtag,
58
app_data->gs_lookup_rtag,
59
app_data->gs_event_rtag,
60
app_data->gs_pcp_rtag);
63
static int wsa_cleanup_with_handle (void *handle)
67
if (!(app_data = (APP_DATA*) get_app_data(gLibId)))
70
return WSACleanupRTag(app_data->gs_startup_rtag);
73
static int UnregisterAppWithWinSock (void *nlm_handle)
75
if (!WSACleanupWithNLMHandle)
77
if (!(WSACleanupWithNLMHandle = ImportPublicObject(gLibHandle, "WSACleanupWithNLMHandle")))
78
WSACleanupWithNLMHandle = wsa_cleanup_with_handle;
81
return (*WSACleanupWithNLMHandle)(nlm_handle);
84
static int RegisterAppWithWinSock (void *nlm_handle)
88
WORD wVersionRequested = MAKEWORD(WSAHighByte, WSALowByte);
90
if (!WSAStartupWithNLMHandle)
92
if (!(WSAStartupWithNLMHandle = ImportPublicObject(gLibHandle, "WSAStartupWithNLMHandle")))
93
WSAStartupWithNLMHandle = wsa_startup_with_handle;
96
err = (*WSAStartupWithNLMHandle)(wVersionRequested, &wsaData, nlm_handle);
98
if (LOBYTE(wsaData.wVersion) != WSAHighByte ||
99
HIBYTE(wsaData.wVersion) != WSALowByte) {
101
UnregisterAppWithWinSock (nlm_handle);
111
APR_DECLARE(apr_status_t) apr_app_initialize(int *argc,
112
const char * const * *argv,
113
const char * const * *env)
115
/* An absolute noop. At present, only Win32 requires this stub, but it's
116
* required in order to move command arguments passed through the service
117
* control manager into the process, and it's required to fix the char*
118
* data passed in from win32 unicode into utf-8, win32's apr internal fmt.
120
return apr_initialize();
123
APR_DECLARE(apr_status_t) apr_initialize(void)
127
void *nlmhandle = getnlmhandle();
129
/* Register the NLM as using APR. If it is already
130
registered then just return. */
131
if (register_NLM(nlmhandle) != 0) {
135
/* apr_pool_initialize() is being called from the library
136
startup code since all of the memory resources belong
137
to the library rather than the application. */
139
if (apr_pool_create(&pool, NULL) != APR_SUCCESS) {
143
apr_pool_tag(pool, "apr_initilialize");
146
err = RegisterAppWithWinSock (nlmhandle);
153
apr_signal_init(pool);
158
APR_DECLARE_NONSTD(void) apr_terminate(void)
162
/* Get our instance data for shutting down. */
163
if (!(app_data = (APP_DATA*) get_app_data(gLibId)))
166
/* Unregister the NLM. If it is not registered
168
if (unregister_NLM(app_data->gs_nlmhandle) != 0) {
172
/* apr_pool_terminate() is being called from the
173
library shutdown code since the memory resources
174
belong to the library rather than the application */
176
/* Just clean up the memory for the app that is going
178
netware_pool_proc_cleanup ();
181
UnregisterAppWithWinSock (app_data->gs_nlmhandle);
185
APR_DECLARE(void) apr_terminate2(void)