1/** 2 * perl-libxml-mm.h 3 * $Id: perl-libxml-mm.h,v 1.1.1.2 2007/10/10 23:04:14 ahuda Exp $ 4 * 5 * Basic concept: 6 * perl varies in the implementation of UTF8 handling. this header (together 7 * with the c source) implements a few functions, that can be used from within 8 * the core module inorder to avoid cascades of c pragmas 9 */ 10 11#ifndef __PERL_LIBXML_MM_H__ 12#define __PERL_LIBXML_MM_H__ 13 14#ifdef __cplusplus 15extern "C" { 16#endif 17#include "EXTERN.h" 18#include "perl.h" 19 20#include <libxml/parser.h> 21 22#ifdef __cplusplus 23} 24#endif 25 26/* 27 * NAME xs_warn 28 * TYPE MACRO 29 * 30 * this makro is for XML::LibXML development and debugging. 31 * 32 * SYNOPSIS 33 * xs_warn("my warning") 34 * 35 * this makro takes only a single string(!) and passes it to perls 36 * warn function if the XS_WARNRINGS pragma is used at compile time 37 * otherwise any xs_warn call is ignored. 38 * 39 * pay attention, that xs_warn does not implement a complete wrapper 40 * for warn!! 41 */ 42#ifdef XS_WARNINGS 43#define xs_warn(string) warn("%s",string) 44#else 45#define xs_warn(string) 46#endif 47 48struct _ProxyNode { 49 xmlNodePtr node; 50 xmlNodePtr owner; 51 int count; 52 int encoding; 53}; 54 55/* helper type for the proxy structure */ 56typedef struct _ProxyNode ProxyNode; 57 58/* pointer to the proxy structure */ 59typedef ProxyNode* ProxyNodePtr; 60 61/* this my go only into the header used by the xs */ 62#define SvPROXYNODE(x) ((ProxyNodePtr)SvIV(SvRV(x))) 63#define PmmPROXYNODE(x) ((ProxyNodePtr)x->_private) 64 65#define PmmREFCNT(node) node->count 66#define PmmREFCNT_inc(node) node->count++ 67#define PmmNODE(xnode) xnode->node 68#define PmmOWNER(node) node->owner 69#define PmmOWNERPO(node) ((node && PmmOWNER(node)) ? (ProxyNodePtr)PmmOWNER(node)->_private : node) 70#define PmmENCODING(node) node->encoding 71 72ProxyNodePtr 73PmmNewNode(xmlNodePtr node); 74 75ProxyNodePtr 76PmmNewFragment(xmlDocPtr document); 77 78SV* 79PmmCreateDocNode( unsigned int type, ProxyNodePtr pdoc, ...); 80 81int 82PmmREFCNT_dec( ProxyNodePtr node ); 83 84SV* 85PmmNodeToSv( xmlNodePtr node, ProxyNodePtr owner ); 86 87/* PmmFixProxyEncoding 88 * TYPE 89 * Method 90 * PARAMETER 91 * @dfProxy: The proxystructure to fix. 92 * 93 * DESCRIPTION 94 * 95 * This little helper allows to fix the proxied encoding information 96 * after a not standard operation was done. This is required for 97 * XML::LibXSLT 98 */ 99void 100PmmFixProxyEncoding( ProxyNodePtr dfProxy ); 101 102/* PmmSvNodeExt 103 * TYPE 104 * Function 105 * PARAMETER 106 * @perlnode: the perl reference that holds the scalar. 107 * @copy : copy flag 108 * 109 * DESCRIPTION 110 * 111 * The function recognizes XML::LibXML and XML::GDOME 112 * nodes as valid input data. The second parameter 'copy' 113 * indicates if in case of GDOME nodes the libxml2 node 114 * should be copied. In some cases, where the node is 115 * cloned anyways, this flag has to be set to '0', while 116 * the default value should be allways '1'. 117 */ 118xmlNodePtr 119PmmSvNodeExt( SV * perlnode, int copy ); 120 121/* PmmSvNode 122 * TYPE 123 * Macro 124 * PARAMETER 125 * @perlnode: a perl reference that holds a libxml node 126 * 127 * DESCRIPTION 128 * 129 * PmmSvNode fetches the libxml node such as PmmSvNodeExt does. It is 130 * a wrapper, that sets the copy always to 1, which is good for all 131 * cases XML::LibXML uses. 132 */ 133#define PmmSvNode(n) PmmSvNodeExt(n,1) 134 135 136xmlNodePtr 137PmmSvOwner( SV * perlnode ); 138 139SV* 140PmmSetSvOwner(SV * perlnode, SV * owner ); 141 142void 143PmmFixOwner(ProxyNodePtr node, ProxyNodePtr newOwner ); 144 145void 146PmmFixOwnerNode(xmlNodePtr node, ProxyNodePtr newOwner ); 147 148int 149PmmContextREFCNT_dec( ProxyNodePtr node ); 150 151SV* 152PmmContextSv( xmlParserCtxtPtr ctxt ); 153 154xmlParserCtxtPtr 155PmmSvContext( SV * perlctxt ); 156 157/** 158 * NAME PmmCopyNode 159 * TYPE function 160 * 161 * returns libxml2 node 162 * 163 * DESCRIPTION 164 * This function implements a nodetype independant node cloning. 165 * 166 * Note that this function has to stay in this module, since 167 * XML::LibXSLT reuses it. 168 */ 169xmlNodePtr 170PmmCloneNode( xmlNodePtr node , int deep ); 171 172/** 173 * NAME PmmNodeToGdomeSv 174 * TYPE function 175 * 176 * returns XML::GDOME node 177 * 178 * DESCRIPTION 179 * creates an Gdome node from our XML::LibXML node. 180 * this function is very usefull for the parser. 181 * 182 * the function will only work, if XML::LibXML is compiled with 183 * XML::GDOME support. 184 * 185 */ 186SV * 187PmmNodeToGdomeSv( xmlNodePtr node ); 188 189/** 190 * NAME PmmNodeTypeName 191 * TYPE function 192 * 193 * returns the perl class name for the given node 194 * 195 * SYNOPSIS 196 * CLASS = PmmNodeTypeName( node ); 197 */ 198const char* 199PmmNodeTypeName( xmlNodePtr elem ); 200 201xmlChar* 202PmmEncodeString( const char *encoding, const char *string ); 203 204char* 205PmmDecodeString( const char *encoding, const xmlChar *string); 206 207/* string manipulation will go elsewhere! */ 208 209/* 210 * NAME c_string_to_sv 211 * TYPE function 212 * SYNOPSIS 213 * SV *my_sv = c_string_to_sv( "my string", encoding ); 214 * 215 * this function converts a libxml2 string to a SV*. although the 216 * string is copied, the func does not free the c-string for you! 217 * 218 * encoding is either NULL or a encoding string such as provided by 219 * the documents encoding. if encoding is NULL UTF8 is assumed. 220 * 221 */ 222SV* 223C2Sv( const xmlChar *string, const xmlChar *encoding ); 224 225/* 226 * NAME sv_to_c_string 227 * TYPE function 228 * SYNOPSIS 229 * SV *my_sv = sv_to_c_string( my_sv, encoding ); 230 * 231 * this function converts a SV* to a libxml string. the SV-value will 232 * be copied into a *newly* allocated string. (don't forget to free it!) 233 * 234 * encoding is either NULL or a encoding string such as provided by 235 * the documents encoding. if encoding is NULL UTF8 is assumed. 236 * 237 */ 238xmlChar * 239Sv2C( SV* scalar, const xmlChar *encoding ); 240 241SV* 242nodeC2Sv( const xmlChar * string, xmlNodePtr refnode ); 243 244xmlChar * 245nodeSv2C( SV * scalar, xmlNodePtr refnode ); 246 247#endif 248