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