Mercurial > repos > ktnyt > gembassy
comparison GEMBASSY-1.0.3/gsoap/custom/struct_timeval.c @ 0:8300eb051bea draft
Initial upload
author | ktnyt |
---|---|
date | Fri, 26 Jun 2015 05:19:29 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:8300eb051bea |
---|---|
1 /* | |
2 struct_timeval.c | |
3 | |
4 Custom serializer for struct timeval | |
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_timeval.h": */ | |
55 #include "soapH.h" | |
56 | |
57 void soap_default_xsd__dateTime(struct soap *soap, struct timeval *a) | |
58 { memset(a, 0, sizeof(struct timeval)); | |
59 } | |
60 | |
61 void soap_serialize_xsd__dateTime(struct soap *soap, struct timeval const *a) | |
62 { } | |
63 | |
64 const char *soap_xsd__dateTime2s(struct soap *soap, const struct timeval a) | |
65 { char *s = soap->tmpbuf; | |
66 size_t n; | |
67 soap_dateTime2s(soap, a.tv_sec); /* assuming result is in tmpbuf! */ | |
68 n = strlen(s); | |
69 if (s[n-1] == 'Z') | |
70 n--; | |
71 sprintf(s + n, ".%.6dZ", a.tv_usec); | |
72 return s; | |
73 } | |
74 | |
75 int soap_out_xsd__dateTime(struct soap *soap, const char *tag, int id, const struct timeval *a, const char *type) | |
76 { if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, a, SOAP_TYPE_xsd__dateTime), type) | |
77 || soap_string_out(soap, soap_xsd__dateTime2s(soap, *a), 0)) | |
78 return soap->error; | |
79 return soap_element_end_out(soap, tag); | |
80 } | |
81 | |
82 int soap_s2xsd__dateTime(struct soap *soap, const char *s, struct timeval *a) | |
83 { memset((void*)a, 0, sizeof(struct timeval)); | |
84 if (s) | |
85 { char rest[32]; | |
86 const char *t; | |
87 struct tm tm; | |
88 memset((void*)&tm, 0, sizeof(struct tm)); | |
89 rest[sizeof(rest)-1] = '\0'; | |
90 if (strchr(s, '-')) | |
91 t = "%d-%d-%dT%d:%d:%d%31s"; | |
92 else if (strchr(s, ':')) | |
93 t = "%4d%2d%2dT%d:%d:%d%31s"; | |
94 else /* parse non-XSD-standard alternative ISO 8601 format */ | |
95 t = "%4d%2d%2dT%2d%2d%2d%31s"; | |
96 if (sscanf(s, t, &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec, rest) < 6) | |
97 return soap->error = SOAP_TYPE; | |
98 tm.tm_wday = -1; | |
99 tm.tm_yday = -1; | |
100 if (tm.tm_year == 1) | |
101 tm.tm_year = 70; | |
102 else | |
103 tm.tm_year -= 1900; | |
104 tm.tm_mon--; | |
105 tm.tm_isdst = 0; | |
106 if (*rest) | |
107 { if (*rest == '.') | |
108 { double f = 0; | |
109 for (s = rest + 1; *s; s++) | |
110 if (*s < '0' || *s > '9') | |
111 break; | |
112 sscanf(rest, "%lg", &f); | |
113 a->tv_usec = (int)(f*1000000.0); | |
114 } | |
115 else | |
116 { s = rest; | |
117 a->tv_usec = 0; | |
118 } | |
119 } | |
120 if (*s) | |
121 { if (*s == '+' || *s == '-') | |
122 { int h = 0, m = 0; | |
123 if (s[3] == ':') | |
124 { /* +hh:mm */ | |
125 sscanf(s, "%d:%d", &h, &m); | |
126 if (h < 0) | |
127 m = -m; | |
128 } | |
129 else /* +hhmm */ | |
130 { m = (int)atol(s); | |
131 h = m / 100; | |
132 m = m % 100; | |
133 } | |
134 tm.tm_hour -= h; | |
135 tm.tm_min -= m; | |
136 /* put hour and min in range */ | |
137 tm.tm_hour += tm.tm_min / 60; | |
138 tm.tm_min %= 60; | |
139 if (tm.tm_min < 0) | |
140 { tm.tm_min += 60; | |
141 tm.tm_hour--; | |
142 } | |
143 tm.tm_mday += tm.tm_hour / 24; | |
144 tm.tm_hour %= 24; | |
145 if (tm.tm_hour < 0) | |
146 { tm.tm_hour += 24; | |
147 tm.tm_mday--; | |
148 } | |
149 /* note: day of the month may be out of range, timegm() handles it */ | |
150 } | |
151 a->tv_sec = soap_timegm(&tm); | |
152 } | |
153 else | |
154 a->tv_sec = mktime(&tm); | |
155 } | |
156 return soap->error; | |
157 } | |
158 | |
159 struct timeval *soap_in_xsd__dateTime(struct soap *soap, const char *tag, struct timeval *a, const char *type) | |
160 { if (soap_element_begin_in(soap, tag, 0, NULL)) | |
161 return NULL; | |
162 if (*soap->type | |
163 && soap_match_tag(soap, soap->type, type) | |
164 && soap_match_tag(soap, soap->type, ":dateTime")) | |
165 { soap->error = SOAP_TYPE; | |
166 soap_revert(soap); | |
167 return NULL; | |
168 } | |
169 a = (struct timeval*)soap_id_enter(soap, soap->id, a, SOAP_TYPE_xsd__dateTime, sizeof(struct timeval), 0, NULL, NULL, NULL); | |
170 if (*soap->href) | |
171 a = (struct timeval*)soap_id_forward(soap, soap->href, a, 0, SOAP_TYPE_xsd__dateTime, 0, sizeof(struct timeval), 0, NULL); | |
172 else if (a) | |
173 { if (soap_s2xsd__dateTime(soap, soap_value(soap), a)) | |
174 return NULL; | |
175 } | |
176 if (soap->body && soap_element_end_in(soap, tag)) | |
177 return NULL; | |
178 return a; | |
179 } |