ReactOS 0.4.15-dev-7924-g5949c20
xlink.c
Go to the documentation of this file.
1/*
2 * xlink.c : implementation of the hyperlinks detection module
3 * This version supports both XML XLinks and HTML simple links
4 *
5 * See Copyright for the status of this software.
6 *
7 * daniel@veillard.com
8 */
9
10
11#define IN_LIBXML
12#include "libxml.h"
13
14#ifdef LIBXML_XPTR_ENABLED
15#include <string.h> /* for memset() only */
16#include <ctype.h>
17#include <stdlib.h>
18
19#include <libxml/xmlmemory.h>
20#include <libxml/tree.h>
21#include <libxml/parser.h>
22#include <libxml/valid.h>
23#include <libxml/xlink.h>
24#include <libxml/globals.h>
25
26#define XLINK_NAMESPACE (BAD_CAST "http://www.w3.org/1999/xlink/namespace/")
27#define XHTML_NAMESPACE (BAD_CAST "http://www.w3.org/1999/xhtml/")
28
29/****************************************************************
30 * *
31 * Default setting and related functions *
32 * *
33 ****************************************************************/
34
35static xlinkHandlerPtr xlinkDefaultHandler = NULL;
36static xlinkNodeDetectFunc xlinkDefaultDetect = NULL;
37
45xlinkHandlerPtr
46xlinkGetDefaultHandler(void) {
47 return(xlinkDefaultHandler);
48}
49
50
57void
58xlinkSetDefaultHandler(xlinkHandlerPtr handler) {
59 xlinkDefaultHandler = handler;
60}
61
69xlinkNodeDetectFunc
70xlinkGetDefaultDetect (void) {
71 return(xlinkDefaultDetect);
72}
73
80void
81xlinkSetDefaultDetect (xlinkNodeDetectFunc func) {
82 xlinkDefaultDetect = func;
83}
84
85/****************************************************************
86 * *
87 * The detection routines *
88 * *
89 ****************************************************************/
90
91
106xlinkType
107xlinkIsLink (xmlDocPtr doc, xmlNodePtr node) {
108 xmlChar *type = NULL, *role = NULL;
109 xlinkType ret = XLINK_TYPE_NONE;
110
111 if (node == NULL) return(XLINK_TYPE_NONE);
112 if (doc == NULL) doc = node->doc;
113 if ((doc != NULL) && (doc->type == XML_HTML_DOCUMENT_NODE)) {
114 /*
115 * This is an HTML document.
116 */
117 } else if ((node->ns != NULL) &&
118 (xmlStrEqual(node->ns->href, XHTML_NAMESPACE))) {
119 /*
120 * !!!! We really need an IS_XHTML_ELEMENT function from HTMLtree.h @@@
121 */
122 /*
123 * This is an XHTML element within an XML document
124 * Check whether it's one of the element able to carry links
125 * and in that case if it holds the attributes.
126 */
127 }
128
129 /*
130 * We don't prevent a-priori having XML Linking constructs on
131 * XHTML elements
132 */
133 type = xmlGetNsProp(node, BAD_CAST"type", XLINK_NAMESPACE);
134 if (type != NULL) {
135 if (xmlStrEqual(type, BAD_CAST "simple")) {
136 ret = XLINK_TYPE_SIMPLE;
137 } else if (xmlStrEqual(type, BAD_CAST "extended")) {
138 role = xmlGetNsProp(node, BAD_CAST "role", XLINK_NAMESPACE);
139 if (role != NULL) {
140 xmlNsPtr xlink;
141 xlink = xmlSearchNs(doc, node, XLINK_NAMESPACE);
142 if (xlink == NULL) {
143 /* Humm, fallback method */
144 if (xmlStrEqual(role, BAD_CAST"xlink:external-linkset"))
145 ret = XLINK_TYPE_EXTENDED_SET;
146 } else {
147 xmlChar buf[200];
148 snprintf((char *) buf, sizeof(buf), "%s:external-linkset",
149 (char *) xlink->prefix);
150 buf[sizeof(buf) - 1] = 0;
151 if (xmlStrEqual(role, buf))
152 ret = XLINK_TYPE_EXTENDED_SET;
153
154 }
155
156 }
157 ret = XLINK_TYPE_EXTENDED;
158 }
159 }
160
161 if (type != NULL) xmlFree(type);
162 if (role != NULL) xmlFree(role);
163 return(ret);
164}
165#endif /* LIBXML_XPTR_ENABLED */
#define NULL
Definition: types.h:112
UINT(* handler)(MSIPACKAGE *)
Definition: action.c:7482
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLenum func
Definition: glext.h:6028
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
XMLPUBVAR xmlFreeFunc xmlFree
Definition: globals.h:251
XMLPUBFUN xmlNsPtr XMLCALL xmlSearchNs(xmlDocPtr doc, xmlNodePtr node, const xmlChar *nameSpace)
XMLPUBFUN xmlChar *XMLCALL xmlGetNsProp(const xmlNode *node, const xmlChar *name, const xmlChar *nameSpace)
@ XML_HTML_DOCUMENT_NODE
Definition: tree.h:172
Definition: tree.h:551
xmlElementType type
Definition: tree.h:553
Definition: tree.h:489
Definition: tree.h:389
const xmlChar * prefix
Definition: tree.h:393
Definition: dlist.c:348
int ret
#define snprintf
Definition: wintirpc.h:48
#define BAD_CAST
Definition: xmlstring.h:35
XMLPUBFUN int XMLCALL xmlStrEqual(const xmlChar *str1, const xmlChar *str2)
Definition: xmlstring.c:160
unsigned char xmlChar
Definition: xmlstring.h:28