]> git.evergreen-ils.org Git - Evergreen.git/blob - OpenSRF/src/router/osrf_router.h
clark knows how to use custom widget filter code now
[Evergreen.git] / OpenSRF / src / router / osrf_router.h
1 #include <sys/select.h>
2 #include <signal.h>
3 #include <stdio.h>
4
5 #include "opensrf/utils.h"
6 #include "opensrf/log.h"
7 #include "opensrf/osrf_list.h"
8 #include "opensrf/osrf_hash.h"
9
10 #include "opensrf/string_array.h"
11 #include "opensrf/transport_client.h"
12 #include "opensrf/transport_message.h"
13
14 #include "opensrf/osrf_message.h"
15
16
17
18 /* a router maintains a list of server classes */
19 struct __osrfRouterStruct {
20
21         osrfHash* classes;      /* our list of server classes */
22         char* domain;                   /* our login domain */
23         char* name;
24         char* resource;
25         char* password;
26         int port;
27
28         osrfStringArray* trustedClients;
29         osrfStringArray* trustedServers;
30
31         transport_client* connection;
32 };
33
34 typedef struct __osrfRouterStruct osrfRouter;
35
36
37 /* a class maintains a set of server nodes */
38 struct __osrfRouterClassStruct {
39         osrfRouter* router; /* our router handle */
40         osrfHashIterator* itr;
41         osrfHash* nodes;
42         transport_client* connection;
43 };
44 typedef struct __osrfRouterClassStruct osrfRouterClass;
45
46 /* represents a link to a single server's inbound connection */
47 struct __osrfRouterNodeStruct {
48         char* remoteId; /* send message to me via this login */
49         int count;                      /* how many message have been sent to this node */
50         transport_message* lastMessage;
51 };
52 typedef struct __osrfRouterNodeStruct osrfRouterNode;
53
54 /**
55   Allocates a new router.  
56   @param domain The jabber domain to connect to
57   @param name The login name for the router
58   @param resource The login resource for the router
59   @param password The login password for the new router
60   @param port The port to connect to the jabber server on
61   @param trustedClients The array of client domains that we allow to send requests through us
62   @param trustedServers The array of server domains that we allow to register, etc. with ust.
63   @return The allocated router or NULL on memory error
64   */
65 osrfRouter* osrfNewRouter( char* domain, char* name, char* resource, 
66         char* password, int port, osrfStringArray* trustedClients, osrfStringArray* trustedServers );
67
68 /**
69   Connects the given router to the network
70   */
71 int osrfRouterConnect( osrfRouter* router );
72
73 /**
74   Waits for incoming data to route
75   If this function returns, then the router's connection to the jabber server
76   has failed.
77   */
78 void osrfRouterRun( osrfRouter* router );
79
80
81 /**
82   Allocates and adds a new router class handler to the router's list of handlers.
83   Also connects the class handler to the network at <routername>@domain/<classname>
84   @param router The current router instance
85   @param classname The name of the class this node handles.
86   @return 0 on success, -1 on connection error.
87   */
88 osrfRouterClass* osrfRouterAddClass( osrfRouter* router, char* classname );
89
90 /**
91   Adds a new server node to the given class.
92   @param rclass The Router class to add the node to
93   @param remoteId The remote login of this node
94   @return 0 on success, -1 on generic error
95   */
96 int osrfRouterClassAddNode( osrfRouterClass* rclass, char* remoteId );
97
98
99 /**
100   Handles top level router messages
101   @return 0 on success
102   */
103 int osrfRouterHandleMessage( osrfRouter* router, transport_message* msg );
104
105
106 /**
107   Handles class level requests
108   @return 0 on success
109   */
110 int osrfRouterClassHandleMessage( osrfRouter* router, 
111                 osrfRouterClass* rclass, transport_message* msg );
112
113 /**
114   Removes a given class from the router, freeing as it goes
115   */
116 int osrfRouterRemoveClass( osrfRouter* router, char* classname );
117
118 /**
119   Removes the given node from the class.  Also, if this is that last node in the set,
120   removes the class from the router 
121   @return 0 on successful removal with no class removal
122   @return 1 on successful remove with class removal
123   @return -1 error on removal
124  */
125 int osrfRouterClassRemoveNode( osrfRouter* router, char* classname, char* remoteId );
126
127 /**
128   Frees a router class object
129   Takes a void* since it is freed by the hash code
130   */
131 void osrfRouterClassFree( char* classname, void* rclass );
132
133 /**
134   Frees a router node object 
135   Takes a void* since it is freed by the list code
136   */
137 void osrfRouterNodeFree( char* remoteId, void* node );
138
139
140 /**
141   Frees a router
142   */
143 void osrfRouterFree( osrfRouter* router );
144
145 /**
146   Finds the class associated with the given class name in the list of classes
147   */
148 osrfRouterClass* osrfRouterFindClass( osrfRouter* router, char* classname );
149
150 /**
151   Finds the router node within this class with the given remote id 
152   */
153 osrfRouterNode* osrfRouterClassFindNode( osrfRouterClass* rclass, char* remoteId );
154
155
156 /**
157   Clears and populates the provided fd_set* with file descriptors
158   from the router's top level connection as well as each of the
159   router class connections
160   @return The largest file descriptor found in the filling process
161   */
162 int __osrfRouterFillFDSet( osrfRouter* router, fd_set* set );
163
164
165
166 /**
167   Utility method for handling incoming requests to the router
168   and making sure the sender is allowed.
169   */
170 void osrfRouterHandleIncoming( osrfRouter* router );
171
172 /**
173         Utility method for handling incoming requests to a router class,
174         makes sure sender is a trusted client
175         */
176 int osrfRouterClassHandleIncoming( osrfRouter* router, char* classname,  osrfRouterClass* class );
177
178 /* handles case where router node is not longer reachable.  copies over the
179         data from the last sent message and returns a newly crafted suitable for treating
180         as a newly inconing message.  Removes the dead node and If there are no more
181         nodes to send the new message to, returns NULL.
182         */
183 transport_message* osrfRouterClassHandleBounce(
184                 osrfRouter* router, char* classname, osrfRouterClass* rclass, transport_message* msg );
185
186
187
188 /**
189   handles messages that don't have a 'router_command' set.  They are assumed to
190   be app request messages 
191   */
192 int osrfRouterHandleAppRequest( osrfRouter* router, transport_message* msg );
193
194
195 /**
196   Handles connects, disconnects, etc.
197   */
198 int osrfRouterHandeStatusMessage( osrfRouter* router, transport_message* msg );
199
200
201 /**
202   Handles REQUEST messages 
203   */
204 int osrfRouterHandleRequestMessage( osrfRouter* router, transport_message* msg );
205
206
207
208 int osrfRouterHandleAppRequest( osrfRouter* router, transport_message* msg );
209
210
211 int osrfRouterRespondConnect( osrfRouter* router, transport_message* msg, osrfMessage* omsg );
212
213
214
215 int osrfRouterProcessAppRequest( osrfRouter* router, transport_message* msg, osrfMessage* omsg );
216
217 int osrfRouterHandleAppResponse( osrfRouter* router, 
218                 transport_message* msg, osrfMessage* omsg, jsonObject* response );
219
220
221 int osrfRouterHandleMethodNFound( osrfRouter* router, transport_message* msg, osrfMessage* omsg );
222