session.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * Copyright (c) 2018-2019 SignalWire, Inc
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in all
  12. * copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. #pragma once
  23. KS_BEGIN_EXTERN_C
  24. /* Obfuscate our session internals */
  25. typedef struct swclt_sess_ctx swclt_sess_ctx_t;
  26. typedef void (*swclt_sess_auth_failed_cb_t)(swclt_sess_t sess);
  27. SWCLT_DECLARE(ks_status_t) __swclt_sess_create(
  28. swclt_sess_t *sess,
  29. const char *identity_uri,
  30. swclt_config_t *config,
  31. const char *file,
  32. int line,
  33. const char *tag);
  34. #define swclt_sess_create(sess, ident, cfg) __swclt_sess_create(sess, ident, cfg, __FILE__, __LINE__, __PRETTY_FUNCTION__)
  35. SWCLT_DECLARE(ks_status_t) swclt_sess_set_auth_failed_cb(swclt_sess_t sess, swclt_sess_auth_failed_cb_t cb);
  36. SWCLT_DECLARE(ks_status_t) swclt_sess_target_set(swclt_sess_t sess, const char *target);
  37. SWCLT_DECLARE(ks_status_t) swclt_sess_metric_register(swclt_sess_t sess, const char *protocol, int interval, int rank);
  38. SWCLT_DECLARE(ks_status_t) swclt_sess_metric_update(swclt_sess_t sess, const char *protocol, int rank);
  39. SWCLT_DECLARE(ks_status_t) swclt_sess_metric_current(swclt_sess_t sess, const char *protocol, int *rank);
  40. SWCLT_DECLARE(ks_bool_t) swclt_sess_has_authentication(swclt_sess_t sess);
  41. SWCLT_DECLARE(ks_status_t) swclt_sess_rescan_env_config(swclt_sess_t sess);
  42. SWCLT_DECLARE(ks_status_t) swclt_sess_connect(swclt_sess_t sess);
  43. SWCLT_DECLARE(ks_status_t) swclt_sess_disconnect(swclt_sess_t sess);
  44. SWCLT_DECLARE(ks_bool_t) swclt_sess_connected(swclt_sess_t sess);
  45. SWCLT_DECLARE(ks_bool_t) swclt_sess_restored(swclt_sess_t sess);
  46. SWCLT_DECLARE(ks_status_t) swclt_sess_info(swclt_sess_t sess, ks_pool_t *pool, ks_uuid_t *sessionid, char **nodeid, char **master_nodeid);
  47. SWCLT_DECLARE(ks_status_t) swclt_sess_nodeid(swclt_sess_t sess, ks_pool_t *pool, char **nodeid);
  48. SWCLT_DECLARE(ks_bool_t) swclt_sess_nodeid_local(swclt_sess_t sess, const char *nodeid);
  49. SWCLT_DECLARE(ks_status_t) __swclt_sess_register_protocol_method(
  50. swclt_sess_t sess,
  51. const char *protocol,
  52. const char *method,
  53. swclt_pmethod_cb_t pmethod,
  54. void *cb_data);
  55. #define swclt_sess_register_protocol_method(sess, protocol, method, pmethod, cb_data) \
  56. __swclt_sess_register_protocol_method(sess, protocol, method, pmethod, cb_data)
  57. SWCLT_DECLARE(ks_status_t) swclt_sess_register_subscription_method(
  58. swclt_sess_t sess,
  59. swclt_sub_t *sub,
  60. const char *protocol,
  61. const char *channel,
  62. swclt_sub_cb_t cb,
  63. void *cb_data);
  64. SWCLT_DECLARE(ks_status_t) swclt_sess_broadcast(
  65. swclt_sess_t sess,
  66. const char *protocol,
  67. const char *channel,
  68. const char *event,
  69. ks_json_t **params);
  70. SWCLT_DECLARE(ks_status_t) swclt_sess_subscription_add(
  71. swclt_sess_t sess,
  72. const char *protocol,
  73. const char *channel,
  74. swclt_sub_cb_t cb,
  75. void *cb_data,
  76. swclt_sub_t *sub,
  77. swclt_cmd_t *cmdP);
  78. SWCLT_DECLARE(ks_status_t) swclt_sess_subscription_add_async(
  79. swclt_sess_t sess,
  80. const char *protocol,
  81. const char *channel,
  82. swclt_sub_cb_t cb,
  83. void *cb_data,
  84. swclt_sub_t *sub,
  85. swclt_cmd_cb_t response_callback,
  86. void *response_callback_data,
  87. swclt_cmd_t *cmdP);
  88. SWCLT_DECLARE(ks_status_t) swclt_sess_subscription_remove(
  89. swclt_sess_t sess,
  90. const char *protocol,
  91. const char *channel,
  92. swclt_cmd_t *cmdP);
  93. SWCLT_DECLARE(ks_status_t) swclt_sess_subscription_remove_async(
  94. swclt_sess_t sess,
  95. const char *protocol,
  96. const char *channel,
  97. swclt_cmd_cb_t response_callback,
  98. void *response_callback_data,
  99. swclt_cmd_t *cmd);
  100. SWCLT_DECLARE(ks_status_t) swclt_sess_protocol_provider_add(
  101. swclt_sess_t sess,
  102. const char * protocol,
  103. blade_access_control_t default_method_execute_access,
  104. blade_access_control_t default_channel_subscribe_access,
  105. blade_access_control_t default_channel_broadcast_access,
  106. ks_json_t **methods,
  107. ks_json_t **channels,
  108. int rank,
  109. ks_json_t **data,
  110. swclt_cmd_t *cmdP);
  111. SWCLT_DECLARE(ks_status_t) swclt_sess_protocol_provider_add_async(
  112. swclt_sess_t sess,
  113. const char * protocol,
  114. blade_access_control_t default_method_execute_access,
  115. blade_access_control_t default_channel_subscribe_access,
  116. blade_access_control_t default_channel_broadcast_access,
  117. ks_json_t **methods,
  118. ks_json_t **channels,
  119. int rank,
  120. ks_json_t **data,
  121. swclt_cmd_cb_t response_callback,
  122. void *response_callback_data,
  123. swclt_cmd_t *cmd);
  124. SWCLT_DECLARE(ks_status_t) swclt_sess_protocol_provider_remove(swclt_sess_t sess, const char * protocol, swclt_cmd_t *cmdP);
  125. SWCLT_DECLARE(ks_status_t) swclt_sess_protocol_provider_remove_async(
  126. swclt_sess_t sess,
  127. const char * protocol,
  128. swclt_cmd_cb_t response_callback,
  129. void *response_callback_data,
  130. swclt_cmd_t *cmdP);
  131. SWCLT_DECLARE(ks_status_t) swclt_sess_protocol_provider_rank_update(
  132. swclt_sess_t sess,
  133. const char * protocol,
  134. int rank,
  135. swclt_cmd_t *cmdP);
  136. SWCLT_DECLARE(ks_status_t) swclt_sess_protocol_provider_rank_update_async(
  137. swclt_sess_t sess,
  138. const char * protocol,
  139. int rank,
  140. swclt_cmd_cb_t response_callback,
  141. void *response_callback_data,
  142. swclt_cmd_t *cmd);
  143. SWCLT_DECLARE(ks_status_t) swclt_sess_identity_add(swclt_sess_t sess, const char *identity, swclt_cmd_t *cmdP);
  144. SWCLT_DECLARE(ks_status_t) swclt_sess_identity_add_async(
  145. swclt_sess_t sess,
  146. const char *identity,
  147. swclt_cmd_cb_t response_callback,
  148. void *response_callback_data,
  149. swclt_cmd_t *cmd);
  150. SWCLT_DECLARE(ks_status_t) swclt_sess_execute(
  151. swclt_sess_t sess,
  152. const char *responder,
  153. const char *protocol,
  154. const char *method,
  155. ks_json_t **params,
  156. swclt_cmd_t *cmdP);
  157. SWCLT_DECLARE(ks_status_t) swclt_sess_nodestore(swclt_sess_t sess, swclt_store_t *store);
  158. SWCLT_DECLARE(ks_status_t) swclt_sess_execute_async(
  159. swclt_sess_t sess,
  160. const char *responder,
  161. const char *protocol,
  162. const char *method,
  163. ks_json_t **params,
  164. swclt_cmd_cb_t response_callback,
  165. void *response_callback_data,
  166. swclt_cmd_t *cmdP);
  167. SWCLT_DECLARE(ks_status_t) swclt_sess_nodestore(swclt_sess_t sess, swclt_store_t *store);
  168. #define swclt_sess_get(sess, contextP) __ks_handle_get(SWCLT_HTYPE_SESS, sess, (ks_handle_base_t**)contextP, __FILE__, __LINE__, __PRETTY_FUNCTION__)
  169. #define swclt_sess_put(contextP) __ks_handle_put(SWCLT_HTYPE_SESS, (ks_handle_base_t**)contextP, __FILE__, __LINE__, __PRETTY_FUNCTION__)
  170. SWCLT_DECLARE(ks_status_t) swclt_sess_signalwire_setup(swclt_sess_t sess, const char *service, swclt_sub_cb_t cb, void *cb_data);
  171. SWCLT_DECLARE(ks_status_t) swclt_sess_provisioning_setup(swclt_sess_t sess, swclt_sub_cb_t cb, void *cb_data);
  172. SWCLT_DECLARE(ks_status_t) swclt_sess_provisioning_configure(swclt_sess_t sess,
  173. const char *target,
  174. const char *local_endpoint,
  175. const char *external_endpoint,
  176. const char *relay_connector_id,
  177. swclt_cmd_t *cmdP);
  178. SWCLT_DECLARE(ks_status_t) swclt_sess_provisioning_configure_async(swclt_sess_t sess,
  179. const char *target,
  180. const char *local_endpoint,
  181. const char *external_endpoint,
  182. const char *relay_connector_id,
  183. swclt_cmd_cb_t response_callback,
  184. void *response_callback_data,
  185. swclt_cmd_t *cmdP);
  186. KS_END_EXTERN_C
  187. /* For Emacs:
  188. * Local Variables:
  189. * mode:c
  190. * indent-tabs-mode:t
  191. * tab-width:4
  192. * c-basic-offset:4
  193. * End:
  194. * For VIM:
  195. * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
  196. */