getinfo.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 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 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. * SPDX-License-Identifier: curl
  22. *
  23. ***************************************************************************/
  24. #include "curl_setup.h"
  25. #include <curl/curl.h>
  26. #include "urldata.h"
  27. #include "getinfo.h"
  28. #include "cfilters.h"
  29. #include "vtls/vtls.h"
  30. #include "connect.h" /* Curl_getconnectinfo() */
  31. #include "progress.h"
  32. #include "curlx/strparse.h"
  33. /* The last #include files should be: */
  34. #include "curl_memory.h"
  35. #include "memdebug.h"
  36. /*
  37. * Initialize statistical and informational data.
  38. *
  39. * This function is called in curl_easy_reset, curl_easy_duphandle and at the
  40. * beginning of a perform session. It must reset the session-info variables,
  41. * in particular all variables in struct PureInfo.
  42. */
  43. CURLcode Curl_initinfo(struct Curl_easy *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_appconnect = 0;
  50. pro->t_pretransfer = 0;
  51. pro->t_posttransfer = 0;
  52. pro->t_starttransfer = 0;
  53. pro->timespent = 0;
  54. pro->t_redirect = 0;
  55. pro->is_t_startransfer_set = FALSE;
  56. info->httpcode = 0;
  57. info->httpproxycode = 0;
  58. info->httpversion = 0;
  59. info->filetime = -1; /* -1 is an illegal time and thus means unknown */
  60. info->timecond = FALSE;
  61. info->header_size = 0;
  62. info->request_size = 0;
  63. info->proxyauthavail = 0;
  64. info->httpauthavail = 0;
  65. info->proxyauthpicked = 0;
  66. info->httpauthpicked = 0;
  67. info->numconnects = 0;
  68. free(info->contenttype);
  69. info->contenttype = NULL;
  70. free(info->wouldredirect);
  71. info->wouldredirect = NULL;
  72. memset(&info->primary, 0, sizeof(info->primary));
  73. info->primary.remote_port = -1;
  74. info->primary.local_port = -1;
  75. info->retry_after = 0;
  76. info->conn_scheme = 0;
  77. info->conn_protocol = 0;
  78. #ifdef USE_SSL
  79. Curl_ssl_free_certinfo(data);
  80. #endif
  81. return CURLE_OK;
  82. }
  83. static CURLcode getinfo_char(struct Curl_easy *data, CURLINFO info,
  84. const char **param_charp)
  85. {
  86. switch(info) {
  87. case CURLINFO_EFFECTIVE_URL:
  88. *param_charp = data->state.url ? data->state.url : "";
  89. break;
  90. case CURLINFO_EFFECTIVE_METHOD: {
  91. const char *m = data->set.str[STRING_CUSTOMREQUEST];
  92. if(!m) {
  93. if(data->set.opt_no_body)
  94. m = "HEAD";
  95. #ifndef CURL_DISABLE_HTTP
  96. else {
  97. switch(data->state.httpreq) {
  98. case HTTPREQ_POST:
  99. case HTTPREQ_POST_FORM:
  100. case HTTPREQ_POST_MIME:
  101. m = "POST";
  102. break;
  103. case HTTPREQ_PUT:
  104. m = "PUT";
  105. break;
  106. default: /* this should never happen */
  107. case HTTPREQ_GET:
  108. m = "GET";
  109. break;
  110. case HTTPREQ_HEAD:
  111. m = "HEAD";
  112. break;
  113. }
  114. }
  115. #endif
  116. }
  117. *param_charp = m;
  118. }
  119. break;
  120. case CURLINFO_CONTENT_TYPE:
  121. *param_charp = data->info.contenttype;
  122. break;
  123. case CURLINFO_PRIVATE:
  124. *param_charp = (char *) data->set.private_data;
  125. break;
  126. case CURLINFO_FTP_ENTRY_PATH:
  127. /* Return the entrypath string from the most recent connection.
  128. This pointer was copied from the connectdata structure by FTP.
  129. The actual string may be free()ed by subsequent libcurl calls so
  130. it must be copied to a safer area before the next libcurl call.
  131. Callers must never free it themselves. */
  132. *param_charp = data->state.most_recent_ftp_entrypath;
  133. break;
  134. case CURLINFO_REDIRECT_URL:
  135. /* Return the URL this request would have been redirected to if that
  136. option had been enabled! */
  137. *param_charp = data->info.wouldredirect;
  138. break;
  139. case CURLINFO_REFERER:
  140. /* Return the referrer header for this request, or NULL if unset */
  141. *param_charp = data->state.referer;
  142. break;
  143. case CURLINFO_PRIMARY_IP:
  144. /* Return the ip address of the most recent (primary) connection */
  145. *param_charp = data->info.primary.remote_ip;
  146. break;
  147. case CURLINFO_LOCAL_IP:
  148. /* Return the source/local ip address of the most recent (primary)
  149. connection */
  150. *param_charp = data->info.primary.local_ip;
  151. break;
  152. case CURLINFO_RTSP_SESSION_ID:
  153. #ifndef CURL_DISABLE_RTSP
  154. *param_charp = data->set.str[STRING_RTSP_SESSION_ID];
  155. #else
  156. *param_charp = NULL;
  157. #endif
  158. break;
  159. case CURLINFO_SCHEME:
  160. *param_charp = data->info.conn_scheme;
  161. break;
  162. case CURLINFO_CAPATH:
  163. #ifdef CURL_CA_PATH
  164. *param_charp = CURL_CA_PATH;
  165. #else
  166. *param_charp = NULL;
  167. #endif
  168. break;
  169. case CURLINFO_CAINFO:
  170. #ifdef CURL_CA_BUNDLE
  171. *param_charp = CURL_CA_BUNDLE;
  172. #else
  173. *param_charp = NULL;
  174. #endif
  175. break;
  176. default:
  177. return CURLE_UNKNOWN_OPTION;
  178. }
  179. return CURLE_OK;
  180. }
  181. static CURLcode getinfo_long(struct Curl_easy *data, CURLINFO info,
  182. long *param_longp)
  183. {
  184. curl_socket_t sockfd;
  185. union {
  186. unsigned long *to_ulong;
  187. long *to_long;
  188. } lptr;
  189. #ifdef DEBUGBUILD
  190. const char *timestr = getenv("CURL_TIME");
  191. if(timestr) {
  192. curl_off_t val;
  193. curlx_str_number(&timestr, &val, TIME_T_MAX);
  194. switch(info) {
  195. case CURLINFO_LOCAL_PORT:
  196. *param_longp = (long)val;
  197. return CURLE_OK;
  198. default:
  199. break;
  200. }
  201. }
  202. /* use another variable for this to allow different values */
  203. timestr = getenv("CURL_DEBUG_SIZE");
  204. if(timestr) {
  205. curl_off_t val;
  206. curlx_str_number(&timestr, &val, LONG_MAX);
  207. switch(info) {
  208. case CURLINFO_HEADER_SIZE:
  209. case CURLINFO_REQUEST_SIZE:
  210. *param_longp = (long)val;
  211. return CURLE_OK;
  212. default:
  213. break;
  214. }
  215. }
  216. #endif
  217. switch(info) {
  218. case CURLINFO_RESPONSE_CODE:
  219. *param_longp = data->info.httpcode;
  220. break;
  221. case CURLINFO_HTTP_CONNECTCODE:
  222. *param_longp = data->info.httpproxycode;
  223. break;
  224. case CURLINFO_FILETIME:
  225. if(data->info.filetime > LONG_MAX)
  226. *param_longp = LONG_MAX;
  227. #if !defined(MSDOS) && !defined(__AMIGA__)
  228. else if(data->info.filetime < LONG_MIN)
  229. *param_longp = LONG_MIN;
  230. #endif
  231. else
  232. *param_longp = (long)data->info.filetime;
  233. break;
  234. case CURLINFO_HEADER_SIZE:
  235. *param_longp = (long)data->info.header_size;
  236. break;
  237. case CURLINFO_REQUEST_SIZE:
  238. *param_longp = (long)data->info.request_size;
  239. break;
  240. case CURLINFO_SSL_VERIFYRESULT:
  241. *param_longp = data->set.ssl.certverifyresult;
  242. break;
  243. case CURLINFO_PROXY_SSL_VERIFYRESULT:
  244. #ifndef CURL_DISABLE_PROXY
  245. *param_longp = data->set.proxy_ssl.certverifyresult;
  246. #else
  247. *param_longp = 0;
  248. #endif
  249. break;
  250. case CURLINFO_REDIRECT_COUNT:
  251. *param_longp = data->state.followlocation;
  252. break;
  253. case CURLINFO_HTTPAUTH_AVAIL:
  254. lptr.to_long = param_longp;
  255. *lptr.to_ulong = data->info.httpauthavail;
  256. break;
  257. case CURLINFO_PROXYAUTH_AVAIL:
  258. lptr.to_long = param_longp;
  259. *lptr.to_ulong = data->info.proxyauthavail;
  260. break;
  261. case CURLINFO_HTTPAUTH_USED:
  262. lptr.to_long = param_longp;
  263. *lptr.to_ulong = data->info.httpauthpicked;
  264. break;
  265. case CURLINFO_PROXYAUTH_USED:
  266. lptr.to_long = param_longp;
  267. *lptr.to_ulong = data->info.proxyauthpicked;
  268. break;
  269. case CURLINFO_OS_ERRNO:
  270. *param_longp = data->state.os_errno;
  271. break;
  272. case CURLINFO_NUM_CONNECTS:
  273. *param_longp = data->info.numconnects;
  274. break;
  275. case CURLINFO_LASTSOCKET:
  276. sockfd = Curl_getconnectinfo(data, NULL);
  277. /* note: this is not a good conversion for systems with 64-bit sockets and
  278. 32-bit longs */
  279. if(sockfd != CURL_SOCKET_BAD)
  280. *param_longp = (long)sockfd;
  281. else
  282. /* this interface is documented to return -1 in case of badness, which
  283. may not be the same as the CURL_SOCKET_BAD value */
  284. *param_longp = -1;
  285. break;
  286. case CURLINFO_PRIMARY_PORT:
  287. /* Return the (remote) port of the most recent (primary) connection */
  288. *param_longp = data->info.primary.remote_port;
  289. break;
  290. case CURLINFO_LOCAL_PORT:
  291. /* Return the local port of the most recent (primary) connection */
  292. *param_longp = data->info.primary.local_port;
  293. break;
  294. case CURLINFO_PROXY_ERROR:
  295. *param_longp = (long)data->info.pxcode;
  296. break;
  297. case CURLINFO_CONDITION_UNMET:
  298. if(data->info.httpcode == 304)
  299. *param_longp = 1L;
  300. else
  301. /* return if the condition prevented the document to get transferred */
  302. *param_longp = data->info.timecond ? 1L : 0L;
  303. break;
  304. #ifndef CURL_DISABLE_RTSP
  305. case CURLINFO_RTSP_CLIENT_CSEQ:
  306. *param_longp = data->state.rtsp_next_client_CSeq;
  307. break;
  308. case CURLINFO_RTSP_SERVER_CSEQ:
  309. *param_longp = data->state.rtsp_next_server_CSeq;
  310. break;
  311. case CURLINFO_RTSP_CSEQ_RECV:
  312. *param_longp = data->state.rtsp_CSeq_recv;
  313. break;
  314. #else
  315. case CURLINFO_RTSP_CLIENT_CSEQ:
  316. case CURLINFO_RTSP_SERVER_CSEQ:
  317. case CURLINFO_RTSP_CSEQ_RECV:
  318. *param_longp = 0;
  319. break;
  320. #endif
  321. case CURLINFO_HTTP_VERSION:
  322. switch(data->info.httpversion) {
  323. case 10:
  324. *param_longp = CURL_HTTP_VERSION_1_0;
  325. break;
  326. case 11:
  327. *param_longp = CURL_HTTP_VERSION_1_1;
  328. break;
  329. case 20:
  330. *param_longp = CURL_HTTP_VERSION_2_0;
  331. break;
  332. case 30:
  333. *param_longp = CURL_HTTP_VERSION_3;
  334. break;
  335. default:
  336. *param_longp = CURL_HTTP_VERSION_NONE;
  337. break;
  338. }
  339. break;
  340. case CURLINFO_PROTOCOL:
  341. *param_longp = (long)data->info.conn_protocol;
  342. break;
  343. case CURLINFO_USED_PROXY:
  344. *param_longp =
  345. #ifdef CURL_DISABLE_PROXY
  346. 0
  347. #else
  348. data->info.used_proxy
  349. #endif
  350. ;
  351. break;
  352. default:
  353. return CURLE_UNKNOWN_OPTION;
  354. }
  355. return CURLE_OK;
  356. }
  357. #define DOUBLE_SECS(x) (double)(x)/1000000
  358. static CURLcode getinfo_offt(struct Curl_easy *data, CURLINFO info,
  359. curl_off_t *param_offt)
  360. {
  361. #ifdef DEBUGBUILD
  362. const char *timestr = getenv("CURL_TIME");
  363. if(timestr) {
  364. curl_off_t val;
  365. curlx_str_number(&timestr, &val, CURL_OFF_T_MAX);
  366. switch(info) {
  367. case CURLINFO_TOTAL_TIME_T:
  368. case CURLINFO_NAMELOOKUP_TIME_T:
  369. case CURLINFO_CONNECT_TIME_T:
  370. case CURLINFO_APPCONNECT_TIME_T:
  371. case CURLINFO_PRETRANSFER_TIME_T:
  372. case CURLINFO_POSTTRANSFER_TIME_T:
  373. case CURLINFO_QUEUE_TIME_T:
  374. case CURLINFO_STARTTRANSFER_TIME_T:
  375. case CURLINFO_REDIRECT_TIME_T:
  376. case CURLINFO_SPEED_DOWNLOAD_T:
  377. case CURLINFO_SPEED_UPLOAD_T:
  378. *param_offt = (curl_off_t)val;
  379. return CURLE_OK;
  380. default:
  381. break;
  382. }
  383. }
  384. #endif
  385. switch(info) {
  386. case CURLINFO_FILETIME_T:
  387. *param_offt = (curl_off_t)data->info.filetime;
  388. break;
  389. case CURLINFO_SIZE_UPLOAD_T:
  390. *param_offt = data->progress.ul.cur_size;
  391. break;
  392. case CURLINFO_SIZE_DOWNLOAD_T:
  393. *param_offt = data->progress.dl.cur_size;
  394. break;
  395. case CURLINFO_SPEED_DOWNLOAD_T:
  396. *param_offt = data->progress.dl.speed;
  397. break;
  398. case CURLINFO_SPEED_UPLOAD_T:
  399. *param_offt = data->progress.ul.speed;
  400. break;
  401. case CURLINFO_CONTENT_LENGTH_DOWNLOAD_T:
  402. *param_offt = data->progress.dl_size_known ?
  403. data->progress.dl.total_size : -1;
  404. break;
  405. case CURLINFO_CONTENT_LENGTH_UPLOAD_T:
  406. *param_offt = data->progress.ul_size_known ?
  407. data->progress.ul.total_size : -1;
  408. break;
  409. case CURLINFO_TOTAL_TIME_T:
  410. *param_offt = data->progress.timespent;
  411. break;
  412. case CURLINFO_NAMELOOKUP_TIME_T:
  413. *param_offt = data->progress.t_nslookup;
  414. break;
  415. case CURLINFO_CONNECT_TIME_T:
  416. *param_offt = data->progress.t_connect;
  417. break;
  418. case CURLINFO_APPCONNECT_TIME_T:
  419. *param_offt = data->progress.t_appconnect;
  420. break;
  421. case CURLINFO_PRETRANSFER_TIME_T:
  422. *param_offt = data->progress.t_pretransfer;
  423. break;
  424. case CURLINFO_POSTTRANSFER_TIME_T:
  425. *param_offt = data->progress.t_posttransfer;
  426. break;
  427. case CURLINFO_STARTTRANSFER_TIME_T:
  428. *param_offt = data->progress.t_starttransfer;
  429. break;
  430. case CURLINFO_QUEUE_TIME_T:
  431. *param_offt = data->progress.t_postqueue;
  432. break;
  433. case CURLINFO_REDIRECT_TIME_T:
  434. *param_offt = data->progress.t_redirect;
  435. break;
  436. case CURLINFO_RETRY_AFTER:
  437. *param_offt = data->info.retry_after;
  438. break;
  439. case CURLINFO_XFER_ID:
  440. *param_offt = data->id;
  441. break;
  442. case CURLINFO_CONN_ID:
  443. *param_offt = data->conn ?
  444. data->conn->connection_id : data->state.recent_conn_id;
  445. break;
  446. case CURLINFO_EARLYDATA_SENT_T:
  447. *param_offt = data->progress.earlydata_sent;
  448. break;
  449. default:
  450. return CURLE_UNKNOWN_OPTION;
  451. }
  452. return CURLE_OK;
  453. }
  454. static CURLcode getinfo_double(struct Curl_easy *data, CURLINFO info,
  455. double *param_doublep)
  456. {
  457. #ifdef DEBUGBUILD
  458. const char *timestr = getenv("CURL_TIME");
  459. if(timestr) {
  460. curl_off_t val;
  461. curlx_str_number(&timestr, &val, CURL_OFF_T_MAX);
  462. switch(info) {
  463. case CURLINFO_TOTAL_TIME:
  464. case CURLINFO_NAMELOOKUP_TIME:
  465. case CURLINFO_CONNECT_TIME:
  466. case CURLINFO_APPCONNECT_TIME:
  467. case CURLINFO_PRETRANSFER_TIME:
  468. case CURLINFO_STARTTRANSFER_TIME:
  469. case CURLINFO_REDIRECT_TIME:
  470. case CURLINFO_SPEED_DOWNLOAD:
  471. case CURLINFO_SPEED_UPLOAD:
  472. *param_doublep = (double)val;
  473. return CURLE_OK;
  474. default:
  475. break;
  476. }
  477. }
  478. #endif
  479. switch(info) {
  480. case CURLINFO_TOTAL_TIME:
  481. *param_doublep = DOUBLE_SECS(data->progress.timespent);
  482. break;
  483. case CURLINFO_NAMELOOKUP_TIME:
  484. *param_doublep = DOUBLE_SECS(data->progress.t_nslookup);
  485. break;
  486. case CURLINFO_CONNECT_TIME:
  487. *param_doublep = DOUBLE_SECS(data->progress.t_connect);
  488. break;
  489. case CURLINFO_APPCONNECT_TIME:
  490. *param_doublep = DOUBLE_SECS(data->progress.t_appconnect);
  491. break;
  492. case CURLINFO_PRETRANSFER_TIME:
  493. *param_doublep = DOUBLE_SECS(data->progress.t_pretransfer);
  494. break;
  495. case CURLINFO_STARTTRANSFER_TIME:
  496. *param_doublep = DOUBLE_SECS(data->progress.t_starttransfer);
  497. break;
  498. case CURLINFO_SIZE_UPLOAD:
  499. *param_doublep = (double)data->progress.ul.cur_size;
  500. break;
  501. case CURLINFO_SIZE_DOWNLOAD:
  502. *param_doublep = (double)data->progress.dl.cur_size;
  503. break;
  504. case CURLINFO_SPEED_DOWNLOAD:
  505. *param_doublep = (double)data->progress.dl.speed;
  506. break;
  507. case CURLINFO_SPEED_UPLOAD:
  508. *param_doublep = (double)data->progress.ul.speed;
  509. break;
  510. case CURLINFO_CONTENT_LENGTH_DOWNLOAD:
  511. *param_doublep = data->progress.dl_size_known ?
  512. (double)data->progress.dl.total_size : -1;
  513. break;
  514. case CURLINFO_CONTENT_LENGTH_UPLOAD:
  515. *param_doublep = data->progress.ul_size_known ?
  516. (double)data->progress.ul.total_size : -1;
  517. break;
  518. case CURLINFO_REDIRECT_TIME:
  519. *param_doublep = DOUBLE_SECS(data->progress.t_redirect);
  520. break;
  521. default:
  522. return CURLE_UNKNOWN_OPTION;
  523. }
  524. return CURLE_OK;
  525. }
  526. static CURLcode getinfo_slist(struct Curl_easy *data, CURLINFO info,
  527. struct curl_slist **param_slistp)
  528. {
  529. union {
  530. struct curl_certinfo *to_certinfo;
  531. struct curl_slist *to_slist;
  532. } ptr;
  533. switch(info) {
  534. case CURLINFO_SSL_ENGINES:
  535. *param_slistp = Curl_ssl_engines_list(data);
  536. break;
  537. case CURLINFO_COOKIELIST:
  538. *param_slistp = Curl_cookie_list(data);
  539. break;
  540. case CURLINFO_CERTINFO:
  541. /* Return the a pointer to the certinfo struct. Not really an slist
  542. pointer but we can pretend it is here */
  543. ptr.to_certinfo = &data->info.certs;
  544. *param_slistp = ptr.to_slist;
  545. break;
  546. case CURLINFO_TLS_SESSION:
  547. case CURLINFO_TLS_SSL_PTR:
  548. {
  549. struct curl_tlssessioninfo **tsip = (struct curl_tlssessioninfo **)
  550. param_slistp;
  551. struct curl_tlssessioninfo *tsi = &data->tsi;
  552. /* we are exposing a pointer to internal memory with unknown
  553. * lifetime here. */
  554. *tsip = tsi;
  555. if(!Curl_conn_get_ssl_info(data, data->conn, FIRSTSOCKET, tsi)) {
  556. tsi->backend = Curl_ssl_backend();
  557. tsi->internals = NULL;
  558. }
  559. }
  560. break;
  561. default:
  562. return CURLE_UNKNOWN_OPTION;
  563. }
  564. return CURLE_OK;
  565. }
  566. static CURLcode getinfo_socket(struct Curl_easy *data, CURLINFO info,
  567. curl_socket_t *param_socketp)
  568. {
  569. switch(info) {
  570. case CURLINFO_ACTIVESOCKET:
  571. *param_socketp = Curl_getconnectinfo(data, NULL);
  572. break;
  573. default:
  574. return CURLE_UNKNOWN_OPTION;
  575. }
  576. return CURLE_OK;
  577. }
  578. CURLcode Curl_getinfo(struct Curl_easy *data, CURLINFO info, ...)
  579. {
  580. va_list arg;
  581. long *param_longp = NULL;
  582. double *param_doublep = NULL;
  583. curl_off_t *param_offt = NULL;
  584. const char **param_charp = NULL;
  585. struct curl_slist **param_slistp = NULL;
  586. curl_socket_t *param_socketp = NULL;
  587. int type;
  588. CURLcode result = CURLE_UNKNOWN_OPTION;
  589. if(!data)
  590. return CURLE_BAD_FUNCTION_ARGUMENT;
  591. va_start(arg, info);
  592. type = CURLINFO_TYPEMASK & (int)info;
  593. switch(type) {
  594. case CURLINFO_STRING:
  595. param_charp = va_arg(arg, const char **);
  596. if(param_charp)
  597. result = getinfo_char(data, info, param_charp);
  598. break;
  599. case CURLINFO_LONG:
  600. param_longp = va_arg(arg, long *);
  601. if(param_longp)
  602. result = getinfo_long(data, info, param_longp);
  603. break;
  604. case CURLINFO_DOUBLE:
  605. param_doublep = va_arg(arg, double *);
  606. if(param_doublep)
  607. result = getinfo_double(data, info, param_doublep);
  608. break;
  609. case CURLINFO_OFF_T:
  610. param_offt = va_arg(arg, curl_off_t *);
  611. if(param_offt)
  612. result = getinfo_offt(data, info, param_offt);
  613. break;
  614. case CURLINFO_SLIST:
  615. param_slistp = va_arg(arg, struct curl_slist **);
  616. if(param_slistp)
  617. result = getinfo_slist(data, info, param_slistp);
  618. break;
  619. case CURLINFO_SOCKET:
  620. param_socketp = va_arg(arg, curl_socket_t *);
  621. if(param_socketp)
  622. result = getinfo_socket(data, info, param_socketp);
  623. break;
  624. default:
  625. break;
  626. }
  627. va_end(arg);
  628. return result;
  629. }