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