added external file to hold the commonly used jabber XML
authorerickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Wed, 17 Aug 2005 15:16:22 +0000 (15:16 +0000)
committererickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Wed, 17 Aug 2005 15:16:22 +0000 (15:16 +0000)
git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@488 9efc2488-bf62-4759-914b-345cdb29e865

src/jserver/jserver-c.c
src/jserver/jserver-c.h
src/jserver/jserver-c_session.c
src/jserver/jserver-c_session.h
src/jserver/jstrings.h [new file with mode: 0644]

index d7e923e..9590708 100644 (file)
@@ -1,16 +1,5 @@
 #include "jserver-c.h"
 
-/* ------------------------------------------------
-       some pre-packaged Jabber XML
-       ------------------------------------------------ */
-static const char* xml_parse_error = "<stream:stream xmlns:stream='http://etherx.jabber.org/streams'" 
-       "version='1.0'><stream:error xmlns:stream='http://etherx.jabber.org/streams'>"
-       "<xml-not-well-formed xmlns='urn:ietf:params:xml:ns:xmpp-streams'/>"
-       "<text xmlns='urn:ietf:params:xml:ns:xmpp-streams'>syntax error</text></stream:error></stream:stream>";
-
-static const char* xml_login_ok = "<iq xmlns='jabber:client' id='asdfjkl' type='result'/>";
-
-
 jserver* jserver_init() {
        jserver* js                                     = safe_malloc(sizeof(jserver));
        js->mgr                                         = safe_malloc(sizeof(socket_manager));
@@ -112,7 +101,8 @@ void jserver_client_login_ok(void* blob) {
        jclient_node* node = (jclient_node*) blob;
        if(node == NULL) return;
        info_handler("Client logging in ok => %d", node->id);
-       jserver_send_id(node->id, xml_login_ok);
+       //jserver_send_id(node->id, xml_login_ok);
+       jserver_send_id(node->id, JSTRING_LOGIN_OK);
 }
 
 void jserver_client_handle_msg( 
@@ -249,10 +239,13 @@ int jserver_send(jserver* js, int from_id, char* to_addr, const char* msg_xml) {
                                info_handler("replying with error...");
                                char buf[2048];
                                memset(buf, 0, 2048);
+                               /*
                                snprintf(buf, 2047, "<message xmlns='jabber:client' type='error' from='%s' "
                                        "to='%s'><error type='cancel' code='404'><item-not-found "
                                        "xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error>"
                                        "<body>NOT ADDING BODY</body></message>", to_addr, from->addr );
+                                       */
+                               snprintf(buf, 2047, JSTRING_NO_RECIPIENT, to_addr, from->addr );
                                jserver_send_id(from_id, buf);
                        }
                }
@@ -299,7 +292,8 @@ void jserver_handle_request(void* js_blob,
 
        if(_jserver_push_client_data(node, data) == -1) {
                warning_handler("Client sent bad data, disconnecting...");
-               jserver_send_id(node->id, xml_parse_error);
+               //jserver_send_id(node->id, xml_parse_error);
+               jserver_send_id(node->id, JSTRING_PARSE_ERROR);
                _jserver_remove_client(js, node->addr);         
 
        } else {
@@ -310,4 +304,3 @@ void jserver_handle_request(void* js_blob,
 
 
 
-
index 36026ec..d215a12 100644 (file)
@@ -2,6 +2,7 @@
 #include "logging.h"
 #include "socket_bundle.h"
 #include "jserver-c_session.h"
+#include "jstrings.h"
 
 
 
index 4652ccb..7c69c1c 100644 (file)
@@ -83,13 +83,9 @@ void sax_start_element(
                        debug_handler("jserver-c_session received opening stream from client on domain %s", 
                                session->current_domain);
 
-                       char buf[512];
-                       memset(buf,0,512);
-
-                       /* reply with the stock jabber login response */
-                       sprintf(buf, "<?xml version='1.0'?><stream:stream xmlns:stream='http://etherx.jabber.org/streams' " 
-                               "xmlns='jabber:client' from='%s' to='%s' version='1.0' id='d253et09iw1fv8a2noqc38f28sb0y5fc7kfmegvx'>",
-                               session->current_domain, from_domain);
+                       char buf[1024];
+                       memset(buf,0,1024);
+                       snprintf(buf, 1023, JSTRING_START_STREAM, session->current_domain, from_domain);
 
                        debug_handler("Session Sending: %s", buf);
 
index 9761339..d90b048 100644 (file)
@@ -3,6 +3,8 @@
 #include "utils.h"
 #include "logging.h"
 
+#include "jstrings.h"
+
 #include <stdio.h>
 #include <string.h>
 
diff --git a/src/jserver/jstrings.h b/src/jserver/jstrings.h
new file mode 100644 (file)
index 0000000..bc9878c
--- /dev/null
@@ -0,0 +1,17 @@
+/* ------------------------------------------------
+       some pre-packaged Jabber XML
+       ------------------------------------------------ */
+
+#ifndef _JSTRINGS_H_
+#define _JSTRINGS_H_
+
+#define JSTRING_START_STREAM "<?xml version='1.0'?><stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' from='%s' to='%s' version='1.0' id='d253et09iw1fv8a2noqc38f28sb0y5fc7kfmegvx'>" /* this will need to by dynamic when we add login handling */
+
+
+#define JSTRING_PARSE_ERROR "<stream:stream xmlns:stream='http://etherx.jabber.org/streams' version='1.0'><stream:error xmlns:stream='http://etherx.jabber.org/streams'><xml-not-well-formed xmlns='urn:ietf:params:xml:ns:xmpp-streams'/><text xmlns='urn:ietf:params:xml:ns:xmpp-streams'>syntax error</text></stream:error></stream:stream>" 
+
+#define JSTRING_LOGIN_OK "<iq xmlns='jabber:client' id='0123456789' type='result'/>"
+
+#define JSTRING_NO_RECIPIENT "<message xmlns='jabber:client' type='error' from='%s' to='%s'><error type='cancel' code='404'><item-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error><body>NOT ADDING BODY</body></message>"
+
+#endif