again... moving header files to their home locations, makefiles copy them
authorerickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Sun, 19 Jun 2005 16:19:11 +0000 (16:19 +0000)
committererickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Sun, 19 Jun 2005 16:19:11 +0000 (16:19 +0000)
to right place

git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@351 9efc2488-bf62-4759-914b-345cdb29e865

src/libstack/osrf_app_session.h [new file with mode: 0644]
src/libstack/osrf_config.h [new file with mode: 0644]
src/libstack/osrf_message.h [new file with mode: 0644]
src/libstack/osrf_stack.h [new file with mode: 0644]
src/libstack/osrf_system.h [new file with mode: 0644]

diff --git a/src/libstack/osrf_app_session.h b/src/libstack/osrf_app_session.h
new file mode 100644 (file)
index 0000000..0ddd72b
--- /dev/null
@@ -0,0 +1,197 @@
+#include "libjson/json.h"
+#include "opensrf/transport_client.h"
+#include "opensrf/generic_utils.h"
+#include "osrf_message.h"
+#include "osrf_system.h"
+#include "string_array.h"
+
+#ifndef OSRF_APP_SESSION
+#define OSRF_APP_SESSION
+
+
+#define        DEF_RECV_TIMEOUT 6 /* receive timeout */
+#define        DEF_QUEUE_SIZE  
+
+enum OSRF_SESSION_STATE { OSRF_SESSION_CONNECTING, OSRF_SESSION_CONNECTED, OSRF_SESSION_DISCONNECTED };
+enum OSRF_SESSION_TYPE { OSRF_SESSION_SERVER, OSRF_SESSION_CLIENT };
+
+struct osrf_app_request_struct {
+       /** Our controlling session */
+       struct osrf_app_session_struct* session;
+
+       /** our "id" */
+       int request_id;
+       /** True if we have received a 'request complete' message from our request */
+       int complete;
+       /** Our original request payload */
+       osrf_message* payload; 
+       /** List of responses to our request */
+       osrf_message* result;
+
+       /** So we can be listified */
+       struct osrf_app_request_struct* next;
+};
+typedef struct osrf_app_request_struct osrf_app_request;
+
+struct osrf_app_session_struct {
+
+       /** Our messag passing object */
+       transport_client* transport_handle;
+       /** Cache of active app_request objects */
+       osrf_app_request* request_queue;
+
+       /** The original remote id of the remote service we're talking to */
+       char* orig_remote_id;
+       /** The current remote id of the remote service we're talking to */
+       char* remote_id;
+
+       /** Who we're talking to */
+       char* remote_service;
+
+       /** The current request thread_trace */
+       int thread_trace;
+       /** Our ID */
+       char* session_id;
+
+       /* true if this session does not require connect messages */
+       int stateless;
+
+       /** The connect state */
+       enum OSRF_SESSION_STATE state;
+
+       /** SERVER or CLIENT */
+       enum OSRF_SESSION_TYPE type;
+
+       /** So we can be listified */
+       struct osrf_app_session_struct* next;
+};
+typedef struct osrf_app_session_struct osrf_app_session;
+
+
+
+// -------------------------------------------------------------------------- 
+// PUBLIC API ***
+// -------------------------------------------------------------------------- 
+
+/** Allocates a initializes a new app_session */
+osrf_app_session* osrf_app_client_session_init( char* remote_service );
+
+/** Allocates and initializes a new server session.  The global session cache
+  * is checked to see if this session already exists, if so, it's returned 
+  */
+osrf_app_session* osrf_app_server_session_init( 
+               char* session_id, char* our_app, char* remote_service, char* remote_id );
+
+/** returns a session from the global session hash */
+osrf_app_session* osrf_app_session_find_session( char* session_id );
+
+/** Builds a new app_request object with the given payload andn returns
+  * the id of the request.  This id is then used to perform work on the
+  * requeset.
+  */
+int osrf_app_session_make_request( 
+               osrf_app_session* session, json* params, 
+               char* method_name, int protocol, string_array* arr );
+
+/** Sets the given request to complete state */
+void osrf_app_session_set_complete( osrf_app_session* session, int request_id );
+
+/** Returns true if the given request is complete */
+int osrf_app_session_request_complete( osrf_app_session* session, int request_id );
+
+/** Does a recv call on the given request */
+osrf_message* osrf_app_session_request_recv( 
+               osrf_app_session* session, int request_id, int timeout );
+
+/** Removes the request from the request set and frees the reqest */
+void osrf_app_session_request_finish( osrf_app_session* session, int request_id );
+
+/** Resends the orginal request with the given request id */
+int osrf_app_session_request_resend( osrf_app_session*, int request_id );
+
+/** Resets the remote connection target to that of the original*/
+void osrf_app_session_reset_remote( osrf_app_session* );
+
+/** Sets the remote target to 'remote_id' */
+void osrf_app_session_set_remote( osrf_app_session* session, char* remote_id );
+
+/** pushes the given message into the result list of the app_request
+  * whose request_id matches the messages thread_trace 
+  */
+int osrf_app_session_push_queue( osrf_app_session*, osrf_message* msg );
+
+/** Attempts to connect to the remote service. Returns 1 on successful 
+  * connection, 0 otherwise.
+  */
+int osrf_app_session_connect( osrf_app_session* );
+
+/** Sends a disconnect message to the remote service.  No response is expected */
+int osrf_app_session_disconnect( osrf_app_session* );
+
+/**  Waits up to 'timeout' seconds for some data to arrive.
+  * Any data that arrives will be processed according to its
+  * payload and message type.  This method will return after
+  * any data has arrived.
+  */
+int osrf_app_session_queue_wait( osrf_app_session*, int timeout );
+
+/** Disconnects (if client), frees any attached app_reuqests, removes the session from the 
+  * global session cache and frees the session.  Needless to say, only call this when the
+  * session is completey done.
+  */
+void osrf_app_session_destroy ( osrf_app_session* );
+
+
+
+// --------------------------------------------------------------------------
+// --------------------------------------------------------------------------
+// Request functions
+// --------------------------------------------------------------------------
+
+/** Allocations and initializes a new app_request object */
+osrf_app_request* _osrf_app_request_init( osrf_app_session* session, osrf_message* msg );
+
+/** Frees memory used by an app_request object */
+void _osrf_app_request_free( osrf_app_request * req );
+
+/** Pushes the given message onto the list of 'responses' to this request */
+void _osrf_app_request_push_queue( osrf_app_request*, osrf_message* payload );
+
+/** Checks the receive queue for messages.  If any are found, the first
+  * is popped off and returned.  Otherwise, this method will wait at most timeout 
+  * seconds for a message to appear in the receive queue.  Once it arrives it is returned.
+  * If no messages arrive in the timeout provided, null is returned.
+  */
+osrf_message* _osrf_app_request_recv( osrf_app_request* req, int timeout );
+
+/** Resend this requests original request message */
+int _osrf_app_request_resend( osrf_app_request* req );
+
+
+// --------------------------------------------------------------------------
+// --------------------------------------------------------------------------
+// Session functions 
+// --------------------------------------------------------------------------
+
+/** Returns the app_request with the given thread_trace (request_id) */
+osrf_app_request* _osrf_app_session_get_request( osrf_app_session*, int thread_trace );
+
+/** frees memory held by a session. Note: We delete all requests in the request list */
+void _osrf_app_session_free( osrf_app_session* );
+
+/** adds a session to the global session cache */
+void _osrf_app_session_push_session( osrf_app_session* );
+
+/** removes from global session cache */
+void _osrf_app_session_remove_session( char* session_id );
+
+/** Adds an app_request to the request set */
+void _osrf_app_session_push_request( osrf_app_session*, osrf_app_request* req );
+
+/** Removes an app_request from this session request set, freeing the request object */
+void _osrf_app_session_remove_request( osrf_app_session*, osrf_app_request* req );
+
+/** Send the given message */
+int _osrf_app_session_send( osrf_app_session*, osrf_message* msg );
+
+#endif
diff --git a/src/libstack/osrf_config.h b/src/libstack/osrf_config.h
new file mode 100644 (file)
index 0000000..1d6385f
--- /dev/null
@@ -0,0 +1,13 @@
+#include <stdio.h>
+
+#include "opensrf/transport_client.h"
+#include "opensrf/transport_message.h"
+#include "osrf_message.h"
+#include "opensrf/generic_utils.h"
+
+
+char* osrf_config_value(char* path);
+
+void _osrf_config_grab_config();
+
+
diff --git a/src/libstack/osrf_message.h b/src/libstack/osrf_message.h
new file mode 100644 (file)
index 0000000..5c32c2d
--- /dev/null
@@ -0,0 +1,99 @@
+#include "libjson/json.h"
+#include "opensrf/generic_utils.h"
+#include "string_array.h"
+
+#ifndef osrf_message_h
+#define osrf_message_h
+
+#define OSRF_XML_NAMESPACE "http://open-ils.org/xml/namespaces/oils_v1"
+
+#define OSRF_STATUS_CONTINUE                                           100
+
+#define OSRF_STATUS_OK                                                         200
+#define OSRF_STATUS_ACCEPTED                                           202
+#define OSRF_STATUS_COMPLETE                                           205
+
+#define OSRF_STATUS_REDIRECTED                                 307
+
+#define OSRF_STATUS_BADREQUEST                                 400
+#define OSRF_STATUS_UNAUTHORIZED                                       401
+#define OSRF_STATUS_FORBIDDEN                                          403
+#define OSRF_STATUS_NOTFOUND                                           404
+#define OSRF_STATUS_NOTALLOWED                                 405
+#define OSRF_STATUS_TIMEOUT                                            408
+#define OSRF_STATUS_EXPFAILED                                          417
+
+#define OSRF_STATUS_INTERNALSERVERERROR                500
+#define OSRF_STATUS_NOTIMPLEMENTED                             501
+#define OSRF_STATUS_VERSIONNOTSUPPORTED                505
+
+
+enum M_TYPE { CONNECT, REQUEST, RESULT, STATUS, DISCONNECT };
+
+#define OSRF_MAX_PARAMS                                                                128;
+
+struct osrf_message_struct {
+
+       enum M_TYPE m_type;
+       int thread_trace;
+       int protocol;
+
+       int parse_json_result;
+       int parse_json_params;
+       
+       /* if we're a STATUS message */
+       char* status_name;
+
+       /* if we're a STATUS or RESULT */
+       char* status_text;
+       int status_code;
+
+       int is_exception;
+
+       /* if we're a RESULT */
+       json* result_content;
+
+       /* unparsed json string */
+       char* result_string;
+
+       /* if we're a REQUEST */
+       char* method_name;
+       json* params;
+
+       /* in case anyone wants to make a list of us.  
+               we won't touch this variable */
+       struct osrf_message_struct* next;
+
+       string_array* parray;
+       char* full_param_string;
+
+};
+typedef struct osrf_message_struct osrf_message;
+
+
+osrf_message* osrf_message_init( enum M_TYPE type, int thread_trace, int protocol );
+void osrf_message_set_request_info( osrf_message*, char* param_name, json* params );
+void osrf_message_set_status_info( osrf_message*, char* status_name, char* status_text, int status_code );
+void osrf_message_set_result_content( osrf_message*, char* json_string );
+void osrf_message_free( osrf_message* );
+char* osrf_message_to_xml( osrf_message* );
+/** Pushes any message retreived from the xml into the 'msgs' array.
+  * it is assumed that 'msgs' has beenn pre-allocated.
+  * Returns the number of message that are in the buffer.
+  */
+int osrf_message_from_xml( char* xml, osrf_message* msgs[] );
+
+/* decides whether all message automatically parse incoming json data */
+/* to change a single message, set msg->parse_json accordingly */
+//void osrf_message_set_json_parse( int bool );
+
+void osrf_message_set_json_parse_result( int ibool );
+void osrf_message_set_json_parse_params( int ibool );
+       
+
+void osrf_message_add_param( osrf_message*, char* param_string );
+
+
+
+
+#endif
diff --git a/src/libstack/osrf_stack.h b/src/libstack/osrf_stack.h
new file mode 100644 (file)
index 0000000..23b358e
--- /dev/null
@@ -0,0 +1,17 @@
+#include "opensrf/transport_client.h"
+#include "osrf_message.h"
+#include "osrf_app_session.h"
+
+#ifndef OSRF_STACK_H
+#define OSRF_STACK_H
+
+/* the max number of oilsMessage blobs present in any one root packet */
+#define OSRF_MAX_MSGS_PER_PACKET 16 
+// -----------------------------------------------------------------------------
+
+int osrf_stack_transport_handler( transport_message* msg );
+int osrf_stack_message_handler( osrf_app_session* session, osrf_message* msg );
+int osrf_stack_application_handler( osrf_app_session* session, osrf_message*msg );
+
+
+#endif
diff --git a/src/libstack/osrf_system.h b/src/libstack/osrf_system.h
new file mode 100644 (file)
index 0000000..7247d3a
--- /dev/null
@@ -0,0 +1,12 @@
+#include "opensrf/transport_client.h"
+
+#ifndef OSRF_SYSTEM_H
+#define OSRF_SYSTEM_H
+
+/** Connects to jabber.  Returns 1 on success, 0 on failure */
+int osrf_system_bootstrap_client(); 
+transport_client* osrf_system_get_transport_client();
+
+int osrf_system_shutdown(); 
+
+#endif