]> git.evergreen-ils.org Git - OpenSRF.git/blob - include/opensrf/osrf_message.h
57f1aa5406ad3b4ca5b044bd975cf0c309519832
[OpenSRF.git] / include / opensrf / osrf_message.h
1 #include <opensrf/string_array.h>
2 #include <opensrf/utils.h>
3 #include <opensrf/log.h>
4 #include <opensrf/osrf_json.h>
5
6
7 /* libxml stuff for the config reader */
8 #include <libxml/xmlmemory.h>
9 #include <libxml/parser.h>
10 #include <libxml/xpath.h>
11 #include <libxml/xpathInternals.h>
12 #include <libxml/tree.h>
13
14
15
16 #ifndef osrf_message_h
17 #define osrf_message_h
18
19 #define OSRF_XML_NAMESPACE "http://open-ils.org/xml/namespaces/oils_v1"
20
21 #define OSRF_STATUS_CONTINUE                                            100
22
23 #define OSRF_STATUS_OK                                                          200
24 #define OSRF_STATUS_ACCEPTED                                            202
25 #define OSRF_STATUS_COMPLETE                                            205
26
27 #define OSRF_STATUS_REDIRECTED                                  307
28
29 #define OSRF_STATUS_BADREQUEST                                  400
30 #define OSRF_STATUS_UNAUTHORIZED                                        401
31 #define OSRF_STATUS_FORBIDDEN                                           403
32 #define OSRF_STATUS_NOTFOUND                                            404
33 #define OSRF_STATUS_NOTALLOWED                                  405
34 #define OSRF_STATUS_TIMEOUT                                             408
35 #define OSRF_STATUS_EXPFAILED                                           417
36
37 #define OSRF_STATUS_INTERNALSERVERERROR         500
38 #define OSRF_STATUS_NOTIMPLEMENTED                              501
39 #define OSRF_STATUS_VERSIONNOTSUPPORTED         505
40
41
42 enum M_TYPE { CONNECT, REQUEST, RESULT, STATUS, DISCONNECT };
43
44 #define OSRF_MAX_PARAMS                                                         128;
45
46 struct osrf_message_struct {
47
48         enum M_TYPE m_type;
49         int thread_trace;
50         int protocol;
51
52         /* if we're a STATUS message */
53         char* status_name;
54
55         /* if we're a STATUS or RESULT */
56         char* status_text;
57         int status_code;
58
59         int is_exception;
60
61         /* if we're a RESULT */
62         jsonObject* _result_content;
63
64         /* unparsed json string */
65         char* result_string;
66
67         /* if we're a REQUEST */
68         char* method_name;
69
70         jsonObject* _params;
71
72         /* in case anyone wants to make a list of us.  
73                 we won't touch this variable */
74         struct osrf_message_struct* next;
75
76         char* full_param_string;
77
78         /* magical LOCALE hint */
79         char* sender_locale;
80
81         /* timezone offset from GMT of sender, in seconds */
82         int sender_tz_offset;
83
84 };
85 typedef struct osrf_message_struct osrf_message;
86 typedef struct osrf_message_struct osrfMessage;
87
88 /* Set the locale hint for this message.
89    default_locale is used if not set.
90    Returns NULL if msg or locale is not set, char* to msg->sender_locale on success.
91 */
92 char* osrf_message_set_locale( osrf_message* msg, const char* locale );
93
94 /* Set the default locale hint to be used for future outgoing messages.
95    Returns NULL if locale is NULL, const char* to default_locale otherwise.
96 */
97 const char* osrf_message_set_default_locale( const char* locale );
98
99 /* Get the current locale hint -- either the default or most recently received locale.
100    Returns const char* to current_locale.
101 */
102 const char* osrf_message_get_current_locale(void);
103
104 osrf_message* osrf_message_init( enum M_TYPE type, int thread_trace, int protocol );
105 //void osrf_message_set_request_info( osrf_message*, char* param_name, json* params );
106 void osrf_message_set_status_info( osrf_message*,
107                 const char* status_name, const char* status_text, int status_code );
108 void osrf_message_set_result_content( osrf_message*, const char* json_string );
109 void osrfMessageFree( osrfMessage* );
110 void osrf_message_free( osrf_message* );
111 char* osrf_message_to_xml( osrf_message* );
112 char* osrf_message_serialize(const osrf_message*);
113
114 /* count is the max number of messages we'll put into msgs[] */
115 int osrf_message_deserialize(const char* json, osrf_message* 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, osrf_message* msgs[] );
124
125 void osrf_message_set_params( osrf_message* msg, const jsonObject* o );
126 void osrf_message_set_method( osrf_message* msg, const char* method_name );
127 void osrf_message_add_object_param( osrf_message* msg, const jsonObject* o );
128 void osrf_message_add_param( osrf_message*, 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
142 #endif