]> git.evergreen-ils.org Git - OpenSRF.git/blob - include/opensrf/osrf_message.h
1f992fcbb7c22dcffa3f117cac8c2076fe81cc67
[OpenSRF.git] / include / opensrf / osrf_message.h
1 #include "libjson/json.h"
2 #include "opensrf/generic_utils.h"
3
4 #ifndef osrf_message_h
5 #define osrf_message_h
6
7 #define OSRF_XML_NAMESPACE "http://open-ils.org/xml/namespaces/oils_v1"
8
9 #define OSRF_STATUS_CONTINUE                                            100
10
11 #define OSRF_STATUS_OK                                                          200
12 #define OSRF_STATUS_ACCEPTED                                            202
13 #define OSRF_STATUS_COMPLETE                                            205
14
15 #define OSRF_STATUS_REDIRECTED                                  307
16
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
24
25 #define OSRF_STATUS_INTERNALSERVERERROR         500
26 #define OSRF_STATUS_NOTIMPLEMENTED                              501
27 #define OSRF_STATUS_VERSIONNOTSUPPORTED         505
28
29
30 enum M_TYPE { CONNECT, REQUEST, RESULT, STATUS, DISCONNECT };
31
32 struct osrf_message_struct {
33
34         enum M_TYPE m_type;
35         int thread_trace;
36         int protocol;
37
38         int parse_json;
39         
40         /* if we're a STATUS message */
41         char* status_name;
42
43         /* if we're a STATUS or RESULT */
44         char* status_text;
45         int status_code;
46
47         int is_exception;
48
49         /* if we're a RESULT */
50         json* result_content;
51
52         /* unparsed json string */
53         char* result_string;
54
55         /* if we're a REQUEST */
56         char* method_name;
57         json* params;
58
59         /* in case anyone wants to make a list of us.  
60                 we won't touch this variable */
61         struct osrf_message_struct* next;
62
63 };
64 typedef struct osrf_message_struct osrf_message;
65
66
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.
76   */
77 int osrf_message_from_xml( char* xml, osrf_message* msgs[] );
78
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 );
82
83
84
85
86 #endif