1 #include "node_metadata.h"
2 #include "acorn_version.h"
3 #include "ada.h"
4 #include "ares.h"
5 #include "base64_version.h"
6 #include "brotli/encode.h"
7 #include "cjs_module_lexer_version.h"
8 #include "llhttp.h"
9 #include "nghttp2/nghttp2ver.h"
10 #include "node.h"
11 #include "simdutf.h"
12 #include "undici_version.h"
13 #include "util.h"
14 #include "uv.h"
15 #include "uvwasi.h"
16 #include "v8.h"
17 #include "zlib.h"
18
19 #if HAVE_OPENSSL
20 #include <openssl/opensslv.h>
21 #if NODE_OPENSSL_HAS_QUIC
22 #include <openssl/quic.h>
23 #endif
24 #endif // HAVE_OPENSSL
25
26 #ifdef OPENSSL_INFO_QUIC
27 #include <ngtcp2/version.h>
28 #include <nghttp3/version.h>
29 #endif
30
31 #ifdef NODE_HAVE_I18N_SUPPORT
32 #include <unicode/timezone.h>
33 #include <unicode/ulocdata.h>
34 #include <unicode/uvernum.h>
35 #include <unicode/uversion.h>
36 #endif // NODE_HAVE_I18N_SUPPORT
37
38 namespace node {
39
40 namespace per_process {
41 Metadata metadata;
42 }
43
44 #if HAVE_OPENSSL
search(const char * s,char c,size_t n=0)45 static constexpr size_t search(const char* s, char c, size_t n = 0) {
46 return *s == c ? n : search(s + 1, c, n + 1);
47 }
48
GetOpenSSLVersion()49 static inline std::string GetOpenSSLVersion() {
50 // sample openssl version string format
51 // for reference: "OpenSSL 1.1.0i 14 Aug 2018"
52 constexpr size_t start = search(OPENSSL_VERSION_TEXT, ' ') + 1;
53 constexpr size_t len = search(&OPENSSL_VERSION_TEXT[start], ' ');
54 return std::string(OPENSSL_VERSION_TEXT, start, len);
55 }
56 #endif // HAVE_OPENSSL
57
58 #ifdef NODE_HAVE_I18N_SUPPORT
InitializeIntlVersions()59 void Metadata::Versions::InitializeIntlVersions() {
60 UErrorCode status = U_ZERO_ERROR;
61
62 const char* tz_version = icu::TimeZone::getTZDataVersion(status);
63 if (U_SUCCESS(status)) {
64 tz = tz_version;
65 }
66
67 char buf[U_MAX_VERSION_STRING_LENGTH];
68 UVersionInfo versionArray;
69 ulocdata_getCLDRVersion(versionArray, &status);
70 if (U_SUCCESS(status)) {
71 u_versionToString(versionArray, buf);
72 cldr = buf;
73 }
74 }
75 #endif // NODE_HAVE_I18N_SUPPORT
76
Versions()77 Metadata::Versions::Versions() {
78 node = NODE_VERSION_STRING;
79 v8 = v8::V8::GetVersion();
80 uv = uv_version_string();
81 zlib = ZLIB_VERSION;
82 ares = ARES_VERSION_STR;
83 modules = NODE_STRINGIFY(NODE_MODULE_VERSION);
84 nghttp2 = NGHTTP2_VERSION;
85 napi = NODE_STRINGIFY(NAPI_VERSION);
86 llhttp =
87 NODE_STRINGIFY(LLHTTP_VERSION_MAJOR)
88 "."
89 NODE_STRINGIFY(LLHTTP_VERSION_MINOR)
90 "."
91 NODE_STRINGIFY(LLHTTP_VERSION_PATCH);
92
93 brotli =
94 std::to_string(BrotliEncoderVersion() >> 24) +
95 "." +
96 std::to_string((BrotliEncoderVersion() & 0xFFF000) >> 12) +
97 "." +
98 std::to_string(BrotliEncoderVersion() & 0xFFF);
99 #ifndef NODE_SHARED_BUILTIN_UNDICI_UNDICI_PATH
100 undici = UNDICI_VERSION;
101 #endif
102
103 acorn = ACORN_VERSION;
104 cjs_module_lexer = CJS_MODULE_LEXER_VERSION;
105 base64 = BASE64_VERSION;
106 uvwasi = UVWASI_VERSION_STRING;
107
108 #if HAVE_OPENSSL
109 openssl = GetOpenSSLVersion();
110 #endif
111
112 #ifdef NODE_HAVE_I18N_SUPPORT
113 icu = U_ICU_VERSION;
114 unicode = U_UNICODE_VERSION;
115 #endif // NODE_HAVE_I18N_SUPPORT
116
117 #ifdef OPENSSL_INFO_QUIC
118 ngtcp2 = NGTCP2_VERSION;
119 nghttp3 = NGHTTP3_VERSION;
120 #endif
121
122 simdutf = SIMDUTF_VERSION;
123 ada = ADA_VERSION;
124 }
125
Release()126 Metadata::Release::Release() : name(NODE_RELEASE) {
127 #if NODE_VERSION_IS_LTS
128 lts = NODE_VERSION_LTS_CODENAME;
129 #endif // NODE_VERSION_IS_LTS
130
131 #ifdef NODE_HAS_RELEASE_URLS
132 #define NODE_RELEASE_URLPFX NODE_RELEASE_URLBASE "v" NODE_VERSION_STRING "/"
133 #define NODE_RELEASE_URLFPFX NODE_RELEASE_URLPFX "node-v" NODE_VERSION_STRING
134
135 source_url = NODE_RELEASE_URLFPFX ".tar.gz";
136 headers_url = NODE_RELEASE_URLFPFX "-headers.tar.gz";
137 #ifdef _WIN32
138 lib_url = strcmp(NODE_ARCH, "ia32") ? NODE_RELEASE_URLPFX "win-" NODE_ARCH
139 "/node.lib"
140 : NODE_RELEASE_URLPFX "win-x86/node.lib";
141 #endif // _WIN32
142
143 #endif // NODE_HAS_RELEASE_URLS
144 }
145
Metadata()146 Metadata::Metadata() : arch(NODE_ARCH), platform(NODE_PLATFORM) {}
147
148 } // namespace node
149