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