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