1 #ifndef TRANSPORT_SESSION_H
2 #define TRANSPORT_SESSION_H
5 @file transport_session.h
6 @brief Header for routines to manage a connection to a Jabber server.
8 Manages a Jabber session. Reads messages from a socket and pushes them into a SAX parser
9 as they arrive, responding to various Jabber document elements as they appear. When it
10 sees the end of a complete message, it sends a representation of that message to the
11 calling code via a callback function.
14 #include <opensrf/transport_message.h>
16 #include <opensrf/utils.h>
17 #include <opensrf/log.h>
18 #include <opensrf/socket_bundle.h>
23 #include <libxml/globals.h>
24 #include <libxml/xmlerror.h>
25 #include <libxml/parser.h>
26 #include <libxml/parserInternals.h> /* only for xmlNewInputFromFile() */
27 #include <libxml/tree.h>
28 #include <libxml/debugXML.h>
29 #include <libxml/xmlmemory.h>
35 /** Note whether the login information should be sent as plaintext or as a hash digest. */
36 enum TRANSPORT_AUTH_TYPE { AUTH_PLAIN, AUTH_DIGEST };
39 // ---------------------------------------------------------------------------------
40 // Jabber state machine. This is how we know where we are in the Jabber
42 // ---------------------------------------------------------------------------------
43 struct jabber_state_machine_struct {
56 typedef struct jabber_state_machine_struct jabber_machine;
60 @brief Collection of things for managing a Jabber session.
62 struct transport_session_struct {
64 /* our socket connection */
65 socket_manager* sock_mgr; /**< Manages the socket to the Jabber server. */
67 /* our Jabber state machine */
68 jabber_machine* state_machine; /**< Keeps track of where we are in the XML. */
69 /* our SAX push parser context */
70 xmlParserCtxtPtr parser_ctxt; /**< Used by the XML parser. */
72 /* our text buffers for holding text data */
73 growing_buffer* body_buffer; /**< Text of <body> of message stanza. */
74 growing_buffer* subject_buffer; /**< Text of <subject> of message stanza. */
75 growing_buffer* thread_buffer; /**< Text of <thread> of message stanza. */
76 growing_buffer* from_buffer; /**< "from" attribute of <message>. */
77 growing_buffer* recipient_buffer; /**< "to" attribute of <message>. */
78 growing_buffer* status_buffer; /**< Text of <status> of message stanza. */
79 growing_buffer* message_error_type; /**< "type" attribute of <error>. */
80 growing_buffer* session_id; /**< "id" attribute of stream header. */
81 int message_error_code; /**< "code" attribute of <error>. */
83 /* for OILS extensions */
84 growing_buffer* router_to_buffer; /**< "router_to" attribute of <message>. */
85 growing_buffer* router_from_buffer; /**< "router_from" attribute of <message>. */
86 growing_buffer* router_class_buffer; /**< "router_class" attribute of <message>. */
87 growing_buffer* router_command_buffer; /**< "router_command" attribute of <message>. */
88 growing_buffer* osrf_xid_buffer; /**< "osrf_xid" attribute of <message>. */
89 int router_broadcast; /**< "broadcast" attribute of <message>. */
91 void* user_data; /**< Opaque pointer from calling code. */
93 char* server; /**< address of Jabber server. */
94 char* unix_path; /**< Unix pathname (if any) of socket to Jabber server */
95 int port; /**< Port number of Jabber server. */
96 int sock_id; /**< File descriptor of socket to Jabber. */
98 int component; /**< Boolean; true if we're a Jabber component. */
100 /** Callback from calling code, for when a complete message stanza is received. */
101 void (*message_callback) ( void* user_data, transport_message* msg );
102 //void (iq_callback) ( void* user_data, transport_iq_message* iq );
104 typedef struct transport_session_struct transport_session;
106 transport_session* init_transport( const char* server, int port,
107 const char* unix_path, void* user_data, int component );
109 int session_wait( transport_session* session, int timeout );
111 int session_send_msg( transport_session* session, transport_message* msg );
113 int session_connected( transport_session* session );
115 int session_free( transport_session* session );
117 int session_discard( transport_session* session );
119 int session_connect( transport_session* session,
120 const char* username, const char* password,
121 const char* resource, int connect_timeout,
122 enum TRANSPORT_AUTH_TYPE auth_type );
124 int session_disconnect( transport_session* session );