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