Skip to content

Commit 7a273ac

Browse files
committed
chore: bump version 10.9.40
Signed-off-by: Dylan <2894220@gmail.com>
1 parent a13d049 commit 7a273ac

20 files changed

Lines changed: 523 additions & 29 deletions

CMakeLists.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,25 @@ target_link_libraries(${TARGET_NAME}
139139
nim_chatroom_cpp_wrapper
140140
nim_tools_cpp_wrapper
141141
nim_qchat_cpp_wrapper
142-
nim_wrapper_util)
142+
nim_wrapper_util
143+
${CONAN_LIBS_NE_CHROMIUM_BASE}
144+
${CONAN_LIBS_OPENSSL}
145+
)
146+
if (WIN32)
147+
target_link_libraries(${TARGET_NAME} Psapi Dbghelp Version Ws2_32)
148+
endif ()
143149

144150
set_target_properties(${TARGET_NAME} PROPERTIES PREFIX "" SUFFIX ".node")
145151
if (APPLE)
146152
set_target_properties(${TARGET_NAME}
147153
PROPERTIES
148154
BUILD_WITH_INSTALL_RPATH 1
149155
INSTALL_RPATH "@loader_path")
156+
target_link_libraries(${TARGET_NAME}
157+
"-framework AppKit"
158+
"-framework SystemConfiguration"
159+
"-framework Security"
160+
)
150161
endif ()
151162

152163
# installation

