| OLD | NEW |
| 1 /* | 1 /* |
| 2 * xlink.c : implementation of the hyperlinks detection module | 2 * xlink.c : implementation of the hyperlinks detection module |
| 3 * This version supports both XML XLinks and HTML simple links | 3 * This version supports both XML XLinks and HTML simple links |
| 4 * | 4 * |
| 5 * See Copyright for the status of this software. | 5 * See Copyright for the status of this software. |
| 6 * | 6 * |
| 7 * daniel@veillard.com | 7 * daniel@veillard.com |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 | 10 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 #include <libxml/globals.h> | 40 #include <libxml/globals.h> |
| 41 | 41 |
| 42 #define XLINK_NAMESPACE (BAD_CAST "http://www.w3.org/1999/xlink/namespace/") | 42 #define XLINK_NAMESPACE (BAD_CAST "http://www.w3.org/1999/xlink/namespace/") |
| 43 #define XHTML_NAMESPACE (BAD_CAST "http://www.w3.org/1999/xhtml/") | 43 #define XHTML_NAMESPACE (BAD_CAST "http://www.w3.org/1999/xhtml/") |
| 44 | 44 |
| 45 /**************************************************************** | 45 /**************************************************************** |
| 46 * * | 46 * * |
| 47 * Default setting and related functions * | 47 * Default setting and related functions * |
| 48 * * | 48 * * |
| 49 ****************************************************************/ | 49 ****************************************************************/ |
| 50 | 50 |
| 51 static xlinkHandlerPtr xlinkDefaultHandler = NULL; | 51 static xlinkHandlerPtr xlinkDefaultHandler = NULL; |
| 52 static xlinkNodeDetectFunc xlinkDefaultDetect = NULL; | 52 static xlinkNodeDetectFunc xlinkDefaultDetect = NULL; |
| 53 | 53 |
| 54 /** | 54 /** |
| 55 * xlinkGetDefaultHandler: | 55 * xlinkGetDefaultHandler: |
| 56 * | 56 * |
| 57 * Get the default xlink handler. | 57 * Get the default xlink handler. |
| 58 * | 58 * |
| 59 * Returns the current xlinkHandlerPtr value. | 59 * Returns the current xlinkHandlerPtr value. |
| 60 */ | 60 */ |
| (...skipping 25 matching lines...) Expand all Loading... |
| 86 xlinkGetDefaultDetect (void) { | 86 xlinkGetDefaultDetect (void) { |
| 87 return(xlinkDefaultDetect); | 87 return(xlinkDefaultDetect); |
| 88 } | 88 } |
| 89 | 89 |
| 90 /** | 90 /** |
| 91 * xlinkSetDefaultDetect: | 91 * xlinkSetDefaultDetect: |
| 92 * @func: pointer to the new detection routine. | 92 * @func: pointer to the new detection routine. |
| 93 * | 93 * |
| 94 * Set the default xlink detection routine | 94 * Set the default xlink detection routine |
| 95 */ | 95 */ |
| 96 void | 96 void |
| 97 xlinkSetDefaultDetect (xlinkNodeDetectFunc func) { | 97 xlinkSetDefaultDetect (xlinkNodeDetectFunc func) { |
| 98 xlinkDefaultDetect = func; | 98 xlinkDefaultDetect = func; |
| 99 } | 99 } |
| 100 | 100 |
| 101 /**************************************************************** | 101 /**************************************************************** |
| 102 * * | 102 * * |
| 103 * The detection routines * | 103 * The detection routines * |
| 104 * * | 104 * * |
| 105 ****************************************************************/ | 105 ****************************************************************/ |
| 106 | 106 |
| 107 | 107 |
| 108 /** | 108 /** |
| 109 * xlinkIsLink: | 109 * xlinkIsLink: |
| 110 * @doc: the document containing the node | 110 * @doc: the document containing the node |
| 111 * @node: the node pointer itself | 111 * @node: the node pointer itself |
| 112 * | 112 * |
| 113 * Check whether the given node carries the attributes needed | 113 * Check whether the given node carries the attributes needed |
| 114 * to be a link element (or is one of the linking elements issued | 114 * to be a link element (or is one of the linking elements issued |
| 115 * from the (X)HTML DtDs). | 115 * from the (X)HTML DtDs). |
| 116 * This routine don't try to do full checking of the link validity | 116 * This routine don't try to do full checking of the link validity |
| 117 * but tries to detect and return the appropriate link type. | 117 * but tries to detect and return the appropriate link type. |
| 118 * | 118 * |
| 119 * Returns the xlinkType of the node (XLINK_TYPE_NONE if there is no | 119 * Returns the xlinkType of the node (XLINK_TYPE_NONE if there is no |
| 120 * link detected. | 120 * link detected. |
| 121 */ | 121 */ |
| 122 xlinkType | 122 xlinkType |
| 123 xlinkIsLink (xmlDocPtr doc, xmlNodePtr node) { | 123 xlinkIsLink (xmlDocPtr doc, xmlNodePtr node) { |
| 124 xmlChar *type = NULL, *role = NULL; | 124 xmlChar *type = NULL, *role = NULL; |
| 125 xlinkType ret = XLINK_TYPE_NONE; | 125 xlinkType ret = XLINK_TYPE_NONE; |
| 126 | 126 |
| 127 if (node == NULL) return(XLINK_TYPE_NONE); | 127 if (node == NULL) return(XLINK_TYPE_NONE); |
| 128 if (doc == NULL) doc = node->doc; | 128 if (doc == NULL) doc = node->doc; |
| 129 if ((doc != NULL) && (doc->type == XML_HTML_DOCUMENT_NODE)) { | 129 if ((doc != NULL) && (doc->type == XML_HTML_DOCUMENT_NODE)) { |
| 130 /* | 130 /* |
| 131 * This is an HTML document. | 131 * This is an HTML document. |
| 132 */ | 132 */ |
| (...skipping 10 matching lines...) Expand all Loading... |
| 143 } | 143 } |
| 144 | 144 |
| 145 /* | 145 /* |
| 146 * We don't prevent a-priori having XML Linking constructs on | 146 * We don't prevent a-priori having XML Linking constructs on |
| 147 * XHTML elements | 147 * XHTML elements |
| 148 */ | 148 */ |
| 149 type = xmlGetNsProp(node, BAD_CAST"type", XLINK_NAMESPACE); | 149 type = xmlGetNsProp(node, BAD_CAST"type", XLINK_NAMESPACE); |
| 150 if (type != NULL) { | 150 if (type != NULL) { |
| 151 if (xmlStrEqual(type, BAD_CAST "simple")) { | 151 if (xmlStrEqual(type, BAD_CAST "simple")) { |
| 152 ret = XLINK_TYPE_SIMPLE; | 152 ret = XLINK_TYPE_SIMPLE; |
| 153 » } if (xmlStrEqual(type, BAD_CAST "extended")) { | 153 » } else if (xmlStrEqual(type, BAD_CAST "extended")) { |
| 154 role = xmlGetNsProp(node, BAD_CAST "role", XLINK_NAMESPACE); | 154 role = xmlGetNsProp(node, BAD_CAST "role", XLINK_NAMESPACE); |
| 155 if (role != NULL) { | 155 if (role != NULL) { |
| 156 xmlNsPtr xlink; | 156 xmlNsPtr xlink; |
| 157 xlink = xmlSearchNs(doc, node, XLINK_NAMESPACE); | 157 xlink = xmlSearchNs(doc, node, XLINK_NAMESPACE); |
| 158 if (xlink == NULL) { | 158 if (xlink == NULL) { |
| 159 /* Humm, fallback method */ | 159 /* Humm, fallback method */ |
| 160 » » if (xmlStrEqual(role, BAD_CAST"xlink:external-linkset")) | 160 » » if (xmlStrEqual(role, BAD_CAST"xlink:external-linkset")) |
| 161 ret = XLINK_TYPE_EXTENDED_SET; | 161 ret = XLINK_TYPE_EXTENDED_SET; |
| 162 } else { | 162 } else { |
| 163 xmlChar buf[200]; | 163 xmlChar buf[200]; |
| 164 snprintf((char *) buf, sizeof(buf), "%s:external-linkset", | 164 snprintf((char *) buf, sizeof(buf), "%s:external-linkset", |
| 165 (char *) xlink->prefix); | 165 (char *) xlink->prefix); |
| 166 buf[sizeof(buf) - 1] = 0; | 166 buf[sizeof(buf) - 1] = 0; |
| 167 if (xmlStrEqual(role, buf)) | 167 if (xmlStrEqual(role, buf)) |
| 168 ret = XLINK_TYPE_EXTENDED_SET; | 168 ret = XLINK_TYPE_EXTENDED_SET; |
| 169 | 169 |
| 170 } | 170 } |
| 171 | 171 |
| 172 } | 172 } |
| 173 ret = XLINK_TYPE_EXTENDED; | 173 ret = XLINK_TYPE_EXTENDED; |
| 174 } | 174 } |
| 175 } | 175 } |
| 176 | 176 |
| 177 if (type != NULL) xmlFree(type); | 177 if (type != NULL) xmlFree(type); |
| 178 if (role != NULL) xmlFree(role); | 178 if (role != NULL) xmlFree(role); |
| 179 return(ret); | 179 return(ret); |
| 180 } | 180 } |
| 181 #endif /* LIBXML_XPTR_ENABLED */ | 181 #endif /* LIBXML_XPTR_ENABLED */ |
| 182 #define bottom_xlink | 182 #define bottom_xlink |
| 183 #include "elfgcchack.h" | 183 #include "elfgcchack.h" |
| OLD | NEW |