11#include " kerberos.h"
2+
23#include " kerberos_worker.h"
34
45// / KerberosClient
@@ -13,22 +14,22 @@ struct InstanceData {
1314};
1415
1516static 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));
1819
1920inline String NewMaybeWideString (Env env, const char * str) {
2021 return String::New (env, str);
2122}
2223#ifdef _WIN32
2324inline String NewMaybeWideString (Env env, const WCHAR* str) {
2425 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" );
2627 std::wstring wstr (str);
2728 std::u16string u16 (wstr.begin (), wstr.end ());
2829 return String::New (env, u16 );
2930}
3031#endif
31- }
32+ } // namespace
3233
3334std::string ToStringWithNonStringAsEmpty (Napi::Value value) {
3435 if (!value.IsString ()) {
@@ -38,7 +39,8 @@ std::string ToStringWithNonStringAsEmpty(Napi::Value value) {
3839}
3940
4041int KerberosClient::ParseWrapOptionsProtect (const Napi::Object& options) {
41- if (!options.Has (" protect" )) return 0 ;
42+ if (!options.Has (" protect" ))
43+ return 0 ;
4244
4345 if (!options.Get (" protect" ).IsBoolean ()) {
4446 throw TypeError::New (options.Env (), " options.protect must be a boolean." );
@@ -49,18 +51,16 @@ int KerberosClient::ParseWrapOptionsProtect(const Napi::Object& options) {
4951}
5052
5153Function 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 )});
6464}
6565
6666Object 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
7171 return obj;
7272}
7373
74- KerberosClient::KerberosClient (const CallbackInfo& info)
75- : ObjectWrap(info) {}
74+ KerberosClient::KerberosClient (const CallbackInfo& info) : ObjectWrap(info) {}
7675
7776std::shared_ptr<krb_client_state> KerberosClient::state () const {
7877 return _state;
@@ -102,16 +101,14 @@ Value KerberosClient::ContextCompleteGetter(const CallbackInfo& info) {
102101
103102// / KerberosServer
104103Function 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 )});
115112}
116113
117114Object 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
122119 return obj;
123120}
124121
125- KerberosServer::KerberosServer (const CallbackInfo& info)
126- : ObjectWrap(info) {}
122+ KerberosServer::KerberosServer (const CallbackInfo& info) : ObjectWrap(info) {}
127123
128124std::shared_ptr<krb_server_state> KerberosServer::state () const {
129125 return _state;
@@ -154,31 +150,8 @@ Value KerberosServer::ContextCompleteGetter(const CallbackInfo& info) {
154150 return Boolean::New (Env (), state ()->context_complete );
155151}
156152
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));
182155}
183156
184157static Object Init (Env env, Object exports) {
@@ -190,18 +163,16 @@ static Object Init(Env env, Object exports) {
190163 Function KerberosServerCtor = KerberosServer::Init (env);
191164 exports[" KerberosClient" ] = KerberosClientCtor;
192165 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 )});
197168 exports[" initializeClient" ] = Function::New (env, InitializeClient);
198169 exports[" initializeServer" ] = Function::New (env, InitializeServer);
199170 exports[" principalDetails" ] = Function::New (env, PrincipalDetails);
200171 exports[" checkPassword" ] = Function::New (env, CheckPassword);
201- exports[" _testMethod " ] = Function::New (env, TestMethod );
172+ exports[" definedNapiVersion " ] = Function::New (env, GetDefinedNapiVersion );
202173 return exports;
203174}
204175
205176NODE_API_MODULE (kerberos, Init)
206177
207- }
178+ } // namespace node_kerberos
0 commit comments