Coverage Report

Created: 2025-07-11 06:33

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