]> git.evergreen-ils.org Git - working/Evergreen.git/blob - OpenSRF/src/jserver/jserver-c.h
36026ec40ab3d96b31b6070440309523e0de79d4
[working/Evergreen.git] / OpenSRF / src / jserver / jserver-c.h
1 #include "utils.h"
2 #include "logging.h"
3 #include "socket_bundle.h"
4 #include "jserver-c_session.h"
5
6
7
8 struct jclient_node_struct {
9         int id;
10         char* addr;
11         struct jclient_node_struct* next;
12         jserver_session* session;
13         struct jserver_struct* parent;
14 };
15 typedef struct jclient_node_struct jclient_node;
16
17 struct jserver_struct {
18         jclient_node* client;
19         socket_manager* mgr;
20 };
21 typedef struct jserver_struct jserver;
22
23 /* allocats and sets up a new jserver */
24 jserver* jserver_init();
25
26 void jserver_socket_closed(void* blob, int sock_id);
27
28 /* disconnects all client, deallocates the server and all clients */
29 void jserver_free();
30
31 /* opens the inet and unix sockets that we're listening on 
32         listen_ip is the IP address the server should listen on.
33         if listen_ip is NULL, jserver will bind to all local IP's. 
34         if(port < 1) no inet socket is opened
35         if unix_path == NULL no unix socket is opened
36         returns -1 on error */
37 int jserver_connect(jserver* js, int port, char* listen_ip, char* unix_path);
38
39 /* allocates a new client node */
40 jclient_node* _new_jclient_node(int id);
41
42 void _free_jclient_node(jclient_node* node);
43
44 int _jserver_push_client_data(jclient_node* node, char* data);
45
46 void jclient_on_parse_error(void* blob, jserver_session* session);
47
48 /* called when a newly connected client reveals its address */
49 void jserver_client_from_found(void* blob, char* from);
50 void jserver_client_login_init(void* blob, char* reply);
51 void jserver_client_login_ok(void* blob);
52 void jserver_client_finish(void* blob);
53
54 /* allocates a new client node and adds it to the set */
55 jclient_node* _jserver_add_client(jserver* js, int id);
56
57 /* removes and frees a client node */
58 void _jserver_remove_client(jserver* js, char* addr);
59
60 void _jserver_remove_client_id(jserver* js, int id);
61
62 /* finds a client node by addr */
63 jclient_node* jserver_find_client(jserver* js, char* addr);
64
65 jclient_node* jserver_find_client_id(jserver* js, int id);
66
67 /* sends msg to client at 'to_addr'. from_id is the id
68         of the sending client (if from_id > 0). used for error replies */
69 int jserver_send(jserver* js, int from_id, char* to_addr, const char* msg_xml);
70
71 /* send the data to the client with client_id */
72 int jserver_send_id(int client_id, const char* msg_xml);
73
74 /* waits for any incoming data */
75 int jserver_wait(jserver* js);
76
77 /* handles all incoming socket data */
78 void jserver_handle_request(void* js, 
79         socket_manager* mgr, int sock_id, char* data, int parent_id ); 
80
81
82 /* called by the jserver_session when any client has a 
83         complete message parsed and ready to forward on */
84 void jserver_client_handle_msg( 
85                 void* blob, char* xml, char* from, char* to );