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