removed %M printf handler, five more to go

This commit is contained in:
Martin Willi
2007-04-11 09:12:21 +00:00
parent 82240938ca
commit cd08b6880b
2 changed files with 27 additions and 56 deletions
+27 -54
View File
@@ -24,7 +24,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <printf.h>
#include "message.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, static void get_string(private_message_t *this, char *buf, int len)
const void *const *args)
{ {
private_message_t *this = *((private_message_t**)(args[0]));
iterator_t *iterator; iterator_t *iterator;
payload_t *payload; payload_t *payload;
bool first = TRUE; int written;
size_t total_written = 0;
size_t 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;
} }
buf += written;
written = fprintf(stream, "%N %s [", len -= written;
exchange_type_names, this->exchange_type,
this->is_request ? "request" : "response");
if (written < 0)
{
return written;
}
total_written += written;
iterator = this->payloads->create_iterator(this->payloads, TRUE); iterator = this->payloads->create_iterator(this->payloads, TRUE);
while (iterator->iterate(iterator, (void**)&payload)) while (iterator->iterate(iterator, (void**)&payload))
{ {
if (!first) written = snprintf(buf, len, "%N ", payload_type_short_names,
payload->get_type(payload));
if (written >= len || written < 0)
{ {
written = fprintf(stream, " "); return;
if (written < 0)
{
return written;
}
total_written += written;
} }
else buf += written;
{ len -= written;
first = FALSE;
}
written = fprintf(stream, "%N", payload_type_short_names,
payload->get_type(payload));
if (written < 0)
{
return written;
}
total_written += written;
} }
iterator->destroy(iterator); iterator->destroy(iterator);
written = fprintf(stream, "]");
if (written < 0) /* remove last space */
{ len++;
return written; buf--;
} snprintf(buf, len, "]");
total_written += written;
return total_written;
}
/**
* register printf() handlers
*/
static void __attribute__ ((constructor))print_register()
{
register_printf_function(PRINTF_MESSAGE, print, arginfo_ptr);
} }
/** /**
@@ -757,6 +726,7 @@ static status_t generate(private_message_t *this, crypter_t *crypter, signer_t*
iterator_t *iterator; iterator_t *iterator;
status_t status; status_t status;
chunk_t packet_data; chunk_t packet_data;
char str[128];
if (is_encoded(this)) if (is_encoded(this))
{ {
@@ -765,7 +735,8 @@ static status_t generate(private_message_t *this, crypter_t *crypter, signer_t*
return SUCCESS; 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) 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; status_t status = SUCCESS;
payload_type_t current_payload_type; payload_type_t current_payload_type;
char str[128];
current_payload_type = this->first_payload; 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; return status;
} }
DBG1(DBG_ENC, "parsed %M", this); get_string(this, str, sizeof(str));
DBG1(DBG_ENC, "parsed %s", str);
return SUCCESS; return SUCCESS;
} }
-2
View File
@@ -43,8 +43,6 @@
/** 1 argument: ike_sa_t *ike_sa */ /** 1 argument: ike_sa_t *ike_sa */
#define PRINTF_IKE_SA 'K' #define PRINTF_IKE_SA 'K'
/** 1 argument: message_t *message */ /** 1 argument: message_t *message */
#define PRINTF_MESSAGE 'M'
/** 2 arguments: enum_name_t *name, long value */
#define PRINTF_ENUM 'N' #define PRINTF_ENUM 'N'
/** 1 argument: child_sa_t *child_sa */ /** 1 argument: child_sa_t *child_sa */
#define PRINTF_CHILD_SA 'P' #define PRINTF_CHILD_SA 'P'