Coverage Report

Created: 2025-11-09 06:51

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