f6c4ca1c97313f4440dbdb8ffd46c1aab1ef8af2
[OpenSRF.git] / include / opensrf / osrf_message.h
1 #include "libjson/json.h"
2 #include "opensrf/generic_utils.h"
3 #include "opensrf/string_array.h"
4
5 #ifndef osrf_message_h
6 #define osrf_message_h
7
8 #define OSRF_XML_NAMESPACE "http://open-ils.org/xml/namespaces/oils_v1"
9
10 #define OSRF_STATUS_CONTINUE                                            100
11
12 #define OSRF_STATUS_OK                                                          200
13 #define OSRF_STATUS_ACCEPTED                                            202
14 #define OSRF_STATUS_COMPLETE                                            205
15
16 #define OSRF_STATUS_REDIRECTED                                  307
17
18 #define OSRF_STATUS_BADREQUEST                                  400
19 #define OSRF_STATUS_UNAUTHORIZED                                        401
20 #define OSRF_STATUS_FORBIDDEN                                           403
21 #define OSRF_STATUS_NOTFOUND                                            404
22 #define OSRF_STATUS_NOTALLOWED                                  405
23 #define OSRF_STATUS_TIMEOUT                                             408
24 #define OSRF_STATUS_EXPFAILED                                           417
25
26 #define OSRF_STATUS_INTERNALSERVERERROR         500
27 #define OSRF_STATUS_NOTIMPLEMENTED                              501
28 #define OSRF_STATUS_VERSIONNOTSUPPORTED         505
29
30
31 enum M_TYPE { CONNECT, REQUEST, RESULT, STATUS, DISCONNECT };
32
33 #define OSRF_MAX_PARAMS                                                         128;
34
35 struct osrf_message_struct {
36
37         enum M_TYPE m_type;
38         int thread_trace;
39         int protocol;
40
41         int parse_json_result;
42         int parse_json_params;
43         
44         /* if we're a STATUS message */
45         char* status_name;
46
47         /* if we're a STATUS or RESULT */
48         char* status_text;
49         int status_code;
50
51         int is_exception;
52
53         /* if we're a RESULT */
54         json* result_content;
55
56         /* unparsed json string */
57         char* result_string;
58
59         /* if we're a REQUEST */
60         char* method_name;
61         json* params;
62
63         /* in case anyone wants to make a list of us.  
64                 we won't touch this variable */
65         struct osrf_message_struct* next;
66
67         string_array* parray;
68         char* full_param_string;
69
70 };
71 typedef struct osrf_message_struct osrf_message;
72
73
74 osrf_message* osrf_message_init( enum M_TYPE type, int thread_trace, int protocol );
75 void osrf_message_set_request_info( osrf_message*, char* param_name, json* params );
76 void osrf_message_set_status_info( osrf_message*, char* status_name, char* status_text, int status_code );
77 void osrf_message_set_result_content( osrf_message*, char* json_string );
78 void osrf_message_free( osrf_message* );
79 char* osrf_message_to_xml( osrf_message* );
80 /** Pushes any message retreived from the xml into the 'msgs' array.
81   * it is assumed that 'msgs' has beenn pre-allocated.
82   * Returns the number of message that are in the buffer.
83   */
84 int osrf_message_from_xml( char* xml, osrf_message* msgs[] );
85
86 /* decides whether all message automatically parse incoming json data */
87 /* to change a single message, set msg->parse_json accordingly */
88 //void osrf_message_set_json_parse( int bool );
89
90 void osrf_message_set_json_parse_result( int ibool );
91 void osrf_message_set_json_parse_params( int ibool );
92         
93
94 void osrf_message_add_param( osrf_message*, char* param_string );
95
96
97
98
99 #endif