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