123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- /* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #include "fspr.h"
- #include "fspr_general.h"
- #include "fspr_pools.h"
- #include "fspr_signal.h"
- #include "fspr_arch_misc.h" /* for WSAHighByte / WSALowByte */
- #include "fspr_arch_proc_mutex.h" /* for fspr_proc_mutex_unix_setup_lock() */
- #include "fspr_arch_internal_time.h"
- #ifdef USE_WINSOCK
- /*
- ** Resource tag signatures for using NetWare WinSock 2. These will no longer
- ** be needed by anyone once the new WSAStartupWithNlmHandle() is available
- ** since WinSock will make the calls to AllocateResourceTag().
- */
- #define WS_LOAD_ENTRY_SIGNATURE (*(unsigned long *) "WLDE")
- #define WS_SKT_SIGNATURE (*(unsigned long *) "WSKT")
- #define WS_LOOKUP_SERVICE_SIGNATURE (*(unsigned long *) "WLUP")
- #define WS_WSAEVENT_SIGNATURE (*(unsigned long *) "WEVT")
- #define WS_CPORT_SIGNATURE (*(unsigned long *) "WCPT")
- int (*WSAStartupWithNLMHandle)( WORD version, LPWSADATA data, void *handle ) = NULL;
- int (*WSACleanupWithNLMHandle)( void *handle ) = NULL;
- static int wsa_startup_with_handle (WORD wVersionRequested, LPWSADATA data, void *handle)
- {
- APP_DATA *app_data;
-
- if (!(app_data = (APP_DATA*) get_app_data(gLibId)))
- return APR_EGENERAL;
- app_data->gs_startup_rtag = AllocateResourceTag(handle, "WinSock Start-up", WS_LOAD_ENTRY_SIGNATURE);
- app_data->gs_socket_rtag = AllocateResourceTag(handle, "WinSock socket()", WS_SKT_SIGNATURE);
- app_data->gs_lookup_rtag = AllocateResourceTag(handle, "WinSock Look-up", WS_LOOKUP_SERVICE_SIGNATURE);
- app_data->gs_event_rtag = AllocateResourceTag(handle, "WinSock Event", WS_WSAEVENT_SIGNATURE);
- app_data->gs_pcp_rtag = AllocateResourceTag(handle, "WinSock C-Port", WS_CPORT_SIGNATURE);
- return WSAStartupRTags(wVersionRequested, data,
- app_data->gs_startup_rtag,
- app_data->gs_socket_rtag,
- app_data->gs_lookup_rtag,
- app_data->gs_event_rtag,
- app_data->gs_pcp_rtag);
- }
- static int wsa_cleanup_with_handle (void *handle)
- {
- APP_DATA *app_data;
-
- if (!(app_data = (APP_DATA*) get_app_data(gLibId)))
- return APR_EGENERAL;
- return WSACleanupRTag(app_data->gs_startup_rtag);
- }
- static int UnregisterAppWithWinSock (void *nlm_handle)
- {
- if (!WSACleanupWithNLMHandle)
- {
- if (!(WSACleanupWithNLMHandle = ImportPublicObject(gLibHandle, "WSACleanupWithNLMHandle")))
- WSACleanupWithNLMHandle = wsa_cleanup_with_handle;
- }
- return (*WSACleanupWithNLMHandle)(nlm_handle);
- }
- static int RegisterAppWithWinSock (void *nlm_handle)
- {
- int err;
- WSADATA wsaData;
- WORD wVersionRequested = MAKEWORD(WSAHighByte, WSALowByte);
- if (!WSAStartupWithNLMHandle)
- {
- if (!(WSAStartupWithNLMHandle = ImportPublicObject(gLibHandle, "WSAStartupWithNLMHandle")))
- WSAStartupWithNLMHandle = wsa_startup_with_handle;
- }
- err = (*WSAStartupWithNLMHandle)(wVersionRequested, &wsaData, nlm_handle);
- if (LOBYTE(wsaData.wVersion) != WSAHighByte ||
- HIBYTE(wsaData.wVersion) != WSALowByte) {
-
- UnregisterAppWithWinSock (nlm_handle);
- return APR_EEXIST;
- }
- return err;
- }
- #endif
- APR_DECLARE(fspr_status_t) fspr_app_initialize(int *argc,
- const char * const * *argv,
- const char * const * *env)
- {
- /* An absolute noop. At present, only Win32 requires this stub, but it's
- * required in order to move command arguments passed through the service
- * control manager into the process, and it's required to fix the char*
- * data passed in from win32 unicode into utf-8, win32's apr internal fmt.
- */
- return fspr_initialize();
- }
- APR_DECLARE(fspr_status_t) fspr_initialize(void)
- {
- fspr_pool_t *pool;
- int err;
- void *nlmhandle = getnlmhandle();
- /* Register the NLM as using APR. If it is already
- registered then just return. */
- if (register_NLM(nlmhandle) != 0) {
- return APR_SUCCESS;
- }
- /* fspr_pool_initialize() is being called from the library
- startup code since all of the memory resources belong
- to the library rather than the application. */
-
- if (fspr_pool_create(&pool, NULL) != APR_SUCCESS) {
- return APR_ENOPOOL;
- }
- fspr_pool_tag(pool, "fspr_initilialize");
- #ifdef USE_WINSOCK
- err = RegisterAppWithWinSock (nlmhandle);
-
- if (err) {
- return err;
- }
- #endif
- fspr_signal_init(pool);
- return APR_SUCCESS;
- }
- APR_DECLARE_NONSTD(void) fspr_terminate(void)
- {
- APP_DATA *app_data;
- /* Get our instance data for shutting down. */
- if (!(app_data = (APP_DATA*) get_app_data(gLibId)))
- return;
- /* Unregister the NLM. If it is not registered
- then just return. */
- if (unregister_NLM(app_data->gs_nlmhandle) != 0) {
- return;
- }
- /* fspr_pool_terminate() is being called from the
- library shutdown code since the memory resources
- belong to the library rather than the application */
- /* Just clean up the memory for the app that is going
- away. */
- netware_pool_proc_cleanup ();
- #ifdef USE_WINSOCK
- UnregisterAppWithWinSock (app_data->gs_nlmhandle);
- #endif
- }
- APR_DECLARE(void) fspr_terminate2(void)
- {
- fspr_terminate();
- }
|