node-nim-tester.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,11 @@ program
129129
if (options.nimSdkUrl) {
130130
await downloadSDK(options.nimSdkUrl)
131131
}
132-
const NIM = require('./dist/node-nim')
132+
const nimInstance = require('./dist/node-nim')
133+
nimInstance.v2 = new nimInstance.V2NIMClient()
134+
nimInstance.nim = new nimInstance.NIM()
135+
nimInstance.qchat = new nimInstance.QChat()
136+
nimInstance.chatroom = new nimInstance.ChatRoom()
133137
new WebAT({
134138
applicationName: 'nim',
135139
platform: 'Windows&MacOS',
@@ -138,7 +142,7 @@ program
138142
deviceId: options.deviceId,
139143
taskId: options.taskId,
140144
targets: {
141-
NIM
145+
NIM: nimInstance
142146
},
143147
oncompleted: () => {
144148
// 执行完成后退出进程

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-nim",
3-
"version": "10.9.33",
3+
"version": "10.9.40",
44
"description": "NetEase IM nodejs wrapper based on NetEase IM C++ SDK",
55
"main": "dist/node-nim.js",
66
"bin": {

src/chatroom/chatroom.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#include "chatroom.h"
2+
#include "common_helper.h"
23
#include "reflection/reflection_include.h"
34

45
namespace node_nim {
6+
57
Napi::Object NIMChatRoom::Init(Napi::Env env, Napi::Object exports) {
68
// clang-format off
79
return InternalInit("NIMChatRoom", env, exports, {

src/chatroom/chatroom.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
#ifndef __CHATROOM_H__
22
#define __CHATROOM_H__
3+
34
#include <napi.h>
45
#include "service_base.h"
56

67
namespace node_nim {
8+
79
class NIMChatRoom : public BizService<NIMChatRoom> {
810
public:
911
static Napi::Object Init(Napi::Env env, Napi::Object exports);
1012
void InitEventHandlers();
1113
explicit NIMChatRoom(const Napi::CallbackInfo& info);
1214
};
15+
1316
} // namespace node_nim
17+
1418
#endif // __CHATROOM_H__

src/common_helper.cpp

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
// Copyright (c) 2015-2016, NetEase Inc. All rights reserved.
2+
//
3+
// Author: litianyi <litianyi@corp.netease.com>
4+
// Date: 2015/10/20
5+
//
6+
// NIM SDK内部使用的helper
7+
8+
#include "common_helper.h"
9+
#include "base/files/file_path.h"
10+
#include "extension/file_util/path_util.h"
11+
#include "extension/strings/string_util.h"
12+
13+
namespace node_nim {
14+
15+
const std::string PathChecker::kCurrentDirectoryDescriptor = ".";
16+
const std::string PathChecker::kParentDirectoryDescriptor = "..";
17+
const char PathChecker::kDriveLettar = ':';
18+
const std::string PathChecker::kPathDelimiter = "/";
19+
const std::string PathChecker::kPathDelimiter_WIN = "\\";
20+
const char PathChecker::kCurrentDirectoryDescriptorLettar = '.';
21+
const char PathChecker::kSpaceLettar = ' ';
22+
23+
PathChecker::PathChecker(const std::string& path)
24+
: src_path_(path) {}
25+
26+
PathChecker::Result PathChecker::Check() {
27+
if (!CheckFormat())
28+
return Format_Error;
29+
#if !defined(OS_WIN)
30+
auto file_path = base::FilePath(src_path_);
31+
return file_path.IsAbsolute() ? Absolute_Path : Relative_Path;
32+
#else
33+
auto it = tokened_.begin();
34+
bool has_drive;
35+
if (!CheckDrive(*it++, has_drive))
36+
return Format_Error;
37+
while (it != tokened_.end()) {
38+
if ((it->compare(kParentDirectoryDescriptor) == 0 && it == tokened_.begin()) ||
39+
(it != tokened_.begin() && it->find(kDriveLettar) != std::string::npos)) {
40+
return Format_Error;
41+
} else if (it->compare(kCurrentDirectoryDescriptor) == 0) {
42+
it = tokened_.erase(it);
43+
} else if (it->compare(kParentDirectoryDescriptor) == 0) {
44+
it = tokened_.erase(it);
45+
it--;
46+
it = tokened_.erase(it);
47+
} else {
48+
it++;
49+
}
50+
}
51+
if (has_drive) {
52+
bool has_drive_check;
53+
if (!CheckDrive(*tokened_.begin(), has_drive_check))
54+
return Format_Error;
55+
return has_drive_check ? Absolute_Path : Format_Error;
56+
}
57+
return Relative_Path;
58+
#endif
59+
}
60+
61+
std::string PathChecker::GetPath() {
62+
#if !defined(OS_WIN)
63+
return src_path_;
64+
#else
65+
std::string ret;
66+
auto it = tokened_.begin();
67+
while (it != tokened_.end()) {
68+
ret.append(*it).append(kPathDelimiter);
69+
it++;
70+
}
71+
return ret;
72+
#endif
73+
}
74+
75+
bool PathChecker::CheckFormat() {
76+
// 不可以含有不支持的字符
77+
static const std::string kFobidenLettars = "*?\"<>|";
78+
auto itFobidenLettars = kFobidenLettars.begin();
79+
while (itFobidenLettars != kFobidenLettars.end()) {
80+
if (src_path_.find(*itFobidenLettars) != std::string::npos)
81+
return false;
82+
itFobidenLettars++;
83+
}
84+
// C:\A\B\C\..\..\..\..\D:\A\B\C这种格式同样不支持
85+
if (src_path_.find(kDriveLettar) != std::string::npos && src_path_.find_first_of(kDriveLettar) != src_path_.find_last_of(kDriveLettar))
86+
return false;
87+
#if !defined(OS_WIN)
88+
if (src_path_.length() == 0)
89+
return false;
90+
#else
91+
nbase::StringReplaceAll(kPathDelimiter_WIN, kPathDelimiter, src_path_);
92+
tokened_ = SplitPathItem(src_path_.c_str(), kPathDelimiter.c_str());
93+
// 过滤掉最后一个右侧" "与"."
94+
{
95+
auto rit = tokened_.rbegin();
96+
auto temp = *rit;
97+
while (!temp.empty()) {
98+
if (temp[temp.length() - 1] == kSpaceLettar || temp[temp.length() - 1] == kCurrentDirectoryDescriptorLettar)
99+
temp.resize(temp.length() - 1);
100+
else
101+
break;
102+
}
103+
if (temp.empty())
104+
return false;
105+
if (rit->compare(temp) != 0)
106+
rit->assign(temp.begin(), temp.end());
107+
}
108+
// 判断中间路径是否有不合规则的"."或者".."或者""或者" "或者(.... / .. .. / . . ./// ) 并移除掉所有的"."
109+
auto it = tokened_.begin();
110+
while (it != tokened_.end()) {
111+
auto temp = *it;
112+
if (temp.compare(kCurrentDirectoryDescriptor) == 0) // 合格的
113+
{
114+
it = tokened_.erase(it);
115+
} else if (temp.compare(kParentDirectoryDescriptor) == 0) // 合格的
116+
{
117+
it++;
118+
} else {
119+
nbase::StringReplaceAll(" ", "", temp);
120+
nbase::StringReplaceAll(".", "", temp);
121+
if (temp.empty()) //(....、 .. ..、 . . .、 、这种型的)
122+
return false;
123+
temp = *it;
124+
if (*temp.rbegin() == kSpaceLettar) // 不可以是空格结尾
125+
return false;
126+
if (temp.length() > 2) {
127+
if (temp[temp.length() - 1] == kCurrentDirectoryDescriptorLettar &&
128+
(temp[temp.length() - 2] == kCurrentDirectoryDescriptorLettar ||
129+
temp[temp.length() - 2] == kSpaceLettar)) // 末尾带一个点,合格,多于一个,不合格
130+
return false;
131+
else if (temp[temp.length() - 1] == kCurrentDirectoryDescriptorLettar) {
132+
temp.resize(temp.length() - 1);
133+
it->assign(temp.begin(), temp.end());
134+
}
135+
}
136+
it++;
137+
}
138+
}
139+
if (tokened_.empty())
140+
return false;
141+
if (tokened_.begin()->compare(kParentDirectoryDescriptor) == 0) // ..\ABC\DEF 开头以..的不支持 但..ABC..\DEF是支持的
142+
return false;
143+
#endif
144+
145+
return true;
146+
}
147+
148+
bool PathChecker::CheckDrive(const std::string& data, bool& has_drive) {
149+
has_drive = false;
150+
auto drive_pos = data.find(kDriveLettar);
151+
if (drive_pos == std::string::npos) {
152+
has_drive = false;
153+
return true;
154+
}
155+
std::string temp(data);
156+
if (temp.length() > 2)
157+
return false;
158+
auto drive = *data.begin();
159+
static const std::string kDriveList = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
160+
if (kDriveList.find(drive) != std::string::npos) {
161+
has_drive = true;
162+
return true;
163+
}
164+
return false;
165+
}
166+
167+
std::list<std::string> PathChecker::SplitPathItem(const std::string& input, const char* delimitor) {
168+
std::list<std::string> output;
169+
std::string temp(input);
170+
if (*temp.rbegin() == *delimitor)
171+
temp.resize(temp.length() - 1);
172+
size_t pos{std::string::npos};
173+
do {
174+
pos = temp.find_first_of(delimitor);
175+
if (pos != std::string::npos) {
176+
output.emplace_back(temp.substr(0, pos));
177+
temp = temp.substr(pos + 1);
178+
} else {
179+
output.emplace_back(temp);
180+
}
181+
} while (pos != std::string::npos);
182+
return output;
183+
}
184+
185+
bool parseAppdataPaths(const std::string& userAppData, base::FilePath& fullPath, std::string& parsedPath, std::string& parsedFolder) {
186+
std::string app_data_path = userAppData.empty() ? DEFAULT_APP_DATA_DIR : userAppData;
187+
node_nim::PathChecker path_checker(app_data_path);
188+
auto check_result = path_checker.Check();
189+
if (check_result == node_nim::PathChecker::Format_Error) {
190+
return false;
191+
// return V2NIMError{V2NIM_ERROR_CODE_INVALID_PARAMETER, {"appDataPath", appDataPath}};
192+
}
193+
base::FilePath local_app_data_path_obj;
194+
base::FilePath app_data_path_obj;
195+
if (check_result == node_nim::PathChecker::Absolute_Path) {
196+
std::list<UTF8String> path_components;
197+
bool result = nbase::ParsePathComponents(path_checker.GetPath().c_str(), path_components);
198+
if (!result)
199+
return false;
200+
std::size_t index = 0;
201+
for (const auto& path_component : path_components) {
202+
if (index < path_components.size() - 1) {
203+
parsedPath.append(path_component);
204+
}
205+
index++;
206+
}
207+
parsedFolder = base::FilePath::FromUTF8Unsafe(path_checker.GetPath()).BaseName().AsUTF8Unsafe();
208+
} else {
209+
parsedPath = base::FilePath::FromUTF8Unsafe(base::extension::GetSysLocalAppDataDir()).AsUTF8Unsafe();
210+
parsedFolder = app_data_path;
211+
}
212+
base::extension::SetLocalAppDataDir(parsedPath);
213+
base::extension::SetCustomAppDataDirName(parsedFolder);
214+
fullPath = base::FilePath::FromUTF8Unsafe(parsedPath).Append(base::FilePath::FromUTF8Unsafe(parsedFolder));
215+
return true;
216+
}
217+
218+
} // namespace node_nim

src/common_helper.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) 2015-2016, NetEase Inc. All rights reserved.
2+
//
3+
// Author: litianyi <litianyi@corp.netease.com>
4+
// Date: 2015/10/20
5+
//
6+
// NIM SDK内部使用的helper
7+
8+
#ifndef SRC_CPP_INVOKER_COMMON_HELPER_H_
9+
#define SRC_CPP_INVOKER_COMMON_HELPER_H_
10+
11+
// #include <sys/timeb.h>
12+
#include <list>
13+
#include <string>
14+
#include "extension/file_util/path_util.h"
15+
#include "extension/file_util/utf8_file_util.h"
16+
#include "node_public_defines.h"
17+
18+
namespace node_nim {
19+
20+
std::string GetUserAppDataPath(const std::string& app_account);
21+
22+
class PathChecker {
23+
public:
24+
enum Result {
25+
Format_Error = 1,
26+
Absolute_Path = 2,
27+
Relative_Path = 3,
28+
};
29+
30+
PathChecker(const std::string& path);
31+
~PathChecker() = default;
32+
Result Check();
33+
std::string GetPath();
34+
35+
private:
36+
bool CheckFormat();
37+
bool CheckDrive(const std::string& data, bool& has_drive);
38+
std::list<std::string> SplitPathItem(const std::string& input, const char* delimitor);
39+
40+
std::string src_path_;
41+
std::list<std::string> tokened_;
42+
static const std::string kCurrentDirectoryDescriptor;
43+
static const std::string kParentDirectoryDescriptor;
44+
static const char kDriveLettar;
45+
static const std::string kPathDelimiter;
46+
static const std::string kPathDelimiter_WIN;
47+
static const char kSpaceLettar;
48+
static const char kCurrentDirectoryDescriptorLettar;
49+
};
50+
51+
bool parseAppdataPaths(const std::string& userAppData, base::FilePath& fullPath, std::string& parsedPath, std::string& parsedFolder);
52+
53+
} // namespace node_nim
54+
55+
#endif // SRC_CPP_INVOKER_COMMON_HELPER_H_

0 commit comments

Comments
 (0)