9 #include <libxml/globals.h>
10 #include <libxml/xmlerror.h>
11 #include <libxml/parser.h>
12 #include <libxml/parserInternals.h> /* only for xmlNewInputFromFile() */
13 #include <libxml/tree.h>
14 #include <libxml/debugXML.h>
15 #include <libxml/xmlmemory.h>
19 #define JABBER_STATE_CONNECTED 2
20 #define JABBER_STATE_CONNECTING 4
21 #define JABBER_STATE_IN_MESSAGE 8
24 struct jserver_session_struct {
26 /* our connection state */
29 /* incoming XML is parsed with the SAX parser */
30 xmlParserCtxtPtr parser_ctxt;
32 /* incoming message are shoved into this DOM doc after they are parsed */
33 xmlDocPtr current_msg;
35 /* we have to grab off the from and to for routing */
40 char* current_resource;
41 char* current_username;
47 void* blob; /* callback blob - can be anything that needs passing around */
48 void (*on_msg_complete) (void* blob, char* msg_xml, char* from, char* to );
50 /* happens after someone logs in and we've pieced together the from address */
51 void (*on_from_discovered) (void* blob, char* from );
52 void (*on_login_init) (void* blob, char* reply );
53 void (*on_login_ok) (void* blob);
54 void (*on_client_finish) (void* blob);
57 typedef struct jserver_session_struct jserver_session;
60 jserver_session* jserver_session_init();
61 void jserver_session_free(jserver_session* session);
62 char* sax_xml_attr( const xmlChar** atts, char* attr_name );
63 int jserver_session_push_data(jserver_session* session, char* data);
65 void dom_add_attrs(xmlNodePtr node, const xmlChar** atts);
66 char* _xml_to_string( xmlDocPtr doc );
69 // ---------------------------------------------------------------------------------
71 // ---------------------------------------------------------------------------------
72 void sax_start_element(
73 void *session, const xmlChar *name, const xmlChar **atts);
75 void sax_end_element( void* blob, const xmlChar *name);
77 void sax_start_doc(void* blob);
78 //void sax_end_doc(void* blob);
80 void sax_character( void* blob, const xmlChar *ch, int len);
82 void sax_warning( void* blob, const char* msg, ... );
84 static xmlSAXHandler sax_handler_struct = {
85 NULL, /* internalSubset */
86 NULL, /* isStandalone */
87 NULL, /* hasInternalSubset */
88 NULL, /* hasExternalSubset */
89 NULL, /* resolveEntity */
91 NULL, /* entityDecl */
92 NULL, /* notationDecl */
93 NULL, /* attributeDecl */
94 NULL, /* elementDecl */
95 NULL, /* unparsedEntityDecl */
96 NULL, /* setDocumentLocator */
97 sax_start_doc, /* startDocument */
98 NULL, /* endDocument */
99 sax_start_element, /* startElement */
100 sax_end_element, /* endElement */
101 NULL, /* reference */
102 sax_character, /* characters */
103 NULL, /* ignorableWhitespace */
104 NULL, /* processingInstruction */
106 sax_warning, /* xmlParserWarning */
107 sax_warning, /* xmlParserError */
108 NULL, /* xmlParserFatalError : unused */
109 NULL, /* getParameterEntity */
110 NULL, /* cdataBlock; */
111 NULL, /* externalSubset; */
114 NULL, /* startElementNs */
115 NULL, /* endElementNs */
116 NULL /* xmlStructuredErrorFunc */
119 static const xmlSAXHandlerPtr sax_handler = &sax_handler_struct;