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 };
38 struct jabber_state_machine_struct;
39 typedef struct jabber_state_machine_struct jabber_machine;
42 @brief Collection of things for managing a Jabber session.
44 struct transport_session_struct {
46 /* our socket connection */
47 socket_manager* sock_mgr; /**< Manages the socket to the Jabber server. */
49 /* our Jabber state machine */
50 jabber_machine* state_machine; /**< Keeps track of where we are in the XML. */
51 /* our SAX push parser context */
52 xmlParserCtxtPtr parser_ctxt; /**< Used by the XML parser. */
54 /* our text buffers for holding text data */
55 growing_buffer* body_buffer; /**< Text of <body> of message stanza. */
56 growing_buffer* subject_buffer; /**< Text of <subject> of message stanza. */
57 growing_buffer* thread_buffer; /**< Text of <thread> of message stanza. */
58 growing_buffer* from_buffer; /**< "from" attribute of <message>. */
59 growing_buffer* recipient_buffer; /**< "to" attribute of <message>. */
60 growing_buffer* status_buffer; /**< Text of <status> of message stanza. */
61 growing_buffer* message_error_type; /**< "type" attribute of <error>. */
62 growing_buffer* session_id; /**< "id" attribute of stream header. */
63 int message_error_code; /**< "code" attribute of <error>. */
65 /* for OILS extensions */
66 growing_buffer* router_to_buffer; /**< "router_to" attribute of <message>. */
67 growing_buffer* router_from_buffer; /**< "router_from" attribute of <message>. */
68 growing_buffer* router_class_buffer; /**< "router_class" attribute of <message>. */
69 growing_buffer* router_command_buffer; /**< "router_command" attribute of <message>. */
70 growing_buffer* osrf_xid_buffer; /**< "osrf_xid" attribute of <message>. */
71 int router_broadcast; /**< "broadcast" attribute of <message>. */
73 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. */
80 int component; /**< Boolean; true if we're a Jabber component. */
82 /** Callback from calling code, for when a complete message stanza is received. */
83 void (*message_callback) ( void* user_data, transport_message* msg );
84 //void (iq_callback) ( void* user_data, transport_iq_message* iq );
86 typedef struct transport_session_struct transport_session;
88 transport_session* init_transport( const char* server, int port,
89 const char* unix_path, void* user_data, int component );
91 int session_wait( transport_session* session, int timeout );
93 int session_send_msg( transport_session* session, transport_message* msg );
95 int session_connected( transport_session* session );
97 int session_free( transport_session* session );
99 int session_discard( transport_session* session );
101 int session_connect( transport_session* session,
102 const char* username, const char* password,
103 const char* resource, int connect_timeout,
104 enum TRANSPORT_AUTH_TYPE auth_type );
106 int session_disconnect( transport_session* session );