Base code merged to SPIN 2.4
[platform/upstream/curl.git] / src / tool_cb_dbg.c
index 7ac9a73..4add67c 100644 (file)
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -19,9 +19,7 @@
  * KIND, either express or implied.
  *
  ***************************************************************************/
-#include "setup.h"
-
-#include <curl/curl.h>
+#include "tool_setup.h"
 
 #define ENABLE_CURLX_PRINTF
 /* use our own printf() functions */
@@ -46,7 +44,8 @@ int tool_debug_cb(CURL *handle, curl_infotype type,
                   unsigned char *data, size_t size,
                   void *userdata)
 {
-  struct Configurable *config = userdata;
+  struct OperationConfig *operation = userdata;
+  struct GlobalConfig *config = operation->global;
   FILE *output = config->errors;
   const char *text;
   struct timeval tv;
@@ -89,7 +88,7 @@ int tool_debug_cb(CURL *handle, curl_infotype type,
     output = config->trace_stream;
 
   if(!output) {
-    warnf(config, "Failed to create/open output");
+    warnf(operation, "Failed to create/open output");
     return 0;
   }
 
@@ -108,19 +107,21 @@ int tool_debug_cb(CURL *handle, curl_infotype type,
 
     switch(type) {
     case CURLINFO_HEADER_OUT:
-      for(i = 0; i < size - 1; i++) {
-        if(data[i] == '\n') { /* LF */
-          if(!newl) {
-            fprintf(output, "%s%s ", timebuf, s_infotype[type]);
+      if(size > 0) {
+        for(i = 0; i < size - 1; i++) {
+          if(data[i] == '\n') { /* LF */
+            if(!newl) {
+              fprintf(output, "%s%s ", timebuf, s_infotype[type]);
+            }
+            (void)fwrite(data + st, i - st + 1, 1, output);
+            st = i + 1;
+            newl = FALSE;
           }
-          (void)fwrite(data + st, i - st + 1, 1, output);
-          st = i + 1;
-          newl = FALSE;
         }
+        if(!newl)
+          fprintf(output, "%s%s ", timebuf, s_infotype[type]);
+        (void)fwrite(data + st, i - st + 1, 1, output);
       }
-      if(!newl)
-        fprintf(output, "%s%s ", timebuf, s_infotype[type]);
-      (void)fwrite(data + st, i - st + 1, 1, output);
       newl = (size && (data[size - 1] != '\n')) ? TRUE : FALSE;
       traced_data = FALSE;
       break;
@@ -141,11 +142,10 @@ int tool_debug_cb(CURL *handle, curl_infotype type,
            to stderr or stdout, we don't display the alert about the data not
            being shown as the data _is_ shown then just not via this
            function */
-        if(!config->isatty ||
-           ((output != stderr) && (output != stdout))) {
+        if(!config->isatty || ((output != stderr) && (output != stdout))) {
           if(!newl)
             fprintf(output, "%s%s ", timebuf, s_infotype[type]);
-          fprintf(output, "[data not shown]\n");
+          fprintf(output, "[%zd bytes data]\n", size);
           newl = FALSE;
           traced_data = TRUE;
         }