+/**
+ * cx_register_namespaces:
+ * @xpath_ctx: the pointer to an XPath context.
+ * @nslist: the list of known namespaces in
+ * "<prefix1>=<href1> <prefix2>=href2> ..." format.
+ *
+ * Registers namespaces from @nslist in @xpath_ctx.
+ *
+ * Returns 0 on success and a negative value otherwise.
+ *
+ * author: Aleksey Sanin
+ *
+ * The following license statement applies to the function
+ * cx_register_namespaces only:
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is fur-
+ * nished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT-
+ * NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * DANIEL VEILLARD BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CON-
+ * NECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Daniel Veillard shall not
+ * be used in advertising or otherwise to promote the sale, use or other deal-
+ * ings in this Software without prior written authorization from him.
+ */
+static int cx_register_namespaces(xmlXPathContextPtr xpath_ctx, /* {{{ */
+ const xmlChar* nslist)
+{
+ xmlChar* nslistdup;
+ xmlChar* prefix;
+ xmlChar* href;
+ xmlChar* next;
+
+ assert(xpath_ctx);
+ assert(nslist);
+
+ nslistdup = xmlStrdup(nslist);
+ if(nslistdup == NULL) {
+ ERROR ("curl_xml plugin: "
+ "unable to strdup namespaces list");
+ return (-1);
+ }
+
+ next = nslistdup;
+ while(next != NULL) {
+ /* skip spaces */
+ while((*next) == ' ') next++;
+ if((*next) == '\0') break;
+
+ /* find prefix */
+ prefix = next;
+ next = (xmlChar*)xmlStrchr(next, '=');
+ if(next == NULL) {
+ ERROR ("curl_xml plugin: "
+ "invalid namespaces list format");
+ xmlFree(nslistdup);
+ return (-1);
+ }
+ *(next++) = '\0';
+
+ /* find href */
+ href = next;
+ next = (xmlChar*)xmlStrchr(next, ' ');
+ if(next != NULL) {
+ *(next++) = '\0';
+ }
+
+ /* do register namespace */
+ if(xmlXPathRegisterNs(xpath_ctx, prefix, href) != 0) {
+ ERROR ("curl_xml plugin: "
+ "unable to register NS with prefix=\"%s\" and href=\"%s\"\n",
+ prefix, href);
+ xmlFree(nslistdup);
+ return (-1);
+ }
+ }
+
+ xmlFree(nslistdup);
+ return (0);
+} /* }}} cx_register_namespaces */
+