5
Custom serializer for <time.h> struct tm
7
Compile this file and link it with your code.
9
gSOAP XML Web services tools
10
Copyright (C) 2000-2005, Robert van Engelen, Genivia Inc., All Rights Reserved.
11
This part of the software is released under one of the following licenses:
12
GPL, the gSOAP public license, or Genivia's license for commercial use.
13
--------------------------------------------------------------------------------
16
The contents of this file are subject to the gSOAP Public License Version 1.3
17
(the "License"); you may not use this file except in compliance with the
18
License. You may obtain a copy of the License at
19
http://www.cs.fsu.edu/~engelen/soaplicense.html
20
Software distributed under the License is distributed on an "AS IS" basis,
21
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
22
for the specific language governing rights and limitations under the License.
24
The Initial Developer of the Original Code is Robert A. van Engelen.
25
Copyright (C) 2000-2005, Robert van Engelen, Genivia, Inc., All Rights Reserved.
26
--------------------------------------------------------------------------------
29
This program is free software; you can redistribute it and/or modify it under
30
the terms of the GNU General Public License as published by the Free Software
31
Foundation; either version 2 of the License, or (at your option) any later
34
This program is distributed in the hope that it will be useful, but WITHOUT ANY
35
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
36
PARTICULAR PURPOSE. See the GNU General Public License for more details.
38
You should have received a copy of the GNU General Public License along with
39
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
40
Place, Suite 330, Boston, MA 02111-1307 USA
42
Author contact information:
43
engelen@genivia.com / engelen@acm.org
44
--------------------------------------------------------------------------------
45
A commercial use license is available from Genivia, Inc., contact@genivia.com
46
--------------------------------------------------------------------------------
49
// soapH.h generated by soapcpp2 from .h file containing #import "struct_tm.h":
52
void soap_default_xsd__dateTime(struct soap *soap, struct tm *a)
53
{ memset(a, 0, sizeof(struct tm));
56
void soap_serialize_xsd__dateTime(struct soap *soap, struct tm const *a)
59
int soap_out_xsd__dateTime(struct soap *soap, const char *tag, int id, const struct tm *a, const char *type)
60
{ if (soap_element_begin_out(soap, tag, soap_embedded_id(soap, id, a, SOAP_TYPE_xsd__dateTime), type)
61
|| soap_string_out(soap, soap_xsd__dateTime2s(soap, *a), 0))
63
return soap_element_end_out(soap, tag);
66
const char *soap_xsd__dateTime2s(struct soap *soap, const struct tm a)
67
{ strftime(soap->tmpbuf, sizeof(soap->tmpbuf), "%Y-%m-%dT%H:%M:%SZ", &a);
71
struct tm *soap_in_xsd__dateTime(struct soap *soap, const char *tag, struct tm *a, const char *type)
72
{ if (soap_element_begin_in(soap, tag, 0, NULL))
75
&& soap_match_tag(soap, soap->type, type)
76
&& soap_match_tag(soap, soap->type, ":dateTime"))
77
{ soap->error = SOAP_TYPE;
81
a = (struct tm*)soap_id_enter(soap, soap->id, a, SOAP_TYPE_xsd__dateTime, sizeof(struct tm), 0, NULL, NULL, NULL);
83
a = (struct tm*)soap_id_forward(soap, soap->href, a, 0, SOAP_TYPE_xsd__dateTime, 0, sizeof(struct tm), 0, NULL);
85
{ if (soap_s2xsd__dateTime(soap, soap_value(soap), a))
88
if (soap->body && soap_element_end_in(soap, tag))
93
int soap_s2xsd__dateTime(struct soap *soap, const char *s, struct tm *a)
94
{ memset((void*)a, 0, sizeof(struct tm));
98
zone[sizeof(zone)-1] = '\0';
100
t = "%d-%d-%dT%d:%d:%d%31s";
101
else if (strchr(s, ':'))
102
t = "%4d%2d%2dT%d:%d:%d%31s";
103
else /* parse non-XSD-standard alternative ISO 8601 format */
104
t = "%4d%2d%2dT%2d%2d%2d%31s";
105
sscanf(s, t, &a->tm_year, &a->tm_mon, &a->tm_mday, &a->tm_hour, &a->tm_min, &a->tm_sec, zone);
115
{ for (s = zone + 1; *s; s++)
116
if (*s < '0' || *s > '9')
121
if (*s == '+' || *s == '-')
124
{ sscanf(s, "%d:%d", &h, &m);