]> git.evergreen-ils.org Git - OpenSRF.git/blob - include/opensrf/osrf_message.h
Prepare for #inclusion in C++
[OpenSRF.git] / include / opensrf / osrf_message.h
1 #ifndef osrf_message_h
2 #define osrf_message_h
3
4 #include <opensrf/string_array.h>
5 #include <opensrf/utils.h>
6 #include <opensrf/log.h>
7 #include <opensrf/osrf_json.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 #ifdef __cplusplus
18 extern "C" {
19 #endif
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         /* if we're a STATUS message */
55         char* status_name;
56
57         /* if we're a STATUS or RESULT */
58         char* status_text;
59         int status_code;
60
61         int is_exception;
62
63         /* if we're a RESULT */
64         jsonObject* _result_content;
65
66         /* unparsed json string */
67         char* result_string;
68
69         /* if we're a REQUEST */
70         char* method_name;
71
72         jsonObject* _params;
73
74         /* in case anyone wants to make a list of us.  
75                 we won't touch this variable */
76         struct osrf_message_struct* next;
77
78         char* full_param_string;
79
80         /* magical LOCALE hint */
81         char* sender_locale;
82
83         /* timezone offset from GMT of sender, in seconds */
84         int sender_tz_offset;
85
86 };
87 typedef struct osrf_message_struct osrfMessage;
88
89 /* Set the locale hint for this message.
90    default_locale is used if not set.
91    Returns NULL if msg or locale is not set, char* to msg->sender_locale on success.
92 */
93 char* osrf_message_set_locale( osrfMessage* msg, const char* locale );
94
95 /* Set the default locale hint to be used for future outgoing messages.
96    Returns NULL if locale is NULL, const char* to default_locale otherwise.
97 */
98 const char* osrf_message_set_default_locale( const char* locale );
99
100 /* Get the current locale hint -- either the default or most recently received locale.
101    Returns const char* to current_locale.
102 */
103 const char* osrf_message_get_last_locale(void);
104
105 osrfMessage* osrf_message_init( enum M_TYPE type, int thread_trace, int protocol );
106 //void osrf_message_set_request_info( osrfMessage*, char* param_name, json* params );
107 void osrf_message_set_status_info( osrfMessage*,
108                 const char* status_name, const char* status_text, int status_code );
109 void osrf_message_set_result_content( osrfMessage*, const char* json_string );
110 void osrfMessageFree( osrfMessage* );
111 char* osrf_message_to_xml( osrfMessage* );
112 char* osrf_message_serialize(const osrfMessage*);
113
114 /* count is the max number of messages we'll put into msgs[] */
115 int osrf_message_deserialize(const char* json, osrfMessage* msgs[], int count);
116
117
118
119 /** Pushes any message retreived from the xml into the 'msgs' array.
120   * it is assumed that 'msgs' has beenn pre-allocated.
121   * Returns the number of message that are in the buffer.
122   */
123 int osrf_message_from_xml( char* xml, osrfMessage* msgs[] );
124
125 void osrf_message_set_params( osrfMessage* msg, const jsonObject* o );
126 void osrf_message_set_method( osrfMessage* msg, const char* method_name );
127 void osrf_message_add_object_param( osrfMessage* msg, const jsonObject* o );
128 void osrf_message_add_param( osrfMessage*, const char* param_string );
129
130
131 jsonObject* osrfMessageGetResult( osrfMessage* msg );
132
133 /**
134   Returns the message as a jsonObject
135   @return The jsonObject which must be freed by the caller.
136   */
137 jsonObject* osrfMessageToJSON( const osrfMessage* msg );
138
139 char* osrfMessageSerializeBatch( osrfMessage* msgs [], int count );
140
141 #ifdef __cplusplus
142 }
143 #endif
144
145 #endif