1 #include <opensrf/string_array.h>
2 #include <opensrf/utils.h>
3 #include <opensrf/log.h>
4 #include <opensrf/osrf_json.h>
7 /* libxml stuff for the config reader */
8 #include <libxml/xmlmemory.h>
9 #include <libxml/parser.h>
10 #include <libxml/xpath.h>
11 #include <libxml/xpathInternals.h>
12 #include <libxml/tree.h>
16 #ifndef osrf_message_h
17 #define osrf_message_h
19 #define OSRF_XML_NAMESPACE "http://open-ils.org/xml/namespaces/oils_v1"
21 #define OSRF_STATUS_CONTINUE 100
23 #define OSRF_STATUS_OK 200
24 #define OSRF_STATUS_ACCEPTED 202
25 #define OSRF_STATUS_COMPLETE 205
27 #define OSRF_STATUS_REDIRECTED 307
29 #define OSRF_STATUS_BADREQUEST 400
30 #define OSRF_STATUS_UNAUTHORIZED 401
31 #define OSRF_STATUS_FORBIDDEN 403
32 #define OSRF_STATUS_NOTFOUND 404
33 #define OSRF_STATUS_NOTALLOWED 405
34 #define OSRF_STATUS_TIMEOUT 408
35 #define OSRF_STATUS_EXPFAILED 417
37 #define OSRF_STATUS_INTERNALSERVERERROR 500
38 #define OSRF_STATUS_NOTIMPLEMENTED 501
39 #define OSRF_STATUS_VERSIONNOTSUPPORTED 505
42 enum M_TYPE { CONNECT, REQUEST, RESULT, STATUS, DISCONNECT };
44 #define OSRF_MAX_PARAMS 128;
46 struct osrf_message_struct {
52 /* if we're a STATUS message */
55 /* if we're a STATUS or RESULT */
61 /* if we're a RESULT */
62 jsonObject* _result_content;
64 /* unparsed json string */
67 /* if we're a REQUEST */
72 /* in case anyone wants to make a list of us.
73 we won't touch this variable */
74 struct osrf_message_struct* next;
76 char* full_param_string;
78 /* magical LOCALE hint */
81 /* timezone offset from GMT of sender, in seconds */
85 typedef struct osrf_message_struct osrfMessage;
87 /* Set the locale hint for this message.
88 default_locale is used if not set.
89 Returns NULL if msg or locale is not set, char* to msg->sender_locale on success.
91 char* osrf_message_set_locale( osrfMessage* msg, const char* locale );
93 /* Set the default locale hint to be used for future outgoing messages.
94 Returns NULL if locale is NULL, const char* to default_locale otherwise.
96 const char* osrf_message_set_default_locale( const char* locale );
98 /* Get the current locale hint -- either the default or most recently received locale.
99 Returns const char* to current_locale.
101 const char* osrf_message_get_last_locale(void);
103 osrfMessage* osrf_message_init( enum M_TYPE type, int thread_trace, int protocol );
104 //void osrf_message_set_request_info( osrfMessage*, char* param_name, json* params );
105 void osrf_message_set_status_info( osrfMessage*,
106 const char* status_name, const char* status_text, int status_code );
107 void osrf_message_set_result_content( osrfMessage*, const char* json_string );
108 void osrfMessageFree( osrfMessage* );
109 char* osrf_message_to_xml( osrfMessage* );
110 char* osrf_message_serialize(const osrfMessage*);
112 /* count is the max number of messages we'll put into msgs[] */
113 int osrf_message_deserialize(const char* json, osrfMessage* msgs[], int count);
117 /** Pushes any message retreived from the xml into the 'msgs' array.
118 * it is assumed that 'msgs' has beenn pre-allocated.
119 * Returns the number of message that are in the buffer.
121 int osrf_message_from_xml( char* xml, osrfMessage* msgs[] );
123 void osrf_message_set_params( osrfMessage* msg, const jsonObject* o );
124 void osrf_message_set_method( osrfMessage* msg, const char* method_name );
125 void osrf_message_add_object_param( osrfMessage* msg, const jsonObject* o );
126 void osrf_message_add_param( osrfMessage*, const char* param_string );
129 jsonObject* osrfMessageGetResult( osrfMessage* msg );
132 Returns the message as a jsonObject
133 @return The jsonObject which must be freed by the caller.
135 jsonObject* osrfMessageToJSON( const osrfMessage* msg );
137 char* osrfMessageSerializeBatch( osrfMessage* msgs [], int count );