annotate GEMBASSY-1.0.3/gsoap/custom/duration.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 duration.c
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
3
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
4 Custom serializer for xsd:duration stored in a LONG64 with ms precision
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
5 - the LONG64 int can represent 106751991167 days forward and backward
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
6 - LONG64 is long long int under Unix/Linux
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
7 - millisecond resolution (1/1000 sec) means 1 second = 1000
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
8 - when adding to a time_t value, conversion may be needed since time_t
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
9 may (or may) not have seconds resolution
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
10 - durations longer than a month are always output in days, rather than
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
11 months to avoid days-per-month conversion
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
12 - durations expressed in years and months are not well defined, since
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
13 there is no reference starting time; the decoder assumes 30 days per
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
14 month and conversion of P4M gives 120 days and therefore the duration
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
15 P4M and P120D are assumed identical, while they may yield different
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
16 result depending on the reference starting time
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
17
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
18 Compile this file and link it with your code.
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
19
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
20 gSOAP XML Web services tools
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
21 Copyright (C) 2000-2009, Robert van Engelen, Genivia Inc., All Rights Reserved.
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
22 This part of the software is released under ONE of the following licenses:
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
23 GPL, the gSOAP public license, OR Genivia's license for commercial use.
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
24 --------------------------------------------------------------------------------
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
25 gSOAP public license.
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
26
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
27 The contents of this file are subject to the gSOAP Public License Version 1.3
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
28 (the "License"); you may not use this file except in compliance with the
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
29 License. You may obtain a copy of the License at
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
30 http://www.cs.fsu.edu/~engelen/soaplicense.html
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
31 Software distributed under the License is distributed on an "AS IS" basis,
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
32 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
33 for the specific language governing rights and limitations under the License.
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
34
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
35 The Initial Developer of the Original Code is Robert A. van Engelen.
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
36 Copyright (C) 2000-2009, Robert van Engelen, Genivia, Inc., All Rights Reserved.
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
37 --------------------------------------------------------------------------------
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
38 GPL license.
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
39
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
40 This program is free software; you can redistribute it and/or modify it under
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
41 the terms of the GNU General Public License as published by the Free Software
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
42 Foundation; either version 2 of the License, or (at your option) any later
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
43 version.
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
44
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
45 This program is distributed in the hope that it will be useful, but WITHOUT ANY
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
46 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
47 PARTICULAR PURPOSE. See the GNU General Public License for more details.
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
48
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
49 You should have received a copy of the GNU General Public License along with
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
50 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
51 Place, Suite 330, Boston, MA 02111-1307 USA
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
52
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
53 Author contact information:
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
54 engelen@genivia.com / engelen@acm.org
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
55
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
56 This program is released under the GPL with the additional exemption that
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
57 compiling, linking, and/or using OpenSSL is allowed.
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
58 --------------------------------------------------------------------------------
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
59 A commercial use license is available from Genivia, Inc., contact@genivia.com
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
60 --------------------------------------------------------------------------------
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
61 */
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
62
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
63 /* soapH.h generated by soapcpp2 from .h file containing #import "duration.h":*/
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
64 #include "soapH.h"
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
65
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
66 void soap_default_xsd__duration(struct soap *soap, LONG64 *a)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
67 { (void)soap; /* appease -Wall -Werror */
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
68 *a = 0;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
69 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
70
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
71 const char *soap_xsd__duration2s(struct soap *soap, LONG64 a)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
72 { LONG64 d;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
73 int k, h, m, s, f;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
74 if (a < 0)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
75 { strcpy(soap->tmpbuf, "-P");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
76 k = 2;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
77 a = -a;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
78 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
79 else
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
80 { strcpy(soap->tmpbuf, "P");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
81 k = 1;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
82 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
83 f = a % 1000;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
84 a /= 1000;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
85 s = a % 60;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
86 a /= 60;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
87 m = a % 60;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
88 a /= 60;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
89 h = a % 24;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
90 d = a / 24;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
91 if (d)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
92 sprintf(soap->tmpbuf + k, SOAP_LONG_FORMAT "D", d);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
93 if (h || m || s || f)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
94 { if (d)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
95 k = strlen(soap->tmpbuf);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
96 if (f)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
97 sprintf(soap->tmpbuf + k, "T%dH%dM%d.%03dS", h, m, s, f);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
98 else
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
99 sprintf(soap->tmpbuf + k, "T%dH%dM%dS", h, m, s);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
100 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
101 else if (!d)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
102 strcpy(soap->tmpbuf + k, "T0S");
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
103 return soap->tmpbuf;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
104 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
105
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
106 int soap_out_xsd__duration(struct soap *soap, const char *tag, int id, const LONG64 *a, const char *type)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
107 { if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, a, SOAP_TYPE_xsd__duration), type)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
108 || soap_string_out(soap, soap_xsd__duration2s(soap, *a), 0))
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
109 return soap->error;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
110 return soap_element_end_out(soap, tag);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
111 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
112
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
113 int soap_s2xsd__duration(struct soap *soap, const char *s, LONG64 *a)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
114 { LONG64 sign = 1, Y = 0, M = 0, D = 0, H = 0, N = 0, S = 0;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
115 float f = 0;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
116 *a = 0;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
117 if (s)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
118 { if (*s == '-')
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
119 { sign = -1;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
120 s++;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
121 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
122 if (*s++ != 'P')
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
123 return soap->error = SOAP_TYPE;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
124 /* date part */
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
125 while (s && *s)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
126 { LONG64 n;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
127 char k;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
128 if (*s == 'T')
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
129 { s++;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
130 break;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
131 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
132 if (sscanf(s, SOAP_LONG_FORMAT "%c", &n, &k) != 2)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
133 return soap->error = SOAP_TYPE;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
134 s = strchr(s, k);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
135 if (!s)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
136 return soap->error = SOAP_TYPE;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
137 switch (k)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
138 { case 'Y':
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
139 Y = n;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
140 break;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
141 case 'M':
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
142 M = n;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
143 break;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
144 case 'D':
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
145 D = n;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
146 break;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
147 default:
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
148 return soap->error = SOAP_TYPE;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
149 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
150 s++;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
151 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
152 /* time part */
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
153 while (s && *s)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
154 { LONG64 n;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
155 char k;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
156 if (sscanf(s, SOAP_LONG_FORMAT "%c", &n, &k) != 2)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
157 return soap->error = SOAP_TYPE;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
158 s = strchr(s, k);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
159 if (!s)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
160 return soap->error = SOAP_TYPE;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
161 switch (k)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
162 { case 'H':
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
163 H = n;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
164 break;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
165 case 'M':
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
166 N = n;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
167 break;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
168 case '.':
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
169 S = n;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
170 if (sscanf(s, "%g", &f) != 1)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
171 return soap->error = SOAP_TYPE;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
172 s = NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
173 continue;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
174 case 'S':
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
175 S = n;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
176 break;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
177 default:
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
178 return soap->error = SOAP_TYPE;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
179 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
180 s++;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
181 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
182 /* convert Y-M-D H:N:S.f to signed long long int */
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
183 *a = sign * ((((((((((((Y * 12) + M) * 30) + D) * 24) + H) * 60) + N) * 60) + S) * 1000) + (long)(1000.0 * f));
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
184 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
185 return soap->error;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
186 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
187
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
188 LONG64 *soap_in_xsd__duration(struct soap *soap, const char *tag, LONG64 *a, const char *type)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
189 { if (soap_element_begin_in(soap, tag, 0, NULL))
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
190 return NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
191 if (*soap->type
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
192 && soap_match_tag(soap, soap->type, type)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
193 && soap_match_tag(soap, soap->type, ":duration"))
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
194 { soap->error = SOAP_TYPE;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
195 soap_revert(soap);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
196 return NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
197 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
198 a = (LONG64*)soap_id_enter(soap, soap->id, a, SOAP_TYPE_xsd__duration, sizeof(LONG64), 0, NULL, NULL, NULL);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
199 if (*soap->href)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
200 a = (LONG64*)soap_id_forward(soap, soap->href, a, 0, SOAP_TYPE_xsd__duration, 0, sizeof(LONG64), 0, NULL);
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
201 else if (a)
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
202 { if (soap_s2xsd__duration(soap, soap_value(soap), a))
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
203 return NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
204 }
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
205 if (soap->body && soap_element_end_in(soap, tag))
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
206 return NULL;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
207 return a;
8300eb051bea Initial upload
ktnyt
parents:
diff changeset
208 }