CURLOPT_DEBUGFUNCTION.3 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
  9. .\" *
  10. .\" * This software is licensed as described in the file COPYING, which
  11. .\" * you should have received as part of this distribution. The terms
  12. .\" * are also available at https://curl.se/docs/copyright.html.
  13. .\" *
  14. .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. .\" * copies of the Software, and permit persons to whom the Software is
  16. .\" * furnished to do so, under the terms of the COPYING file.
  17. .\" *
  18. .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. .\" * KIND, either express or implied.
  20. .\" *
  21. .\" **************************************************************************
  22. .\"
  23. .TH CURLOPT_DEBUGFUNCTION 3 "17 Jun 2014" "libcurl 7.37.0" "curl_easy_setopt options"
  24. .SH NAME
  25. CURLOPT_DEBUGFUNCTION \- debug callback
  26. .SH SYNOPSIS
  27. .nf
  28. #include <curl/curl.h>
  29. typedef enum {
  30. CURLINFO_TEXT = 0,
  31. CURLINFO_HEADER_IN, /* 1 */
  32. CURLINFO_HEADER_OUT, /* 2 */
  33. CURLINFO_DATA_IN, /* 3 */
  34. CURLINFO_DATA_OUT, /* 4 */
  35. CURLINFO_SSL_DATA_IN, /* 5 */
  36. CURLINFO_SSL_DATA_OUT, /* 6 */
  37. CURLINFO_END
  38. } curl_infotype;
  39. int debug_callback(CURL *handle,
  40. curl_infotype type,
  41. char *data,
  42. size_t size,
  43. void *userptr);
  44. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_DEBUGFUNCTION,
  45. debug_callback);
  46. .SH DESCRIPTION
  47. Pass a pointer to your callback function, which should match the prototype
  48. shown above.
  49. \fICURLOPT_DEBUGFUNCTION(3)\fP replaces the standard debug function used when
  50. \fICURLOPT_VERBOSE(3)\fP is in effect. This callback receives debug
  51. information, as specified in the \fItype\fP argument. This function must
  52. return 0. The \fIdata\fP pointed to by the char * passed to this function WILL
  53. NOT be null-terminated, but will be exactly of the \fIsize\fP as told by the
  54. \fIsize\fP argument.
  55. The \fIuserptr\fP argument is the pointer set with \fICURLOPT_DEBUGDATA(3)\fP.
  56. Available curl_infotype values:
  57. .IP CURLINFO_TEXT
  58. The data is informational text.
  59. .IP CURLINFO_HEADER_IN
  60. The data is header (or header-like) data received from the peer.
  61. .IP CURLINFO_HEADER_OUT
  62. The data is header (or header-like) data sent to the peer.
  63. .IP CURLINFO_DATA_IN
  64. The data is protocol data received from the peer.
  65. .IP CURLINFO_DATA_OUT
  66. The data is protocol data sent to the peer.
  67. .IP CURLINFO_SSL_DATA_OUT
  68. The data is SSL/TLS (binary) data sent to the peer.
  69. .IP CURLINFO_SSL_DATA_IN
  70. The data is SSL/TLS (binary) data received from the peer.
  71. .SH DEFAULT
  72. NULL
  73. .SH PROTOCOLS
  74. All
  75. .SH EXAMPLE
  76. .nf
  77. static
  78. void dump(const char *text,
  79. FILE *stream, unsigned char *ptr, size_t size)
  80. {
  81. size_t i;
  82. size_t c;
  83. unsigned int width=0x10;
  84. fprintf(stream, "%s, %10.10ld bytes (0x%8.8lx)\\n",
  85. text, (long)size, (long)size);
  86. for(i=0; i<size; i+= width) {
  87. fprintf(stream, "%4.4lx: ", (long)i);
  88. /* show hex to the left */
  89. for(c = 0; c < width; c++) {
  90. if(i+c < size)
  91. fprintf(stream, "%02x ", ptr[i+c]);
  92. else
  93. fputs(" ", stream);
  94. }
  95. /* show data on the right */
  96. for(c = 0; (c < width) && (i+c < size); c++) {
  97. char x = (ptr[i+c] >= 0x20 && ptr[i+c] < 0x80) ? ptr[i+c] : '.';
  98. fputc(x, stream);
  99. }
  100. fputc('\\n', stream); /* newline */
  101. }
  102. }
  103. static
  104. int my_trace(CURL *handle, curl_infotype type,
  105. char *data, size_t size,
  106. void *userp)
  107. {
  108. const char *text;
  109. (void)handle; /* prevent compiler warning */
  110. (void)userp;
  111. switch (type) {
  112. case CURLINFO_TEXT:
  113. fprintf(stderr, "== Info: %s", data);
  114. default: /* in case a new one is introduced to shock us */
  115. return 0;
  116. case CURLINFO_HEADER_OUT:
  117. text = "=> Send header";
  118. break;
  119. case CURLINFO_DATA_OUT:
  120. text = "=> Send data";
  121. break;
  122. case CURLINFO_SSL_DATA_OUT:
  123. text = "=> Send SSL data";
  124. break;
  125. case CURLINFO_HEADER_IN:
  126. text = "<= Recv header";
  127. break;
  128. case CURLINFO_DATA_IN:
  129. text = "<= Recv data";
  130. break;
  131. case CURLINFO_SSL_DATA_IN:
  132. text = "<= Recv SSL data";
  133. break;
  134. }
  135. dump(text, stderr, (unsigned char *)data, size);
  136. return 0;
  137. }
  138. int main(void)
  139. {
  140. CURL *curl;
  141. CURLcode res;
  142. curl = curl_easy_init();
  143. if(curl) {
  144. curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
  145. /* the DEBUGFUNCTION has no effect until we enable VERBOSE */
  146. curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
  147. /* example.com is redirected, so we tell libcurl to follow redirection */
  148. curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
  149. curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
  150. res = curl_easy_perform(curl);
  151. /* Check for errors */
  152. if(res != CURLE_OK)
  153. fprintf(stderr, "curl_easy_perform() failed: %s\\n",
  154. curl_easy_strerror(res));
  155. /* always cleanup */
  156. curl_easy_cleanup(curl);
  157. }
  158. return 0;
  159. }
  160. .fi
  161. .SH AVAILABILITY
  162. Always
  163. .SH RETURN VALUE
  164. Returns CURLE_OK
  165. .SH "SEE ALSO"
  166. .BR CURLOPT_VERBOSE "(3), " CURLOPT_DEBUGDATA "(3), "