annotate GEMBASSY-1.0.3/gsoap/custom/struct_tm.c @ 1:84a17b3fad1f draft

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