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