]> git.evergreen-ils.org Git - OpenSRF.git/blob - include/opensrf/osrf_message.h
added some basic exception handling and propogation
[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         /* if we're a REQUEST */
51         char* method_name;
52         json* params;
53
54         /* in case anyone wants to make a list of us.  
55                 we won't touch this variable */
56         struct osrf_message_struct* next;
57
58 };
59 typedef struct osrf_message_struct osrf_message;
60
61
62 osrf_message* osrf_message_init( enum M_TYPE type, int thread_trace, int protocol );
63 void osrf_message_set_request_info( osrf_message*, char* param_name, json* params );
64 void osrf_message_set_status_info( osrf_message*, char* status_name, char* status_text, int status_code );
65 void osrf_message_set_result_content( osrf_message*, json* result_content );
66 void osrf_message_free( osrf_message* );
67 char* osrf_message_to_xml( osrf_message* );
68 /** Pushes any message retreived from the xml into the 'msgs' array.
69   * it is assumed that 'msgs' has beenn pre-allocated.
70   * Returns the number of message that are in the buffer.
71   */
72 int osrf_message_from_xml( char* xml, osrf_message* msgs[] );
73
74
75
76
77 #endif