getinfo.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2004, 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 http://curl.haxx.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. * $Id$
  22. ***************************************************************************/
  23. #include "setup.h"
  24. #include <curl/curl.h>
  25. #include "urldata.h"
  26. #include "getinfo.h"
  27. #include <stdio.h>
  28. #include <string.h>
  29. #include <stdarg.h>
  30. #ifdef VMS
  31. #include <stdlib.h>
  32. #endif
  33. /* Make this the last #include */
  34. #ifdef CURLDEBUG
  35. #include "memdebug.h"
  36. #else
  37. #include <stdlib.h>
  38. #endif
  39. /*
  40. * This is supposed to be called in the beginning of a permform() session
  41. * and should reset all session-info variables
  42. */
  43. CURLcode Curl_initinfo(struct SessionHandle *data)
  44. {
  45. struct Progress *pro = &data->progress;
  46. struct PureInfo *info =&data->info;
  47. pro->t_nslookup = 0;
  48. pro->t_connect = 0;
  49. pro->t_pretransfer = 0;
  50. pro->t_starttransfer = 0;
  51. pro->timespent = 0;
  52. pro->t_redirect = 0;
  53. info->httpcode = 0;
  54. info->httpversion=0;
  55. info->filetime=-1; /* -1 is an illegal time and thus means unknown */
  56. if (info->contenttype)
  57. free(info->contenttype);
  58. info->contenttype = NULL;
  59. info->header_size = 0;
  60. info->request_size = 0;
  61. return CURLE_OK;
  62. }
  63. CURLcode Curl_getinfo(struct SessionHandle *data, CURLINFO info, ...)
  64. {
  65. va_list arg;
  66. long *param_longp=NULL;
  67. double *param_doublep=NULL;
  68. char **param_charp=NULL;
  69. va_start(arg, info);
  70. switch(info&CURLINFO_TYPEMASK) {
  71. default:
  72. return CURLE_BAD_FUNCTION_ARGUMENT;
  73. case CURLINFO_STRING:
  74. param_charp = va_arg(arg, char **);
  75. if(NULL == param_charp)
  76. return CURLE_BAD_FUNCTION_ARGUMENT;
  77. break;
  78. case CURLINFO_LONG:
  79. param_longp = va_arg(arg, long *);
  80. if(NULL == param_longp)
  81. return CURLE_BAD_FUNCTION_ARGUMENT;
  82. break;
  83. case CURLINFO_DOUBLE:
  84. param_doublep = va_arg(arg, double *);
  85. if(NULL == param_doublep)
  86. return CURLE_BAD_FUNCTION_ARGUMENT;
  87. break;
  88. }
  89. switch(info) {
  90. case CURLINFO_EFFECTIVE_URL:
  91. *param_charp = data->change.url?data->change.url:(char *)"";
  92. break;
  93. case CURLINFO_RESPONSE_CODE:
  94. *param_longp = data->info.httpcode;
  95. break;
  96. case CURLINFO_HTTP_CONNECTCODE:
  97. *param_longp = data->info.httpproxycode;
  98. break;
  99. case CURLINFO_FILETIME:
  100. *param_longp = data->info.filetime;
  101. break;
  102. case CURLINFO_HEADER_SIZE:
  103. *param_longp = data->info.header_size;
  104. break;
  105. case CURLINFO_REQUEST_SIZE:
  106. *param_longp = data->info.request_size;
  107. break;
  108. case CURLINFO_TOTAL_TIME:
  109. *param_doublep = data->progress.timespent;
  110. break;
  111. case CURLINFO_NAMELOOKUP_TIME:
  112. *param_doublep = data->progress.t_nslookup;
  113. break;
  114. case CURLINFO_CONNECT_TIME:
  115. *param_doublep = data->progress.t_connect;
  116. break;
  117. case CURLINFO_PRETRANSFER_TIME:
  118. *param_doublep = data->progress.t_pretransfer;
  119. break;
  120. case CURLINFO_STARTTRANSFER_TIME:
  121. *param_doublep = data->progress.t_starttransfer;
  122. break;
  123. case CURLINFO_SIZE_UPLOAD:
  124. *param_doublep = (double)data->progress.uploaded;
  125. break;
  126. case CURLINFO_SIZE_DOWNLOAD:
  127. *param_doublep = (double)data->progress.downloaded;
  128. break;
  129. case CURLINFO_SPEED_DOWNLOAD:
  130. *param_doublep = (double)data->progress.dlspeed;
  131. break;
  132. case CURLINFO_SPEED_UPLOAD:
  133. *param_doublep = (double)data->progress.ulspeed;
  134. break;
  135. case CURLINFO_SSL_VERIFYRESULT:
  136. *param_longp = data->set.ssl.certverifyresult;
  137. break;
  138. case CURLINFO_CONTENT_LENGTH_DOWNLOAD:
  139. *param_doublep = (double)data->progress.size_dl;
  140. break;
  141. case CURLINFO_CONTENT_LENGTH_UPLOAD:
  142. *param_doublep = (double)data->progress.size_ul;
  143. break;
  144. case CURLINFO_REDIRECT_TIME:
  145. *param_doublep = data->progress.t_redirect;
  146. break;
  147. case CURLINFO_REDIRECT_COUNT:
  148. *param_longp = data->set.followlocation;
  149. break;
  150. case CURLINFO_CONTENT_TYPE:
  151. *param_charp = data->info.contenttype;
  152. break;
  153. case CURLINFO_PRIVATE:
  154. *param_charp = data->set.private;
  155. break;
  156. case CURLINFO_HTTPAUTH_AVAIL:
  157. *param_longp = data->info.httpauthavail;
  158. break;
  159. case CURLINFO_PROXYAUTH_AVAIL:
  160. *param_longp = data->info.proxyauthavail;
  161. break;
  162. default:
  163. return CURLE_BAD_FUNCTION_ARGUMENT;
  164. }
  165. return CURLE_OK;
  166. }