call_credentials.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. *
  3. * Copyright 2015 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. #ifndef GRPC_NODE_CALL_CREDENTIALS_H_
  19. #define GRPC_NODE_CALL_CREDENTIALS_H_
  20. #include <queue>
  21. #include <nan.h>
  22. #include <node.h>
  23. #include <uv.h>
  24. #include "grpc/grpc_security.h"
  25. namespace grpc {
  26. namespace node {
  27. class CallCredentials : public Nan::ObjectWrap {
  28. public:
  29. static void Init(v8::Local<v8::Object> exports);
  30. static bool HasInstance(v8::Local<v8::Value> val);
  31. /* Wrap a grpc_call_credentials struct in a javascript object */
  32. static v8::Local<v8::Value> WrapStruct(grpc_call_credentials *credentials);
  33. /* Returns the grpc_call_credentials struct that this object wraps */
  34. grpc_call_credentials *GetWrappedCredentials();
  35. private:
  36. explicit CallCredentials(grpc_call_credentials *credentials);
  37. ~CallCredentials();
  38. // Prevent copying
  39. CallCredentials(const CallCredentials &);
  40. CallCredentials &operator=(const CallCredentials &);
  41. static NAN_METHOD(New);
  42. static NAN_METHOD(CreateSsl);
  43. static NAN_METHOD(CreateFromPlugin);
  44. static NAN_METHOD(Compose);
  45. static Nan::Callback *constructor;
  46. // Used for typechecking instances of this javascript class
  47. static Nan::Persistent<v8::FunctionTemplate> fun_tpl;
  48. grpc_call_credentials *wrapped_credentials;
  49. };
  50. /* Auth metadata plugin functionality */
  51. typedef struct plugin_callback_data {
  52. const char *service_url;
  53. grpc_credentials_plugin_metadata_cb cb;
  54. void *user_data;
  55. } plugin_callback_data;
  56. typedef struct plugin_state {
  57. Nan::Callback *callback;
  58. std::queue<plugin_callback_data *> *pending_callbacks;
  59. uv_mutex_t plugin_mutex;
  60. // async.data == this
  61. uv_async_t plugin_async;
  62. } plugin_state;
  63. void plugin_get_metadata(void *state, grpc_auth_metadata_context context,
  64. grpc_credentials_plugin_metadata_cb cb,
  65. void *user_data);
  66. void plugin_destroy_state(void *state);
  67. NAN_METHOD(PluginCallback);
  68. NAUV_WORK_CB(SendPluginCallback);
  69. } // namespace node
  70. } // namepsace grpc
  71. #endif // GRPC_NODE_CALL_CREDENTIALS_H_