]> git.evergreen-ils.org Git - OpenSRF.git/blob - include/opensrf/transport_session.h
Close a substantial resource leak in drone processes.
[OpenSRF.git] / include / opensrf / transport_session.h
1 #ifndef TRANSPORT_SESSION_H
2 #define TRANSPORT_SESSION_H
3
4 /**
5         @file transport_session.h
6         @brief Header for routines to manage a connection to a Jabber server.
7
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.
12 */
13
14 #include <opensrf/transport_message.h>
15
16 #include <opensrf/utils.h>
17 #include <opensrf/log.h>
18 #include <opensrf/socket_bundle.h>
19
20 #include "sha.h"
21
22 #include <string.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>
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
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 };
37
38 struct jabber_state_machine_struct;
39 typedef struct jabber_state_machine_struct jabber_machine;
40
41 /**
42         @brief Collection of things for managing a Jabber session.
43 */
44 struct transport_session_struct {
45
46         /* our socket connection */
47         socket_manager* sock_mgr;             /**< Manages the socket to the Jabber server. */
48
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. */
53
54         /* our text buffers for holding text data */
55         growing_buffer* body_buffer;          /**< Text of &lt;body&gt; of message stanza. */
56         growing_buffer* subject_buffer;       /**< Text of &lt;subject&gt; of message stanza. */
57         growing_buffer* thread_buffer;        /**< Text of &lt;thread&gt; of message stanza. */
58         growing_buffer* from_buffer;          /**< "from" attribute of &lt;message&gt;. */
59         growing_buffer* recipient_buffer;     /**< "to" attribute of &lt;message&gt;. */
60         growing_buffer* status_buffer;        /**< Text of &lt;status&gt; of message stanza. */
61         growing_buffer* message_error_type;   /**< "type" attribute of &lt;error&gt;. */
62         growing_buffer* session_id;           /**< "id" attribute of stream header. */
63         int message_error_code;               /**< "code" attribute of &lt;error&gt;. */
64
65         /* for OILS extensions */
66         growing_buffer* router_to_buffer;     /**< "router_to" attribute of &lt;message&gt;. */
67         growing_buffer* router_from_buffer;   /**< "router_from" attribute of &lt;message&gt;. */
68         growing_buffer* router_class_buffer;  /**< "router_class" attribute of &lt;message&gt;. */
69         growing_buffer* router_command_buffer; /**< "router_command" attribute of &lt;message&gt;. */
70         growing_buffer* osrf_xid_buffer;      /**< "osrf_xid" attribute of &lt;message&gt;. */
71         int router_broadcast;                 /**< "broadcast" attribute of &lt;message&gt;. */
72
73         void* user_data;                      /**< Opaque pointer from calling code. */
74
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
80         int component;                        /**< Boolean; true if we're a Jabber component. */
81
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 );
85 };
86 typedef struct transport_session_struct transport_session;
87
88 transport_session* init_transport( const char* server, int port,
89         const char* unix_path, void* user_data, int component );
90
91 int session_wait( transport_session* session, int timeout );
92
93 int session_send_msg( transport_session* session, transport_message* msg );
94
95 int session_connected( transport_session* session );
96
97 int session_free( transport_session* session );
98
99 int session_discard( transport_session* session );
100
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 );
105
106 int session_disconnect( transport_session* session );
107
108 #ifdef __cplusplus
109 }
110 #endif
111
112 #endif