removed %M printf handler, five more to go
This commit is contained in:
@@ -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 = snprintf(buf, len, "%N ", payload_type_short_names,
|
||||
payload->get_type(payload));
|
||||
if (written >= len || written < 0)
|
||||
{
|
||||
written = fprintf(stream, " ");
|
||||
if (written < 0)
|
||||
{
|
||||
return written;
|
||||
}
|
||||
total_written += written;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
first = FALSE;
|
||||
}
|
||||
written = fprintf(stream, "%N", payload_type_short_names,
|
||||
payload->get_type(payload));
|
||||
if (written < 0)
|
||||
{
|
||||
return written;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -43,8 +43,6 @@
|
||||
/** 1 argument: ike_sa_t *ike_sa */
|
||||
#define PRINTF_IKE_SA 'K'
|
||||
/** 1 argument: message_t *message */
|
||||
#define PRINTF_MESSAGE 'M'
|
||||
/** 2 arguments: enum_name_t *name, long value */
|
||||
#define PRINTF_ENUM 'N'
|
||||
/** 1 argument: child_sa_t *child_sa */
|
||||
#define PRINTF_CHILD_SA 'P'
|
||||
|
||||
Reference in New Issue
Block a user