changed lame code to smarter code -> dumping document element instead of
authorerickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Wed, 6 Jul 2005 16:53:30 +0000 (16:53 +0000)
committererickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Wed, 6 Jul 2005 16:53:30 +0000 (16:53 +0000)
doc and remove declaration

git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@382 9efc2488-bf62-4759-914b-345cdb29e865

src/jserver/jserver-c_session.c
src/libstack/osrf_message.c

index 5e86a5f..4652ccb 100644 (file)
@@ -147,11 +147,14 @@ void sax_end_element( void* blob, const xmlChar *name) {
        if(session->state & JABBER_STATE_CONNECTED) {
                if(!strcmp(name, "message")) {
                        if(session->on_msg_complete) {
+
+                               debug_handler("Message is complete, finishing DOC");
+
                                /* we have to make sure the 'from' address is set.. */
                                xmlNodePtr msg = xmlDocGetRootElement(session->current_msg);
                                if(msg) xmlSetProp(msg, BAD_CAST "from", BAD_CAST session->current_from );
-
                                char* string = _xml_to_string(session->current_msg);
+
                                session->on_msg_complete(session->blob, string, 
                                        session->current_from, session->current_to );
                                free(string);
@@ -266,38 +269,11 @@ char* sax_xml_attr( const xmlChar** atts, char* attr_name ) {
 
 char* _xml_to_string( xmlDocPtr doc ) {
        
-       int                     bufsize;
-       xmlChar*                xmlbuf;
-       xmlDocDumpFormatMemory( doc, &xmlbuf, &bufsize, 0 );
-
-       char* xml = strdup(xmlbuf);
-       xmlFree(xmlbuf);
-
-       /*** remove the XML declaration */
-       int len = strlen(xml);
-       char tmp[len];
-       memset( tmp, 0, len );
-       int i;
-       int found_at = 0;
-                                               
-       /* when we reach the first >, take everything after it */
-       for( i = 0; i!= len; i++ ) {
-               if( xml[i] == 62) { /* ascii > */
-       
-                       /* found_at holds the starting index of the rest of the doc*/
-                       found_at = i + 1; 
-                       break;
-               }
-       }
-
-       if( found_at ) {
+       xmlBufferPtr xmlbuf = xmlBufferCreate();
+       xmlNodeDump( xmlbuf, doc, xmlDocGetRootElement(doc), 0, 0);
 
-               /* move the shortened doc into the tmp buffer */
-               strncpy( tmp, xml + found_at, len - found_at );
-               /* move the tmp buffer back into the allocated space */
-               memset( xml, 0, len );
-               strcpy( xml, tmp );
-       }
+       char* xml = strdup( (char*) (xmlBufferContent(xmlbuf)));
+       xmlBufferFree(xmlbuf);
 
        int l = strlen(xml)-1;
        if( xml[l] == 10 || xml[l] == 13 )
index 95b1bba..87d33c5 100644 (file)
@@ -161,9 +161,9 @@ char* osrf_message_to_xml( osrf_message* msg ) {
        if( msg == NULL )
                return NULL;
 
-       int                     bufsize;
-       xmlChar*                xmlbuf;
-       char*                   encoded_msg;
+       //int                   bufsize;
+       //xmlChar*              xmlbuf;
+       //char*                 encoded_msg;
 
        xmlKeepBlanksDefault(0);
 
@@ -330,6 +330,10 @@ char* osrf_message_to_xml( osrf_message* msg ) {
 
        //xmlDocDumpFormatMemory( doc, &xmlbuf, &bufsize, 0 );
        //xmlDocDumpMemoryEnc( doc, &xmlbuf, &bufsize, "UTF-8" );
+
+
+
+       /*
        xmlDocDumpMemoryEnc( doc, &xmlbuf, &bufsize, "UTF-8" );
 
        encoded_msg = strdup( (char*) xmlbuf );
@@ -341,34 +345,48 @@ char* osrf_message_to_xml( osrf_message* msg ) {
        xmlFree(xmlbuf);
        xmlFreeDoc( doc );
        xmlCleanupParser();
+       */
+
+
+       /***/
+       xmlBufferPtr xmlbuf = xmlBufferCreate();
+       xmlNodeDump( xmlbuf, doc, xmlDocGetRootElement(doc), 0, 0);
+
+       char* xml = strdup( (char*) (xmlBufferContent(xmlbuf)));
+       xmlBufferFree(xmlbuf);
+
+       int l = strlen(xml)-1;
+       if( xml[l] == 10 || xml[l] == 13 )
+               xml[l] = '\0';
+
+       return xml;
+       /***/
+
 
 
-       /*** remove the XML declaration */
+       /*
        int len = strlen(encoded_msg);
        char tmp[len];
        memset( tmp, 0, len );
        int i;
        int found_at = 0;
 
-       /* when we reach the first >, take everything after it */
        for( i = 0; i!= len; i++ ) {
-               if( encoded_msg[i] == 62) { /* ascii > */
+               if( encoded_msg[i] == 62) { 
 
-                       /* found_at holds the starting index of the rest of the doc*/
                        found_at = i + 1; 
                        break;
                }
        }
 
        if( found_at ) {
-               /* move the shortened doc into the tmp buffer */
                strncpy( tmp, encoded_msg + found_at, len - found_at );
-               /* move the tmp buffer back into the allocated space */
                memset( encoded_msg, 0, len );
                strcpy( encoded_msg, tmp );
        }
 
        return encoded_msg;
+       */
 
 }