1
0

getinfo.c 4.9 KB

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