diff options
author | hongbotian <hongbo.tianhongbo@huawei.com> | 2015-11-30 01:45:08 -0500 |
---|---|---|
committer | hongbotian <hongbo.tianhongbo@huawei.com> | 2015-11-30 01:45:08 -0500 |
commit | e8ec7aa8e38a93f5b034ac74cebce5de23710317 (patch) | |
tree | aa031937bf856c1f8d6ad7877b8d2cb0224da5ef /rubbos/app/httpd-2.0.64/srclib/apr/misc/win32 | |
parent | cc40af334e619bb549038238507407866f774f8f (diff) |
upload http
JIRA: BOTTLENECK-10
Change-Id: I7598427ff904df438ce77c2819ee48ac75ffa8da
Signed-off-by: hongbotian <hongbo.tianhongbo@huawei.com>
Diffstat (limited to 'rubbos/app/httpd-2.0.64/srclib/apr/misc/win32')
-rw-r--r-- | rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/apr_app.c | 80 | ||||
-rw-r--r-- | rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/charset.c | 55 | ||||
-rw-r--r-- | rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/env.c | 192 | ||||
-rw-r--r-- | rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/internal.c | 102 | ||||
-rw-r--r-- | rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/misc.c | 237 | ||||
-rw-r--r-- | rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/rand.c | 69 | ||||
-rw-r--r-- | rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/start.c | 230 | ||||
-rw-r--r-- | rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/utf8.c | 254 |
8 files changed, 1219 insertions, 0 deletions
diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/apr_app.c b/rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/apr_app.c new file mode 100644 index 00000000..baac96e8 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/apr_app.c @@ -0,0 +1,80 @@ +/* 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. + */ + +/* Usage Notes: + * + * this module, and the misc/win32/utf8.c modules must be + * compiled APR_EXPORT_STATIC and linked to an application with + * the /entry:wmainCRTStartup flag. This module becomes the true + * wmain entry point, and passes utf-8 reformatted argv and env + * arrays to the application's main function. + * + * This module is only compatible with Unicode-only executables. + * Mixed (Win9x backwards compatible) binaries should refer instead + * to the apr_startup.c module. + * + * _dbg_malloc/realloc is used in place of the usual API, in order + * to convince the MSVCRT that they created these entities. If we + * do not create them as _CRT_BLOCK entities, the crt will fault + * on an assert. We are not worrying about the crt's locks here, + * since we are single threaded [so far]. + */ + +#include "apr_general.h" +#include "ShellAPI.h" +#include "crtdbg.h" +#include "wchar.h" +#include "apr_arch_file_io.h" +#include "assert.h" +#include "apr_private.h" +#include "apr_arch_misc.h" + +/* This symbol is _private_, although it must be exported. + */ + +extern int main(int argc, const char **argv, const char **env); + +int wmain(int argc, const wchar_t **wargv, const wchar_t **wenv) +{ + char **argv; + char **env; + int dupenv; + + (void)apr_wastrtoastr(&argv, wargv, argc); + + dupenv = apr_wastrtoastr(&env, wenv, -1); + + _environ = _malloc_dbg((dupenv + 1) * sizeof (char *), + _CRT_BLOCK, __FILE__, __LINE__ ); + memcpy(_environ, env, (dupenv + 1) * sizeof (char *)); + + /* MSVCRT will attempt to maintain the wide environment calls + * on _putenv(), which is bogus if we've passed a non-ascii + * string to _putenv(), since they use MultiByteToWideChar + * and breaking the implicit utf-8 assumption we've built. + * + * Reset _wenviron for good measure. + */ + if (_wenviron) { + wenv = _wenviron; + _wenviron = NULL; + free((wchar_t **)wenv); + } + + apr_app_init_complete = 1; + + return main(argc, argv, env); +} diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/charset.c b/rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/charset.c new file mode 100644 index 00000000..41135b25 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/charset.c @@ -0,0 +1,55 @@ +/* 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 "apr.h" +#include "apr_strings.h" +#include "apr_portable.h" + + +APR_DECLARE(const char*) apr_os_default_encoding (apr_pool_t *pool) +{ + return apr_psprintf(pool, "CP%u", (unsigned) GetACP()); +} + + +APR_DECLARE(const char*) apr_os_locale_encoding (apr_pool_t *pool) +{ +#ifdef _UNICODE + int i; +#endif +#if defined(_WIN32_WCE) + LCID locale = GetUserDefaultLCID(); +#else + LCID locale = GetThreadLocale(); +#endif + int len = GetLocaleInfo(locale, LOCALE_IDEFAULTANSICODEPAGE, NULL, 0); + char *cp = apr_palloc(pool, (len * sizeof(TCHAR)) + 2); + if (0 < GetLocaleInfo(locale, LOCALE_IDEFAULTANSICODEPAGE, (TCHAR*) (cp + 2), len)) + { + /* Fix up the returned number to make a valid codepage name of + the form "CPnnnn". */ + cp[0] = 'C'; + cp[1] = 'P'; +#ifdef _UNICODE + for(i = 0; i < len; i++) { + cp[i + 2] = (char) ((TCHAR*) (cp + 2))[i]; + } +#endif + return cp; + } + + return apr_os_default_encoding(pool); +} diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/env.c b/rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/env.c new file mode 100644 index 00000000..644f59b8 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/env.c @@ -0,0 +1,192 @@ +/* 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. + */ + +#define APR_WANT_STRFUNC +#include "apr_want.h" +#include "apr.h" +#include "apr_arch_misc.h" +#include "apr_arch_utf8.h" +#include "apr_env.h" +#include "apr_errno.h" +#include "apr_pools.h" +#include "apr_strings.h" + +#if APR_HAS_UNICODE_FS && !defined(_WIN32_WCE) +static apr_status_t widen_envvar_name (apr_wchar_t *buffer, + apr_size_t bufflen, + const char *envvar) +{ + apr_size_t inchars; + apr_status_t status; + + inchars = strlen(envvar) + 1; + status = apr_conv_utf8_to_ucs2(envvar, &inchars, buffer, &bufflen); + if (status == APR_INCOMPLETE) + status = APR_ENAMETOOLONG; + + return status; +} +#endif + + +APR_DECLARE(apr_status_t) apr_env_get(char **value, + const char *envvar, + apr_pool_t *pool) +{ +#if defined(_WIN32_WCE) + return APR_ENOTIMPL; +#else + char *val = NULL; + DWORD size; + +#if APR_HAS_UNICODE_FS + IF_WIN_OS_IS_UNICODE + { + apr_wchar_t wenvvar[APR_PATH_MAX]; + apr_size_t inchars, outchars; + apr_wchar_t *wvalue, dummy; + apr_status_t status; + + status = widen_envvar_name(wenvvar, APR_PATH_MAX, envvar); + if (status) + return status; + + SetLastError(0); + size = GetEnvironmentVariableW(wenvvar, &dummy, 0); + if (GetLastError() == ERROR_ENVVAR_NOT_FOUND) + /* The environment variable doesn't exist. */ + return APR_ENOENT; + + if (size == 0) { + /* The environment value exists, but is zero-length. */ + *value = apr_pstrdup(pool, ""); + return APR_SUCCESS; + } + + wvalue = apr_palloc(pool, size * sizeof(*wvalue)); + size = GetEnvironmentVariableW(wenvvar, wvalue, size); + + inchars = wcslen(wvalue) + 1; + outchars = 3 * inchars; /* Enough for any UTF-8 representation */ + val = apr_palloc(pool, outchars); + status = apr_conv_ucs2_to_utf8(wvalue, &inchars, val, &outchars); + if (status) + return status; + } +#endif +#if APR_HAS_ANSI_FS + ELSE_WIN_OS_IS_ANSI + { + char dummy; + + SetLastError(0); + size = GetEnvironmentVariableA(envvar, &dummy, 0); + if (GetLastError() == ERROR_ENVVAR_NOT_FOUND) + /* The environment variable doesn't exist. */ + return APR_ENOENT; + + if (size == 0) { + /* The environment value exists, but is zero-length. */ + *value = apr_pstrdup(pool, ""); + return APR_SUCCESS; + } + + val = apr_palloc(pool, size); + size = GetEnvironmentVariableA(envvar, val, size); + if (size == 0) + /* Mid-air collision?. Somebody must've changed the env. var. */ + return APR_INCOMPLETE; + } +#endif + + *value = val; + return APR_SUCCESS; +#endif +} + + +APR_DECLARE(apr_status_t) apr_env_set(const char *envvar, + const char *value, + apr_pool_t *pool) +{ +#if defined(_WIN32_WCE) + return APR_ENOTIMPL; +#else +#if APR_HAS_UNICODE_FS + IF_WIN_OS_IS_UNICODE + { + apr_wchar_t wenvvar[APR_PATH_MAX]; + apr_wchar_t *wvalue; + apr_size_t inchars, outchars; + apr_status_t status; + + status = widen_envvar_name(wenvvar, APR_PATH_MAX, envvar); + if (status) + return status; + + outchars = inchars = strlen(value) + 1; + wvalue = apr_palloc(pool, outchars * sizeof(*wvalue)); + status = apr_conv_utf8_to_ucs2(value, &inchars, wvalue, &outchars); + if (status) + return status; + + if (!SetEnvironmentVariableW(wenvvar, wvalue)) + return apr_get_os_error(); + } +#endif +#if APR_HAS_ANSI_FS + ELSE_WIN_OS_IS_ANSI + { + if (!SetEnvironmentVariableA(envvar, value)) + return apr_get_os_error(); + } +#endif + + return APR_SUCCESS; +#endif +} + + +APR_DECLARE(apr_status_t) apr_env_delete(const char *envvar, apr_pool_t *pool) +{ +#if defined(_WIN32_WCE) + return APR_ENOTIMPL; +#else +#if APR_HAS_UNICODE_FS + IF_WIN_OS_IS_UNICODE + { + apr_wchar_t wenvvar[APR_PATH_MAX]; + apr_status_t status; + + status = widen_envvar_name(wenvvar, APR_PATH_MAX, envvar); + if (status) + return status; + + if (!SetEnvironmentVariableW(wenvvar, NULL)) + return apr_get_os_error(); + } +#endif +#if APR_HAS_ANSI_FS + ELSE_WIN_OS_IS_ANSI + { + if (!SetEnvironmentVariableA(envvar, NULL)) + return apr_get_os_error(); + } +#endif + + return APR_SUCCESS; +#endif +} diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/internal.c b/rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/internal.c new file mode 100644 index 00000000..b045bd42 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/internal.c @@ -0,0 +1,102 @@ +/* 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 "apr_private.h" + +#include "apr_arch_misc.h" +#include "apr_arch_file_io.h" +#include <crtdbg.h> +#include <assert.h> + +/* This module is the source of -static- helper functions that are + * entirely internal to apr. If the fn is exported - it does not + * belong here. + * + * Namespace decoration is still required to protect us from symbol + * clashes in static linkages. + */ + + +/* Shared by apr_app.c and start.c + * + * An internal apr function to convert an array of strings (either + * a counted or NULL terminated list, such as an argv[argc] or env[] + * list respectively) from wide Unicode strings to narrow utf-8 strings. + * These are allocated from the MSVCRT's _CRT_BLOCK to trick the system + * into trusting our store. + */ +int apr_wastrtoastr(char const * const * *retarr, + wchar_t const * const *arr, int args) +{ + apr_size_t elesize = 0; + char **newarr; + char *elements; + char *ele; + int arg; + + if (args < 0) { + for (args = 0; arr[args]; ++args) + ; + } + + newarr = _malloc_dbg((args + 1) * sizeof(char *), + _CRT_BLOCK, __FILE__, __LINE__); + + for (arg = 0; arg < args; ++arg) { + newarr[arg] = (void*)(wcslen(arr[arg]) + 1); + elesize += (apr_size_t)newarr[arg]; + } + + /* This is a safe max allocation, we will realloc after + * processing and return the excess to the free store. + * 3 ucs bytes hold any single wchar_t value (16 bits) + * 4 ucs bytes will hold a wchar_t pair value (20 bits) + */ + elesize = elesize * 3 + 1; + ele = elements = _malloc_dbg(elesize * sizeof(char), + _CRT_BLOCK, __FILE__, __LINE__); + + for (arg = 0; arg < args; ++arg) { + apr_size_t len = (apr_size_t)newarr[arg]; + apr_size_t newlen = elesize; + + newarr[arg] = ele; + (void)apr_conv_ucs2_to_utf8(arr[arg], &len, + newarr[arg], &elesize); + + newlen -= elesize; + ele += newlen; + assert(elesize && (len == 0)); + } + + newarr[arg] = NULL; + *(ele++) = '\0'; + + /* Return to the free store if the heap realloc is the least bit optimized + */ + ele = _realloc_dbg(elements, ele - elements, + _CRT_BLOCK, __FILE__, __LINE__); + + if (ele != elements) { + apr_size_t diff = ele - elements; + for (arg = 0; arg < args; ++arg) { + newarr[arg] += diff; + } + } + + *retarr = newarr; + return args; +} diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/misc.c b/rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/misc.c new file mode 100644 index 00000000..f121cac9 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/misc.c @@ -0,0 +1,237 @@ +/* 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 "apr_private.h" +#include "apr_arch_misc.h" +#include "crtdbg.h" +#include "apr_arch_file_io.h" +#include "assert.h" +#include "apr_lib.h" + +APR_DECLARE_DATA apr_oslevel_e apr_os_level = APR_WIN_UNK; + +apr_status_t apr_get_oslevel(apr_oslevel_e *level) +{ + if (apr_os_level == APR_WIN_UNK) + { + static OSVERSIONINFO oslev; + oslev.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + GetVersionEx(&oslev); + + if (oslev.dwPlatformId == VER_PLATFORM_WIN32_NT) + { + static unsigned int servpack = 0; + char *pservpack; + if (pservpack = oslev.szCSDVersion) { + while (*pservpack && !apr_isdigit(*pservpack)) { + pservpack++; + } + if (*pservpack) + servpack = atoi(pservpack); + } + + if (oslev.dwMajorVersion < 3) { + apr_os_level = APR_WIN_UNSUP; + } + else if (oslev.dwMajorVersion == 3) { + if (oslev.dwMajorVersion < 50) { + apr_os_level = APR_WIN_UNSUP; + } + else if (oslev.dwMajorVersion == 50) { + apr_os_level = APR_WIN_NT_3_5; + } + else { + apr_os_level = APR_WIN_NT_3_51; + } + } + else if (oslev.dwMajorVersion == 4) { + if (servpack < 2) + apr_os_level = APR_WIN_NT_4; + else if (servpack <= 2) + apr_os_level = APR_WIN_NT_4_SP2; + else if (servpack <= 3) + apr_os_level = APR_WIN_NT_4_SP3; + else if (servpack <= 4) + apr_os_level = APR_WIN_NT_4_SP4; + else if (servpack <= 5) + apr_os_level = APR_WIN_NT_4_SP5; + else + apr_os_level = APR_WIN_NT_4_SP6; + } + else if (oslev.dwMajorVersion == 5) { + if (oslev.dwMinorVersion == 0) { + if (servpack == 0) + apr_os_level = APR_WIN_2000; + else if (servpack == 1) + apr_os_level = APR_WIN_2000_SP1; + else + apr_os_level = APR_WIN_2000_SP2; + } + else { + apr_os_level = APR_WIN_XP; + } + } + else { + apr_os_level = APR_WIN_XP; + } + } +#ifndef WINNT + else if (oslev.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) { + char *prevision; + if (prevision = oslev.szCSDVersion) { + while (*prevision && !apr_isupper(*prevision)) { + prevision++; + } + } + else prevision = ""; + + if (oslev.dwMinorVersion < 10) { + if (*prevision < 'C') + apr_os_level = APR_WIN_95; + else + apr_os_level = APR_WIN_95_OSR2; + } + else if (oslev.dwMinorVersion < 90) { + if (*prevision < 'A') + apr_os_level = APR_WIN_98; + else + apr_os_level = APR_WIN_98_SE; + } + else { + apr_os_level = APR_WIN_ME; + } + } +#endif +#ifdef _WIN32_WCE + else if (oslev.dwPlatformId == VER_PLATFORM_WIN32_CE) + { + if (oslev.dwMajorVersion < 3) { + apr_os_level = APR_WIN_UNSUP; + } + else { + apr_os_level = APR_WIN_CE_3; + } + } +#endif + else { + apr_os_level = APR_WIN_UNSUP; + } + } + + *level = apr_os_level; + + if (apr_os_level < APR_WIN_UNSUP) { + return APR_EGENERAL; + } + + return APR_SUCCESS; +} + + +/* This is the helper code to resolve late bound entry points + * missing from one or more releases of the Win32 API + */ + +static const char* const lateDllName[DLL_defined] = { + "kernel32", "advapi32", "mswsock", "ws2_32", "shell32", "ntdll.dll" }; +static HMODULE lateDllHandle[DLL_defined] = { + NULL, NULL, NULL, NULL, NULL, NULL }; + +FARPROC apr_load_dll_func(apr_dlltoken_e fnLib, char* fnName, int ordinal) +{ + if (!lateDllHandle[fnLib]) { + lateDllHandle[fnLib] = LoadLibrary(lateDllName[fnLib]); + if (!lateDllHandle[fnLib]) + return NULL; + } + if (ordinal) + return GetProcAddress(lateDllHandle[fnLib], (char *) ordinal); + else + return GetProcAddress(lateDllHandle[fnLib], fnName); +} + +/* Declared in include/arch/win32/apr_dbg_win32_handles.h + */ +APR_DECLARE_NONSTD(HANDLE) apr_dbg_log(char* fn, HANDLE ha, char* fl, int ln, + int nh, /* HANDLE hv, char *dsc */...) +{ + static DWORD tlsid = 0xFFFFFFFF; + static HANDLE fh = NULL; + static long ctr = 0; + static CRITICAL_SECTION cs; + long seq; + DWORD wrote; + char *sbuf; + + seq = (InterlockedIncrement)(&ctr); + + if (tlsid == 0xFFFFFFFF) { + tlsid = (TlsAlloc)(); + } + + sbuf = (TlsGetValue)(tlsid); + if (!fh || !sbuf) { + sbuf = (malloc)(1024); + (TlsSetValue)(tlsid, sbuf); + sbuf[1023] = '\0'; + if (!fh) { + (GetModuleFileName)(NULL, sbuf, 250); + sprintf(strchr(sbuf, '\0'), ".%d", + (GetCurrentProcessId)()); + fh = (CreateFile)(sbuf, GENERIC_WRITE, 0, NULL, + CREATE_ALWAYS, 0, NULL); + (InitializeCriticalSection)(&cs); + } + } + + if (!nh) { + (sprintf)(sbuf, "%08x %08x %08x %s() %s:%d\n", + (DWORD)ha, seq, GetCurrentThreadId(), fn, fl, ln); + (EnterCriticalSection)(&cs); + (WriteFile)(fh, sbuf, strlen(sbuf), &wrote, NULL); + (LeaveCriticalSection)(&cs); + } + else { + va_list a; + va_start(a,nh); + (EnterCriticalSection)(&cs); + do { + HANDLE *hv = va_arg(a, HANDLE*); + char *dsc = va_arg(a, char*); + if (strcmp(dsc, "Signaled") == 0) { + if ((DWORD)ha >= STATUS_WAIT_0 + && (DWORD)ha < STATUS_ABANDONED_WAIT_0) { + hv += (DWORD)ha; + } + else if ((DWORD)ha >= STATUS_ABANDONED_WAIT_0 + && (DWORD)ha < STATUS_USER_APC) { + hv += (DWORD)ha - STATUS_ABANDONED_WAIT_0; + dsc = "Abandoned"; + } + else if ((DWORD)ha == WAIT_TIMEOUT) { + dsc = "Timed Out"; + } + } + (sprintf)(sbuf, "%08x %08x %08x %s(%s) %s:%d\n", + (DWORD*)*hv, seq, GetCurrentThreadId(), + fn, dsc, fl, ln); + (WriteFile)(fh, sbuf, strlen(sbuf), &wrote, NULL); + } while (--nh); + (LeaveCriticalSection)(&cs); + va_end(a); + } + return ha; +} diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/rand.c b/rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/rand.c new file mode 100644 index 00000000..e72637bf --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/rand.c @@ -0,0 +1,69 @@ +/* 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 <windows.h> +#include <wincrypt.h> +#include "apr.h" +#include "apr_private.h" +#include "apr_general.h" +#include "apr_portable.h" +#include "apr_arch_misc.h" + + +APR_DECLARE(apr_status_t) apr_generate_random_bytes(unsigned char * buf, +#ifdef APR_ENABLE_FOR_1_0 + apr_size_t length) +#else + int length) +#endif +{ + HCRYPTPROV hProv; + apr_status_t res = APR_SUCCESS; + + /* 0x40 bit = CRYPT_SILENT, only introduced in more recent PSDKs + * and will only work for Win2K and later. + */ + DWORD flags = CRYPT_VERIFYCONTEXT + | ((apr_os_level >= APR_WIN_2000) ? 0x40 : 0); + + if (!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, flags)) { + return apr_get_os_error(); + } + if (!CryptGenRandom(hProv, length, buf)) { + res = apr_get_os_error(); + } + CryptReleaseContext(hProv, 0); + return res; +} + + +APR_DECLARE(apr_status_t) apr_os_uuid_get(unsigned char *uuid_data) +{ + /* Note: this call doesn't actually require CoInitialize() first + * + * XXX: we should scramble the bytes or some such to eliminate the + * possible misuse/abuse since uuid is based on the NIC address, and + * is therefore not only a uniqifier, but an identity (which might not + * be appropriate in all cases. + * + * Note that Win2000, XP and later no longer suffer from this problem, + * a scrambling fix is only needed for (apr_os_level < APR_WIN_2000) + */ + if (FAILED(UuidCreate((UUID *)uuid_data))) { + return APR_EGENERAL; + } + return APR_SUCCESS; +} diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/start.c b/rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/start.c new file mode 100644 index 00000000..f25776be --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/start.c @@ -0,0 +1,230 @@ +/* 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 "apr_private.h" +#include "apr_general.h" +#include "apr_pools.h" +#include "apr_signal.h" +#include "shellapi.h" + +#include "apr_arch_misc.h" /* for WSAHighByte / WSALowByte */ +#include "wchar.h" +#include "apr_arch_file_io.h" /* bring in unicode-ness */ +#include "apr_arch_threadproc.h" /* bring in apr_threadproc_init */ +#include "crtdbg.h" +#include "assert.h" + +/* This symbol is _private_, although it must be exported. + */ +int APR_DECLARE_DATA apr_app_init_complete = 0; + +#if !defined(_WIN32_WCE) +/* Used by apr_app_initialize to reprocess the environment + * + * An internal apr function to convert a double-null terminated set + * of single-null terminated strings from wide Unicode to narrow utf-8 + * as a list of strings. These are allocated from the MSVCRT's + * _CRT_BLOCK to trick the system into trusting our store. + */ +static int warrsztoastr(const char * const * *retarr, + const wchar_t * arrsz, int args) +{ + const apr_wchar_t *wch; + apr_size_t totlen; + apr_size_t newlen; + apr_size_t wsize; + char **newarr; + int arg; + + if (args < 0) { + for (args = 1, wch = arrsz; wch[0] || wch[1]; ++wch) + if (!*wch) + ++args; + } + wsize = 1 + wch - arrsz; + + newarr = _malloc_dbg((args + 1) * sizeof(char *), + _CRT_BLOCK, __FILE__, __LINE__); + + /* This is a safe max allocation, we will realloc after + * processing and return the excess to the free store. + * 3 ucs bytes hold any single wchar_t value (16 bits) + * 4 ucs bytes will hold a wchar_t pair value (20 bits) + */ + newlen = totlen = wsize * 3 + 1; + newarr[0] = _malloc_dbg(newlen * sizeof(char), + _CRT_BLOCK, __FILE__, __LINE__); + + (void)apr_conv_ucs2_to_utf8(arrsz, &wsize, + newarr[0], &newlen); + + assert(newlen && !wsize); + /* Return to the free store if the heap realloc is the least bit optimized + */ + newarr[0] = _realloc_dbg(newarr[0], totlen - newlen, + _CRT_BLOCK, __FILE__, __LINE__); + + for (arg = 1; arg < args; ++arg) { + newarr[arg] = newarr[arg - 1] + 2; + while (*(newarr[arg]++)) { + /* continue */; + } + } + + newarr[arg] = NULL; + + *retarr = newarr; + return args; +} +#endif + +/* Reprocess the arguments to main() for a completely apr-ized application + */ + +APR_DECLARE(apr_status_t) apr_app_initialize(int *argc, + const char * const * *argv, + const char * const * *env) +{ + apr_status_t rv = apr_initialize(); + + if (rv != APR_SUCCESS) { + return rv; + } + +#if defined(_WIN32_WCE) + apr_app_init_complete = 1; +#elif APR_HAS_UNICODE_FS + IF_WIN_OS_IS_UNICODE + { + apr_wchar_t **wstrs; + apr_wchar_t *sysstr; + int wstrc; + int dupenv; + + if (apr_app_init_complete) { + return rv; + } + + apr_app_init_complete = 1; + + sysstr = GetCommandLineW(); + if (sysstr) { + wstrs = CommandLineToArgvW(sysstr, &wstrc); + if (wstrs) { + *argc = apr_wastrtoastr(argv, wstrs, wstrc); + GlobalFree(wstrs); + } + } + + sysstr = GetEnvironmentStringsW(); + dupenv = warrsztoastr(&_environ, sysstr, -1); + + if (env) { + *env = _malloc_dbg((dupenv + 1) * sizeof (char *), + _CRT_BLOCK, __FILE__, __LINE__ ); + memcpy((void*)*env, _environ, (dupenv + 1) * sizeof (char *)); + } + else { + } + + FreeEnvironmentStringsW(sysstr); + + /* MSVCRT will attempt to maintain the wide environment calls + * on _putenv(), which is bogus if we've passed a non-ascii + * string to _putenv(), since they use MultiByteToWideChar + * and breaking the implicit utf-8 assumption we've built. + * + * Reset _wenviron for good measure. + */ + if (_wenviron) { + apr_wchar_t **wenv = _wenviron; + _wenviron = NULL; + free(wenv); + } + + } +#endif + return rv; +} + +static int initialized = 0; + +/* Provide to win32/thread.c */ +extern DWORD tls_apr_thread; + +APR_DECLARE(apr_status_t) apr_initialize(void) +{ + apr_pool_t *pool; + apr_status_t status; + int iVersionRequested; + WSADATA wsaData; + int err; + apr_oslevel_e osver; + + if (initialized++) { + return APR_SUCCESS; + } + + /* Initialize apr_os_level global */ + if (apr_get_oslevel(&osver) != APR_SUCCESS) { + return APR_EEXIST; + } + + tls_apr_thread = TlsAlloc(); + if ((status = apr_pool_initialize()) != APR_SUCCESS) + return status; + + if (apr_pool_create(&pool, NULL) != APR_SUCCESS) { + return APR_ENOPOOL; + } + + apr_pool_tag(pool, "apr_initialize"); + + iVersionRequested = MAKEWORD(WSAHighByte, WSALowByte); + err = WSAStartup((WORD) iVersionRequested, &wsaData); + if (err) { + return err; + } + if (LOBYTE(wsaData.wVersion) != WSAHighByte || + HIBYTE(wsaData.wVersion) != WSALowByte) { + WSACleanup(); + return APR_EEXIST; + } + + apr_signal_init(pool); + + apr_threadproc_init(pool); + + return APR_SUCCESS; +} + +APR_DECLARE_NONSTD(void) apr_terminate(void) +{ + initialized--; + if (initialized) { + return; + } + apr_pool_terminate(); + + WSACleanup(); + + TlsFree(tls_apr_thread); +} + +APR_DECLARE(void) apr_terminate2(void) +{ + apr_terminate(); +} diff --git a/rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/utf8.c b/rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/utf8.c new file mode 100644 index 00000000..b37dba44 --- /dev/null +++ b/rubbos/app/httpd-2.0.64/srclib/apr/misc/win32/utf8.c @@ -0,0 +1,254 @@ +/* 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 "apr.h" +#include "apr_private.h" +#include "apr_errno.h" +#include "apr_arch_utf8.h" + +/* Implement the design principal specified by RFC 2718 2.2.5 + * Guidelines for new URL Schemes - within the APR. + * + * Since many architectures support unicode, and UCS2 is the most + * efficient storage used by those archictures, these functions + * exist to validate a UCS string. It is up to the operating system + * to determine the validitity of the string in the context of it's + * native language support. File systems that support filename + * characters of 0x80-0xff but have no support of Unicode will find + * this function useful only for validating the character sequences + * and rejecting poorly encoded strings, if RFC 2718 2.2.5 naming is + * desired. + * + * from RFC 2279 UTF-8, a transformation format of ISO 10646 + * + * UCS-4 range (hex.) UTF-8 octet sequence (binary) + * 1:2 0000 0000-0000 007F 0xxxxxxx + * 2:2 0000 0080-0000 07FF 110XXXXx 10xxxxxx + * 3:2 0000 0800-0000 FFFF 1110XXXX 10Xxxxxx 10xxxxxx + * 4:4 0001 0000-001F FFFF 11110zXX 10XXxxxx 10xxxxxx 10xxxxxx + * inv 0020 0000-03FF FFFF 111110XX 10XXXxxx 10xxxxxx 10xxxxxx 10xxxxxx + * inv 0400 0000-7FFF FFFF 1111110X 10XXXXxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx + * + * One of the X values must be one for the encoding length to be legit. + * Neither the z bit, nor the final two forms, are used for ucs-2 + * + * "Pairs of UCS-2 values between D800 and DFFF (surrogate pairs in + * Unicode parlance), being actually UCS-4 characters transformed + * through UTF-16, need special treatment: the UTF-16 transformation + * must be undone, yielding a UCS-4 character that is then transformed + * as above." + * + * from RFC2781 UTF-16: the compressed ISO 10646 encoding bitmask + * + * U' = U - 0x10000 + * U' = 000000000000yyyyyyyyyyxxxxxxxxxx + * W1 = 110110yyyyyyyyyy + * W2 = 110111xxxxxxxxxx + * + * apr_conv_utf8_to_ucs2 out bytes:sizeof(in) * 1 <= Req <= sizeof(in) * 2 + * + * apr_conv_ucs2_to_utf8 out words:sizeof(in) / 2 <= Req <= sizeof(in) * 3 / 2 + */ + +APR_DECLARE(apr_status_t) apr_conv_utf8_to_ucs2(const char *in, + apr_size_t *inbytes, + apr_wchar_t *out, + apr_size_t *outwords) +{ + apr_int64_t newch, mask; + apr_size_t expect, eating; + int ch; + + while (*inbytes && *outwords) + { + ch = (unsigned char)(*in++); + if (!(ch & 0200)) { + /* US-ASCII-7 plain text + */ + --*inbytes; + --*outwords; + *(out++) = ch; + } + else + { + if ((ch & 0300) != 0300) { + /* Multibyte Continuation is out of place + */ + return APR_EINVAL; + } + else + { + /* Multibyte Sequence Lead Character + * + * Compute the expected bytes while adjusting + * or lead byte and leading zeros mask. + */ + mask = 0340; + expect = 1; + while ((ch & mask) == mask) { + mask |= mask >> 1; + if (++expect > 3) /* (truly 5 for ucs-4) */ + return APR_EINVAL; + } + newch = ch & ~mask; + eating = expect + 1; + if (*inbytes <= expect) + return APR_INCOMPLETE; + /* Reject values of excessive leading 0 bits + * utf-8 _demands_ the shortest possible byte length + */ + if (expect == 1) { + if (!(newch & 0036)) + return APR_EINVAL; + } + else { + /* Reject values of excessive leading 0 bits + */ + if (!newch && !((unsigned char)*in & 0077 & (mask << 1))) + return APR_EINVAL; + if (expect == 2) { + /* Reject values D800-DFFF when not utf16 encoded + * (may not be an appropriate restriction for ucs-4) + */ + if (newch == 0015 && ((unsigned char)*in & 0040)) + return APR_EINVAL; + } + else if (expect == 3) { + /* Short circuit values > 110000 + */ + if (newch > 4) + return APR_EINVAL; + if (newch == 4 && ((unsigned char)*in & 0060)) + return APR_EINVAL; + } + } + /* Where the boolean (expect > 2) is true, we will need + * an extra word for the output. + */ + if (*outwords < (apr_size_t)(expect > 2) + 1) + break; /* buffer full */ + while (expect--) + { + /* Multibyte Continuation must be legal */ + if (((ch = (unsigned char)*(in++)) & 0300) != 0200) + return APR_EINVAL; + newch <<= 6; + newch |= (ch & 0077); + } + *inbytes -= eating; + /* newch is now a true ucs-4 character + * + * now we need to fold to ucs-2 + */ + if (newch < 0x10000) + { + --*outwords; + *(out++) = (apr_wchar_t) newch; + } + else + { + *outwords -= 2; + newch -= 0x10000; + *(out++) = (apr_wchar_t) (0xD800 | (newch >> 10)); + *(out++) = (apr_wchar_t) (0xDC00 | (newch & 0x03FF)); + } + } + } + } + /* Buffer full 'errors' aren't errors, the client must inspect both + * the inbytes and outwords values + */ + return APR_SUCCESS; +} + +APR_DECLARE(apr_status_t) apr_conv_ucs2_to_utf8(const apr_wchar_t *in, + apr_size_t *inwords, + char *out, + apr_size_t *outbytes) +{ + apr_int64_t newch, require; + apr_size_t need; + char *invout; + int ch; + + while (*inwords && *outbytes) + { + ch = (unsigned short)(*in++); + if (ch < 0x80) + { + --*inwords; + --*outbytes; + *(out++) = (unsigned char) ch; + } + else + { + if ((ch & 0xFC00) == 0xDC00) { + /* Invalid Leading ucs-2 Multiword Continuation Character + */ + return APR_EINVAL; + } + if ((ch & 0xFC00) == 0xD800) { + /* Leading ucs-2 Multiword Character + */ + if (*inwords < 2) { + /* Missing ucs-2 Multiword Continuation Character + */ + return APR_INCOMPLETE; + } + if (((unsigned short)(*in) & 0xFC00) != 0xDC00) { + /* Invalid ucs-2 Multiword Continuation Character + */ + return APR_EINVAL; + } + newch = (ch & 0x03FF) << 10 | ((unsigned short)(*in++) & 0x03FF); + newch += 0x10000; + } + else { + /* ucs-2 Single Word Character + */ + newch = ch; + } + /* Determine the absolute minimum utf-8 bytes required + */ + require = newch >> 11; + need = 1; + while (require) + require >>= 5, ++need; + if (need >= *outbytes) + break; /* Insufficient buffer */ + *inwords -= (need > 2) + 1; + *outbytes -= need + 1; + /* Compute the utf-8 characters in last to first order, + * calculating the lead character length bits along the way. + */ + ch = 0200; + out += need + 1; + invout = out; + while (need--) { + ch |= ch >> 1; + *(--invout) = (unsigned char)(0200 | (newch & 0077)); + newch >>= 6; + } + /* Compute the lead utf-8 character and move the dest offset + */ + *(--invout) = (unsigned char)(ch | newch); + } + } + /* Buffer full 'errors' aren't errors, the client must inspect both + * the inwords and outbytes values + */ + return APR_SUCCESS; +} |