/*
* entities.c : implementation for the XML entities handling
*
* See Copyright for the status of this software.
*
* daniel@veillard.com
*/
#define IN_LIBXML
#include "libxml.h"
#include <string.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include <libxml/xmlmemory.h>
#include <libxml/entities.h>
#include <libxml/parserInternals.h>
#include <libxml/xmlerror.h>
/*
* The XML predefined entities.
*/
};
};
};
};
};
/**
* xmlEntitiesErrMemory:
* @extra: extra informations
*
* Handle an out of memory condition
*/
static void
{
}
/**
* xmlEntitiesErr:
* @code: the error code
* @msg: the message
*
* Handle an out of memory condition
*/
static void
{
}
/*
* xmlFreeEntity : clean-up an entity record.
*/
static void
{
return;
} else {
}
}
/*
* xmlAddEntity : register a new entity for an entities table.
*/
static xmlEntityPtr
return(NULL);
return(NULL);
switch (type) {
break;
break;
return(NULL);
}
return(NULL);
xmlEntitiesErrMemory("xmlAddEntity:: malloc failed");
return(NULL);
}
/*
* fill the structure.
*/
if (ExternalID != NULL)
} else {
if (ExternalID != NULL)
}
else
} else {
}
the defining entity */
/*
* entity was already defined at another level.
*/
return(NULL);
}
return(ret);
}
/**
* xmlGetPredefinedEntity:
* @name: the entity name
*
* Check whether this name is an predefined entity.
*
* Returns NULL if not, otherwise the entity
*/
switch (name[0]) {
case 'l':
return(&xmlEntityLt);
break;
case 'g':
return(&xmlEntityGt);
break;
case 'a':
return(&xmlEntityAmp);
return(&xmlEntityApos);
break;
case 'q':
return(&xmlEntityQuot);
break;
default:
break;
}
return(NULL);
}
/**
* xmlAddDtdEntity:
* @doc: the document
* @name: the entity name
* @type: the entity type XML_xxx_yyy_ENTITY
* @ExternalID: the entity external ID if available
* @SystemID: the entity system ID if available
* @content: the entity content
*
* Register a new entity for this document DTD external subset.
*
* Returns a pointer to the entity or NULL in case of error
*/
"xmlAddDtdEntity: document is NULL");
return(NULL);
}
"xmlAddDtdEntity: document without external subset");
return(NULL);
}
/*
* Link it to the DTD
*/
} else {
}
return(ret);
}
/**
* xmlAddDocEntity:
* @doc: the document
* @name: the entity name
* @type: the entity type XML_xxx_yyy_ENTITY
* @ExternalID: the entity external ID if available
* @SystemID: the entity system ID if available
* @content: the entity content
*
* Register a new entity for this document.
*
* Returns a pointer to the entity or NULL in case of error
*/
"xmlAddDocEntity: document is NULL");
return(NULL);
}
"xmlAddDocEntity: document without internal subset");
return(NULL);
}
/*
* Link it to the DTD
*/
} else {
}
return(ret);
}
/**
* xmlGetEntityFromTable:
* @table: an entity table
* @name: the entity name
* @parameter: look for parameter entities
*
* Do an entity lookup in the table.
* returns the corresponding parameter entity, if found.
*
* Returns A pointer to the entity structure or NULL if not found.
*/
static xmlEntityPtr
}
/**
* xmlGetParameterEntity:
* @doc: the document referencing the entity
* @name: the entity name
*
* Do an entity lookup in the internal and external subsets and
* returns the corresponding parameter entity, if found.
*
* Returns A pointer to the entity structure or NULL if not found.
*/
return(NULL);
return(ret);
}
}
return(NULL);
}
/**
* xmlGetDtdEntity:
* @doc: the document referencing the entity
* @name: the entity name
*
* Do an entity lookup in the DTD entity hash table and
* returns the corresponding entity, if found.
* Note: the first argument is the document node, not the DTD node.
*
* Returns A pointer to the entity structure or NULL if not found.
*/
return(NULL);
}
return(NULL);
}
/**
* xmlGetDocEntity:
* @doc: the document referencing the entity
* @name: the entity name
*
* Do an entity lookup in the document entity hash table and
* returns the corresponding entity, otherwise a lookup is done
* in the predefined entities too.
*
* Returns A pointer to the entity structure or NULL if not found.
*/
return(cur);
}
return(cur);
}
}
}
return(xmlGetPredefinedEntity(name));
}
/*
* Macro used to grow the current buffer.
*/
#define growBufferReentrant() { \
buffer_size = new_size; \
}
/**
* xmlEncodeEntitiesReentrant:
* @doc: the document containing the string
* @input: A string to convert to XML.
*
* Do a global encoding of a string, replacing the predefined entities
* and non ASCII values with their entities and CharRef counterparts.
* Contrary to xmlEncodeEntities, this routine is reentrant, and result
* must be deallocated.
*
* Returns A newly allocated string with the substitution done.
*/
xmlChar *
int html = 0;
/*
* allocate an translation buffer.
*/
buffer_size = 1000;
xmlEntitiesErrMemory("xmlEncodeEntitiesReentrant: malloc failed");
return(NULL);
}
while (*cur != '\0') {
}
/*
* By default one have to encode at least '<', '>', '"' and '&' !
*/
if (*cur == '<') {
*out++ = '&';
*out++ = 'l';
*out++ = 't';
*out++ = ';';
} else if (*cur == '>') {
*out++ = '&';
*out++ = 'g';
*out++ = 't';
*out++ = ';';
} else if (*cur == '&') {
*out++ = '&';
*out++ = 'a';
*out++ = 'm';
*out++ = 'p';
*out++ = ';';
/*
* default case, just copy !
*/
} else if (*cur >= 0x80) {
/*
* Bj�rn Reese <br@sseusa.com> provided the patch
xmlChar xc;
xc = (*cur & 0x3F) << 6;
if (cur[1] != 0) {
xc += *(++cur) & 0x3F;
*out++ = xc;
} else
*/
} else {
/*
* We assume we have UTF-8 input.
*/
if (*cur < 0xC0) {
"xmlEncodeEntitiesReentrant : input not UTF-8");
cur++;
continue;
} else if (*cur < 0xE0) {
val <<= 6;
l = 2;
} else if (*cur < 0xF0) {
val <<= 6;
val <<= 6;
l = 3;
} else if (*cur < 0xF8) {
val <<= 6;
val <<= 6;
val <<= 6;
l = 4;
}
"xmlEncodeEntitiesReentrant : char out of range\n");
cur++;
continue;
}
/*
* We could do multiple things here. Just save as a char ref
*/
cur += l;
continue;
}
} else if (IS_BYTE_CHAR(*cur)) {
}
cur++;
}
*out++ = 0;
return(buffer);
xmlEntitiesErrMemory("xmlEncodeEntitiesReentrant: realloc failed");
return(NULL);
}
/**
* xmlEncodeSpecialChars:
* @doc: the document containing the string
* @input: A string to convert to XML.
*
* Do a global encoding of a string, replacing the predefined entities
* this routine is reentrant, and result must be deallocated.
*
* Returns A newly allocated string with the substitution done.
*/
xmlChar *
/*
* allocate an translation buffer.
*/
buffer_size = 1000;
xmlEntitiesErrMemory("xmlEncodeSpecialChars: malloc failed");
return(NULL);
}
while (*cur != '\0') {
}
/*
* By default one have to encode at least '<', '>', '"' and '&' !
*/
if (*cur == '<') {
*out++ = '&';
*out++ = 'l';
*out++ = 't';
*out++ = ';';
} else if (*cur == '>') {
*out++ = '&';
*out++ = 'g';
*out++ = 't';
*out++ = ';';
} else if (*cur == '&') {
*out++ = '&';
*out++ = 'a';
*out++ = 'm';
*out++ = 'p';
*out++ = ';';
} else if (*cur == '"') {
*out++ = '&';
*out++ = 'q';
*out++ = 'u';
*out++ = 'o';
*out++ = 't';
*out++ = ';';
} else if (*cur == '\r') {
*out++ = '&';
*out++ = '#';
*out++ = '1';
*out++ = '3';
*out++ = ';';
} else {
/*
* Works because on UTF-8, all extended sequences cannot
* result in bytes in the ASCII range.
*/
}
cur++;
}
*out++ = 0;
return(buffer);
xmlEntitiesErrMemory("xmlEncodeSpecialChars: realloc failed");
return(NULL);
}
/**
* xmlCreateEntitiesTable:
*
* create and initialize an empty entities hash table.
* This really doesn't make sense and should be deprecated
*
* Returns the xmlEntitiesTablePtr just created or NULL in case of error.
*/
xmlCreateEntitiesTable(void) {
return((xmlEntitiesTablePtr) xmlHashCreate(0));
}
/**
* xmlFreeEntityWrapper:
* @entity: An entity
* @name: its name
*
* Deallocate the memory used by an entities in the hash table.
*/
static void
}
/**
* xmlFreeEntitiesTable:
* @table: An entity table
*
* Deallocate the memory used by an entities hash table.
*/
void
}
#ifdef LIBXML_TREE_ENABLED
/**
* xmlCopyEntity:
* @ent: An entity
*
* Build a copy of an entity
*
* Returns the new xmlEntitiesPtr or NULL in case of error.
*/
static xmlEntityPtr
xmlEntitiesErrMemory("xmlCopyEntity:: malloc failed");
return(NULL);
}
return(cur);
}
/**
* xmlCopyEntitiesTable:
* @table: An entity table
*
* Build a copy of an entity table.
*
* Returns the new xmlEntitiesTablePtr or NULL in case of error.
*/
}
#endif /* LIBXML_TREE_ENABLED */
#ifdef LIBXML_OUTPUT_ENABLED
/**
* xmlDumpEntityContent:
* @buf: An XML buffer.
* @content: The entity content.
*
* This will dump the quoted string value, taking care of the special
* treatment required by %
*/
static void
while (*cur != 0) {
if (*cur == '"') {
cur++;
} else if (*cur == '%') {
cur++;
} else {
cur++;
}
}
} else {
}
}
/**
* xmlDumpEntityDecl:
* @buf: An XML buffer.
* @ent: An entity table
*
* This will dump the content of the entity table as an XML DTD definition
*/
void
else
break;
} else {
}
break;
} else {
}
else
}
break;
else
break;
} else {
}
break;
default:
"xmlDumpEntitiesDecl: internal: unknown type entity type");
}
}
/**
* xmlDumpEntityDeclScan:
* @ent: An entity table
* @buf: An XML buffer.
*
* When using the hash table scan function, arguments need to be reversed
*/
static void
}
/**
* xmlDumpEntitiesTable:
* @buf: An XML buffer.
* @table: An entity table
*
* This will dump the content of the entity table as an XML DTD definition
*/
void
}
#endif /* LIBXML_OUTPUT_ENABLED */
#define bottom_entities
#include "elfgcchack.h"