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