1 // ---------------------------------------------------------------------------------
2 // Manages the Jabber session. Data is taken from the TCP object and pushed into
3 // a SAX push parser as it arrives. When key Jabber documetn elements are met,
5 // ---------------------------------------------------------------------------------
6 #ifndef TRANSPORT_SESSION_H
7 #define TRANSPORT_SESSION_H
9 #include <opensrf/transport_message.h>
11 #include <opensrf/utils.h>
12 #include <opensrf/log.h>
13 #include <opensrf/socket_bundle.h>
18 #include <libxml/globals.h>
19 #include <libxml/xmlerror.h>
20 #include <libxml/parser.h>
21 #include <libxml/parserInternals.h> /* only for xmlNewInputFromFile() */
22 #include <libxml/tree.h>
23 #include <libxml/debugXML.h>
24 #include <libxml/xmlmemory.h>
30 #define CONNECTING_1 1 /* just starting the connection to Jabber */
31 #define CONNECTING_2 2 /* First <stream> packet sent and <stream> packet received from server */
33 /* Note. these are growing buffers, so all that's necessary is a sane starting point */
34 #define JABBER_BODY_BUFSIZE 4096
35 #define JABBER_SUBJECT_BUFSIZE 64
36 #define JABBER_THREAD_BUFSIZE 64
37 #define JABBER_JID_BUFSIZE 64
38 #define JABBER_STATUS_BUFSIZE 16
40 // ---------------------------------------------------------------------------------
41 // Jabber state machine. This is how we know where we are in the Jabber
43 // ---------------------------------------------------------------------------------
44 struct jabber_state_machine_struct {
57 typedef struct jabber_state_machine_struct jabber_machine;
60 enum TRANSPORT_AUTH_TYPE { AUTH_PLAIN, AUTH_DIGEST };
62 // ---------------------------------------------------------------------------------
63 // Transport session. This maintains all the various parts of a session
64 // ---------------------------------------------------------------------------------
65 struct transport_session_struct {
67 /* our socket connection */
68 socket_manager* sock_mgr;
70 /* our Jabber state machine */
71 jabber_machine* state_machine;
72 /* our SAX push parser context */
73 xmlParserCtxtPtr parser_ctxt;
75 /* our text buffers for holding text data */
76 growing_buffer* body_buffer;
77 growing_buffer* subject_buffer;
78 growing_buffer* thread_buffer;
79 growing_buffer* from_buffer;
80 growing_buffer* recipient_buffer;
81 growing_buffer* status_buffer;
82 growing_buffer* message_error_type;
83 growing_buffer* session_id;
84 int message_error_code;
86 /* for OILS extenstions */
87 growing_buffer* router_to_buffer;
88 growing_buffer* router_from_buffer;
89 growing_buffer* router_class_buffer;
90 growing_buffer* router_command_buffer;
91 growing_buffer* osrf_xid_buffer;
94 /* this can be anything. It will show up in the
95 callbacks for your convenience. Otherwise, it's
104 int component; /* true if we're a component */
106 /* the Jabber message callback */
107 void (*message_callback) ( void* user_data, transport_message* msg );
108 //void (iq_callback) ( void* user_data, transport_iq_message* iq );
110 typedef struct transport_session_struct transport_session;
113 // ------------------------------------------------------------------
114 // Allocates and initializes the necessary transport session
116 // If port > 0, then this session uses TCP connection. Otherwise,
117 // if unix_path != NULL, it uses a UNIX domain socket.
118 // ------------------------------------------------------------------
119 transport_session* init_transport( const char* server, int port,
120 const char* unix_path, void* user_data, int component );
122 // ------------------------------------------------------------------
123 // Waits at most 'timeout' seconds for data to arrive from the
124 // TCP handler. A timeout of -1 means to wait indefinitely.
125 // ------------------------------------------------------------------
126 int session_wait( transport_session* session, int timeout );
128 // ---------------------------------------------------------------------------------
129 // Sends the given Jabber message
130 // ---------------------------------------------------------------------------------
131 int session_send_msg( transport_session* session, transport_message* msg );
133 // ---------------------------------------------------------------------------------
134 // Returns 1 if this session is connected to the jabber server. 0 otherwise
135 // ---------------------------------------------------------------------------------
136 int session_connected( transport_session* );
138 // ------------------------------------------------------------------
139 // Deallocates session memory
140 // ------------------------------------------------------------------
141 int session_free( transport_session* session );
143 // ------------------------------------------------------------------
144 // Connects to the Jabber server. Waits at most connect_timeout
145 // seconds before failing
146 // ------------------------------------------------------------------
147 int session_connect( transport_session* session,
148 const char* username, const char* password,
149 const char* resource, int connect_timeout,
150 enum TRANSPORT_AUTH_TYPE auth_type );
152 int session_disconnect( transport_session* session );