logging returned content at info level
[OpenSRF.git] / src / jserver / jserver-c_session.h
1 #define _GNU_SOURCE
2
3 #include "opensrf/utils.h"
4 #include "opensrf/logging.h"
5
6 #include "jstrings.h"
7
8 #include <stdio.h>
9 #include <string.h>
10
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>
18
19
20 /* session states */
21 #define JABBER_STATE_CONNECTED                  2
22 #define JABBER_STATE_CONNECTING                 4 
23 #define JABBER_STATE_IN_MESSAGE                 8       
24
25
26 struct jserver_session_struct {
27
28         /* our connection state */
29         unsigned int state;
30
31         /* incoming XML is parsed with the SAX parser */
32         xmlParserCtxtPtr parser_ctxt;
33
34         /* incoming message are shoved into this DOM doc after they are parsed */
35         xmlDocPtr current_msg;
36
37         /* we have to grab off the from and to for routing */
38         char* current_to;
39         char* current_from;
40
41         char* current_domain;
42         char* current_resource;
43         char* current_username;
44
45         int in_iq;
46         int in_uname;
47         int in_resource;
48
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 );
51
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);
57
58 };
59 typedef struct jserver_session_struct jserver_session;
60
61
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);
66
67 void dom_add_attrs(xmlNodePtr node, const xmlChar** atts);
68 char* _xml_to_string( xmlDocPtr doc ); 
69
70
71 // ---------------------------------------------------------------------------------
72 // Our SAX handlers 
73 // ---------------------------------------------------------------------------------
74 void sax_start_element( 
75                 void *session, const xmlChar *name, const xmlChar **atts);
76
77 void sax_end_element( void* blob, const xmlChar *name);
78
79 void sax_start_doc(void* blob);
80 //void sax_end_doc(void* blob);
81
82 void sax_character( void* blob, const xmlChar *ch, int len);
83
84 void  sax_warning( void* blob, const char* msg, ... );
85
86 static xmlSAXHandler sax_handler_struct = {
87    NULL,                                                /* internalSubset */
88    NULL,                                                /* isStandalone */
89    NULL,                                                /* hasInternalSubset */
90    NULL,                                                /* hasExternalSubset */
91    NULL,                                                /* resolveEntity */
92    NULL,                                                /* getEntity */
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 */
107    NULL,                                                /* comment */
108    sax_warning,                 /* xmlParserWarning */
109    sax_warning,                 /* xmlParserError */
110    NULL,                                                /* xmlParserFatalError : unused */
111    NULL,                                                /* getParameterEntity */
112    NULL,                                                /* cdataBlock; */
113    NULL,                                                /* externalSubset; */
114    1,
115    NULL,
116    NULL,                                                /* startElementNs */
117    NULL,                                                /* endElementNs */
118         NULL                                            /* xmlStructuredErrorFunc */
119 };
120
121 static const xmlSAXHandlerPtr sax_handler = &sax_handler_struct;