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