~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

Viewing changes to srclib/apr/misc/netware/start.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
 
2
 * applicable.
 
3
 *
 
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
 
7
 *
 
8
 *     http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
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.
 
15
 */
 
16
 
 
17
#include "apr.h"
 
18
#include "apr_general.h"
 
19
#include "apr_pools.h"
 
20
#include "apr_signal.h"
 
21
 
 
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"
 
25
 
 
26
#ifdef USE_WINSOCK
 
27
/*
 
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().
 
31
*/
 
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")
 
37
 
 
38
 
 
39
int (*WSAStartupWithNLMHandle)( WORD version, LPWSADATA data, void *handle ) = NULL;
 
40
int (*WSACleanupWithNLMHandle)( void *handle ) = NULL;
 
41
 
 
42
static int wsa_startup_with_handle (WORD wVersionRequested, LPWSADATA data, void *handle)
 
43
{
 
44
    APP_DATA *app_data;
 
45
    
 
46
    if (!(app_data = (APP_DATA*) get_app_data(gLibId)))
 
47
        return APR_EGENERAL;
 
48
 
 
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);
 
54
 
 
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);
 
61
}
 
62
 
 
63
static int wsa_cleanup_with_handle (void *handle)
 
64
{
 
65
    APP_DATA *app_data;
 
66
    
 
67
    if (!(app_data = (APP_DATA*) get_app_data(gLibId)))
 
68
        return APR_EGENERAL;
 
69
 
 
70
    return WSACleanupRTag(app_data->gs_startup_rtag);
 
71
}
 
72
 
 
73
static int UnregisterAppWithWinSock (void *nlm_handle)
 
74
{
 
75
    if (!WSACleanupWithNLMHandle)
 
76
    {
 
77
        if (!(WSACleanupWithNLMHandle = ImportPublicObject(gLibHandle, "WSACleanupWithNLMHandle")))
 
78
            WSACleanupWithNLMHandle = wsa_cleanup_with_handle;
 
79
    }
 
80
 
 
81
    return (*WSACleanupWithNLMHandle)(nlm_handle);
 
82
}
 
83
 
 
84
static int RegisterAppWithWinSock (void *nlm_handle)
 
85
{
 
86
    int err;
 
87
    WSADATA wsaData;
 
88
    WORD wVersionRequested = MAKEWORD(WSAHighByte, WSALowByte);
 
89
 
 
90
    if (!WSAStartupWithNLMHandle)
 
91
    {
 
92
        if (!(WSAStartupWithNLMHandle = ImportPublicObject(gLibHandle, "WSAStartupWithNLMHandle")))
 
93
            WSAStartupWithNLMHandle = wsa_startup_with_handle;
 
94
    }
 
95
 
 
96
    err = (*WSAStartupWithNLMHandle)(wVersionRequested, &wsaData, nlm_handle);
 
97
 
 
98
    if (LOBYTE(wsaData.wVersion) != WSAHighByte ||
 
99
        HIBYTE(wsaData.wVersion) != WSALowByte) {
 
100
        
 
101
        UnregisterAppWithWinSock (nlm_handle);
 
102
        return APR_EEXIST;
 
103
    }
 
104
 
 
105
    return err;
 
106
}
 
107
#endif
 
108
 
 
109
 
 
110
 
 
111
APR_DECLARE(apr_status_t) apr_app_initialize(int *argc, 
 
112
                                             const char * const * *argv, 
 
113
                                             const char * const * *env)
 
114
{
 
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.
 
119
     */
 
120
    return apr_initialize();
 
121
}
 
122
 
 
123
APR_DECLARE(apr_status_t) apr_initialize(void)
 
124
{
 
125
    apr_pool_t *pool;
 
126
    int err;
 
127
    void *nlmhandle = getnlmhandle();
 
128
 
 
129
    /* Register the NLM as using APR. If it is already
 
130
        registered then just return. */
 
131
    if (register_NLM(nlmhandle) != 0) {
 
132
        return APR_SUCCESS;
 
133
    }
 
134
 
 
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. */
 
138
    
 
139
    if (apr_pool_create(&pool, NULL) != APR_SUCCESS) {
 
140
        return APR_ENOPOOL;
 
141
    }
 
142
 
 
143
    apr_pool_tag(pool, "apr_initilialize");
 
144
 
 
145
#ifdef USE_WINSOCK
 
146
    err = RegisterAppWithWinSock (nlmhandle);
 
147
    
 
148
    if (err) {
 
149
        return err;
 
150
    }
 
151
#endif
 
152
 
 
153
    apr_signal_init(pool);
 
154
 
 
155
    return APR_SUCCESS;
 
156
}
 
157
 
 
158
APR_DECLARE_NONSTD(void) apr_terminate(void)
 
159
{
 
160
    APP_DATA *app_data;
 
161
 
 
162
    /* Get our instance data for shutting down. */
 
163
    if (!(app_data = (APP_DATA*) get_app_data(gLibId)))
 
164
        return;
 
165
 
 
166
    /* Unregister the NLM. If it is not registered
 
167
        then just return. */
 
168
    if (unregister_NLM(app_data->gs_nlmhandle) != 0) {
 
169
        return;
 
170
    }
 
171
 
 
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 */
 
175
 
 
176
    /* Just clean up the memory for the app that is going
 
177
        away. */
 
178
    netware_pool_proc_cleanup ();
 
179
 
 
180
#ifdef USE_WINSOCK
 
181
    UnregisterAppWithWinSock (app_data->gs_nlmhandle);
 
182
#endif
 
183
}
 
184
 
 
185
APR_DECLARE(void) apr_terminate2(void)
 
186
{
 
187
    apr_terminate();
 
188
}