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
00039 #ifndef __OS_solaris
00040 #define _XOPEN_SOURCE 600
00041 #else
00042 #define _XOPEN_SOURCE_EXTENDED 1
00043 #endif
00044
00045 #include <time.h>
00046
00047 #undef _XOPEN_SOURCE
00048 #undef _XOPEN_SOURCE_EXTENDED
00049
00050 #include <string.h>
00051 #include <stdlib.h>
00052 #include <libxml/parser.h>
00053 #include "../../dprint.h"
00054 #include "pidf.h"
00055
00056 xmlAttrPtr xmlNodeGetAttrByName(xmlNodePtr node, const char *name)
00057 {
00058 xmlAttrPtr attr = node->properties;
00059 while (attr) {
00060 if (xmlStrcasecmp(attr->name, (unsigned char*)name) == 0)
00061 return attr;
00062 attr = attr->next;
00063 }
00064 return NULL;
00065 }
00066
00067 char *xmlNodeGetAttrContentByName(xmlNodePtr node, const char *name)
00068 {
00069 xmlAttrPtr attr = xmlNodeGetAttrByName(node, name);
00070 if (attr)
00071 return (char*)xmlNodeGetContent(attr->children);
00072 else
00073 return NULL;
00074 }
00075
00076 xmlNodePtr xmlNodeGetChildByName(xmlNodePtr node, const char *name)
00077 {
00078 xmlNodePtr cur = node->children;
00079 while (cur) {
00080 if (xmlStrcasecmp(cur->name, (unsigned char*)name) == 0)
00081 return cur;
00082 cur = cur->next;
00083 }
00084 return NULL;
00085 }
00086
00087 xmlNodePtr xmlNodeGetNodeByName(xmlNodePtr node, const char *name,
00088 const char *ns)
00089 {
00090 xmlNodePtr cur = node;
00091 while (cur) {
00092 xmlNodePtr match = NULL;
00093 if (xmlStrcasecmp(cur->name, (unsigned char*)name) == 0) {
00094 if (!ns || (cur->ns && xmlStrcasecmp(cur->ns->prefix,
00095 (unsigned char*)ns) == 0))
00096 return cur;
00097 }
00098 match = xmlNodeGetNodeByName(cur->children, name, ns);
00099 if (match)
00100 return match;
00101 cur = cur->next;
00102 }
00103 return NULL;
00104 }
00105
00106 char *xmlNodeGetNodeContentByName(xmlNodePtr root, const char *name,
00107 const char *ns)
00108 {
00109 xmlNodePtr node = xmlNodeGetNodeByName(root, name, ns);
00110 if (node)
00111 return (char*)xmlNodeGetContent(node->children);
00112 else
00113 return NULL;
00114 }
00115
00116 xmlNodePtr xmlDocGetNodeByName(xmlDocPtr doc, const char *name, const char *ns)
00117 {
00118 xmlNodePtr cur = doc->children;
00119 return xmlNodeGetNodeByName(cur, name, ns);
00120 }
00121
00122 char *xmlDocGetNodeContentByName(xmlDocPtr doc, const char *name,
00123 const char *ns)
00124 {
00125 xmlNodePtr node = xmlDocGetNodeByName(doc, name, ns);
00126 if (node)
00127 return (char*)xmlNodeGetContent(node->children);
00128 else
00129 return NULL;
00130 }
00131
00132 time_t xml_parse_dateTime(char* xml_time_str)
00133 {
00134 struct tm tm;
00135 char * p;
00136 int h, m;
00137 char h1, h2, m1, m2;
00138 int sign= 1;
00139 signed int timezone_diff= 0;
00140
00141 p= strptime(xml_time_str, "%F", &tm);
00142 if(p== NULL)
00143 {
00144 printf("error: failed to parse time\n");
00145 return 0;
00146 }
00147 p++;
00148 p= strptime(p, "%T", &tm);
00149 if(p== NULL)
00150 {
00151 printf("error: failed to parse time\n");
00152 return 0;
00153 }
00154
00155 if(*p== '\0')
00156 goto done;
00157
00158 if(*p== '.')
00159 {
00160 p++;
00161
00162 while(*p!= '\0' && *p>= '0' && *p<= '9')
00163 {
00164 p++;
00165 }
00166 }
00167
00168 if(*p== '\0')
00169 goto done;
00170
00171
00172
00173
00174 if(*p== 'Z')
00175 {
00176 goto done;
00177 }
00178
00179 if(*p== '+')
00180 sign= -1;
00181
00182 p++;
00183
00184 sscanf(p, "%c%c:%c%c", &h1, &h2, &m1, &m2);
00185
00186 h= (h1- '0')*10+ h2- '0';
00187 m= (m1- '0')*10+ m2- '0';
00188
00189 timezone_diff= sign* ((m+ h* 60)* 60);
00190
00191 done:
00192 return (mktime(&tm) + timezone_diff);
00193 }
00194
00195