1/***************************************************************************
2 *                                  _   _ ____  _
3 *  Project                     ___| | | |  _ \| |
4 *                             / __| | | | |_) | |
5 *                            | (__| |_| |  _ <| |___
6 *                             \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) 1998 - 2012, 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 "tool_setup.h"
23
24#include "rawstr.h"
25
26#define ENABLE_CURLX_PRINTF
27/* use our own printf() functions */
28#include "curlx.h"
29
30#include "tool_libinfo.h"
31
32#include "memdebug.h" /* keep this as LAST include */
33
34/* global variable definitions, for libcurl run-time info */
35
36curl_version_info_data *curlinfo = NULL;
37long built_in_protos = 0;
38
39/*
40 * libcurl_info_init: retrieves run-time information about libcurl,
41 * setting a global pointer 'curlinfo' to libcurl's run-time info
42 * struct, and a global bit pattern 'built_in_protos' composed of
43 * CURLPROTO_* bits indicating which protocols are actually built
44 * into library being used.
45 */
46
47CURLcode get_libcurl_info(void)
48{
49  static struct proto_name_pattern {
50    const char *proto_name;
51    long        proto_pattern;
52  } const possibly_built_in[] = {
53    { "dict",   CURLPROTO_DICT   },
54    { "file",   CURLPROTO_FILE   },
55    { "ftp",    CURLPROTO_FTP    },
56    { "ftps",   CURLPROTO_FTPS   },
57    { "gopher", CURLPROTO_GOPHER },
58    { "http",   CURLPROTO_HTTP   },
59    { "https",  CURLPROTO_HTTPS  },
60    { "imap",   CURLPROTO_IMAP   },
61    { "imaps",  CURLPROTO_IMAPS  },
62    { "ldap",   CURLPROTO_LDAP   },
63    { "ldaps",  CURLPROTO_LDAPS  },
64    { "pop3",   CURLPROTO_POP3   },
65    { "pop3s",  CURLPROTO_POP3S  },
66    { "rtmp",   CURLPROTO_RTMP   },
67    { "rtsp",   CURLPROTO_RTSP   },
68    { "scp",    CURLPROTO_SCP    },
69    { "sftp",   CURLPROTO_SFTP   },
70    { "smtp",   CURLPROTO_SMTP   },
71    { "smtps",  CURLPROTO_SMTPS  },
72    { "telnet", CURLPROTO_TELNET },
73    { "tftp",   CURLPROTO_TFTP   },
74    {  NULL,    0                }
75  };
76
77  struct proto_name_pattern const *p;
78  const char *const *proto;
79
80  /* Pointer to libcurl's run-time version information */
81  curlinfo = curl_version_info(CURLVERSION_NOW);
82  if(!curlinfo)
83    return CURLE_FAILED_INIT;
84
85  /* Build CURLPROTO_* bit pattern with libcurl's built-in protocols */
86  built_in_protos = 0;
87  if(curlinfo->protocols) {
88    for(proto = curlinfo->protocols; *proto; proto++) {
89      for(p = possibly_built_in; p->proto_name; p++) {
90        if(curlx_raw_equal(*proto, p->proto_name)) {
91          built_in_protos |= p->proto_pattern;
92          break;
93        }
94      }
95    }
96  }
97
98  return CURLE_OK;
99}
100
101