]> git.evergreen-ils.org Git - OpenSRF.git/blob - include/opensrf/transport_client.h
Patches from Scott McKellar covering:
[OpenSRF.git] / include / opensrf / transport_client.h
1 #include <opensrf/transport_session.h>
2 #include <opensrf/utils.h>
3 #include <opensrf/log.h>
4
5 #include <time.h>
6
7 #ifndef TRANSPORT_CLIENT_H
8 #define TRANSPORT_CLIENT_H
9
10 #define MESSAGE_LIST_HEAD 1
11 #define MESSAGE_LIST_ITEM 2
12
13
14 // ---------------------------------------------------------------------------
15 // Represents a node in a linked list.  The node holds a pointer to the next
16 // node (which is null unless set), a pointer to a transport_message, and
17 // and a type variable (which is not really curently necessary).
18 // ---------------------------------------------------------------------------
19 struct message_list_struct {
20         struct message_list_struct* next;
21         transport_message* message;
22         int type;
23 };
24
25 typedef struct message_list_struct transport_message_list;
26 typedef struct message_list_struct transport_message_node;
27
28 // ---------------------------------------------------------------------------
29 // Our client struct.  We manage a list of messages and a controlling session
30 // ---------------------------------------------------------------------------
31 struct transport_client_struct {
32         transport_message_list* m_list;
33         transport_session* session;
34         int error;
35 };
36 typedef struct transport_client_struct transport_client;
37
38 // ---------------------------------------------------------------------------
39 // Allocates and initializes and transport_client.  This does no connecting
40 // The user must call client_free(client) when finished with the allocated
41 // object.
42 // if port > 0 => connect via TCP
43 // else if unix_path != NULL => connect via UNIX socket
44 // ---------------------------------------------------------------------------
45 transport_client* client_init( const char* server, int port, const char* unix_path, int component );
46
47
48 // ---------------------------------------------------------------------------
49 // Connects to the Jabber server with the provided information. Returns 1 on
50 // success, 0 otherwise.
51 // ---------------------------------------------------------------------------
52 int client_connect( transport_client* client, 
53                 char* username, char* password, char* resource, 
54                 int connect_timeout, enum TRANSPORT_AUTH_TYPE auth_type );
55
56
57 int client_disconnect( transport_client* client );
58
59 // ---------------------------------------------------------------------------
60 // De-allocates memory associated with a transport_client object.  Users
61 // must use this method when finished with a client object.
62 // ---------------------------------------------------------------------------
63 int client_free( transport_client* client );
64
65 // ---------------------------------------------------------------------------
66 //  Sends the given message.  The message must at least have the recipient
67 // field set.
68 // ---------------------------------------------------------------------------
69 int client_send_message( transport_client* client, transport_message* msg );
70
71 // ---------------------------------------------------------------------------
72 // Returns 1 if this client is currently connected to the server, 0 otherwise
73 // ---------------------------------------------------------------------------
74 int client_connected( transport_client* client );
75
76 // ---------------------------------------------------------------------------
77 // This is the message handler required by transport_session.  This handler
78 // takes all incoming messages and puts them into the back of a linked list
79 // of messages.  
80 // ---------------------------------------------------------------------------
81 void client_message_handler( void* client, transport_message* msg );
82
83 // ---------------------------------------------------------------------------
84 // If there are any message in the message list, the 'oldest' message is
85 // returned.  If not, this function will wait at most 'timeout' seconds 
86 // for a message to arrive.  Specifying -1 means that this function will not
87 // return unless a message arrives.
88 // ---------------------------------------------------------------------------
89 transport_message* client_recv( transport_client* client, int timeout );
90
91
92 #endif