blob: 1f35595f3d3422195aaee56e37da019021bd6d60 [file] [log] [blame]
murgatroid99749666e2015-01-12 18:25:58 -08001/*
2 *
murgatroid9925269f02016-03-16 16:00:07 -07003 * Copyright 2015-2016, Google Inc.
murgatroid99749666e2015-01-12 18:25:58 -08004 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
murgatroid995f709ca2015-09-30 14:22:54 -070034#ifndef GRPC_NODE_CALL_CREDENTIALS_H_
35#define GRPC_NODE_CALL_CREDENTIALS_H_
murgatroid99e5061512015-01-12 18:14:35 -080036
murgatroid99734c8db2016-03-16 11:39:15 -070037#include <list>
38
murgatroid99e5061512015-01-12 18:14:35 -080039#include <node.h>
40#include <nan.h>
murgatroid99734c8db2016-03-16 11:39:15 -070041#include <uv.h>
murgatroid99e5061512015-01-12 18:14:35 -080042#include "grpc/grpc_security.h"
43
44namespace grpc {
45namespace node {
46
murgatroid995f709ca2015-09-30 14:22:54 -070047class CallCredentials : public Nan::ObjectWrap {
murgatroid99e5061512015-01-12 18:14:35 -080048 public:
murgatroid992b097832015-09-17 13:56:25 -070049 static void Init(v8::Local<v8::Object> exports);
50 static bool HasInstance(v8::Local<v8::Value> val);
murgatroid997c0dbf82015-10-20 16:10:20 -070051 /* Wrap a grpc_call_credentials struct in a javascript object */
52 static v8::Local<v8::Value> WrapStruct(grpc_call_credentials *credentials);
murgatroid99e5061512015-01-12 18:14:35 -080053
murgatroid997c0dbf82015-10-20 16:10:20 -070054 /* Returns the grpc_call_credentials struct that this object wraps */
55 grpc_call_credentials *GetWrappedCredentials();
murgatroid99e5061512015-01-12 18:14:35 -080056
57 private:
murgatroid997c0dbf82015-10-20 16:10:20 -070058 explicit CallCredentials(grpc_call_credentials *credentials);
murgatroid995f709ca2015-09-30 14:22:54 -070059 ~CallCredentials();
murgatroid99e5061512015-01-12 18:14:35 -080060
61 // Prevent copying
murgatroid995f709ca2015-09-30 14:22:54 -070062 CallCredentials(const CallCredentials &);
63 CallCredentials &operator=(const CallCredentials &);
murgatroid99e5061512015-01-12 18:14:35 -080064
65 static NAN_METHOD(New);
murgatroid99e5061512015-01-12 18:14:35 -080066 static NAN_METHOD(CreateSsl);
murgatroid99ada3f612015-09-23 10:47:35 -070067 static NAN_METHOD(CreateFromPlugin);
murgatroid995f709ca2015-09-30 14:22:54 -070068
69 static NAN_METHOD(Compose);
murgatroid992b097832015-09-17 13:56:25 -070070 static Nan::Callback *constructor;
murgatroid99e5061512015-01-12 18:14:35 -080071 // Used for typechecking instances of this javascript class
murgatroid992b097832015-09-17 13:56:25 -070072 static Nan::Persistent<v8::FunctionTemplate> fun_tpl;
murgatroid99e5061512015-01-12 18:14:35 -080073
murgatroid997c0dbf82015-10-20 16:10:20 -070074 grpc_call_credentials *wrapped_credentials;
murgatroid99e5061512015-01-12 18:14:35 -080075};
76
murgatroid99ada3f612015-09-23 10:47:35 -070077/* Auth metadata plugin functionality */
78
murgatroid998d4aec32015-09-24 10:54:55 -070079typedef struct plugin_callback_data {
murgatroid998d4aec32015-09-24 10:54:55 -070080 const char *service_url;
81 grpc_credentials_plugin_metadata_cb cb;
82 void *user_data;
83} plugin_callback_data;
84
murgatroid99734c8db2016-03-16 11:39:15 -070085typedef struct plugin_state {
86 Nan::Callback *callback;
87 std::list<plugin_callback_data*> *pending_callbacks;
88 uv_mutex_t plugin_mutex;
89 // async.data == this
90 uv_async_t plugin_async;
91} plugin_state;
92
Julien Boeuf35b6b942015-11-18 22:12:29 -080093void plugin_get_metadata(void *state, grpc_auth_metadata_context context,
murgatroid998d4aec32015-09-24 10:54:55 -070094 grpc_credentials_plugin_metadata_cb cb,
95 void *user_data);
murgatroid99ada3f612015-09-23 10:47:35 -070096
97void plugin_destroy_state(void *state);
98
murgatroid99153b09d2015-09-25 16:04:03 -070099NAN_METHOD(PluginCallback);
murgatroid99ada3f612015-09-23 10:47:35 -0700100
murgatroid99153b09d2015-09-25 16:04:03 -0700101NAUV_WORK_CB(SendPluginCallback);
murgatroid998d4aec32015-09-24 10:54:55 -0700102
murgatroid99e5061512015-01-12 18:14:35 -0800103} // namespace node
murgatroid995f709ca2015-09-30 14:22:54 -0700104} // namepsace grpc
murgatroid99e5061512015-01-12 18:14:35 -0800105
murgatroid995f709ca2015-09-30 14:22:54 -0700106#endif // GRPC_NODE_CALL_CREDENTIALS_H_