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);
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 )
if( msg == NULL )
return NULL;
- int bufsize;
- xmlChar* xmlbuf;
- char* encoded_msg;
+ //int bufsize;
+ //xmlChar* xmlbuf;
+ //char* encoded_msg;
xmlKeepBlanksDefault(0);
//xmlDocDumpFormatMemory( doc, &xmlbuf, &bufsize, 0 );
//xmlDocDumpMemoryEnc( doc, &xmlbuf, &bufsize, "UTF-8" );
+
+
+
+ /*
xmlDocDumpMemoryEnc( doc, &xmlbuf, &bufsize, "UTF-8" );
encoded_msg = strdup( (char*) xmlbuf );
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;
+ */
}