3 #include "opensrf/utils.h"
4 #include "opensrf/logging.h"
11 #include <libxml/globals.h>
12 #include <libxml/xmlerror.h>
13 #include <libxml/parser.h>
14 #include <libxml/parserInternals.h> /* only for xmlNewInputFromFile() */
15 #include <libxml/tree.h>
16 #include <libxml/debugXML.h>
17 #include <libxml/xmlmemory.h>
21 #define JABBER_STATE_CONNECTED 2
22 #define JABBER_STATE_CONNECTING 4
23 #define JABBER_STATE_IN_MESSAGE 8
26 struct jserver_session_struct {
28 /* our connection state */
31 /* incoming XML is parsed with the SAX parser */
32 xmlParserCtxtPtr parser_ctxt;
34 /* incoming message are shoved into this DOM doc after they are parsed */
35 xmlDocPtr current_msg;
37 /* we have to grab off the from and to for routing */
42 char* current_resource;
43 char* current_username;
49 void* blob; /* callback blob - can be anything that needs passing around */
50 void (*on_msg_complete) (void* blob, char* msg_xml, char* from, char* to );
52 /* happens after someone logs in and we've pieced together the from address */
53 void (*on_from_discovered) (void* blob, char* from );
54 void (*on_login_init) (void* blob, char* reply );
55 void (*on_login_ok) (void* blob);
56 void (*on_client_finish) (void* blob);
59 typedef struct jserver_session_struct jserver_session;
62 jserver_session* jserver_session_init();
63 void jserver_session_free(jserver_session* session);
64 char* sax_xml_attr( const xmlChar** atts, char* attr_name );
65 int jserver_session_push_data(jserver_session* session, char* data);
67 void dom_add_attrs(xmlNodePtr node, const xmlChar** atts);
68 char* _xml_to_string( xmlDocPtr doc );
71 // ---------------------------------------------------------------------------------
73 // ---------------------------------------------------------------------------------
74 void sax_start_element(
75 void *session, const xmlChar *name, const xmlChar **atts);
77 void sax_end_element( void* blob, const xmlChar *name);
79 void sax_start_doc(void* blob);
80 //void sax_end_doc(void* blob);
82 void sax_character( void* blob, const xmlChar *ch, int len);
84 void sax_warning( void* blob, const char* msg, ... );
86 static xmlSAXHandler sax_handler_struct = {
87 NULL, /* internalSubset */
88 NULL, /* isStandalone */
89 NULL, /* hasInternalSubset */
90 NULL, /* hasExternalSubset */
91 NULL, /* resolveEntity */
93 NULL, /* entityDecl */
94 NULL, /* notationDecl */
95 NULL, /* attributeDecl */
96 NULL, /* elementDecl */
97 NULL, /* unparsedEntityDecl */
98 NULL, /* setDocumentLocator */
99 sax_start_doc, /* startDocument */
100 NULL, /* endDocument */
101 sax_start_element, /* startElement */
102 sax_end_element, /* endElement */
103 NULL, /* reference */
104 sax_character, /* characters */
105 NULL, /* ignorableWhitespace */
106 NULL, /* processingInstruction */
108 sax_warning, /* xmlParserWarning */
109 sax_warning, /* xmlParserError */
110 NULL, /* xmlParserFatalError : unused */
111 NULL, /* getParameterEntity */
112 NULL, /* cdataBlock; */
113 NULL, /* externalSubset; */
116 NULL, /* startElementNs */
117 NULL, /* endElementNs */
118 NULL /* xmlStructuredErrorFunc */
121 static const xmlSAXHandlerPtr sax_handler = &sax_handler_struct;