PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/include/opensrf/transport_session.h

https://gitlab.com/evergreen-bjwebb/opensrf-debian
C Header | 130 lines | 77 code | 29 blank | 24 comment | 0 complexity | ac59d42967fdab807b9057b22cfd156c MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause
  1. #ifndef TRANSPORT_SESSION_H
  2. #define TRANSPORT_SESSION_H
  3. /**
  4. @file transport_session.h
  5. @brief Header for routines to manage a connection to a Jabber server.
  6. Manages a Jabber session. Reads messages from a socket and pushes them into a SAX parser
  7. as they arrive, responding to various Jabber document elements as they appear. When it
  8. sees the end of a complete message, it sends a representation of that message to the
  9. calling code via a callback function.
  10. */
  11. #include <opensrf/transport_message.h>
  12. #include <opensrf/utils.h>
  13. #include <opensrf/log.h>
  14. #include <opensrf/socket_bundle.h>
  15. #include "sha.h"
  16. #include <string.h>
  17. #include <libxml/globals.h>
  18. #include <libxml/xmlerror.h>
  19. #include <libxml/parser.h>
  20. #include <libxml/parserInternals.h> /* only for xmlNewInputFromFile() */
  21. #include <libxml/tree.h>
  22. #include <libxml/debugXML.h>
  23. #include <libxml/xmlmemory.h>
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. /** Note whether the login information should be sent as plaintext or as a hash digest. */
  28. enum TRANSPORT_AUTH_TYPE { AUTH_PLAIN, AUTH_DIGEST };
  29. // ---------------------------------------------------------------------------------
  30. // Jabber state machine. This is how we know where we are in the Jabber
  31. // conversation.
  32. // ---------------------------------------------------------------------------------
  33. struct jabber_state_machine_struct {
  34. int connected;
  35. int connecting;
  36. int in_message;
  37. int in_message_body;
  38. int in_thread;
  39. int in_subject;
  40. int in_error;
  41. int in_message_error;
  42. int in_iq;
  43. int in_presence;
  44. int in_status;
  45. };
  46. typedef struct jabber_state_machine_struct jabber_machine;
  47. /**
  48. @brief Collection of things for managing a Jabber session.
  49. */
  50. struct transport_session_struct {
  51. /* our socket connection */
  52. socket_manager* sock_mgr; /**< Manages the socket to the Jabber server. */
  53. /* our Jabber state machine */
  54. jabber_machine* state_machine; /**< Keeps track of where we are in the XML. */
  55. /* our SAX push parser context */
  56. xmlParserCtxtPtr parser_ctxt; /**< Used by the XML parser. */
  57. /* our text buffers for holding text data */
  58. growing_buffer* body_buffer; /**< Text of &lt;body&gt; of message stanza. */
  59. growing_buffer* subject_buffer; /**< Text of &lt;subject&gt; of message stanza. */
  60. growing_buffer* thread_buffer; /**< Text of &lt;thread&gt; of message stanza. */
  61. growing_buffer* from_buffer; /**< "from" attribute of &lt;message&gt;. */
  62. growing_buffer* recipient_buffer; /**< "to" attribute of &lt;message&gt;. */
  63. growing_buffer* status_buffer; /**< Text of &lt;status&gt; of message stanza. */
  64. growing_buffer* message_error_type; /**< "type" attribute of &lt;error&gt;. */
  65. growing_buffer* session_id; /**< "id" attribute of stream header. */
  66. int message_error_code; /**< "code" attribute of &lt;error&gt;. */
  67. /* for OILS extensions */
  68. growing_buffer* router_to_buffer; /**< "router_to" attribute of &lt;message&gt;. */
  69. growing_buffer* router_from_buffer; /**< "router_from" attribute of &lt;message&gt;. */
  70. growing_buffer* router_class_buffer; /**< "router_class" attribute of &lt;message&gt;. */
  71. growing_buffer* router_command_buffer; /**< "router_command" attribute of &lt;message&gt;. */
  72. growing_buffer* osrf_xid_buffer; /**< "osrf_xid" attribute of &lt;message&gt;. */
  73. int router_broadcast; /**< "broadcast" attribute of &lt;message&gt;. */
  74. void* user_data; /**< Opaque pointer from calling code. */
  75. char* server; /**< address of Jabber server. */
  76. char* unix_path; /**< Unix pathname (if any) of socket to Jabber server */
  77. int port; /**< Port number of Jabber server. */
  78. int sock_id; /**< File descriptor of socket to Jabber. */
  79. int component; /**< Boolean; true if we're a Jabber component. */
  80. /** Callback from calling code, for when a complete message stanza is received. */
  81. void (*message_callback) ( void* user_data, transport_message* msg );
  82. //void (iq_callback) ( void* user_data, transport_iq_message* iq );
  83. };
  84. typedef struct transport_session_struct transport_session;
  85. transport_session* init_transport( const char* server, int port,
  86. const char* unix_path, void* user_data, int component );
  87. int session_wait( transport_session* session, int timeout );
  88. int session_send_msg( transport_session* session, transport_message* msg );
  89. int session_connected( transport_session* session );
  90. int session_free( transport_session* session );
  91. int session_discard( transport_session* session );
  92. int session_connect( transport_session* session,
  93. const char* username, const char* password,
  94. const char* resource, int connect_timeout,
  95. enum TRANSPORT_AUTH_TYPE auth_type );
  96. int session_disconnect( transport_session* session );
  97. #ifdef __cplusplus
  98. }
  99. #endif
  100. #endif