diff options
Diffstat (limited to 'src/libstrongswan/utils')
-rw-r--r-- | src/libstrongswan/utils/hashtable.c | 6 | ||||
-rw-r--r-- | src/libstrongswan/utils/host.c | 67 | ||||
-rw-r--r-- | src/libstrongswan/utils/host.h | 9 | ||||
-rw-r--r-- | src/libstrongswan/utils/identification.c | 40 | ||||
-rw-r--r-- | src/libstrongswan/utils/identification.h | 13 | ||||
-rw-r--r-- | src/libstrongswan/utils/leak_detective.c | 3 | ||||
-rw-r--r-- | src/libstrongswan/utils/linked_list.c | 12 |
7 files changed, 62 insertions, 88 deletions
diff --git a/src/libstrongswan/utils/hashtable.c b/src/libstrongswan/utils/hashtable.c index 892d08b6c..27a7a66c1 100644 --- a/src/libstrongswan/utils/hashtable.c +++ b/src/libstrongswan/utils/hashtable.c @@ -12,7 +12,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * $Id: hashtable.c 4812 2008-12-17 09:56:05Z tobias $ + * $Id: hashtable.c 4936 2009-03-12 18:07:32Z tobias $ */ #include <utils/linked_list.h> @@ -282,7 +282,7 @@ static void *get(private_hashtable_t *this, void *key) /** * Implementation of hashtable_t.remove */ -static void *remove(private_hashtable_t *this, void *key) +static void *remove_(private_hashtable_t *this, void *key) { void *value = NULL; linked_list_t *list; @@ -414,7 +414,7 @@ hashtable_t *hashtable_create(hashtable_hash_t hash, hashtable_equals_t equals, this->public.put = (void*(*)(hashtable_t*,void*,void*))put; this->public.get = (void*(*)(hashtable_t*,void*))get; - this->public.remove = (void*(*)(hashtable_t*,void*))remove; + this->public.remove = (void*(*)(hashtable_t*,void*))remove_; this->public.get_count = (u_int(*)(hashtable_t*))get_count; this->public.create_enumerator = (enumerator_t*(*)(hashtable_t*))create_enumerator; this->public.destroy = (void(*)(hashtable_t*))destroy; diff --git a/src/libstrongswan/utils/host.c b/src/libstrongswan/utils/host.c index 719c5a529..a40c42c49 100644 --- a/src/libstrongswan/utils/host.c +++ b/src/libstrongswan/utils/host.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2007 Tobias Brunner + * Copyright (C) 2006-2009 Tobias Brunner * Copyright (C) 2006 Daniel Roethlisberger * Copyright (C) 2005-2006 Martin Willi * Copyright (C) 2005 Jan Hutter @@ -15,13 +15,12 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * $Id: host.c 4856 2009-02-05 22:13:48Z andreas $ + * $Id: host.c 4977 2009-03-19 09:16:03Z martin $ */ #define _GNU_SOURCE #include <netdb.h> #include <string.h> -#include <printf.h> #include "host.h" @@ -106,10 +105,10 @@ static bool is_anyaddr(private_host_t *this) } /** - * output handler in printf() + * Described in header. */ -static int print(FILE *stream, const struct printf_info *info, - const void *const *args) +int host_printf_hook(char *dst, size_t dstlen, printf_hook_spec_t *spec, + const void *const *args) { private_host_t *this = *((private_host_t**)(args[0])); char buffer[INET6_ADDRSTRLEN + 16]; @@ -120,7 +119,8 @@ static int print(FILE *stream, const struct printf_info *info, } else if (is_anyaddr(this)) { - snprintf(buffer, sizeof(buffer), "%%any"); + snprintf(buffer, sizeof(buffer), "%%any%s", + this->address.sa_family == AF_INET6 ? "6" : ""); } else { @@ -145,7 +145,7 @@ static int print(FILE *stream, const struct printf_info *info, snprintf(buffer, sizeof(buffer), "(address conversion failed)"); } - else if (info->alt) + else if (spec->hash) { len = strlen(buffer); snprintf(buffer + len, sizeof(buffer) - len, @@ -157,34 +157,11 @@ static int print(FILE *stream, const struct printf_info *info, break; } } - if (info->left) + if (spec->minus) { - return fprintf(stream, "%-*s", info->width, buffer); + return print_in_hook(dst, dstlen, "%-*s", spec->width, buffer); } - return fprintf(stream, "%*s", info->width, buffer); -} - - -/** - * arginfo handler for printf() hosts - */ -int arginfo(const struct printf_info *info, size_t n, int *argtypes) -{ - if (n > 0) - { - argtypes[0] = PA_POINTER; - } - return 1; -} - -/** - * return printf hook functions for a host - */ -printf_hook_functions_t host_get_printf_hooks() -{ - printf_hook_functions_t hooks = {print, arginfo}; - - return hooks; + return print_in_hook(dst, dstlen, "%*s", spec->width, buffer); } /** @@ -388,6 +365,18 @@ static private_host_t *host_create_empty(void) } /* + * Create a %any host with port + */ +static host_t *host_create_any_port(int family, u_int16_t port) +{ + host_t *this; + + this = host_create_any(family); + this->set_port(this, port); + return this; +} + +/* * Described in header. */ host_t *host_create_from_string(char *string, u_int16_t port) @@ -396,7 +385,11 @@ host_t *host_create_from_string(char *string, u_int16_t port) if (streq(string, "%any")) { - return host_create_any(AF_INET); + return host_create_any_port(AF_INET, port); + } + if (streq(string, "%any6")) + { + return host_create_any_port(AF_INET6, port); } this = host_create_empty(); @@ -451,11 +444,11 @@ host_t *host_create_from_dns(char *string, int af, u_int16_t port) if (streq(string, "%any")) { - return host_create_any(af ? af : AF_INET); + return host_create_any_port(af ? af : AF_INET, port); } if (streq(string, "%any6")) { - return host_create_any(af ? af : AF_INET6); + return host_create_any_port(af ? af : AF_INET6, port); } else if (strchr(string, ':')) { diff --git a/src/libstrongswan/utils/host.h b/src/libstrongswan/utils/host.h index 667cc6bcc..5f00872b8 100644 --- a/src/libstrongswan/utils/host.h +++ b/src/libstrongswan/utils/host.h @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 Martin Willi - * Copyright (C) 2006-2007 Tobias Brunner + * Copyright (C) 2006-2009 Tobias Brunner * Copyright (C) 2006 Daniel Roethlisberger + * Copyright (C) 2005-2008 Martin Willi * Copyright (C) 2005 Jan Hutter * Hochschule fuer Technik Rapperswil * @@ -198,12 +198,13 @@ host_t *host_create_from_sockaddr(sockaddr_t *sockaddr); host_t *host_create_any(int family); /** - * Get printf hooks for a host. + * printf hook function for host_t. * * Arguments are: * host_t *host * Use #-modifier to include port number */ -printf_hook_functions_t host_get_printf_hooks(); +int host_printf_hook(char *dst, size_t len, printf_hook_spec_t *spec, + const void *const *args); #endif /* HOST_H_ @}*/ diff --git a/src/libstrongswan/utils/identification.c b/src/libstrongswan/utils/identification.c index 529e62509..ff97f3610 100644 --- a/src/libstrongswan/utils/identification.c +++ b/src/libstrongswan/utils/identification.c @@ -1,4 +1,5 @@ /* + * Copyright (C) 2009 Tobias Brunner * Copyright (C) 2005-2008 Martin Willi * Copyright (C) 2005 Jan Hutter * Hochschule fuer Technik Rapperswil @@ -13,7 +14,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * $Id: identification.c 4856 2009-02-05 22:13:48Z andreas $ + * $Id: identification.c 4936 2009-03-12 18:07:32Z tobias $ */ #define _GNU_SOURCE @@ -23,7 +24,6 @@ #include <string.h> #include <stdio.h> #include <ctype.h> -#include <printf.h> #include "identification.h" @@ -879,10 +879,10 @@ static id_match_t matches_dn(private_identification_t *this, } /** - * output handler in printf() + * Described in header. */ -static int print(FILE *stream, const struct printf_info *info, - const void *const *args) +int identification_printf_hook(char *dst, size_t len, printf_hook_spec_t *spec, + const void *const *args) { private_identification_t *this = *((private_identification_t**)(args[0])); char buf[BUF_LEN]; @@ -890,7 +890,7 @@ static int print(FILE *stream, const struct printf_info *info, if (this == NULL) { - return fprintf(stream, "%*s", info->width, "(null)"); + return print_in_hook(dst, len, "%*s", spec->width, "(null)"); } switch (this->type) @@ -940,33 +940,11 @@ static int print(FILE *stream, const struct printf_info *info, snprintf(buf, sizeof(buf), "(unknown ID type: %d)", this->type); break; } - if (info->left) - { - return fprintf(stream, "%-*s", info->width, buf); - } - return fprintf(stream, "%*s", info->width, buf); -} - -/** - * arginfo handler - */ -static int arginfo(const struct printf_info *info, size_t n, int *argtypes) -{ - if (n > 0) + if (spec->minus) { - argtypes[0] = PA_POINTER; + return print_in_hook(dst, len, "%-*s", spec->width, buf); } - return 1; -} - -/** - * Get printf hook functions - */ -printf_hook_functions_t identification_get_printf_hooks() -{ - printf_hook_functions_t hook = {print, arginfo}; - - return hook; + return print_in_hook(dst, len, "%*s", spec->width, buf); } /** diff --git a/src/libstrongswan/utils/identification.h b/src/libstrongswan/utils/identification.h index 3b895961d..070984490 100644 --- a/src/libstrongswan/utils/identification.h +++ b/src/libstrongswan/utils/identification.h @@ -1,4 +1,5 @@ /* + * Copyright (C) 2009 Tobias Brunner * Copyright (C) 2005-2006 Martin Willi * Copyright (C) 2005 Jan Hutter * Hochschule fuer Technik Rapperswil @@ -13,7 +14,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * $Id: identification.h 4344 2008-09-17 02:17:01Z andreas $ + * $Id: identification.h 4936 2009-03-12 18:07:32Z tobias $ */ /** @@ -274,10 +275,12 @@ identification_t * identification_create_from_string(char *string); identification_t * identification_create_from_encoding(id_type_t type, chunk_t encoded); /** - * Get the printf hook functions. - * - * @return printf hook functions + * printf hook function for identification_t. + * + * Arguments are: + * identification_t *identification */ -printf_hook_functions_t identification_get_printf_hooks(); +int identification_printf_hook(char *dst, size_t len, printf_hook_spec_t *spec, + const void *const *args); #endif /* IDENTIFICATION_H_ @} */ diff --git a/src/libstrongswan/utils/leak_detective.c b/src/libstrongswan/utils/leak_detective.c index 4c56c9596..0e0866fec 100644 --- a/src/libstrongswan/utils/leak_detective.c +++ b/src/libstrongswan/utils/leak_detective.c @@ -12,7 +12,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * $Id: leak_detective.c 4796 2008-12-12 09:10:52Z martin $ + * $Id: leak_detective.c 4936 2009-03-12 18:07:32Z tobias $ */ #define _GNU_SOURCE @@ -29,7 +29,6 @@ #include <syslog.h> #include <pthread.h> #include <netdb.h> -#include <printf.h> #include <locale.h> #include "leak_detective.h" diff --git a/src/libstrongswan/utils/linked_list.c b/src/libstrongswan/utils/linked_list.c index 068d13f99..bfe30b0df 100644 --- a/src/libstrongswan/utils/linked_list.c +++ b/src/libstrongswan/utils/linked_list.c @@ -14,7 +14,7 @@ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * - * $Id: linked_list.c 4580 2008-11-05 11:55:17Z martin $ + * $Id: linked_list.c 4936 2009-03-12 18:07:32Z tobias $ */ #include <stdlib.h> @@ -224,7 +224,7 @@ static void iterator_reset(private_iterator_t *this) /** * Implementation of iterator_t.remove. */ -static status_t remove_(private_iterator_t *this) +static status_t iterator_remove(private_iterator_t *this) { element_t *new_current; @@ -514,8 +514,8 @@ static status_t remove_last(private_linked_list_t *this, void **item) /** * Implementation of linked_list_t.remove. */ -static int remove(private_linked_list_t *this, void *item, - bool (*compare)(void *,void*)) +static int remove_(private_linked_list_t *this, void *item, + bool (*compare)(void *,void*)) { element_t *current = this->first; int removed = 0; @@ -727,7 +727,7 @@ static iterator_t *create_iterator(private_linked_list_t *linked_list, bool forw this->public.insert_before = (void (*) (iterator_t*, void *item)) insert_before; this->public.insert_after = (void (*) (iterator_t*, void *item)) insert_after; this->public.replace = (status_t (*) (iterator_t*, void **, void *)) replace; - this->public.remove = (status_t (*) (iterator_t*)) remove_; + this->public.remove = (status_t (*) (iterator_t*)) iterator_remove; this->public.reset = (void (*) (iterator_t*)) iterator_reset; this->public.destroy = (void (*) (iterator_t*)) iterator_destroy; @@ -756,7 +756,7 @@ linked_list_t *linked_list_create() this->public.insert_last = (void (*) (linked_list_t *, void *item))insert_last; this->public.remove_first = (status_t (*) (linked_list_t *, void **item))remove_first; this->public.remove_last = (status_t (*) (linked_list_t *, void **item))remove_last; - this->public.remove = (int(*)(linked_list_t*, void *item, bool (*compare)(void *,void*)))remove; + this->public.remove = (int(*)(linked_list_t*, void *item, bool (*compare)(void *,void*)))remove_; this->public.remove_at = (void(*)(linked_list_t*, enumerator_t *enumerator))remove_at; this->public.invoke_offset = (void (*)(linked_list_t*,size_t,...))invoke_offset; this->public.invoke_function = (void (*)(linked_list_t*,linked_list_invoke_t,...))invoke_function; |