1 #include "libjson/json.h"
2 #include "opensrf/generic_utils.h"
7 #define OSRF_XML_NAMESPACE "http://open-ils.org/xml/namespaces/oils_v1"
9 #define OSRF_STATUS_CONTINUE 100
11 #define OSRF_STATUS_OK 200
12 #define OSRF_STATUS_ACCEPTED 202
13 #define OSRF_STATUS_COMPLETE 205
15 #define OSRF_STATUS_REDIRECTED 307
17 #define OSRF_STATUS_BADREQUEST 400
18 #define OSRF_STATUS_UNAUTHORIZED 401
19 #define OSRF_STATUS_FORBIDDEN 403
20 #define OSRF_STATUS_NOTFOUND 404
21 #define OSRF_STATUS_NOTALLOWED 405
22 #define OSRF_STATUS_TIMEOUT 408
23 #define OSRF_STATUS_EXPFAILED 417
25 #define OSRF_STATUS_INTERNALSERVERERROR 500
26 #define OSRF_STATUS_NOTIMPLEMENTED 501
27 #define OSRF_STATUS_VERSIONNOTSUPPORTED 505
30 enum M_TYPE { CONNECT, REQUEST, RESULT, STATUS, DISCONNECT };
32 struct osrf_message_struct {
40 /* if we're a STATUS message */
43 /* if we're a STATUS or RESULT */
49 /* if we're a RESULT */
52 /* unparsed json string */
55 /* if we're a REQUEST */
59 /* in case anyone wants to make a list of us.
60 we won't touch this variable */
61 struct osrf_message_struct* next;
64 typedef struct osrf_message_struct osrf_message;
67 osrf_message* osrf_message_init( enum M_TYPE type, int thread_trace, int protocol );
68 void osrf_message_set_request_info( osrf_message*, char* param_name, json* params );
69 void osrf_message_set_status_info( osrf_message*, char* status_name, char* status_text, int status_code );
70 void osrf_message_set_result_content( osrf_message*, char* json_string );
71 void osrf_message_free( osrf_message* );
72 char* osrf_message_to_xml( osrf_message* );
73 /** Pushes any message retreived from the xml into the 'msgs' array.
74 * it is assumed that 'msgs' has beenn pre-allocated.
75 * Returns the number of message that are in the buffer.
77 int osrf_message_from_xml( char* xml, osrf_message* msgs[] );
79 /* decides whether all message automatically parse incoming json data */
80 /* to change a single message, set msg->parse_json accordingly */
81 void osrf_message_set_json_parse( int bool );