GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: node_metadata.cc Lines: 44 44 100.0 %
Date: 2022-01-15 04:15:29 Branches: 4 6 66.7 %

Line Branch Exec Source
1
#include "node_metadata.h"
2
#include "ares.h"
3
#include "brotli/encode.h"
4
#include "llhttp.h"
5
#include "nghttp2/nghttp2ver.h"
6
#include "node.h"
7
#include "util.h"
8
#include "uv.h"
9
#include "v8.h"
10
#include "zlib.h"
11
12
#if HAVE_OPENSSL
13
#include <openssl/opensslv.h>
14
#if NODE_OPENSSL_HAS_QUIC
15
#include <openssl/quic.h>
16
#endif
17
#endif  // HAVE_OPENSSL
18
19
#ifdef OPENSSL_INFO_QUIC
20
#include <ngtcp2/version.h>
21
#include <nghttp3/version.h>
22
#endif
23
24
#ifdef NODE_HAVE_I18N_SUPPORT
25
#include <unicode/timezone.h>
26
#include <unicode/ulocdata.h>
27
#include <unicode/uvernum.h>
28
#include <unicode/uversion.h>
29
#endif  // NODE_HAVE_I18N_SUPPORT
30
31
namespace node {
32
33
namespace per_process {
34
Metadata metadata;
35
}
36
37
#if HAVE_OPENSSL
38
94639
constexpr int search(const char* s, int n, int c) {
39
94639
  return *s == c ? n : search(s + 1, n + 1, c);
40
}
41
42
4981
std::string GetOpenSSLVersion() {
43
  // sample openssl version string format
44
  // for reference: "OpenSSL 1.1.0i 14 Aug 2018"
45
  char buf[128];
46
4981
  const char* etext = OPENSSL_VERSION_TEXT;
47
4981
  const int start = search(etext, 0, ' ') + 1;
48
4981
  etext += start;
49
4981
  const int end = search(etext, start, ' ');
50
4981
  const int len = end - start;
51
4981
  snprintf(buf, sizeof(buf), "%.*s", len, &OPENSSL_VERSION_TEXT[start]);
52
4981
  return std::string(buf);
53
}
54
#endif  // HAVE_OPENSSL
55
56
#ifdef NODE_HAVE_I18N_SUPPORT
57
4929
void Metadata::Versions::InitializeIntlVersions() {
58
4929
  UErrorCode status = U_ZERO_ERROR;
59
60
4929
  const char* tz_version = icu::TimeZone::getTZDataVersion(status);
61
4929
  if (U_SUCCESS(status)) {
62
4929
    tz = tz_version;
63
  }
64
65
  char buf[U_MAX_VERSION_STRING_LENGTH];
66
  UVersionInfo versionArray;
67
4929
  ulocdata_getCLDRVersion(versionArray, &status);
68
4929
  if (U_SUCCESS(status)) {
69
4929
    u_versionToString(versionArray, buf);
70
4929
    cldr = buf;
71
  }
72
4929
}
73
#endif  // NODE_HAVE_I18N_SUPPORT
74
75
4981
Metadata::Versions::Versions() {
76
4981
  node = NODE_VERSION_STRING;
77
4981
  v8 = v8::V8::GetVersion();
78
4981
  uv = uv_version_string();
79
4981
  zlib = ZLIB_VERSION;
80
4981
  ares = ARES_VERSION_STR;
81
4981
  modules = NODE_STRINGIFY(NODE_MODULE_VERSION);
82
4981
  nghttp2 = NGHTTP2_VERSION;
83
4981
  napi = NODE_STRINGIFY(NAPI_VERSION);
84
  llhttp =
85
      NODE_STRINGIFY(LLHTTP_VERSION_MAJOR)
86
      "."
87
      NODE_STRINGIFY(LLHTTP_VERSION_MINOR)
88
      "."
89
4981
      NODE_STRINGIFY(LLHTTP_VERSION_PATCH);
90
91
  brotli =
92
9962
    std::to_string(BrotliEncoderVersion() >> 24) +
93
9962
    "." +
94
19924
    std::to_string((BrotliEncoderVersion() & 0xFFF000) >> 12) +
95
9962
    "." +
96
14943
    std::to_string(BrotliEncoderVersion() & 0xFFF);
97
98
#if HAVE_OPENSSL
99
4981
  openssl = GetOpenSSLVersion();
100
#endif
101
102
#ifdef NODE_HAVE_I18N_SUPPORT
103
4981
  icu = U_ICU_VERSION;
104
4981
  unicode = U_UNICODE_VERSION;
105
#endif  // NODE_HAVE_I18N_SUPPORT
106
107
#ifdef OPENSSL_INFO_QUIC
108
4981
  ngtcp2 = NGTCP2_VERSION;
109
4981
  nghttp3 = NGHTTP3_VERSION;
110
#endif
111
4981
}
112
113
4981
Metadata::Release::Release() : name(NODE_RELEASE) {
114
#if NODE_VERSION_IS_LTS
115
  lts = NODE_VERSION_LTS_CODENAME;
116
#endif  // NODE_VERSION_IS_LTS
117
118
#ifdef NODE_HAS_RELEASE_URLS
119
#define NODE_RELEASE_URLPFX NODE_RELEASE_URLBASE "v" NODE_VERSION_STRING "/"
120
#define NODE_RELEASE_URLFPFX NODE_RELEASE_URLPFX "node-v" NODE_VERSION_STRING
121
122
  source_url = NODE_RELEASE_URLFPFX ".tar.gz";
123
  headers_url = NODE_RELEASE_URLFPFX "-headers.tar.gz";
124
#ifdef _WIN32
125
  lib_url = strcmp(NODE_ARCH, "ia32") ? NODE_RELEASE_URLPFX "win-" NODE_ARCH
126
                                                           "/node.lib"
127
                                     : NODE_RELEASE_URLPFX "win-x86/node.lib";
128
#endif  // _WIN32
129
130
#endif  // NODE_HAS_RELEASE_URLS
131
4981
}
132
133
4981
Metadata::Metadata() : arch(NODE_ARCH), platform(NODE_PLATFORM) {}
134
135
}  // namespace node