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