7 #include <libxml/globals.h>
8 #include <libxml/xmlerror.h>
9 #include <libxml/parser.h>
10 #include <libxml/parserInternals.h> /* only for xmlNewInputFromFile() */
11 #include <libxml/tree.h>
12 #include <libxml/debugXML.h>
13 #include <libxml/xmlmemory.h>
17 #define JABBER_STATE_CONNECTED 2
18 #define JABBER_STATE_CONNECTING 4
19 #define JABBER_STATE_IN_MESSAGE 8
22 struct jserver_session_struct {
24 /* our connection state */
27 /* incoming XML is parsed with the SAX parser */
28 xmlParserCtxtPtr parser_ctxt;
30 /* incoming message are shoved into this DOM doc after they are parsed */
31 xmlDocPtr current_msg;
33 /* we have to grab off the from and to for routing */
38 char* current_resource;
39 char* current_username;
45 void* blob; /* callback blob - can be anything that needs passing around */
46 void (*on_msg_complete) (void* blob, char* msg_xml, char* from, char* to );
48 /* happens after someone logs in and we've pieced together the from address */
49 void (*on_from_discovered) (void* blob, char* from );
50 void (*on_login_init) (void* blob, char* reply );
51 void (*on_login_ok) (void* blob);
52 void (*on_client_finish) (void* blob);
55 typedef struct jserver_session_struct jserver_session;
58 jserver_session* jserver_session_init();
59 void jserver_session_free(jserver_session* session);
60 char* sax_xml_attr( const xmlChar** atts, char* attr_name );
61 int jserver_session_push_data(jserver_session* session, char* data);
63 void dom_add_attrs(xmlNodePtr node, const xmlChar** atts);
64 char* _xml_to_string( xmlDocPtr doc );
67 // ---------------------------------------------------------------------------------
69 // ---------------------------------------------------------------------------------
70 void sax_start_element(
71 void *session, const xmlChar *name, const xmlChar **atts);
73 void sax_end_element( void* blob, const xmlChar *name);
75 void sax_start_doc(void* blob);
76 //void sax_end_doc(void* blob);
78 void sax_character( void* blob, const xmlChar *ch, int len);
80 void sax_warning( void* blob, const char* msg, ... );
82 static xmlSAXHandler sax_handler_struct = {
83 NULL, /* internalSubset */
84 NULL, /* isStandalone */
85 NULL, /* hasInternalSubset */
86 NULL, /* hasExternalSubset */
87 NULL, /* resolveEntity */
89 NULL, /* entityDecl */
90 NULL, /* notationDecl */
91 NULL, /* attributeDecl */
92 NULL, /* elementDecl */
93 NULL, /* unparsedEntityDecl */
94 NULL, /* setDocumentLocator */
95 sax_start_doc, /* startDocument */
96 NULL, /* endDocument */
97 sax_start_element, /* startElement */
98 sax_end_element, /* endElement */
100 sax_character, /* characters */
101 NULL, /* ignorableWhitespace */
102 NULL, /* processingInstruction */
104 sax_warning, /* xmlParserWarning */
105 sax_warning, /* xmlParserError */
106 NULL, /* xmlParserFatalError : unused */
107 NULL, /* getParameterEntity */
108 NULL, /* cdataBlock; */
109 NULL, /* externalSubset; */
112 NULL, /* startElementNs */
113 NULL, /* endElementNs */
114 NULL /* xmlStructuredErrorFunc */
117 static const xmlSAXHandlerPtr sax_handler = &sax_handler_struct;