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