pua/pidf.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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