GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: node_metadata.cc Lines: 44 44 100.0 %
Date: 2022-03-19 03:15:25 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
95494
constexpr int search(const char* s, int n, int c) {
39
95494
  return *s == c ? n : search(s + 1, n + 1, c);
40
}
41
42
5026
std::string GetOpenSSLVersion() {
43
  // sample openssl version string format
44
  // for reference: "OpenSSL 1.1.0i 14 Aug 2018"
45
  char buf[128];
46
5026
  const char* etext = OPENSSL_VERSION_TEXT;
47
5026
  const int start = search(etext, 0, ' ') + 1;
48
5026
  etext += start;
49
5026
  const int end = search(etext, start, ' ');
50
5026
  const int len = end - start;
51
5026
  snprintf(buf, sizeof(buf), "%.*s", len, &OPENSSL_VERSION_TEXT[start]);
52
5026
  return std::string(buf);
53
}
54
#endif  // HAVE_OPENSSL
55
56
#ifdef NODE_HAVE_I18N_SUPPORT
57
4974
void Metadata::Versions::InitializeIntlVersions() {
58
4974
  UErrorCode status = U_ZERO_ERROR;
59
60
4974
  const char* tz_version = icu::TimeZone::getTZDataVersion(status);
61
4974
  if (U_SUCCESS(status)) {
62
4974
    tz = tz_version;
63
  }
64
65
  char buf[U_MAX_VERSION_STRING_LENGTH];
66
  UVersionInfo versionArray;
67
4974
  ulocdata_getCLDRVersion(versionArray, &status);
68
4974
  if (U_SUCCESS(status)) {
69
4974
    u_versionToString(versionArray, buf);
70
4974
    cldr = buf;
71
  }
72
4974
}
73
#endif  // NODE_HAVE_I18N_SUPPORT
74
75
5026
Metadata::Versions::Versions() {
76
5026
  node = NODE_VERSION_STRING;
77
5026
  v8 = v8::V8::GetVersion();
78
5026
  uv = uv_version_string();
79
5026
  zlib = ZLIB_VERSION;
80
5026
  ares = ARES_VERSION_STR;
81
5026
  modules = NODE_STRINGIFY(NODE_MODULE_VERSION);
82
5026
  nghttp2 = NGHTTP2_VERSION;
83
5026
  napi = NODE_STRINGIFY(NAPI_VERSION);
84
  llhttp =
85
      NODE_STRINGIFY(LLHTTP_VERSION_MAJOR)
86
      "."
87
      NODE_STRINGIFY(LLHTTP_VERSION_MINOR)
88
      "."
89
5026
      NODE_STRINGIFY(LLHTTP_VERSION_PATCH);
90
91
  brotli =
92
10052
    std::to_string(BrotliEncoderVersion() >> 24) +
93
10052
    "." +
94
20104
    std::to_string((BrotliEncoderVersion() & 0xFFF000) >> 12) +
95
10052
    "." +
96
15078
    std::to_string(BrotliEncoderVersion() & 0xFFF);
97
98
#if HAVE_OPENSSL
99
5026
  openssl = GetOpenSSLVersion();
100
#endif
101
102
#ifdef NODE_HAVE_I18N_SUPPORT
103
5026
  icu = U_ICU_VERSION;
104
5026
  unicode = U_UNICODE_VERSION;
105
#endif  // NODE_HAVE_I18N_SUPPORT
106
107
#ifdef OPENSSL_INFO_QUIC
108
5026
  ngtcp2 = NGTCP2_VERSION;
109
5026
  nghttp3 = NGHTTP3_VERSION;
110
#endif
111
5026
}
112
113
5026
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
5026
}
132
133
5026
Metadata::Metadata() : arch(NODE_ARCH), platform(NODE_PLATFORM) {}
134
135
}  // namespace node