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