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