Mercurial > repos > ktnyt > gembassy
comparison GEMBASSY-1.0.3/gsoap/custom/struct_tm.c @ 2:8947fca5f715 draft default tip
Uploaded
| author | ktnyt |
|---|---|
| date | Fri, 26 Jun 2015 05:21:44 -0400 |
| parents | 84a17b3fad1f |
| children |
comparison
equal
deleted
inserted
replaced
| 1:84a17b3fad1f | 2:8947fca5f715 |
|---|---|
| 1 /* | |
| 2 struct_tm.c | |
| 3 | |
| 4 Custom serializer for <time.h> struct tm | |
| 5 | |
| 6 Compile this file and link it with your code. | |
| 7 | |
| 8 Changes: | |
| 9 Feb 8, 2008: fixed local time to internal GMT conversion | |
| 10 | |
| 11 gSOAP XML Web services tools | |
| 12 Copyright (C) 2000-2008, Robert van Engelen, Genivia Inc., All Rights Reserved. | |
| 13 This part of the software is released under ONE of the following licenses: | |
| 14 GPL, the gSOAP public license, OR Genivia's license for commercial use. | |
| 15 -------------------------------------------------------------------------------- | |
| 16 gSOAP public license. | |
| 17 | |
| 18 The contents of this file are subject to the gSOAP Public License Version 1.3 | |
| 19 (the "License"); you may not use this file except in compliance with the | |
| 20 License. You may obtain a copy of the License at | |
| 21 http://www.cs.fsu.edu/~engelen/soaplicense.html | |
| 22 Software distributed under the License is distributed on an "AS IS" basis, | |
| 23 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
| 24 for the specific language governing rights and limitations under the License. | |
| 25 | |
| 26 The Initial Developer of the Original Code is Robert A. van Engelen. | |
| 27 Copyright (C) 2000-2008, Robert van Engelen, Genivia, Inc., All Rights Reserved. | |
| 28 -------------------------------------------------------------------------------- | |
| 29 GPL license. | |
| 30 | |
| 31 This program is free software; you can redistribute it and/or modify it under | |
| 32 the terms of the GNU General Public License as published by the Free Software | |
| 33 Foundation; either version 2 of the License, or (at your option) any later | |
| 34 version. | |
| 35 | |
| 36 This program is distributed in the hope that it will be useful, but WITHOUT ANY | |
| 37 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | |
| 38 PARTICULAR PURPOSE. See the GNU General Public License for more details. | |
| 39 | |
| 40 You should have received a copy of the GNU General Public License along with | |
| 41 this program; if not, write to the Free Software Foundation, Inc., 59 Temple | |
| 42 Place, Suite 330, Boston, MA 02111-1307 USA | |
| 43 | |
| 44 Author contact information: | |
| 45 engelen@genivia.com / engelen@acm.org | |
| 46 | |
| 47 This program is released under the GPL with the additional exemption that | |
| 48 compiling, linking, and/or using OpenSSL is allowed. | |
| 49 -------------------------------------------------------------------------------- | |
| 50 A commercial use license is available from Genivia, Inc., contact@genivia.com | |
| 51 -------------------------------------------------------------------------------- | |
| 52 */ | |
| 53 | |
| 54 /* soapH.h generated by soapcpp2 from .h file containing #import "struct_tm.h": */ | |
| 55 #include "soapH.h" | |
| 56 | |
| 57 void soap_default_xsd__dateTime(struct soap *soap, struct tm *a) | |
| 58 { memset(a, 0, sizeof(struct tm)); | |
| 59 } | |
| 60 | |
| 61 void soap_serialize_xsd__dateTime(struct soap *soap, struct tm const *a) | |
| 62 { } | |
| 63 | |
| 64 const char *soap_xsd__dateTime2s(struct soap *soap, const struct tm a) | |
| 65 { strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%SZ", &a); | |
| 66 return soap->tmpbuf; | |
| 67 } | |
| 68 | |
| 69 int soap_out_xsd__dateTime(struct soap *soap, const char *tag, int id, const struct tm *a, const char *type) | |
| 70 { if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, a, SOAP_TYPE_xsd__dateTime), type) | |
| 71 || soap_string_out(soap, soap_xsd__dateTime2s(soap, *a), 0)) | |
| 72 return soap->error; | |
| 73 return soap_element_end_out(soap, tag); | |
| 74 } | |
| 75 | |
| 76 int soap_s2xsd__dateTime(struct soap *soap, const char *s, struct tm *a) | |
| 77 { memset((void*)a, 0, sizeof(struct tm)); | |
| 78 if (s) | |
| 79 { char zone[32]; | |
| 80 const char *t; | |
| 81 if (strchr(s, '-')) | |
| 82 t = "%d-%d-%dT%d:%d:%d%31s"; | |
| 83 else if (strchr(s, ':')) | |
| 84 t = "%4d%2d%2dT%d:%d:%d%31s"; | |
| 85 else /* parse non-XSD-standard alternative ISO 8601 format */ | |
| 86 t = "%4d%2d%2dT%2d%2d%2d%31s"; | |
| 87 if (sscanf(s, t, &a->tm_year, &a->tm_mon, &a->tm_mday, &a->tm_hour, &a->tm_min, &a->tm_sec, zone) < 6) | |
| 88 return soap->error = SOAP_TYPE; | |
| 89 a->tm_wday = -1; | |
| 90 a->tm_yday = -1; | |
| 91 if (a->tm_year == 1) | |
| 92 a->tm_year = 70; | |
| 93 else | |
| 94 a->tm_year -= 1900; | |
| 95 a->tm_mon--; | |
| 96 if (*zone == '.') | |
| 97 { for (s = zone + 1; *s; s++) | |
| 98 if (*s < '0' || *s > '9') | |
| 99 break; | |
| 100 } | |
| 101 else | |
| 102 s = zone; | |
| 103 if (*s) | |
| 104 { if (*s == '+' || *s == '-') | |
| 105 { int h = 0, m = 0; | |
| 106 if (s[3] == ':') | |
| 107 { /* +hh:mm */ | |
| 108 sscanf(s, "%d:%d", &h, &m); | |
| 109 if (h < 0) | |
| 110 m = -m; | |
| 111 } | |
| 112 else /* +hhmm */ | |
| 113 { m = (int)atol(s); | |
| 114 h = m / 100; | |
| 115 m = m % 100; | |
| 116 } | |
| 117 a->tm_hour -= h; | |
| 118 a->tm_min -= m; | |
| 119 } | |
| 120 } | |
| 121 else /* if no time zone then convert to internal GMT without considering DST */ | |
| 122 { int minuteswest; | |
| 123 #if defined(HAVE_GETTIMEOFDAY) | |
| 124 struct timeval tv; | |
| 125 struct timezone tz; | |
| 126 gettimeofday(&tv, &tz); | |
| 127 minuteswest = tz.tz_minuteswest; | |
| 128 #elif defined(HAVE_FTIME) | |
| 129 struct timeb tb; | |
| 130 memset((void*)&tb, 0, sizeof(tb)); | |
| 131 #ifdef __BORLAND__ | |
| 132 ::ftime(&tb); | |
| 133 #else | |
| 134 ftime(&tb); | |
| 135 #endif | |
| 136 minuteswest = tb.timezone; | |
| 137 #else | |
| 138 /* local timezone unknown */ | |
| 139 minuteswest = 0; | |
| 140 #endif | |
| 141 a->tm_min += minuteswest; | |
| 142 } | |
| 143 /* put hour and min in range */ | |
| 144 a->tm_hour += a->tm_min / 60; | |
| 145 a->tm_min %= 60; | |
| 146 if (a->tm_min < 0) | |
| 147 { a->tm_min += 60; | |
| 148 a->tm_hour--; | |
| 149 } | |
| 150 a->tm_mday += a->tm_hour / 24; | |
| 151 a->tm_hour %= 24; | |
| 152 if (a->tm_hour < 0) | |
| 153 { a->tm_hour += 24; | |
| 154 a->tm_mday--; | |
| 155 } | |
| 156 } | |
| 157 return soap->error; | |
| 158 } | |
| 159 | |
| 160 struct tm *soap_in_xsd__dateTime(struct soap *soap, const char *tag, struct tm *a, const char *type) | |
| 161 { if (soap_element_begin_in(soap, tag, 0, NULL)) | |
| 162 return NULL; | |
| 163 if (*soap->type | |
| 164 && soap_match_tag(soap, soap->type, type) | |
| 165 && soap_match_tag(soap, soap->type, ":dateTime")) | |
| 166 { soap->error = SOAP_TYPE; | |
| 167 soap_revert(soap); | |
| 168 return NULL; | |
| 169 } | |
| 170 a = (struct tm*)soap_id_enter(soap, soap->id, a, SOAP_TYPE_xsd__dateTime, sizeof(struct tm), 0, NULL, NULL, NULL); | |
| 171 if (*soap->href) | |
| 172 a = (struct tm*)soap_id_forward(soap, soap->href, a, 0, SOAP_TYPE_xsd__dateTime, 0, sizeof(struct tm), 0, NULL); | |
| 173 else if (a) | |
| 174 { if (soap_s2xsd__dateTime(soap, soap_value(soap), a)) | |
| 175 return NULL; | |
| 176 } | |
| 177 if (soap->body && soap_element_end_in(soap, tag)) | |
| 178 return NULL; | |
| 179 return a; | |
| 180 } |
