PageRenderTime 51ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/jni/curl/lib/getinfo.c

https://github.com/LeifAndersen/Android-Supertux
C | 273 lines | 213 code | 19 blank | 41 comment | 10 complexity | 3970b34b072dfa960acd9fc6e6f152b5 MD5 | raw file
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2010, 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. ***************************************************************************/
  22. #include "setup.h"
  23. #include <curl/curl.h>
  24. #include "urldata.h"
  25. #include "getinfo.h"
  26. #include <stdio.h>
  27. #include <string.h>
  28. #include <stdarg.h>
  29. #include <stdlib.h>
  30. #include "curl_memory.h"
  31. #include "sslgen.h"
  32. #include "connect.h" /* Curl_getconnectinfo() */
  33. #include "progress.h"
  34. /* Make this the last #include */
  35. #include "memdebug.h"
  36. /*
  37. * This is supposed to be called in the beginning of a perform() session
  38. * and should reset all session-info variables
  39. */
  40. CURLcode Curl_initinfo(struct SessionHandle *data)
  41. {
  42. struct Progress *pro = &data->progress;
  43. struct PureInfo *info =&data->info;
  44. pro->t_nslookup = 0;
  45. pro->t_connect = 0;
  46. pro->t_pretransfer = 0;
  47. pro->t_starttransfer = 0;
  48. pro->timespent = 0;
  49. pro->t_redirect = 0;
  50. info->httpcode = 0;
  51. info->httpversion=0;
  52. info->filetime=-1; /* -1 is an illegal time and thus means unknown */
  53. if(info->contenttype)
  54. free(info->contenttype);
  55. info->contenttype = NULL;
  56. info->header_size = 0;
  57. info->request_size = 0;
  58. info->numconnects = 0;
  59. info->ip[0] = 0;
  60. info->port = 0;
  61. info->localip[0] = 0;
  62. info->localport = 0;
  63. return CURLE_OK;
  64. }
  65. CURLcode Curl_getinfo(struct SessionHandle *data, CURLINFO info, ...)
  66. {
  67. va_list arg;
  68. long *param_longp=NULL;
  69. double *param_doublep=NULL;
  70. char **param_charp=NULL;
  71. struct curl_slist **param_slistp=NULL;
  72. int type;
  73. union {
  74. struct curl_certinfo * to_certinfo;
  75. struct curl_slist * to_slist;
  76. } ptr;
  77. if(!data)
  78. return CURLE_BAD_FUNCTION_ARGUMENT;
  79. va_start(arg, info);
  80. type = CURLINFO_TYPEMASK & (int)info;
  81. switch(type) {
  82. case CURLINFO_STRING:
  83. param_charp = va_arg(arg, char **);
  84. if(NULL == param_charp)
  85. return CURLE_BAD_FUNCTION_ARGUMENT;
  86. break;
  87. case CURLINFO_LONG:
  88. param_longp = va_arg(arg, long *);
  89. if(NULL == param_longp)
  90. return CURLE_BAD_FUNCTION_ARGUMENT;
  91. break;
  92. case CURLINFO_DOUBLE:
  93. param_doublep = va_arg(arg, double *);
  94. if(NULL == param_doublep)
  95. return CURLE_BAD_FUNCTION_ARGUMENT;
  96. break;
  97. case CURLINFO_SLIST:
  98. param_slistp = va_arg(arg, struct curl_slist **);
  99. if(NULL == param_slistp)
  100. return CURLE_BAD_FUNCTION_ARGUMENT;
  101. break;
  102. default:
  103. return CURLE_BAD_FUNCTION_ARGUMENT;
  104. }
  105. switch(info) {
  106. case CURLINFO_EFFECTIVE_URL:
  107. *param_charp = data->change.url?data->change.url:(char *)"";
  108. break;
  109. case CURLINFO_RESPONSE_CODE:
  110. *param_longp = data->info.httpcode;
  111. break;
  112. case CURLINFO_HTTP_CONNECTCODE:
  113. *param_longp = data->info.httpproxycode;
  114. break;
  115. case CURLINFO_FILETIME:
  116. *param_longp = data->info.filetime;
  117. break;
  118. case CURLINFO_HEADER_SIZE:
  119. *param_longp = data->info.header_size;
  120. break;
  121. case CURLINFO_REQUEST_SIZE:
  122. *param_longp = data->info.request_size;
  123. break;
  124. case CURLINFO_TOTAL_TIME:
  125. *param_doublep = data->progress.timespent;
  126. break;
  127. case CURLINFO_NAMELOOKUP_TIME:
  128. *param_doublep = data->progress.t_nslookup;
  129. break;
  130. case CURLINFO_CONNECT_TIME:
  131. *param_doublep = data->progress.t_connect;
  132. break;
  133. case CURLINFO_APPCONNECT_TIME:
  134. *param_doublep = data->progress.t_appconnect;
  135. break;
  136. case CURLINFO_PRETRANSFER_TIME:
  137. *param_doublep = data->progress.t_pretransfer;
  138. break;
  139. case CURLINFO_STARTTRANSFER_TIME:
  140. *param_doublep = data->progress.t_starttransfer;
  141. break;
  142. case CURLINFO_SIZE_UPLOAD:
  143. *param_doublep = (double)data->progress.uploaded;
  144. break;
  145. case CURLINFO_SIZE_DOWNLOAD:
  146. *param_doublep = (double)data->progress.downloaded;
  147. break;
  148. case CURLINFO_SPEED_DOWNLOAD:
  149. *param_doublep = (double)data->progress.dlspeed;
  150. break;
  151. case CURLINFO_SPEED_UPLOAD:
  152. *param_doublep = (double)data->progress.ulspeed;
  153. break;
  154. case CURLINFO_SSL_VERIFYRESULT:
  155. *param_longp = data->set.ssl.certverifyresult;
  156. break;
  157. case CURLINFO_CONTENT_LENGTH_DOWNLOAD:
  158. *param_doublep = (data->progress.flags & PGRS_DL_SIZE_KNOWN)?
  159. (double)data->progress.size_dl:-1;
  160. break;
  161. case CURLINFO_CONTENT_LENGTH_UPLOAD:
  162. *param_doublep = (data->progress.flags & PGRS_UL_SIZE_KNOWN)?
  163. (double)data->progress.size_ul:-1;
  164. break;
  165. case CURLINFO_REDIRECT_TIME:
  166. *param_doublep = data->progress.t_redirect;
  167. break;
  168. case CURLINFO_REDIRECT_COUNT:
  169. *param_longp = data->set.followlocation;
  170. break;
  171. case CURLINFO_CONTENT_TYPE:
  172. *param_charp = data->info.contenttype;
  173. break;
  174. case CURLINFO_PRIVATE:
  175. *param_charp = (char *) data->set.private_data;
  176. break;
  177. case CURLINFO_HTTPAUTH_AVAIL:
  178. *param_longp = data->info.httpauthavail;
  179. break;
  180. case CURLINFO_PROXYAUTH_AVAIL:
  181. *param_longp = data->info.proxyauthavail;
  182. break;
  183. case CURLINFO_OS_ERRNO:
  184. *param_longp = data->state.os_errno;
  185. break;
  186. case CURLINFO_NUM_CONNECTS:
  187. *param_longp = data->info.numconnects;
  188. break;
  189. case CURLINFO_SSL_ENGINES:
  190. *param_slistp = Curl_ssl_engines_list(data);
  191. break;
  192. case CURLINFO_COOKIELIST:
  193. *param_slistp = Curl_cookie_list(data);
  194. break;
  195. case CURLINFO_FTP_ENTRY_PATH:
  196. /* Return the entrypath string from the most recent connection.
  197. This pointer was copied from the connectdata structure by FTP.
  198. The actual string may be free()ed by subsequent libcurl calls so
  199. it must be copied to a safer area before the next libcurl call.
  200. Callers must never free it themselves. */
  201. *param_charp = data->state.most_recent_ftp_entrypath;
  202. break;
  203. case CURLINFO_LASTSOCKET:
  204. (void)Curl_getconnectinfo(data, param_longp, NULL);
  205. break;
  206. case CURLINFO_REDIRECT_URL:
  207. /* Return the URL this request would have been redirected to if that
  208. option had been enabled! */
  209. *param_charp = data->info.wouldredirect;
  210. break;
  211. case CURLINFO_PRIMARY_IP:
  212. /* Return the ip address of the most recent (primary) connection */
  213. *param_charp = data->info.ip;
  214. break;
  215. case CURLINFO_PRIMARY_PORT:
  216. /* Return the (remote) port of the most recent (primary) connection */
  217. *param_longp = data->info.port;
  218. break;
  219. case CURLINFO_LOCAL_IP:
  220. /* Return the source/local ip address of the most recent (primary)
  221. connection */
  222. *param_charp = data->info.localip;
  223. break;
  224. case CURLINFO_LOCAL_PORT:
  225. /* Return the local port of the most recent (primary) connection */
  226. *param_longp = data->info.localport;
  227. break;
  228. case CURLINFO_CERTINFO:
  229. /* Return the a pointer to the certinfo struct. Not really an slist
  230. pointer but we can pretend it is here */
  231. ptr.to_certinfo = &data->info.certs;
  232. *param_slistp = ptr.to_slist;
  233. break;
  234. case CURLINFO_CONDITION_UNMET:
  235. /* return if the condition prevented the document to get transfered */
  236. *param_longp = data->info.timecond;
  237. break;
  238. case CURLINFO_RTSP_SESSION_ID:
  239. *param_charp = data->set.str[STRING_RTSP_SESSION_ID];
  240. break;
  241. case CURLINFO_RTSP_CLIENT_CSEQ:
  242. *param_longp = data->state.rtsp_next_client_CSeq;
  243. break;
  244. case CURLINFO_RTSP_SERVER_CSEQ:
  245. *param_longp = data->state.rtsp_next_server_CSeq;
  246. break;
  247. case CURLINFO_RTSP_CSEQ_RECV:
  248. *param_longp = data->state.rtsp_CSeq_recv;
  249. break;
  250. default:
  251. return CURLE_BAD_FUNCTION_ARGUMENT;
  252. }
  253. return CURLE_OK;
  254. }