code stringlengths 1 2.01M | repo_name stringlengths 3 62 | path stringlengths 1 267 | language stringclasses 231 values | license stringclasses 13 values | size int64 1 2.01M |
|---|---|---|---|---|---|
/* 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_general.h"
#include "apr_pools.h"
#include "apr_signal.h"
#include "apr_arch_misc.h" /* for WSAHighByte / WSALowByte */
#include "apr_arch_proc_mutex.h" /* for apr_proc_mutex_unix_setup_lock() */
#include "apr_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(apr_status_t) apr_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 apr_initialize();
}
APR_DECLARE(apr_status_t) apr_initialize(void)
{
apr_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;
}
/* apr_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 (apr_pool_create(&pool, NULL) != APR_SUCCESS) {
return APR_ENOPOOL;
}
apr_pool_tag(pool, "apr_initilialize");
#ifdef USE_WINSOCK
err = RegisterAppWithWinSock (nlmhandle);
if (err) {
return err;
}
#endif
apr_signal_init(pool);
return APR_SUCCESS;
}
APR_DECLARE_NONSTD(void) apr_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;
}
/* apr_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) apr_terminate2(void)
{
apr_terminate();
}
| 001-log4cxx | trunk/src/apr/misc/netware/start.c | C | asf20 | 6,155 |
/* 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_MEMFUNC
#include "apr_want.h"
#include "apr_general.h"
#include "apr_private.h"
#if APR_HAS_RANDOM
#include <nks/plat.h>
static int NXSeedRandomInternal( size_t width, void *seed )
{
static int init = 0;
int *s = (int *) seed;
union { int x; char y[4]; } u;
if (!init) {
srand(NXGetSystemTick());
init = 1;
}
if (width > 3)
{
do
{
*s++ = rand();
}
while ((width -= 4) > 3);
}
if (width > 0)
{
char *p = (char *) s;
u.x = rand();
while (width > 0)
*p++ = u.y[width--];
}
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_generate_random_bytes(unsigned char *buf,
apr_size_t length)
{
if (NXSeedRandom(length, buf) != 0) {
return NXSeedRandomInternal (length, buf);
}
return APR_SUCCESS;
}
#endif /* APR_HAS_RANDOM */
| 001-log4cxx | trunk/src/apr/misc/netware/rand.c | C | asf20 | 1,791 |
/* 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_private.h"
#include "apr_lib.h"
#if APR_HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if APR_HAVE_STRING_H
#include <string.h>
#endif
#if APR_HAVE_CTYPE_H
#include <ctype.h>
#endif
/*
* Apache's "replacement" for the strncpy() function. We roll our
* own to implement these specific changes:
* (1) strncpy() doesn't always null terminate and we want it to.
* (2) strncpy() null fills, which is bogus, esp. when copy 8byte
* strings into 8k blocks.
* (3) Instead of returning the pointer to the beginning of
* the destination string, we return a pointer to the
* terminating '\0' to allow us to "check" for truncation
*
* apr_cpystrn() follows the same call structure as strncpy().
*/
APR_DECLARE(char *) apr_cpystrn(char *dst, const char *src, apr_size_t dst_size)
{
char *d, *end;
if (dst_size == 0) {
return (dst);
}
d = dst;
end = dst + dst_size - 1;
for (; d < end; ++d, ++src) {
if (!(*d = *src)) {
return (d);
}
}
*d = '\0'; /* always null terminate */
return (d);
}
/*
* This function provides a way to parse a generic argument string
* into a standard argv[] form of argument list. It respects the
* usual "whitespace" and quoteing rules. In the future this could
* be expanded to include support for the apr_call_exec command line
* string processing (including converting '+' to ' ' and doing the
* url processing. It does not currently support this function.
*
* token_context: Context from which pool allocations will occur.
* arg_str: Input argument string for conversion to argv[].
* argv_out: Output location. This is a pointer to an array
* of pointers to strings (ie. &(char *argv[]).
* This value will be allocated from the contexts
* pool and filled in with copies of the tokens
* found during parsing of the arg_str.
*/
APR_DECLARE(apr_status_t) apr_tokenize_to_argv(const char *arg_str,
char ***argv_out,
apr_pool_t *token_context)
{
const char *cp;
const char *ct;
char *cleaned, *dirty;
int escaped;
int isquoted, numargs = 0, argnum;
#define SKIP_WHITESPACE(cp) \
for ( ; *cp == ' ' || *cp == '\t'; ) { \
cp++; \
};
#define CHECK_QUOTATION(cp,isquoted) \
isquoted = 0; \
if (*cp == '"') { \
isquoted = 1; \
cp++; \
} \
else if (*cp == '\'') { \
isquoted = 2; \
cp++; \
}
/* DETERMINE_NEXTSTRING:
* At exit, cp will point to one of the following: NULL, SPACE, TAB or QUOTE.
* NULL implies the argument string has been fully traversed.
*/
#define DETERMINE_NEXTSTRING(cp,isquoted) \
for ( ; *cp != '\0'; cp++) { \
if ( (isquoted && (*cp == ' ' || *cp == '\t')) \
|| (*cp == '\\' && (*(cp+1) == ' ' || *(cp+1) == '\t' || \
*(cp+1) == '"' || *(cp+1) == '\''))) { \
cp++; \
continue; \
} \
if ( (!isquoted && (*cp == ' ' || *cp == '\t')) \
|| (isquoted == 1 && *cp == '"') \
|| (isquoted == 2 && *cp == '\'') ) { \
break; \
} \
}
/* REMOVE_ESCAPE_CHARS:
* Compresses the arg string to remove all of the '\' escape chars.
* The final argv strings should not have any extra escape chars in it.
*/
#define REMOVE_ESCAPE_CHARS(cleaned, dirty, escaped) \
escaped = 0; \
while(*dirty) { \
if (!escaped && *dirty == '\\') { \
escaped = 1; \
} \
else { \
escaped = 0; \
*cleaned++ = *dirty; \
} \
++dirty; \
} \
*cleaned = 0; /* last line of macro... */
cp = arg_str;
SKIP_WHITESPACE(cp);
ct = cp;
/* This is ugly and expensive, but if anyone wants to figure a
* way to support any number of args without counting and
* allocating, please go ahead and change the code.
*
* Must account for the trailing NULL arg.
*/
numargs = 1;
while (*ct != '\0') {
CHECK_QUOTATION(ct, isquoted);
DETERMINE_NEXTSTRING(ct, isquoted);
if (*ct != '\0') {
ct++;
}
numargs++;
SKIP_WHITESPACE(ct);
}
*argv_out = apr_palloc(token_context, numargs * sizeof(char*));
/* determine first argument */
for (argnum = 0; argnum < (numargs-1); argnum++) {
SKIP_WHITESPACE(cp);
CHECK_QUOTATION(cp, isquoted);
ct = cp;
DETERMINE_NEXTSTRING(cp, isquoted);
cp++;
(*argv_out)[argnum] = apr_palloc(token_context, cp - ct);
apr_cpystrn((*argv_out)[argnum], ct, cp - ct);
cleaned = dirty = (*argv_out)[argnum];
REMOVE_ESCAPE_CHARS(cleaned, dirty, escaped);
}
(*argv_out)[argnum] = NULL;
return APR_SUCCESS;
}
/* Filepath_name_get returns the final element of the pathname.
* Using the current platform's filename syntax.
* "/foo/bar/gum" -> "gum"
* "/foo/bar/gum/" -> ""
* "gum" -> "gum"
* "wi\\n32\\stuff" -> "stuff
*
* Corrected Win32 to accept "a/b\\stuff", "a:stuff"
*/
APR_DECLARE(const char *) apr_filepath_name_get(const char *pathname)
{
const char path_separator = '/';
const char *s = strrchr(pathname, path_separator);
#ifdef WIN32
const char path_separator_win = '\\';
const char drive_separator_win = ':';
const char *s2 = strrchr(pathname, path_separator_win);
if (s2 > s) s = s2;
if (!s) s = strrchr(pathname, drive_separator_win);
#endif
return s ? ++s : pathname;
}
/* length of dest assumed >= length of src
* collapse in place (src == dest) is legal.
* returns terminating null ptr to dest string.
*/
APR_DECLARE(char *) apr_collapse_spaces(char *dest, const char *src)
{
while (*src) {
if (!apr_isspace(*src))
*dest++ = *src;
++src;
}
*dest = 0;
return (dest);
}
#if !APR_HAVE_STRDUP
char *strdup(const char *str)
{
char *sdup;
size_t len = strlen(str) + 1;
sdup = (char *) malloc(len);
memcpy(sdup, str, len);
return sdup;
}
#endif
/* The following two routines were donated for SVR4 by Andreas Vogel */
#if (!APR_HAVE_STRCASECMP && !APR_HAVE_STRICMP)
int strcasecmp(const char *a, const char *b)
{
const char *p = a;
const char *q = b;
for (p = a, q = b; *p && *q; p++, q++) {
int diff = apr_tolower(*p) - apr_tolower(*q);
if (diff)
return diff;
}
if (*p)
return 1; /* p was longer than q */
if (*q)
return -1; /* p was shorter than q */
return 0; /* Exact match */
}
#endif
#if (!APR_HAVE_STRNCASECMP && !APR_HAVE_STRNICMP)
int strncasecmp(const char *a, const char *b, size_t n)
{
const char *p = a;
const char *q = b;
for (p = a, q = b; /*NOTHING */ ; p++, q++) {
int diff;
if (p == a + n)
return 0; /* Match up to n characters */
if (!(*p && *q))
return *p - *q;
diff = apr_tolower(*p) - apr_tolower(*q);
if (diff)
return diff;
}
/*NOTREACHED */
}
#endif
/* The following routine was donated for UTS21 by dwd@bell-labs.com */
#if (!APR_HAVE_STRSTR)
char *strstr(char *s1, char *s2)
{
char *p1, *p2;
if (*s2 == '\0') {
/* an empty s2 */
return(s1);
}
while((s1 = strchr(s1, *s2)) != NULL) {
/* found first character of s2, see if the rest matches */
p1 = s1;
p2 = s2;
while (*++p1 == *++p2) {
if (*p1 == '\0') {
/* both strings ended together */
return(s1);
}
}
if (*p2 == '\0') {
/* second string ended, a match */
break;
}
/* didn't find a match here, try starting at next character in s1 */
s1++;
}
return(s1);
}
#endif
| 001-log4cxx | trunk/src/apr/strings/apr_cpystrn.c | C | asf20 | 8,912 |
/*
* Copyright (c) 1989, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Guido van Rossum.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)fnmatch.c 8.2 (Berkeley) 4/16/94";
#endif /* LIBC_SCCS and not lint */
/*
* Function fnmatch() as specified in POSIX 1003.2-1992, section B.6.
* Compares a filename or pathname to a pattern.
*/
#ifndef WIN32
#include "apr_private.h"
#endif
#include "apr_file_info.h"
#include "apr_fnmatch.h"
#include "apr_tables.h"
#include "apr_lib.h"
#include "apr_strings.h"
#include <string.h>
#if APR_HAVE_CTYPE_H
# include <ctype.h>
#endif
#define EOS '\0'
static const char *rangematch(const char *, int, int);
APR_DECLARE(apr_status_t) apr_fnmatch(const char *pattern, const char *string, int flags)
{
const char *stringstart;
char c, test;
for (stringstart = string;;) {
switch (c = *pattern++) {
case EOS:
return (*string == EOS ? APR_SUCCESS : APR_FNM_NOMATCH);
case '?':
if (*string == EOS) {
return (APR_FNM_NOMATCH);
}
if (*string == '/' && (flags & APR_FNM_PATHNAME)) {
return (APR_FNM_NOMATCH);
}
if (*string == '.' && (flags & APR_FNM_PERIOD) &&
(string == stringstart ||
((flags & APR_FNM_PATHNAME) && *(string - 1) == '/'))) {
return (APR_FNM_NOMATCH);
}
++string;
break;
case '*':
c = *pattern;
/* Collapse multiple stars. */
while (c == '*') {
c = *++pattern;
}
if (*string == '.' && (flags & APR_FNM_PERIOD) &&
(string == stringstart ||
((flags & APR_FNM_PATHNAME) && *(string - 1) == '/'))) {
return (APR_FNM_NOMATCH);
}
/* Optimize for pattern with * at end or before /. */
if (c == EOS) {
if (flags & APR_FNM_PATHNAME) {
return (strchr(string, '/') == NULL ? APR_SUCCESS : APR_FNM_NOMATCH);
}
else {
return (APR_SUCCESS);
}
}
else if (c == '/' && flags & APR_FNM_PATHNAME) {
if ((string = strchr(string, '/')) == NULL) {
return (APR_FNM_NOMATCH);
}
break;
}
/* General case, use recursion. */
while ((test = *string) != EOS) {
if (!apr_fnmatch(pattern, string, flags & ~APR_FNM_PERIOD)) {
return (APR_SUCCESS);
}
if (test == '/' && flags & APR_FNM_PATHNAME) {
break;
}
++string;
}
return (APR_FNM_NOMATCH);
case '[':
if (*string == EOS) {
return (APR_FNM_NOMATCH);
}
if (*string == '/' && flags & APR_FNM_PATHNAME) {
return (APR_FNM_NOMATCH);
}
if (*string == '.' && (flags & APR_FNM_PERIOD) &&
(string == stringstart ||
((flags & APR_FNM_PATHNAME) && *(string - 1) == '/'))) {
return (APR_FNM_NOMATCH);
}
if ((pattern = rangematch(pattern, *string, flags)) == NULL) {
return (APR_FNM_NOMATCH);
}
++string;
break;
case '\\':
if (!(flags & APR_FNM_NOESCAPE)) {
if ((c = *pattern++) == EOS) {
c = '\\';
--pattern;
}
}
/* FALLTHROUGH */
default:
if (flags & APR_FNM_CASE_BLIND) {
if (apr_tolower(c) != apr_tolower(*string)) {
return (APR_FNM_NOMATCH);
}
}
else if (c != *string) {
return (APR_FNM_NOMATCH);
}
string++;
break;
}
/* NOTREACHED */
}
}
static const char *rangematch(const char *pattern, int test, int flags)
{
int negate, ok;
char c, c2;
/*
* A bracket expression starting with an unquoted circumflex
* character produces unspecified results (IEEE 1003.2-1992,
* 3.13.2). This implementation treats it like '!', for
* consistency with the regular expression syntax.
* J.T. Conklin (conklin@ngai.kaleida.com)
*/
if ((negate = (*pattern == '!' || *pattern == '^'))) {
++pattern;
}
for (ok = 0; (c = *pattern++) != ']';) {
if (c == '\\' && !(flags & APR_FNM_NOESCAPE)) {
c = *pattern++;
}
if (c == EOS) {
return (NULL);
}
if (*pattern == '-' && (c2 = *(pattern + 1)) != EOS && c2 != ']') {
pattern += 2;
if (c2 == '\\' && !(flags & APR_FNM_NOESCAPE)) {
c2 = *pattern++;
}
if (c2 == EOS) {
return (NULL);
}
if ((c <= test && test <= c2)
|| ((flags & APR_FNM_CASE_BLIND)
&& ((apr_tolower(c) <= apr_tolower(test))
&& (apr_tolower(test) <= apr_tolower(c2))))) {
ok = 1;
}
}
else if ((c == test)
|| ((flags & APR_FNM_CASE_BLIND)
&& (apr_tolower(c) == apr_tolower(test)))) {
ok = 1;
}
}
return (ok == negate ? NULL : pattern);
}
/* This function is an Apache addition */
/* return non-zero if pattern has any glob chars in it */
APR_DECLARE(int) apr_fnmatch_test(const char *pattern)
{
int nesting;
nesting = 0;
while (*pattern) {
switch (*pattern) {
case '?':
case '*':
return 1;
case '\\':
if (*pattern++ == '\0') {
return 0;
}
break;
case '[': /* '[' is only a glob if it has a matching ']' */
++nesting;
break;
case ']':
if (nesting) {
return 1;
}
break;
}
++pattern;
}
return 0;
}
/* Find all files matching the specified pattern */
APR_DECLARE(apr_status_t) apr_match_glob(const char *pattern,
apr_array_header_t **result,
apr_pool_t *p)
{
apr_dir_t *dir;
apr_finfo_t finfo;
apr_status_t rv;
char *path;
/* XXX So, this is kind of bogus. Basically, I need to strip any leading
* directories off the pattern, but there is no portable way to do that.
* So, for now we just find the last occurance of '/' and if that doesn't
* return anything, then we look for '\'. This means that we could
* screw up on unix if the pattern is something like "foo\.*" That '\'
* isn't a directory delimiter, it is a part of the filename. To fix this,
* we really need apr_filepath_basename, which will be coming as soon as
* I get to it. rbb
*/
char *idx = strrchr(pattern, '/');
if (idx == NULL) {
idx = strrchr(pattern, '\\');
}
if (idx == NULL) {
path = ".";
}
else {
path = apr_pstrndup(p, pattern, idx - pattern);
pattern = idx + 1;
}
*result = apr_array_make(p, 0, sizeof(char *));
rv = apr_dir_open(&dir, path, p);
if (rv != APR_SUCCESS) {
return rv;
}
while (apr_dir_read(&finfo, APR_FINFO_NAME, dir) == APR_SUCCESS) {
if (apr_fnmatch(pattern, finfo.name, 0) == APR_SUCCESS) {
*(const char **)apr_array_push(*result) = apr_pstrdup(p, finfo.name);
}
}
apr_dir_close(dir);
return APR_SUCCESS;
}
| 001-log4cxx | trunk/src/apr/strings/apr_fnmatch.c | C | asf20 | 8,440 |
/* 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.
*/
#ifdef HAVE_STDDEF_H
#include <stddef.h> /* for NULL */
#endif
#include "apr.h"
#include "apr_strings.h"
#define APR_WANT_STRFUNC /* for strchr() */
#include "apr_want.h"
APR_DECLARE(char *) apr_strtok(char *str, const char *sep, char **last)
{
char *token;
if (!str) /* subsequent call */
str = *last; /* start where we left off */
/* skip characters in sep (will terminate at '\0') */
while (*str && strchr(sep, *str))
++str;
if (!*str) /* no more tokens */
return NULL;
token = str;
/* skip valid token characters to terminate token and
* prepare for the next call (will terminate at '\0)
*/
*last = token + 1;
while (**last && !strchr(sep, **last))
++*last;
if (**last) {
**last = '\0';
++*last;
}
return token;
}
| 001-log4cxx | trunk/src/apr/strings/apr_strtok.c | C | asf20 | 1,666 |
/* -*- mode: c; c-file-style: "k&r" -*-
strnatcmp.c -- Perform 'natural order' comparisons of strings in C.
Copyright (C) 2000 by Martin Pool <mbp@humbug.org.au>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include <ctype.h>
#include <string.h>
#include "apr_strings.h"
#include "apr_lib.h" /* for apr_is*() */
#if defined(__GNUC__)
# define UNUSED __attribute__((__unused__))
#else
# define UNUSED
#endif
/* based on "strnatcmp.c,v 1.6 2000/04/20 07:30:11 mbp Exp $" */
static int
compare_right(char const *a, char const *b)
{
int bias = 0;
/* The longest run of digits wins. That aside, the greatest
value wins, but we can't know that it will until we've scanned
both numbers to know that they have the same magnitude, so we
remember it in BIAS. */
for (;; a++, b++) {
if (!apr_isdigit(*a) && !apr_isdigit(*b))
break;
else if (!apr_isdigit(*a))
return -1;
else if (!apr_isdigit(*b))
return +1;
else if (*a < *b) {
if (!bias)
bias = -1;
} else if (*a > *b) {
if (!bias)
bias = +1;
} else if (!*a && !*b)
break;
}
return bias;
}
static int
compare_left(char const *a, char const *b)
{
/* Compare two left-aligned numbers: the first to have a
different value wins. */
for (;; a++, b++) {
if (!apr_isdigit(*a) && !apr_isdigit(*b))
break;
else if (!apr_isdigit(*a))
return -1;
else if (!apr_isdigit(*b))
return +1;
else if (*a < *b)
return -1;
else if (*a > *b)
return +1;
}
return 0;
}
static int strnatcmp0(char const *a, char const *b, int fold_case)
{
int ai, bi;
char ca, cb;
int fractional, result;
ai = bi = 0;
while (1) {
ca = a[ai]; cb = b[bi];
/* skip over leading spaces or zeros */
while (apr_isspace(ca))
ca = a[++ai];
while (apr_isspace(cb))
cb = b[++bi];
/* process run of digits */
if (apr_isdigit(ca) && apr_isdigit(cb)) {
fractional = (ca == '0' || cb == '0');
if (fractional) {
if ((result = compare_left(a+ai, b+bi)) != 0)
return result;
} else {
if ((result = compare_right(a+ai, b+bi)) != 0)
return result;
}
}
if (!ca && !cb) {
/* The strings compare the same. Perhaps the caller
will want to call strcmp to break the tie. */
return 0;
}
if (fold_case) {
ca = apr_toupper(ca);
cb = apr_toupper(cb);
}
if (ca < cb)
return -1;
else if (ca > cb)
return +1;
++ai; ++bi;
}
}
APR_DECLARE(int) apr_strnatcmp(char const *a, char const *b)
{
return strnatcmp0(a, b, 0);
}
/* Compare, recognizing numeric string and ignoring case. */
APR_DECLARE(int) apr_strnatcasecmp(char const *a, char const *b)
{
return strnatcmp0(a, b, 1);
}
| 001-log4cxx | trunk/src/apr/strings/.svn/text-base/apr_strnatcmp.c.svn-base | C | asf20 | 3,714 |
/* 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.
*/
/*
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "apr.h"
#include "apr_strings.h"
#include "apr_general.h"
#include "apr_private.h"
#include "apr_lib.h"
#define APR_WANT_STDIO
#define APR_WANT_STRFUNC
#include "apr_want.h"
#ifdef HAVE_STDDEF_H
#include <stddef.h> /* NULL */
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h> /* strtol and strtoll */
#endif
/** this is used to cache lengths in apr_pstrcat */
#define MAX_SAVED_LENGTHS 6
APR_DECLARE(char *) apr_pstrdup(apr_pool_t *a, const char *s)
{
char *res;
apr_size_t len;
if (s == NULL) {
return NULL;
}
len = strlen(s) + 1;
res = apr_palloc(a, len);
memcpy(res, s, len);
return res;
}
APR_DECLARE(char *) apr_pstrndup(apr_pool_t *a, const char *s, apr_size_t n)
{
char *res;
const char *end;
if (s == NULL) {
return NULL;
}
end = memchr(s, '\0', n);
if (end != NULL)
n = end - s;
res = apr_palloc(a, n + 1);
memcpy(res, s, n);
res[n] = '\0';
return res;
}
APR_DECLARE(char *) apr_pstrmemdup(apr_pool_t *a, const char *s, apr_size_t n)
{
char *res;
if (s == NULL) {
return NULL;
}
res = apr_palloc(a, n + 1);
memcpy(res, s, n);
res[n] = '\0';
return res;
}
APR_DECLARE(void *) apr_pmemdup(apr_pool_t *a, const void *m, apr_size_t n)
{
void *res;
if (m == NULL)
return NULL;
res = apr_palloc(a, n);
memcpy(res, m, n);
return res;
}
APR_DECLARE_NONSTD(char *) apr_pstrcat(apr_pool_t *a, ...)
{
char *cp, *argp, *res;
apr_size_t saved_lengths[MAX_SAVED_LENGTHS];
int nargs = 0;
/* Pass one --- find length of required string */
apr_size_t len = 0;
va_list adummy;
va_start(adummy, a);
while ((cp = va_arg(adummy, char *)) != NULL) {
apr_size_t cplen = strlen(cp);
if (nargs < MAX_SAVED_LENGTHS) {
saved_lengths[nargs++] = cplen;
}
len += cplen;
}
va_end(adummy);
/* Allocate the required string */
res = (char *) apr_palloc(a, len + 1);
cp = res;
/* Pass two --- copy the argument strings into the result space */
va_start(adummy, a);
nargs = 0;
while ((argp = va_arg(adummy, char *)) != NULL) {
if (nargs < MAX_SAVED_LENGTHS) {
len = saved_lengths[nargs++];
}
else {
len = strlen(argp);
}
memcpy(cp, argp, len);
cp += len;
}
va_end(adummy);
/* Return the result string */
*cp = '\0';
return res;
}
APR_DECLARE(char *) apr_pstrcatv(apr_pool_t *a, const struct iovec *vec,
apr_size_t nvec, apr_size_t *nbytes)
{
apr_size_t i;
apr_size_t len;
const struct iovec *src;
char *res;
char *dst;
/* Pass one --- find length of required string */
len = 0;
src = vec;
for (i = nvec; i; i--) {
len += src->iov_len;
src++;
}
if (nbytes) {
*nbytes = len;
}
/* Allocate the required string */
res = (char *) apr_palloc(a, len + 1);
/* Pass two --- copy the argument strings into the result space */
src = vec;
dst = res;
for (i = nvec; i; i--) {
memcpy(dst, src->iov_base, src->iov_len);
dst += src->iov_len;
src++;
}
/* Return the result string */
*dst = '\0';
return res;
}
#if (!APR_HAVE_MEMCHR)
void *memchr(const void *s, int c, size_t n)
{
const char *cp;
for (cp = s; n > 0; n--, cp++) {
if (*cp == c)
return (char *) cp; /* Casting away the const here */
}
return NULL;
}
#endif
#ifndef INT64_MAX
#define INT64_MAX APR_INT64_C(0x7fffffffffffffff)
#endif
#ifndef INT64_MIN
#define INT64_MIN (-APR_INT64_C(0x7fffffffffffffff) - APR_INT64_C(1))
#endif
APR_DECLARE(apr_status_t) apr_strtoff(apr_off_t *offset, const char *nptr,
char **endptr, int base)
{
errno = 0;
*offset = APR_OFF_T_STRFN(nptr, endptr, base);
return APR_FROM_OS_ERROR(errno);
}
APR_DECLARE(apr_int64_t) apr_strtoi64(const char *nptr, char **endptr, int base)
{
#ifdef APR_INT64_STRFN
return APR_INT64_STRFN(nptr, endptr, base);
#else
const char *s;
apr_int64_t acc;
apr_int64_t val;
int neg, any;
char c;
/*
* Skip white space and pick up leading +/- sign if any.
* If base is 0, allow 0x for hex and 0 for octal, else
* assume decimal; if base is already 16, allow 0x.
*/
s = nptr;
do {
c = *s++;
} while (apr_isspace(c));
if (c == '-') {
neg = 1;
c = *s++;
} else {
neg = 0;
if (c == '+')
c = *s++;
}
if ((base == 0 || base == 16) &&
c == '0' && (*s == 'x' || *s == 'X')) {
c = s[1];
s += 2;
base = 16;
}
if (base == 0)
base = c == '0' ? 8 : 10;
acc = any = 0;
if (base < 2 || base > 36) {
errno = EINVAL;
if (endptr != NULL)
*endptr = (char *)(any ? s - 1 : nptr);
return acc;
}
/* The classic bsd implementation requires div/mod operators
* to compute a cutoff. Benchmarking proves that is very, very
* evil to some 32 bit processors. Instead, look for underflow
* in both the mult and add/sub operation. Unlike the bsd impl,
* we also work strictly in a signed int64 word as we haven't
* implemented the unsigned type in win32.
*
* Set 'any' if any `digits' consumed; make it negative to indicate
* overflow.
*/
val = 0;
for ( ; ; c = *s++) {
if (c >= '0' && c <= '9')
c -= '0';
#if (('Z' - 'A') == 25)
else if (c >= 'A' && c <= 'Z')
c -= 'A' - 10;
else if (c >= 'a' && c <= 'z')
c -= 'a' - 10;
#elif APR_CHARSET_EBCDIC
else if (c >= 'A' && c <= 'I')
c -= 'A' - 10;
else if (c >= 'J' && c <= 'R')
c -= 'J' - 19;
else if (c >= 'S' && c <= 'Z')
c -= 'S' - 28;
else if (c >= 'a' && c <= 'i')
c -= 'a' - 10;
else if (c >= 'j' && c <= 'r')
c -= 'j' - 19;
else if (c >= 's' && c <= 'z')
c -= 'z' - 28;
#else
#error "CANNOT COMPILE apr_strtoi64(), only ASCII and EBCDIC supported"
#endif
else
break;
if (c >= base)
break;
val *= base;
if ( (any < 0) /* already noted an over/under flow - short circuit */
|| (neg && (val > acc || (val -= c) > acc)) /* underflow */
|| (!neg && (val < acc || (val += c) < acc))) { /* overflow */
any = -1; /* once noted, over/underflows never go away */
#ifdef APR_STRTOI64_OVERFLOW_IS_BAD_CHAR
break;
#endif
} else {
acc = val;
any = 1;
}
}
if (any < 0) {
acc = neg ? INT64_MIN : INT64_MAX;
errno = ERANGE;
} else if (!any) {
errno = EINVAL;
}
if (endptr != NULL)
*endptr = (char *)(any ? s - 1 : nptr);
return (acc);
#endif
}
APR_DECLARE(apr_int64_t) apr_atoi64(const char *buf)
{
return apr_strtoi64(buf, NULL, 10);
}
APR_DECLARE(char *) apr_itoa(apr_pool_t *p, int n)
{
const int BUFFER_SIZE = sizeof(int) * 3 + 2;
char *buf = apr_palloc(p, BUFFER_SIZE);
char *start = buf + BUFFER_SIZE - 1;
int negative;
if (n < 0) {
negative = 1;
n = -n;
}
else {
negative = 0;
}
*start = 0;
do {
*--start = '0' + (n % 10);
n /= 10;
} while (n);
if (negative) {
*--start = '-';
}
return start;
}
APR_DECLARE(char *) apr_ltoa(apr_pool_t *p, long n)
{
const int BUFFER_SIZE = sizeof(long) * 3 + 2;
char *buf = apr_palloc(p, BUFFER_SIZE);
char *start = buf + BUFFER_SIZE - 1;
int negative;
if (n < 0) {
negative = 1;
n = -n;
}
else {
negative = 0;
}
*start = 0;
do {
*--start = (char)('0' + (n % 10));
n /= 10;
} while (n);
if (negative) {
*--start = '-';
}
return start;
}
APR_DECLARE(char *) apr_off_t_toa(apr_pool_t *p, apr_off_t n)
{
const int BUFFER_SIZE = sizeof(apr_off_t) * 3 + 2;
char *buf = apr_palloc(p, BUFFER_SIZE);
char *start = buf + BUFFER_SIZE - 1;
int negative;
if (n < 0) {
negative = 1;
n = -n;
}
else {
negative = 0;
}
*start = 0;
do {
*--start = '0' + (char)(n % 10);
n /= 10;
} while (n);
if (negative) {
*--start = '-';
}
return start;
}
APR_DECLARE(char *) apr_strfsize(apr_off_t size, char *buf)
{
const char ord[] = "KMGTPE";
const char *o = ord;
int remain;
if (size < 0) {
return strcpy(buf, " - ");
}
if (size < 973) {
if (apr_snprintf(buf, 5, "%3d ", (int) size) < 0)
return strcpy(buf, "****");
return buf;
}
do {
remain = (int)(size & 1023);
size >>= 10;
if (size >= 973) {
++o;
continue;
}
if (size < 9 || (size == 9 && remain < 973)) {
if ((remain = ((remain * 5) + 256) / 512) >= 10)
++size, remain = 0;
if (apr_snprintf(buf, 5, "%d.%d%c", (int) size, remain, *o) < 0)
return strcpy(buf, "****");
return buf;
}
if (remain >= 512)
++size;
if (apr_snprintf(buf, 5, "%3d%c", (int) size, *o) < 0)
return strcpy(buf, "****");
return buf;
} while (1);
}
| 001-log4cxx | trunk/src/apr/strings/apr_strings.c | C | asf20 | 11,824 |
/* -*- mode: c; c-file-style: "k&r" -*-
strnatcmp.c -- Perform 'natural order' comparisons of strings in C.
Copyright (C) 2000 by Martin Pool <mbp@humbug.org.au>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include <ctype.h>
#include <string.h>
#include "apr_strings.h"
#include "apr_lib.h" /* for apr_is*() */
#if defined(__GNUC__)
# define UNUSED __attribute__((__unused__))
#else
# define UNUSED
#endif
/* based on "strnatcmp.c,v 1.6 2000/04/20 07:30:11 mbp Exp $" */
static int
compare_right(char const *a, char const *b)
{
int bias = 0;
/* The longest run of digits wins. That aside, the greatest
value wins, but we can't know that it will until we've scanned
both numbers to know that they have the same magnitude, so we
remember it in BIAS. */
for (;; a++, b++) {
if (!apr_isdigit(*a) && !apr_isdigit(*b))
break;
else if (!apr_isdigit(*a))
return -1;
else if (!apr_isdigit(*b))
return +1;
else if (*a < *b) {
if (!bias)
bias = -1;
} else if (*a > *b) {
if (!bias)
bias = +1;
} else if (!*a && !*b)
break;
}
return bias;
}
static int
compare_left(char const *a, char const *b)
{
/* Compare two left-aligned numbers: the first to have a
different value wins. */
for (;; a++, b++) {
if (!apr_isdigit(*a) && !apr_isdigit(*b))
break;
else if (!apr_isdigit(*a))
return -1;
else if (!apr_isdigit(*b))
return +1;
else if (*a < *b)
return -1;
else if (*a > *b)
return +1;
}
return 0;
}
static int strnatcmp0(char const *a, char const *b, int fold_case)
{
int ai, bi;
char ca, cb;
int fractional, result;
ai = bi = 0;
while (1) {
ca = a[ai]; cb = b[bi];
/* skip over leading spaces or zeros */
while (apr_isspace(ca))
ca = a[++ai];
while (apr_isspace(cb))
cb = b[++bi];
/* process run of digits */
if (apr_isdigit(ca) && apr_isdigit(cb)) {
fractional = (ca == '0' || cb == '0');
if (fractional) {
if ((result = compare_left(a+ai, b+bi)) != 0)
return result;
} else {
if ((result = compare_right(a+ai, b+bi)) != 0)
return result;
}
}
if (!ca && !cb) {
/* The strings compare the same. Perhaps the caller
will want to call strcmp to break the tie. */
return 0;
}
if (fold_case) {
ca = apr_toupper(ca);
cb = apr_toupper(cb);
}
if (ca < cb)
return -1;
else if (ca > cb)
return +1;
++ai; ++bi;
}
}
APR_DECLARE(int) apr_strnatcmp(char const *a, char const *b)
{
return strnatcmp0(a, b, 0);
}
/* Compare, recognizing numeric string and ignoring case. */
APR_DECLARE(int) apr_strnatcasecmp(char const *a, char const *b)
{
return strnatcmp0(a, b, 1);
}
| 001-log4cxx | trunk/src/apr/strings/apr_strnatcmp.c | C | asf20 | 3,714 |
/* 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_lib.h"
#include "apr_strings.h"
#include "apr_network_io.h"
#include "apr_portable.h"
#include <math.h>
#if APR_HAVE_CTYPE_H
#include <ctype.h>
#endif
#if APR_HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#if APR_HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#if APR_HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#if APR_HAVE_LIMITS_H
#include <limits.h>
#endif
#if APR_HAVE_STRING_H
#include <string.h>
#endif
typedef enum {
NO = 0, YES = 1
} boolean_e;
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
#define NUL '\0'
#define WIDE_INT long
typedef WIDE_INT wide_int;
typedef unsigned WIDE_INT u_wide_int;
typedef apr_int64_t widest_int;
#ifdef __TANDEM
/* Although Tandem supports "long long" there is no unsigned variant. */
typedef unsigned long u_widest_int;
#else
typedef apr_uint64_t u_widest_int;
#endif
typedef int bool_int;
#define S_NULL "(null)"
#define S_NULL_LEN 6
#define FLOAT_DIGITS 6
#define EXPONENT_LENGTH 10
/*
* NUM_BUF_SIZE is the size of the buffer used for arithmetic conversions
*
* NOTICE: this is a magic number; do not decrease it
*/
#define NUM_BUF_SIZE 512
/*
* cvt.c - IEEE floating point formatting routines for FreeBSD
* from GNU libc-4.6.27. Modified to be thread safe.
*/
/*
* apr_ecvt converts to decimal
* the number of digits is specified by ndigit
* decpt is set to the position of the decimal point
* sign is set to 0 for positive, 1 for negative
*/
#define NDIG 80
/* buf must have at least NDIG bytes */
static char *apr_cvt(double arg, int ndigits, int *decpt, int *sign,
int eflag, char *buf)
{
register int r2;
double fi, fj;
register char *p, *p1;
if (ndigits >= NDIG - 1)
ndigits = NDIG - 2;
r2 = 0;
*sign = 0;
p = &buf[0];
if (arg < 0) {
*sign = 1;
arg = -arg;
}
arg = modf(arg, &fi);
p1 = &buf[NDIG];
/*
* Do integer part
*/
if (fi != 0) {
p1 = &buf[NDIG];
while (p1 > &buf[0] && fi != 0) {
fj = modf(fi / 10, &fi);
*--p1 = (int) ((fj + .03) * 10) + '0';
r2++;
}
while (p1 < &buf[NDIG])
*p++ = *p1++;
}
else if (arg > 0) {
while ((fj = arg * 10) < 1) {
arg = fj;
r2--;
}
}
p1 = &buf[ndigits];
if (eflag == 0)
p1 += r2;
if (p1 < &buf[0]) {
*decpt = -ndigits;
buf[0] = '\0';
return (buf);
}
*decpt = r2;
while (p <= p1 && p < &buf[NDIG]) {
arg *= 10;
arg = modf(arg, &fj);
*p++ = (int) fj + '0';
}
if (p1 >= &buf[NDIG]) {
buf[NDIG - 1] = '\0';
return (buf);
}
p = p1;
*p1 += 5;
while (*p1 > '9') {
*p1 = '0';
if (p1 > buf)
++ * --p1;
else {
*p1 = '1';
(*decpt)++;
if (eflag == 0) {
if (p > buf)
*p = '0';
p++;
}
}
}
*p = '\0';
return (buf);
}
static char *apr_ecvt(double arg, int ndigits, int *decpt, int *sign, char *buf)
{
return (apr_cvt(arg, ndigits, decpt, sign, 1, buf));
}
static char *apr_fcvt(double arg, int ndigits, int *decpt, int *sign, char *buf)
{
return (apr_cvt(arg, ndigits, decpt, sign, 0, buf));
}
/*
* apr_gcvt - Floating output conversion to
* minimal length string
*/
static char *apr_gcvt(double number, int ndigit, char *buf, boolean_e altform)
{
int sign, decpt;
register char *p1, *p2;
register int i;
char buf1[NDIG];
p1 = apr_ecvt(number, ndigit, &decpt, &sign, buf1);
p2 = buf;
if (sign)
*p2++ = '-';
for (i = ndigit - 1; i > 0 && p1[i] == '0'; i--)
ndigit--;
if ((decpt >= 0 && decpt - ndigit > 4)
|| (decpt < 0 && decpt < -3)) { /* use E-style */
decpt--;
*p2++ = *p1++;
*p2++ = '.';
for (i = 1; i < ndigit; i++)
*p2++ = *p1++;
*p2++ = 'e';
if (decpt < 0) {
decpt = -decpt;
*p2++ = '-';
}
else
*p2++ = '+';
if (decpt / 100 > 0)
*p2++ = decpt / 100 + '0';
if (decpt / 10 > 0)
*p2++ = (decpt % 100) / 10 + '0';
*p2++ = decpt % 10 + '0';
}
else {
if (decpt <= 0) {
if (*p1 != '0')
*p2++ = '.';
while (decpt < 0) {
decpt++;
*p2++ = '0';
}
}
for (i = 1; i <= ndigit; i++) {
*p2++ = *p1++;
if (i == decpt)
*p2++ = '.';
}
if (ndigit < decpt) {
while (ndigit++ < decpt)
*p2++ = '0';
*p2++ = '.';
}
}
if (p2[-1] == '.' && !altform)
p2--;
*p2 = '\0';
return (buf);
}
/*
* The INS_CHAR macro inserts a character in the buffer and writes
* the buffer back to disk if necessary
* It uses the char pointers sp and bep:
* sp points to the next available character in the buffer
* bep points to the end-of-buffer+1
* While using this macro, note that the nextb pointer is NOT updated.
*
* NOTE: Evaluation of the c argument should not have any side-effects
*/
#define INS_CHAR(c, sp, bep, cc) \
{ \
if (sp) { \
if (sp >= bep) { \
vbuff->curpos = sp; \
if (flush_func(vbuff)) \
return -1; \
sp = vbuff->curpos; \
bep = vbuff->endpos; \
} \
*sp++ = (c); \
} \
cc++; \
}
#define NUM(c) (c - '0')
#define STR_TO_DEC(str, num) \
num = NUM(*str++); \
while (apr_isdigit(*str)) \
{ \
num *= 10 ; \
num += NUM(*str++); \
}
/*
* This macro does zero padding so that the precision
* requirement is satisfied. The padding is done by
* adding '0's to the left of the string that is going
* to be printed. We don't allow precision to be large
* enough that we continue past the start of s.
*
* NOTE: this makes use of the magic info that s is
* always based on num_buf with a size of NUM_BUF_SIZE.
*/
#define FIX_PRECISION(adjust, precision, s, s_len) \
if (adjust) { \
apr_size_t p = (precision + 1 < NUM_BUF_SIZE) \
? precision : NUM_BUF_SIZE - 1; \
while (s_len < p) \
{ \
*--s = '0'; \
s_len++; \
} \
}
/*
* Macro that does padding. The padding is done by printing
* the character ch.
*/
#define PAD(width, len, ch) \
do \
{ \
INS_CHAR(ch, sp, bep, cc); \
width--; \
} \
while (width > len)
/*
* Prefix the character ch to the string str
* Increase length
* Set the has_prefix flag
*/
#define PREFIX(str, length, ch) \
*--str = ch; \
length++; \
has_prefix=YES;
/*
* Convert num to its decimal format.
* Return value:
* - a pointer to a string containing the number (no sign)
* - len contains the length of the string
* - is_negative is set to TRUE or FALSE depending on the sign
* of the number (always set to FALSE if is_unsigned is TRUE)
*
* The caller provides a buffer for the string: that is the buf_end argument
* which is a pointer to the END of the buffer + 1 (i.e. if the buffer
* is declared as buf[ 100 ], buf_end should be &buf[ 100 ])
*
* Note: we have 2 versions. One is used when we need to use quads
* (conv_10_quad), the other when we don't (conv_10). We're assuming the
* latter is faster.
*/
static char *conv_10(register wide_int num, register bool_int is_unsigned,
register bool_int *is_negative, char *buf_end,
register apr_size_t *len)
{
register char *p = buf_end;
register u_wide_int magnitude;
if (is_unsigned) {
magnitude = (u_wide_int) num;
*is_negative = FALSE;
}
else {
*is_negative = (num < 0);
/*
* On a 2's complement machine, negating the most negative integer
* results in a number that cannot be represented as a signed integer.
* Here is what we do to obtain the number's magnitude:
* a. add 1 to the number
* b. negate it (becomes positive)
* c. convert it to unsigned
* d. add 1
*/
if (*is_negative) {
wide_int t = num + 1;
magnitude = ((u_wide_int) -t) + 1;
}
else
magnitude = (u_wide_int) num;
}
/*
* We use a do-while loop so that we write at least 1 digit
*/
do {
register u_wide_int new_magnitude = magnitude / 10;
*--p = (char) (magnitude - new_magnitude * 10 + '0');
magnitude = new_magnitude;
}
while (magnitude);
*len = buf_end - p;
return (p);
}
static char *conv_10_quad(widest_int num, register bool_int is_unsigned,
register bool_int *is_negative, char *buf_end,
register apr_size_t *len)
{
register char *p = buf_end;
u_widest_int magnitude;
/*
* We see if we can use the faster non-quad version by checking the
* number against the largest long value it can be. If <=, we
* punt to the quicker version.
*/
if ((num <= ULONG_MAX && is_unsigned)
|| (num <= LONG_MAX && num >= LONG_MIN && !is_unsigned))
return(conv_10( (wide_int)num, is_unsigned, is_negative,
buf_end, len));
if (is_unsigned) {
magnitude = (u_widest_int) num;
*is_negative = FALSE;
}
else {
*is_negative = (num < 0);
/*
* On a 2's complement machine, negating the most negative integer
* results in a number that cannot be represented as a signed integer.
* Here is what we do to obtain the number's magnitude:
* a. add 1 to the number
* b. negate it (becomes positive)
* c. convert it to unsigned
* d. add 1
*/
if (*is_negative) {
widest_int t = num + 1;
magnitude = ((u_widest_int) -t) + 1;
}
else
magnitude = (u_widest_int) num;
}
/*
* We use a do-while loop so that we write at least 1 digit
*/
do {
u_widest_int new_magnitude = magnitude / 10;
*--p = (char) (magnitude - new_magnitude * 10 + '0');
magnitude = new_magnitude;
}
while (magnitude);
*len = buf_end - p;
return (p);
}
static char *conv_in_addr(struct in_addr *ia, char *buf_end, apr_size_t *len)
{
unsigned addr = ntohl(ia->s_addr);
char *p = buf_end;
bool_int is_negative;
apr_size_t sub_len;
p = conv_10((addr & 0x000000FF) , TRUE, &is_negative, p, &sub_len);
*--p = '.';
p = conv_10((addr & 0x0000FF00) >> 8, TRUE, &is_negative, p, &sub_len);
*--p = '.';
p = conv_10((addr & 0x00FF0000) >> 16, TRUE, &is_negative, p, &sub_len);
*--p = '.';
p = conv_10((addr & 0xFF000000) >> 24, TRUE, &is_negative, p, &sub_len);
*len = buf_end - p;
return (p);
}
static char *conv_apr_sockaddr(apr_sockaddr_t *sa, char *buf_end, apr_size_t *len)
{
char *p = buf_end;
bool_int is_negative;
apr_size_t sub_len;
char *ipaddr_str;
p = conv_10(sa->port, TRUE, &is_negative, p, &sub_len);
*--p = ':';
apr_sockaddr_ip_get(&ipaddr_str, sa);
sub_len = strlen(ipaddr_str);
#if APR_HAVE_IPV6
if (sa->family == APR_INET6 &&
!IN6_IS_ADDR_V4MAPPED(&sa->sa.sin6.sin6_addr)) {
*(p - 1) = ']';
p -= sub_len + 2;
*p = '[';
memcpy(p + 1, ipaddr_str, sub_len);
}
else
#endif
{
p -= sub_len;
memcpy(p, ipaddr_str, sub_len);
}
*len = buf_end - p;
return (p);
}
#if APR_HAS_THREADS
static char *conv_os_thread_t(apr_os_thread_t *tid, char *buf_end, apr_size_t *len)
{
union {
apr_os_thread_t tid;
apr_uint64_t alignme;
} u;
int is_negative;
u.tid = *tid;
switch(sizeof(u.tid)) {
case sizeof(apr_int32_t):
return conv_10(*(apr_uint32_t *)&u.tid, TRUE, &is_negative, buf_end, len);
case sizeof(apr_int64_t):
return conv_10_quad(*(apr_uint64_t *)&u.tid, TRUE, &is_negative, buf_end, len);
default:
/* not implemented; stick 0 in the buffer */
return conv_10(0, TRUE, &is_negative, buf_end, len);
}
}
#endif
/*
* Convert a floating point number to a string formats 'f', 'e' or 'E'.
* The result is placed in buf, and len denotes the length of the string
* The sign is returned in the is_negative argument (and is not placed
* in buf).
*/
static char *conv_fp(register char format, register double num,
boolean_e add_dp, int precision, bool_int *is_negative,
char *buf, apr_size_t *len)
{
register char *s = buf;
register char *p;
int decimal_point;
char buf1[NDIG];
if (format == 'f')
p = apr_fcvt(num, precision, &decimal_point, is_negative, buf1);
else /* either e or E format */
p = apr_ecvt(num, precision + 1, &decimal_point, is_negative, buf1);
/*
* Check for Infinity and NaN
*/
if (apr_isalpha(*p)) {
*len = strlen(p);
memcpy(buf, p, *len + 1);
*is_negative = FALSE;
return (buf);
}
if (format == 'f') {
if (decimal_point <= 0) {
*s++ = '0';
if (precision > 0) {
*s++ = '.';
while (decimal_point++ < 0)
*s++ = '0';
}
else if (add_dp)
*s++ = '.';
}
else {
while (decimal_point-- > 0)
*s++ = *p++;
if (precision > 0 || add_dp)
*s++ = '.';
}
}
else {
*s++ = *p++;
if (precision > 0 || add_dp)
*s++ = '.';
}
/*
* copy the rest of p, the NUL is NOT copied
*/
while (*p)
*s++ = *p++;
if (format != 'f') {
char temp[EXPONENT_LENGTH]; /* for exponent conversion */
apr_size_t t_len;
bool_int exponent_is_negative;
*s++ = format; /* either e or E */
decimal_point--;
if (decimal_point != 0) {
p = conv_10((wide_int) decimal_point, FALSE, &exponent_is_negative,
&temp[EXPONENT_LENGTH], &t_len);
*s++ = exponent_is_negative ? '-' : '+';
/*
* Make sure the exponent has at least 2 digits
*/
if (t_len == 1)
*s++ = '0';
while (t_len--)
*s++ = *p++;
}
else {
*s++ = '+';
*s++ = '0';
*s++ = '0';
}
}
*len = s - buf;
return (buf);
}
/*
* Convert num to a base X number where X is a power of 2. nbits determines X.
* For example, if nbits is 3, we do base 8 conversion
* Return value:
* a pointer to a string containing the number
*
* The caller provides a buffer for the string: that is the buf_end argument
* which is a pointer to the END of the buffer + 1 (i.e. if the buffer
* is declared as buf[ 100 ], buf_end should be &buf[ 100 ])
*
* As with conv_10, we have a faster version which is used when
* the number isn't quad size.
*/
static char *conv_p2(register u_wide_int num, register int nbits,
char format, char *buf_end, register apr_size_t *len)
{
register int mask = (1 << nbits) - 1;
register char *p = buf_end;
static const char low_digits[] = "0123456789abcdef";
static const char upper_digits[] = "0123456789ABCDEF";
register const char *digits = (format == 'X') ? upper_digits : low_digits;
do {
*--p = digits[num & mask];
num >>= nbits;
}
while (num);
*len = buf_end - p;
return (p);
}
static char *conv_p2_quad(u_widest_int num, register int nbits,
char format, char *buf_end, register apr_size_t *len)
{
register int mask = (1 << nbits) - 1;
register char *p = buf_end;
static const char low_digits[] = "0123456789abcdef";
static const char upper_digits[] = "0123456789ABCDEF";
register const char *digits = (format == 'X') ? upper_digits : low_digits;
if (num <= ULONG_MAX)
return(conv_p2((u_wide_int)num, nbits, format, buf_end, len));
do {
*--p = digits[num & mask];
num >>= nbits;
}
while (num);
*len = buf_end - p;
return (p);
}
#if APR_HAS_THREADS
static char *conv_os_thread_t_hex(apr_os_thread_t *tid, char *buf_end, apr_size_t *len)
{
union {
apr_os_thread_t tid;
apr_uint64_t alignme;
} u;
int is_negative;
u.tid = *tid;
switch(sizeof(u.tid)) {
case sizeof(apr_int32_t):
return conv_p2(*(apr_uint32_t *)&u.tid, 4, 'x', buf_end, len);
case sizeof(apr_int64_t):
return conv_p2_quad(*(apr_uint64_t *)&u.tid, 4, 'x', buf_end, len);
default:
/* not implemented; stick 0 in the buffer */
return conv_10(0, TRUE, &is_negative, buf_end, len);
}
}
#endif
/*
* Do format conversion placing the output in buffer
*/
APR_DECLARE(int) apr_vformatter(int (*flush_func)(apr_vformatter_buff_t *),
apr_vformatter_buff_t *vbuff, const char *fmt, va_list ap)
{
register char *sp;
register char *bep;
register int cc = 0;
register apr_size_t i;
register char *s = NULL;
char *q;
apr_size_t s_len;
register apr_size_t min_width = 0;
apr_size_t precision = 0;
enum {
LEFT, RIGHT
} adjust;
char pad_char;
char prefix_char;
double fp_num;
widest_int i_quad = (widest_int) 0;
u_widest_int ui_quad;
wide_int i_num = (wide_int) 0;
u_wide_int ui_num;
char num_buf[NUM_BUF_SIZE];
char char_buf[2]; /* for printing %% and %<unknown> */
enum var_type_enum {
IS_QUAD, IS_LONG, IS_SHORT, IS_INT
};
enum var_type_enum var_type = IS_INT;
/*
* Flag variables
*/
boolean_e alternate_form;
boolean_e print_sign;
boolean_e print_blank;
boolean_e adjust_precision;
boolean_e adjust_width;
bool_int is_negative;
sp = vbuff->curpos;
bep = vbuff->endpos;
while (*fmt) {
if (*fmt != '%') {
INS_CHAR(*fmt, sp, bep, cc);
}
else {
/*
* Default variable settings
*/
boolean_e print_something = YES;
adjust = RIGHT;
alternate_form = print_sign = print_blank = NO;
pad_char = ' ';
prefix_char = NUL;
fmt++;
/*
* Try to avoid checking for flags, width or precision
*/
if (!apr_islower(*fmt)) {
/*
* Recognize flags: -, #, BLANK, +
*/
for (;; fmt++) {
if (*fmt == '-')
adjust = LEFT;
else if (*fmt == '+')
print_sign = YES;
else if (*fmt == '#')
alternate_form = YES;
else if (*fmt == ' ')
print_blank = YES;
else if (*fmt == '0')
pad_char = '0';
else
break;
}
/*
* Check if a width was specified
*/
if (apr_isdigit(*fmt)) {
STR_TO_DEC(fmt, min_width);
adjust_width = YES;
}
else if (*fmt == '*') {
int v = va_arg(ap, int);
fmt++;
adjust_width = YES;
if (v < 0) {
adjust = LEFT;
min_width = (apr_size_t)(-v);
}
else
min_width = (apr_size_t)v;
}
else
adjust_width = NO;
/*
* Check if a precision was specified
*/
if (*fmt == '.') {
adjust_precision = YES;
fmt++;
if (apr_isdigit(*fmt)) {
STR_TO_DEC(fmt, precision);
}
else if (*fmt == '*') {
int v = va_arg(ap, int);
fmt++;
precision = (v < 0) ? 0 : (apr_size_t)v;
}
else
precision = 0;
}
else
adjust_precision = NO;
}
else
adjust_precision = adjust_width = NO;
/*
* Modifier check. Note that if APR_INT64_T_FMT is "d",
* the first if condition is never true.
*/
if ((sizeof(APR_INT64_T_FMT) == 4 &&
fmt[0] == APR_INT64_T_FMT[0] &&
fmt[1] == APR_INT64_T_FMT[1]) ||
(sizeof(APR_INT64_T_FMT) == 3 &&
fmt[0] == APR_INT64_T_FMT[0]) ||
(sizeof(APR_INT64_T_FMT) > 4 &&
strncmp(fmt, APR_INT64_T_FMT,
sizeof(APR_INT64_T_FMT) - 2) == 0)) {
/* Need to account for trailing 'd' and null in sizeof() */
var_type = IS_QUAD;
fmt += (sizeof(APR_INT64_T_FMT) - 2);
}
else if (*fmt == 'q') {
var_type = IS_QUAD;
fmt++;
}
else if (*fmt == 'l') {
var_type = IS_LONG;
fmt++;
}
else if (*fmt == 'h') {
var_type = IS_SHORT;
fmt++;
}
else {
var_type = IS_INT;
}
/*
* Argument extraction and printing.
* First we determine the argument type.
* Then, we convert the argument to a string.
* On exit from the switch, s points to the string that
* must be printed, s_len has the length of the string
* The precision requirements, if any, are reflected in s_len.
*
* NOTE: pad_char may be set to '0' because of the 0 flag.
* It is reset to ' ' by non-numeric formats
*/
switch (*fmt) {
case 'u':
if (var_type == IS_QUAD) {
i_quad = va_arg(ap, u_widest_int);
s = conv_10_quad(i_quad, 1, &is_negative,
&num_buf[NUM_BUF_SIZE], &s_len);
}
else {
if (var_type == IS_LONG)
i_num = (wide_int) va_arg(ap, u_wide_int);
else if (var_type == IS_SHORT)
i_num = (wide_int) (unsigned short) va_arg(ap, unsigned int);
else
i_num = (wide_int) va_arg(ap, unsigned int);
s = conv_10(i_num, 1, &is_negative,
&num_buf[NUM_BUF_SIZE], &s_len);
}
FIX_PRECISION(adjust_precision, precision, s, s_len);
break;
case 'd':
case 'i':
if (var_type == IS_QUAD) {
i_quad = va_arg(ap, widest_int);
s = conv_10_quad(i_quad, 0, &is_negative,
&num_buf[NUM_BUF_SIZE], &s_len);
}
else {
if (var_type == IS_LONG)
i_num = (wide_int) va_arg(ap, wide_int);
else if (var_type == IS_SHORT)
i_num = (wide_int) (short) va_arg(ap, int);
else
i_num = (wide_int) va_arg(ap, int);
s = conv_10(i_num, 0, &is_negative,
&num_buf[NUM_BUF_SIZE], &s_len);
}
FIX_PRECISION(adjust_precision, precision, s, s_len);
if (is_negative)
prefix_char = '-';
else if (print_sign)
prefix_char = '+';
else if (print_blank)
prefix_char = ' ';
break;
case 'o':
if (var_type == IS_QUAD) {
ui_quad = va_arg(ap, u_widest_int);
s = conv_p2_quad(ui_quad, 3, *fmt,
&num_buf[NUM_BUF_SIZE], &s_len);
}
else {
if (var_type == IS_LONG)
ui_num = (u_wide_int) va_arg(ap, u_wide_int);
else if (var_type == IS_SHORT)
ui_num = (u_wide_int) (unsigned short) va_arg(ap, unsigned int);
else
ui_num = (u_wide_int) va_arg(ap, unsigned int);
s = conv_p2(ui_num, 3, *fmt,
&num_buf[NUM_BUF_SIZE], &s_len);
}
FIX_PRECISION(adjust_precision, precision, s, s_len);
if (alternate_form && *s != '0') {
*--s = '0';
s_len++;
}
break;
case 'x':
case 'X':
if (var_type == IS_QUAD) {
ui_quad = va_arg(ap, u_widest_int);
s = conv_p2_quad(ui_quad, 4, *fmt,
&num_buf[NUM_BUF_SIZE], &s_len);
}
else {
if (var_type == IS_LONG)
ui_num = (u_wide_int) va_arg(ap, u_wide_int);
else if (var_type == IS_SHORT)
ui_num = (u_wide_int) (unsigned short) va_arg(ap, unsigned int);
else
ui_num = (u_wide_int) va_arg(ap, unsigned int);
s = conv_p2(ui_num, 4, *fmt,
&num_buf[NUM_BUF_SIZE], &s_len);
}
FIX_PRECISION(adjust_precision, precision, s, s_len);
if (alternate_form && i_num != 0) {
*--s = *fmt; /* 'x' or 'X' */
*--s = '0';
s_len += 2;
}
break;
case 's':
s = va_arg(ap, char *);
if (s != NULL) {
if (!adjust_precision) {
s_len = strlen(s);
}
else {
/* From the C library standard in section 7.9.6.1:
* ...if the precision is specified, no more then
* that many characters are written. If the
* precision is not specified or is greater
* than the size of the array, the array shall
* contain a null character.
*
* My reading is is precision is specified and
* is less then or equal to the size of the
* array, no null character is required. So
* we can't do a strlen.
*
* This figures out the length of the string
* up to the precision. Once it's long enough
* for the specified precision, we don't care
* anymore.
*
* NOTE: you must do the length comparison
* before the check for the null character.
* Otherwise, you'll check one beyond the
* last valid character.
*/
const char *walk;
for (walk = s, s_len = 0;
(s_len < precision) && (*walk != '\0');
++walk, ++s_len);
}
}
else {
s = S_NULL;
s_len = S_NULL_LEN;
}
pad_char = ' ';
break;
case 'f':
case 'e':
case 'E':
fp_num = va_arg(ap, double);
/*
* We use &num_buf[ 1 ], so that we have room for the sign
*/
s = NULL;
#ifdef HAVE_ISNAN
if (isnan(fp_num)) {
s = "nan";
s_len = 3;
}
#endif
#ifdef HAVE_ISINF
if (!s && isinf(fp_num)) {
s = "inf";
s_len = 3;
}
#endif
if (!s) {
s = conv_fp(*fmt, fp_num, alternate_form,
(adjust_precision == NO) ? FLOAT_DIGITS : precision,
&is_negative, &num_buf[1], &s_len);
if (is_negative)
prefix_char = '-';
else if (print_sign)
prefix_char = '+';
else if (print_blank)
prefix_char = ' ';
}
break;
case 'g':
case 'G':
if (adjust_precision == NO)
precision = FLOAT_DIGITS;
else if (precision == 0)
precision = 1;
/*
* * We use &num_buf[ 1 ], so that we have room for the sign
*/
s = apr_gcvt(va_arg(ap, double), precision, &num_buf[1],
alternate_form);
if (*s == '-')
prefix_char = *s++;
else if (print_sign)
prefix_char = '+';
else if (print_blank)
prefix_char = ' ';
s_len = strlen(s);
if (alternate_form && (q = strchr(s, '.')) == NULL) {
s[s_len++] = '.';
s[s_len] = '\0'; /* delimit for following strchr() */
}
if (*fmt == 'G' && (q = strchr(s, 'e')) != NULL)
*q = 'E';
break;
case 'c':
char_buf[0] = (char) (va_arg(ap, int));
s = &char_buf[0];
s_len = 1;
pad_char = ' ';
break;
case '%':
char_buf[0] = '%';
s = &char_buf[0];
s_len = 1;
pad_char = ' ';
break;
case 'n':
if (var_type == IS_QUAD)
*(va_arg(ap, widest_int *)) = cc;
else if (var_type == IS_LONG)
*(va_arg(ap, long *)) = cc;
else if (var_type == IS_SHORT)
*(va_arg(ap, short *)) = cc;
else
*(va_arg(ap, int *)) = cc;
print_something = NO;
break;
/*
* This is where we extend the printf format, with a second
* type specifier
*/
case 'p':
switch(*++fmt) {
/*
* If the pointer size is equal to or smaller than the size
* of the largest unsigned int, we convert the pointer to a
* hex number, otherwise we print "%p" to indicate that we
* don't handle "%p".
*/
case 'p':
#ifdef APR_VOID_P_IS_QUAD
if (sizeof(void *) <= sizeof(u_widest_int)) {
ui_quad = (u_widest_int) va_arg(ap, void *);
s = conv_p2_quad(ui_quad, 4, 'x',
&num_buf[NUM_BUF_SIZE], &s_len);
}
#else
if (sizeof(void *) <= sizeof(u_wide_int)) {
ui_num = (u_wide_int) va_arg(ap, void *);
s = conv_p2(ui_num, 4, 'x',
&num_buf[NUM_BUF_SIZE], &s_len);
}
#endif
else {
s = "%p";
s_len = 2;
prefix_char = NUL;
}
pad_char = ' ';
break;
/* print an apr_sockaddr_t as a.b.c.d:port */
case 'I':
{
apr_sockaddr_t *sa;
sa = va_arg(ap, apr_sockaddr_t *);
if (sa != NULL) {
s = conv_apr_sockaddr(sa, &num_buf[NUM_BUF_SIZE], &s_len);
if (adjust_precision && precision < s_len)
s_len = precision;
}
else {
s = S_NULL;
s_len = S_NULL_LEN;
}
pad_char = ' ';
}
break;
/* print a struct in_addr as a.b.c.d */
case 'A':
{
struct in_addr *ia;
ia = va_arg(ap, struct in_addr *);
if (ia != NULL) {
s = conv_in_addr(ia, &num_buf[NUM_BUF_SIZE], &s_len);
if (adjust_precision && precision < s_len)
s_len = precision;
}
else {
s = S_NULL;
s_len = S_NULL_LEN;
}
pad_char = ' ';
}
break;
case 'T':
#if APR_HAS_THREADS
{
apr_os_thread_t *tid;
tid = va_arg(ap, apr_os_thread_t *);
if (tid != NULL) {
s = conv_os_thread_t(tid, &num_buf[NUM_BUF_SIZE], &s_len);
if (adjust_precision && precision < s_len)
s_len = precision;
}
else {
s = S_NULL;
s_len = S_NULL_LEN;
}
pad_char = ' ';
}
#else
char_buf[0] = '0';
s = &char_buf[0];
s_len = 1;
pad_char = ' ';
#endif
break;
case 't':
#if APR_HAS_THREADS
{
apr_os_thread_t *tid;
tid = va_arg(ap, apr_os_thread_t *);
if (tid != NULL) {
s = conv_os_thread_t_hex(tid, &num_buf[NUM_BUF_SIZE], &s_len);
if (adjust_precision && precision < s_len)
s_len = precision;
}
else {
s = S_NULL;
s_len = S_NULL_LEN;
}
pad_char = ' ';
}
#else
char_buf[0] = '0';
s = &char_buf[0];
s_len = 1;
pad_char = ' ';
#endif
break;
case NUL:
/* if %p ends the string, oh well ignore it */
continue;
default:
s = "bogus %p";
s_len = 8;
prefix_char = NUL;
(void)va_arg(ap, void *); /* skip the bogus argument on the stack */
break;
}
break;
case NUL:
/*
* The last character of the format string was %.
* We ignore it.
*/
continue;
/*
* The default case is for unrecognized %'s.
* We print %<char> to help the user identify what
* option is not understood.
* This is also useful in case the user wants to pass
* the output of format_converter to another function
* that understands some other %<char> (like syslog).
* Note that we can't point s inside fmt because the
* unknown <char> could be preceded by width etc.
*/
default:
char_buf[0] = '%';
char_buf[1] = *fmt;
s = char_buf;
s_len = 2;
pad_char = ' ';
break;
}
if (prefix_char != NUL && s != S_NULL && s != char_buf) {
*--s = prefix_char;
s_len++;
}
if (adjust_width && adjust == RIGHT && min_width > s_len) {
if (pad_char == '0' && prefix_char != NUL) {
INS_CHAR(*s, sp, bep, cc);
s++;
s_len--;
min_width--;
}
PAD(min_width, s_len, pad_char);
}
/*
* Print the string s.
*/
if (print_something == YES) {
for (i = s_len; i != 0; i--) {
INS_CHAR(*s, sp, bep, cc);
s++;
}
}
if (adjust_width && adjust == LEFT && min_width > s_len)
PAD(min_width, s_len, pad_char);
}
fmt++;
}
vbuff->curpos = sp;
return cc;
}
static int snprintf_flush(apr_vformatter_buff_t *vbuff)
{
/* if the buffer fills we have to abort immediately, there is no way
* to "flush" an apr_snprintf... there's nowhere to flush it to.
*/
return -1;
}
APR_DECLARE_NONSTD(int) apr_snprintf(char *buf, apr_size_t len,
const char *format, ...)
{
int cc;
va_list ap;
apr_vformatter_buff_t vbuff;
if (len == 0) {
/* NOTE: This is a special case; we just want to return the number
* of chars that would be written (minus \0) if the buffer
* size was infinite. We leverage the fact that INS_CHAR
* just does actual inserts iff the buffer pointer is non-NULL.
* In this case, we don't care what buf is; it can be NULL, since
* we don't touch it at all.
*/
vbuff.curpos = NULL;
vbuff.endpos = NULL;
} else {
/* save one byte for nul terminator */
vbuff.curpos = buf;
vbuff.endpos = buf + len - 1;
}
va_start(ap, format);
cc = apr_vformatter(snprintf_flush, &vbuff, format, ap);
va_end(ap);
if (len != 0) {
*vbuff.curpos = '\0';
}
return (cc == -1) ? (int)len - 1 : cc;
}
APR_DECLARE(int) apr_vsnprintf(char *buf, apr_size_t len, const char *format,
va_list ap)
{
int cc;
apr_vformatter_buff_t vbuff;
if (len == 0) {
/* See above note */
vbuff.curpos = NULL;
vbuff.endpos = NULL;
} else {
/* save one byte for nul terminator */
vbuff.curpos = buf;
vbuff.endpos = buf + len - 1;
}
cc = apr_vformatter(snprintf_flush, &vbuff, format, ap);
if (len != 0) {
*vbuff.curpos = '\0';
}
return (cc == -1) ? (int)len - 1 : cc;
}
| 001-log4cxx | trunk/src/apr/strings/apr_snprintf.c | C | asf20 | 41,813 |
/* 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_general.h"
#include "apr_strings.h"
#include "win32/apr_arch_thread_mutex.h"
#include "win32/apr_arch_thread_cond.h"
#include "apr_portable.h"
static apr_status_t thread_cond_cleanup(void *data)
{
apr_thread_cond_t *cond = data;
CloseHandle(cond->event);
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_cond_create(apr_thread_cond_t **cond,
apr_pool_t *pool)
{
*cond = apr_palloc(pool, sizeof(**cond));
(*cond)->pool = pool;
(*cond)->event = CreateEvent(NULL, TRUE, FALSE, NULL);
(*cond)->signal_all = 0;
(*cond)->num_waiting = 0;
return APR_SUCCESS;
}
static APR_INLINE apr_status_t _thread_cond_timedwait(apr_thread_cond_t *cond,
apr_thread_mutex_t *mutex,
DWORD timeout_ms )
{
DWORD res;
while (1) {
cond->num_waiting++;
apr_thread_mutex_unlock(mutex);
res = WaitForSingleObject(cond->event, timeout_ms);
apr_thread_mutex_lock(mutex);
cond->num_waiting--;
if (res != WAIT_OBJECT_0) {
apr_status_t rv = apr_get_os_error();
if (res == WAIT_TIMEOUT) {
return APR_TIMEUP;
}
return apr_get_os_error();
}
if (cond->signal_all) {
if (cond->num_waiting == 0) {
cond->signal_all = 0;
cond->signalled = 0;
ResetEvent(cond->event);
}
break;
}
else if (cond->signalled) {
cond->signalled = 0;
ResetEvent(cond->event);
break;
}
}
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_cond_wait(apr_thread_cond_t *cond,
apr_thread_mutex_t *mutex)
{
return _thread_cond_timedwait(cond, mutex, INFINITE);
}
APR_DECLARE(apr_status_t) apr_thread_cond_timedwait(apr_thread_cond_t *cond,
apr_thread_mutex_t *mutex,
apr_interval_time_t timeout)
{
DWORD timeout_ms = (DWORD) apr_time_as_msec(timeout);
return _thread_cond_timedwait(cond, mutex, timeout_ms);
}
APR_DECLARE(apr_status_t) apr_thread_cond_signal(apr_thread_cond_t *cond)
{
apr_status_t rv = APR_SUCCESS;
DWORD res;
cond->signalled = 1;
res = SetEvent(cond->event);
if (res == 0) {
rv = apr_get_os_error();
}
return rv;
}
APR_DECLARE(apr_status_t) apr_thread_cond_broadcast(apr_thread_cond_t *cond)
{
apr_status_t rv = APR_SUCCESS;
DWORD res;
cond->signalled = 1;
cond->signal_all = 1;
res = SetEvent(cond->event);
if (res == 0) {
rv = apr_get_os_error();
}
return rv;
}
APR_DECLARE(apr_status_t) apr_thread_cond_destroy(apr_thread_cond_t *cond)
{
return apr_pool_cleanup_run(cond->pool, cond, thread_cond_cleanup);
}
APR_POOL_IMPLEMENT_ACCESSOR(thread_cond)
| 001-log4cxx | trunk/src/apr/locks/win32/thread_cond.c | C | asf20 | 3,913 |
/* 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_general.h"
#include "apr_strings.h"
#include "apr_arch_thread_mutex.h"
#include "apr_thread_mutex.h"
#include "apr_portable.h"
#include "apr_arch_misc.h"
static apr_status_t thread_mutex_cleanup(void *data)
{
apr_thread_mutex_t *lock = data;
if (lock->type == thread_mutex_critical_section) {
lock->type = -1;
DeleteCriticalSection(&lock->section);
}
else {
if (!CloseHandle(lock->handle)) {
return apr_get_os_error();
}
}
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_mutex_create(apr_thread_mutex_t **mutex,
unsigned int flags,
apr_pool_t *pool)
{
(*mutex) = (apr_thread_mutex_t *)apr_palloc(pool, sizeof(**mutex));
(*mutex)->pool = pool;
if (flags & APR_THREAD_MUTEX_UNNESTED) {
/* Use an auto-reset signaled event, ready to accept one
* waiting thread.
*/
(*mutex)->type = thread_mutex_unnested_event;
(*mutex)->handle = CreateEvent(NULL, FALSE, TRUE, NULL);
}
else {
#if APR_HAS_UNICODE_FS
/* Critical Sections are terrific, performance-wise, on NT.
* On Win9x, we cannot 'try' on a critical section, so we
* use a [slower] mutex object, instead.
*/
IF_WIN_OS_IS_UNICODE {
InitializeCriticalSection(&(*mutex)->section);
(*mutex)->type = thread_mutex_critical_section;
}
#endif
#if APR_HAS_ANSI_FS
ELSE_WIN_OS_IS_ANSI {
(*mutex)->type = thread_mutex_nested_mutex;
(*mutex)->handle = CreateMutex(NULL, FALSE, NULL);
}
#endif
}
apr_pool_cleanup_register((*mutex)->pool, (*mutex), thread_mutex_cleanup,
apr_pool_cleanup_null);
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_mutex_lock(apr_thread_mutex_t *mutex)
{
if (mutex->type == thread_mutex_critical_section) {
EnterCriticalSection(&mutex->section);
}
else {
DWORD rv = WaitForSingleObject(mutex->handle, INFINITE);
if ((rv != WAIT_OBJECT_0) && (rv != WAIT_ABANDONED)) {
return (rv == WAIT_TIMEOUT) ? APR_EBUSY : apr_get_os_error();
}
}
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_mutex_trylock(apr_thread_mutex_t *mutex)
{
if (mutex->type == thread_mutex_critical_section) {
if (!TryEnterCriticalSection(&mutex->section)) {
return APR_EBUSY;
}
}
else {
DWORD rv = WaitForSingleObject(mutex->handle, 0);
if ((rv != WAIT_OBJECT_0) && (rv != WAIT_ABANDONED)) {
return (rv == WAIT_TIMEOUT) ? APR_EBUSY : apr_get_os_error();
}
}
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_mutex_unlock(apr_thread_mutex_t *mutex)
{
if (mutex->type == thread_mutex_critical_section) {
LeaveCriticalSection(&mutex->section);
}
else if (mutex->type == thread_mutex_unnested_event) {
if (!SetEvent(mutex->handle)) {
return apr_get_os_error();
}
}
else if (mutex->type == thread_mutex_nested_mutex) {
if (!ReleaseMutex(mutex->handle)) {
return apr_get_os_error();
}
}
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_mutex_destroy(apr_thread_mutex_t *mutex)
{
return apr_pool_cleanup_run(mutex->pool, mutex, thread_mutex_cleanup);
}
APR_POOL_IMPLEMENT_ACCESSOR(thread_mutex)
| 001-log4cxx | trunk/src/apr/locks/win32/thread_mutex.c | C | asf20 | 4,359 |
/* 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_general.h"
#include "apr_strings.h"
#include "apr_portable.h"
#include "apr_arch_file_io.h"
#include "apr_arch_proc_mutex.h"
#include "apr_arch_misc.h"
static apr_status_t proc_mutex_cleanup(void *mutex_)
{
apr_proc_mutex_t *mutex = mutex_;
if (mutex->handle) {
if (CloseHandle(mutex->handle) == 0) {
return apr_get_os_error();
}
}
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_proc_mutex_create(apr_proc_mutex_t **mutex,
const char *fname,
apr_lockmech_e mech,
apr_pool_t *pool)
{
HANDLE hMutex;
void *mutexkey;
/* res_name_from_filename turns fname into a pseduo-name
* without slashes or backslashes, and prepends the \global
* prefix on Win2K and later
*/
if (fname) {
mutexkey = res_name_from_filename(fname, 1, pool);
}
else {
mutexkey = NULL;
}
#if APR_HAS_UNICODE_FS
IF_WIN_OS_IS_UNICODE
{
hMutex = CreateMutexW(NULL, FALSE, mutexkey);
}
#endif
#if APR_HAS_ANSI_FS
ELSE_WIN_OS_IS_ANSI
{
hMutex = CreateMutexA(NULL, FALSE, mutexkey);
}
#endif
if (!hMutex) {
return apr_get_os_error();
}
*mutex = (apr_proc_mutex_t *)apr_palloc(pool, sizeof(apr_proc_mutex_t));
(*mutex)->pool = pool;
(*mutex)->handle = hMutex;
(*mutex)->fname = fname;
apr_pool_cleanup_register((*mutex)->pool, *mutex,
proc_mutex_cleanup, apr_pool_cleanup_null);
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_proc_mutex_child_init(apr_proc_mutex_t **mutex,
const char *fname,
apr_pool_t *pool)
{
HANDLE hMutex;
void *mutexkey;
if (!fname) {
/* Reinitializing unnamed mutexes is a noop in the Unix code. */
return APR_SUCCESS;
}
/* res_name_from_filename turns file into a pseudo-name
* without slashes or backslashes, and prepends the \global
* prefix on Win2K and later
*/
mutexkey = res_name_from_filename(fname, 1, pool);
#if APR_HAS_UNICODE_FS
IF_WIN_OS_IS_UNICODE
{
hMutex = OpenMutexW(MUTEX_ALL_ACCESS, FALSE, mutexkey);
}
#endif
#if APR_HAS_ANSI_FS
ELSE_WIN_OS_IS_ANSI
{
hMutex = OpenMutexA(MUTEX_ALL_ACCESS, FALSE, mutexkey);
}
#endif
if (!hMutex) {
return apr_get_os_error();
}
*mutex = (apr_proc_mutex_t *)apr_palloc(pool, sizeof(apr_proc_mutex_t));
(*mutex)->pool = pool;
(*mutex)->handle = hMutex;
(*mutex)->fname = fname;
apr_pool_cleanup_register((*mutex)->pool, *mutex,
proc_mutex_cleanup, apr_pool_cleanup_null);
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_proc_mutex_lock(apr_proc_mutex_t *mutex)
{
DWORD rv;
rv = WaitForSingleObject(mutex->handle, INFINITE);
if (rv == WAIT_OBJECT_0 || rv == WAIT_ABANDONED) {
return APR_SUCCESS;
}
else if (rv == WAIT_TIMEOUT) {
return APR_EBUSY;
}
return apr_get_os_error();
}
APR_DECLARE(apr_status_t) apr_proc_mutex_trylock(apr_proc_mutex_t *mutex)
{
DWORD rv;
rv = WaitForSingleObject(mutex->handle, 0);
if (rv == WAIT_OBJECT_0 || rv == WAIT_ABANDONED) {
return APR_SUCCESS;
}
else if (rv == WAIT_TIMEOUT) {
return APR_EBUSY;
}
return apr_get_os_error();
}
APR_DECLARE(apr_status_t) apr_proc_mutex_unlock(apr_proc_mutex_t *mutex)
{
if (ReleaseMutex(mutex->handle) == 0) {
return apr_get_os_error();
}
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_proc_mutex_destroy(apr_proc_mutex_t *mutex)
{
apr_status_t stat;
stat = proc_mutex_cleanup(mutex);
if (stat == APR_SUCCESS) {
apr_pool_cleanup_kill(mutex->pool, mutex, proc_mutex_cleanup);
}
return stat;
}
APR_DECLARE(apr_status_t) apr_proc_mutex_cleanup(void *mutex)
{
return apr_proc_mutex_destroy((apr_proc_mutex_t *)mutex);
}
APR_DECLARE(const char *) apr_proc_mutex_lockfile(apr_proc_mutex_t *mutex)
{
return NULL;
}
APR_DECLARE(const char *) apr_proc_mutex_name(apr_proc_mutex_t *mutex)
{
return mutex->fname;
}
APR_DECLARE(const char *) apr_proc_mutex_defname(void)
{
return "win32mutex";
}
APR_POOL_IMPLEMENT_ACCESSOR(proc_mutex)
/* Implement OS-specific accessors defined in apr_portable.h */
APR_DECLARE(apr_status_t) apr_os_proc_mutex_get(apr_os_proc_mutex_t *ospmutex,
apr_proc_mutex_t *mutex)
{
*ospmutex = mutex->handle;
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_os_proc_mutex_put(apr_proc_mutex_t **pmutex,
apr_os_proc_mutex_t *ospmutex,
apr_pool_t *pool)
{
if (pool == NULL) {
return APR_ENOPOOL;
}
if ((*pmutex) == NULL) {
(*pmutex) = (apr_proc_mutex_t *)apr_palloc(pool,
sizeof(apr_proc_mutex_t));
(*pmutex)->pool = pool;
}
(*pmutex)->handle = *ospmutex;
return APR_SUCCESS;
}
| 001-log4cxx | trunk/src/apr/locks/win32/proc_mutex.c | C | asf20 | 6,131 |
/* 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_general.h"
#include "apr_strings.h"
#include "win32/apr_arch_thread_rwlock.h"
#include "apr_portable.h"
static apr_status_t thread_rwlock_cleanup(void *data)
{
apr_thread_rwlock_t *rwlock = data;
if (! CloseHandle(rwlock->read_event))
return apr_get_os_error();
if (! CloseHandle(rwlock->write_mutex))
return apr_get_os_error();
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t)apr_thread_rwlock_create(apr_thread_rwlock_t **rwlock,
apr_pool_t *pool)
{
*rwlock = apr_palloc(pool, sizeof(**rwlock));
(*rwlock)->pool = pool;
(*rwlock)->readers = 0;
if (! ((*rwlock)->read_event = CreateEvent(NULL, TRUE, FALSE, NULL))) {
*rwlock = NULL;
return apr_get_os_error();
}
if (! ((*rwlock)->write_mutex = CreateMutex(NULL, FALSE, NULL))) {
CloseHandle((*rwlock)->read_event);
*rwlock = NULL;
return apr_get_os_error();
}
apr_pool_cleanup_register(pool, *rwlock, thread_rwlock_cleanup,
apr_pool_cleanup_null);
return APR_SUCCESS;
}
static apr_status_t apr_thread_rwlock_rdlock_core(apr_thread_rwlock_t *rwlock,
DWORD milliseconds)
{
DWORD code = WaitForSingleObject(rwlock->write_mutex, milliseconds);
if (code == WAIT_FAILED || code == WAIT_TIMEOUT)
return APR_FROM_OS_ERROR(code);
/* We've successfully acquired the writer mutex, we can't be locked
* for write, so it's OK to add the reader lock. The writer mutex
* doubles as race condition protection for the readers counter.
*/
InterlockedIncrement(&rwlock->readers);
if (! ResetEvent(rwlock->read_event))
return apr_get_os_error();
if (! ReleaseMutex(rwlock->write_mutex))
return apr_get_os_error();
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_rdlock(apr_thread_rwlock_t *rwlock)
{
return apr_thread_rwlock_rdlock_core(rwlock, INFINITE);
}
APR_DECLARE(apr_status_t)
apr_thread_rwlock_tryrdlock(apr_thread_rwlock_t *rwlock)
{
return apr_thread_rwlock_rdlock_core(rwlock, 0);
}
static apr_status_t
apr_thread_rwlock_wrlock_core(apr_thread_rwlock_t *rwlock, DWORD milliseconds)
{
DWORD code = WaitForSingleObject(rwlock->write_mutex, milliseconds);
if (code == WAIT_FAILED || code == WAIT_TIMEOUT)
return APR_FROM_OS_ERROR(code);
/* We've got the writer lock but we have to wait for all readers to
* unlock before it's ok to use it.
*/
if (rwlock->readers) {
/* Must wait for readers to finish before returning, unless this
* is an trywrlock (milliseconds == 0):
*/
code = milliseconds
? WaitForSingleObject(rwlock->read_event, milliseconds)
: WAIT_TIMEOUT;
if (code == WAIT_FAILED || code == WAIT_TIMEOUT) {
/* Unable to wait for readers to finish, release write lock: */
if (! ReleaseMutex(rwlock->write_mutex))
return apr_get_os_error();
return APR_FROM_OS_ERROR(code);
}
}
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_wrlock(apr_thread_rwlock_t *rwlock)
{
return apr_thread_rwlock_wrlock_core(rwlock, INFINITE);
}
APR_DECLARE(apr_status_t)apr_thread_rwlock_trywrlock(apr_thread_rwlock_t *rwlock)
{
return apr_thread_rwlock_wrlock_core(rwlock, 0);
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_unlock(apr_thread_rwlock_t *rwlock)
{
apr_status_t rv = 0;
/* First, guess that we're unlocking a writer */
if (! ReleaseMutex(rwlock->write_mutex))
rv = apr_get_os_error();
if (rv == APR_FROM_OS_ERROR(ERROR_NOT_OWNER)) {
/* Nope, we must have a read lock */
if (rwlock->readers &&
! InterlockedDecrement(&rwlock->readers) &&
! SetEvent(rwlock->read_event)) {
rv = apr_get_os_error();
}
else {
rv = 0;
}
}
return rv;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_destroy(apr_thread_rwlock_t *rwlock)
{
return apr_pool_cleanup_run(rwlock->pool, rwlock, thread_rwlock_cleanup);
}
APR_POOL_IMPLEMENT_ACCESSOR(thread_rwlock)
| 001-log4cxx | trunk/src/apr/locks/win32/thread_rwlock.c | C | asf20 | 5,165 |
/* 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_arch_thread_mutex.h"
#include "apr_arch_thread_cond.h"
#include "apr_strings.h"
#include "apr_portable.h"
static apr_status_t thread_cond_cleanup(void *data)
{
struct waiter *w;
apr_thread_cond_t *cond = (apr_thread_cond_t *)data;
acquire_sem(cond->lock);
delete_sem(cond->lock);
return APR_SUCCESS;
}
static struct waiter_t *make_waiter(apr_pool_t *pool)
{
struct waiter_t *w = (struct waiter_t*)
apr_palloc(pool, sizeof(struct waiter_t));
if (w == NULL)
return NULL;
w->sem = create_sem(0, "apr conditional waiter");
if (w->sem < 0)
return NULL;
APR_RING_ELEM_INIT(w, link);
return w;
}
APR_DECLARE(apr_status_t) apr_thread_cond_create(apr_thread_cond_t **cond,
apr_pool_t *pool)
{
apr_thread_cond_t *new_cond;
sem_id rv;
int i;
new_cond = (apr_thread_cond_t *)apr_palloc(pool, sizeof(apr_thread_cond_t));
if (new_cond == NULL)
return APR_ENOMEM;
if ((rv = create_sem(1, "apr conditional lock")) < B_OK)
return rv;
new_cond->lock = rv;
new_cond->pool = pool;
APR_RING_INIT(&new_cond->alist, waiter_t, link);
APR_RING_INIT(&new_cond->flist, waiter_t, link);
for (i=0;i < 10 ;i++) {
struct waiter_t *nw = make_waiter(pool);
APR_RING_INSERT_TAIL(&new_cond->flist, nw, waiter_t, link);
}
apr_pool_cleanup_register(new_cond->pool,
(void *)new_cond, thread_cond_cleanup,
apr_pool_cleanup_null);
*cond = new_cond;
return APR_SUCCESS;
}
static apr_status_t do_wait(apr_thread_cond_t *cond, apr_thread_mutex_t *mutex,
int timeout)
{
struct waiter_t *wait;
thread_id cth = find_thread(NULL);
apr_status_t rv;
int flags = B_RELATIVE_TIMEOUT;
/* We must be the owner of the mutex or we can't do this... */
if (mutex->owner != cth) {
/* What should we return??? */
return APR_EINVAL;
}
acquire_sem(cond->lock);
wait = APR_RING_FIRST(&cond->flist);
if (wait)
APR_RING_REMOVE(wait, link);
else
wait = make_waiter(cond->pool);
APR_RING_INSERT_TAIL(&cond->alist, wait, waiter_t, link);
cond->condlock = mutex;
release_sem(cond->lock);
apr_thread_mutex_unlock(cond->condlock);
if (timeout == 0)
flags = 0;
rv = acquire_sem_etc(wait->sem, 1, flags, timeout);
apr_thread_mutex_lock(cond->condlock);
if (rv != B_OK)
if (rv == B_TIMED_OUT)
return APR_TIMEUP;
return rv;
acquire_sem(cond->lock);
APR_RING_REMOVE(wait, link);
APR_RING_INSERT_TAIL(&cond->flist, wait, waiter_t, link);
release_sem(cond->lock);
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_cond_wait(apr_thread_cond_t *cond,
apr_thread_mutex_t *mutex)
{
return do_wait(cond, mutex, 0);
}
APR_DECLARE(apr_status_t) apr_thread_cond_timedwait(apr_thread_cond_t *cond,
apr_thread_mutex_t *mutex,
apr_interval_time_t timeout)
{
return do_wait(cond, mutex, timeout);
}
APR_DECLARE(apr_status_t) apr_thread_cond_signal(apr_thread_cond_t *cond)
{
struct waiter_t *wake;
acquire_sem(cond->lock);
if (!APR_RING_EMPTY(&cond->alist, waiter_t, link)) {
wake = APR_RING_FIRST(&cond->alist);
APR_RING_REMOVE(wake, link);
release_sem(wake->sem);
APR_RING_INSERT_TAIL(&cond->flist, wake, waiter_t, link);
}
release_sem(cond->lock);
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_cond_broadcast(apr_thread_cond_t *cond)
{
struct waiter_t *wake;
acquire_sem(cond->lock);
while (! APR_RING_EMPTY(&cond->alist, waiter_t, link)) {
wake = APR_RING_FIRST(&cond->alist);
APR_RING_REMOVE(wake, link);
release_sem(wake->sem);
APR_RING_INSERT_TAIL(&cond->flist, wake, waiter_t, link);
}
release_sem(cond->lock);
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_cond_destroy(apr_thread_cond_t *cond)
{
apr_status_t stat;
if ((stat = thread_cond_cleanup(cond)) == APR_SUCCESS) {
apr_pool_cleanup_kill(cond->pool, cond, thread_cond_cleanup);
return APR_SUCCESS;
}
return stat;
}
APR_POOL_IMPLEMENT_ACCESSOR(thread_cond)
| 001-log4cxx | trunk/src/apr/locks/beos/thread_cond.c | C | asf20 | 5,379 |
/* 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.
*/
/*Read/Write locking implementation based on the MultiLock code from
* Stephen Beaulieu <hippo@be.com>
*/
#include "apr_arch_thread_mutex.h"
#include "apr_strings.h"
#include "apr_portable.h"
static apr_status_t _thread_mutex_cleanup(void * data)
{
apr_thread_mutex_t *lock = (apr_thread_mutex_t*)data;
if (lock->LockCount != 0) {
/* we're still locked... */
while (atomic_add(&lock->LockCount , -1) > 1){
/* OK we had more than one person waiting on the lock so
* the sem is also locked. Release it until we have no more
* locks left.
*/
release_sem (lock->Lock);
}
}
delete_sem(lock->Lock);
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_mutex_create(apr_thread_mutex_t **mutex,
unsigned int flags,
apr_pool_t *pool)
{
apr_thread_mutex_t *new_m;
apr_status_t stat = APR_SUCCESS;
new_m = (apr_thread_mutex_t *)apr_pcalloc(pool, sizeof(apr_thread_mutex_t));
if (new_m == NULL){
return APR_ENOMEM;
}
if ((stat = create_sem(0, "APR_Lock")) < B_NO_ERROR) {
_thread_mutex_cleanup(new_m);
return stat;
}
new_m->LockCount = 0;
new_m->Lock = stat;
new_m->pool = pool;
/* Optimal default is APR_THREAD_MUTEX_UNNESTED,
* no additional checks required for either flag.
*/
new_m->nested = flags & APR_THREAD_MUTEX_NESTED;
apr_pool_cleanup_register(new_m->pool, (void *)new_m, _thread_mutex_cleanup,
apr_pool_cleanup_null);
(*mutex) = new_m;
return APR_SUCCESS;
}
#if APR_HAS_CREATE_LOCKS_NP
APR_DECLARE(apr_status_t) apr_thread_mutex_create_np(apr_thread_mutex_t **mutex,
const char *fname,
apr_lockmech_e_np mech,
apr_pool_t *pool)
{
return APR_ENOTIMPL;
}
#endif
APR_DECLARE(apr_status_t) apr_thread_mutex_lock(apr_thread_mutex_t *mutex)
{
int32 stat;
thread_id me = find_thread(NULL);
if (mutex->nested && mutex->owner == me) {
mutex->owner_ref++;
return APR_SUCCESS;
}
if (atomic_add(&mutex->LockCount, 1) > 0) {
if ((stat = acquire_sem(mutex->Lock)) < B_NO_ERROR) {
/* Oh dear, acquire_sem failed!! */
atomic_add(&mutex->LockCount, -1);
return stat;
}
}
mutex->owner = me;
mutex->owner_ref = 1;
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_mutex_trylock(apr_thread_mutex_t *mutex)
{
return APR_ENOTIMPL;
}
APR_DECLARE(apr_status_t) apr_thread_mutex_unlock(apr_thread_mutex_t *mutex)
{
int32 stat;
if (mutex->nested && mutex->owner == find_thread(NULL)) {
mutex->owner_ref--;
if (mutex->owner_ref > 0)
return APR_SUCCESS;
}
if (atomic_add(&mutex->LockCount, -1) > 1) {
if ((stat = release_sem(mutex->Lock)) < B_NO_ERROR) {
atomic_add(&mutex->LockCount, 1);
return stat;
}
}
mutex->owner = -1;
mutex->owner_ref = 0;
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_mutex_destroy(apr_thread_mutex_t *mutex)
{
apr_status_t stat;
if ((stat = _thread_mutex_cleanup(mutex)) == APR_SUCCESS) {
apr_pool_cleanup_kill(mutex->pool, mutex, _thread_mutex_cleanup);
return APR_SUCCESS;
}
return stat;
}
APR_POOL_IMPLEMENT_ACCESSOR(thread_mutex)
| 001-log4cxx | trunk/src/apr/locks/beos/thread_mutex.c | C | asf20 | 4,412 |
/* 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.
*/
/*Read/Write locking implementation based on the MultiLock code from
* Stephen Beaulieu <hippo@be.com>
*/
#include "apr_arch_proc_mutex.h"
#include "apr_strings.h"
#include "apr_portable.h"
static apr_status_t _proc_mutex_cleanup(void * data)
{
apr_proc_mutex_t *lock = (apr_proc_mutex_t*)data;
if (lock->LockCount != 0) {
/* we're still locked... */
while (atomic_add(&lock->LockCount , -1) > 1){
/* OK we had more than one person waiting on the lock so
* the sem is also locked. Release it until we have no more
* locks left.
*/
release_sem (lock->Lock);
}
}
delete_sem(lock->Lock);
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_proc_mutex_create(apr_proc_mutex_t **mutex,
const char *fname,
apr_lockmech_e mech,
apr_pool_t *pool)
{
apr_proc_mutex_t *new;
apr_status_t stat = APR_SUCCESS;
if (mech != APR_LOCK_DEFAULT) {
return APR_ENOTIMPL;
}
new = (apr_proc_mutex_t *)apr_pcalloc(pool, sizeof(apr_proc_mutex_t));
if (new == NULL){
return APR_ENOMEM;
}
if ((stat = create_sem(0, "APR_Lock")) < B_NO_ERROR) {
_proc_mutex_cleanup(new);
return stat;
}
new->LockCount = 0;
new->Lock = stat;
new->pool = pool;
apr_pool_cleanup_register(new->pool, (void *)new, _proc_mutex_cleanup,
apr_pool_cleanup_null);
(*mutex) = new;
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_proc_mutex_child_init(apr_proc_mutex_t **mutex,
const char *fname,
apr_pool_t *pool)
{
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_proc_mutex_lock(apr_proc_mutex_t *mutex)
{
int32 stat;
if (atomic_add(&mutex->LockCount, 1) > 0) {
if ((stat = acquire_sem(mutex->Lock)) < B_NO_ERROR) {
atomic_add(&mutex->LockCount, -1);
return stat;
}
}
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_proc_mutex_trylock(apr_proc_mutex_t *mutex)
{
return APR_ENOTIMPL;
}
APR_DECLARE(apr_status_t) apr_proc_mutex_unlock(apr_proc_mutex_t *mutex)
{
int32 stat;
if (atomic_add(&mutex->LockCount, -1) > 1) {
if ((stat = release_sem(mutex->Lock)) < B_NO_ERROR) {
atomic_add(&mutex->LockCount, 1);
return stat;
}
}
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_proc_mutex_destroy(apr_proc_mutex_t *mutex)
{
apr_status_t stat;
if ((stat = _proc_mutex_cleanup(mutex)) == APR_SUCCESS) {
apr_pool_cleanup_kill(mutex->pool, mutex, _proc_mutex_cleanup);
return APR_SUCCESS;
}
return stat;
}
APR_DECLARE(apr_status_t) apr_proc_mutex_cleanup(void *mutex)
{
return _proc_mutex_cleanup(mutex);
}
APR_DECLARE(const char *) apr_proc_mutex_lockfile(apr_proc_mutex_t *mutex)
{
return NULL;
}
APR_DECLARE(const char *) apr_proc_mutex_name(apr_proc_mutex_t *mutex)
{
return "beossem";
}
APR_DECLARE(const char *) apr_proc_mutex_defname(void)
{
return "beossem";
}
APR_POOL_IMPLEMENT_ACCESSOR(proc_mutex)
/* Implement OS-specific accessors defined in apr_portable.h */
APR_DECLARE(apr_status_t) apr_os_proc_mutex_get(apr_os_proc_mutex_t *ospmutex,
apr_proc_mutex_t *pmutex)
{
ospmutex->sem = pmutex->Lock;
ospmutex->ben = pmutex->LockCount;
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_os_proc_mutex_put(apr_proc_mutex_t **pmutex,
apr_os_proc_mutex_t *ospmutex,
apr_pool_t *pool)
{
if (pool == NULL) {
return APR_ENOPOOL;
}
if ((*pmutex) == NULL) {
(*pmutex) = (apr_proc_mutex_t *)apr_pcalloc(pool, sizeof(apr_proc_mutex_t));
(*pmutex)->pool = pool;
}
(*pmutex)->Lock = ospmutex->sem;
(*pmutex)->LockCount = ospmutex->ben;
return APR_SUCCESS;
}
| 001-log4cxx | trunk/src/apr/locks/beos/proc_mutex.c | C | asf20 | 4,961 |
/* 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.
*/
/*Read/Write locking implementation based on the MultiLock code from
* Stephen Beaulieu <hippo@be.com>
*/
#include "apr_arch_thread_rwlock.h"
#include "apr_strings.h"
#include "apr_portable.h"
#define BIG_NUM 100000
static apr_status_t _thread_rw_cleanup(void * data)
{
apr_thread_rwlock_t *mutex = (apr_thread_rwlock_t*)data;
if (mutex->ReadCount != 0) {
while (atomic_add(&mutex->ReadCount , -1) > 1){
release_sem (mutex->Read);
}
}
if (mutex->WriteCount != 0) {
while (atomic_add(&mutex->WriteCount , -1) > 1){
release_sem (mutex->Write);
}
}
if (mutex->LockCount != 0) {
while (atomic_add(&mutex->LockCount , -1) > 1){
release_sem (mutex->Lock);
}
}
delete_sem(mutex->Read);
delete_sem(mutex->Write);
delete_sem(mutex->Lock);
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_create(apr_thread_rwlock_t **rwlock,
apr_pool_t *pool)
{
apr_thread_rwlock_t *new;
new = (apr_thread_rwlock_t *)apr_pcalloc(pool, sizeof(apr_thread_rwlock_t));
if (new == NULL){
return APR_ENOMEM;
}
new->pool = pool;
/* we need to make 3 locks... */
new->ReadCount = 0;
new->WriteCount = 0;
new->LockCount = 0;
new->Read = create_sem(0, "APR_ReadLock");
new->Write = create_sem(0, "APR_WriteLock");
new->Lock = create_sem(0, "APR_Lock");
if (new->Lock < 0 || new->Read < 0 || new->Write < 0) {
_thread_rw_cleanup(new);
return -1;
}
apr_pool_cleanup_register(new->pool, (void *)new, _thread_rw_cleanup,
apr_pool_cleanup_null);
(*rwlock) = new;
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_rdlock(apr_thread_rwlock_t *rwlock)
{
int32 rv = APR_SUCCESS;
if (find_thread(NULL) == rwlock->writer) {
/* we're the writer - no problem */
rwlock->Nested++;
} else {
/* we're not the writer */
int32 r = atomic_add(&rwlock->ReadCount, 1);
if (r < 0) {
/* Oh dear, writer holds lock, wait for sem */
rv = acquire_sem_etc(rwlock->Read, 1, B_DO_NOT_RESCHEDULE,
B_INFINITE_TIMEOUT);
}
}
return rv;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_tryrdlock(apr_thread_rwlock_t *rwlock)
{
return APR_ENOTIMPL;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_wrlock(apr_thread_rwlock_t *rwlock)
{
int rv = APR_SUCCESS;
if (find_thread(NULL) == rwlock->writer) {
rwlock->Nested++;
} else {
/* we're not the writer... */
if (atomic_add(&rwlock->LockCount, 1) >= 1) {
/* we're locked - acquire the sem */
rv = acquire_sem_etc(rwlock->Lock, 1, B_DO_NOT_RESCHEDULE,
B_INFINITE_TIMEOUT);
}
if (rv == APR_SUCCESS) {
/* decrement the ReadCount to a large -ve number so that
* we block on new readers...
*/
int32 readers = atomic_add(&rwlock->ReadCount, -BIG_NUM);
if (readers > 0) {
/* readers are holding the lock */
rv = acquire_sem_etc(rwlock->Write, readers, B_DO_NOT_RESCHEDULE,
B_INFINITE_TIMEOUT);
}
if (rv == APR_SUCCESS)
rwlock->writer = find_thread(NULL);
}
}
return rv;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_trywrlock(apr_thread_rwlock_t *rwlock)
{
return APR_ENOTIMPL;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_unlock(apr_thread_rwlock_t *rwlock)
{
apr_status_t rv = APR_SUCCESS;
int32 readers;
/* we know we hold the lock, so don't check it :) */
if (find_thread(NULL) == rwlock->writer) {
/* we know we hold the lock, so don't check it :) */
if (rwlock->Nested > 1) {
/* we're recursively locked */
rwlock->Nested--;
return APR_SUCCESS;
}
/* OK so we need to release the sem if we have it :) */
readers = atomic_add(&rwlock->ReadCount, BIG_NUM) + BIG_NUM;
if (readers > 0) {
rv = release_sem_etc(rwlock->Read, readers, B_DO_NOT_RESCHEDULE);
}
if (rv == APR_SUCCESS) {
rwlock->writer = -1;
if (atomic_add(&rwlock->LockCount, -1) > 1) {
rv = release_sem_etc(rwlock->Lock, 1, B_DO_NOT_RESCHEDULE);
}
}
} else {
/* We weren't the Writer, so just release the ReadCount... */
if (atomic_add(&rwlock->ReadCount, -1) < 0) {
/* we have a writer waiting for the lock, so release it */
rv = release_sem_etc(rwlock->Write, 1, B_DO_NOT_RESCHEDULE);
}
}
return rv;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_destroy(apr_thread_rwlock_t *rwlock)
{
apr_status_t stat;
if ((stat = _thread_rw_cleanup(rwlock)) == APR_SUCCESS) {
apr_pool_cleanup_kill(rwlock->pool, rwlock, _thread_rw_cleanup);
return APR_SUCCESS;
}
return stat;
}
APR_POOL_IMPLEMENT_ACCESSOR(thread_rwlock)
| 001-log4cxx | trunk/src/apr/locks/beos/thread_rwlock.c | C | asf20 | 6,009 |
/* 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"
#if APR_HAS_THREADS
#include "apr_arch_thread_mutex.h"
#include "apr_arch_thread_cond.h"
static apr_status_t thread_cond_cleanup(void *data)
{
apr_thread_cond_t *cond = (apr_thread_cond_t *)data;
apr_status_t rv;
rv = pthread_cond_destroy(&cond->cond);
#ifdef PTHREAD_SETS_ERRNO
if (rv) {
rv = errno;
}
#endif
return rv;
}
APR_DECLARE(apr_status_t) apr_thread_cond_create(apr_thread_cond_t **cond,
apr_pool_t *pool)
{
apr_thread_cond_t *new_cond;
apr_status_t rv;
new_cond = apr_palloc(pool, sizeof(apr_thread_cond_t));
new_cond->pool = pool;
if ((rv = pthread_cond_init(&new_cond->cond, NULL))) {
#ifdef PTHREAD_SETS_ERRNO
rv = errno;
#endif
return rv;
}
apr_pool_cleanup_register(new_cond->pool,
(void *)new_cond, thread_cond_cleanup,
apr_pool_cleanup_null);
*cond = new_cond;
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_cond_wait(apr_thread_cond_t *cond,
apr_thread_mutex_t *mutex)
{
apr_status_t rv;
rv = pthread_cond_wait(&cond->cond, &mutex->mutex);
#ifdef PTHREAD_SETS_ERRNO
if (rv) {
rv = errno;
}
#endif
return rv;
}
APR_DECLARE(apr_status_t) apr_thread_cond_timedwait(apr_thread_cond_t *cond,
apr_thread_mutex_t *mutex,
apr_interval_time_t timeout)
{
apr_status_t rv;
apr_time_t then;
struct timespec abstime;
then = apr_time_now() + timeout;
abstime.tv_sec = apr_time_sec(then);
abstime.tv_nsec = apr_time_usec(then) * 1000; /* nanoseconds */
rv = pthread_cond_timedwait(&cond->cond, &mutex->mutex, &abstime);
#ifdef PTHREAD_SETS_ERRNO
if (rv) {
rv = errno;
}
#endif
if (ETIMEDOUT == rv) {
return APR_TIMEUP;
}
return rv;
}
APR_DECLARE(apr_status_t) apr_thread_cond_signal(apr_thread_cond_t *cond)
{
apr_status_t rv;
rv = pthread_cond_signal(&cond->cond);
#ifdef PTHREAD_SETS_ERRNO
if (rv) {
rv = errno;
}
#endif
return rv;
}
APR_DECLARE(apr_status_t) apr_thread_cond_broadcast(apr_thread_cond_t *cond)
{
apr_status_t rv;
rv = pthread_cond_broadcast(&cond->cond);
#ifdef PTHREAD_SETS_ERRNO
if (rv) {
rv = errno;
}
#endif
return rv;
}
APR_DECLARE(apr_status_t) apr_thread_cond_destroy(apr_thread_cond_t *cond)
{
return apr_pool_cleanup_run(cond->pool, cond, thread_cond_cleanup);
}
APR_POOL_IMPLEMENT_ACCESSOR(thread_cond)
#endif /* APR_HAS_THREADS */
| 001-log4cxx | trunk/src/apr/locks/unix/thread_cond.c | C | asf20 | 3,514 |
/* 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_arch_thread_mutex.h"
#define APR_WANT_MEMFUNC
#include "apr_want.h"
#if APR_HAS_THREADS
static apr_status_t thread_mutex_cleanup(void *data)
{
apr_thread_mutex_t *mutex = data;
apr_status_t rv;
rv = pthread_mutex_destroy(&mutex->mutex);
#ifdef PTHREAD_SETS_ERRNO
if (rv) {
rv = errno;
}
#endif
return rv;
}
APR_DECLARE(apr_status_t) apr_thread_mutex_create(apr_thread_mutex_t **mutex,
unsigned int flags,
apr_pool_t *pool)
{
apr_thread_mutex_t *new_mutex;
apr_status_t rv;
#ifndef HAVE_PTHREAD_MUTEX_RECURSIVE
if (flags & APR_THREAD_MUTEX_NESTED) {
return APR_ENOTIMPL;
}
#endif
new_mutex = apr_pcalloc(pool, sizeof(apr_thread_mutex_t));
new_mutex->pool = pool;
#ifdef HAVE_PTHREAD_MUTEX_RECURSIVE
if (flags & APR_THREAD_MUTEX_NESTED) {
pthread_mutexattr_t mattr;
rv = pthread_mutexattr_init(&mattr);
if (rv) return rv;
rv = pthread_mutexattr_settype(&mattr, PTHREAD_MUTEX_RECURSIVE);
if (rv) {
pthread_mutexattr_destroy(&mattr);
return rv;
}
rv = pthread_mutex_init(&new_mutex->mutex, &mattr);
pthread_mutexattr_destroy(&mattr);
} else
#endif
rv = pthread_mutex_init(&new_mutex->mutex, NULL);
if (rv) {
#ifdef PTHREAD_SETS_ERRNO
rv = errno;
#endif
return rv;
}
apr_pool_cleanup_register(new_mutex->pool,
new_mutex, thread_mutex_cleanup,
apr_pool_cleanup_null);
*mutex = new_mutex;
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_mutex_lock(apr_thread_mutex_t *mutex)
{
apr_status_t rv;
rv = pthread_mutex_lock(&mutex->mutex);
#ifdef PTHREAD_SETS_ERRNO
if (rv) {
rv = errno;
}
#endif
return rv;
}
APR_DECLARE(apr_status_t) apr_thread_mutex_trylock(apr_thread_mutex_t *mutex)
{
apr_status_t rv;
rv = pthread_mutex_trylock(&mutex->mutex);
if (rv) {
#ifdef PTHREAD_SETS_ERRNO
rv = errno;
#endif
return (rv == EBUSY) ? APR_EBUSY : rv;
}
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_mutex_unlock(apr_thread_mutex_t *mutex)
{
apr_status_t status;
status = pthread_mutex_unlock(&mutex->mutex);
#ifdef PTHREAD_SETS_ERRNO
if (status) {
status = errno;
}
#endif
return status;
}
APR_DECLARE(apr_status_t) apr_thread_mutex_destroy(apr_thread_mutex_t *mutex)
{
return apr_pool_cleanup_run(mutex->pool, mutex, thread_mutex_cleanup);
}
APR_POOL_IMPLEMENT_ACCESSOR(thread_mutex)
#endif /* APR_HAS_THREADS */
| 001-log4cxx | trunk/src/apr/locks/unix/thread_mutex.c | C | asf20 | 3,560 |
/* 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_arch_global_mutex.h"
#include "apr_proc_mutex.h"
#include "apr_thread_mutex.h"
#include "apr_portable.h"
static apr_status_t global_mutex_cleanup(void *data)
{
apr_global_mutex_t *m = (apr_global_mutex_t *)data;
apr_status_t rv;
rv = apr_proc_mutex_destroy(m->proc_mutex);
#if APR_HAS_THREADS
if (m->thread_mutex) {
if (rv != APR_SUCCESS) {
(void)apr_thread_mutex_destroy(m->thread_mutex);
}
else {
rv = apr_thread_mutex_destroy(m->thread_mutex);
}
}
#endif /* APR_HAS_THREADS */
return rv;
}
APR_DECLARE(apr_status_t) apr_global_mutex_create(apr_global_mutex_t **mutex,
const char *fname,
apr_lockmech_e mech,
apr_pool_t *pool)
{
apr_status_t rv;
apr_global_mutex_t *m;
m = (apr_global_mutex_t *)apr_palloc(pool, sizeof(*m));
m->pool = pool;
rv = apr_proc_mutex_create(&m->proc_mutex, fname, mech, m->pool);
if (rv != APR_SUCCESS) {
return rv;
}
#if APR_HAS_THREADS
if (m->proc_mutex->inter_meth->flags & APR_PROCESS_LOCK_MECH_IS_GLOBAL) {
m->thread_mutex = NULL; /* We don't need a thread lock. */
}
else {
rv = apr_thread_mutex_create(&m->thread_mutex,
APR_THREAD_MUTEX_DEFAULT, m->pool);
if (rv != APR_SUCCESS) {
rv = apr_proc_mutex_destroy(m->proc_mutex);
return rv;
}
}
#endif /* APR_HAS_THREADS */
apr_pool_cleanup_register(m->pool, (void *)m,
global_mutex_cleanup, apr_pool_cleanup_null);
*mutex = m;
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_global_mutex_child_init(
apr_global_mutex_t **mutex,
const char *fname,
apr_pool_t *pool)
{
apr_status_t rv;
rv = apr_proc_mutex_child_init(&((*mutex)->proc_mutex), fname, pool);
return rv;
}
APR_DECLARE(apr_status_t) apr_global_mutex_lock(apr_global_mutex_t *mutex)
{
apr_status_t rv;
#if APR_HAS_THREADS
if (mutex->thread_mutex) {
rv = apr_thread_mutex_lock(mutex->thread_mutex);
if (rv != APR_SUCCESS) {
return rv;
}
}
#endif /* APR_HAS_THREADS */
rv = apr_proc_mutex_lock(mutex->proc_mutex);
#if APR_HAS_THREADS
if (rv != APR_SUCCESS) {
if (mutex->thread_mutex) {
(void)apr_thread_mutex_unlock(mutex->thread_mutex);
}
}
#endif /* APR_HAS_THREADS */
return rv;
}
APR_DECLARE(apr_status_t) apr_global_mutex_trylock(apr_global_mutex_t *mutex)
{
apr_status_t rv;
#if APR_HAS_THREADS
if (mutex->thread_mutex) {
rv = apr_thread_mutex_trylock(mutex->thread_mutex);
if (rv != APR_SUCCESS) {
return rv;
}
}
#endif /* APR_HAS_THREADS */
rv = apr_proc_mutex_trylock(mutex->proc_mutex);
#if APR_HAS_THREADS
if (rv != APR_SUCCESS) {
if (mutex->thread_mutex) {
(void)apr_thread_mutex_unlock(mutex->thread_mutex);
}
}
#endif /* APR_HAS_THREADS */
return rv;
}
APR_DECLARE(apr_status_t) apr_global_mutex_unlock(apr_global_mutex_t *mutex)
{
apr_status_t rv;
rv = apr_proc_mutex_unlock(mutex->proc_mutex);
#if APR_HAS_THREADS
if (mutex->thread_mutex) {
if (rv != APR_SUCCESS) {
(void)apr_thread_mutex_unlock(mutex->thread_mutex);
}
else {
rv = apr_thread_mutex_unlock(mutex->thread_mutex);
}
}
#endif /* APR_HAS_THREADS */
return rv;
}
APR_DECLARE(apr_status_t) apr_os_global_mutex_get(apr_os_global_mutex_t *ospmutex,
apr_global_mutex_t *pmutex)
{
ospmutex->pool = pmutex->pool;
ospmutex->proc_mutex = pmutex->proc_mutex;
#if APR_HAS_THREADS
ospmutex->thread_mutex = pmutex->thread_mutex;
#endif
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_global_mutex_destroy(apr_global_mutex_t *mutex)
{
return apr_pool_cleanup_run(mutex->pool, mutex, global_mutex_cleanup);
}
APR_POOL_IMPLEMENT_ACCESSOR(global_mutex)
| 001-log4cxx | trunk/src/apr/locks/unix/global_mutex.c | C | asf20 | 5,090 |
/* 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_arch_proc_mutex.h"
#include "apr_arch_file_io.h" /* for apr_mkstemp() */
APR_DECLARE(apr_status_t) apr_proc_mutex_destroy(apr_proc_mutex_t *mutex)
{
return apr_pool_cleanup_run(mutex->pool, mutex, apr_proc_mutex_cleanup);
}
static apr_status_t proc_mutex_no_tryacquire(apr_proc_mutex_t *new_mutex)
{
return APR_ENOTIMPL;
}
#if APR_HAS_POSIXSEM_SERIALIZE || APR_HAS_FCNTL_SERIALIZE || \
APR_HAS_PROC_PTHREAD_SERIALIZE || APR_HAS_SYSVSEM_SERIALIZE
static apr_status_t proc_mutex_no_child_init(apr_proc_mutex_t **mutex,
apr_pool_t *cont,
const char *fname)
{
return APR_SUCCESS;
}
#endif
#if APR_HAS_POSIXSEM_SERIALIZE
#ifndef SEM_FAILED
#define SEM_FAILED (-1)
#endif
static apr_status_t proc_mutex_posix_cleanup(void *mutex_)
{
apr_proc_mutex_t *mutex = mutex_;
if (sem_close(mutex->psem_interproc) < 0) {
return errno;
}
return APR_SUCCESS;
}
static apr_status_t proc_mutex_posix_create(apr_proc_mutex_t *new_mutex,
const char *fname)
{
sem_t *psem;
char semname[31];
apr_time_t now;
unsigned long sec;
unsigned long usec;
new_mutex->interproc = apr_palloc(new_mutex->pool,
sizeof(*new_mutex->interproc));
/*
* This bogusness is to follow what appears to be the
* lowest common denominator in Posix semaphore naming:
* - start with '/'
* - be at most 14 chars
* - be unique and not match anything on the filesystem
*
* Because of this, we ignore fname, and try our
* own naming system. We tuck the name away, since it might
* be useful for debugging. to make this as robust as possible,
* we initially try something larger (and hopefully more unique)
* and gracefully fail down to the LCD above.
*
* NOTE: Darwin (Mac OS X) seems to be the most restrictive
* implementation. Versions previous to Darwin 6.2 had the 14
* char limit, but later rev's allow up to 31 characters.
*
* FIXME: There is a small window of opportunity where
* instead of getting a new semaphore descriptor, we get
* a previously obtained one. This can happen if the requests
* are made at the "same time" and in the small span of time between
* the sem_open and the sem_unlink. Use of O_EXCL does not
* help here however...
*
*/
now = apr_time_now();
sec = apr_time_sec(now);
usec = apr_time_usec(now);
apr_snprintf(semname, sizeof(semname), "/ApR.%lxZ%lx", sec, usec);
psem = sem_open(semname, O_CREAT, 0644, 1);
if ((psem == (sem_t *)SEM_FAILED) && (errno == ENAMETOOLONG)) {
/* Oh well, good try */
semname[13] = '\0';
psem = sem_open(semname, O_CREAT, 0644, 1);
}
if (psem == (sem_t *)SEM_FAILED) {
return errno;
}
/* Ahhh. The joys of Posix sems. Predelete it... */
sem_unlink(semname);
new_mutex->psem_interproc = psem;
new_mutex->fname = apr_pstrdup(new_mutex->pool, semname);
apr_pool_cleanup_register(new_mutex->pool, (void *)new_mutex,
apr_proc_mutex_cleanup,
apr_pool_cleanup_null);
return APR_SUCCESS;
}
static apr_status_t proc_mutex_posix_acquire(apr_proc_mutex_t *mutex)
{
if (sem_wait(mutex->psem_interproc) < 0) {
return errno;
}
mutex->curr_locked = 1;
return APR_SUCCESS;
}
static apr_status_t proc_mutex_posix_release(apr_proc_mutex_t *mutex)
{
mutex->curr_locked = 0;
if (sem_post(mutex->psem_interproc) < 0) {
/* any failure is probably fatal, so no big deal to leave
* ->curr_locked at 0. */
return errno;
}
return APR_SUCCESS;
}
static const apr_proc_mutex_unix_lock_methods_t mutex_posixsem_methods =
{
#if APR_PROCESS_LOCK_IS_GLOBAL || !APR_HAS_THREADS || defined(POSIXSEM_IS_GLOBAL)
APR_PROCESS_LOCK_MECH_IS_GLOBAL,
#else
0,
#endif
proc_mutex_posix_create,
proc_mutex_posix_acquire,
proc_mutex_no_tryacquire,
proc_mutex_posix_release,
proc_mutex_posix_cleanup,
proc_mutex_no_child_init,
"posixsem"
};
#endif /* Posix sem implementation */
#if APR_HAS_SYSVSEM_SERIALIZE
static struct sembuf proc_mutex_op_on;
static struct sembuf proc_mutex_op_off;
static void proc_mutex_sysv_setup(void)
{
proc_mutex_op_on.sem_num = 0;
proc_mutex_op_on.sem_op = -1;
proc_mutex_op_on.sem_flg = SEM_UNDO;
proc_mutex_op_off.sem_num = 0;
proc_mutex_op_off.sem_op = 1;
proc_mutex_op_off.sem_flg = SEM_UNDO;
}
static apr_status_t proc_mutex_sysv_cleanup(void *mutex_)
{
apr_proc_mutex_t *mutex=mutex_;
union semun ick;
if (mutex->interproc->filedes != -1) {
ick.val = 0;
semctl(mutex->interproc->filedes, 0, IPC_RMID, ick);
}
return APR_SUCCESS;
}
static apr_status_t proc_mutex_sysv_create(apr_proc_mutex_t *new_mutex,
const char *fname)
{
union semun ick;
apr_status_t rv;
new_mutex->interproc = apr_palloc(new_mutex->pool, sizeof(*new_mutex->interproc));
new_mutex->interproc->filedes = semget(IPC_PRIVATE, 1, IPC_CREAT | 0600);
if (new_mutex->interproc->filedes < 0) {
rv = errno;
proc_mutex_sysv_cleanup(new_mutex);
return rv;
}
ick.val = 1;
if (semctl(new_mutex->interproc->filedes, 0, SETVAL, ick) < 0) {
rv = errno;
proc_mutex_sysv_cleanup(new_mutex);
return rv;
}
new_mutex->curr_locked = 0;
apr_pool_cleanup_register(new_mutex->pool,
(void *)new_mutex, apr_proc_mutex_cleanup,
apr_pool_cleanup_null);
return APR_SUCCESS;
}
static apr_status_t proc_mutex_sysv_acquire(apr_proc_mutex_t *mutex)
{
int rc;
do {
rc = semop(mutex->interproc->filedes, &proc_mutex_op_on, 1);
} while (rc < 0 && errno == EINTR);
if (rc < 0) {
return errno;
}
mutex->curr_locked = 1;
return APR_SUCCESS;
}
static apr_status_t proc_mutex_sysv_release(apr_proc_mutex_t *mutex)
{
int rc;
mutex->curr_locked = 0;
do {
rc = semop(mutex->interproc->filedes, &proc_mutex_op_off, 1);
} while (rc < 0 && errno == EINTR);
if (rc < 0) {
return errno;
}
return APR_SUCCESS;
}
static const apr_proc_mutex_unix_lock_methods_t mutex_sysv_methods =
{
#if APR_PROCESS_LOCK_IS_GLOBAL || !APR_HAS_THREADS || defined(SYSVSEM_IS_GLOBAL)
APR_PROCESS_LOCK_MECH_IS_GLOBAL,
#else
0,
#endif
proc_mutex_sysv_create,
proc_mutex_sysv_acquire,
proc_mutex_no_tryacquire,
proc_mutex_sysv_release,
proc_mutex_sysv_cleanup,
proc_mutex_no_child_init,
"sysvsem"
};
#endif /* SysV sem implementation */
#if APR_HAS_PROC_PTHREAD_SERIALIZE
static apr_status_t proc_mutex_proc_pthread_cleanup(void *mutex_)
{
apr_proc_mutex_t *mutex=mutex_;
apr_status_t rv;
if (mutex->curr_locked == 1) {
if ((rv = pthread_mutex_unlock(mutex->pthread_interproc))) {
#ifdef PTHREAD_SETS_ERRNO
rv = errno;
#endif
return rv;
}
}
/* curr_locked is set to -1 until the mutex has been created */
if (mutex->curr_locked != -1) {
if ((rv = pthread_mutex_destroy(mutex->pthread_interproc))) {
#ifdef PTHREAD_SETS_ERRNO
rv = errno;
#endif
return rv;
}
}
if (munmap((caddr_t)mutex->pthread_interproc, sizeof(pthread_mutex_t))) {
return errno;
}
return APR_SUCCESS;
}
static apr_status_t proc_mutex_proc_pthread_create(apr_proc_mutex_t *new_mutex,
const char *fname)
{
apr_status_t rv;
int fd;
pthread_mutexattr_t mattr;
fd = open("/dev/zero", O_RDWR);
if (fd < 0) {
return errno;
}
new_mutex->pthread_interproc = (pthread_mutex_t *)mmap(
(caddr_t) 0,
sizeof(pthread_mutex_t),
PROT_READ | PROT_WRITE, MAP_SHARED,
fd, 0);
if (new_mutex->pthread_interproc == (pthread_mutex_t *) (caddr_t) -1) {
close(fd);
return errno;
}
close(fd);
new_mutex->curr_locked = -1; /* until the mutex has been created */
if ((rv = pthread_mutexattr_init(&mattr))) {
#ifdef PTHREAD_SETS_ERRNO
rv = errno;
#endif
proc_mutex_proc_pthread_cleanup(new_mutex);
return rv;
}
if ((rv = pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED))) {
#ifdef PTHREAD_SETS_ERRNO
rv = errno;
#endif
proc_mutex_proc_pthread_cleanup(new_mutex);
pthread_mutexattr_destroy(&mattr);
return rv;
}
#ifdef HAVE_PTHREAD_MUTEX_ROBUST
if ((rv = pthread_mutexattr_setrobust_np(&mattr,
PTHREAD_MUTEX_ROBUST_NP))) {
#ifdef PTHREAD_SETS_ERRNO
rv = errno;
#endif
proc_mutex_proc_pthread_cleanup(new_mutex);
pthread_mutexattr_destroy(&mattr);
return rv;
}
if ((rv = pthread_mutexattr_setprotocol(&mattr, PTHREAD_PRIO_INHERIT))) {
#ifdef PTHREAD_SETS_ERRNO
rv = errno;
#endif
proc_mutex_proc_pthread_cleanup(new_mutex);
pthread_mutexattr_destroy(&mattr);
return rv;
}
#endif /* HAVE_PTHREAD_MUTEX_ROBUST */
if ((rv = pthread_mutex_init(new_mutex->pthread_interproc, &mattr))) {
#ifdef PTHREAD_SETS_ERRNO
rv = errno;
#endif
proc_mutex_proc_pthread_cleanup(new_mutex);
pthread_mutexattr_destroy(&mattr);
return rv;
}
new_mutex->curr_locked = 0; /* mutex created now */
if ((rv = pthread_mutexattr_destroy(&mattr))) {
#ifdef PTHREAD_SETS_ERRNO
rv = errno;
#endif
proc_mutex_proc_pthread_cleanup(new_mutex);
return rv;
}
apr_pool_cleanup_register(new_mutex->pool,
(void *)new_mutex,
apr_proc_mutex_cleanup,
apr_pool_cleanup_null);
return APR_SUCCESS;
}
static apr_status_t proc_mutex_proc_pthread_acquire(apr_proc_mutex_t *mutex)
{
apr_status_t rv;
if ((rv = pthread_mutex_lock(mutex->pthread_interproc))) {
#ifdef PTHREAD_SETS_ERRNO
rv = errno;
#endif
#ifdef HAVE_PTHREAD_MUTEXATTR_SETROBUST_NP
/* Okay, our owner died. Let's try to make it consistent again. */
if (rv == EOWNERDEAD) {
pthread_mutex_consistent_np(mutex->pthread_interproc);
}
else
return rv;
#else
return rv;
#endif
}
mutex->curr_locked = 1;
return APR_SUCCESS;
}
/* TODO: Add proc_mutex_proc_pthread_tryacquire(apr_proc_mutex_t *mutex) */
static apr_status_t proc_mutex_proc_pthread_release(apr_proc_mutex_t *mutex)
{
apr_status_t rv;
mutex->curr_locked = 0;
if ((rv = pthread_mutex_unlock(mutex->pthread_interproc))) {
#ifdef PTHREAD_SETS_ERRNO
rv = errno;
#endif
return rv;
}
return APR_SUCCESS;
}
static const apr_proc_mutex_unix_lock_methods_t mutex_proc_pthread_methods =
{
APR_PROCESS_LOCK_MECH_IS_GLOBAL,
proc_mutex_proc_pthread_create,
proc_mutex_proc_pthread_acquire,
proc_mutex_no_tryacquire,
proc_mutex_proc_pthread_release,
proc_mutex_proc_pthread_cleanup,
proc_mutex_no_child_init,
"pthread"
};
#endif
#if APR_HAS_FCNTL_SERIALIZE
static struct flock proc_mutex_lock_it;
static struct flock proc_mutex_unlock_it;
static apr_status_t proc_mutex_fcntl_release(apr_proc_mutex_t *);
static void proc_mutex_fcntl_setup(void)
{
proc_mutex_lock_it.l_whence = SEEK_SET; /* from current point */
proc_mutex_lock_it.l_start = 0; /* -"- */
proc_mutex_lock_it.l_len = 0; /* until end of file */
proc_mutex_lock_it.l_type = F_WRLCK; /* set exclusive/write lock */
proc_mutex_lock_it.l_pid = 0; /* pid not actually interesting */
proc_mutex_unlock_it.l_whence = SEEK_SET; /* from current point */
proc_mutex_unlock_it.l_start = 0; /* -"- */
proc_mutex_unlock_it.l_len = 0; /* until end of file */
proc_mutex_unlock_it.l_type = F_UNLCK; /* set exclusive/write lock */
proc_mutex_unlock_it.l_pid = 0; /* pid not actually interesting */
}
static apr_status_t proc_mutex_fcntl_cleanup(void *mutex_)
{
apr_status_t status;
apr_proc_mutex_t *mutex=mutex_;
if (mutex->curr_locked == 1) {
status = proc_mutex_fcntl_release(mutex);
if (status != APR_SUCCESS)
return status;
}
return apr_file_close(mutex->interproc);
}
static apr_status_t proc_mutex_fcntl_create(apr_proc_mutex_t *new_mutex,
const char *fname)
{
int rv;
if (fname) {
new_mutex->fname = apr_pstrdup(new_mutex->pool, fname);
rv = apr_file_open(&new_mutex->interproc, new_mutex->fname,
APR_CREATE | APR_WRITE | APR_EXCL,
APR_UREAD | APR_UWRITE | APR_GREAD | APR_WREAD,
new_mutex->pool);
}
else {
new_mutex->fname = apr_pstrdup(new_mutex->pool, "/tmp/aprXXXXXX");
rv = apr_file_mktemp(&new_mutex->interproc, new_mutex->fname,
APR_CREATE | APR_WRITE | APR_EXCL,
new_mutex->pool);
}
if (rv != APR_SUCCESS) {
return rv;
}
new_mutex->curr_locked = 0;
unlink(new_mutex->fname);
apr_pool_cleanup_register(new_mutex->pool,
(void*)new_mutex,
apr_proc_mutex_cleanup,
apr_pool_cleanup_null);
return APR_SUCCESS;
}
static apr_status_t proc_mutex_fcntl_acquire(apr_proc_mutex_t *mutex)
{
int rc;
do {
rc = fcntl(mutex->interproc->filedes, F_SETLKW, &proc_mutex_lock_it);
} while (rc < 0 && errno == EINTR);
if (rc < 0) {
return errno;
}
mutex->curr_locked=1;
return APR_SUCCESS;
}
static apr_status_t proc_mutex_fcntl_release(apr_proc_mutex_t *mutex)
{
int rc;
mutex->curr_locked=0;
do {
rc = fcntl(mutex->interproc->filedes, F_SETLKW, &proc_mutex_unlock_it);
} while (rc < 0 && errno == EINTR);
if (rc < 0) {
return errno;
}
return APR_SUCCESS;
}
static const apr_proc_mutex_unix_lock_methods_t mutex_fcntl_methods =
{
#if APR_PROCESS_LOCK_IS_GLOBAL || !APR_HAS_THREADS || defined(FCNTL_IS_GLOBAL)
APR_PROCESS_LOCK_MECH_IS_GLOBAL,
#else
0,
#endif
proc_mutex_fcntl_create,
proc_mutex_fcntl_acquire,
proc_mutex_no_tryacquire,
proc_mutex_fcntl_release,
proc_mutex_fcntl_cleanup,
proc_mutex_no_child_init,
"fcntl"
};
#endif /* fcntl implementation */
#if APR_HAS_FLOCK_SERIALIZE
static apr_status_t proc_mutex_flock_release(apr_proc_mutex_t *);
static apr_status_t proc_mutex_flock_cleanup(void *mutex_)
{
apr_status_t status;
apr_proc_mutex_t *mutex=mutex_;
if (mutex->curr_locked == 1) {
status = proc_mutex_flock_release(mutex);
if (status != APR_SUCCESS)
return status;
}
if (mutex->interproc) { /* if it was opened properly */
apr_file_close(mutex->interproc);
}
unlink(mutex->fname);
return APR_SUCCESS;
}
static apr_status_t proc_mutex_flock_create(apr_proc_mutex_t *new_mutex,
const char *fname)
{
int rv;
if (fname) {
new_mutex->fname = apr_pstrdup(new_mutex->pool, fname);
rv = apr_file_open(&new_mutex->interproc, new_mutex->fname,
APR_CREATE | APR_WRITE | APR_EXCL,
APR_UREAD | APR_UWRITE,
new_mutex->pool);
}
else {
new_mutex->fname = apr_pstrdup(new_mutex->pool, "/tmp/aprXXXXXX");
rv = apr_file_mktemp(&new_mutex->interproc, new_mutex->fname,
APR_CREATE | APR_WRITE | APR_EXCL,
new_mutex->pool);
}
if (rv != APR_SUCCESS) {
proc_mutex_flock_cleanup(new_mutex);
return errno;
}
new_mutex->curr_locked = 0;
apr_pool_cleanup_register(new_mutex->pool, (void *)new_mutex,
apr_proc_mutex_cleanup,
apr_pool_cleanup_null);
return APR_SUCCESS;
}
static apr_status_t proc_mutex_flock_acquire(apr_proc_mutex_t *mutex)
{
int rc;
do {
rc = flock(mutex->interproc->filedes, LOCK_EX);
} while (rc < 0 && errno == EINTR);
if (rc < 0) {
return errno;
}
mutex->curr_locked = 1;
return APR_SUCCESS;
}
static apr_status_t proc_mutex_flock_release(apr_proc_mutex_t *mutex)
{
int rc;
mutex->curr_locked = 0;
do {
rc = flock(mutex->interproc->filedes, LOCK_UN);
} while (rc < 0 && errno == EINTR);
if (rc < 0) {
return errno;
}
return APR_SUCCESS;
}
static apr_status_t proc_mutex_flock_child_init(apr_proc_mutex_t **mutex,
apr_pool_t *pool,
const char *fname)
{
apr_proc_mutex_t *new_mutex;
int rv;
new_mutex = (apr_proc_mutex_t *)apr_palloc(pool, sizeof(apr_proc_mutex_t));
memcpy(new_mutex, *mutex, sizeof *new_mutex);
new_mutex->pool = pool;
if (!fname) {
fname = (*mutex)->fname;
}
new_mutex->fname = apr_pstrdup(pool, fname);
rv = apr_file_open(&new_mutex->interproc, new_mutex->fname,
APR_WRITE, 0, new_mutex->pool);
if (rv != APR_SUCCESS) {
return rv;
}
*mutex = new_mutex;
return APR_SUCCESS;
}
static const apr_proc_mutex_unix_lock_methods_t mutex_flock_methods =
{
#if APR_PROCESS_LOCK_IS_GLOBAL || !APR_HAS_THREADS || defined(FLOCK_IS_GLOBAL)
APR_PROCESS_LOCK_MECH_IS_GLOBAL,
#else
0,
#endif
proc_mutex_flock_create,
proc_mutex_flock_acquire,
proc_mutex_no_tryacquire,
proc_mutex_flock_release,
proc_mutex_flock_cleanup,
proc_mutex_flock_child_init,
"flock"
};
#endif /* flock implementation */
void apr_proc_mutex_unix_setup_lock(void)
{
/* setup only needed for sysvsem and fnctl */
#if APR_HAS_SYSVSEM_SERIALIZE
proc_mutex_sysv_setup();
#endif
#if APR_HAS_FCNTL_SERIALIZE
proc_mutex_fcntl_setup();
#endif
}
static apr_status_t proc_mutex_choose_method(apr_proc_mutex_t *new_mutex, apr_lockmech_e mech)
{
switch (mech) {
case APR_LOCK_FCNTL:
#if APR_HAS_FCNTL_SERIALIZE
new_mutex->inter_meth = &mutex_fcntl_methods;
#else
return APR_ENOTIMPL;
#endif
break;
case APR_LOCK_FLOCK:
#if APR_HAS_FLOCK_SERIALIZE
new_mutex->inter_meth = &mutex_flock_methods;
#else
return APR_ENOTIMPL;
#endif
break;
case APR_LOCK_SYSVSEM:
#if APR_HAS_SYSVSEM_SERIALIZE
new_mutex->inter_meth = &mutex_sysv_methods;
#else
return APR_ENOTIMPL;
#endif
break;
case APR_LOCK_POSIXSEM:
#if APR_HAS_POSIXSEM_SERIALIZE
new_mutex->inter_meth = &mutex_posixsem_methods;
#else
return APR_ENOTIMPL;
#endif
break;
case APR_LOCK_PROC_PTHREAD:
#if APR_HAS_PROC_PTHREAD_SERIALIZE
new_mutex->inter_meth = &mutex_proc_pthread_methods;
#else
return APR_ENOTIMPL;
#endif
break;
case APR_LOCK_DEFAULT:
#if APR_USE_FLOCK_SERIALIZE
new_mutex->inter_meth = &mutex_flock_methods;
#elif APR_USE_SYSVSEM_SERIALIZE
new_mutex->inter_meth = &mutex_sysv_methods;
#elif APR_USE_FCNTL_SERIALIZE
new_mutex->inter_meth = &mutex_fcntl_methods;
#elif APR_USE_PROC_PTHREAD_SERIALIZE
new_mutex->inter_meth = &mutex_proc_pthread_methods;
#elif APR_USE_POSIXSEM_SERIALIZE
new_mutex->inter_meth = &mutex_posixsem_methods;
#else
return APR_ENOTIMPL;
#endif
break;
default:
return APR_ENOTIMPL;
}
return APR_SUCCESS;
}
APR_DECLARE(const char *) apr_proc_mutex_defname(void)
{
apr_status_t rv;
apr_proc_mutex_t mutex;
if ((rv = proc_mutex_choose_method(&mutex, APR_LOCK_DEFAULT)) != APR_SUCCESS) {
return "unknown";
}
mutex.meth = mutex.inter_meth;
return apr_proc_mutex_name(&mutex);
}
static apr_status_t proc_mutex_create(apr_proc_mutex_t *new_mutex, apr_lockmech_e mech, const char *fname)
{
apr_status_t rv;
if ((rv = proc_mutex_choose_method(new_mutex, mech)) != APR_SUCCESS) {
return rv;
}
new_mutex->meth = new_mutex->inter_meth;
if ((rv = new_mutex->meth->create(new_mutex, fname)) != APR_SUCCESS) {
return rv;
}
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_proc_mutex_create(apr_proc_mutex_t **mutex,
const char *fname,
apr_lockmech_e mech,
apr_pool_t *pool)
{
apr_proc_mutex_t *new_mutex;
apr_status_t rv;
new_mutex = apr_pcalloc(pool, sizeof(apr_proc_mutex_t));
new_mutex->pool = pool;
if ((rv = proc_mutex_create(new_mutex, mech, fname)) != APR_SUCCESS)
return rv;
*mutex = new_mutex;
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_proc_mutex_child_init(apr_proc_mutex_t **mutex,
const char *fname,
apr_pool_t *pool)
{
return (*mutex)->meth->child_init(mutex, pool, fname);
}
APR_DECLARE(apr_status_t) apr_proc_mutex_lock(apr_proc_mutex_t *mutex)
{
return mutex->meth->acquire(mutex);
}
APR_DECLARE(apr_status_t) apr_proc_mutex_trylock(apr_proc_mutex_t *mutex)
{
return mutex->meth->tryacquire(mutex);
}
APR_DECLARE(apr_status_t) apr_proc_mutex_unlock(apr_proc_mutex_t *mutex)
{
return mutex->meth->release(mutex);
}
APR_DECLARE(apr_status_t) apr_proc_mutex_cleanup(void *mutex)
{
return ((apr_proc_mutex_t *)mutex)->meth->cleanup(mutex);
}
APR_DECLARE(const char *) apr_proc_mutex_name(apr_proc_mutex_t *mutex)
{
return mutex->meth->name;
}
APR_DECLARE(const char *) apr_proc_mutex_lockfile(apr_proc_mutex_t *mutex)
{
/* POSIX sems use the fname field but don't use a file,
* so be careful. */
#if APR_HAS_FLOCK_SERIALIZE
if (mutex->meth == &mutex_flock_methods) {
return mutex->fname;
}
#endif
#if APR_HAS_FCNTL_SERIALIZE
if (mutex->meth == &mutex_fcntl_methods) {
return mutex->fname;
}
#endif
return NULL;
}
APR_POOL_IMPLEMENT_ACCESSOR(proc_mutex)
/* Implement OS-specific accessors defined in apr_portable.h */
APR_DECLARE(apr_status_t) apr_os_proc_mutex_get(apr_os_proc_mutex_t *ospmutex,
apr_proc_mutex_t *pmutex)
{
#if APR_HAS_SYSVSEM_SERIALIZE || APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE || APR_HAS_POSIXSEM_SERIALIZE
ospmutex->crossproc = pmutex->interproc->filedes;
#endif
#if APR_HAS_PROC_PTHREAD_SERIALIZE
ospmutex->pthread_interproc = pmutex->pthread_interproc;
#endif
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_os_proc_mutex_put(apr_proc_mutex_t **pmutex,
apr_os_proc_mutex_t *ospmutex,
apr_pool_t *pool)
{
if (pool == NULL) {
return APR_ENOPOOL;
}
if ((*pmutex) == NULL) {
(*pmutex) = (apr_proc_mutex_t *)apr_pcalloc(pool,
sizeof(apr_proc_mutex_t));
(*pmutex)->pool = pool;
}
#if APR_HAS_SYSVSEM_SERIALIZE || APR_HAS_FCNTL_SERIALIZE || APR_HAS_FLOCK_SERIALIZE || APR_HAS_POSIXSEM_SERIALIZE
apr_os_file_put(&(*pmutex)->interproc, &ospmutex->crossproc, 0, pool);
#endif
#if APR_HAS_PROC_PTHREAD_SERIALIZE
(*pmutex)->pthread_interproc = ospmutex->pthread_interproc;
#endif
return APR_SUCCESS;
}
| 001-log4cxx | trunk/src/apr/locks/unix/proc_mutex.c | C | asf20 | 24,976 |
/* 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_arch_thread_rwlock.h"
#include "apr_private.h"
#if APR_HAS_THREADS
#ifdef HAVE_PTHREAD_RWLOCKS
/* The rwlock must be initialized but not locked by any thread when
* cleanup is called. */
static apr_status_t thread_rwlock_cleanup(void *data)
{
apr_thread_rwlock_t *rwlock = (apr_thread_rwlock_t *)data;
apr_status_t stat;
stat = pthread_rwlock_destroy(&rwlock->rwlock);
#ifdef PTHREAD_SETS_ERRNO
if (stat) {
stat = errno;
}
#endif
return stat;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_create(apr_thread_rwlock_t **rwlock,
apr_pool_t *pool)
{
apr_thread_rwlock_t *new_rwlock;
apr_status_t stat;
new_rwlock = apr_palloc(pool, sizeof(apr_thread_rwlock_t));
new_rwlock->pool = pool;
if ((stat = pthread_rwlock_init(&new_rwlock->rwlock, NULL))) {
#ifdef PTHREAD_SETS_ERRNO
stat = errno;
#endif
return stat;
}
apr_pool_cleanup_register(new_rwlock->pool,
(void *)new_rwlock, thread_rwlock_cleanup,
apr_pool_cleanup_null);
*rwlock = new_rwlock;
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_rdlock(apr_thread_rwlock_t *rwlock)
{
apr_status_t stat;
stat = pthread_rwlock_rdlock(&rwlock->rwlock);
#ifdef PTHREAD_SETS_ERRNO
if (stat) {
stat = errno;
}
#endif
return stat;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_tryrdlock(apr_thread_rwlock_t *rwlock)
{
apr_status_t stat;
stat = pthread_rwlock_tryrdlock(&rwlock->rwlock);
#ifdef PTHREAD_SETS_ERRNO
if (stat) {
stat = errno;
}
#endif
/* Normalize the return code. */
if (stat == EBUSY)
stat = APR_EBUSY;
return stat;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_wrlock(apr_thread_rwlock_t *rwlock)
{
apr_status_t stat;
stat = pthread_rwlock_wrlock(&rwlock->rwlock);
#ifdef PTHREAD_SETS_ERRNO
if (stat) {
stat = errno;
}
#endif
return stat;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_trywrlock(apr_thread_rwlock_t *rwlock)
{
apr_status_t stat;
stat = pthread_rwlock_trywrlock(&rwlock->rwlock);
#ifdef PTHREAD_SETS_ERRNO
if (stat) {
stat = errno;
}
#endif
/* Normalize the return code. */
if (stat == EBUSY)
stat = APR_EBUSY;
return stat;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_unlock(apr_thread_rwlock_t *rwlock)
{
apr_status_t stat;
stat = pthread_rwlock_unlock(&rwlock->rwlock);
#ifdef PTHREAD_SETS_ERRNO
if (stat) {
stat = errno;
}
#endif
return stat;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_destroy(apr_thread_rwlock_t *rwlock)
{
return apr_pool_cleanup_run(rwlock->pool, rwlock, thread_rwlock_cleanup);
}
#else /* HAVE_PTHREAD_RWLOCKS */
APR_DECLARE(apr_status_t) apr_thread_rwlock_create(apr_thread_rwlock_t **rwlock,
apr_pool_t *pool)
{
return APR_ENOTIMPL;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_rdlock(apr_thread_rwlock_t *rwlock)
{
return APR_ENOTIMPL;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_tryrdlock(apr_thread_rwlock_t *rwlock)
{
return APR_ENOTIMPL;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_wrlock(apr_thread_rwlock_t *rwlock)
{
return APR_ENOTIMPL;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_trywrlock(apr_thread_rwlock_t *rwlock)
{
return APR_ENOTIMPL;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_unlock(apr_thread_rwlock_t *rwlock)
{
return APR_ENOTIMPL;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_destroy(apr_thread_rwlock_t *rwlock)
{
return APR_ENOTIMPL;
}
#endif /* HAVE_PTHREAD_RWLOCKS */
APR_POOL_IMPLEMENT_ACCESSOR(thread_rwlock)
#endif /* APR_HAS_THREADS */
| 001-log4cxx | trunk/src/apr/locks/unix/thread_rwlock.c | C | asf20 | 4,591 |
/* 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 <nks/errno.h>
#include "apr.h"
#include "apr_private.h"
#include "apr_general.h"
#include "apr_strings.h"
#include "apr_arch_thread_mutex.h"
#include "apr_arch_thread_cond.h"
#include "apr_portable.h"
static apr_status_t thread_cond_cleanup(void *data)
{
apr_thread_cond_t *cond = (apr_thread_cond_t *)data;
NXCondFree(cond->cond);
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_cond_create(apr_thread_cond_t **cond,
apr_pool_t *pool)
{
apr_thread_cond_t *new_cond = NULL;
new_cond = (apr_thread_cond_t *)apr_pcalloc(pool, sizeof(apr_thread_cond_t));
if(new_cond ==NULL) {
return APR_ENOMEM;
}
new_cond->pool = pool;
new_cond->cond = NXCondAlloc(NULL);
if(new_cond->cond == NULL)
return APR_ENOMEM;
apr_pool_cleanup_register(new_cond->pool, new_cond,
(void*)thread_cond_cleanup,
apr_pool_cleanup_null);
*cond = new_cond;
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_cond_wait(apr_thread_cond_t *cond,
apr_thread_mutex_t *mutex)
{
if (NXCondWait(cond->cond, mutex->mutex) != 0)
return APR_EINTR;
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_cond_timedwait(apr_thread_cond_t *cond,
apr_thread_mutex_t *mutex,
apr_interval_time_t timeout){
if (NXCondTimedWait(cond->cond, mutex->mutex,
(timeout*1000)/NXGetSystemTick()) == NX_ETIMEDOUT) {
return APR_TIMEUP;
}
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_cond_signal(apr_thread_cond_t *cond)
{
NXCondSignal(cond->cond);
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_cond_broadcast(apr_thread_cond_t *cond)
{
NXCondBroadcast(cond->cond);
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_cond_destroy(apr_thread_cond_t *cond)
{
apr_status_t stat;
if ((stat = thread_cond_cleanup(cond)) == APR_SUCCESS) {
apr_pool_cleanup_kill(cond->pool, cond, thread_cond_cleanup);
return APR_SUCCESS;
}
return stat;
}
APR_POOL_IMPLEMENT_ACCESSOR(thread_cond)
| 001-log4cxx | trunk/src/apr/locks/netware/thread_cond.c | C | asf20 | 3,132 |
/* 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_general.h"
#include "apr_strings.h"
#include "apr_arch_thread_mutex.h"
#include "apr_portable.h"
static apr_status_t thread_mutex_cleanup(void *data)
{
apr_thread_mutex_t *mutex = (apr_thread_mutex_t *)data;
NXMutexFree(mutex->mutex);
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_mutex_create(apr_thread_mutex_t **mutex,
unsigned int flags,
apr_pool_t *pool)
{
apr_thread_mutex_t *new_mutex = NULL;
/* XXX: Implement _UNNESTED flavor and favor _DEFAULT for performance
*/
if (flags & APR_THREAD_MUTEX_UNNESTED) {
return APR_ENOTIMPL;
}
new_mutex = (apr_thread_mutex_t *)apr_pcalloc(pool, sizeof(apr_thread_mutex_t));
if(new_mutex ==NULL) {
return APR_ENOMEM;
}
new_mutex->pool = pool;
new_mutex->mutex = NXMutexAlloc(NX_MUTEX_RECURSIVE, 0, NULL);
if(new_mutex->mutex == NULL)
return APR_ENOMEM;
apr_pool_cleanup_register(new_mutex->pool, new_mutex,
(void*)thread_mutex_cleanup,
apr_pool_cleanup_null);
*mutex = new_mutex;
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_mutex_lock(apr_thread_mutex_t *mutex)
{
NXLock(mutex->mutex);
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_mutex_trylock(apr_thread_mutex_t *mutex)
{
if (!NXTryLock(mutex->mutex))
return APR_EBUSY;
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_mutex_unlock(apr_thread_mutex_t *mutex)
{
NXUnlock(mutex->mutex);
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_mutex_destroy(apr_thread_mutex_t *mutex)
{
apr_status_t stat;
if ((stat = thread_mutex_cleanup(mutex)) == APR_SUCCESS) {
apr_pool_cleanup_kill(mutex->pool, mutex, thread_mutex_cleanup);
return APR_SUCCESS;
}
return stat;
}
APR_POOL_IMPLEMENT_ACCESSOR(thread_mutex)
| 001-log4cxx | trunk/src/apr/locks/netware/thread_mutex.c | C | asf20 | 2,862 |
/* 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_portable.h"
#include "apr_arch_proc_mutex.h"
#include "apr_arch_thread_mutex.h"
APR_DECLARE(apr_status_t) apr_proc_mutex_create(apr_proc_mutex_t **mutex,
const char *fname,
apr_lockmech_e mech,
apr_pool_t *pool)
{
apr_status_t ret;
apr_proc_mutex_t *new_mutex = NULL;
new_mutex = (apr_proc_mutex_t *)apr_pcalloc(pool, sizeof(apr_proc_mutex_t));
if(new_mutex ==NULL) {
return APR_ENOMEM;
}
new_mutex->pool = pool;
ret = apr_thread_mutex_create(&(new_mutex->mutex), APR_THREAD_MUTEX_DEFAULT, pool);
if (ret == APR_SUCCESS)
*mutex = new_mutex;
return ret;
}
APR_DECLARE(apr_status_t) apr_proc_mutex_child_init(apr_proc_mutex_t **mutex,
const char *fname,
apr_pool_t *pool)
{
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_proc_mutex_lock(apr_proc_mutex_t *mutex)
{
if (mutex)
return apr_thread_mutex_lock(mutex->mutex);
return APR_ENOLOCK;
}
APR_DECLARE(apr_status_t) apr_proc_mutex_trylock(apr_proc_mutex_t *mutex)
{
if (mutex)
return apr_thread_mutex_trylock(mutex->mutex);
return APR_ENOLOCK;
}
APR_DECLARE(apr_status_t) apr_proc_mutex_unlock(apr_proc_mutex_t *mutex)
{
if (mutex)
return apr_thread_mutex_unlock(mutex->mutex);
return APR_ENOLOCK;
}
APR_DECLARE(apr_status_t) apr_proc_mutex_cleanup(void *mutex)
{
return apr_proc_mutex_destroy(mutex);
}
APR_DECLARE(apr_status_t) apr_proc_mutex_destroy(apr_proc_mutex_t *mutex)
{
if (mutex)
return apr_thread_mutex_destroy(mutex->mutex);
return APR_ENOLOCK;
}
APR_DECLARE(const char *) apr_proc_mutex_lockfile(apr_proc_mutex_t *mutex)
{
return NULL;
}
APR_DECLARE(const char *) apr_proc_mutex_name(apr_proc_mutex_t *mutex)
{
return "netwarethread";
}
APR_DECLARE(const char *) apr_proc_mutex_defname(void)
{
return "netwarethread";
}
APR_POOL_IMPLEMENT_ACCESSOR(proc_mutex)
/* Implement OS-specific accessors defined in apr_portable.h */
apr_status_t apr_os_proc_mutex_get(apr_os_proc_mutex_t *ospmutex,
apr_proc_mutex_t *pmutex)
{
if (pmutex)
ospmutex = pmutex->mutex->mutex;
return APR_ENOLOCK;
}
apr_status_t apr_os_proc_mutex_put(apr_proc_mutex_t **pmutex,
apr_os_proc_mutex_t *ospmutex,
apr_pool_t *pool)
{
return APR_ENOTIMPL;
}
| 001-log4cxx | trunk/src/apr/locks/netware/proc_mutex.c | C | asf20 | 3,484 |
/* 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_general.h"
#include "apr_strings.h"
#include "apr_arch_thread_rwlock.h"
#include "apr_portable.h"
static apr_status_t thread_rwlock_cleanup(void *data)
{
apr_thread_rwlock_t *rwlock = (apr_thread_rwlock_t *)data;
NXRwLockFree (rwlock->rwlock);
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_create(apr_thread_rwlock_t **rwlock,
apr_pool_t *pool)
{
apr_thread_rwlock_t *new_rwlock = NULL;
NXHierarchy_t hierarchy = 1; //for libc NKS NXRwLockAlloc
NXLockInfo_t *info; //for libc NKS NXRwLockAlloc
new_rwlock = (apr_thread_rwlock_t *)apr_pcalloc(pool, sizeof(apr_thread_rwlock_t));
if(new_rwlock ==NULL) {
return APR_ENOMEM;
}
new_rwlock->pool = pool;
info = (NXLockInfo_t *)apr_pcalloc(pool, sizeof(NXLockInfo_t));
new_rwlock->rwlock = NXRwLockAlloc(hierarchy, info);
if(new_rwlock->rwlock == NULL)
return APR_ENOMEM;
apr_pool_cleanup_register(new_rwlock->pool, new_rwlock, thread_rwlock_cleanup,
apr_pool_cleanup_null);
*rwlock = new_rwlock;
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_rdlock(apr_thread_rwlock_t *rwlock)
{
NXRdLock(rwlock->rwlock);
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_tryrdlock(apr_thread_rwlock_t *rwlock)
{
if (!NXTryRdLock(rwlock->rwlock))
return APR_EBUSY;
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_wrlock(apr_thread_rwlock_t *rwlock)
{
NXWrLock(rwlock->rwlock);
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_trywrlock(apr_thread_rwlock_t *rwlock)
{
if (!NXTryWrLock(rwlock->rwlock))
return APR_EBUSY;
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_unlock(apr_thread_rwlock_t *rwlock)
{
NXRwUnlock(rwlock->rwlock);
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_destroy(apr_thread_rwlock_t *rwlock)
{
apr_status_t stat;
if ((stat = thread_rwlock_cleanup(rwlock)) == APR_SUCCESS) {
apr_pool_cleanup_kill(rwlock->pool, rwlock, thread_rwlock_cleanup);
return APR_SUCCESS;
}
return stat;
}
APR_POOL_IMPLEMENT_ACCESSOR(thread_rwlock)
| 001-log4cxx | trunk/src/apr/locks/netware/thread_rwlock.c | C | asf20 | 3,137 |
/* 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_general.h"
#include "apr_lib.h"
#include "apr_strings.h"
#include "apr_portable.h"
#include "apr_arch_thread_mutex.h"
#include "apr_arch_thread_cond.h"
#include "apr_arch_file_io.h"
#include <string.h>
APR_DECLARE(apr_status_t) apr_thread_cond_create(apr_thread_cond_t **cond,
apr_pool_t *pool)
{
return APR_ENOTIMPL;
}
APR_DECLARE(apr_status_t) apr_thread_cond_wait(apr_thread_cond_t *cond,
apr_thread_mutex_t *mutex)
{
return APR_ENOTIMPL;
}
APR_DECLARE(apr_status_t) apr_thread_cond_timedwait(apr_thread_cond_t *cond,
apr_thread_mutex_t *mutex,
apr_interval_time_t timeout){
return APR_ENOTIMPL;
}
APR_DECLARE(apr_status_t) apr_thread_cond_signal(apr_thread_cond_t *cond)
{
return APR_ENOTIMPL;
}
APR_DECLARE(apr_status_t) apr_thread_cond_broadcast(apr_thread_cond_t *cond)
{
return APR_ENOTIMPL;
}
APR_DECLARE(apr_status_t) apr_thread_cond_destroy(apr_thread_cond_t *cond)
{
return APR_ENOTIMPL;
}
APR_POOL_IMPLEMENT_ACCESSOR(thread_cond)
| 001-log4cxx | trunk/src/apr/locks/os2/thread_cond.c | C | asf20 | 1,989 |
/* 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_general.h"
#include "apr_lib.h"
#include "apr_strings.h"
#include "apr_portable.h"
#include "apr_arch_thread_mutex.h"
#include "apr_arch_file_io.h"
#include <string.h>
#include <stddef.h>
static apr_status_t thread_mutex_cleanup(void *themutex)
{
apr_thread_mutex_t *mutex = themutex;
return apr_thread_mutex_destroy(mutex);
}
/* XXX: Need to respect APR_THREAD_MUTEX_[UN]NESTED flags argument
* or return APR_ENOTIMPL!!!
*/
APR_DECLARE(apr_status_t) apr_thread_mutex_create(apr_thread_mutex_t **mutex,
unsigned int flags,
apr_pool_t *pool)
{
apr_thread_mutex_t *new_mutex;
ULONG rc;
new_mutex = (apr_thread_mutex_t *)apr_palloc(pool, sizeof(apr_thread_mutex_t));
new_mutex->pool = pool;
rc = DosCreateMutexSem(NULL, &(new_mutex->hMutex), 0, FALSE);
*mutex = new_mutex;
if (!rc)
apr_pool_cleanup_register(pool, new_mutex, thread_mutex_cleanup, apr_pool_cleanup_null);
return APR_OS2_STATUS(rc);
}
APR_DECLARE(apr_status_t) apr_thread_mutex_lock(apr_thread_mutex_t *mutex)
{
ULONG rc = DosRequestMutexSem(mutex->hMutex, SEM_INDEFINITE_WAIT);
return APR_OS2_STATUS(rc);
}
APR_DECLARE(apr_status_t) apr_thread_mutex_trylock(apr_thread_mutex_t *mutex)
{
ULONG rc = DosRequestMutexSem(mutex->hMutex, SEM_IMMEDIATE_RETURN);
return APR_OS2_STATUS(rc);
}
APR_DECLARE(apr_status_t) apr_thread_mutex_unlock(apr_thread_mutex_t *mutex)
{
ULONG rc = DosReleaseMutexSem(mutex->hMutex);
return APR_OS2_STATUS(rc);
}
APR_DECLARE(apr_status_t) apr_thread_mutex_destroy(apr_thread_mutex_t *mutex)
{
ULONG rc;
if (mutex->hMutex == 0)
return APR_SUCCESS;
while (DosReleaseMutexSem(mutex->hMutex) == 0);
rc = DosCloseMutexSem(mutex->hMutex);
if (!rc) {
mutex->hMutex = 0;
return APR_SUCCESS;
}
return APR_FROM_OS_ERROR(rc);
}
APR_POOL_IMPLEMENT_ACCESSOR(thread_mutex)
| 001-log4cxx | trunk/src/apr/locks/os2/thread_mutex.c | C | asf20 | 2,819 |
/* 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_general.h"
#include "apr_lib.h"
#include "apr_strings.h"
#include "apr_portable.h"
#include "apr_arch_proc_mutex.h"
#include "apr_arch_file_io.h"
#include <string.h>
#include <stddef.h>
#define CurrentTid (*_threadid)
static char *fixed_name(const char *fname, apr_pool_t *pool)
{
char *semname;
if (fname == NULL)
semname = NULL;
else {
// Semaphores don't live in the file system, fix up the name
while (*fname == '/' || *fname == '\\') {
fname++;
}
semname = apr_pstrcat(pool, "/SEM32/", fname, NULL);
if (semname[8] == ':') {
semname[8] = '$';
}
}
return semname;
}
APR_DECLARE(apr_status_t) apr_proc_mutex_cleanup(void *vmutex)
{
apr_proc_mutex_t *mutex = vmutex;
return apr_proc_mutex_destroy(mutex);
}
APR_DECLARE(const char *) apr_proc_mutex_lockfile(apr_proc_mutex_t *mutex)
{
return NULL;
}
APR_DECLARE(const char *) apr_proc_mutex_name(apr_proc_mutex_t *mutex)
{
return "os2sem";
}
APR_DECLARE(const char *) apr_proc_mutex_defname(void)
{
return "os2sem";
}
APR_DECLARE(apr_status_t) apr_proc_mutex_create(apr_proc_mutex_t **mutex,
const char *fname,
apr_lockmech_e mech,
apr_pool_t *pool)
{
apr_proc_mutex_t *new;
ULONG rc;
char *semname;
if (mech != APR_LOCK_DEFAULT) {
return APR_ENOTIMPL;
}
new = (apr_proc_mutex_t *)apr_palloc(pool, sizeof(apr_proc_mutex_t));
new->pool = pool;
new->owner = 0;
new->lock_count = 0;
*mutex = new;
semname = fixed_name(fname, pool);
rc = DosCreateMutexSem(semname, &(new->hMutex), DC_SEM_SHARED, FALSE);
if (!rc) {
apr_pool_cleanup_register(pool, new, apr_proc_mutex_cleanup, apr_pool_cleanup_null);
}
return APR_FROM_OS_ERROR(rc);
}
APR_DECLARE(apr_status_t) apr_proc_mutex_child_init(apr_proc_mutex_t **mutex,
const char *fname,
apr_pool_t *pool)
{
apr_proc_mutex_t *new;
ULONG rc;
char *semname;
new = (apr_proc_mutex_t *)apr_palloc(pool, sizeof(apr_proc_mutex_t));
new->pool = pool;
new->owner = 0;
new->lock_count = 0;
semname = fixed_name(fname, pool);
rc = DosOpenMutexSem(semname, &(new->hMutex));
*mutex = new;
if (!rc) {
apr_pool_cleanup_register(pool, new, apr_proc_mutex_cleanup, apr_pool_cleanup_null);
}
return APR_FROM_OS_ERROR(rc);
}
APR_DECLARE(apr_status_t) apr_proc_mutex_lock(apr_proc_mutex_t *mutex)
{
ULONG rc = DosRequestMutexSem(mutex->hMutex, SEM_INDEFINITE_WAIT);
if (rc == 0) {
mutex->owner = CurrentTid;
mutex->lock_count++;
}
return APR_FROM_OS_ERROR(rc);
}
APR_DECLARE(apr_status_t) apr_proc_mutex_trylock(apr_proc_mutex_t *mutex)
{
ULONG rc = DosRequestMutexSem(mutex->hMutex, SEM_IMMEDIATE_RETURN);
if (rc == 0) {
mutex->owner = CurrentTid;
mutex->lock_count++;
}
return APR_FROM_OS_ERROR(rc);
}
APR_DECLARE(apr_status_t) apr_proc_mutex_unlock(apr_proc_mutex_t *mutex)
{
ULONG rc;
if (mutex->owner == CurrentTid && mutex->lock_count > 0) {
mutex->lock_count--;
rc = DosReleaseMutexSem(mutex->hMutex);
return APR_FROM_OS_ERROR(rc);
}
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_proc_mutex_destroy(apr_proc_mutex_t *mutex)
{
ULONG rc;
apr_status_t status = APR_SUCCESS;
if (mutex->owner == CurrentTid) {
while (mutex->lock_count > 0 && status == APR_SUCCESS) {
status = apr_proc_mutex_unlock(mutex);
}
}
if (status != APR_SUCCESS) {
return status;
}
if (mutex->hMutex == 0) {
return APR_SUCCESS;
}
rc = DosCloseMutexSem(mutex->hMutex);
if (!rc) {
mutex->hMutex = 0;
}
return APR_FROM_OS_ERROR(rc);
}
APR_POOL_IMPLEMENT_ACCESSOR(proc_mutex)
/* Implement OS-specific accessors defined in apr_portable.h */
APR_DECLARE(apr_status_t) apr_os_proc_mutex_get(apr_os_proc_mutex_t *ospmutex,
apr_proc_mutex_t *pmutex)
{
*ospmutex = pmutex->hMutex;
return APR_ENOTIMPL;
}
APR_DECLARE(apr_status_t) apr_os_proc_mutex_put(apr_proc_mutex_t **pmutex,
apr_os_proc_mutex_t *ospmutex,
apr_pool_t *pool)
{
apr_proc_mutex_t *new;
new = (apr_proc_mutex_t *)apr_palloc(pool, sizeof(apr_proc_mutex_t));
new->pool = pool;
new->owner = 0;
new->lock_count = 0;
new->hMutex = *ospmutex;
*pmutex = new;
return APR_SUCCESS;
}
| 001-log4cxx | trunk/src/apr/locks/os2/proc_mutex.c | C | asf20 | 5,689 |
/* 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_general.h"
#include "apr_lib.h"
#include "apr_strings.h"
#include "apr_portable.h"
#include "apr_arch_thread_rwlock.h"
#include "apr_arch_file_io.h"
#include <string.h>
static apr_status_t thread_rwlock_cleanup(void *therwlock)
{
apr_thread_rwlock_t *rwlock = therwlock;
return apr_thread_rwlock_destroy(rwlock);
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_create(apr_thread_rwlock_t **rwlock,
apr_pool_t *pool)
{
apr_thread_rwlock_t *new_rwlock;
ULONG rc;
new_rwlock = (apr_thread_rwlock_t *)apr_palloc(pool, sizeof(apr_thread_rwlock_t));
new_rwlock->pool = pool;
new_rwlock->readers = 0;
rc = DosCreateMutexSem(NULL, &(new_rwlock->write_lock), 0, FALSE);
if (rc)
return APR_FROM_OS_ERROR(rc);
rc = DosCreateEventSem(NULL, &(new_rwlock->read_done), 0, FALSE);
if (rc)
return APR_FROM_OS_ERROR(rc);
*rwlock = new_rwlock;
if (!rc)
apr_pool_cleanup_register(pool, new_rwlock, thread_rwlock_cleanup,
apr_pool_cleanup_null);
return APR_FROM_OS_ERROR(rc);
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_rdlock(apr_thread_rwlock_t *rwlock)
{
ULONG rc, posts;
rc = DosRequestMutexSem(rwlock->write_lock, SEM_INDEFINITE_WAIT);
if (rc)
return APR_FROM_OS_ERROR(rc);
/* We've successfully acquired the writer mutex so we can't be locked
* for write which means it's ok to add a reader lock. The writer mutex
* doubles as race condition protection for the readers counter.
*/
rwlock->readers++;
DosResetEventSem(rwlock->read_done, &posts);
rc = DosReleaseMutexSem(rwlock->write_lock);
return APR_FROM_OS_ERROR(rc);
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_tryrdlock(apr_thread_rwlock_t *rwlock)
{
/* As above but with different wait time */
ULONG rc, posts;
rc = DosRequestMutexSem(rwlock->write_lock, SEM_IMMEDIATE_RETURN);
if (rc)
return APR_FROM_OS_ERROR(rc);
rwlock->readers++;
DosResetEventSem(rwlock->read_done, &posts);
rc = DosReleaseMutexSem(rwlock->write_lock);
return APR_FROM_OS_ERROR(rc);
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_wrlock(apr_thread_rwlock_t *rwlock)
{
ULONG rc;
rc = DosRequestMutexSem(rwlock->write_lock, SEM_INDEFINITE_WAIT);
if (rc)
return APR_FROM_OS_ERROR(rc);
/* We've got the writer lock but we have to wait for all readers to
* unlock before it's ok to use it
*/
if (rwlock->readers) {
rc = DosWaitEventSem(rwlock->read_done, SEM_INDEFINITE_WAIT);
if (rc)
DosReleaseMutexSem(rwlock->write_lock);
}
return APR_FROM_OS_ERROR(rc);
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_trywrlock(apr_thread_rwlock_t *rwlock)
{
ULONG rc;
rc = DosRequestMutexSem(rwlock->write_lock, SEM_IMMEDIATE_RETURN);
if (rc)
return APR_FROM_OS_ERROR(rc);
/* We've got the writer lock but we have to wait for all readers to
* unlock before it's ok to use it
*/
if (rwlock->readers) {
/* There are readers active, give up */
DosReleaseMutexSem(rwlock->write_lock);
rc = ERROR_TIMEOUT;
}
return APR_FROM_OS_ERROR(rc);
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_unlock(apr_thread_rwlock_t *rwlock)
{
ULONG rc;
/* First, guess that we're unlocking a writer */
rc = DosReleaseMutexSem(rwlock->write_lock);
if (rc == ERROR_NOT_OWNER) {
/* Nope, we must have a read lock */
if (rwlock->readers) {
DosEnterCritSec();
rwlock->readers--;
if (rwlock->readers == 0) {
DosPostEventSem(rwlock->read_done);
}
DosExitCritSec();
rc = 0;
}
}
return APR_FROM_OS_ERROR(rc);
}
APR_DECLARE(apr_status_t) apr_thread_rwlock_destroy(apr_thread_rwlock_t *rwlock)
{
ULONG rc;
if (rwlock->write_lock == 0)
return APR_SUCCESS;
while (DosReleaseMutexSem(rwlock->write_lock) == 0);
rc = DosCloseMutexSem(rwlock->write_lock);
if (!rc) {
rwlock->write_lock = 0;
DosCloseEventSem(rwlock->read_done);
return APR_SUCCESS;
}
return APR_FROM_OS_ERROR(rc);
}
APR_POOL_IMPLEMENT_ACCESSOR(thread_rwlock)
| 001-log4cxx | trunk/src/apr/locks/os2/thread_rwlock.c | C | asf20 | 5,150 |
;
; 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.
;
MessageId=1
Language=English
Trace
.
MessageId=2
Language=English
Debug
.
MessageId=3
Language=English
Info
.
MessageId=4
Language=English
Warn
.
MessageId=5
Language=English
Error
.
MessageId=6
Language=English
Fatal
.
MessageId=0x1000
Language=English
%1
.
| 001-log4cxx | trunk/src/main/resources/EventLogCategories.mc | M4 | asf20 | 1,050 |
/*
* 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.
*/
#ifndef _LOG4CXX_APPENDER_H
#define _LOG4CXX_APPENDER_H
#if defined(_MSC_VER)
#pragma warning ( push )
#pragma warning ( disable: 4231 4251 4275 4786 )
#endif
#include <log4cxx/spi/optionhandler.h>
#include <log4cxx/helpers/objectptr.h>
#include <log4cxx/helpers/object.h>
#include <vector>
namespace log4cxx
{
// Forward declarations
namespace spi
{
class LoggingEvent;
typedef helpers::ObjectPtrT<LoggingEvent> LoggingEventPtr;
class Filter;
typedef helpers::ObjectPtrT<Filter> FilterPtr;
class ErrorHandler;
typedef log4cxx::helpers::ObjectPtrT<ErrorHandler> ErrorHandlerPtr;
}
class Layout;
typedef log4cxx::helpers::ObjectPtrT<Layout> LayoutPtr;
/**
Implement this interface for your own strategies for outputting log
statements.
*/
class LOG4CXX_EXPORT Appender :
public virtual spi::OptionHandler
{
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(Appender)
virtual ~Appender() {}
/**
Add a filter to the end of the filter list.
*/
virtual void addFilter(const spi::FilterPtr& newFilter) = 0;
/**
Returns the head Filter. The Filters are organized in a linked list
and so all Filters on this Appender are available through the result.
@return the head Filter or null, if no Filters are present
*/
virtual spi::FilterPtr getFilter() const = 0;
/**
Clear the list of filters by removing all the filters in it.
*/
virtual void clearFilters() = 0;
/**
Release any resources allocated within the appender such as file
handles, network connections, etc.
<p>It is a programming error to append to a closed appender.
*/
virtual void close() = 0;
/**
Log in <code>Appender</code> specific way. When appropriate,
Loggers will call the <code>doAppend</code> method of appender
implementations in order to log.
*/
virtual void doAppend(const spi::LoggingEventPtr& event,
log4cxx::helpers::Pool& pool) = 0;
/**
Get the name of this appender. The name uniquely identifies the
appender.
*/
virtual LogString getName() const = 0;
/**
Set the Layout for this appender.
*/
virtual void setLayout(const LayoutPtr& layout) = 0;
/**
Returns this appenders layout.
*/
virtual LayoutPtr getLayout() const = 0;
/**
Set the name of this appender. The name is used by other
components to identify this appender.
*/
virtual void setName(const LogString& name) = 0;
/**
Configurators call this method to determine if the appender
requires a layout. If this method returns <code>true</code>,
meaning that layout is required, then the configurator will
configure an layout using the configuration information at its
disposal. If this method returns <code>false</code>, meaning that
a layout is not required, then layout configuration will be
skipped even if there is available layout configuration
information at the disposal of the configurator..
<p>In the rather exceptional case, where the appender
implementation admits a layout but can also work without it, then
the appender should return <code>true</code>.
*/
virtual bool requiresLayout() const = 0;
};
LOG4CXX_PTR_DEF(Appender);
LOG4CXX_LIST_DEF(AppenderList, AppenderPtr);
}
#if defined(_MSC_VER)
#pragma warning ( pop )
#endif
#endif //_LOG4CXX_APPENDER_H
| 001-log4cxx | trunk/src/main/include/log4cxx/appender.h | C++ | asf20 | 4,571 |
/*
* 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.
*/
#ifndef _LOG4CXX_LAYOUT_H
#define _LOG4CXX_LAYOUT_H
#if defined(_MSC_VER)
#pragma warning ( push )
#pragma warning ( disable: 4231 4251 4275 4786 )
#endif
#include <log4cxx/helpers/objectimpl.h>
#include <log4cxx/helpers/objectptr.h>
#include <log4cxx/spi/optionhandler.h>
#include <log4cxx/spi/loggingevent.h>
namespace log4cxx
{
/**
Extend this abstract class to create your own log layout format.
*/
class LOG4CXX_EXPORT Layout :
public virtual spi::OptionHandler,
public virtual helpers::ObjectImpl
{
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(Layout)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(Layout)
LOG4CXX_CAST_ENTRY(spi::OptionHandler)
END_LOG4CXX_CAST_MAP()
virtual ~Layout();
void addRef() const;
void releaseRef() const;
/**
Implement this method to create your own layout format.
*/
virtual void format(LogString& output,
const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& pool) const = 0;
/**
Returns the content type output by this layout. The base class
returns "text/plain".
*/
virtual LogString getContentType() const;
/**
Append the header for the layout format. The base class does
nothing.
*/
virtual void appendHeader(LogString& output, log4cxx::helpers::Pool& p);
/**
Append the footer for the layout format. The base class does
nothing.
*/
virtual void appendFooter(LogString& output, log4cxx::helpers::Pool& p);
/**
If the layout handles the throwable object contained within
{@link spi::LoggingEvent LoggingEvent}, then the layout should return
<code>false</code>. Otherwise, if the layout ignores throwable
object, then the layout should return <code>true</code>.
<p>The SimpleLayout, TTCCLayout,
PatternLayout all return <code>true</code>. The {@link
xml::XMLLayout XMLLayout} returns <code>false</code>.
*/
virtual bool ignoresThrowable() const = 0;
};
LOG4CXX_PTR_DEF(Layout);
}
#if defined(_MSC_VER)
#pragma warning ( pop )
#endif
#endif // _LOG4CXX_LAYOUT_H
| 001-log4cxx | trunk/src/main/include/log4cxx/layout.h | C++ | asf20 | 3,444 |
/*
* 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.
*/
#ifndef _LOG4CXX_HIERARCHY_H
#define _LOG4CXX_HIERARCHY_H
#if defined(_MSC_VER)
#pragma warning (push)
#pragma warning ( disable: 4231 4251 4275 4786 )
#endif
#include <log4cxx/spi/loggerrepository.h>
#include <log4cxx/spi/loggerfactory.h>
#include <vector>
#include <map>
#include <log4cxx/provisionnode.h>
#include <log4cxx/helpers/objectimpl.h>
#include <log4cxx/spi/hierarchyeventlistener.h>
#include <log4cxx/helpers/pool.h>
namespace log4cxx
{
/**
This class is specialized in retrieving loggers by name and also
maintaining the logger hierarchy.
<p><em>The casual user does not have to deal with this class
directly.</em>
<p>The structure of the logger hierarchy is maintained by the
#getLogger method. The hierarchy is such that children link
to their parent but parents do not have any pointers to their
children. Moreover, loggers can be instantiated in any order, in
particular descendant before ancestor.
<p>In case a descendant is created before a particular ancestor,
then it creates a provision node for the ancestor and adds itself
to the provision node. Other descendants of the same ancestor add
themselves to the previously created provision node.
*/
class LOG4CXX_EXPORT Hierarchy :
public virtual spi::LoggerRepository,
public virtual helpers::ObjectImpl
{
private:
log4cxx::helpers::Pool pool;
log4cxx::helpers::Mutex mutex;
bool configured;
spi::LoggerFactoryPtr defaultFactory;
spi::HierarchyEventListenerList listeners;
typedef std::map<LogString, LoggerPtr> LoggerMap;
LoggerMap* loggers;
typedef std::map<LogString, ProvisionNode> ProvisionNodeMap;
ProvisionNodeMap* provisionNodes;
LoggerPtr root;
int thresholdInt;
LevelPtr threshold;
bool emittedNoAppenderWarning;
bool emittedNoResourceBundleWarning;
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(Hierarchy)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(spi::LoggerRepository)
END_LOG4CXX_CAST_MAP()
/**
Create a new logger hierarchy.
*/
Hierarchy();
~Hierarchy();
void addRef() const;
void releaseRef() const;
void addHierarchyEventListener(const spi::HierarchyEventListenerPtr& listener);
/**
This call will clear all logger definitions from the internal
hashtable. Invoking this method will irrevocably mess up the
logger hierarchy.
<p>You should <em>really</em> know what you are doing before
invoking this method.
*/
void clear();
void emitNoAppenderWarning(const LoggerPtr& logger);
/**
Check if the named logger exists in the hierarchy. If so return
its reference, otherwise returns <code>null</code>.
@param name The name of the logger to search for.
*/
LoggerPtr exists(const LogString& name);
/**
The string form of {@link #setThreshold(const LevelPtr&) setThreshold}.
*/
void setThreshold(const LogString& levelStr);
/**
Enable logging for logging requests with level <code>l</code> or
higher. By default all levels are enabled.
@param l The minimum level for which logging requests are sent to
their appenders. */
void setThreshold(const LevelPtr& l);
void fireAddAppenderEvent(const LoggerPtr& logger, const AppenderPtr& appender);
void fireRemoveAppenderEvent(const LoggerPtr& logger,
const AppenderPtr& appender);
/**
Returns a Level representation of the <code>enable</code>
state.
*/
const LevelPtr& getThreshold() const;
/**
Return a new logger instance named as the first parameter using
the default factory.
<p>If a logger of that name already exists, then it will be
returned. Otherwise, a new logger will be instantiated and
then linked with its existing ancestors as well as children.
@param name The name of the logger to retrieve.
*/
LoggerPtr getLogger(const LogString& name);
/**
Return a new logger instance named as the first parameter using
<code>factory</code>.
<p>If a logger of that name already exists, then it will be
returned. Otherwise, a new logger will be instantiated by the
<code>factory</code> parameter and linked with its existing
ancestors as well as children.
@param name The name of the logger to retrieve.
@param factory The factory that will make the new logger instance.
*/
LoggerPtr getLogger(const LogString& name,
const spi::LoggerFactoryPtr& factory);
/**
Returns all the currently defined loggers in this hierarchy as
a LoggerList.
<p>The root logger is <em>not</em> included in the returned
LoggerList. */
LoggerList getCurrentLoggers() const;
/**
Get the root of this hierarchy.
*/
LoggerPtr getRootLogger() const;
/**
This method will return <code>true</code> if this repository is
disabled for <code>level</code> object passed as parameter and
<code>false</code> otherwise. See also the
{@link #setThreshold(const LevelPtr&) setThreshold} method. */
bool isDisabled(int level) const;
/**
Reset all values contained in this hierarchy instance to their
default. This removes all appenders from all categories, sets
the level of all non-root categories to <code>null</code>,
sets their additivity flag to <code>true</code> and sets the level
of the root logger to DEBUG. Moreover,
message disabling is set its default "off" value.
<p>Existing categories are not removed. They are just reset.
<p>This method should be used sparingly and with care as it will
block all logging until it is completed.</p>
*/
void resetConfiguration();
/**
Used by subclasses to add a renderer to the hierarchy passed as parameter.
*/
/**
Shutting down a hierarchy will <em>safely</em> close and remove
all appenders in all categories including the root logger.
<p>Some appenders such as {@link net::SocketAppender SocketAppender}
and AsyncAppender need to be closed before the
application exists. Otherwise, pending logging events might be
lost.
<p>The <code>shutdown</code> method is careful to close nested
appenders before closing regular appenders. This is allows
configurations where a regular appender is attached to a logger
and again to a nested appender.
*/
void shutdown();
virtual bool isConfigured();
virtual void setConfigured(bool configured);
private:
/**
This method loops through all the *potential* parents of
'cat'. There 3 possible cases:
1) No entry for the potential parent of 'cat' exists
We create a ProvisionNode for this potential parent and insert
'cat' in that provision node.
2) There entry is of type Logger for the potential parent.
The entry is 'cat's nearest existing parent. We update cat's
parent field with this entry. We also break from the loop
because updating our parent's parent is our parent's
responsibility.
3) There entry is of type ProvisionNode for this potential parent.
We add 'cat' to the list of children for this potential parent.
*/
void updateParents(LoggerPtr logger);
/**
We update the links for all the children that placed themselves
in the provision node 'pn'. The second argument 'cat' is a
reference for the newly created Logger, parent of all the
children in 'pn'
We loop on all the children 'c' in 'pn':
If the child 'c' has been already linked to a child of
'cat' then there is no need to update 'c'.
Otherwise, we set cat's parent field to c's parent and set
c's parent field to cat.
*/
Hierarchy(const Hierarchy&);
Hierarchy& operator=(const Hierarchy&);
void updateChildren(ProvisionNode& pn, LoggerPtr logger);
};
} //namespace log4cxx
#if defined(_MSC_VER)
#pragma warning (pop)
#endif
#endif //_LOG4CXX_HIERARCHY_H
| 001-log4cxx | trunk/src/main/include/log4cxx/hierarchy.h | C++ | asf20 | 10,162 |
/* 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.
*/
#ifndef LOG4CXX_LOG4CXX_H
#define LOG4CXX_LOG4CXX_H
/* GENERATED FILE WARNING! DO NOT EDIT log4cxx.h
*
* Edit log4cxx.hw instead
*
*/
#define LOG4CXX_LOGCHAR_IS_UTF8 0
#if LOG4CXX_LOGCHAR_IS_UTF8
#define LOG4CXX_LOGCHAR_IS_WCHAR 0
#else
#define LOG4CXX_LOGCHAR_IS_WCHAR 1
#endif
#define LOG4CXX_LOGCHAR_IS_UNICHAR 0
#define LOG4CXX_CHAR_API 1
#define LOG4CXX_WCHAR_T_API 1
#define LOG4CXX_UNICHAR_API 0
#define LOG4CXX_CFSTRING_API 0
#if defined(_MSC_VER)
typedef __int64 log4cxx_int64_t;
#if _MSC_VER < 1300
#define LOG4CXX_USE_GLOBAL_SCOPE_TEMPLATE 1
#define LOG4CXX_LOGSTREAM_ADD_NOP 1
#endif
#elif defined(__BORLANDC__)
typedef __int64 log4cxx_int64_t;
#else
typedef long long log4cxx_int64_t;
#endif
typedef log4cxx_int64_t log4cxx_time_t;
typedef int log4cxx_status_t;
typedef unsigned int log4cxx_uint32_t;
// definitions used when using static library
#if defined(LOG4CXX_STATIC)
#define LOG4CXX_EXPORT
// definitions used when building DLL
#elif defined(LOG4CXX)
#define LOG4CXX_EXPORT __declspec(dllexport)
#else
// definitions used when using DLL
#define LOG4CXX_EXPORT __declspec(dllimport)
#endif
//
// pointer and list definition macros when building DLL using VC
//
#if defined(_MSC_VER) && !defined(LOG4CXX_STATIC) && defined(LOG4CXX)
#define LOG4CXX_PTR_DEF(T) \
template class LOG4CXX_EXPORT log4cxx::helpers::ObjectPtrT<T>; \
typedef log4cxx::helpers::ObjectPtrT<T> T##Ptr
#define LOG4CXX_LIST_DEF(N, T) \
template class LOG4CXX_EXPORT std::allocator<T>; \
template class LOG4CXX_EXPORT std::vector<T>; \
typedef std::vector<T> N
//
// pointer and list definition macros when linking with DLL using VC
//
#elif defined(_MSC_VER) && !defined(LOG4CXX_STATIC)
#define LOG4CXX_PTR_DEF(T) \
extern template class LOG4CXX_EXPORT log4cxx::helpers::ObjectPtrT<T>; \
typedef log4cxx::helpers::ObjectPtrT<T> T##Ptr
#define LOG4CXX_LIST_DEF(N, T) \
extern template class LOG4CXX_EXPORT std::allocator<T>; \
extern template class LOG4CXX_EXPORT std::vector<T>; \
typedef std::vector<T> N
//
// pointer and list definition macros for all other cases
//
#else
#define LOG4CXX_PTR_DEF(T) typedef log4cxx::helpers::ObjectPtrT<T> T##Ptr
#define LOG4CXX_LIST_DEF(N, T) typedef std::vector<T> N
#endif
#endif
| 001-log4cxx | trunk/src/main/include/log4cxx/log4cxx.h | C++ | asf20 | 3,037 |
/*
* 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.
*/
#ifndef _LOG4CXX_DEFAULT_CONFIGURATOR_H
#define _LOG4CXX_DEFAULT_CONFIGURATOR_H
#include <log4cxx/spi/configurator.h>
namespace log4cxx
{
namespace spi {
class LoggerRepository;
typedef helpers::ObjectPtrT<LoggerRepository> LoggerRepositoryPtr;
}
/**
* Configures the repository from environmental settings and files.
*
*/
class LOG4CXX_EXPORT DefaultConfigurator
{
private:
DefaultConfigurator() {}
public:
/**
Add a ConsoleAppender that uses PatternLayout
using the PatternLayout#TTCC_CONVERSION_PATTERN and
prints to <code>stdout</code> to the root logger.*/
static void configure(log4cxx::spi::LoggerRepository*);
private:
static const LogString getConfigurationFileName();
static const LogString getConfiguratorClass();
}; // class DefaultConfigurator
} // namespace log4cxx
#endif //_LOG4CXX_DEFAULT_CONFIGURATOR_H
| 001-log4cxx | trunk/src/main/include/log4cxx/defaultconfigurator.h | C++ | asf20 | 1,747 |
/*
* 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.
*/
#ifndef _LOG4CXX_SPI_ERROR_HANDLER_H
#define _LOG4CXX_SPI_ERROR_HANDLER_H
#if defined(_MSC_VER)
#pragma warning ( push )
#pragma warning ( disable: 4231 4251 4275 4786 )
#endif
#include <log4cxx/spi/optionhandler.h>
#include <log4cxx/helpers/exception.h>
#include <log4cxx/appender.h>
#include <log4cxx/spi/loggingevent.h>
namespace log4cxx
{
namespace spi
{
class ErrorCode
{
public:
enum
{
GENERIC_FAILURE = 0,
WRITE_FAILURE = 1,
FLUSH_FAILURE = 2,
CLOSE_FAILURE = 3,
FILE_OPEN_FAILURE = 4,
MISSING_LAYOUT = 5,
ADDRESS_PARSE_FAILURE = 6
};
};
/**
Appenders may delegate their error handling to
<code>ErrorHandlers</code>.
<p>Error handling is a particularly tedious to get right because by
definition errors are hard to predict and to reproduce.
<p>Please take the time to contact the author in case you discover
that errors are not properly handled. You are most welcome to
suggest new error handling policies or criticize existing policies.
*/
class LOG4CXX_EXPORT ErrorHandler : public virtual OptionHandler
{
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(ErrorHandler)
virtual ~ErrorHandler() {}
/**
Add a reference to a logger to which the failing appender might
be attached to. The failing appender will be searched and
replaced only in the loggers you add through this method.
@param logger One of the loggers that will be searched for the failing
appender in view of replacement.
*/
virtual void setLogger(const LoggerPtr& logger) = 0;
/**
Equivalent to the error(const String&, helpers::Exception&, int,
spi::LoggingEvent&) with the the event parameteter set to
null.
*/
virtual void error(const LogString& message, const std::exception& e,
int errorCode) const = 0;
/**
This method is normally used to just print the error message
passed as a parameter.
*/
virtual void error(const LogString& message) const = 0;
/**
This method is invoked to handle the error.
@param message The message assoicated with the error.
@param e The Exption that was thrown when the error occured.
@param errorCode The error code associated with the error.
@param event The logging event that the failing appender is asked
to log.
*/
virtual void error(const LogString& message, const std::exception& e,
int errorCode, const LoggingEventPtr& event) const = 0;
/**
Set the appender for which errors are handled. This method is
usually called when the error handler is configured.
*/
virtual void setAppender(const AppenderPtr& appender) = 0;
/**
Set the appender to fallback upon in case of failure.
*/
virtual void setBackupAppender(const AppenderPtr& appender) = 0;
};
LOG4CXX_PTR_DEF(ErrorHandler);
} //namespace spi
} //namespace log4cxx
#if defined(_MSC_VER)
#pragma warning ( pop )
#endif
#endif //_LOG4CXX_SPI_ERROR_HANDLER_H
| 001-log4cxx | trunk/src/main/include/log4cxx/spi/errorhandler.h | C++ | asf20 | 5,154 |
/*
* 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.
*/
#ifndef _LOG4CXX_SPI_LOGGERFACTORY_H
#define _LOG4CXX_SPI_LOGGERFACTORY_H
#include <log4cxx/logger.h>
namespace log4cxx
{
namespace spi
{
/**
Implement this interface to create new instances of Logger or
a sub-class of Logger.
*/
class LOG4CXX_EXPORT LoggerFactory : public virtual helpers::Object
{
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(LoggerFactory)
virtual ~LoggerFactory() {}
virtual LoggerPtr makeNewLoggerInstance(
log4cxx::helpers::Pool& pool,
const LogString& name) const = 0;
};
} // namespace spi
} // namesapce log4cxx
#endif //_LOG4CXX_SPI_LOGGERFACTORY_H
| 001-log4cxx | trunk/src/main/include/log4cxx/spi/loggerfactory.h | C++ | asf20 | 1,663 |
/*
* 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.
*/
#ifndef _LOG4CXX_SPI_TRIGGERING_EVENT_EVALUATOR_H
#define _LOG4CXX_SPI_TRIGGERING_EVENT_EVALUATOR_H
#include <log4cxx/spi/loggingevent.h>
namespace log4cxx
{
namespace spi
{
/**
Implementions of this interface allow certain appenders to decide
when to perform an appender specific action.
<p>For example the {@link net::SMTPAppender SMTPAppender} sends
an email when the #isTriggeringEvent method returns
<code>true</code> and adds the event to an internal buffer when the
returned result is <code>false</code>.
*/
class LOG4CXX_EXPORT TriggeringEventEvaluator : public virtual helpers::Object
{
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(TriggeringEventEvaluator)
/**
Is this the triggering event?
*/
virtual bool isTriggeringEvent(const spi::LoggingEventPtr& event) = 0;
};
LOG4CXX_PTR_DEF(TriggeringEventEvaluator);
}
}
#endif // _LOG4CXX_SPI_TRIGGERING_EVENT_EVALUATOR_H
| 001-log4cxx | trunk/src/main/include/log4cxx/spi/triggeringeventevaluator.h | C++ | asf20 | 2,029 |
/*
* 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.
*/
#ifndef _LOG4CXX_SPI_REPOSITORY_SELECTOR_H
#define _LOG4CXX_SPI_REPOSITORY_SELECTOR_H
#include <log4cxx/helpers/objectptr.h>
#include <log4cxx/helpers/object.h>
namespace log4cxx
{
namespace spi
{
class LoggerRepository;
typedef helpers::ObjectPtrT<LoggerRepository> LoggerRepositoryPtr;
/**
The <code>LogManager</code> uses one (and only one)
<code>RepositorySelector</code> implementation to select the
{@link log4cxx::spi::LoggerRepository LoggerRepository}
for a particular application context.
<p>It is the responsability of the <code>RepositorySelector</code>
implementation to track the application context. log4cxx makes no
assumptions about the application context or on its management.
<p>See also LogManager.
*/
class LOG4CXX_EXPORT RepositorySelector : public virtual helpers::Object
{
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(RepositorySelector)
virtual ~RepositorySelector() {}
virtual LoggerRepositoryPtr& getLoggerRepository() = 0;
};
LOG4CXX_PTR_DEF(RepositorySelector);
} //namespace spi
} //namespace log4cxx
#endif //_LOG4CXX_SPI_REPOSITORY_SELECTOR_H
| 001-log4cxx | trunk/src/main/include/log4cxx/spi/repositoryselector.h | C++ | asf20 | 2,160 |
/*
* 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.
*/
#ifndef _LOG4CXX_SPI_HIERARCHY_EVENT_LISTENER_H
#define _LOG4CXX_SPI_HIERARCHY_EVENT_LISTENER_H
#if defined(_MSC_VER)
#pragma warning ( push )
#pragma warning ( disable: 4231 4251 4275 4786 )
#endif
#include <log4cxx/helpers/object.h>
#include <log4cxx/helpers/objectptr.h>
#include <vector>
namespace log4cxx
{
class Logger;
class Appender;
namespace spi
{
/** Listen to events occuring within a Hierarchy.*/
class LOG4CXX_EXPORT HierarchyEventListener :
public virtual log4cxx::helpers::Object
{
public:
virtual ~HierarchyEventListener() {}
virtual void addAppenderEvent(
const log4cxx::helpers::ObjectPtrT<Logger>& logger,
const log4cxx::helpers::ObjectPtrT<Appender>& appender) = 0;
virtual void removeAppenderEvent(
const log4cxx::helpers::ObjectPtrT<Logger>& logger,
const log4cxx::helpers::ObjectPtrT<Appender>& appender) = 0;
};
LOG4CXX_PTR_DEF(HierarchyEventListener);
LOG4CXX_LIST_DEF(HierarchyEventListenerList, HierarchyEventListenerPtr);
} // namespace spi
} // namespace log4cxx
#if defined(_MSC_VER)
#pragma warning ( pop )
#endif
#endif //_LOG4CXX_SPI_HIERARCHY_EVENT_LISTENER_H
| 001-log4cxx | trunk/src/main/include/log4cxx/spi/hierarchyeventlistener.h | C++ | asf20 | 2,243 |
/*
* 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.
*/
#ifndef _LOG4CXX_SPI_ROOT_LOGGER_H
#define _LOG4CXX_SPI_ROOT_LOGGER_H
#include <log4cxx/logger.h>
namespace log4cxx
{
namespace spi
{
/**
RootLogger sits at the top of the logger hierachy. It is a
regular logger except that it provides several guarantees.
<p>First, it cannot be assigned a null
level. Second, since root logger cannot have a parent, the
#getEffectiveLevel method always returns the value of the
level field without walking the hierarchy.
*/
class LOG4CXX_EXPORT RootLogger : public Logger
{
public:
/**
The root logger names itself as "root". However, the root
logger cannot be retrieved by name.
*/
RootLogger(log4cxx::helpers::Pool& pool, const LevelPtr& level);
/**
Return the assigned level value without walking the logger
hierarchy.
*/
virtual const LevelPtr& getEffectiveLevel() const;
/**
Setting a null value to the level of the root logger may have catastrophic
results. We prevent this here.
*/
void setLevel(const LevelPtr& level);
};
} // namespace spi
} // namespace log4cxx
#endif //_LOG4CXX_SPI_ROOT_LOGGER_H
| 001-log4cxx | trunk/src/main/include/log4cxx/spi/rootlogger.h | C++ | asf20 | 2,213 |
/*
* 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.
*/
#ifndef _LOG4CXX_SPI_APPENDER_ATTACHABLE_H_
#define _LOG4CXX_SPI_APPENDER_ATTACHABLE_H_
#if defined(_MSC_VER)
#pragma warning ( push )
#pragma warning ( disable: 4231 4251 4275 4786 )
#endif
#include <log4cxx/logstring.h>
#include <vector>
#include <log4cxx/helpers/objectptr.h>
#include <log4cxx/helpers/object.h>
#include <log4cxx/appender.h>
namespace log4cxx
{
namespace spi
{
/**
* This Interface is for attaching Appenders to objects.
*/
class LOG4CXX_EXPORT AppenderAttachable : public virtual helpers::Object
{
public:
// Methods
DECLARE_ABSTRACT_LOG4CXX_OBJECT(AppenderAttachable)
/**
* Add an appender.
*/
virtual void addAppender(const AppenderPtr& newAppender) = 0;
/**
* Get all previously added appenders as an AppenderList.
*/
virtual AppenderList getAllAppenders() const = 0;
/**
* Get an appender by name.
*/
virtual AppenderPtr getAppender(const LogString& name) const = 0;
/**
Returns <code>true</code> if the specified appender is in list of
attached attached, <code>false</code> otherwise.
*/
virtual bool isAttached(const AppenderPtr& appender) const = 0;
/**
* Remove all previously added appenders.
*/
virtual void removeAllAppenders() = 0;
/**
* Remove the appender passed as parameter from the list of appenders.
*/
virtual void removeAppender(const AppenderPtr& appender) = 0;
/**
* Remove the appender with the name passed as parameter from the
* list of appenders.
*/
virtual void removeAppender(const LogString& name) = 0;
// Dtor
virtual ~AppenderAttachable(){}
};
LOG4CXX_PTR_DEF(AppenderAttachable);
}
}
#if defined(_MSC_VER)
#pragma warning ( pop )
#endif
#endif //_LOG4CXX_SPI_APPENDER_ATTACHABLE_H_
| 001-log4cxx | trunk/src/main/include/log4cxx/spi/appenderattachable.h | C++ | asf20 | 2,945 |
/*
* 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.
*/
#ifndef _LOG4CXX_SPI_FILTER_H
#define _LOG4CXX_SPI_FILTER_H
#include <log4cxx/helpers/objectptr.h>
#include <log4cxx/helpers/objectimpl.h>
#include <log4cxx/spi/optionhandler.h>
#include <log4cxx/spi/loggingevent.h>
namespace log4cxx
{
namespace spi
{
class Filter;
LOG4CXX_PTR_DEF(Filter);
/**
Users should extend this class to implement customized logging
event filtering. Note that Logger and
AppenderSkeleton, the parent class of all standard
appenders, have built-in filtering rules. It is suggested that you
first use and understand the built-in rules before rushing to write
your own custom filters.
<p>This abstract class assumes and also imposes that filters be
organized in a linear chain. The {@link #decide
decide(LoggingEvent)} method of each filter is called sequentially,
in the order of their addition to the chain.
<p>The {@link #decide decide(LoggingEvent)} method must return one
of the integer constants #DENY, #NEUTRAL or
#ACCEPT.
<p>If the value #DENY is returned, then the log event is
dropped immediately without consulting with the remaining
filters.
<p>If the value #NEUTRAL is returned, then the next filter
in the chain is consulted. If there are no more filters in the
chain, then the log event is logged. Thus, in the presence of no
filters, the default behaviour is to log all logging events.
<p>If the value #ACCEPT is returned, then the log
event is logged without consulting the remaining filters.
<p>The philosophy of log4cxx filters is largely inspired from the
Linux ipchains.
<p>Note that filtering is only supported by the {@link
xml::DOMConfigurator DOMConfigurator}.
*/
class LOG4CXX_EXPORT Filter : public virtual OptionHandler,
public virtual helpers::ObjectImpl
{
/**
Points to the next filter in the filter chain.
*/
FilterPtr next;
public:
Filter();
void addRef() const;
void releaseRef() const;
DECLARE_ABSTRACT_LOG4CXX_OBJECT(Filter)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(Filter)
LOG4CXX_CAST_ENTRY(spi::OptionHandler)
END_LOG4CXX_CAST_MAP()
log4cxx::spi::FilterPtr getNext() const;
void setNext(const log4cxx::spi::FilterPtr& newNext);
enum FilterDecision
{
/**
The log event must be dropped immediately without consulting
with the remaining filters, if any, in the chain. */
DENY = -1,
/**
This filter is neutral with respect to the log event. The
remaining filters, if any, should be consulted for a final decision.
*/
NEUTRAL = 0,
/**
The log event must be logged immediately without consulting with
the remaining filters, if any, in the chain.
*/
ACCEPT = 1
};
/**
Usually filters options become active when set. We provide a
default do-nothing implementation for convenience.
*/
void activateOptions(log4cxx::helpers::Pool& p);
void setOption(const LogString& option, const LogString& value);
/**
<p>If the decision is <code>DENY</code>, then the event will be
dropped. If the decision is <code>NEUTRAL</code>, then the next
filter, if any, will be invoked. If the decision is ACCEPT then
the event will be logged without consulting with other filters in
the chain.
@param event The LoggingEvent to decide upon.
@return The decision of the filter. */
virtual FilterDecision decide(const LoggingEventPtr& event) const = 0;
};
}
}
#endif //_LOG4CXX_SPI_FILTER_H
| 001-log4cxx | trunk/src/main/include/log4cxx/spi/filter.h | C++ | asf20 | 5,201 |
/*
* 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.
*/
#ifndef _LOG4CXX_SPI_DEFAULT_REPOSITORY_SELECTOR_H
#define _LOG4CXX_SPI_DEFAULT_REPOSITORY_SELECTOR_H
#include <log4cxx/spi/repositoryselector.h>
#include <log4cxx/helpers/objectimpl.h>
#include <log4cxx/spi/loggerrepository.h>
namespace log4cxx
{
namespace spi
{
class LOG4CXX_EXPORT DefaultRepositorySelector :
public virtual RepositorySelector,
public virtual helpers::ObjectImpl
{
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(DefaultRepositorySelector)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(RepositorySelector)
END_LOG4CXX_CAST_MAP()
DefaultRepositorySelector(const LoggerRepositoryPtr& repository1);
void addRef() const;
void releaseRef() const;
virtual LoggerRepositoryPtr& getLoggerRepository();
private:
LoggerRepositoryPtr repository;
};
} // namespace spi
} // namespace log4cxx
#endif //_LOG4CXX_SPI_DEFAULT_REPOSITORY_SELECTOR_H
| 001-log4cxx | trunk/src/main/include/log4cxx/spi/defaultrepositoryselector.h | C++ | asf20 | 2,028 |
/*
* 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.
*/
#ifndef _LOG4CXX_SPI_LOGGING_EVENT_H
#define _LOG4CXX_SPI_LOGGING_EVENT_H
#if defined(_MSC_VER)
#pragma warning (push)
#pragma warning ( disable: 4231 4251 4275 4786 )
#endif
#include <log4cxx/helpers/objectptr.h>
#include <log4cxx/logstring.h>
#include <time.h>
#include <log4cxx/logger.h>
#include <log4cxx/mdc.h>
#include <log4cxx/spi/location/locationinfo.h>
#include <vector>
namespace log4cxx
{
namespace helpers
{
class ObjectOutputStream;
}
namespace spi
{
/**
The internal representation of logging events. When an affirmative
decision is made to log then a <code>LoggingEvent</code> instance
is created. This instance is passed around to the different log4cxx
components.
<p>This class is of concern to those wishing to extend log4cxx.
*/
class LOG4CXX_EXPORT LoggingEvent :
public virtual helpers::ObjectImpl
{
public:
DECLARE_LOG4CXX_OBJECT(LoggingEvent)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(LoggingEvent)
END_LOG4CXX_CAST_MAP()
/** For serialization only
*/
LoggingEvent();
/**
Instantiate a LoggingEvent from the supplied parameters.
<p>Except timeStamp all the other fields of
<code>LoggingEvent</code> are filled when actually needed.
<p>
@param logger The logger of this event.
@param level The level of this event.
@param message The message of this event.
@param location location of logging request.
*/
LoggingEvent(const LogString& logger,
const LevelPtr& level, const LogString& message,
const log4cxx::spi::LocationInfo& location);
~LoggingEvent();
/** Return the level of this event. */
inline const LevelPtr& getLevel() const
{ return level; }
/** Return the name of the logger. */
inline const LogString& getLoggerName() const {
return logger;
}
/** Return the message for this logging event. */
inline const LogString& getMessage() const
{ return message; }
/** Return the message for this logging event. */
inline const LogString& getRenderedMessage() const
{ return message; }
/**Returns the time when the application started,
in seconds elapsed since 01.01.1970.
*/
static log4cxx_time_t getStartTime();
/** Return the threadName of this event. */
inline const LogString& getThreadName() const {
return threadName;
}
/** Return the timeStamp of this event. */
inline log4cxx_time_t getTimeStamp() const
{ return timeStamp; }
/* Return the file where this log statement was written. */
inline const log4cxx::spi::LocationInfo& getLocationInformation() const
{ return locationInfo; }
/**
* This method appends the NDC for this event to passed string. It will return the
* correct content even if the event was generated in a different
* thread or even on a different machine. The NDC#get method
* should <em>never</em> be called directly.
*
* @param dest destination for NDC, unchanged if NDC is not set.
* @return true if NDC is set.
*/
bool getNDC(LogString& dest) const;
/**
* Writes the content of the LoggingEvent
* in a format compatible with log4j's serialized form.
*/
void write(helpers::ObjectOutputStream& os, helpers::Pool& p) const;
/**
* Appends the the context corresponding to the <code>key</code> parameter.
* If there is a local MDC copy, possibly because we are in a logging
* server or running inside AsyncAppender, then we search for the key in
* MDC copy, if a value is found it is returned. Otherwise, if the search
* in MDC copy returns an empty result, then the current thread's
* <code>MDC</code> is used.
*
* <p>
* Note that <em>both</em> the local MDC copy and the current thread's MDC
* are searched.
* </p>
* @param key key.
* @param dest string to which value, if any, is appended.
* @return true if key had a corresponding value.
*/
bool getMDC(const LogString& key, LogString& dest) const;
LOG4CXX_LIST_DEF(KeySet, LogString);
/**
* Returns the set of of the key values in the MDC for the event.
* The returned set is unmodifiable by the caller.
*
* @return Set an unmodifiable set of the MDC keys.
*
*/
KeySet getMDCKeySet() const;
/**
Obtain a copy of this thread's MDC prior to serialization
or asynchronous logging.
*/
void getMDCCopy() const;
/**
* Return a previously set property.
* @param key key.
* @param dest string to which value, if any, is appended.
* @return true if key had a corresponding value.
*/
bool getProperty(const LogString& key, LogString& dest) const;
/**
* Returns the set of of the key values in the properties
* for the event. The returned set is unmodifiable by the caller.
*
* @return Set an unmodifiable set of the property keys.
*/
KeySet getPropertyKeySet() const;
/**
* Set a string property using a key and a string value. since 1.3
*/
void setProperty(const LogString& key, const LogString& value);
private:
/**
* The logger of the logging event.
**/
LogString logger;
/** level of logging event. */
LevelPtr level;
/** The nested diagnostic context (NDC) of logging event. */
mutable LogString* ndc;
/** The mapped diagnostic context (MDC) of logging event. */
mutable MDC::Map* mdcCopy;
/**
* A map of String keys and String values.
*/
std::map<LogString, LogString> * properties;
/** Have we tried to do an NDC lookup? If we did, there is no need
* to do it again. Note that its value is always false when
* serialized. Thus, a receiving SocketNode will never use it's own
* (incorrect) NDC. See also writeObject method.
*/
mutable bool ndcLookupRequired;
/**
* Have we tried to do an MDC lookup? If we did, there is no need to do it
* again. Note that its value is always false when serialized. See also
* the getMDC and getMDCCopy methods.
*/
mutable bool mdcCopyLookupRequired;
/** The application supplied message of logging event. */
LogString message;
/** The number of milliseconds elapsed from 1/1/1970 until logging event
was created. */
log4cxx_time_t timeStamp;
/** The is the location where this log statement was written. */
const log4cxx::spi::LocationInfo locationInfo;
/** The identifier of thread in which this logging event
was generated.
*/
const LogString threadName;
//
// prevent copy and assignment
//
LoggingEvent(const LoggingEvent&);
LoggingEvent& operator=(const LoggingEvent&);
static const LogString getCurrentThreadName();
static void writeProlog(log4cxx::helpers::ObjectOutputStream& os, log4cxx::helpers::Pool& p);
};
LOG4CXX_PTR_DEF(LoggingEvent);
LOG4CXX_LIST_DEF(LoggingEventList, LoggingEventPtr);
}
}
#if defined(_MSC_VER)
#pragma warning (pop)
#endif
#endif //_LOG4CXX_SPI_LOGGING_EVENT_H
| 001-log4cxx | trunk/src/main/include/log4cxx/spi/loggingevent.h | C++ | asf20 | 11,381 |
/*
* 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.
*/
#ifndef _LOG4CXX_SPI_CONFIGURATOR_H
#define _LOG4CXX_SPI_CONFIGURATOR_H
#include <log4cxx/spi/loggerrepository.h>
namespace log4cxx
{
class File;
namespace spi
{
/**
Implemented by classes capable of configuring log4j using a URL.
*/
class LOG4CXX_EXPORT Configurator : virtual public helpers::Object
{
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(Configurator)
Configurator();
/**
Interpret a resource pointed by a URL and set up log4j accordingly.
The configuration is done relative to the <code>hierarchy</code>
parameter.
@param configFileName The file to parse
@param repository The hierarchy to operation upon.
*/
virtual void doConfigure(const File& configFileName,
spi::LoggerRepositoryPtr& repository) = 0;
private:
Configurator(const Configurator&);
Configurator& operator=(const Configurator&);
bool initialized;
};
LOG4CXX_PTR_DEF(Configurator);
}
}
#endif // _LOG4CXX_SPI_CONFIGURATOR_H
| 001-log4cxx | trunk/src/main/include/log4cxx/spi/configurator.h | C++ | asf20 | 1,905 |
/*
* 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.
*/
#ifndef _LOG4CXX_SPI_OPTION_HANDLER_H
#define _LOG4CXX_SPI_OPTION_HANDLER_H
#include <log4cxx/logstring.h>
#include <log4cxx/helpers/object.h>
#include <log4cxx/helpers/objectptr.h>
namespace log4cxx
{
namespace spi
{
class OptionHandler;
typedef helpers::ObjectPtrT<OptionHandler> OptionHandlerPtr;
/**
A string based interface to configure package components.
*/
class LOG4CXX_EXPORT OptionHandler : public virtual helpers::Object
{
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(OptionHandler)
virtual ~OptionHandler() {}
/**
Activate the options that were previously set with calls to option
setters.
<p>This allows to defer activiation of the options until all
options have been set. This is required for components which have
related options that remain ambigous until all are set.
<p>For example, the FileAppender has the {@link
FileAppender#setFile File} and {@link
FileAppender#setAppend Append} options both of
which are ambigous until the other is also set. */
virtual void activateOptions(log4cxx::helpers::Pool& p) = 0;
/**
Set <code>option</code> to <code>value</code>.
<p>The handling of each option depends on the OptionHandler
instance. Some options may become active immediately whereas
other may be activated only when #activateOptions is
called.
*/
virtual void setOption(const LogString& option,
const LogString& value) = 0;
}; // class OptionConverter
} // namespace spi
} // namespace log4cxx
#endif //_LOG4CXX_SPI_OPTION_HANDLER_H
| 001-log4cxx | trunk/src/main/include/log4cxx/spi/optionhandler.h | C++ | asf20 | 2,966 |
# 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.
#
spiincdir = $(includedir)/log4cxx/spi/location
spiinc_HEADERS= $(top_srcdir)/src/main/include/log4cxx/spi/location/*.h
| 001-log4cxx | trunk/src/main/include/log4cxx/spi/location/Makefile.am | Makefile | asf20 | 904 |
/*
* 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.
*/
#ifndef _LOG4CXX_SPI_LOCATION_LOCATIONINFO_H
#define _LOG4CXX_SPI_LOCATION_LOCATIONINFO_H
#include <log4cxx/log4cxx.h>
#include <string>
#include <log4cxx/helpers/objectoutputstream.h>
namespace log4cxx
{
namespace spi
{
/**
* This class represents the location of a logging statement.
*
*/
class LOG4CXX_EXPORT LocationInfo
{
public:
/**
* When location information is not available the constant
* <code>NA</code> is returned. Current value of this string constant is <b>?</b>.
*/
static const char * const NA;
static const char * const NA_METHOD;
static const LocationInfo& getLocationUnavailable();
/**
* Constructor.
* @remarks Used by LOG4CXX_LOCATION to generate
* location info for current code site
*/
LocationInfo( const char * const fileName,
const char * const functionName,
int lineNumber);
/**
* Default constructor.
*/
LocationInfo();
/**
* Copy constructor.
* @param src source location
*/
LocationInfo( const LocationInfo & src );
/**
* Assignment operator.
* @param src source location
*/
LocationInfo & operator = ( const LocationInfo & src );
/**
* Resets location info to default state.
*/
void clear();
/** Return the class name of the call site. */
const std::string getClassName() const;
/**
* Return the file name of the caller.
* @returns file name, may be null.
*/
const char * getFileName() const;
/**
* Returns the line number of the caller.
* @returns line number, -1 if not available.
*/
int getLineNumber() const;
/** Returns the method name of the caller. */
const std::string getMethodName() const;
void write(log4cxx::helpers::ObjectOutputStream& os, log4cxx::helpers::Pool& p) const;
private:
/** Caller's line number. */
int lineNumber;
/** Caller's file name. */
const char * fileName;
/** Caller's method name. */
const char * methodName;
};
}
}
#if !defined(LOG4CXX_LOCATION)
#if defined(_MSC_VER)
#if _MSC_VER >= 1300
#define __LOG4CXX_FUNC__ __FUNCSIG__
#endif
#else
#if defined(__GNUC__)
#define __LOG4CXX_FUNC__ __PRETTY_FUNCTION__
#endif
#endif
#if !defined(__LOG4CXX_FUNC__)
#define __LOG4CXX_FUNC__ ""
#endif
#define LOG4CXX_LOCATION ::log4cxx::spi::LocationInfo(__FILE__, \
__LOG4CXX_FUNC__, \
__LINE__)
#endif
#endif //_LOG4CXX_SPI_LOCATION_LOCATIONINFO_H
| 001-log4cxx | trunk/src/main/include/log4cxx/spi/location/locationinfo.h | C++ | asf20 | 3,700 |
# 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.
#
SUBDIRS = location
spiincdir = $(includedir)/log4cxx/spi
spiinc_HEADERS= $(top_srcdir)/src/main/include/log4cxx/spi/*.h
| 001-log4cxx | trunk/src/main/include/log4cxx/spi/Makefile.am | Makefile | asf20 | 905 |
/*
* 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.
*/
#ifndef _LOG4CXX_SPI_LOG_REPOSITORY_H
#define _LOG4CXX_SPI_LOG_REPOSITORY_H
#if defined(_MSC_VER)
#pragma warning ( push )
#pragma warning ( disable: 4231 4251 4275 4786 )
#endif
#include <log4cxx/appender.h>
#include <log4cxx/spi/loggerfactory.h>
#include <log4cxx/level.h>
#include <log4cxx/spi/hierarchyeventlistener.h>
namespace log4cxx
{
namespace spi
{
/**
A <code>LoggerRepository</code> is used to create and retrieve
<code>Loggers</code>. The relation between loggers in a repository
depends on the repository but typically loggers are arranged in a
named hierarchy.
<p>In addition to the creational methods, a
<code>LoggerRepository</code> can be queried for existing loggers,
can act as a point of registry for events related to loggers.
*/
class LOG4CXX_EXPORT LoggerRepository : public virtual helpers::Object
{
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(LoggerRepository)
virtual ~LoggerRepository() {}
/**
Add a {@link spi::HierarchyEventListener HierarchyEventListener}
event to the repository.
*/
virtual void addHierarchyEventListener(const HierarchyEventListenerPtr&
listener) = 0;
/**
Is the repository disabled for a given level? The answer depends
on the repository threshold and the <code>level</code>
parameter. See also #setThreshold method. */
virtual bool isDisabled(int level) const = 0;
/**
Set the repository-wide threshold. All logging requests below the
threshold are immediately dropped. By default, the threshold is
set to <code>Level::getAll()</code> which has the lowest possible rank. */
virtual void setThreshold(const LevelPtr& level) = 0;
/**
Another form of {@link #setThreshold(const LevelPtr&)
setThreshold} accepting a string
parameter instead of a <code>Level</code>. */
virtual void setThreshold(const LogString& val) = 0;
virtual void emitNoAppenderWarning(const LoggerPtr& logger) = 0;
/**
Get the repository-wide threshold. See {@link
#setThreshold(const LevelPtr&) setThreshold}
for an explanation. */
virtual const LevelPtr& getThreshold() const = 0;
virtual LoggerPtr getLogger(const LogString& name) = 0;
virtual LoggerPtr getLogger(const LogString& name,
const spi::LoggerFactoryPtr& factory) = 0;
virtual LoggerPtr getRootLogger() const = 0;
virtual LoggerPtr exists(const LogString& name) = 0;
virtual void shutdown() = 0;
virtual LoggerList getCurrentLoggers() const = 0;
virtual void fireAddAppenderEvent(const LoggerPtr& logger,
const AppenderPtr& appender) = 0;
virtual void resetConfiguration() = 0;
virtual bool isConfigured() = 0;
virtual void setConfigured(bool configured) = 0;
}; // class LoggerRepository
} // namespace spi
} // namespace log4cxx
#if defined(_MSC_VER)
#pragma warning ( pop )
#endif
#endif //_LOG4CXX_SPI_LOG_REPOSITORY_H
| 001-log4cxx | trunk/src/main/include/log4cxx/spi/loggerrepository.h | C++ | asf20 | 4,456 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_ONLY_ONCE_ERROR_HANDLER_H
#define _LOG4CXX_HELPERS_ONLY_ONCE_ERROR_HANDLER_H
#include <log4cxx/spi/errorhandler.h>
#include <log4cxx/helpers/objectimpl.h>
namespace log4cxx
{
namespace helpers
{
/**
The <code>OnlyOnceErrorHandler</code> implements log4cxx's default
error handling policy which consists of emitting a message for the
first error in an appender and ignoring all following errors.
<p>The error message is printed on <code>System.err</code>.
<p>This policy aims at protecting an otherwise working application
from being flooded with error messages when logging fails
*/
class LOG4CXX_EXPORT OnlyOnceErrorHandler :
public virtual spi::ErrorHandler,
public virtual ObjectImpl
{
private:
LogString WARN_PREFIX;
LogString ERROR_PREFIX;
mutable bool firstTime;
public:
DECLARE_LOG4CXX_OBJECT(OnlyOnceErrorHandler)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(spi::OptionHandler)
LOG4CXX_CAST_ENTRY(spi::ErrorHandler)
END_LOG4CXX_CAST_MAP()
OnlyOnceErrorHandler();
void addRef() const;
void releaseRef() const;
/**
Does not do anything.
*/
void setLogger(const LoggerPtr& logger);
/**
No options to activate.
*/
void activateOptions(log4cxx::helpers::Pool& p);
void setOption(const LogString& option, const LogString& value);
/**
Prints the message and the stack trace of the exception on
<code>System.err</code>. */
void error(const LogString& message, const std::exception& e,
int errorCode) const;
/**
Prints the message and the stack trace of the exception on
<code>System.err</code>.
*/
void error(const LogString& message, const std::exception& e,
int errorCode, const spi::LoggingEventPtr& event) const;
/**
Print a the error message passed as parameter on
<code>System.err</code>.
*/
void error(const LogString& message) const;
/**
Does not do anything.
*/
void setAppender(const AppenderPtr& appender);
/**
Does not do anything.
*/
void setBackupAppender(const AppenderPtr& appender);
};
} // namespace helpers
} // namespace log4cxx
#endif //_LOG4CXX_HELPERS_ONLY_ONCE_ERROR_HANDLER_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/onlyonceerrorhandler.h | C++ | asf20 | 3,895 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_SYSTEMOUTWRITER_H
#define _LOG4CXX_HELPERS_SYSTEMOUTWRITER_H
#include <log4cxx/helpers/writer.h>
namespace log4cxx
{
namespace helpers {
/**
* Abstract class for writing to character streams.
*/
class LOG4CXX_EXPORT SystemOutWriter : public Writer
{
public:
DECLARE_LOG4CXX_OBJECT(SystemOutWriter)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(SystemOutWriter)
LOG4CXX_CAST_ENTRY_CHAIN(Writer)
END_LOG4CXX_CAST_MAP()
SystemOutWriter();
~SystemOutWriter();
virtual void close(Pool& p);
virtual void flush(Pool& p);
virtual void write(const LogString& str, Pool& p);
static void write(const LogString& str);
static void flush();
private:
SystemOutWriter(const SystemOutWriter&);
SystemOutWriter& operator=(const SystemOutWriter&);
static bool isWide();
};
} // namespace helpers
} //namespace log4cxx
#endif //_LOG4CXX_HELPERS_SYSTEMOUTWRITER_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/systemoutwriter.h | C++ | asf20 | 2,094 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_DATE_TIME_DATE_FORMAT_H
#define _LOG4CXX_HELPERS_DATE_TIME_DATE_FORMAT_H
#include <log4cxx/helpers/simpledateformat.h>
namespace log4cxx
{
namespace helpers
{
/**
Formats a date in the format <b>dd MMM yyyy HH:mm:ss,SSS</b> for example,
"06 Nov 1994 15:49:37,459".
*/
class LOG4CXX_EXPORT DateTimeDateFormat : public SimpleDateFormat
{
public:
DateTimeDateFormat()
: SimpleDateFormat(LOG4CXX_STR("dd MMM yyyy HH:mm:ss,SSS")) {}
DateTimeDateFormat(const std::locale* locale)
: SimpleDateFormat(LOG4CXX_STR("dd MMM yyyy HH:mm:ss,SSS"), locale) {}
};
} // namespace helpers
} // namespace log4cxx
#endif // _LOG4CXX_HELPERS_DATE_TIME_DATE_FORMAT_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/datetimedateformat.h | C++ | asf20 | 1,725 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_INPUTSTREAMREADER_H
#define _LOG4CXX_HELPERS_INPUTSTREAMREADER_H
#include <log4cxx/helpers/reader.h>
#include <log4cxx/helpers/inputstream.h>
#include <log4cxx/helpers/charsetdecoder.h>
namespace log4cxx
{
namespace helpers {
/**
* Class for reading from character streams.
* Decorates a byte based InputStream and provides appropriate
* conversion to characters.
*/
class LOG4CXX_EXPORT InputStreamReader : public Reader
{
private:
InputStreamPtr in;
CharsetDecoderPtr dec;
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(InputStreamReader)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(InputStreamReader)
LOG4CXX_CAST_ENTRY_CHAIN(Reader)
END_LOG4CXX_CAST_MAP()
/**
* Creates an InputStreamReader that uses the default charset.
*
* @param in The input stream to decorate.
*/
InputStreamReader(const InputStreamPtr& in);
/**
* Creates an InputStreamReader that uses the given charset decoder.
*
* @param in The input stream to decorate.
* @param enc The charset decoder to use for the conversion.
*/
InputStreamReader(const InputStreamPtr& in, const CharsetDecoderPtr &enc);
~InputStreamReader();
/**
* Closes the stream.
*
* @param p The memory pool associated with the reader.
*/
virtual void close(Pool& p);
/**
* @return The complete stream contents as a LogString.
* @param p The memory pool associated with the reader.
*/
virtual LogString read(Pool& p);
/**
* @return The name of the character encoding being used by this stream.
*/
LogString getEncoding() const;
private:
InputStreamReader(const InputStreamReader&);
InputStreamReader& operator=(const InputStreamReader&);
};
LOG4CXX_PTR_DEF(InputStreamReader);
} // namespace helpers
} //namespace log4cxx
#endif //_LOG4CXX_HELPERS_INPUTSTREAMREADER_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/inputstreamreader.h | C++ | asf20 | 3,406 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_DATE_FORMAT_H
#define _LOG4CXX_HELPERS_DATE_FORMAT_H
#include <log4cxx/helpers/timezone.h>
namespace log4cxx
{
namespace helpers
{
/**
* DateFormat is an abstract class for date/time formatting
* patterned after java.text.DateFormat.
*/
class LOG4CXX_EXPORT DateFormat : public ObjectImpl {
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(DateFormat)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(DateFormat)
END_LOG4CXX_CAST_MAP()
/**
* Destructor
*/
virtual ~DateFormat();
/**
* Formats an log4cxx_time_t into a date/time string.
* @param s string to which the date/time string is appended.
* @param tm date to be formatted.
* @param p memory pool used during formatting.
*/
virtual void format(LogString &s, log4cxx_time_t tm, log4cxx::helpers::Pool& p) const = 0;
/**
* Sets the time zone.
* @param zone the given new time zone.
*/
virtual void setTimeZone(const TimeZonePtr& zone);
/**
* Format an integer consistent with the format method.
* @param s string to which the numeric string is appended.
* @param n integer value.
* @param p memory pool used during formatting.
* @remarks This method is used by CachedDateFormat to
* format the milliseconds.
*/
virtual void numberFormat(LogString& s, int n, log4cxx::helpers::Pool& p) const;
protected:
/**
* Constructor.
*/
DateFormat();
private:
/**
* Copy constructor definition to prevent copying.
*/
DateFormat(const DateFormat&);
/**
* Assignment definition to prevent assignment.
*/
DateFormat& operator=(const DateFormat&);
};
LOG4CXX_PTR_DEF(DateFormat);
} // namespace helpers
} // namespace log4cxx
#endif //_LOG4CXX_HELPERS_DATE_FORMAT_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/dateformat.h | C++ | asf20 | 3,416 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_DATAGRAM_PACKET
#define _LOG4CXX_HELPERS_DATAGRAM_PACKET
#include <log4cxx/helpers/objectimpl.h>
#include <log4cxx/helpers/objectptr.h>
#include <log4cxx/helpers/inetaddress.h>
namespace log4cxx
{
namespace helpers
{
/** This class represents a datagram packet.
<p>Datagram packets are used to implement a connectionless packet
delivery service. Each message is routed from one machine to another
based solely on information contained within that packet. Multiple
packets sent from one machine to another might be routed differently,
and might arrive in any order.
*/
class LOG4CXX_EXPORT DatagramPacket : public helpers::ObjectImpl
{
protected:
/** the data for this packet. */
void * buf;
/** The offset of the data for this packet. */
int offset;
/** The length of the data for this packet. */
int length;
/** The IP address for this packet. */
InetAddressPtr address;
/** The UDP port number of the remote host. */
int port;
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(DatagramPacket)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(DatagramPacket)
END_LOG4CXX_CAST_MAP()
/** Constructs a DatagramPacket for receiving packets of length
<code>length</code>. */
DatagramPacket(void * buf, int length);
/** Constructs a datagram packet for sending packets of length
<code>length</code> to the specified port number on the specified
host. */
DatagramPacket(void * buf, int length, InetAddressPtr address, int port);
/** Constructs a DatagramPacket for receiving packets of length
<code>length</code>, specifying an offset into the buffer. */
DatagramPacket(void * buf, int offset, int length);
/** Constructs a datagram packet for sending packets of length
<code>length</code> with offset <code>offset</code> to the
specified port number on the specified host. */
DatagramPacket(void * buf, int offset, int length, InetAddressPtr address,
int port);
~DatagramPacket();
/** Returns the IP address of the machine to which this datagram
is being sent or from which the datagram was received. */
inline InetAddressPtr getAddress() const
{ return address; }
/** Returns the data received or the data to be sent. */
inline void * getData() const
{ return buf; }
/** Returns the length of the data to be sent or the length of the
data received. */
inline int getLength() const
{ return length; }
/** Returns the offset of the data to be sent or the offset of the
data received. */
inline int getOffset() const
{ return offset; }
/** Returns the port number on the remote host to which this
datagram is being sent or from which the datagram was received. */
inline int getPort() const
{ return port; }
inline void setAddress(InetAddressPtr address1)
{ this->address = address1; }
/** Set the data buffer for this packet. */
inline void setData(void * buf1)
{ this->buf = buf1; }
/** Set the data buffer for this packet. */
inline void setData(void * buf1, int offset1, int length1)
{ this->buf = buf1; this->offset = offset1; this->length = length1; }
/** Set the length for this packet. */
inline void setLength(int length1)
{ this->length = length1; }
inline void setPort(int port1)
{ this->port = port1; }
private:
//
// prevent copy and assignment statements
DatagramPacket(const DatagramPacket&);
DatagramPacket& operator=(const DatagramPacket&);
}; // class DatagramPacket
LOG4CXX_PTR_DEF(DatagramPacket);
} // namespace helpers
} // namespace log4cxx
#endif // _LOG4CXX_HELPERS_DATAGRAM_PACKET
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/datagrampacket.h | C++ | asf20 | 6,167 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_CONDITION_H
#define _LOG4CXX_HELPERS_CONDITION_H
#include <log4cxx/log4cxx.h>
#include <log4cxx/helpers/mutex.h>
extern "C" {
struct apr_thread_cond_t;
}
namespace log4cxx
{
namespace helpers
{
class Pool;
/**
* This class provides a means for one thread to suspend exception until
* notified by another thread to resume. This class should have
* similar semantics to java.util.concurrent.locks.Condition.
*/
class LOG4CXX_EXPORT Condition
{
public:
/**
* Create new instance.
* @param p pool on which condition will be created. Needs to be
* longer-lived than created instance.
*/
Condition(log4cxx::helpers::Pool& p);
/**
* Destructor.
*/
~Condition();
/**
* Signal all waiting threads.
*/
log4cxx_status_t signalAll();
/**
* Await signaling of condition.
* @param lock lock associated with condition, calling thread must
* own lock. Lock will be released while waiting and reacquired
* before returning from wait.
* @throws InterruptedException if thread is interrupted.
*/
void await(Mutex& lock);
private:
apr_thread_cond_t* condition;
Condition(const Condition&);
Condition& operator=(const Condition&);
};
} // namespace helpers
} // namespace log4cxx
#endif //_LOG4CXX_HELPERS_CONDITION_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/condition.h | C++ | asf20 | 2,874 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_SOCKET_OUTPUT_STREAM_H
#define _LOG4CXX_HELPERS_SOCKET_OUTPUT_STREAM_H
#if defined(_MSC_VER)
#pragma warning ( push )
#pragma warning ( disable: 4231 4251 4275 4786 )
#endif
#include <log4cxx/logstring.h>
#include <log4cxx/helpers/outputstream.h>
#include <log4cxx/helpers/socket.h>
namespace log4cxx
{
namespace helpers
{
class LOG4CXX_EXPORT SocketOutputStream : public OutputStream
{
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(SocketOutputStream)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(SocketOutputStream)
LOG4CXX_CAST_ENTRY_CHAIN(OutputStream)
END_LOG4CXX_CAST_MAP()
SocketOutputStream(const SocketPtr& socket);
~SocketOutputStream();
virtual void close(Pool& p);
virtual void flush(Pool& p);
virtual void write(ByteBuffer& buf, Pool& p);
private:
LOG4CXX_LIST_DEF(ByteList, unsigned char);
ByteList array;
SocketPtr socket;
//
// prevent copy and assignment statements
SocketOutputStream(const SocketOutputStream&);
SocketOutputStream& operator=(const SocketOutputStream&);
};
LOG4CXX_PTR_DEF(SocketOutputStream);
} // namespace helpers
} // namespace log4cxx
#if defined(_MSC_VER)
#pragma warning ( pop )
#endif
#endif // _LOG4CXX_HELPERS_SOCKET_OUTPUT_STREAM_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/socketoutputstream.h | C++ | asf20 | 2,589 |
/*
* 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.
*/
#ifndef _LOG4CXX_SYSLOG_WRITER_H
#define _LOG4CXX_SYSLOG_WRITER_H
#include <log4cxx/helpers/objectptr.h>
#include <log4cxx/helpers/inetaddress.h>
#include <log4cxx/helpers/datagramsocket.h>
namespace log4cxx
{
namespace helpers
{
/**
SyslogWriter is a wrapper around the DatagramSocket class
it writes text to the specified host on the port 514 (UNIX syslog)
*/
class LOG4CXX_EXPORT SyslogWriter
{
public:
SyslogWriter(const LogString& syslogHost);
void write(const LogString& string);
private:
LogString syslogHost;
InetAddressPtr address;
DatagramSocketPtr ds;
};
} // namespace helpers
} // namespace log4cxx
#endif
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/syslogwriter.h | C++ | asf20 | 1,718 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_DATE_H
#define _LOG4CXX_HELPERS_DATE_H
#include <log4cxx/helpers/objectimpl.h>
#include <log4cxx/log4cxx.h>
namespace log4cxx {
namespace helpers {
/**
* Simple transcoder for converting between
* external char and wchar_t strings and
* internal strings.
*
*/
class LOG4CXX_EXPORT Date : public ObjectImpl {
const log4cxx_time_t time;
public:
DECLARE_LOG4CXX_OBJECT(Date)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(Date)
END_LOG4CXX_CAST_MAP()
Date();
Date(log4cxx_time_t time);
virtual ~Date();
inline log4cxx_time_t getTime() const {
return time;
}
/**
* Get start of next second
*/
log4cxx_time_t getNextSecond() const;
static log4cxx_time_t getMicrosecondsPerDay();
static log4cxx_time_t getMicrosecondsPerSecond();
};
LOG4CXX_PTR_DEF(Date);
}
}
#endif
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/date.h | C++ | asf20 | 1,790 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_SERVER_SOCKET_H
#define _LOG4CXX_HELPERS_SERVER_SOCKET_H
#include <log4cxx/helpers/socket.h>
#include <log4cxx/helpers/mutex.h>
namespace log4cxx
{
namespace helpers
{
class LOG4CXX_EXPORT ServerSocket
{
public:
/** Creates a server socket on a specified port.
*/
ServerSocket(int port);
virtual ~ServerSocket();
/** Listens for a connection to be made to this socket and
accepts it
*/
SocketPtr accept();
/** Closes this socket.
*/
void close();
/** Retrive setting for SO_TIMEOUT.
*/
int getSoTimeout() const;
/** Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.
*/
void setSoTimeout(int timeout);
private:
Pool pool;
Mutex mutex;
apr_socket_t* socket;
int timeout;
};
} // namespace helpers
} // namespace log4cxx
#endif //_LOG4CXX_HELPERS_SERVER_SOCKET_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/serversocket.h | C++ | asf20 | 2,278 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_LOADER_H
#define _LOG4CXX_HELPERS_LOADER_H
#include <log4cxx/helpers/objectptr.h>
#include <log4cxx/logstring.h>
#include <log4cxx/helpers/exception.h>
#include <log4cxx/helpers/inputstream.h>
namespace log4cxx
{
namespace helpers
{
class Class;
class LOG4CXX_EXPORT Loader
{
public:
static const Class& loadClass(const LogString& clazz);
static InputStreamPtr getResourceAsStream(
const LogString& name);
};
} // namespace helpers
} // namespace log4cxx
#endif //_LOG4CXX_HELPERS_LOADER_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/loader.h | C++ | asf20 | 1,534 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_OBJECT_PTR_H
#define _LOG4CXX_HELPERS_OBJECT_PTR_H
#include <log4cxx/log4cxx.h>
//
// Helgrind (race detection tool for Valgrind) will complain if pointer
// is not initialized in an atomic operation. Static analysis tools
// (gcc's -Weffc++, for example) will complain if pointer is not initialized
// in member initialization list. The use of a macro allows quick
// switching between the initialization styles.
//
#if LOG4CXX_HELGRIND
#define _LOG4CXX_OBJECTPTR_INIT(x) { exchange(x);
#else
#define _LOG4CXX_OBJECTPTR_INIT(x) : p(x) {
#endif
namespace log4cxx
{
namespace helpers
{
class Class;
class LOG4CXX_EXPORT ObjectPtrBase {
public:
ObjectPtrBase();
virtual ~ObjectPtrBase();
static void checkNull(const int& null);
static void* exchange(void** destination, void* newValue);
virtual void* cast(const Class& cls) const = 0;
};
/** smart pointer to a Object descendant */
template<typename T> class ObjectPtrT : public ObjectPtrBase
{
public:
ObjectPtrT(const int& null)
_LOG4CXX_OBJECTPTR_INIT(0)
ObjectPtrBase::checkNull(null);
}
ObjectPtrT()
_LOG4CXX_OBJECTPTR_INIT(0)
}
ObjectPtrT(T * p1)
_LOG4CXX_OBJECTPTR_INIT(p1)
if (this->p != 0)
{
this->p->addRef();
}
}
ObjectPtrT(const ObjectPtrT& p1)
_LOG4CXX_OBJECTPTR_INIT(p1.p)
if (this->p != 0)
{
this->p->addRef();
}
}
ObjectPtrT(const ObjectPtrBase& p1)
_LOG4CXX_OBJECTPTR_INIT(reinterpret_cast<T*>(p1.cast(T::getStaticClass())))
if (this->p != 0) {
this->p->addRef();
}
}
ObjectPtrT(ObjectPtrBase& p1)
_LOG4CXX_OBJECTPTR_INIT(reinterpret_cast<T*>(p1.cast(T::getStaticClass())))
if (this->p != 0) {
this->p->addRef();
}
}
~ObjectPtrT()
{
if (p != 0) {
p->releaseRef();
}
}
ObjectPtrT& operator=(const ObjectPtrT& p1) {
T* newPtr = p1.p;
if (newPtr != 0) {
newPtr->addRef();
}
T* oldPtr = exchange(newPtr);
if (oldPtr != 0) {
oldPtr->releaseRef();
}
return *this;
}
ObjectPtrT& operator=(const int& null) //throw(IllegalArgumentException)
{
//
// throws IllegalArgumentException if null != 0
//
ObjectPtrBase::checkNull(null);
T* oldPtr = exchange(0);
if (oldPtr != 0) {
oldPtr->releaseRef();
}
return *this;
}
ObjectPtrT& operator=(T* p1) {
if (p1 != 0) {
p1->addRef();
}
T* oldPtr = exchange(p1);
if (oldPtr != 0) {
oldPtr->releaseRef();
}
return *this;
}
ObjectPtrT& operator=(ObjectPtrBase& p1) {
T* newPtr = reinterpret_cast<T*>(p1.cast(T::getStaticClass()));
return operator=(newPtr);
}
ObjectPtrT& operator=(const ObjectPtrBase& p1) {
T* newPtr = reinterpret_cast<T*>(p1.cast(T::getStaticClass()));
return operator=(newPtr);
}
bool operator==(const ObjectPtrT& p1) const { return (this->p == p1.p); }
bool operator!=(const ObjectPtrT& p1) const { return (this->p != p1.p); }
bool operator<(const ObjectPtrT& p1) const { return (this->p < p1.p); }
bool operator==(const T* p1) const { return (this->p == p1); }
bool operator!=(const T* p1) const { return (this->p != p1); }
bool operator<(const T* p1) const { return (this->p < p1); }
T* operator->() const {return p; }
T& operator*() const {return *p; }
operator T*() const {return p; }
private:
T * p;
virtual void* cast(const Class& cls) const {
if (p != 0) {
return const_cast<void*>(p->cast(cls));
}
return 0;
}
T* exchange(const T* newValue) {
return static_cast<T*>(ObjectPtrBase::exchange(
reinterpret_cast<void**>(&p),
const_cast<T*>(newValue)));
}
};
}
}
#endif //_LOG4CXX_HELPERS_OBJECT_PTR_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/objectptr.h | C++ | asf20 | 5,610 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_MUTEX_H
#define _LOG4CXX_HELPERS_MUTEX_H
#include <log4cxx/log4cxx.h>
extern "C" {
struct apr_thread_mutex_t;
struct apr_pool_t;
}
namespace log4cxx
{
namespace helpers
{
class Pool;
class LOG4CXX_EXPORT Mutex
{
public:
Mutex(log4cxx::helpers::Pool& p);
Mutex(apr_pool_t* p);
~Mutex();
apr_thread_mutex_t* getAPRMutex() const;
private:
Mutex(const Mutex&);
Mutex& operator=(const Mutex&);
apr_thread_mutex_t* mutex;
};
} // namespace helpers
} // namespace log4cxx
#endif //_LOG4CXX_HELPERS_MUTEX_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/mutex.h | C++ | asf20 | 1,629 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_LOG_LOG_H
#define _LOG4CXX_HELPERS_LOG_LOG_H
#include <log4cxx/logstring.h>
#include <log4cxx/helpers/mutex.h>
#include <exception>
namespace log4cxx
{
namespace helpers
{
/**
This class used to output log statements from within the log4cxx package.
<p>Log4cxx components cannot make log4cxx logging calls. However, it is
sometimes useful for the user to learn about what log4cxx is
doing. You can enable log4cxx internal logging by calling the
<b>#setInternalDebugging</b> method.
<p>All log4cxx internal debug calls go to standard output
where as internal error messages are sent to
standard error output. All internal messages are prepended with
the string "log4cxx: ".
*/
class LOG4CXX_EXPORT LogLog
{
private:
bool debugEnabled;
/**
In quietMode not even errors generate any output.
*/
bool quietMode;
Mutex mutex;
LogLog();
LogLog(const LogLog&);
LogLog& operator=(const LogLog&);
static LogLog& getInstance();
public:
/**
Allows to enable/disable log4cxx internal logging.
*/
static void setInternalDebugging(bool enabled);
/**
This method is used to output log4cxx internal debug
statements. Output goes to the standard output.
*/
static void debug(const LogString& msg);
static void debug(const LogString& msg, const std::exception& e);
/**
This method is used to output log4cxx internal error
statements. There is no way to disable error statements.
Output goes to stderr.
*/
static void error(const LogString& msg);
static void error(const LogString& msg, const std::exception& e);
/**
In quiet mode LogLog generates strictly no output, not even
for errors.
@param quietMode <code>true</code> for no output.
*/
static void setQuietMode(bool quietMode);
/**
This method is used to output log4cxx internal warning
statements. There is no way to disable warning statements.
Output goes to stderr.
*/
static void warn(const LogString& msg);
static void warn(const LogString& msg, const std::exception& e);
private:
static void emit(const LogString& msg);
static void emit(const std::exception& ex);
};
} // namespace helpers
} // namespace log4cxx
#define LOGLOG_DEBUG(log) { \
log4cxx::helpers::LogLog::debug(log) ; }
#define LOGLOG_WARN(log) { \
log4cxx::helpers::LogLog::warn(log) ; }
#define LOGLOG_ERROR(log) { \
log4cxx::helpers::LogLog::warn(log); }
#endif //_LOG4CXX_HELPERS_LOG_LOG_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/loglog.h | C++ | asf20 | 4,483 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_ABSOLUTE_TIME_DATE_FORMAT_H
#define _LOG4CXX_HELPERS_ABSOLUTE_TIME_DATE_FORMAT_H
#include <log4cxx/helpers/simpledateformat.h>
namespace log4cxx
{
namespace helpers
{
/**
Formats a date in the format <b>HH:mm:ss,SSS</b> for example,
"15:49:37,459".
*/
class LOG4CXX_EXPORT AbsoluteTimeDateFormat : public SimpleDateFormat
{
public:
AbsoluteTimeDateFormat()
: SimpleDateFormat(LOG4CXX_STR("HH:mm:ss,SSS")) {}
};
} // namespace helpers
} // namespace log4cxx
#endif // _LOG4CXX_HELPERS_ABSOLUTE_TIME_DATE_FORMAT_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/absolutetimedateformat.h | C++ | asf20 | 1,545 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_THREAD_H
#define _LOG4CXX_HELPERS_THREAD_H
#include <log4cxx/log4cxx.h>
#include <log4cxx/helpers/pool.h>
#if !defined(LOG4CXX_THREAD_FUNC)
#if defined(_WIN32)
#define LOG4CXX_THREAD_FUNC __stdcall
#else
#define LOG4CXX_THREAD_FUNC
#endif
#endif
extern "C" {
typedef struct apr_thread_t apr_thread_t;
}
namespace log4cxx
{
namespace helpers
{
class Pool;
class ThreadLocal;
typedef void* (LOG4CXX_THREAD_FUNC *Runnable)(apr_thread_t* thread, void* data);
/**
* This class implements an approximation of java.util.Thread.
*/
class LOG4CXX_EXPORT Thread
{
public:
/**
* Create new instance.
*/
Thread();
/**
* Destructor.
*/
~Thread();
/**
* Runs the specified method on a newly created thread.
*/
void run(Runnable start, void* data);
void join();
inline bool isActive() { return thread != 0; }
/**
* Causes the currently executing thread to sleep for the
* specified number of milliseconds.
* @param millis milliseconds.
* @throws Interrupted Exception if the thread is interrupted.
*/
static void sleep(int millis);
/**
* Sets interrupted status for current thread to true.
*/
static void currentThreadInterrupt();
/**
* Sets interrupted status to true.
*/
void interrupt();
/**
* Tests if the current thread has been interrupted and
* sets the interrupted status to false.
*/
static bool interrupted();
bool isAlive();
bool isCurrentThread() const;
void ending();
private:
Pool p;
apr_thread_t* thread;
volatile unsigned int alive;
volatile unsigned int interruptedStatus;
Thread(const Thread&);
Thread& operator=(const Thread&);
/**
* This class is used to encapsulate the parameters to
* Thread::run when they are passed to Thread::launcher.
*
*/
class LaunchPackage {
public:
/**
* Placement new to create LaunchPackage in specified pool.
* LaunchPackage needs to be dynamically allocated since
* since a stack allocated instance may go out of scope
* before thread is launched.
*/
static void* operator new(size_t, Pool& p);
/**
* operator delete would be called if exception during construction.
*/
static void operator delete(void*, Pool& p);
/**
* Create new instance.
*/
LaunchPackage(Thread* thread, Runnable runnable, void* data);
/**
* Gets thread parameter.
* @return thread.
*/
Thread* getThread() const;
/**
* Gets runnable parameter.
* @return runnable.
*/
Runnable getRunnable() const;
/**
* gets data parameter.
* @return thread.
*/
void* getData() const;
private:
LaunchPackage(const LaunchPackage&);
LaunchPackage& operator=(const LaunchPackage&);
Thread* thread;
Runnable runnable;
void* data;
};
/**
* This object atomically sets the specified memory location
* to non-zero on construction and to zero on destruction.
* Used to maintain Thread.alive.
*/
class LaunchStatus {
public:
/*
* Construct new instance.
* @param p address of memory to set to non-zero on construction, zero on destruction.
*/
LaunchStatus(volatile unsigned int* p);
/**
* Destructor.
*/
~LaunchStatus();
private:
LaunchStatus(const LaunchStatus&);
LaunchStatus& operator=(const LaunchStatus&);
volatile unsigned int* alive;
};
/**
* This method runs on the created thread and sets up thread-local storage
* used to keep the reference to the corresponding Thread object and
* is responsible for maintaining Thread.alive.
*/
static void* LOG4CXX_THREAD_FUNC launcher(apr_thread_t* thread, void* data);
/**
* Get a key to the thread local storage used to hold the reference to
* the corresponding Thread object.
*/
static ThreadLocal& getThreadLocal();
};
} // namespace helpers
} // namespace log4cxx
#endif //_LOG4CXX_HELPERS_THREAD_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/thread.h | C++ | asf20 | 7,856 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_OBJECTOUTPUTSTREAM_H
#define _LOG4CXX_HELPERS_OBJECTOUTPUTSTREAM_H
#include <log4cxx/helpers/objectimpl.h>
#include <log4cxx/mdc.h>
#include <log4cxx/helpers/outputstream.h>
#include <log4cxx/helpers/charsetencoder.h>
namespace log4cxx
{
namespace helpers {
/**
* Emulates java serialization.
*/
class LOG4CXX_EXPORT ObjectOutputStream : public ObjectImpl
{
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(ObjectOutputStream)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(ObjectOutputStream)
END_LOG4CXX_CAST_MAP()
ObjectOutputStream(OutputStreamPtr os, Pool& p);
virtual ~ObjectOutputStream();
void close(Pool& p);
void flush(Pool& p);
void writeObject(const LogString&, Pool& p);
void writeUTFString(const std::string&, Pool& p);
void writeObject(const MDC::Map& mdc, Pool& p);
void writeInt(int val, Pool& p);
void writeLong(log4cxx_time_t val, Pool& p);
void writeProlog(const char* className,
int classDescIncrement,
char* bytes,
size_t len,
Pool& p);
void writeNull(Pool& p);
enum { STREAM_MAGIC = 0xACED };
enum { STREAM_VERSION = 5 };
enum { TC_NULL = 0x70,
TC_REFERENCE = 0x71,
TC_CLASSDESC = 0x72,
TC_OBJECT = 0x73,
TC_STRING = 0x74,
TC_ARRAY = 0x75,
TC_CLASS = 0x76,
TC_BLOCKDATA = 0x77,
TC_ENDBLOCKDATA = 0x78 };
enum {
SC_WRITE_METHOD = 0x01,
SC_SERIALIZABLE = 0x02 };
void writeByte(char val, Pool& p);
void writeBytes(const char* bytes, size_t len, Pool& p);
private:
ObjectOutputStream(const ObjectOutputStream&);
ObjectOutputStream& operator=(const ObjectOutputStream&);
OutputStreamPtr os;
log4cxx::helpers::CharsetEncoderPtr utf8Encoder;
unsigned int objectHandle;
typedef std::map<std::string, unsigned int> ClassDescriptionMap;
ClassDescriptionMap* classDescriptions;
};
LOG4CXX_PTR_DEF(ObjectOutputStream);
} // namespace helpers
} //namespace log4cxx
#endif //_LOG4CXX_HELPERS_OUTPUTSTREAM_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/objectoutputstream.h | C++ | asf20 | 3,647 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_BYTEBUFFER_H
#define _LOG4CXX_HELPERS_BYTEBUFFER_H
#include <log4cxx/log4cxx.h>
#include <stdio.h>
namespace log4cxx
{
namespace helpers {
/**
* A byte buffer.
*/
class LOG4CXX_EXPORT ByteBuffer
{
private:
char* base;
size_t pos;
size_t lim;
size_t cap;
public:
ByteBuffer(char* data, size_t capacity);
~ByteBuffer();
void clear();
void flip();
inline char* data() { return base; }
inline const char* data() const { return base; }
inline char* current() { return base + pos; }
inline const char* current() const { return base + pos; }
inline size_t limit() const { return lim; }
void limit(size_t newLimit);
inline size_t position() const { return pos; }
inline size_t remaining() const { return lim - pos; }
void position(size_t newPosition);
bool put(char byte);
private:
ByteBuffer(const ByteBuffer&);
ByteBuffer& operator=(const ByteBuffer&);
};
} // namespace helpers
} //namespace log4cxx
#endif //_LOG4CXX_HELPERS_BYTEBUFFER_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/bytebuffer.h | C++ | asf20 | 2,243 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPER_PROPERTIES_H
#define _LOG4CXX_HELPER_PROPERTIES_H
#if defined(_MSC_VER)
#pragma warning (push)
#pragma warning ( disable: 4231 4251 4275 4786 )
#endif
#include <log4cxx/logstring.h>
#include <log4cxx/helpers/objectptr.h>
#include <log4cxx/helpers/objectimpl.h>
#include <log4cxx/helpers/inputstream.h>
#include <map>
#include <vector>
#include <istream>
namespace log4cxx
{
namespace helpers
{
class LOG4CXX_EXPORT Properties
{
private:
typedef std::map<LogString, LogString> PropertyMap;
PropertyMap* properties;
Properties(const Properties&);
Properties& operator=(const Properties&);
public:
/**
* Create new instance.
*/
Properties();
/**
* Destructor.
*/
~Properties();
/**
Reads a property list (key and element pairs) from the input stream.
The stream is assumed to be using the ISO 8859-1 character encoding.
<p>Every property occupies one line of the input stream.
Each line is terminated by a line terminator (<code>\\n</code> or
<code>\\r</code> or <code>\\r\\n</code>).
Lines from the input stream are processed until end of file is reached
on the input stream.
<p>A line that contains only whitespace or whose first non-whitespace
character is an ASCII <code>#</code> or <code>!</code> is ignored
(thus, <code>#</code> or <code>!</code> indicate comment lines).
<p>Every line other than a blank line or a comment line describes one
property to be added to the table (except that if a line ends with \,
then the following line, if it exists, is treated as a continuation
line, as described below). The key consists of all the characters in
the line starting with the first non-whitespace character and up to,
but not including, the first ASCII <code>=</code>, <code>:</code>,
or whitespace character. All of the
key termination characters may be included in the key by preceding them
with a <code>\\</code>. Any whitespace after the key is skipped;
if the first
non-whitespace character after the key is <code>=</code> or
<code>:</code>, then it is ignored
and any whitespace characters after it are also skipped. All remaining
characters on the line become part of the associated element string.
Within the element string, the ASCII escape sequences <code>\\t</code>,
<code>\\n</code>, <code>\\r</code>, <code>\\</code>, <code>\\"</code>,
<code>\\'</code>, <code>\\</code> (a backslash and a space), and
<code>\\uxxxx</code> are recognized
and converted to single characters. Moreover, if the last character on
the line is <code>\\</code>, then the next line is treated as a
continuation of the
current line; the <code>\\</code> and line terminator are simply
discarded, and any
leading whitespace characters on the continuation line are also
discarded and are not part of the element string.
<p>As an example, each of the following four lines specifies the key
"Truth" and the associated element value "Beauty":
<pre>
Truth = Beauty
Truth:Beauty
Truth :Beauty
</pre>
As another example, the following three lines specify a single
property:
<pre>
fruits apple, banana, pear, \
cantaloupe, watermelon, \
kiwi, mango
</pre>
The key is "<code>fruits</code>" and the associated element is:
<pre>
"apple, banana, pear, cantaloupe, watermelon, kiwi, mango"
</pre>
Note that a space appears before each \ so that a space will appear
after each comma in the final result; the \, line terminator, and
leading whitespace on the continuation line are merely discarded and are
not replaced by one or more other characters.
<p>As a third example, the line:
<pre>
cheeses
</pre>
specifies that the key is "<code>cheeses</code>" and the associated
element is the empty string.
@param inStream the input stream.
@throw IOException if an error occurred when reading from the input
stream.
*/
void load(InputStreamPtr inStream);
/**
* Calls Properties::put.
* @param key the key to be placed into this property list.
* @param value the value corresponding to key.
* @return the previous value of the specified key in this
* property list, or an empty string if it did not have one.
*/
LogString setProperty(const LogString& key, const LogString& value);
/**
* Puts a property value into the collection.
* @param key the key to be placed into this property list.
* @param value the value corresponding to key.
* @return the previous value of the specified key in this
* property list, or an empty string if it did not have one.
*/
LogString put(const LogString& key, const LogString& value);
/**
* Calls Properties::get.
* @param key the property key.
* @return the value in this property list with the specified
* key value or empty string.
*/
LogString getProperty(const LogString& key) const;
/**
* Gets a property value.
* @param key the property key.
* @return the value in this property list with the specified
* key value or empty string.
*/
LogString get(const LogString& key) const;
/**
Returns an enumeration of all the keys in this property list,
including distinct keys in the default property list if a key
of the same name has not already been found from the main
properties list.
@return an array of all the keys in this
property list, including the keys in the default property list.
*/
std::vector<LogString> propertyNames() const;
}; // class Properties
} // namespace helpers
} // namespace log4cxx
#if defined(_MSC_VER)
#pragma warning (pop)
#endif
#endif //_LOG4CXX_HELPER_PROPERTIES_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/properties.h | C++ | asf20 | 9,067 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_BYTEARRAYOUTPUTSTREAM_H
#define _LOG4CXX_HELPERS_BYTEARRAYOUTPUTSTREAM_H
#if defined(_MSC_VER)
#pragma warning ( push )
#pragma warning ( disable: 4231 4251 4275 4786 )
#endif
#include <log4cxx/helpers/outputstream.h>
#include <vector>
namespace log4cxx
{
namespace helpers {
class Pool;
/**
* OutputStream implemented on top of std::vector
*/
class LOG4CXX_EXPORT ByteArrayOutputStream : public OutputStream
{
private:
LOG4CXX_LIST_DEF(ByteList, unsigned char);
ByteList array;
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(ByteArrayOutputStream)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(ByteArrayOutputStream)
LOG4CXX_CAST_ENTRY_CHAIN(OutputStream)
END_LOG4CXX_CAST_MAP()
ByteArrayOutputStream();
virtual ~ByteArrayOutputStream();
virtual void close(Pool& p);
virtual void flush(Pool& p);
virtual void write(ByteBuffer& buf, Pool& p);
ByteList toByteArray() const;
private:
ByteArrayOutputStream(const ByteArrayOutputStream&);
ByteArrayOutputStream& operator=(const ByteArrayOutputStream&);
};
LOG4CXX_PTR_DEF(ByteArrayOutputStream);
} // namespace helpers
} //namespace log4cxx
#if defined(_MSC_VER)
#pragma warning ( pop )
#endif
#endif //_LOG4CXX_HELPERS_BYTEARRAYOUTPUTSTREAM_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/bytearrayoutputstream.h | C++ | asf20 | 2,440 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_CHARSETENCODER_H
#define _LOG4CXX_HELPERS_CHARSETENCODER_H
#include <log4cxx/helpers/objectimpl.h>
#include <log4cxx/helpers/pool.h>
namespace log4cxx
{
namespace helpers {
class ByteBuffer;
class CharsetEncoder;
LOG4CXX_PTR_DEF(CharsetEncoder);
/**
* An engine to transform LogStrings into bytes
* for the specific character set.
*/
class LOG4CXX_EXPORT CharsetEncoder : public ObjectImpl
{
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(CharsetEncoder)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(CharsetEncoder)
END_LOG4CXX_CAST_MAP()
protected:
/**
* Protected constructor.
*/
CharsetEncoder();
public:
/**
* Destructor.
*/
virtual ~CharsetEncoder();
/**
* Get encoder for default charset.
*/
static CharsetEncoderPtr getDefaultEncoder();
/**
* Get encoder for specified character set.
* @param charset the following values should be recognized:
* "US-ASCII", "ISO-8859-1", "UTF-8",
* "UTF-16BE", "UTF-16LE".
* @return encoder.
* @throws IllegalArgumentException if encoding is not recognized.
*/
static CharsetEncoderPtr getEncoder(const LogString& charset);
/**
* Get encoder for UTF-8.
*/
static CharsetEncoderPtr getUTF8Encoder();
/**
* Encodes a string replacing unmappable
* characters with escape sequences.
*
*/
static void encode(CharsetEncoderPtr& enc,
const LogString& src,
LogString::const_iterator& iter,
ByteBuffer& dst);
/**
* Encodes as many characters from the input string as possible
* to the output buffer.
* @param in input string
* @param iter position in string to start.
* @param out output buffer.
* @return APR_SUCCESS unless a character can not be represented in
* the encoding.
*/
virtual log4cxx_status_t encode(const LogString& in,
LogString::const_iterator& iter,
ByteBuffer& out) = 0;
/**
* Resets any internal state.
*/
virtual void reset();
/**
* Flushes the encoder.
*/
virtual void flush(ByteBuffer& out);
/**
* Determines if the return value from encode indicates
* an unconvertable character.
*/
inline static bool isError(log4cxx_status_t stat) {
return (stat != 0);
}
private:
/**
* Private copy constructor.
*/
CharsetEncoder(const CharsetEncoder&);
/**
* Private assignment operator.
*/
CharsetEncoder& operator=(const CharsetEncoder&);
static CharsetEncoder* createDefaultEncoder();
};
} // namespace helpers
} //namespace log4cxx
#endif //_LOG4CXX_HELPERS_CHARSETENCODER_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/charsetencoder.h | C++ | asf20 | 4,585 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_PROPERTY_RESOURCE_BUNDLE_H
#define _LOG4CXX_HELPERS_PROPERTY_RESOURCE_BUNDLE_H
#include <log4cxx/helpers/resourcebundle.h>
#include <log4cxx/helpers/properties.h>
#include <log4cxx/helpers/inputstream.h>
namespace log4cxx
{
namespace helpers
{
/**
PropertyResourceBundle is a concrete subclass of ResourceBundle that
manages resources for a locale using a set of static strings from a
property file.
*/
class LOG4CXX_EXPORT PropertyResourceBundle : public ResourceBundle
{
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(PropertyResourceBundle)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(PropertyResourceBundle)
LOG4CXX_CAST_ENTRY_CHAIN(ResourceBundle)
END_LOG4CXX_CAST_MAP()
/**
Creates a property resource bundle.
@param inStream property file to read from.
@throw IOException if an error occurred when reading from the
input stream.
*/
PropertyResourceBundle(InputStreamPtr inStream);
virtual LogString getString(const LogString& key) const;
protected:
Properties properties;
}; // class PropertyResourceBundle
LOG4CXX_PTR_DEF(PropertyResourceBundle);
} // namespace helpers
} // namespace log4cxx
#endif // _LOG4CXX_HELPERS_PROPERTY_RESOURCE_BUNDLE_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/propertyresourcebundle.h | C++ | asf20 | 2,534 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_SIMPLE_DATE_FORMAT_H
#define _LOG4CXX_HELPERS_SIMPLE_DATE_FORMAT_H
#if defined(_MSC_VER)
#pragma warning ( push )
#pragma warning ( disable: 4231 4251 4275 4786 )
#endif
#include <log4cxx/helpers/dateformat.h>
#include <vector>
#include <time.h>
namespace std { class locale; }
namespace log4cxx
{
namespace helpers
{
namespace SimpleDateFormatImpl {
class PatternToken;
}
/**
* Concrete class for formatting and parsing dates in a
* locale-sensitive manner.
*/
class LOG4CXX_EXPORT SimpleDateFormat : public DateFormat
{
public:
/**
* Constructs a DateFormat using the given pattern and the default
* time zone.
*
* @param pattern the pattern describing the date and time format
*/
SimpleDateFormat(const LogString& pattern);
SimpleDateFormat(const LogString& pattern, const std::locale* locale);
~SimpleDateFormat();
virtual void format(LogString& s,
log4cxx_time_t tm,
log4cxx::helpers::Pool& p) const;
/**
* Set time zone.
* @param zone new time zone.
*/
void setTimeZone(const TimeZonePtr& zone);
private:
/**
* Time zone.
*/
TimeZonePtr timeZone;
/**
* List of tokens.
*/
LOG4CXX_LIST_DEF(PatternTokenList, log4cxx::helpers::SimpleDateFormatImpl::PatternToken*);
PatternTokenList pattern;
static void addToken(const logchar spec, const int repeat, const std::locale* locale, PatternTokenList& pattern);
static void parsePattern(const LogString& spec, const std::locale* locale, PatternTokenList& pattern);
};
} // namespace helpers
} // namespace log4cxx
#if defined(_MSC_VER)
#pragma warning ( pop )
#endif
#endif // _LOG4CXX_HELPERS_SIMPLE_DATE_FORMAT_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/simpledateformat.h | C++ | asf20 | 3,132 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_STRFTIME_DATE_FORMAT_H
#define _LOG4CXX_HELPERS_STRFTIME_DATE_FORMAT_H
#include <log4cxx/helpers/dateformat.h>
namespace log4cxx
{
namespace helpers
{
/**
Concrete class for formatting and parsing dates in a
locale-sensitive manner.
*/
class LOG4CXX_EXPORT StrftimeDateFormat : public DateFormat
{
public:
/**
Constructs a DateFormat using the given pattern and the default
time zone.
@param pattern the pattern describing the date and time format
*/
StrftimeDateFormat(const LogString& pattern);
~StrftimeDateFormat();
virtual void format(LogString& s,
log4cxx_time_t tm,
log4cxx::helpers::Pool& p) const;
/**
* Set time zone.
* @param zone new time zone.
*/
void setTimeZone(const TimeZonePtr& zone);
private:
/**
* Time zone.
*/
TimeZonePtr timeZone;
std::string pattern;
};
} // namespace helpers
} // namespace log4cxx
#endif // _LOG4CXX_HELPERS_STRFTIME_DATE_FORMAT_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/strftimedateformat.h | C++ | asf20 | 2,236 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_APPENDER_ATTACHABLE_IMPL_H
#define _LOG4CXX_HELPERS_APPENDER_ATTACHABLE_IMPL_H
#if defined(_MSC_VER)
#pragma warning ( push )
#pragma warning ( disable: 4231 4251 4275 4786 )
#endif
#include <log4cxx/spi/appenderattachable.h>
#include <log4cxx/helpers/objectimpl.h>
#include <log4cxx/helpers/mutex.h>
#include <log4cxx/helpers/pool.h>
namespace log4cxx
{
namespace spi
{
class LoggingEvent;
typedef helpers::ObjectPtrT<LoggingEvent> LoggingEventPtr;
}
namespace helpers
{
class LOG4CXX_EXPORT AppenderAttachableImpl :
public virtual spi::AppenderAttachable,
public virtual helpers::ObjectImpl
{
protected:
/** Array of appenders. */
AppenderList appenderList;
public:
/**
* Create new instance.
* @param pool pool, must be longer-lived than instance.
*/
AppenderAttachableImpl(Pool& pool);
DECLARE_ABSTRACT_LOG4CXX_OBJECT(AppenderAttachableImpl)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(AppenderAttachableImpl)
LOG4CXX_CAST_ENTRY(spi::AppenderAttachable)
END_LOG4CXX_CAST_MAP()
void addRef() const;
void releaseRef() const;
// Methods
/**
* Add an appender.
*/
virtual void addAppender(const AppenderPtr& newAppender);
/**
Call the <code>doAppend</code> method on all attached appenders.
*/
int appendLoopOnAppenders(const spi::LoggingEventPtr& event,
log4cxx::helpers::Pool& p);
/**
* Get all previously added appenders as an Enumeration.
*/
virtual AppenderList getAllAppenders() const;
/**
* Get an appender by name.
*/
virtual AppenderPtr getAppender(const LogString& name) const;
/**
Returns <code>true</code> if the specified appender is in the
list of attached appenders, <code>false</code> otherwise.
*/
virtual bool isAttached(const AppenderPtr& appender) const;
/**
* Remove all previously added appenders.
*/
virtual void removeAllAppenders();
/**
* Remove the appender passed as parameter from the list of appenders.
*/
virtual void removeAppender(const AppenderPtr& appender);
/**
* Remove the appender with the name passed as parameter from the
* list of appenders.
*/
virtual void removeAppender(const LogString& name);
inline const log4cxx::helpers::Mutex& getMutex() const { return mutex; }
private:
log4cxx::helpers::Mutex mutex;
AppenderAttachableImpl(const AppenderAttachableImpl&);
AppenderAttachableImpl& operator=(const AppenderAttachableImpl&);
};
LOG4CXX_PTR_DEF(AppenderAttachableImpl);
}
}
#if defined(_MSC_VER)
#pragma warning ( pop )
#endif
#endif //_LOG4CXX_HELPERS_APPENDER_ATTACHABLE_IMPL_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/appenderattachableimpl.h | C++ | asf20 | 4,101 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_POOL_H
#define _LOG4CXX_HELPERS_POOL_H
#include <log4cxx/log4cxx.h>
#include <string>
extern "C" {
struct apr_pool_t;
}
namespace log4cxx
{
namespace helpers
{
class LOG4CXX_EXPORT Pool
{
public:
Pool();
Pool(apr_pool_t* pool, bool release);
~Pool();
apr_pool_t* getAPRPool();
apr_pool_t* create();
void* palloc(size_t length);
char* pstralloc(size_t length);
char* itoa(int n);
char* pstrndup(const char* s, size_t len);
char* pstrdup(const char*s);
char* pstrdup(const std::string&);
protected:
apr_pool_t* pool;
const bool release;
private:
Pool(const log4cxx::helpers::Pool&);
Pool& operator=(const Pool&);
};
} // namespace helpers
} // namespace log4cxx
#endif //_LOG4CXX_HELPERS_POOL_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/pool.h | C++ | asf20 | 2,012 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_RELATIVE_TIME_DATE_FORMAT_H
#define _LOG4CXX_HELPERS_RELATIVE_TIME_DATE_FORMAT_H
#include <log4cxx/helpers/dateformat.h>
namespace log4cxx
{
namespace helpers
{
/**
Formats a date by printing the number of seconds
elapsed since the start of the application. This is the fastest
printing DateFormat in the package.
*/
class LOG4CXX_EXPORT RelativeTimeDateFormat : public DateFormat
{
public:
RelativeTimeDateFormat();
virtual void format(LogString &s,
log4cxx_time_t tm,
log4cxx::helpers::Pool& p) const;
private:
log4cxx_time_t startTime;
};
} // namespace helpers
} // namespace log4cxx
#endif // _LOG4CXX_HELPERS_RELATIVE_TIME_DATE_FORMAT_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/relativetimedateformat.h | C++ | asf20 | 1,814 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_FILEOUTPUTSTREAM_H
#define _LOG4CXX_HELPERS_FILEOUTPUTSTREAM_H
#include <log4cxx/helpers/outputstream.h>
#include <log4cxx/file.h>
#include <log4cxx/helpers/pool.h>
namespace log4cxx
{
namespace helpers {
/**
* OutputStream implemented on top of APR file IO.
*/
class LOG4CXX_EXPORT FileOutputStream : public OutputStream
{
private:
Pool pool;
apr_file_t* fileptr;
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(FileOutputStream)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(FileOutputStream)
LOG4CXX_CAST_ENTRY_CHAIN(OutputStream)
END_LOG4CXX_CAST_MAP()
FileOutputStream(const LogString& filename, bool append = false);
FileOutputStream(const logchar* filename, bool append = false);
virtual ~FileOutputStream();
virtual void close(Pool& p);
virtual void flush(Pool& p);
virtual void write(ByteBuffer& buf, Pool& p);
private:
FileOutputStream(const FileOutputStream&);
FileOutputStream& operator=(const FileOutputStream&);
static apr_file_t* open(const LogString& fn, bool append,
log4cxx::helpers::Pool& p);
};
LOG4CXX_PTR_DEF(FileOutputStream);
} // namespace helpers
} //namespace log4cxx
#endif //_LOG4CXX_HELPERS_FILEOUTPUTSTREAM_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/fileoutputstream.h | C++ | asf20 | 2,404 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_SYNCHRONIZED_H
#define _LOG4CXX_HELPERS_SYNCHRONIZED_H
#include <log4cxx/log4cxx.h>
namespace log4cxx
{
namespace helpers {
class Mutex;
/** utility class for objects multi-thread synchronization.*/
class LOG4CXX_EXPORT synchronized
{
public:
synchronized(const Mutex& mutex);
~synchronized();
private:
void* mutex;
// prevent use of copy and assignment
synchronized(const synchronized&);
synchronized& operator=(const synchronized&);
};
}
}
#endif //_LOG4CXX_HELPERS_SYNCHRONIZED_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/synchronized.h | C++ | asf20 | 1,542 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_INTEGER_H
#define _LOG4CXX_HELPERS_INTEGER_H
#include <log4cxx/helpers/objectimpl.h>
namespace log4cxx {
namespace helpers {
class LOG4CXX_EXPORT Integer : public ObjectImpl {
const int val;
public:
DECLARE_LOG4CXX_OBJECT(Integer)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(Integer)
END_LOG4CXX_CAST_MAP()
Integer();
Integer(int i);
virtual ~Integer();
inline int intValue() const {
return val;
}
};
LOG4CXX_PTR_DEF(Integer);
}
}
#endif
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/integer.h | C++ | asf20 | 1,387 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_BUFFEREDWRITER_H
#define _LOG4CXX_HELPERS_BUFFEREDWRITER_H
#include <log4cxx/helpers/writer.h>
namespace log4cxx
{
namespace helpers {
/**
* Writes text to a character-output stream buffering
* requests to increase efficiency.
*/
class LOG4CXX_EXPORT BufferedWriter : public Writer
{
private:
WriterPtr out;
size_t sz;
LogString buf;
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(BufferedWriter)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(BufferedWriter)
LOG4CXX_CAST_ENTRY_CHAIN(Writer)
END_LOG4CXX_CAST_MAP()
BufferedWriter(WriterPtr& out);
BufferedWriter(WriterPtr& out, size_t sz);
virtual ~BufferedWriter();
virtual void close(Pool& p);
virtual void flush(Pool& p);
virtual void write(const LogString& str, Pool& p);
private:
BufferedWriter(const BufferedWriter&);
BufferedWriter& operator=(const BufferedWriter&);
};
} // namespace helpers
} //namespace log4cxx
#endif //_LOG4CXX_HELPERS_BUFFEREDWRITER_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/bufferedwriter.h | C++ | asf20 | 2,175 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_CLASS_H
#define _LOG4CXX_HELPERS_CLASS_H
#if defined(_MSC_VER)
#pragma warning (push)
#pragma warning ( disable: 4231 4251 4275 4786 )
#endif
#include <log4cxx/logstring.h>
#include <log4cxx/helpers/objectptr.h>
#include <map>
namespace log4cxx
{
namespace helpers
{
class Object;
typedef ObjectPtrT<Object> ObjectPtr;
class LOG4CXX_EXPORT Class
{
public:
virtual ~Class();
virtual ObjectPtr newInstance() const;
LogString toString() const;
virtual LogString getName() const = 0;
static const Class& forName(const LogString& className);
static bool registerClass(const Class& newClass);
protected:
Class();
private:
Class(const Class&);
Class& operator=(const Class&);
typedef std::map<LogString, const Class *> ClassMap;
static ClassMap& getRegistry();
static void registerClasses();
};
} // namespace log4cxx
} // namespace helper
#if defined(_MSC_VER)
#pragma warning (pop)
#endif
#endif //_LOG4CXX_HELPERS_CLASS_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/class.h | C++ | asf20 | 2,199 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_SYSTEM_H
#define _LOG4CXX_HELPERS_SYSTEM_H
#include <log4cxx/logstring.h>
#include <log4cxx/helpers/exception.h>
namespace log4cxx
{
namespace helpers
{
class Properties;
/** The System class contains several useful class fields and methods.
It cannot be instantiated.
*/
class LOG4CXX_EXPORT System
{
public:
/**
Gets the system property indicated by the specified key.
@param key the name of the system property.
@return the string value of the system property, or the default value if
there is no property with that key.
@throws IllegalArgumentException if key is empty.
*/
static LogString getProperty(const LogString& key);
};
} // namespace helpers
} // namespace log4cxx
#endif //_LOG4CXX_HELPERS_SYSTEM_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/system.h | C++ | asf20 | 1,838 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_OBJECT_H
#define _LOG4CXX_HELPERS_OBJECT_H
#include <log4cxx/logstring.h>
#include <log4cxx/helpers/class.h>
#include <log4cxx/helpers/objectptr.h>
#include <log4cxx/helpers/classregistration.h>
#define DECLARE_ABSTRACT_LOG4CXX_OBJECT(object)\
public:\
class Clazz##object : public helpers::Class\
{\
public:\
Clazz##object() : helpers::Class() {}\
virtual ~Clazz##object() {}\
virtual log4cxx::LogString getName() const { return LOG4CXX_STR(#object); } \
};\
virtual const helpers::Class& getClass() const;\
static const helpers::Class& getStaticClass(); \
static const log4cxx::helpers::ClassRegistration& registerClass();
#define DECLARE_LOG4CXX_OBJECT(object)\
public:\
class Clazz##object : public helpers::Class\
{\
public:\
Clazz##object() : helpers::Class() {}\
virtual ~Clazz##object() {}\
virtual log4cxx::LogString getName() const { return LOG4CXX_STR(#object); } \
virtual helpers::ObjectPtr newInstance() const\
{\
return new object();\
}\
};\
virtual const helpers::Class& getClass() const;\
static const helpers::Class& getStaticClass(); \
static const log4cxx::helpers::ClassRegistration& registerClass();
#define DECLARE_LOG4CXX_OBJECT_WITH_CUSTOM_CLASS(object, class)\
public:\
virtual const helpers::Class& getClass() const;\
static const helpers::Class& getStaticClass();\
static const log4cxx::helpers::ClassRegistration& registerClass();
#define IMPLEMENT_LOG4CXX_OBJECT(object)\
const log4cxx::helpers::Class& object::getClass() const { return getStaticClass(); }\
const log4cxx::helpers::Class& object::getStaticClass() { \
static Clazz##object theClass; \
return theClass; \
} \
const log4cxx::helpers::ClassRegistration& object::registerClass() { \
static log4cxx::helpers::ClassRegistration classReg(object::getStaticClass); \
return classReg; \
}\
namespace log4cxx { namespace classes { \
const log4cxx::helpers::ClassRegistration& object##Registration = object::registerClass(); \
} }
#define IMPLEMENT_LOG4CXX_OBJECT_WITH_CUSTOM_CLASS(object, class)\
const log4cxx::helpers::Class& object::getClass() const { return getStaticClass(); }\
const log4cxx::helpers::Class& object::getStaticClass() { \
static class theClass; \
return theClass; \
} \
const log4cxx::helpers::ClassRegistration& object::registerClass() { \
static log4cxx::helpers::ClassRegistration classReg(object::getStaticClass); \
return classReg; \
}\
namespace log4cxx { namespace classes { \
const log4cxx::helpers::ClassRegistration& object##Registration = object::registerClass(); \
} }
namespace log4cxx
{
class AppenderSkeleton;
class Logger;
namespace helpers
{
class Pool;
/** base class for java-like objects.*/
class LOG4CXX_EXPORT Object
{
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(Object)
virtual ~Object() {}
virtual void addRef() const = 0;
virtual void releaseRef() const = 0;
virtual bool instanceof(const Class& clazz) const = 0;
virtual const void * cast(const Class& clazz) const = 0;
};
LOG4CXX_PTR_DEF(Object);
}
}
#define BEGIN_LOG4CXX_CAST_MAP()\
const void * cast(const helpers::Class& clazz) const\
{\
const void * object = 0;\
if (&clazz == &helpers::Object::getStaticClass()) return (const helpers::Object *)this;
#define END_LOG4CXX_CAST_MAP()\
return object;\
}\
bool instanceof(const helpers::Class& clazz) const\
{ return cast(clazz) != 0; }
#define LOG4CXX_CAST_ENTRY(Interface)\
if (&clazz == &Interface::getStaticClass()) return (const Interface *)this;
#define LOG4CXX_CAST_ENTRY2(Interface, interface2)\
if (&clazz == &Interface::getStaticClass()) return (Interface *)(interface2 *)this;
#define LOG4CXX_CAST_ENTRY_CHAIN(Interface)\
object = Interface::cast(clazz);\
if (object != 0) return object;
#endif //_LOG4CXX_HELPERS_OBJECT_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/object.h | C++ | asf20 | 5,200 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_OUTPUTSTREAM_H
#define _LOG4CXX_HELPERS_OUTPUTSTREAM_H
#include <log4cxx/helpers/objectimpl.h>
namespace log4cxx
{
namespace helpers {
class ByteBuffer;
/**
* Abstract class for writing to character streams.
*/
class LOG4CXX_EXPORT OutputStream : public ObjectImpl
{
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(OutputStream)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(OutputStream)
END_LOG4CXX_CAST_MAP()
protected:
OutputStream();
virtual ~OutputStream();
public:
virtual void close(Pool& p) = 0;
virtual void flush(Pool& p) = 0;
virtual void write(ByteBuffer& buf, Pool& p) = 0;
private:
OutputStream(const OutputStream&);
OutputStream& operator=(const OutputStream&);
};
LOG4CXX_PTR_DEF(OutputStream);
} // namespace helpers
} //namespace log4cxx
#endif //_LOG4CXX_HELPERS_OUTPUTSTREAM_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/outputstream.h | C++ | asf20 | 1,972 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_THREAD_SPECIFIC_DATA_H
#define _LOG4CXX_HELPERS_THREAD_SPECIFIC_DATA_H
#include <log4cxx/ndc.h>
#include <log4cxx/mdc.h>
namespace log4cxx
{
namespace helpers
{
/**
* This class contains all the thread-specific
* data in use by log4cxx.
*/
class LOG4CXX_EXPORT ThreadSpecificData
{
public:
ThreadSpecificData();
~ThreadSpecificData();
/**
* Gets current thread specific data.
* @return thread specific data, may be null.
*/
static ThreadSpecificData* getCurrentData();
/**
* Release this ThreadSpecficData if empty.
*/
void recycle();
static void put(const LogString& key, const LogString& val);
static void push(const LogString& val);
static void inherit(const log4cxx::NDC::Stack& stack);
log4cxx::NDC::Stack& getStack();
log4cxx::MDC::Map& getMap();
private:
static ThreadSpecificData& getDataNoThreads();
static ThreadSpecificData* createCurrentData();
log4cxx::NDC::Stack ndcStack;
log4cxx::MDC::Map mdcMap;
};
} // namespace helpers
} // namespace log4cxx
#endif
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/threadspecificdata.h | C++ | asf20 | 2,547 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_WRITER_H
#define _LOG4CXX_HELPERS_WRITER_H
#include <log4cxx/helpers/objectimpl.h>
namespace log4cxx
{
namespace helpers {
/**
* Abstract class for writing to character streams.
*/
class LOG4CXX_EXPORT Writer : public ObjectImpl
{
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(Writer)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(Writer)
END_LOG4CXX_CAST_MAP()
protected:
Writer();
virtual ~Writer();
public:
virtual void close(Pool& p) = 0;
virtual void flush(Pool& p) = 0;
virtual void write(const LogString& str, Pool& p) = 0;
private:
Writer(const Writer&);
Writer& operator=(const Writer&);
};
LOG4CXX_PTR_DEF(Writer);
} // namespace helpers
} //namespace log4cxx
#endif //_LOG4CXX_HELPERS_WRITER_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/writer.h | C++ | asf20 | 1,871 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_BYTEARRAYINPUTSTREAM_H
#define _LOG4CXX_HELPERS_BYTEARRAYINPUTSTREAM_H
#if defined(_MSC_VER)
#pragma warning ( push )
#pragma warning ( disable: 4231 4251 4275 4786 )
#endif
#include <vector>
#include <log4cxx/helpers/inputstream.h>
namespace log4cxx
{
namespace helpers {
/**
* InputStream implemented on top of a byte array.
*/
class LOG4CXX_EXPORT ByteArrayInputStream : public InputStream
{
private:
LOG4CXX_LIST_DEF(ByteList, unsigned char);
ByteList buf;
size_t pos;
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(ByteArrayInputStream)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(ByteArrayInputStream)
LOG4CXX_CAST_ENTRY_CHAIN(InputStream)
END_LOG4CXX_CAST_MAP()
/**
* Creates a ByteArrayInputStream.
*
* @param bytes array of bytes to copy into stream.
*/
ByteArrayInputStream(const ByteList& bytes);
virtual ~ByteArrayInputStream();
/**
* Closes this file input stream and releases any system
* resources associated with the stream.
*/
virtual void close();
/**
* Reads a sequence of bytes into the given buffer.
*
* @param buf The buffer into which bytes are to be transferred.
* @return the total number of bytes read into the buffer, or -1 if there
* is no more data because the end of the stream has been reached.
*/
virtual int read(ByteBuffer& buf);
private:
ByteArrayInputStream(const ByteArrayInputStream&);
ByteArrayInputStream& operator=(const ByteArrayInputStream&);
};
LOG4CXX_PTR_DEF(ByteArrayInputStream);
} // namespace helpers
} //namespace log4cxx
#if defined(_MSC_VER)
#pragma warning ( pop )
#endif
#endif //_LOG4CXX_HELPERS_BYTEARRAYINPUTSTREAM_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/bytearrayinputstream.h | C++ | asf20 | 3,104 |
/*
* 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.
*/
#ifndef _LOG4CXX_MESSAGE_BUFFER_H
#define _LOG4CXX_MESSAGE_BUFFER_H
#include <log4cxx/log4cxx.h>
#include <log4cxx/logstring.h>
#include <sstream>
namespace log4cxx {
namespace helpers {
typedef std::ios_base& (*ios_base_manip)(std::ios_base&);
/**
* This class is used by the LOG4CXX_INFO and similar
* macros to support insertion operators in the message parameter.
* The class is not intended for use outside of that context.
*/
class LOG4CXX_EXPORT CharMessageBuffer {
public:
/**
* Creates a new instance.
*/
CharMessageBuffer();
/**
* Destructor.
*/
~CharMessageBuffer();
/**
* Appends string to buffer.
* @param msg string append.
* @return this buffer.
*/
CharMessageBuffer& operator<<(const std::basic_string<char>& msg);
/**
* Appends string to buffer.
* @param msg string to append.
* @return this buffer.
*/
CharMessageBuffer& operator<<(const char* msg);
/**
* Appends string to buffer.
* @param msg string to append.
* @return this buffer.
*/
CharMessageBuffer& operator<<(char* msg);
/**
* Appends character to buffer.
* @param msg character to append.
* @return this buffer.
*/
CharMessageBuffer& operator<<(const char msg);
/**
* Insertion operator for STL manipulators such as std::fixed.
* @param manip manipulator.
* @return encapsulated STL stream.
*/
std::ostream& operator<<(ios_base_manip manip);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
std::ostream& operator<<(bool val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
std::ostream& operator<<(short val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
std::ostream& operator<<(int val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
std::ostream& operator<<(unsigned int val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
std::ostream& operator<<(long val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
std::ostream& operator<<(unsigned long val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
std::ostream& operator<<(float val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
std::ostream& operator<<(double val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
std::ostream& operator<<(long double val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
std::ostream& operator<<(void* val);
/**
* Cast to ostream.
*/
operator std::basic_ostream<char>&();
/**
* Get content of buffer.
* @param os used only to signal that
* the embedded stream was used.
*/
const std::basic_string<char>& str(std::basic_ostream<char>& os);
/**
* Get content of buffer.
* @param buf used only to signal that
* the embedded stream was not used.
*/
const std::basic_string<char>& str(CharMessageBuffer& buf);
/**
* Returns true if buffer has an encapsulated STL stream.
* @return true if STL stream was created.
*/
bool hasStream() const;
private:
/**
* Prevent use of default copy constructor.
*/
CharMessageBuffer(const CharMessageBuffer&);
/**
* Prevent use of default assignment operator.
*/
CharMessageBuffer& operator=(const CharMessageBuffer&);
/**
* Encapsulated std::string.
*/
std::basic_string<char> buf;
/**
* Encapsulated stream, created on demand.
*/
std::basic_ostringstream<char>* stream;
};
template<class V>
std::basic_ostream<char>& operator<<(CharMessageBuffer& os, const V& val) {
return ((std::basic_ostream<char>&) os) << val;
}
#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API || LOG4CXX_LOGCHAR_IS_UNICHAR
/**
* This class is designed to support insertion operations
* in the message argument to the LOG4CXX_INFO and similar
* macros and is not designed for general purpose use.
*/
class LOG4CXX_EXPORT UniCharMessageBuffer {
public:
/**
* Creates a new instance.
*/
UniCharMessageBuffer();
/**
* Destructor.
*/
~UniCharMessageBuffer();
typedef std::basic_ostream<UniChar> uostream;
/**
* Appends string to buffer.
* @param msg string append.
* @return this buffer.
*/
UniCharMessageBuffer& operator<<(const std::basic_string<UniChar>& msg);
/**
* Appends string to buffer.
* @param msg string to append.
* @return this buffer.
*/
UniCharMessageBuffer& operator<<(const UniChar* msg);
/**
* Appends string to buffer.
* @param msg string to append.
* @return this buffer.
*/
UniCharMessageBuffer& operator<<(UniChar* msg);
/**
* Appends character to buffer.
* @param msg character to append.
* @return this buffer.
*/
UniCharMessageBuffer& operator<<(const UniChar msg);
#if LOG4CXX_CFSTRING_API
/**
* Appends a string into the buffer and
* fixes the buffer to use char characters.
* @param msg message to append.
* @return encapsulated CharMessageBuffer.
*/
UniCharMessageBuffer& operator<<(const CFStringRef& msg);
#endif
/**
* Insertion operator for STL manipulators such as std::fixed.
* @param manip manipulator.
* @return encapsulated STL stream.
*/
uostream& operator<<(ios_base_manip manip);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
uostream& operator<<(bool val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
uostream& operator<<(short val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
uostream& operator<<(int val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
uostream& operator<<(unsigned int val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
uostream& operator<<(long val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
uostream& operator<<(unsigned long val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
uostream& operator<<(float val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
uostream& operator<<(double val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
uostream& operator<<(long double val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
uostream& operator<<(void* val);
/**
* Cast to ostream.
*/
operator uostream&();
/**
* Get content of buffer.
* @param os used only to signal that
* the embedded stream was used.
*/
const std::basic_string<UniChar>& str(uostream& os);
/**
* Get content of buffer.
* @param buf used only to signal that
* the embedded stream was not used.
*/
const std::basic_string<UniChar>& str(UniCharMessageBuffer& buf);
/**
* Returns true if buffer has an encapsulated STL stream.
* @return true if STL stream was created.
*/
bool hasStream() const;
private:
/**
* Prevent use of default copy constructor.
*/
UniCharMessageBuffer(const UniCharMessageBuffer&);
/**
* Prevent use of default assignment operator.
*/
UniCharMessageBuffer& operator=(const UniCharMessageBuffer&);
/**
* Encapsulated std::string.
*/
std::basic_string<UniChar> buf;
/**
* Encapsulated stream, created on demand.
*/
std::basic_ostringstream<UniChar>* stream;
};
template<class V>
UniCharMessageBuffer::uostream& operator<<(UniCharMessageBuffer& os, const V& val) {
return ((UniCharMessageBuffer::uostream&) os) << val;
}
#endif
#if LOG4CXX_WCHAR_T_API
/**
* This class is designed to support insertion operations
* in the message argument to the LOG4CXX_INFO and similar
* macros and is not designed for general purpose use.
*/
class LOG4CXX_EXPORT WideMessageBuffer {
public:
/**
* Creates a new instance.
*/
WideMessageBuffer();
/**
* Destructor.
*/
~WideMessageBuffer();
/**
* Appends string to buffer.
* @param msg string append.
* @return this buffer.
*/
WideMessageBuffer& operator<<(const std::basic_string<wchar_t>& msg);
/**
* Appends string to buffer.
* @param msg string to append.
* @return this buffer.
*/
WideMessageBuffer& operator<<(const wchar_t* msg);
/**
* Appends string to buffer.
* @param msg string to append.
* @return this buffer.
*/
WideMessageBuffer& operator<<(wchar_t* msg);
/**
* Appends character to buffer.
* @param msg character to append.
* @return this buffer.
*/
WideMessageBuffer& operator<<(const wchar_t msg);
/**
* Insertion operator for STL manipulators such as std::fixed.
* @param manip manipulator.
* @return encapsulated STL stream.
*/
std::basic_ostream<wchar_t>& operator<<(ios_base_manip manip);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
std::basic_ostream<wchar_t>& operator<<(bool val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
std::basic_ostream<wchar_t>& operator<<(short val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
std::basic_ostream<wchar_t>& operator<<(int val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
std::basic_ostream<wchar_t>& operator<<(unsigned int val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
std::basic_ostream<wchar_t>& operator<<(long val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
std::basic_ostream<wchar_t>& operator<<(unsigned long val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
std::basic_ostream<wchar_t>& operator<<(float val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
std::basic_ostream<wchar_t>& operator<<(double val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
std::basic_ostream<wchar_t>& operator<<(long double val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
std::basic_ostream<wchar_t>& operator<<(void* val);
/**
* Cast to ostream.
*/
operator std::basic_ostream<wchar_t>&();
/**
* Get content of buffer.
* @param os used only to signal that
* the embedded stream was used.
*/
const std::basic_string<wchar_t>& str(std::basic_ostream<wchar_t>& os);
/**
* Get content of buffer.
* @param buf used only to signal that
* the embedded stream was not used.
*/
const std::basic_string<wchar_t>& str(WideMessageBuffer& buf);
/**
* Returns true if buffer has an encapsulated STL stream.
* @return true if STL stream was created.
*/
bool hasStream() const;
private:
/**
* Prevent use of default copy constructor.
*/
WideMessageBuffer(const WideMessageBuffer&);
/**
* Prevent use of default assignment operator.
*/
WideMessageBuffer& operator=(const WideMessageBuffer&);
/**
* Encapsulated std::string.
*/
std::basic_string<wchar_t> buf;
/**
* Encapsulated stream, created on demand.
*/
std::basic_ostringstream<wchar_t>* stream;
};
template<class V>
std::basic_ostream<wchar_t>& operator<<(WideMessageBuffer& os, const V& val) {
return ((std::basic_ostream<wchar_t>&) os) << val;
}
/**
* This class is used by the LOG4CXX_INFO and similar
* macros to support insertion operators in the message parameter.
* The class is not intended for use outside of that context.
*/
class LOG4CXX_EXPORT MessageBuffer {
public:
/**
* Creates a new instance.
*/
MessageBuffer();
/**
* Destructor.
*/
~MessageBuffer();
/**
* Cast to ostream.
*/
operator std::ostream&();
/**
* Appends a string into the buffer and
* fixes the buffer to use char characters.
* @param msg message to append.
* @return encapsulated CharMessageBuffer.
*/
CharMessageBuffer& operator<<(const std::string& msg);
/**
* Appends a string into the buffer and
* fixes the buffer to use char characters.
* @param msg message to append.
* @return encapsulated CharMessageBuffer.
*/
CharMessageBuffer& operator<<(const char* msg);
/**
* Appends a string into the buffer and
* fixes the buffer to use char characters.
* @param msg message to append.
* @return encapsulated CharMessageBuffer.
*/
CharMessageBuffer& operator<<(char* msg);
/**
* Appends a string into the buffer and
* fixes the buffer to use char characters.
* @param msg message to append.
* @return encapsulated CharMessageBuffer.
*/
CharMessageBuffer& operator<<(const char msg);
/**
* Get content of buffer.
* @param buf used only to signal
* the character type and that
* the embedded stream was not used.
*/
const std::string& str(CharMessageBuffer& buf);
/**
* Get content of buffer.
* @param os used only to signal
* the character type and that
* the embedded stream was used.
*/
const std::string& str(std::ostream& os);
/**
* Appends a string into the buffer and
* fixes the buffer to use char characters.
* @param msg message to append.
* @return encapsulated CharMessageBuffer.
*/
WideMessageBuffer& operator<<(const std::wstring& msg);
/**
* Appends a string into the buffer and
* fixes the buffer to use char characters.
* @param msg message to append.
* @return encapsulated CharMessageBuffer.
*/
WideMessageBuffer& operator<<(const wchar_t* msg);
/**
* Appends a string into the buffer and
* fixes the buffer to use char characters.
* @param msg message to append.
* @return encapsulated CharMessageBuffer.
*/
WideMessageBuffer& operator<<(wchar_t* msg);
/**
* Appends a string into the buffer and
* fixes the buffer to use char characters.
* @param msg message to append.
* @return encapsulated CharMessageBuffer.
*/
WideMessageBuffer& operator<<(const wchar_t msg);
#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
/**
* Appends a string into the buffer and
* fixes the buffer to use char characters.
* @param msg message to append.
* @return encapsulated CharMessageBuffer.
*/
UniCharMessageBuffer& operator<<(const std::basic_string<UniChar>& msg);
/**
* Appends a string into the buffer and
* fixes the buffer to use char characters.
* @param msg message to append.
* @return encapsulated CharMessageBuffer.
*/
UniCharMessageBuffer& operator<<(const UniChar* msg);
/**
* Appends a string into the buffer and
* fixes the buffer to use char characters.
* @param msg message to append.
* @return encapsulated CharMessageBuffer.
*/
UniCharMessageBuffer& operator<<(UniChar* msg);
/**
* Appends a string into the buffer and
* fixes the buffer to use char characters.
* @param msg message to append.
* @return encapsulated CharMessageBuffer.
*/
UniCharMessageBuffer& operator<<(const UniChar msg);
#endif
#if LOG4CXX_CFSTRING_API
/**
* Appends a string into the buffer and
* fixes the buffer to use char characters.
* @param msg message to append.
* @return encapsulated CharMessageBuffer.
*/
UniCharMessageBuffer& operator<<(const CFStringRef& msg);
#endif
/**
* Insertion operator for STL manipulators such as std::fixed.
* @param manip manipulator.
* @return encapsulated STL stream.
*/
std::ostream& operator<<(ios_base_manip manip);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
std::ostream& operator<<(bool val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
std::ostream& operator<<(short val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
std::ostream& operator<<(int val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
std::ostream& operator<<(unsigned int val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
std::ostream& operator<<(long val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
std::ostream& operator<<(unsigned long val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
std::ostream& operator<<(float val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
std::ostream& operator<<(double val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
std::ostream& operator<<(long double val);
/**
* Insertion operator for built-in type.
* @param val build in type.
* @return encapsulated STL stream.
*/
std::ostream& operator<<(void* val);
/**
* Get content of buffer.
* @param buf used only to signal
* the character type and that
* the embedded stream was not used.
*/
const std::wstring& str(WideMessageBuffer& buf);
/**
* Get content of buffer.
* @param os used only to signal
* the character type and that
* the embedded stream was used.
*/
const std::wstring& str(std::basic_ostream<wchar_t>& os);
#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
/**
* Get content of buffer.
* @param buf used only to signal
* the character type and that
* the embedded stream was not used.
*/
const std::basic_string<UniChar>& str(UniCharMessageBuffer& buf);
/**
* Get content of buffer.
* @param os used only to signal
* the character type and that
* the embedded stream was used.
*/
const std::basic_string<UniChar>& str(UniCharMessageBuffer::uostream& os);
#endif
/**
* Returns true if buffer has an encapsulated STL stream.
* @return true if STL stream was created.
*/
bool hasStream() const;
private:
/**
* Prevent use of default copy constructor.
*/
MessageBuffer(const MessageBuffer&);
/**
* Prevent use of default assignment operator.
*/
MessageBuffer& operator=(const MessageBuffer&);
/**
* Character message buffer.
*/
CharMessageBuffer cbuf;
/**
* Encapsulated wide message buffer, created on demand.
*/
WideMessageBuffer* wbuf;
#if LOG4CXX_UNICHAR_API || LOG4CXX_CFSTRING_API
/**
* Encapsulated wide message buffer, created on demand.
*/
UniCharMessageBuffer* ubuf;
#endif
};
template<class V>
std::ostream& operator<<(MessageBuffer& os, const V& val) {
return ((std::ostream&) os) << val;
}
#if LOG4CXX_LOGCHAR_IS_UTF8
typedef CharMessageBuffer LogCharMessageBuffer;
#endif
#if LOG4CXX_LOGCHAR_IS_WCHAR
typedef WideMessageBuffer LogCharMessageBuffer;
#endif
#if LOG4CXX_LOGCHAR_IS_UNICHAR
typedef UniCharMessageBuffer LogCharMessageBuffer;
#endif
#else
typedef CharMessageBuffer MessageBuffer;
typedef CharMessageBuffer LogCharMessageBuffer;
#endif
}}
#endif
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/messagebuffer.h | C++ | asf20 | 26,003 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPER_INETADDRESS_H
#define _LOG4CXX_HELPER_INETADDRESS_H
#if defined(_MSC_VER)
#pragma warning ( push )
#pragma warning ( disable: 4231 4251 4275 4786 )
#endif
#include <log4cxx/helpers/objectimpl.h>
#include <log4cxx/helpers/objectptr.h>
#include <log4cxx/logstring.h>
#include <vector>
#include <log4cxx/helpers/exception.h>
namespace log4cxx
{
namespace helpers
{
class LOG4CXX_EXPORT UnknownHostException : public Exception
{
public:
UnknownHostException(const LogString& msg);
UnknownHostException(const UnknownHostException& src);
UnknownHostException& operator=(const UnknownHostException& src);
};
class InetAddress;
LOG4CXX_PTR_DEF(InetAddress);
LOG4CXX_LIST_DEF(InetAddressList, InetAddressPtr);
class LOG4CXX_EXPORT InetAddress : public ObjectImpl
{
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(InetAddress)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(InetAddress)
END_LOG4CXX_CAST_MAP()
InetAddress(const LogString& hostName, const LogString& hostAddr);
/** Determines all the IP addresses of a host, given the host's name.
*/
static InetAddressList getAllByName(const LogString& host);
/** Determines the IP address of a host, given the host's name.
*/
static InetAddressPtr getByName(const LogString& host);
/** Returns the IP address string "%d.%d.%d.%d".
*/
LogString getHostAddress() const;
/** Gets the host name for this IP address.
*/
LogString getHostName() const;
/** Returns the local host.
*/
static InetAddressPtr getLocalHost();
/** Returns an InetAddress which can be used as any
* address, for example when listening on a port from any
* remote addresss.
*/
static InetAddressPtr anyAddress();
/** Converts this IP address to a String.
*/
LogString toString() const;
private:
LogString ipAddrString;
LogString hostNameString;
}; // class InetAddress
} // namespace helpers
} // namespace log4cxx
#if defined(_MSC_VER)
#pragma warning ( pop )
#endif
#endif // _LOG4CXX_HELPER_INETADDRESS_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/inetaddress.h | C++ | asf20 | 3,775 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_CLASSREGISTRATION_H
#define _LOG4CXX_HELPERS_CLASSREGISTRATION_H
#include <log4cxx/log4cxx.h>
namespace log4cxx
{
namespace helpers
{
class Class;
class LOG4CXX_EXPORT ClassRegistration
{
public:
typedef const Class& (*ClassAccessor)();
ClassRegistration(ClassAccessor classAccessor);
private:
ClassRegistration(const ClassRegistration&);
ClassRegistration& operator=(const ClassRegistration&);
};
} // namespace log4cxx
} // namespace helper
#endif //_LOG4CXX_HELPERS_CLASSREGISTRATION_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/classregistration.h | C++ | asf20 | 1,539 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_ISO_8601_DATE_FORMAT_H
#define _LOG4CXX_HELPERS_ISO_8601_DATE_FORMAT_H
#include <log4cxx/helpers/simpledateformat.h>
namespace log4cxx
{
namespace helpers
{
/**
Formats a date in the format <b>yyyy-MM-dd HH:mm:ss,SSS</b> for example
"1999-11-27 15:49:37,459".
<p>Refer to the
<a href=http://www.cl.cam.ac.uk/~mgk25/iso-time.html>summary of the
International Standard Date and Time Notation</a> for more
information on this format.
*/
class LOG4CXX_EXPORT ISO8601DateFormat : public SimpleDateFormat
{
public:
ISO8601DateFormat()
: SimpleDateFormat(LOG4CXX_STR("yyyy-MM-dd HH:mm:ss,SSS")) {}
};
} // namespace helpers
} // namespace log4cxx
#endif // _LOG4CXX_HELPERS_ISO_8601_DATE_FORMAT_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/iso8601dateformat.h | C++ | asf20 | 1,790 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_CHARSETDECODER_H
#define _LOG4CXX_HELPERS_CHARSETDECODER_H
#include <log4cxx/helpers/objectimpl.h>
namespace log4cxx
{
namespace helpers {
class CharsetDecoder;
LOG4CXX_PTR_DEF(CharsetDecoder);
class ByteBuffer;
/**
* An abstract engine to transform a sequences of bytes in a specific charset
* into a LogString.
*/
class LOG4CXX_EXPORT CharsetDecoder : public ObjectImpl
{
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(CharsetDecoder)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(CharsetDecoder)
END_LOG4CXX_CAST_MAP()
protected:
/**
* Protected constructor.
*/
CharsetDecoder();
public:
/**
* Destructor.
*/
virtual ~CharsetDecoder();
/**
* Get decoder for default charset.
*/
static CharsetDecoderPtr getDefaultDecoder();
/**
* Get decoder for specified character set.
* @param charset the following values should be recognized:
* "US-ASCII", "ISO-8859-1", "UTF-8",
* "UTF-16BE", "UTF-16LE".
* @return decoder
* @throws IllegalArgumentException if charset is not recognized.
*/
static CharsetDecoderPtr getDecoder(const LogString& charset);
/**
* Get decoder for UTF-8.
*/
static CharsetDecoderPtr getUTF8Decoder();
/**
* Get decoder for ISO-8859-1.
*/
static CharsetDecoderPtr getISOLatinDecoder();
/**
* Decodes as many bytes as possible from the given
* input buffer, writing the results to the given output string.
* @param in input buffer.
* @param out output string.
* @return APR_SUCCESS if not encoding errors were found.
*/
virtual log4cxx_status_t decode(ByteBuffer& in,
LogString& out) = 0;
/**
* Determins if status value indicates an invalid byte sequence.
*/
inline static bool isError(log4cxx_status_t stat) {
return (stat != 0);
}
private:
/**
* Private copy constructor.
*/
CharsetDecoder(const CharsetDecoder&);
/**
* Private assignment operator.
*/
CharsetDecoder& operator=(const CharsetDecoder&);
/**
* Creates a new decoder for the default charset.
*/
static CharsetDecoder* createDefaultDecoder();
};
} // namespace helpers
} //namespace log4cxx
#endif //_LOG4CXX_HELPERS_CHARSETENCODER_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/charsetdecoder.h | C++ | asf20 | 4,033 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_XML_H
#define _LOG4CXX_HELPERS_XML_H
#if defined(_MSC_VER)
#pragma warning ( push )
#pragma warning ( disable: 4231 4251 4275 4786 )
#endif
#include <log4cxx/logstring.h>
#include <log4cxx/helpers/objectptr.h>
#include <log4cxx/helpers/object.h>
#include <log4cxx/helpers/exception.h>
namespace log4cxx
{
class File;
namespace helpers
{
class XMLDOMNode;
typedef helpers::ObjectPtrT<XMLDOMNode> XMLDOMNodePtr;
class XMLDOMDocument;
typedef helpers::ObjectPtrT<XMLDOMDocument> XMLDOMDocumentPtr;
class XMLDOMNodeList;
typedef helpers::ObjectPtrT<XMLDOMNodeList> XMLDOMNodeListPtr;
class LOG4CXX_EXPORT DOMException : public RuntimeException
{
public:
DOMException() : RuntimeException(LOG4CXX_STR("DOM exception")) {}
};
/**
The XMLDOMNode interface is the primary datatype for the entire Document
Object Model.
*/
class LOG4CXX_EXPORT XMLDOMNode : virtual public Object
{
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(XMLDOMNode)
enum XMLDOMNodeType
{
NOT_IMPLEMENTED_NODE = 0,
ELEMENT_NODE = 1,
DOCUMENT_NODE = 9
};
virtual XMLDOMNodeListPtr getChildNodes() = 0;
virtual XMLDOMNodeType getNodeType() = 0;
virtual XMLDOMDocumentPtr getOwnerDocument() = 0;
};
LOG4CXX_PTR_DEF(XMLDOMNode);
/**
The XMLDOMElement interface represents an element in an XML document
*/
class LOG4CXX_EXPORT XMLDOMElement : virtual public XMLDOMNode
{
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(XMLDOMElement)
virtual LogString getTagName() = 0;
virtual LogString getAttribute(const LogString& name) = 0;
};
LOG4CXX_PTR_DEF(XMLDOMElement);
/**
The XMLDOMDocument interface represents an entire XML document.
Conceptually, it is the root of the document tree, and provides the
primary access to the document's data.
*/
class LOG4CXX_EXPORT XMLDOMDocument : virtual public XMLDOMNode
{
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(XMLDOMDocument)
virtual void load(const File& fileName) = 0;
virtual XMLDOMElementPtr getDocumentElement() = 0;
virtual XMLDOMElementPtr getElementById(const LogString& tagName,
const LogString& elementId) = 0;
};
LOG4CXX_PTR_DEF(XMLDOMDocument);
/**
The XMLDOMNodeList interface provides the abstraction of an ordered
collection of nodes, without defining or constraining how this
collection is implemented.
XMLDOMNodeList objects in the DOM are live.
The items in the XMLDOMNodeList are accessible via an integral index,
starting from 0.
*/
class LOG4CXX_EXPORT XMLDOMNodeList : virtual public Object
{
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(XMLDOMNodeList)
virtual int getLength() = 0;
virtual XMLDOMNodePtr item(int index) = 0;
};
LOG4CXX_PTR_DEF(XMLDOMNodeList);
} // namespace helpers
} // namespace log4cxx
#if defined(_MSC_VER)
#pragma warning ( pop )
#endif
#endif // _LOG4CXX_HELPERS_XML_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/xml.h | C++ | asf20 | 4,916 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_INPUTSTREAM_H
#define _LOG4CXX_HELPERS_INPUTSTREAM_H
#include <log4cxx/helpers/objectimpl.h>
namespace log4cxx
{
namespace helpers {
class ByteBuffer;
/**
* Abstract class for reading from character streams.
*
*/
class LOG4CXX_EXPORT InputStream : public ObjectImpl
{
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(InputStream)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(InputStream)
END_LOG4CXX_CAST_MAP()
protected:
InputStream();
virtual ~InputStream();
public:
/**
* Reads a sequence of bytes into the given buffer.
*
* @param dst The buffer into which bytes are to be transferred.
* @return the total number of bytes read into the buffer, or -1 if there
* is no more data because the end of the stream has been reached.
*/
virtual int read(ByteBuffer& dst) = 0;
/**
* Closes this input stream and releases any system
* resources associated with the stream.
*/
virtual void close() = 0;
private:
InputStream(const InputStream&);
InputStream& operator=(const InputStream&);
};
LOG4CXX_PTR_DEF(InputStream);
} // namespace helpers
} //namespace log4cxx
#endif //_LOG4CXX_HELPERS_INPUTSTREAM_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/inputstream.h | C++ | asf20 | 2,485 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_SYSTEMERRWRITER_H
#define _LOG4CXX_HELPERS_SYSTEMERRWRITER_H
#include <log4cxx/helpers/writer.h>
namespace log4cxx
{
namespace helpers {
/**
* Abstract class for writing to character streams.
*/
class LOG4CXX_EXPORT SystemErrWriter : public Writer
{
public:
DECLARE_LOG4CXX_OBJECT(SystemErrWriter)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(SystemErrWriter)
LOG4CXX_CAST_ENTRY_CHAIN(Writer)
END_LOG4CXX_CAST_MAP()
SystemErrWriter();
virtual ~SystemErrWriter();
virtual void close(Pool& p);
virtual void flush(Pool& p);
virtual void write(const LogString& str, Pool& p);
static void write(const LogString& str);
static void flush();
private:
SystemErrWriter(const SystemErrWriter&);
SystemErrWriter& operator=(const SystemErrWriter&);
static bool isWide();
};
} // namespace helpers
} //namespace log4cxx
#endif //_LOG4CXX_HELPERS_SYSTEMERRWRITER_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/systemerrwriter.h | C++ | asf20 | 2,069 |
/*
* 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.
*/
#ifndef _LOG4CXX_HELPERS_READER_H
#define _LOG4CXX_HELPERS_READER_H
#include <log4cxx/helpers/objectimpl.h>
namespace log4cxx
{
namespace helpers {
/**
* Abstract class for reading from character streams.
*
*/
class LOG4CXX_EXPORT Reader : public ObjectImpl
{
public:
DECLARE_ABSTRACT_LOG4CXX_OBJECT(Reader)
BEGIN_LOG4CXX_CAST_MAP()
LOG4CXX_CAST_ENTRY(Reader)
END_LOG4CXX_CAST_MAP()
protected:
/**
* Creates a new character-stream reader.
*/
Reader();
virtual ~Reader();
public:
/**
* Closes the stream.
* @param p The memory pool associated with the reader.
*/
virtual void close(Pool& p) = 0;
/**
* @return The complete stream contents as a LogString.
* @param p The memory pool associated with the reader.
*/
virtual LogString read(Pool& p) = 0;
private:
Reader(const Reader&);
Reader& operator=(const Reader&);
};
LOG4CXX_PTR_DEF(Reader);
} // namespace helpers
} //namespace log4cxx
#endif //_LOG4CXX_HELPERS_READER_H
| 001-log4cxx | trunk/src/main/include/log4cxx/helpers/reader.h | C++ | asf20 | 2,275 |