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