]> git.evergreen-ils.org Git - OpenSRF.git/blob - include/opensrf/osrf_message.h
a4beb689a43e35dc9a49dfa18fe3e62f7d6bd70e
[OpenSRF.git] / include / opensrf / osrf_message.h
1 #include "libjson/json.h"
2 #include "opensrf/generic_utils.h"
3
4 #ifndef osrf_message_h
5 #define osrf_message_h
6
7 #define OSRF_XML_NAMESPACE "http://open-ils.org/xml/namespaces/oils_v1"
8
9 #define OSRF_STATUS_CONTINUE                                            100
10
11 #define OSRF_STATUS_OK                                                          200
12 #define OSRF_STATUS_ACCEPTED                                            202
13 #define OSRF_STATUS_COMPLETE                                            205
14
15 #define OSRF_STATUS_REDIRECTED                                  307
16
17 #define OSRF_STATUS_BADREQUEST                                  400
18 #define OSRF_STATUS_UNAUTHORIZED                                        401
19 #define OSRF_STATUS_FORBIDDEN                                           403
20 #define OSRF_STATUS_NOTFOUND                                            404
21 #define OSRF_STATUS_NOTALLOWED                                  405
22 #define OSRF_STATUS_TIMEOUT                                             408
23 #define OSRF_STATUS_EXPFAILED                                           417
24
25 #define OSRF_STATUS_INTERNALSERVERERROR         500
26 #define OSRF_STATUS_NOTIMPLEMENTED                              501
27 #define OSRF_STATUS_VERSIONNOTSUPPORTED         505
28
29
30 enum M_TYPE { CONNECT, REQUEST, RESULT, STATUS, DISCONNECT };
31
32 struct osrf_message_struct {
33
34         enum M_TYPE m_type;
35         int thread_trace;
36         int protocol;
37         
38         /* if we're a STATUS message */
39         char* status_name;
40
41         /* if we're a STATUS or RESULT */
42         char* status_text;
43         int status_code;
44
45         int is_exception;
46
47         /* if we're a RESULT */
48         json* result_content;
49
50         /* unparsed json string */
51         char* result_string;
52
53         /* if we're a REQUEST */
54         char* method_name;
55         json* params;
56
57         /* in case anyone wants to make a list of us.  
58                 we won't touch this variable */
59         struct osrf_message_struct* next;
60
61 };
62 typedef struct osrf_message_struct osrf_message;
63
64
65 osrf_message* osrf_message_init( enum M_TYPE type, int thread_trace, int protocol );
66 void osrf_message_set_request_info( osrf_message*, char* param_name, json* params );
67 void osrf_message_set_status_info( osrf_message*, char* status_name, char* status_text, int status_code );
68 void osrf_message_set_result_content( osrf_message*, json* result_content );
69 void osrf_message_free( osrf_message* );
70 char* osrf_message_to_xml( osrf_message* );
71 /** Pushes any message retreived from the xml into the 'msgs' array.
72   * it is assumed that 'msgs' has beenn pre-allocated.
73   * Returns the number of message that are in the buffer.
74   */
75 int osrf_message_from_xml( char* xml, osrf_message* msgs[] );
76
77
78
79
80 #endif