6 @brief Header for osrfMessage
8 An osrfMessage is the in-memory representation of a message between applications.
10 For transmission, one or more messages are encoded in a JSON array and wrapped in a
11 transport_message, which (together with its JSON cargo) is translated into XML as
14 There are five kinds of messages:
15 - CONNECT -- request to establish a stateful session.
16 - DISCONNECT -- ends a stateful session.
17 - REQUEST -- a remote procedure call.
18 - RESULT -- data returned by a remote procedure call.
19 - STATUS -- reports the success or failure of a requested operation.
21 Different kinds of messages use different combinations of the members of an osrfMessage.
24 #include <opensrf/string_array.h>
25 #include <opensrf/utils.h>
26 #include <opensrf/log.h>
27 #include <opensrf/osrf_json.h>
33 #define OSRF_XML_NAMESPACE "http://open-ils.org/xml/namespaces/oils_v1"
35 #define OSRF_STATUS_CONTINUE 100
37 #define OSRF_STATUS_OK 200
38 #define OSRF_STATUS_ACCEPTED 202
39 #define OSRF_STATUS_COMPLETE 205
41 #define OSRF_STATUS_REDIRECTED 307
43 #define OSRF_STATUS_BADREQUEST 400
44 #define OSRF_STATUS_UNAUTHORIZED 401
45 #define OSRF_STATUS_FORBIDDEN 403
46 #define OSRF_STATUS_NOTFOUND 404
47 #define OSRF_STATUS_NOTALLOWED 405
48 #define OSRF_STATUS_TIMEOUT 408
49 #define OSRF_STATUS_EXPFAILED 417
51 #define OSRF_STATUS_INTERNALSERVERERROR 500
52 #define OSRF_STATUS_NOTIMPLEMENTED 501
53 #define OSRF_STATUS_VERSIONNOTSUPPORTED 505
56 enum M_TYPE { CONNECT, REQUEST, RESULT, STATUS, DISCONNECT };
58 struct osrf_message_struct {
60 /** One of the four message types: CONNECT, REQUEST, RESULT, STATUS, or DISCONNECT. */
63 /** Used to keep track of which responses go with which requests. */
66 /** Currently serves no discernible purpose, but may be useful someday. */
69 /** Used for STATUS or RESULT messages. */
72 /** Used for STATUS or RESULT messages. */
75 /** Used for STATUS or RESULT messages. */
78 /** Boolean: true for some kinds of error conditions. */
81 /** Used for RESULT messages: contains the data returned by a remote procedure. */
82 jsonObject* _result_content;
84 /** For a REQUEST message: name of the remote procedure to call. */
87 /** For a REQUEST message: parameters to pass to the remote procedure call. */
90 /** Pointer for linked lists. Used only by calling code. */
91 struct osrf_message_struct* next;
93 /** Magical LOCALE hint. */
96 /** Magical ingress hint. */
99 /** Magical TZ hint. */
102 typedef struct osrf_message_struct osrfMessage;
104 const char* osrf_message_set_locale( osrfMessage* msg, const char* locale );
106 const char* osrf_message_set_tz( osrfMessage* msg, const char* tz );
108 const char* osrfMessageSetIngress( osrfMessage* msg, const char* ingress );
110 const char* osrf_message_set_default_locale( const char* locale );
112 const char* osrf_message_get_last_locale(void);
114 const char* osrf_message_get_last_tz(void);
116 osrfMessage* osrf_message_init( enum M_TYPE type, int thread_trace, int protocol );
118 void osrf_message_set_status_info( osrfMessage*,
119 const char* status_name, const char* status_text, int status_code );
121 void osrf_message_set_result_content( osrfMessage*, const char* json_string );
123 void osrf_message_set_result( osrfMessage* msg, const jsonObject* obj );
125 void osrfMessageFree( osrfMessage* );
127 char* osrf_message_to_xml( osrfMessage* );
129 jsonObject* osrfMessageToJSON( const osrfMessage* msg );
131 char* osrf_message_serialize(const osrfMessage*);
133 osrfList* osrfMessageDeserialize( const char* string, osrfList* list );
135 int osrf_message_deserialize(const char* json, osrfMessage* msgs[], int count);
137 void osrf_message_set_params( osrfMessage* msg, const jsonObject* o );
139 void osrf_message_set_method( osrfMessage* msg, const char* method_name );
141 void osrf_message_add_object_param( osrfMessage* msg, const jsonObject* o );
143 void osrf_message_add_param( osrfMessage*, const char* param_string );
145 const jsonObject* osrfMessageGetResult( osrfMessage* msg );
147 char* osrfMessageSerializeBatch( osrfMessage* msgs [], int count );