cURL / Mailing Lists / curl-library / Single Mail

curl-library

RE: curl_debug_callback

From: Jeff Pohlmeyer <yetanothergeek_at_yahoo.com>
Date: Mon, 2 Jun 2003 07:07:19 -0700 (PDT)

The one thing I always seem to forget is that you must set
CURLOPT_VERBOSE to TRUE in order for the debug function to be called...

Here is a (very crude) example.

#include <stdio.h>
#include <curl/curl.h>

size_t write_cb(char *buffer, size_t size, size_t nitems, void *outstream) {
  return ( size * nitems);
}

int debug_cb ( CURL *handle, curl_infotype type,
               char *data, size_t size, void *userp) {
  switch ( type ) {
    case CURLINFO_TEXT: {
      printf("INFO: %s\n", data);
      break;
    }
    case CURLINFO_HEADER_IN: {
      printf("RESPONSE: %s", data);
      break;
    }
    case CURLINFO_HEADER_OUT: { /* There is no null-terminator on this one ! */
      size_t i;
      printf("REQUEST: \n");
      for ( i = 0; i < size; i ++) printf("%c", data[i]);
      break;
    }
    case CURLINFO_DATA_IN: {
      printf("RECIEVED: %d bytes\n", size);
      break;
    }
    case CURLINFO_DATA_OUT: {
       printf("TRANSMIT: %d bytes\n", size);
       break;
    }
    case CURLINFO_END: {
       printf("This should never happen!");
       break;
    }
  }
}

int main ( int argc, char ** argv ){
  CURL *curl;
  CURLcode code;
  curl = curl_easy_init();
  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); /* <- Don't forget this !!! */
  curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, debug_cb);
  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb);
  curl_easy_setopt(curl, CURLOPT_URL, "curl.haxx.se");
  code = curl_easy_perform(curl);
  curl_easy_cleanup(curl);
  return( code );
}

__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com

-------------------------------------------------------
This SF.net email is sponsored by: eBay
Get office equipment for less on eBay!
http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5
Received on 2003-06-02