GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: node_metadata.cc Lines: 38 38 100.0 %
Date: 2022-08-31 04:20:31 Branches: 2 4 50.0 %

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
static constexpr size_t search(const char* s, char c, size_t n = 0) {
39
  return *s == c ? n : search(s + 1, c, n + 1);
40
}
41
42
5494
static inline std::string GetOpenSSLVersion() {
43
  // sample openssl version string format
44
  // for reference: "OpenSSL 1.1.0i 14 Aug 2018"
45
5494
  constexpr size_t start = search(OPENSSL_VERSION_TEXT, ' ') + 1;
46
5494
  constexpr size_t len = search(&OPENSSL_VERSION_TEXT[start], ' ');
47
5494
  return std::string(OPENSSL_VERSION_TEXT, start, len);
48
}
49
#endif  // HAVE_OPENSSL
50
51
#ifdef NODE_HAVE_I18N_SUPPORT
52
5442
void Metadata::Versions::InitializeIntlVersions() {
53
5442
  UErrorCode status = U_ZERO_ERROR;
54
55
5442
  const char* tz_version = icu::TimeZone::getTZDataVersion(status);
56
5442
  if (U_SUCCESS(status)) {
57
5442
    tz = tz_version;
58
  }
59
60
  char buf[U_MAX_VERSION_STRING_LENGTH];
61
  UVersionInfo versionArray;
62
5442
  ulocdata_getCLDRVersion(versionArray, &status);
63
5442
  if (U_SUCCESS(status)) {
64
5442
    u_versionToString(versionArray, buf);
65
5442
    cldr = buf;
66
  }
67
5442
}
68
#endif  // NODE_HAVE_I18N_SUPPORT
69
70
5494
Metadata::Versions::Versions() {
71
5494
  node = NODE_VERSION_STRING;
72
5494
  v8 = v8::V8::GetVersion();
73
5494
  uv = uv_version_string();
74
5494
  zlib = ZLIB_VERSION;
75
5494
  ares = ARES_VERSION_STR;
76
5494
  modules = NODE_STRINGIFY(NODE_MODULE_VERSION);
77
5494
  nghttp2 = NGHTTP2_VERSION;
78
5494
  napi = NODE_STRINGIFY(NAPI_VERSION);
79
  llhttp =
80
      NODE_STRINGIFY(LLHTTP_VERSION_MAJOR)
81
      "."
82
      NODE_STRINGIFY(LLHTTP_VERSION_MINOR)
83
      "."
84
5494
      NODE_STRINGIFY(LLHTTP_VERSION_PATCH);
85
86
  brotli =
87
10988
    std::to_string(BrotliEncoderVersion() >> 24) +
88
10988
    "." +
89
21976
    std::to_string((BrotliEncoderVersion() & 0xFFF000) >> 12) +
90
10988
    "." +
91
16482
    std::to_string(BrotliEncoderVersion() & 0xFFF);
92
93
#if HAVE_OPENSSL
94
5494
  openssl = GetOpenSSLVersion();
95
#endif
96
97
#ifdef NODE_HAVE_I18N_SUPPORT
98
5494
  icu = U_ICU_VERSION;
99
5494
  unicode = U_UNICODE_VERSION;
100
#endif  // NODE_HAVE_I18N_SUPPORT
101
102
#ifdef OPENSSL_INFO_QUIC
103
5494
  ngtcp2 = NGTCP2_VERSION;
104
5494
  nghttp3 = NGHTTP3_VERSION;
105
#endif
106
5494
}
107
108
5494
Metadata::Release::Release() : name(NODE_RELEASE) {
109
#if NODE_VERSION_IS_LTS
110
  lts = NODE_VERSION_LTS_CODENAME;
111
#endif  // NODE_VERSION_IS_LTS
112
113
#ifdef NODE_HAS_RELEASE_URLS
114
#define NODE_RELEASE_URLPFX NODE_RELEASE_URLBASE "v" NODE_VERSION_STRING "/"
115
#define NODE_RELEASE_URLFPFX NODE_RELEASE_URLPFX "node-v" NODE_VERSION_STRING
116
117
  source_url = NODE_RELEASE_URLFPFX ".tar.gz";
118
  headers_url = NODE_RELEASE_URLFPFX "-headers.tar.gz";
119
#ifdef _WIN32
120
  lib_url = strcmp(NODE_ARCH, "ia32") ? NODE_RELEASE_URLPFX "win-" NODE_ARCH
121
                                                           "/node.lib"
122
                                     : NODE_RELEASE_URLPFX "win-x86/node.lib";
123
#endif  // _WIN32
124
125
#endif  // NODE_HAS_RELEASE_URLS
126
5494
}
127
128
5494
Metadata::Metadata() : arch(NODE_ARCH), platform(NODE_PLATFORM) {}
129
130
}  // namespace node