This update restructures the mechanism for queueing incoming transport
[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         struct transport_message_struct* next;
38 };
39 typedef struct transport_message_struct transport_message;
40
41 // ---------------------------------------------------------------------------------
42 // Allocates and returns a transport_message.  All chars are safely re-allocated
43 // within this method.
44 // Returns NULL on error
45 // ---------------------------------------------------------------------------------
46 transport_message* message_init( const char* body, const char* subject, 
47                 const char* thread, const char* recipient, const char* sender );
48
49 transport_message* new_message_from_xml( const char* msg_xml );
50
51
52 void message_set_router_info( transport_message* msg, const char* router_from,
53                 const char* router_to, const char* router_class, const char* router_command,
54                 int broadcast_enabled );
55
56 void message_set_osrf_xid( transport_message* msg, const char* osrf_xid );
57
58 // ---------------------------------------------------------------------------------
59 // Call this to create the encoded XML for sending on the wire.
60 // This is a seperate function so that encoding will not necessarily have
61 // to happen on all messages (i.e. typically only occurs outbound messages).
62 // ---------------------------------------------------------------------------------
63 int message_prepare_xml( transport_message* msg );
64
65 // ---------------------------------------------------------------------------------
66 // Deallocates the memory used by the transport_message
67 // Returns 0 on error
68 // ---------------------------------------------------------------------------------
69 int message_free( transport_message* msg );
70
71 // ---------------------------------------------------------------------------------
72 // Determines the username of a Jabber ID.  This expects a pre-allocated char 
73 // array for the return value.
74 // ---------------------------------------------------------------------------------
75 void jid_get_username( const char* jid, char buf[], int size );
76
77 // ---------------------------------------------------------------------------------
78 // Determines the resource of a Jabber ID.  This expects a pre-allocated char 
79 // array for the return value.
80 // ---------------------------------------------------------------------------------
81 void jid_get_resource( const char* jid, char buf[], int size );
82
83 /** Puts the domain portion of the given jid into the pre-allocated buffer */
84 void jid_get_domain( const char* jid, char buf[], int size );
85
86 void set_msg_error( transport_message*, const char* error_type, int error_code);
87
88
89 #endif