2
0

getinfo.c 18 KB

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