Commits

Anonymous committed 6d79162

Modified Files:
LibXML.xs perl-libxml-mm.h perl-libxml-mm.c dom.c dom.h
moved all general functions and possibly shared functions into
perl-libxml-mm.* . dom.* contains now only the really DOM specific
functions.

  • Participants
  • Parent commits fc4e16b

Comments (0)

Files changed (5)

 #endif
             realstring = Sv2C(string,(const xmlChar*)"UTF8" );
             if ( realstring != NULL ) {
-                tstr =  (xmlChar*)domDecodeString( (const char*)encoding,
+                tstr =  (xmlChar*)PmmDecodeString( (const char*)encoding,
                                                    (const xmlChar*)realstring );
                 if ( tstr != NULL ) {
                     RETVAL = C2Sv((const xmlChar*)tstr,(const xmlChar*)encoding);
                                 /* let's be paranoid */
                                 if (tnode->type == XML_NAMESPACE_DECL) {
                                     element = sv_newmortal();
-                                    cls = domNodeTypeName( tnode );
+                                    cls = PmmNodeTypeName( tnode );
                                     element = sv_setref_pv( element,
                                                             (const char *)cls,
                                                             (void *)xmlCopyNamespace((xmlNsPtr)tnode)
                     tnode = nodelist->nodeTab[i];
                     if (tnode->type == XML_NAMESPACE_DECL) {
                         element = sv_newmortal();
-                        cls = domNodeTypeName( tnode );
+                        cls = PmmNodeTypeName( tnode );
                         element = sv_setref_pv( element,
                                                 (const char *)cls,
                                                 (void *)xmlCopyNamespace((xmlNsPtr)tnode)
 #endif
 
 /**
- * this is a wrapper function that does the type evaluation for the 
- * node. this makes the code a little more readable in the .XS
- * 
- * the code is not really portable, but i think we'll avoid some 
- * memory leak problems that way.
- **/
-
-const char*
-domNodeTypeName( xmlNodePtr elem ){
-    const char *name = "XML::LibXML::Node";
-
-    if ( elem != NULL ) {
-        char * ptrHlp;
-        switch ( elem->type ) {
-        case XML_ELEMENT_NODE:
-            name = "XML::LibXML::Element";   
-            break;
-        case XML_TEXT_NODE:
-            name = "XML::LibXML::Text";
-            break;
-        case XML_COMMENT_NODE:
-            name = "XML::LibXML::Comment";
-            break;
-        case XML_CDATA_SECTION_NODE:
-            name = "XML::LibXML::CDATASection";
-            break;
-        case XML_ATTRIBUTE_NODE:
-            name = "XML::LibXML::Attr"; 
-            break;
-        case XML_DOCUMENT_NODE:
-        case XML_HTML_DOCUMENT_NODE:
-            name = "XML::LibXML::Document";
-            break;
-        case XML_DOCUMENT_FRAG_NODE:
-            name = "XML::LibXML::DocumentFragment";
-            break;
-        case XML_NAMESPACE_DECL:
-            name = "XML::LibXML::Namespace";
-            break;
-        case XML_DTD_NODE:
-            name = "XML::LibXML::Dtd";
-            break;
-        case XML_PI_NODE:
-            name = "XML::LibXML::PI";
-            break;
-        default:
-            name = "XML::LibXML::Node";
-            break;
-        };
-        return name;
-    }
-    return "";
-}
-
-/**
  * Name: domReadWellBalancedString
  * Synopsis: xmlNodePtr domReadWellBalancedString( xmlDocPtr doc, xmlChar *string )
  * @doc: the document, the string should belong to
 }
 
 /** 
- * encodeString returns an UTF-8 encoded String
- * while the encodig has the name of the encoding of string
- **/ 
-xmlChar*
-domEncodeString( const char *encoding, const xmlChar *string ){
-    xmlCharEncoding enc;
-    xmlChar *ret = NULL;
-    xmlBufferPtr in, out;
-    xmlCharEncodingHandlerPtr coder = NULL;
-    
-    if ( string != NULL ) {
-        if( encoding != NULL ) {
-            xs_warn( encoding );
-            enc = xmlParseCharEncoding( encoding );
-            if ( enc > 1 ) {
-                coder= xmlGetCharEncodingHandler( enc );
-            }
-            else if ( enc == 1 ) {
-                ret = xmlStrdup( string );
-            }
-            else if ( enc == XML_CHAR_ENCODING_ERROR ){
-                xs_warn("no standard encoding\n");
-                coder = xmlFindCharEncodingHandler( encoding );
-            }
-            else {
-                xs_warn("no encoding found\n");
-            }
-
-            if ( coder != NULL ) {
-                xs_warn("coding machine found\n");
-                in    = xmlBufferCreate();
-                out   = xmlBufferCreate();
-                xmlBufferCCat( in, string );
-                if ( xmlCharEncInFunc( coder, out, in ) >= 0 ) {
-                    ret = xmlStrdup( out->content );
-                }
-                else {
-                     xs_warn( "b0rked encoiding!\n");
-                }
-                    
-                xmlBufferFree( in );
-                xmlBufferFree( out );
-            }
-            else {
-                xs_warn("no coder found\n");
-                /* ret = xmlStrdup( string ); */
-            }
-        }
-        else {
-            /* if utf-8 is requested we do nothing */
-            ret = xmlStrdup( string );
-        }
-    }
-    return ret;
-}
-
-/**
- * decodeString returns an $encoding encoded string.
- * while string is an UTF-8 encoded string and 
- * encoding is the coding name
- **/
-char*
-domDecodeString( const char *encoding, const xmlChar *string){
-    char *ret=NULL;
-    xmlCharEncoding enc;
-    xmlBufferPtr in, out;
-    xmlCharEncodingHandlerPtr coder = NULL;
-
-    if ( string != NULL ) {
-        if( encoding != NULL ) {
-            enc = xmlParseCharEncoding( encoding );
-            if ( enc > 1 ) {
-                coder= xmlGetCharEncodingHandler( enc );
-            }
-            else if ( enc == 1 ) {
-                ret = xmlStrdup( string );
-            }
-            else if ( enc == XML_CHAR_ENCODING_ERROR ) {
-                coder = xmlFindCharEncodingHandler( encoding );
-            }
-            else {
-                xs_warn("no encoding found");
-            }
-
-            if ( coder != NULL ) {
-                in  = xmlBufferCreate();
-                out = xmlBufferCreate();
-                    
-                xmlBufferCat( in, string );        
-                if ( xmlCharEncOutFunc( coder, out, in ) >= 0 ) {
-                    ret=xmlStrdup(out->content);
-                }
-                else {
-                    /* printf("decoding error \n"); */
-                }
-            
-                xmlBufferFree( in );
-                xmlBufferFree( out );
-                xmlCharEncCloseFunc( coder );
-            }
-        }
-        else {
-            ret = xmlStrdup(string);
-        }
-    }
-    return ret;
-}
-
-/** 
  * internal helper: insert node to nodelist
  * synopsis: xmlNodePtr insert_node_to_nodelist( leader, insertnode, followup );
  * while leader and followup are allready list nodes. both may be NULL
 xmlNodePtr 
 domReadWellBalancedString( xmlDocPtr doc, xmlChar* string );
 
-xmlChar*
-domEncodeString( const char *encoding, const char *string );
-
-char*
-domDecodeString( const char *encoding, const xmlChar *string);
-
-/**
- * NAME domNodeTypeName
- * TYPE function
- * 
- * returns the perl class name for the given node
- *
- * SYNOPSIS
- * CLASS = domNodeTypeName( node );
- */
-const char*
-domNodeTypeName( xmlNodePtr self );
-
 /**
  * NAME domIsParent
  * TYPE function

File perl-libxml-mm.c

 #include "XSUB.h"
 
 #include <libxml/parser.h>
-
-#include "dom.h"
+#include <libxml/tree.h>
 
 #ifdef __cplusplus
 }
 #define xs_warn(string)
 #endif
 
+/**
+ * this is a wrapper function that does the type evaluation for the 
+ * node. this makes the code a little more readable in the .XS
+ * 
+ * the code is not really portable, but i think we'll avoid some 
+ * memory leak problems that way.
+ **/
+const char*
+PmmNodeTypeName( xmlNodePtr elem ){
+    const char *name = "XML::LibXML::Node";
+
+    if ( elem != NULL ) {
+        char * ptrHlp;
+        switch ( elem->type ) {
+        case XML_ELEMENT_NODE:
+            name = "XML::LibXML::Element";   
+            break;
+        case XML_TEXT_NODE:
+            name = "XML::LibXML::Text";
+            break;
+        case XML_COMMENT_NODE:
+            name = "XML::LibXML::Comment";
+            break;
+        case XML_CDATA_SECTION_NODE:
+            name = "XML::LibXML::CDATASection";
+            break;
+        case XML_ATTRIBUTE_NODE:
+            name = "XML::LibXML::Attr"; 
+            break;
+        case XML_DOCUMENT_NODE:
+        case XML_HTML_DOCUMENT_NODE:
+            name = "XML::LibXML::Document";
+            break;
+        case XML_DOCUMENT_FRAG_NODE:
+            name = "XML::LibXML::DocumentFragment";
+            break;
+        case XML_NAMESPACE_DECL:
+            name = "XML::LibXML::Namespace";
+            break;
+        case XML_DTD_NODE:
+            name = "XML::LibXML::Dtd";
+            break;
+        case XML_PI_NODE:
+            name = "XML::LibXML::PI";
+            break;
+        default:
+            name = "XML::LibXML::Node";
+            break;
+        };
+        return name;
+    }
+    return "";
+}
+
 /*
  * @node: Reference to the node the structure proxies
  * @owner: libxml defines only the document, but not the node owner
 
     if ( node != NULL ) {
         /* find out about the class */
-        CLASS = domNodeTypeName( node );
+        CLASS = PmmNodeTypeName( node );
         xs_warn(" return new perl node\n");
         xs_warn( CLASS );
 
     return(0);
 }
 
+/** 
+ * encodeString returns an UTF-8 encoded String
+ * while the encodig has the name of the encoding of string
+ **/ 
+xmlChar*
+PmmEncodeString( const char *encoding, const xmlChar *string ){
+    xmlCharEncoding enc;
+    xmlChar *ret = NULL;
+    xmlBufferPtr in, out;
+    xmlCharEncodingHandlerPtr coder = NULL;
+    
+    if ( string != NULL ) {
+        if( encoding != NULL ) {
+            xs_warn( encoding );
+            enc = xmlParseCharEncoding( encoding );
+            if ( enc > 1 ) {
+                coder= xmlGetCharEncodingHandler( enc );
+            }
+            else if ( enc == 1 ) {
+                ret = xmlStrdup( string );
+            }
+            else if ( enc == XML_CHAR_ENCODING_ERROR ){
+                xs_warn("no standard encoding\n");
+                coder = xmlFindCharEncodingHandler( encoding );
+            }
+            else {
+                xs_warn("no encoding found\n");
+            }
+
+            if ( coder != NULL ) {
+                xs_warn("coding machine found\n");
+                in    = xmlBufferCreate();
+                out   = xmlBufferCreate();
+                xmlBufferCCat( in, string );
+                if ( xmlCharEncInFunc( coder, out, in ) >= 0 ) {
+                    ret = xmlStrdup( out->content );
+                }
+                else {
+                     xs_warn( "b0rked encoiding!\n");
+                }
+                    
+                xmlBufferFree( in );
+                xmlBufferFree( out );
+            }
+            else {
+                xs_warn("no coder found\n");
+                /* ret = xmlStrdup( string ); */
+            }
+        }
+        else {
+            /* if utf-8 is requested we do nothing */
+            ret = xmlStrdup( string );
+        }
+    }
+    return ret;
+}
+
+/**
+ * decodeString returns an $encoding encoded string.
+ * while string is an UTF-8 encoded string and 
+ * encoding is the coding name
+ **/
+char*
+PmmDecodeString( const char *encoding, const xmlChar *string){
+    char *ret=NULL;
+    xmlCharEncoding enc;
+    xmlBufferPtr in, out;
+    xmlCharEncodingHandlerPtr coder = NULL;
+
+    if ( string != NULL ) {
+        if( encoding != NULL ) {
+            enc = xmlParseCharEncoding( encoding );
+            if ( enc > 1 ) {
+                coder= xmlGetCharEncodingHandler( enc );
+            }
+            else if ( enc == 1 ) {
+                ret = xmlStrdup( string );
+            }
+            else if ( enc == XML_CHAR_ENCODING_ERROR ) {
+                coder = xmlFindCharEncodingHandler( encoding );
+            }
+            else {
+                xs_warn("no encoding found");
+            }
+
+            if ( coder != NULL ) {
+                in  = xmlBufferCreate();
+                out = xmlBufferCreate();
+                    
+                xmlBufferCat( in, string );        
+                if ( xmlCharEncOutFunc( coder, out, in ) >= 0 ) {
+                    ret=xmlStrdup(out->content);
+                }
+                else {
+                    /* printf("decoding error \n"); */
+                }
+            
+                xmlBufferFree( in );
+                xmlBufferFree( out );
+                xmlCharEncCloseFunc( coder );
+            }
+        }
+        else {
+            ret = xmlStrdup(string);
+        }
+    }
+    return ret;
+}
+
 SV*
 C2Sv( const xmlChar *string, const xmlChar *encoding )
 {
             if ( encoding != NULL ) {
 #endif
                 xs_warn( "domEncodeString!" );
-                ts= domEncodeString( encoding, string );
+                ts= PmmEncodeString( encoding, string );
                 xs_warn( "done!" );
                 if ( string != NULL ) 
                     xmlFree(string);
         xmlDocPtr real_doc = refnode->doc;
         if ( real_doc && real_doc->encoding != NULL ) {
 
-            xmlChar * decoded = domDecodeString( (const char *)real_doc->encoding ,
+            xmlChar * decoded = PmmDecodeString( (const char *)real_doc->encoding ,
                                                  (const xmlChar *)string );
 
             retval = C2Sv( decoded, real_doc->encoding );

File perl-libxml-mm.h

 void
 PmmFixOwner(ProxyNodePtr node, ProxyNodePtr newOwner );
 
+/**
+ * NAME domNodeTypeName
+ * TYPE function
+ * 
+ * returns the perl class name for the given node
+ *
+ * SYNOPSIS
+ * CLASS = domNodeTypeName( node );
+ */
+const char*
+PmmNodeTypeName( xmlNodePtr elem );
+
+xmlChar*
+PmmEncodeString( const char *encoding, const char *string );
+
+char*
+PmmDecodeString( const char *encoding, const xmlChar *string);
+
 /* string manipulation will go elsewhere! */
 
 /*