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