]> git.evergreen-ils.org Git - OpenSRF.git/blob - include/opensrf/osrf_message.h
407a6a31c6893b2fdfe74796e0d3ea6382b253d6
[OpenSRF.git] / include / opensrf / osrf_message.h
1 #ifndef osrf_message_h
2 #define osrf_message_h
3
4 /**
5         @file osrf_message.h
6         @brief Header for osrfMessage
7 */
8
9 #include <opensrf/string_array.h>
10 #include <opensrf/utils.h>
11 #include <opensrf/log.h>
12 #include <opensrf/osrf_json.h>
13
14
15 /* libxml stuff for the config reader */
16 #include <libxml/xmlmemory.h>
17 #include <libxml/parser.h>
18 #include <libxml/xpath.h>
19 #include <libxml/xpathInternals.h>
20 #include <libxml/tree.h>
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26 #define OSRF_XML_NAMESPACE "http://open-ils.org/xml/namespaces/oils_v1"
27
28 #define OSRF_STATUS_CONTINUE                                            100
29
30 #define OSRF_STATUS_OK                                                          200
31 #define OSRF_STATUS_ACCEPTED                                            202
32 #define OSRF_STATUS_COMPLETE                                            205
33
34 #define OSRF_STATUS_REDIRECTED                                  307
35
36 #define OSRF_STATUS_BADREQUEST                                  400
37 #define OSRF_STATUS_UNAUTHORIZED                                        401
38 #define OSRF_STATUS_FORBIDDEN                                           403
39 #define OSRF_STATUS_NOTFOUND                                            404
40 #define OSRF_STATUS_NOTALLOWED                                  405
41 #define OSRF_STATUS_TIMEOUT                                             408
42 #define OSRF_STATUS_EXPFAILED                                           417
43
44 #define OSRF_STATUS_INTERNALSERVERERROR         500
45 #define OSRF_STATUS_NOTIMPLEMENTED                              501
46 #define OSRF_STATUS_VERSIONNOTSUPPORTED         505
47
48
49 enum M_TYPE { CONNECT, REQUEST, RESULT, STATUS, DISCONNECT };
50
51 #define OSRF_MAX_PARAMS                                                         128;
52
53 struct osrf_message_struct {
54
55         enum M_TYPE m_type;
56         int thread_trace;
57         int protocol;
58
59         /* if we're a STATUS message */
60         char* status_name;
61
62         /* if we're a STATUS or RESULT */
63         char* status_text;
64         int status_code;
65
66         int is_exception;
67
68         /* if we're a RESULT */
69         jsonObject* _result_content;
70
71         /* unparsed json string */
72         char* result_string;
73
74         /* if we're a REQUEST */
75         char* method_name;
76
77         jsonObject* _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         /* magical LOCALE hint */
84         char* sender_locale;
85
86         /* timezone offset from GMT of sender, in seconds */
87         int sender_tz_offset;
88
89 };
90 typedef struct osrf_message_struct osrfMessage;
91
92 const char* osrf_message_set_locale( osrfMessage* msg, const char* locale );
93
94 const char* osrf_message_set_default_locale( const char* locale );
95
96 const char* osrf_message_get_last_locale(void);
97
98 osrfMessage* osrf_message_init( enum M_TYPE type, int thread_trace, int protocol );
99
100 void osrf_message_set_status_info( osrfMessage*,
101                 const char* status_name, const char* status_text, int status_code );
102
103 void osrf_message_set_result_content( osrfMessage*, const char* json_string );
104
105 void osrfMessageFree( osrfMessage* );
106
107 char* osrf_message_to_xml( osrfMessage* );
108
109 char* osrf_message_serialize(const osrfMessage*);
110
111 int osrf_message_deserialize(const char* json, osrfMessage* msgs[], int count);
112
113 void osrf_message_set_params( osrfMessage* msg, const jsonObject* o );
114
115 void osrf_message_set_method( osrfMessage* msg, const char* method_name );
116
117 void osrf_message_add_object_param( osrfMessage* msg, const jsonObject* o );
118
119 void osrf_message_add_param( osrfMessage*, const char* param_string );
120
121 jsonObject* osrfMessageGetResult( osrfMessage* msg );
122
123 char* osrfMessageSerializeBatch( osrfMessage* msgs [], int count );
124
125 #ifdef __cplusplus
126 }
127 #endif
128
129 #endif