Commit 3f6133be authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

Jean-Philippe Barrette-LaPierre provided his patch that introduces

CURLOPT_DEBUGFUNCTION and CURLOPT_DEBUGDATA.
parent c3bfb355
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -101,6 +101,23 @@ typedef int (*curl_passwd_callback)(void *clientp,
                                    char *buffer,
                                    int buflen);

/* the kind of data that is passed to information_callback*/
typedef enum {
  CURLINFO_TEXT = 0,
  CURLINFO_HEADER_IN,    /* 1 */
  CURLINFO_HEADER_OUT,   /* 2 */
  CURLINFO_DATA_IN,      /* 3 */
  CURLINFO_DATA_OUT,     /* 4 */
  CURLINFO_END
} curl_infotype;

typedef int (*curl_debug_callback)
       (CURL *handle,      /* the handle/transfer this concerns */
        curl_infotype type, /* what kind of data */
        char *data,        /* points to the data */
        size_t size,       /* size of the data pointed to */
        void *userp);      /* whatever the user please */
  
/* All possible error codes from all sorts of curl functions. Future versions
   may return other values, stay prepared.

@@ -513,6 +530,12 @@ typedef enum {
  /* send linked-list of pre-transfer QUOTE commands (Wesley Laxton)*/
  CINIT(PREQUOTE, OBJECTPOINT, 93),

  /* set the debug function */
  CINIT(DEBUGFUNCTION, FUNCTIONPOINT, 94),

  /* set the data for the debug function */
  CINIT(DEBUGDATA, OBJECTPOINT, 95),
  
  CURLOPT_LASTENTRY /* the last unusued */
} CURLoption;

+7 −9
Original line number Diff line number Diff line
@@ -301,11 +301,8 @@ int Curl_GetFTPResponse(char *buf,
            CURLcode result;

            /* output debug output if that is requested */
            if(data->set.verbose) {
              fputs("< ", data->set.err);
              fwrite(line_start, perline, 1, data->set.err);
              /* no need to output LF here, it is part of the data */
            }
            if(data->set.verbose)
              Curl_debug(data, CURLINFO_HEADER_IN, line_start, perline);

            /*
             * We pass all response-lines to the callback function registered
@@ -2080,15 +2077,13 @@ CURLcode Curl_ftpsendf(struct connectdata *conn,
  ssize_t write_len;
  char *sptr=s;
  CURLcode res = CURLE_OK;
  size_t len;

  va_list ap;
  va_start(ap, fmt);
  vsnprintf(s, 250, fmt, ap);
  va_end(ap);
  
  if(conn->data->set.verbose)
    fprintf(conn->data->set.err, "> %s\n", s);

  strcat(s, "\r\n"); /* append a trailing CRLF */

  bytes_written=0;
@@ -2101,6 +2096,9 @@ CURLcode Curl_ftpsendf(struct connectdata *conn,
    if(CURLE_OK != res)
      break;

    if(conn->data->set.verbose)
      Curl_debug(conn->data, CURLINFO_HEADER_OUT, sptr, bytes_written);

    if(bytes_written != write_len) {
      write_len -= bytes_written;
      sptr += bytes_written;
+6 −11
Original line number Diff line number Diff line
@@ -133,12 +133,6 @@ CURLcode add_buffer_send(int sockfd, struct connectdata *conn, send_buffer *in,
  char *ptr;
  int size;

  if(conn->data->set.verbose) {
    fputs("> ", conn->data->set.err);
    /* this data _may_ contain binary stuff */
    fwrite(in->buffer, in->size_used, 1, conn->data->set.err);
  }

  /* The looping below is required since we use non-blocking sockets, but due
     to the circumstances we will just loop and try again and again etc */

@@ -150,6 +144,10 @@ CURLcode add_buffer_send(int sockfd, struct connectdata *conn, send_buffer *in,
    if(CURLE_OK != res)
      break;

    if(conn->data->set.verbose)
      /* this data _may_ contain binary stuff */
      Curl_debug(conn->data, CURLINFO_DATA_OUT, ptr, amount);

    if(amount != size) {
      size -= amount;
      ptr += amount;
@@ -364,11 +362,8 @@ CURLcode Curl_ConnectHTTPProxyTunnel(struct connectdata *conn,
               the line isn't really terminated until the LF comes */

            /* output debug output if that is requested */
            if(data->set.verbose) {
              fputs("< ", data->set.err);
              fwrite(line_start, perline, 1, data->set.err);
              /* no need to output LF here, it is part of the data */
            }
            if(data->set.verbose)
              Curl_debug(data, CURLINFO_DATA_IN, line_start, perline);
            
            if('\r' == line_start[0]) {
              /* end of headers */
+27 −5
Original line number Diff line number Diff line
@@ -135,10 +135,11 @@ void Curl_infof(struct SessionHandle *data, const char *fmt, ...)
{
  va_list ap;
  if(data->set.verbose) {
    char print_buffer[1024 + 1];
    va_start(ap, fmt);
    fputs("* ", data->set.err);
    vfprintf(data->set.err, fmt, ap);
    vsnprintf(print_buffer, 1024, fmt, ap);
    va_end(ap);
    Curl_debug(data, CURLINFO_TEXT, print_buffer, strlen(print_buffer));
  }
}

@@ -174,9 +175,6 @@ CURLcode Curl_sendf(int sockfd, struct connectdata *conn,
  if(!s)
    return CURLE_OUT_OF_MEMORY; /* failure */

  if(data->set.verbose)
    fprintf(data->set.err, "> %s", s);

  bytes_written=0;
  write_len = strlen(s);
  sptr = s;
@@ -188,6 +186,9 @@ CURLcode Curl_sendf(int sockfd, struct connectdata *conn,
    if(CURLE_OK != res)
      break;

    if(data->set.verbose)
      Curl_debug(data, CURLINFO_DATA_OUT, sptr, bytes_written);

    if(bytes_written != write_len) {
      /* if not all was written at once, we must advance the pointer, decrease
         the size left and try again! */
@@ -380,6 +381,27 @@ int Curl_read(struct connectdata *conn,
  return CURLE_OK;
}

/* return 0 on success */
int Curl_debug(struct SessionHandle *data, curl_infotype type,
               char *ptr, size_t size)
{
  static const char * const s_infotype[CURLINFO_END] = {
    "* ", "< ", "> ", "{ ", "} " };

  if(data->set.fdebug)
    return (*data->set.fdebug)(data, type, ptr, size,
                               data->set.debugdata);

  if(type >= CURLINFO_DATA_IN)
    /* don't do the data parts now */
    return 0;

  fwrite(s_infotype[type], 2, 1, data->set.err);
  fwrite(ptr, size, 1, data->set.err);

  return 0;
}


/*
 * local variables:
+5 −0
Original line number Diff line number Diff line
@@ -53,4 +53,9 @@ CURLcode Curl_write(struct connectdata *conn, int sockfd,
                    void *mem, size_t len,
                    ssize_t *written);

/* the function used to output verbose information */
int Curl_debug(struct SessionHandle *handle, curl_infotype type,
               char *data, size_t size);


#endif
Loading