pua/pidf.c

Go to the documentation of this file.
00001 /*
00002  * $Id: pidf.c 1953 2007-04-04 08:50:33Z anca_vamanu $
00003  *
00004  * pua module
00005  *
00006  * Copyright (C) 2007 Voice Sistem S.R.L.
00007  *
00008  * This file is part of Kamailio, a free SIP server.
00009  *
00010  * Kamailio is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version
00014  *
00015  * Kamailio is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License 
00021  * along with this program; if not, write to the Free Software 
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *
00024  * History:
00025  * --------
00026  *  2007-07-03  initial version (anca)
00027  */
00028 
00029 #include <string.h>
00030 #include <stdlib.h>
00031 #include <libxml/parser.h>
00032 #include "../../dprint.h"
00033 #include "../../sr_module.h"
00034 #include "pidf.h"
00035 
00036 
00037 xmlAttrPtr xmlNodeGetAttrByName(xmlNodePtr node, const char *name)
00038 {
00039    xmlAttrPtr attr = node->properties;
00040    while (attr) {
00041       if (xmlStrcasecmp(attr->name, (unsigned char*)name) == 0)
00042          return attr;
00043       attr = attr->next;
00044    }
00045    return NULL;
00046 }
00047 
00048 char *xmlNodeGetAttrContentByName(xmlNodePtr node, const char *name)
00049 {
00050    xmlAttrPtr attr = xmlNodeGetAttrByName(node, name);
00051    if (attr)
00052       return (char*)xmlNodeGetContent(attr->children);
00053    else
00054       return NULL;
00055 }
00056 
00057 xmlNodePtr xmlNodeGetChildByName(xmlNodePtr node, const char *name)
00058 {
00059    xmlNodePtr cur = node->children;
00060    while (cur) {
00061       if (xmlStrcasecmp(cur->name, (unsigned char*)name) == 0)
00062          return cur;
00063       cur = cur->next;
00064    }
00065    return NULL;
00066 }
00067 
00068 xmlNodePtr xmlNodeGetNodeByName(xmlNodePtr node, const char *name,
00069                                              const char *ns)
00070 {
00071    xmlNodePtr cur = node;
00072    while (cur) {
00073       xmlNodePtr match = NULL;
00074       if (xmlStrcasecmp(cur->name, (unsigned char*)name) == 0) {
00075          if (!ns || (cur->ns && xmlStrcasecmp(cur->ns->prefix,
00076                      (unsigned char*)ns) == 0))
00077             return cur;
00078       }
00079       match = xmlNodeGetNodeByName(cur->children, name, ns);
00080       if (match)
00081          return match;
00082       cur = cur->next;
00083    }
00084    return NULL;
00085 }
00086 
00087 char *xmlNodeGetNodeContentByName(xmlNodePtr root, const char *name,
00088       const char *ns)
00089 {
00090    xmlNodePtr node = xmlNodeGetNodeByName(root, name, ns);
00091    if (node)
00092       return (char*)xmlNodeGetContent(node->children);
00093    else
00094       return NULL;
00095 }
00096 
00097 xmlNodePtr xmlDocGetNodeByName(xmlDocPtr doc, const char *name, const char *ns)
00098 {
00099    xmlNodePtr cur = doc->children;
00100    return xmlNodeGetNodeByName(cur, name, ns);
00101 }
00102 
00103 char *xmlDocGetNodeContentByName(xmlDocPtr doc, const char *name, 
00104       const char *ns)
00105 {
00106    xmlNodePtr node = xmlDocGetNodeByName(doc, name, ns);
00107    if (node)
00108       return (char*)xmlNodeGetContent(node->children);
00109    else
00110       return NULL;
00111 }
00112 
00113 int bind_libxml_api(libxml_api_t* api)
00114 {
00115    if (!api)
00116    {
00117       LM_ERR("Invalid parameter value\n");
00118       return -1;
00119    }
00120    api->xmlDocGetNodeByName         =  xmlDocGetNodeByName;
00121    api->xmlNodeGetNodeByName        =  xmlNodeGetNodeByName;
00122    api->xmlNodeGetNodeContentByName =  xmlNodeGetNodeContentByName;
00123    api->xmlNodeGetAttrContentByName =  xmlNodeGetAttrContentByName;
00124    
00125    return 0;
00126 }  
00127 

Generated on Thu May 24 08:00:52 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6