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