diff options
author | Martin Willi <martin@strongswan.org> | 2007-04-11 09:12:21 +0000 |
---|---|---|
committer | Martin Willi <martin@strongswan.org> | 2007-04-11 09:12:21 +0000 |
commit | cd08b6880ba63792812338c1efe27f396676e7a3 (patch) | |
tree | b77a246dce69c44315d675ef861a4339225afe52 /src/charon/encoding/message.c | |
parent | 82240938ca46d12e9a7625838320ec1899b0f237 (diff) | |
download | strongswan-cd08b6880ba63792812338c1efe27f396676e7a3.tar.bz2 strongswan-cd08b6880ba63792812338c1efe27f396676e7a3.tar.xz |
removed %M printf handler, five more to go
Diffstat (limited to 'src/charon/encoding/message.c')
-rw-r--r-- | src/charon/encoding/message.c | 81 |
1 files changed, 27 insertions, 54 deletions
diff --git a/src/charon/encoding/message.c b/src/charon/encoding/message.c index 5f3f91f8b..077b76738 100644 --- a/src/charon/encoding/message.c +++ b/src/charon/encoding/message.c @@ -24,7 +24,6 @@ #include <stdlib.h> #include <string.h> -#include <printf.h> #include "message.h" @@ -603,72 +602,42 @@ static payload_t *get_payload(private_message_t *this, payload_type_t type) } /** - * output handler in printf() + * get a string representation of the message */ -static int print(FILE *stream, const struct printf_info *info, - const void *const *args) +static void get_string(private_message_t *this, char *buf, int len) { - private_message_t *this = *((private_message_t**)(args[0])); iterator_t *iterator; payload_t *payload; - bool first = TRUE; - size_t total_written = 0; - size_t written; + int written; - if (this == NULL) + written = snprintf(buf, len, "%N %s [", + exchange_type_names, this->exchange_type, + this->is_request ? "request" : "response"); + if (written >= len || written < 0) { - return fprintf(stream, "(null)"); + return; } - - written = fprintf(stream, "%N %s [", - exchange_type_names, this->exchange_type, - this->is_request ? "request" : "response"); - if (written < 0) - { - return written; - } - total_written += written; + buf += written; + len -= written; iterator = this->payloads->create_iterator(this->payloads, TRUE); while (iterator->iterate(iterator, (void**)&payload)) { - if (!first) - { - written = fprintf(stream, " "); - if (written < 0) - { - return written; - } - total_written += written; - } - else - { - first = FALSE; - } - written = fprintf(stream, "%N", payload_type_short_names, - payload->get_type(payload)); - if (written < 0) + written = snprintf(buf, len, "%N ", payload_type_short_names, + payload->get_type(payload)); + if (written >= len || written < 0) { - return written; + return; } - total_written += written; + buf += written; + len -= written; } iterator->destroy(iterator); - written = fprintf(stream, "]"); - if (written < 0) - { - return written; - } - total_written += written; - return total_written; -} - -/** - * register printf() handlers - */ -static void __attribute__ ((constructor))print_register() -{ - register_printf_function(PRINTF_MESSAGE, print, arginfo_ptr); + + /* remove last space */ + len++; + buf--; + snprintf(buf, len, "]"); } /** @@ -757,6 +726,7 @@ static status_t generate(private_message_t *this, crypter_t *crypter, signer_t* iterator_t *iterator; status_t status; chunk_t packet_data; + char str[128]; if (is_encoded(this)) { @@ -765,7 +735,8 @@ static status_t generate(private_message_t *this, crypter_t *crypter, signer_t* return SUCCESS; } - DBG1(DBG_ENC, "generating %M", this); + get_string(this, str, sizeof(str)); + DBG1(DBG_ENC, "generating %s", str); if (this->exchange_type == EXCHANGE_TYPE_UNDEFINED) { @@ -1162,6 +1133,7 @@ static status_t parse_body(private_message_t *this, crypter_t *crypter, signer_t { status_t status = SUCCESS; payload_type_t current_payload_type; + char str[128]; current_payload_type = this->first_payload; @@ -1231,7 +1203,8 @@ static status_t parse_body(private_message_t *this, crypter_t *crypter, signer_t return status; } - DBG1(DBG_ENC, "parsed %M", this); + get_string(this, str, sizeof(str)); + DBG1(DBG_ENC, "parsed %s", str); return SUCCESS; } |