]> git.evergreen-ils.org Git - working/Evergreen.git/blob - OpenSRF/src/libstack/osrf_message.h
added CONNECT handling
[working/Evergreen.git] / OpenSRF / src / libstack / osrf_message.h
1 #include "opensrf/string_array.h"
2 #include "opensrf/utils.h"
3 #include "opensrf/logging.h"
4 #include "objson/object.h"
5 #include "objson/json_parser.h"
6
7
8 /* libxml stuff for the config reader */
9 #include <libxml/xmlmemory.h>
10 #include <libxml/parser.h>
11 #include <libxml/xpath.h>
12 #include <libxml/xpathInternals.h>
13 #include <libxml/tree.h>
14
15
16
17 #ifndef osrf_message_h
18 #define osrf_message_h
19
20 #define OSRF_XML_NAMESPACE "http://open-ils.org/xml/namespaces/oils_v1"
21
22 #define OSRF_STATUS_CONTINUE                                            100
23
24 #define OSRF_STATUS_OK                                                          200
25 #define OSRF_STATUS_ACCEPTED                                            202
26 #define OSRF_STATUS_COMPLETE                                            205
27
28 #define OSRF_STATUS_REDIRECTED                                  307
29
30 #define OSRF_STATUS_BADREQUEST                                  400
31 #define OSRF_STATUS_UNAUTHORIZED                                        401
32 #define OSRF_STATUS_FORBIDDEN                                           403
33 #define OSRF_STATUS_NOTFOUND                                            404
34 #define OSRF_STATUS_NOTALLOWED                                  405
35 #define OSRF_STATUS_TIMEOUT                                             408
36 #define OSRF_STATUS_EXPFAILED                                           417
37
38 #define OSRF_STATUS_INTERNALSERVERERROR         500
39 #define OSRF_STATUS_NOTIMPLEMENTED                              501
40 #define OSRF_STATUS_VERSIONNOTSUPPORTED         505
41
42
43 enum M_TYPE { CONNECT, REQUEST, RESULT, STATUS, DISCONNECT };
44
45 #define OSRF_MAX_PARAMS                                                         128;
46
47 struct osrf_message_struct {
48
49         enum M_TYPE m_type;
50         int thread_trace;
51         int protocol;
52
53         /* if we're a STATUS message */
54         char* status_name;
55
56         /* if we're a STATUS or RESULT */
57         char* status_text;
58         int status_code;
59
60         int is_exception;
61
62         /* if we're a RESULT */
63         jsonObject* _result_content;
64
65         /* unparsed json string */
66         char* result_string;
67
68         /* if we're a REQUEST */
69         char* method_name;
70
71         jsonObject* _params;
72
73         /* in case anyone wants to make a list of us.  
74                 we won't touch this variable */
75         struct osrf_message_struct* next;
76
77         char* full_param_string;
78
79 };
80 typedef struct osrf_message_struct osrf_message;
81 typedef struct osrf_message_struct osrfMessage;
82
83
84 osrf_message* osrf_message_init( enum M_TYPE type, int thread_trace, int protocol );
85 //void osrf_message_set_request_info( osrf_message*, char* param_name, json* params );
86 void osrf_message_set_status_info( osrf_message*, char* status_name, char* status_text, int status_code );
87 void osrf_message_set_result_content( osrf_message*, char* json_string );
88 void osrfMessageFree( osrfMessage* );
89 void osrf_message_free( osrf_message* );
90 char* osrf_message_to_xml( osrf_message* );
91 char* osrf_message_serialize(osrf_message*);
92
93 /* count is the max number of messages we'll put into msgs[] */
94 int osrf_message_deserialize(char* json, osrf_message* msgs[], int count);
95
96
97
98 /** Pushes any message retreived from the xml into the 'msgs' array.
99   * it is assumed that 'msgs' has beenn pre-allocated.
100   * Returns the number of message that are in the buffer.
101   */
102 int osrf_message_from_xml( char* xml, osrf_message* msgs[] );
103
104 void osrf_message_set_params( osrf_message* msg, jsonObject* o );
105 void osrf_message_set_method( osrf_message* msg, char* method_name );
106 void osrf_message_add_object_param( osrf_message* msg, jsonObject* o );
107 void osrf_message_add_param( osrf_message*, char* param_string );
108
109
110 jsonObject* osrfMessageGetResult( osrfMessage* msg );
111
112 /**
113   Returns the message as a jsonObject
114   @return The jsonObject which must be freed by the caller.
115   */
116 jsonObject* osrfMessageToJSON( osrfMessage* msg );
117
118 char* osrfMessageSerializeBatch( osrfMessage* msgs [], int count );
119
120
121 #endif