diff options
Diffstat (limited to 'Source/charon/utils')
-rw-r--r-- | Source/charon/utils/identification.c | 23 | ||||
-rw-r--r-- | Source/charon/utils/identification.h | 14 | ||||
-rw-r--r-- | Source/charon/utils/logger.c | 28 |
3 files changed, 54 insertions, 11 deletions
diff --git a/Source/charon/utils/identification.c b/Source/charon/utils/identification.c index 73f218874..72d1610af 100644 --- a/Source/charon/utils/identification.c +++ b/Source/charon/utils/identification.c @@ -116,6 +116,28 @@ static bool equals (private_identification_t *this,private_identification_t *oth } /** + * Implementation of identification_t.belongs_to. + */ +static bool belongs_to(private_identification_t *this, private_identification_t *other) +{ + if (this->public.equals(&this->public, &other->public)) + { + return TRUE; + } + + if (this->type == other->type && this->type == ID_IPV4_ADDR) + { + /* is this %any (0.0.0.0)?*/ + if (*((u_int32_t*)this->encoded.ptr) == 0) + { + return TRUE; + } + /* TODO: Do we need subnet support? */ + } + return FALSE; +} + +/** * Implementation of identification_t.clone. */ static identification_t *clone(private_identification_t *this) @@ -150,6 +172,7 @@ static private_identification_t *identification_create() private_identification_t *this = allocator_alloc_thing(private_identification_t); this->public.equals = (bool (*) (identification_t*,identification_t*))equals; + this->public.belongs_to = (bool (*) (identification_t*,identification_t*))belongs_to; this->public.get_encoding = (chunk_t (*) (identification_t*))get_encoding; this->public.get_type = (id_type_t (*) (identification_t*))get_type; this->public.get_string = (char* (*) (identification_t*))get_string; diff --git a/Source/charon/utils/identification.h b/Source/charon/utils/identification.h index 38bac5ee1..b973da9a4 100644 --- a/Source/charon/utils/identification.h +++ b/Source/charon/utils/identification.h @@ -153,6 +153,20 @@ struct identification_t { bool (*equals) (identification_t *this,identification_t *other); /** + * @brief Check if an ID belongs to a wildcard ID. + * + * An identification_t may contain wildcards, such as + * *@strongswan.org. This call checks if a given ID + * (e.g. tester@strongswan.org) belongs to a such wildcard + * ID. Returns TRUE if IDs are identical. + * + * @param this the ID containing a wildcard + * @param other the ID without wildcard + * @return TRUE if other belongs to this + */ + bool (*belongs_to) (identification_t *this, identification_t *other); + + /** * @brief Clone a identification_t instance. * * @param this the identification_t object to clone diff --git a/Source/charon/utils/logger.c b/Source/charon/utils/logger.c index 29f485baa..3e2c93860 100644 --- a/Source/charon/utils/logger.c +++ b/Source/charon/utils/logger.c @@ -178,6 +178,7 @@ static void log_bytes(private_logger_t *this, logger_level_t loglevel, char *lab if ((this->level & loglevel) == loglevel) { char buffer[MAX_LOG]; + char ascii_buffer[17]; char *format; char *buffer_pos; char *bytes_pos, *bytes_roof; @@ -207,6 +208,7 @@ static void log_bytes(private_logger_t *this, logger_level_t loglevel, char *lab bytes_pos = bytes; bytes_roof = bytes + len; buffer_pos = buffer; + memset(ascii_buffer, 0, 17); for (i = 1; bytes_pos < bytes_roof; i++) { @@ -219,30 +221,34 @@ static void log_bytes(private_logger_t *this, logger_level_t loglevel, char *lab buffer_pos = buffer; if (this->output == NULL) { - syslog(LOG_INFO, "[=>] [%5d ] %s", line_start, buffer); + syslog(LOG_INFO, "[=>] [%5d ] %s %s", line_start, buffer, ascii_buffer); } else { - fprintf(this->output, "[=>] [%5d ] %s\n", line_start, buffer); + fprintf(this->output, "[=>] [%5d ] %s %s\n", line_start, buffer, ascii_buffer); } + memset(ascii_buffer, 0, 16); line_start += 16; } - else if ((i % 8) == 0) - { - *buffer_pos++ = ' '; - *buffer_pos++ = ' '; - *buffer_pos++ = ' '; - } else if ((i % 4) == 0) { *buffer_pos++ = ' '; - *buffer_pos++ = ' '; + // *buffer_pos++ = ' '; } else { *buffer_pos++ = ' '; } + if (*bytes_pos > 31 && *bytes_pos < 127) + { + ascii_buffer[(i % 16)] = *bytes_pos; + } + else + { + ascii_buffer[(i % 16)] = '*'; + } + bytes_pos++; } @@ -252,11 +258,11 @@ static void log_bytes(private_logger_t *this, logger_level_t loglevel, char *lab buffer_pos = buffer; if (this->output == NULL) { - syslog(LOG_INFO, "[=>] [%5d ] %s", line_start, buffer); + syslog(LOG_INFO, "[=>] [%5d ] %s %16s", line_start, buffer, ascii_buffer); } else { - fprintf(this->output, "[=>] [%5d ] %s\n", line_start, buffer); + fprintf(this->output, "[=>] [%5d ] %s %16s\n", line_start, buffer, ascii_buffer); } } pthread_mutex_unlock(&mutex); |