]> git.evergreen-ils.org Git - OpenSRF.git/blob - include/opensrf/osrf_message.h
d9255ce79b53ee340659c1e4be125a1f8ccd94db
[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 #ifdef __cplusplus
15 extern "C" {
16 #endif
17
18 #define OSRF_XML_NAMESPACE "http://open-ils.org/xml/namespaces/oils_v1"
19
20 #define OSRF_STATUS_CONTINUE                                            100
21
22 #define OSRF_STATUS_OK                                                          200
23 #define OSRF_STATUS_ACCEPTED                                            202
24 #define OSRF_STATUS_COMPLETE                                            205
25
26 #define OSRF_STATUS_REDIRECTED                                  307
27
28 #define OSRF_STATUS_BADREQUEST                                  400
29 #define OSRF_STATUS_UNAUTHORIZED                                        401
30 #define OSRF_STATUS_FORBIDDEN                                           403
31 #define OSRF_STATUS_NOTFOUND                                            404
32 #define OSRF_STATUS_NOTALLOWED                                  405
33 #define OSRF_STATUS_TIMEOUT                                             408
34 #define OSRF_STATUS_EXPFAILED                                           417
35
36 #define OSRF_STATUS_INTERNALSERVERERROR         500
37 #define OSRF_STATUS_NOTIMPLEMENTED                              501
38 #define OSRF_STATUS_VERSIONNOTSUPPORTED         505
39
40
41 enum M_TYPE { CONNECT, REQUEST, RESULT, STATUS, DISCONNECT };
42
43 #define OSRF_MAX_PARAMS                                                         128;
44
45 struct osrf_message_struct {
46
47         enum M_TYPE m_type;
48         int thread_trace;
49         int protocol;
50
51         /* if we're a STATUS message */
52         char* status_name;
53
54         /* if we're a STATUS or RESULT */
55         char* status_text;
56         int status_code;
57
58         int is_exception;
59
60         /* if we're a RESULT */
61         jsonObject* _result_content;
62
63         /* unparsed json string */
64         char* result_string;
65
66         /* if we're a REQUEST */
67         char* method_name;
68
69         jsonObject* _params;
70
71         /* in case anyone wants to make a list of us.  
72                 we won't touch this variable */
73         struct osrf_message_struct* next;
74
75         /* magical LOCALE hint */
76         char* sender_locale;
77
78         /* timezone offset from GMT of sender, in seconds */
79         int sender_tz_offset;
80
81 };
82 typedef struct osrf_message_struct osrfMessage;
83
84 const char* osrf_message_set_locale( osrfMessage* msg, const char* locale );
85
86 const char* osrf_message_set_default_locale( const char* locale );
87
88 const char* osrf_message_get_last_locale(void);
89
90 osrfMessage* osrf_message_init( enum M_TYPE type, int thread_trace, int protocol );
91
92 void osrf_message_set_status_info( osrfMessage*,
93                 const char* status_name, const char* status_text, int status_code );
94
95 void osrf_message_set_result_content( osrfMessage*, const char* json_string );
96
97 void osrfMessageFree( osrfMessage* );
98
99 char* osrf_message_to_xml( osrfMessage* );
100
101 char* osrf_message_serialize(const osrfMessage*);
102
103 osrfList* osrfMessageDeserialize( const char* string, osrfList* list );
104
105 int osrf_message_deserialize(const char* json, osrfMessage* msgs[], int count);
106
107 void osrf_message_set_params( osrfMessage* msg, const jsonObject* o );
108
109 void osrf_message_set_method( osrfMessage* msg, const char* method_name );
110
111 void osrf_message_add_object_param( osrfMessage* msg, const jsonObject* o );
112
113 void osrf_message_add_param( osrfMessage*, const char* param_string );
114
115 jsonObject* osrfMessageGetResult( osrfMessage* msg );
116
117 char* osrfMessageSerializeBatch( osrfMessage* msgs [], int count );
118
119 #ifdef __cplusplus
120 }
121 #endif
122
123 #endif