removed %M printf handler, five more to go
[strongswan.git] / src / charon / encoding / message.c
index 5f3f91f..077b767 100644 (file)
@@ -24,7 +24,6 @@
 
 #include <stdlib.h>
 #include <string.h>
 
 #include <stdlib.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,
-                                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;
        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))
        {
        
        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);
        }
        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;
        iterator_t *iterator;
        status_t status;
        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;
        payload_type_t current_payload_type;
 {
        status_t status = SUCCESS;
        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;
 }