merged tasking branch into trunk

This commit is contained in:
Martin Willi
2007-02-28 14:04:36 +00:00
parent a7a5e834e3
commit c60c7694d2
96 changed files with 8409 additions and 8332 deletions
+31 -2
View File
@@ -6,7 +6,8 @@
*/
/*
* Copyright (C) 2006 Tobias Brunner, Daniel Roethlisberger
* Copyright (C) 2006-2007 Tobias Brunner
* Copyright (C) 2006 Daniel Roethlisberger
* Copyright (C) 2005-2006 Martin Willi
* Copyright (C) 2005 Jan Hutter
* Hochschule fuer Technik Rapperswil
@@ -45,7 +46,7 @@ struct private_host_t {
union {
/** generic type */
struct sockaddr address;
/** maximux sockaddr size */
/** maximum sockaddr size */
struct sockaddr_storage address_max;
/** IPv4 address */
struct sockaddr_in address4;
@@ -495,3 +496,31 @@ host_t *host_create_from_sockaddr(sockaddr_t *sockaddr)
free(this);
return NULL;
}
/*
* Described in header.
*/
host_t *host_create_any(int family)
{
private_host_t *this = host_create_empty();
memset(&this->address_max, 0, sizeof(struct sockaddr_storage));
this->address.sa_family = family;
switch (family)
{
case AF_INET:
{
this->socklen = sizeof(struct sockaddr_in);
return &(this->public);
}
case AF_INET6:
{
this->socklen = sizeof(struct sockaddr_in6);
return &this->public;
}
default:
break;
}
return NULL;
}
+14 -1
View File
@@ -6,7 +6,8 @@
*/
/*
* Copyright (C) 2006 Tobias Brunner, Daniel Roethlisberger
* Copyright (C) 2006-2007 Tobias Brunner
* Copyright (C) 2006 Daniel Roethlisberger
* Copyright (C) 2005-2006 Martin Willi
* Copyright (C) 2005 Jan Hutter
* Hochschule fuer Technik Rapperswil
@@ -216,4 +217,16 @@ host_t *host_create_from_chunk(int family, chunk_t address, u_int16_t port);
*/
host_t *host_create_from_sockaddr(sockaddr_t *sockaddr);
/**
* @brief Create a host without an address, a "any" host.
*
* @param family family of the any host
* @return
* - host_t object
* - NULL, if family not supported.
*
* @ingroup network
*/
host_t *host_create_any(int family);
#endif /*HOST_H_*/
+40 -10
View File
@@ -497,7 +497,10 @@ bool match_dn(chunk_t a, chunk_t b, int *wildcards)
bool next_a, next_b;
/* initialize wildcard counter */
*wildcards = 0;
if (wildcards)
{
*wildcards = 0;
}
/* initialize DN parsing */
if (init_rdn(a, &rdn_a, &attribute_a, &next_a) != SUCCESS
@@ -522,7 +525,10 @@ bool match_dn(chunk_t a, chunk_t b, int *wildcards)
/* does rdn_b contain a wildcard? */
if (value_b.len == 1 && *value_b.ptr == '*')
{
(*wildcards)++;
if (wildcards)
{
(*wildcards)++;
}
continue;
}
/* same lengths for values */
@@ -549,7 +555,10 @@ bool match_dn(chunk_t a, chunk_t b, int *wildcards)
}
/* the two DNs match! */
*wildcards = min(*wildcards, MAX_WILDCARDS);
if (wildcards)
{
*wildcards = min(*wildcards, MAX_WILDCARDS);
}
return TRUE;
}
@@ -750,10 +759,16 @@ static bool matches_binary(private_identification_t *this,
{
if (other->type == ID_ANY)
{
*wildcards = MAX_WILDCARDS;
if (wildcards)
{
*wildcards = MAX_WILDCARDS;
}
return TRUE;
}
*wildcards = 0;
if (wildcards)
{
*wildcards = 0;
}
return this->type == other->type &&
chunk_equals(this->encoded, other->encoded);
}
@@ -769,7 +784,10 @@ static bool matches_string(private_identification_t *this,
if (other->type == ID_ANY)
{
*wildcards = MAX_WILDCARDS;
if (wildcards)
{
*wildcards = MAX_WILDCARDS;
}
return TRUE;
}
@@ -779,7 +797,10 @@ static bool matches_string(private_identification_t *this,
/* try a binary comparison first */
if (equals_binary(this, other))
{
*wildcards = 0;
if (wildcards)
{
*wildcards = 0;
}
return TRUE;
}
@@ -789,7 +810,10 @@ static bool matches_string(private_identification_t *this,
/* check for single wildcard at the head of the string */
if (*other->encoded.ptr == '*')
{
*wildcards = 1;
if (wildcards)
{
*wildcards = 1;
}
/* single asterisk matches any string */
if (len-- == 1)
@@ -809,7 +833,10 @@ static bool matches_string(private_identification_t *this,
static bool matches_any(private_identification_t *this,
private_identification_t *other, int *wildcards)
{
*wildcards = 0;
if (wildcards)
{
*wildcards = 0;
}
return other->type == ID_ANY;
}
@@ -822,7 +849,10 @@ static bool matches_dn(private_identification_t *this,
{
if (other->type == ID_ANY)
{
*wildcards = MAX_WILDCARDS;
if (wildcards)
{
*wildcards = MAX_WILDCARDS;
}
return TRUE;
}
+1 -1
View File
@@ -182,7 +182,7 @@ struct identification_t {
*
* @param this the ID without wildcard
* @param other the ID containing a wildcard
* @param wildcards returns the number of wildcards
* @param wildcards returns the number of wildcards, may be NULL
* @return TRUE if match is found
*/
bool (*matches) (identification_t *this, identification_t *other, int *wildcards);
+16 -1
View File
@@ -24,6 +24,19 @@
#ifndef ITERATOR_H_
#define ITERATOR_H_
#include <library.h>
/**
* @brief Iterator hook function prototype.
*
* @param param user supplied parameter
* @param in the value the hook receives from the iterator
* @param out the value supplied as a result to the iterator
* @return TRUE to return "out", FALSE to skip this value
*/
typedef bool (iterator_hook_t)(void *param, void *in, void **out);
typedef struct iterator_t iterator_t;
/**
@@ -76,8 +89,10 @@ struct iterator_t {
*
* @param this calling object
* @param hook iterator hook which manipulates the iterated value
* @param param user supplied parameter to pass back to the hook
*/
void (*set_iterator_hook) (iterator_t *this, void*(*hook)(void*));
void (*set_iterator_hook) (iterator_t *this, iterator_hook_t *hook,
void *param);
/**
* @brief Inserts a new item before the given iterator position.
+32 -11
View File
@@ -132,7 +132,12 @@ struct private_iterator_t {
/**
* iteration hook
*/
void* (*hook)(void*);
iterator_hook_t *hook;
/**
* user parameter for iterator hook
*/
void *hook_param;
};
/**
@@ -146,23 +151,27 @@ static int get_list_count(private_iterator_t *this)
/**
* default iterator hook which does nothing
*/
static void *iterator_hook(void *value)
static bool iterator_hook(void *param, void *in, void **out)
{
return value;
*out = in;
return TRUE;
}
/**
* Implementation of iterator_t.set_iterator_hook.
*/
static void set_iterator_hook(private_iterator_t *this, void*(*hook)(void*))
static void set_iterator_hook(private_iterator_t *this, iterator_hook_t *hook,
void* param)
{
if (hook == NULL)
{
this->hook = iterator_hook;
this->hook_param = NULL;
}
else
{
this->hook = hook;
this->hook_param = param;
}
}
@@ -178,7 +187,10 @@ static bool iterate(private_iterator_t *this, void** value)
if (this->current == NULL)
{
this->current = (this->forward) ? this->list->first : this->list->last;
*value = this->hook(this->current->value);
if (!this->hook(this->hook_param, this->current->value, value))
{
return iterate(this, value);
}
return TRUE;
}
if (this->forward)
@@ -188,16 +200,21 @@ static bool iterate(private_iterator_t *this, void** value)
return FALSE;
}
this->current = this->current->next;
*value = this->hook(this->current->value);
if (!this->hook(this->hook_param, this->current->value, value))
{
return iterate(this, value);
}
return TRUE;
}
/* backward */
if (this->current->previous == NULL)
{
return FALSE;
}
this->current = this->current->previous;
*value = this->hook(this->current->value);
if (!this->hook(this->hook_param, this->current->value, value))
{
return iterate(this, value);
}
return TRUE;
}
@@ -225,11 +242,15 @@ static status_t remove_(private_iterator_t *this)
{
return NOT_FOUND;
}
/* find out the new iterator position */
if (this->current->previous != NULL)
/* find out the new iterator position, depending on iterator direction */
if (this->forward && this->current->previous != NULL)
{
new_current = this->current->previous;
}
else if (!this->forward && this->current->next != NULL)
{
new_current = this->current->next;
}
else
{
new_current = NULL;
@@ -679,7 +700,7 @@ static iterator_t *create_iterator(private_linked_list_t *linked_list, bool forw
this->public.get_count = (int (*) (iterator_t*)) get_list_count;
this->public.iterate = (bool (*) (iterator_t*, void **value)) iterate;
this->public.set_iterator_hook = (void(*)(iterator_t*, void*(*)(void*)))set_iterator_hook;
this->public.set_iterator_hook = (void(*)(iterator_t*, iterator_hook_t*, void*))set_iterator_hook;
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;