1
1
#include " kerberos.h"
2
+
2
3
#include " kerberos_worker.h"
3
4
4
5
// / KerberosClient
@@ -13,22 +14,22 @@ struct InstanceData {
13
14
};
14
15
15
16
static constexpr napi_property_attributes writable_and_configurable =
16
- static_cast <napi_property_attributes>(
17
- static_cast < int >(napi_writable) | static_cast <int >(napi_configurable));
17
+ static_cast <napi_property_attributes>(static_cast < int >(napi_writable) |
18
+ static_cast <int >(napi_configurable));
18
19
19
20
inline String NewMaybeWideString (Env env, const char * str) {
20
21
return String::New (env, str);
21
22
}
22
23
#ifdef _WIN32
23
24
inline String NewMaybeWideString (Env env, const WCHAR* str) {
24
25
static_assert (sizeof (std::wstring::value_type) == sizeof (std::u16string::value_type),
25
- " wstring and u16string have the same value type on Windows" );
26
+ " wstring and u16string have the same value type on Windows" );
26
27
std::wstring wstr (str);
27
28
std::u16string u16 (wstr.begin (), wstr.end ());
28
29
return String::New (env, u16 );
29
30
}
30
31
#endif
31
- }
32
+ } // namespace
32
33
33
34
std::string ToStringWithNonStringAsEmpty (Napi::Value value) {
34
35
if (!value.IsString ()) {
@@ -38,7 +39,8 @@ std::string ToStringWithNonStringAsEmpty(Napi::Value value) {
38
39
}
39
40
40
41
int KerberosClient::ParseWrapOptionsProtect (const Napi::Object& options) {
41
- if (!options.Has (" protect" )) return 0 ;
42
+ if (!options.Has (" protect" ))
43
+ return 0 ;
42
44
43
45
if (!options.Get (" protect" ).IsBoolean ()) {
44
46
throw TypeError::New (options.Env (), " options.protect must be a boolean." );
@@ -49,18 +51,16 @@ int KerberosClient::ParseWrapOptionsProtect(const Napi::Object& options) {
49
51
}
50
52
51
53
Function KerberosClient::Init (Napi::Env env) {
52
- return
53
- DefineClass (env,
54
- " KerberosClient" ,
55
- {
56
- InstanceMethod (" step" , &KerberosClient::Step, writable_and_configurable),
57
- InstanceMethod (" wrap" , &KerberosClient::WrapData, writable_and_configurable),
58
- InstanceMethod (" unwrap" , &KerberosClient::UnwrapData, writable_and_configurable),
59
- InstanceAccessor (" username" , &KerberosClient::UserNameGetter, nullptr ),
60
- InstanceAccessor (" response" , &KerberosClient::ResponseGetter, nullptr ),
61
- InstanceAccessor (" responseConf" , &KerberosClient::ResponseConfGetter, nullptr ),
62
- InstanceAccessor (" contextComplete" , &KerberosClient::ContextCompleteGetter, nullptr )
63
- });
54
+ return DefineClass (
55
+ env,
56
+ " KerberosClient" ,
57
+ {InstanceMethod (" step" , &KerberosClient::Step, writable_and_configurable),
58
+ InstanceMethod (" wrap" , &KerberosClient::WrapData, writable_and_configurable),
59
+ InstanceMethod (" unwrap" , &KerberosClient::UnwrapData, writable_and_configurable),
60
+ InstanceAccessor (" username" , &KerberosClient::UserNameGetter, nullptr ),
61
+ InstanceAccessor (" response" , &KerberosClient::ResponseGetter, nullptr ),
62
+ InstanceAccessor (" responseConf" , &KerberosClient::ResponseConfGetter, nullptr ),
63
+ InstanceAccessor (" contextComplete" , &KerberosClient::ContextCompleteGetter, nullptr )});
64
64
}
65
65
66
66
Object KerberosClient::NewInstance (Napi::Env env, std::shared_ptr<krb_client_state> state) {
@@ -71,8 +71,7 @@ Object KerberosClient::NewInstance(Napi::Env env, std::shared_ptr<krb_client_sta
71
71
return obj;
72
72
}
73
73
74
- KerberosClient::KerberosClient (const CallbackInfo& info)
75
- : ObjectWrap(info) {}
74
+ KerberosClient::KerberosClient (const CallbackInfo& info) : ObjectWrap(info) {}
76
75
77
76
std::shared_ptr<krb_client_state> KerberosClient::state () const {
78
77
return _state;
@@ -102,16 +101,14 @@ Value KerberosClient::ContextCompleteGetter(const CallbackInfo& info) {
102
101
103
102
// / KerberosServer
104
103
Function KerberosServer::Init (Napi::Env env) {
105
- return
106
- DefineClass (env,
107
- " KerberosServer" ,
108
- {
109
- InstanceMethod (" step" , &KerberosServer::Step, writable_and_configurable),
110
- InstanceAccessor (" username" , &KerberosServer::UserNameGetter, nullptr ),
111
- InstanceAccessor (" response" , &KerberosServer::ResponseGetter, nullptr ),
112
- InstanceAccessor (" targetName" , &KerberosServer::TargetNameGetter, nullptr ),
113
- InstanceAccessor (" contextComplete" , &KerberosServer::ContextCompleteGetter, nullptr )
114
- });
104
+ return DefineClass (
105
+ env,
106
+ " KerberosServer" ,
107
+ {InstanceMethod (" step" , &KerberosServer::Step, writable_and_configurable),
108
+ InstanceAccessor (" username" , &KerberosServer::UserNameGetter, nullptr ),
109
+ InstanceAccessor (" response" , &KerberosServer::ResponseGetter, nullptr ),
110
+ InstanceAccessor (" targetName" , &KerberosServer::TargetNameGetter, nullptr ),
111
+ InstanceAccessor (" contextComplete" , &KerberosServer::ContextCompleteGetter, nullptr )});
115
112
}
116
113
117
114
Object KerberosServer::NewInstance (Napi::Env env, std::shared_ptr<krb_server_state> state) {
@@ -122,8 +119,7 @@ Object KerberosServer::NewInstance(Napi::Env env, std::shared_ptr<krb_server_sta
122
119
return obj;
123
120
}
124
121
125
- KerberosServer::KerberosServer (const CallbackInfo& info)
126
- : ObjectWrap(info) {}
122
+ KerberosServer::KerberosServer (const CallbackInfo& info) : ObjectWrap(info) {}
127
123
128
124
std::shared_ptr<krb_server_state> KerberosServer::state () const {
129
125
return _state;
@@ -154,31 +150,8 @@ Value KerberosServer::ContextCompleteGetter(const CallbackInfo& info) {
154
150
return Boolean::New (Env (), state ()->context_complete );
155
151
}
156
152
157
- void TestMethod (const CallbackInfo& info) {
158
- std::string string = info[0 ].ToString ();
159
- bool shouldError = info[1 ].ToBoolean ();
160
-
161
- std::string optionalString;
162
- Function callback;
163
- if (info[2 ].IsFunction ()) {
164
- callback = info[2 ].As <Function>();
165
- } else {
166
- optionalString = info[2 ].ToString ();
167
- callback = info[3 ].As <Function>();
168
- }
169
-
170
- KerberosWorker::Run (callback, " kerberos:TestMethod" , [=](KerberosWorker::SetOnFinishedHandler onFinished) {
171
- return onFinished ([=](KerberosWorker* worker) {
172
- Napi::Env env = worker->Env ();
173
- if (shouldError) {
174
- worker->Call (std::initializer_list<napi_value>
175
- { Error::New (env).Value (), env.Null () });
176
- } else {
177
- worker->Call (std::initializer_list<napi_value>
178
- { env.Null (), String::New (env, optionalString) });
179
- }
180
- });
181
- });
153
+ Value GetDefinedNapiVersion (const CallbackInfo& info) {
154
+ return String::New (info.Env (), std::to_string (NAPI_VERSION));
182
155
}
183
156
184
157
static Object Init (Env env, Object exports) {
@@ -190,18 +163,16 @@ static Object Init(Env env, Object exports) {
190
163
Function KerberosServerCtor = KerberosServer::Init (env);
191
164
exports[" KerberosClient" ] = KerberosClientCtor;
192
165
exports[" KerberosServer" ] = KerberosServerCtor;
193
- env.SetInstanceData (new InstanceData {
194
- Reference<Function>::New (KerberosClientCtor, 1 ),
195
- Reference<Function>::New (KerberosServerCtor, 1 )
196
- });
166
+ env.SetInstanceData (new InstanceData{Reference<Function>::New (KerberosClientCtor, 1 ),
167
+ Reference<Function>::New (KerberosServerCtor, 1 )});
197
168
exports[" initializeClient" ] = Function::New (env, InitializeClient);
198
169
exports[" initializeServer" ] = Function::New (env, InitializeServer);
199
170
exports[" principalDetails" ] = Function::New (env, PrincipalDetails);
200
171
exports[" checkPassword" ] = Function::New (env, CheckPassword);
201
- exports[" _testMethod " ] = Function::New (env, TestMethod );
172
+ exports[" definedNapiVersion " ] = Function::New (env, GetDefinedNapiVersion );
202
173
return exports;
203
174
}
204
175
205
176
NODE_API_MODULE (kerberos, Init)
206
177
207
- }
178
+ } // namespace node_kerberos
0 commit comments