]> git.evergreen-ils.org Git - OpenSRF.git/blob - include/opensrf/transport_client.h
924605ff2d3678655bbe513e90cd5ba13b2b98ee
[OpenSRF.git] / include / opensrf / transport_client.h
1 #ifndef TRANSPORT_CLIENT_H
2 #define TRANSPORT_CLIENT_H
3
4 #include <time.h>
5 #include <opensrf/transport_session.h>
6 #include <opensrf/utils.h>
7 #include <opensrf/log.h>
8
9 struct message_list_struct;
10
11 // ---------------------------------------------------------------------------
12 // Our client struct.  We manage a list of messages and a controlling session
13 // ---------------------------------------------------------------------------
14 struct transport_client_struct {
15         transport_message* msg_q_head;
16         transport_message* msg_q_tail;
17         transport_session* session;
18         int error;
19 };
20 typedef struct transport_client_struct transport_client;
21
22 // ---------------------------------------------------------------------------
23 // Allocates and initializes a transport_client.  This does no connecting
24 // The user must call client_free(client) when finished with the allocated
25 // object.
26 // if port > 0 => connect via TCP
27 // else if unix_path != NULL => connect via UNIX socket
28 // ---------------------------------------------------------------------------
29 transport_client* client_init( const char* server, int port, const char* unix_path, int component );
30
31
32 // ---------------------------------------------------------------------------
33 // Connects to the Jabber server with the provided information. Returns 1 on
34 // success, 0 otherwise.
35 // ---------------------------------------------------------------------------
36 int client_connect( transport_client* client, 
37                 const char* username, const char* password, const char* resource,
38                 int connect_timeout, enum TRANSPORT_AUTH_TYPE auth_type );
39
40
41 int client_disconnect( transport_client* client );
42
43 // ---------------------------------------------------------------------------
44 // De-allocates memory associated with a transport_client object.  Users
45 // must use this method when finished with a client object.
46 // ---------------------------------------------------------------------------
47 int client_free( transport_client* client );
48
49 // ---------------------------------------------------------------------------
50 // Sends the given message.  The message must at least have the recipient
51 // field set.
52 // ---------------------------------------------------------------------------
53 int client_send_message( transport_client* client, transport_message* msg );
54
55 // ---------------------------------------------------------------------------
56 // Returns 1 if this client is currently connected to the server, 0 otherwise
57 // ---------------------------------------------------------------------------
58 int client_connected( const transport_client* client );
59
60 // ---------------------------------------------------------------------------
61 // If there are any messages in the message list, the 'oldest' message is
62 // returned.  If not, this function will wait at most 'timeout' seconds 
63 // for a message to arrive.  Specifying -1 means that this function will not
64 // return unless a message arrives.
65 // ---------------------------------------------------------------------------
66 transport_message* client_recv( transport_client* client, int timeout );
67
68
69 #endif