+#ifndef OSRF_ROUTER_H
+#define OSRF_ROUTER_H
+
#include <sys/select.h>
#include <signal.h>
#include <stdio.h>
#include "opensrf/osrf_message.h"
-
+#ifdef __cplusplus
+extern "C" {
+#endif
/* a router maintains a list of server classes */
-struct __osrfRouterStruct {
+struct _osrfRouterStruct {
- osrfHash* classes; /* our list of server classes */
- char* domain; /* our login domain */
- char* name;
- char* resource;
- char* password;
- int port;
+ osrfHash* classes; /**< our list of server classes */
+ char* domain; /**< Domain name of Jabber server. */
+ char* name; /**< Router's username for the Jabber logon. */
+ char* resource; /**< Router's resource name for the Jabber logon. */
+ char* password; /**< Router's password for the Jabber logon. */
+ int port; /**< Jabber's port number. */
+ sig_atomic_t stop; /**< To be set by signal handler to interrupt main loop */
osrfStringArray* trustedClients;
osrfStringArray* trustedServers;
transport_client* connection;
};
-typedef struct __osrfRouterStruct osrfRouter;
-
-
-/* a class maintains a set of server nodes */
-struct __osrfRouterClassStruct {
- osrfRouter* router; /* our router handle */
- osrfHashIterator* itr;
- osrfHash* nodes;
- transport_client* connection;
-};
-typedef struct __osrfRouterClassStruct osrfRouterClass;
-
-/* represents a link to a single server's inbound connection */
-struct __osrfRouterNodeStruct {
- char* remoteId; /* send message to me via this login */
- int count; /* how many message have been sent to this node */
- transport_message* lastMessage;
-};
-typedef struct __osrfRouterNodeStruct osrfRouterNode;
+typedef struct _osrfRouterStruct osrfRouter;
/**
Allocates a new router.
@param trustedServers The array of server domains that we allow to register, etc. with ust.
@return The allocated router or NULL on memory error
*/
-osrfRouter* osrfNewRouter( char* domain, char* name, char* resource,
- char* password, int port, osrfStringArray* trustedClients, osrfStringArray* trustedServers );
+osrfRouter* osrfNewRouter( const char* domain, const char* name, const char* resource,
+ const char* password, int port, osrfStringArray* trustedClients,
+ osrfStringArray* trustedServers );
/**
Connects the given router to the network
*/
void osrfRouterRun( osrfRouter* router );
-
-/**
- Allocates and adds a new router class handler to the router's list of handlers.
- Also connects the class handler to the network at <routername>@domain/<classname>
- @param router The current router instance
- @param classname The name of the class this node handles.
- @return 0 on success, -1 on connection error.
- */
-osrfRouterClass* osrfRouterAddClass( osrfRouter* router, char* classname );
-
-/**
- Adds a new server node to the given class.
- @param rclass The Router class to add the node to
- @param remoteId The remote login of this node
- @return 0 on success, -1 on generic error
- */
-int osrfRouterClassAddNode( osrfRouterClass* rclass, char* remoteId );
-
-
-/**
- Handles top level router messages
- @return 0 on success
- */
-int osrfRouterHandleMessage( osrfRouter* router, transport_message* msg );
-
-
-/**
- Handles class level requests
- @return 0 on success
- */
-int osrfRouterClassHandleMessage( osrfRouter* router,
- osrfRouterClass* rclass, transport_message* msg );
-
-/**
- Removes a given class from the router, freeing as it goes
- */
-int osrfRouterRemoveClass( osrfRouter* router, char* classname );
-
-/**
- Removes the given node from the class. Also, if this is that last node in the set,
- removes the class from the router
- @return 0 on successful removal with no class removal
- @return 1 on successful remove with class removal
- @return -1 error on removal
- */
-int osrfRouterClassRemoveNode( osrfRouter* router, char* classname, char* remoteId );
-
-/**
- Frees a router class object
- Takes a void* since it is freed by the hash code
- */
-void osrfRouterClassFree( char* classname, void* rclass );
-
-/**
- Frees a router node object
- Takes a void* since it is freed by the list code
- */
-void osrfRouterNodeFree( char* remoteId, void* node );
-
+void router_stop( osrfRouter* router );
/**
Frees a router
void osrfRouterFree( osrfRouter* router );
/**
- Finds the class associated with the given class name in the list of classes
- */
-osrfRouterClass* osrfRouterFindClass( osrfRouter* router, char* classname );
-
-/**
- Finds the router node within this class with the given remote id
- */
-osrfRouterNode* osrfRouterClassFindNode( osrfRouterClass* rclass, char* remoteId );
-
-
-/**
- Clears and populates the provided fd_set* with file descriptors
- from the router's top level connection as well as each of the
- router class connections
- @return The largest file descriptor found in the filling process
- */
-int __osrfRouterFillFDSet( osrfRouter* router, fd_set* set );
-
-
-
-/**
- Utility method for handling incoming requests to the router
- and making sure the sender is allowed.
- */
-void osrfRouterHandleIncoming( osrfRouter* router );
-
-/**
- Utility method for handling incoming requests to a router class,
- makes sure sender is a trusted client
- */
-int osrfRouterClassHandleIncoming( osrfRouter* router, char* classname, osrfRouterClass* class );
-
-/* handles case where router node is not longer reachable. copies over the
- data from the last sent message and returns a newly crafted suitable for treating
- as a newly inconing message. Removes the dead node and If there are no more
- nodes to send the new message to, returns NULL.
- */
-transport_message* osrfRouterClassHandleBounce(
- osrfRouter* router, char* classname, osrfRouterClass* rclass, transport_message* msg );
-
-
-
-/**
- handles messages that don't have a 'router_command' set. They are assumed to
- be app request messages
- */
-int osrfRouterHandleAppRequest( osrfRouter* router, transport_message* msg );
-
-
-/**
Handles connects, disconnects, etc.
*/
-int osrfRouterHandeStatusMessage( osrfRouter* router, transport_message* msg );
-
+//int osrfRouterHandeStatusMessage( osrfRouter* router, transport_message* msg );
/**
Handles REQUEST messages
*/
-int osrfRouterHandleRequestMessage( osrfRouter* router, transport_message* msg );
-
-
-
-int osrfRouterHandleAppRequest( osrfRouter* router, transport_message* msg );
-
-
-int osrfRouterRespondConnect( osrfRouter* router, transport_message* msg, osrfMessage* omsg );
-
-
-
-int osrfRouterProcessAppRequest( osrfRouter* router, transport_message* msg, osrfMessage* omsg );
-
-int osrfRouterHandleAppResponse( osrfRouter* router,
- transport_message* msg, osrfMessage* omsg, jsonObject* response );
+//int osrfRouterHandleRequestMessage( osrfRouter* router, transport_message* msg );
+#ifdef __cplusplus
+}
+#endif
-int osrfRouterHandleMethodNFound( osrfRouter* router, transport_message* msg, osrfMessage* omsg );
+#endif