]> git.evergreen-ils.org Git - OpenSRF.git/blob - include/opensrf/transport_message.h
ddd8f390591ffd7c7930cad464b31aded728147f
[OpenSRF.git] / include / opensrf / transport_message.h
1 #include <string.h>
2 #include <libxml/globals.h>
3 #include <libxml/xmlerror.h>
4 #include <libxml/parser.h>
5 #include <libxml/tree.h>
6 #include <libxml/debugXML.h>
7 #include <libxml/xmlmemory.h>
8
9 #include <opensrf/utils.h>
10 #include <opensrf/xml_utils.h>
11 #include <opensrf/log.h>
12
13 #ifndef TRANSPORT_MESSAGE_H
14 #define TRANSPORT_MESSAGE_H
15
16
17
18 // ---------------------------------------------------------------------------------
19 // Jabber message object.
20 // ---------------------------------------------------------------------------------
21 struct transport_message_struct {
22         char* body;
23         char* subject;
24         char* thread;
25         char* recipient;
26         char* sender;
27         char* router_from;
28         char* router_to;
29         char* router_class;
30         char* router_command;
31    char* osrf_xid;
32         int is_error;
33         char* error_type;
34         int error_code;
35         int broadcast;
36         char* msg_xml; /* the entire message as XML complete with entity encoding */
37 };
38 typedef struct transport_message_struct transport_message;
39
40 // ---------------------------------------------------------------------------------
41 // Allocates and returns a transport_message.  All chars are safely re-allocated
42 // within this method.
43 // Returns NULL on error
44 // ---------------------------------------------------------------------------------
45 transport_message* message_init( char* body, char* subject, 
46                 char* thread, char* recipient, char* sender );
47
48 transport_message* new_message_from_xml( const char* msg_xml );
49
50
51 void message_set_router_info( transport_message* msg, char* router_from,
52                 char* router_to, char* router_class, char* router_command, int broadcast_enabled );
53
54 void message_set_osrf_xid( transport_message* msg, char* osrf_xid );
55
56 // ---------------------------------------------------------------------------------
57 // Formats the Jabber message as XML for encoding. 
58 // Returns NULL on error
59 // ---------------------------------------------------------------------------------
60 char* message_to_xml( const transport_message* msg );
61
62
63 // ---------------------------------------------------------------------------------
64 // Call this to create the encoded XML for sending on the wire.
65 // This is a seperate function so that encoding will not necessarily have
66 // to happen on all messages (i.e. typically only occurs outbound messages).
67 // ---------------------------------------------------------------------------------
68 int message_prepare_xml( transport_message* msg );
69
70 // ---------------------------------------------------------------------------------
71 // Deallocates the memory used by the transport_message
72 // Returns 0 on error
73 // ---------------------------------------------------------------------------------
74 int message_free( transport_message* msg );
75
76 // ---------------------------------------------------------------------------------
77 // Prepares the shared XML document
78 // ---------------------------------------------------------------------------------
79 //int message_init_xml();
80
81 // ---------------------------------------------------------------------------------
82 // Determines the username of a Jabber ID.  This expects a pre-allocated char 
83 // array for the return value.
84 // ---------------------------------------------------------------------------------
85 void jid_get_username( const char* jid, char buf[], int size );
86
87 // ---------------------------------------------------------------------------------
88 // Determines the resource of a Jabber ID.  This expects a pre-allocated char 
89 // array for the return value.
90 // ---------------------------------------------------------------------------------
91 void jid_get_resource( const char* jid, char buf[], int size );
92
93 /** Puts the domain portion of the given jid into the pre-allocated buffer */
94 void jid_get_domain( const char* jid, char buf[], int size );
95
96 void set_msg_error( transport_message*, char* error_type, int error_code);
97
98
99 #endif