824b5042e8655301ce64ee907f9dc52e9e9ab63f
[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 the Jabber session.  Reads data from a socket and pushes it into a SAX
9         parser as it arrives.  When key Jabber document elements are met, logic ensues.
10 */
11
12 #include <opensrf/transport_message.h>
13
14 #include <opensrf/utils.h>
15 #include <opensrf/log.h>
16 #include <opensrf/socket_bundle.h>
17
18 #include "sha.h"
19
20 #include <string.h>
21 #include <libxml/globals.h>
22 #include <libxml/xmlerror.h>
23 #include <libxml/parser.h>
24 #include <libxml/parserInternals.h> /* only for xmlNewInputFromFile() */
25 #include <libxml/tree.h>
26 #include <libxml/debugXML.h>
27 #include <libxml/xmlmemory.h>
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 enum TRANSPORT_AUTH_TYPE { AUTH_PLAIN, AUTH_DIGEST };
34
35 struct jabber_state_machine_struct;
36 typedef struct jabber_state_machine_struct jabber_machine;
37
38 // ---------------------------------------------------------------------------------
39 // Transport session.  This maintains all the various parts of a session
40 // ---------------------------------------------------------------------------------
41 struct transport_session_struct {
42
43         /* our socket connection */
44         socket_manager* sock_mgr;
45
46         /* our Jabber state machine */
47         jabber_machine* state_machine;
48         /* our SAX push parser context */
49         xmlParserCtxtPtr parser_ctxt;
50
51         /* our text buffers for holding text data */
52         growing_buffer* body_buffer;
53         growing_buffer* subject_buffer;
54         growing_buffer* thread_buffer;
55         growing_buffer* from_buffer;
56         growing_buffer* recipient_buffer;
57         growing_buffer* status_buffer;
58         growing_buffer* message_error_type;
59         growing_buffer* session_id;
60         int message_error_code;
61
62         /* for OILS extenstions */
63         growing_buffer* router_to_buffer;
64         growing_buffer* router_from_buffer;
65         growing_buffer* router_class_buffer;
66         growing_buffer* router_command_buffer;
67         growing_buffer* osrf_xid_buffer;
68         int router_broadcast;
69
70         /* this can be anything.  It will show up in the
71                 callbacks for your convenience. Otherwise, it's
72                 left untouched.  */
73         void* user_data;
74
75         char* server;
76         char* unix_path;
77         int     port;
78         int sock_id;
79
80         int component; /* true if we're a component */
81
82         /* the Jabber message callback */
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 // ---------------------------------------------------------------------------------
94 // Sends the given Jabber message
95 // ---------------------------------------------------------------------------------
96 int session_send_msg( transport_session* session, transport_message* msg );
97
98 int session_connected( transport_session* session );
99
100 int session_free( transport_session* session );
101
102 int session_connect( transport_session* session,
103                 const char* username, const char* password,
104                 const char* resource, int connect_timeout,
105                 enum TRANSPORT_AUTH_TYPE auth_type );
106
107 int session_disconnect( transport_session* session );
108
109 #ifdef __cplusplus
110 }
111 #endif
112
113 #endif