1 /*
2  * Portions of this file Copyright 1999-2005 University of Chicago
3  * Portions of this file Copyright 1999-2005 The University of Southern California.
4  *
5  * This file or a portion of this file is licensed under the
6  * terms of the Globus Toolkit Public License, found at
7  * http://www.globus.org/toolkit/download/license.html.
8  * If you redistribute this file, with or without
9  * modifications, you must include this notice in the file.
10  */
11
12 #include "globus_common.h"
13 #include "globus_i_xsd.h"
14 #include "globus_xsd_type_info.h"
15 #include "globus_soap_message_utils.h"
16
17 /**
18  * Create a new #globus_xsd_type_info_t type for serializing and
19  * deserializing an element with the same type as the given template.
20  *
21  * @param info
22  *     Pointer to the info type to be initialized;
23  * @param type
24  *     Element name.
25  * @param source
26  *     Original type info.
27  *
28  * @retval GLOBUS_XSD_ERROR_TYPE_NULL_PARAM
29  *     One of the parameters was invalid.
30  * @retval GLOBUS_XSD_ERROR_TYPE_OUT_OF_MEMORY
31  *     Unable to allocate type-related data structures.
32  */
33 globus_result_t
34 globus_xsd_type_info_init_from_template(
35     globus_xsd_type_info_t *            info,
36     const xsd_QName *                   name,
37     globus_xsd_type_info_t              source)
38 28 {
39 28     struct globus_xsd_type_info_s *     p;
40 28     globus_result_t                     result;
41 28     GlobusFuncName(globus_xsd_type_info_init);
42 28     GlobusSoapMessageDebugEnter();
43
44 28     if (info == NULL || name == NULL ||
45         source == NULL)
46     {
47 3         result = GlobusSoapMessageErrorNullParam;
48
49 3         goto error;
50     }
51 25     *info = NULL;
52
53 25     p = globus_libc_malloc(sizeof(struct globus_xsd_type_info_s));
54
55 25     if (p == NULL)
56     {
57 0         result = GlobusSoapMessageErrorOutOfMemory;
58
59 0         goto error;
60     }
61 25     memcpy(p, source, sizeof(struct globus_xsd_type_info_s));
62
63 25     p->type = globus_libc_malloc(sizeof(xsd_QName));
64 25     if (p->type == NULL)
65     {
66 0         result = GlobusSoapMessageErrorOutOfMemory;
67
68 0         goto free_p_error;
69     }
70
71 25     p->type->Namespace = globus_libc_strdup(name->Namespace);
72 25     if (p->type->Namespace == NULL)
73     {
74 0         result = GlobusSoapMessageErrorOutOfMemory;
75         
76 0         goto free_p_type_error;
77     }
78 25     p->type->local = globus_libc_strdup(name->local);
79 25     if (p->type->local == NULL)
80     {
81 0         result = GlobusSoapMessageErrorOutOfMemory;
82
83 0         goto free_ns_error;
84     }
85
86 25     *info = p;
87 25     return GLOBUS_SUCCESS;
88
89 free_ns_error:
90 0     globus_libc_free(p->type->Namespace);
91 free_p_type_error:
92 0     globus_libc_free(p->type);
93 free_p_error:
94 0     globus_libc_free(p);
95 error:
96 3     GlobusSoapMessageDebugExit();
97 3     return result;
98 }
99 /* globus_xsd_type_info_init_from_template() */
100
101 /**
102  * Destroy a previously allocated type info structure.
103  *
104  * @param info
105  *     Info to destroy.
106  * @retval GLOBUS_SUCCESS
107  *     Info structure destroyed successfully.
108  * @retval GLOBUS_XSD_ERROR_TYPE_NULL_PARAM
109  *     The @a info parameter was invalid.
110  */
111 void
112 globus_xsd_type_info_destroy(
113     globus_xsd_type_info_t              info)
114 2 {
115 2     globus_result_t                     result;
116 2     GlobusFuncName(globus_xsd_type_info_destroy);
117 2     GlobusSoapMessageDebugEnter();
118
119 2     if (info == NULL)
120     {
121 1         result = GlobusSoapMessageErrorNullParam;
122
123 1         goto error;
124     }
125
126 1     if (info->type->Namespace != NULL)
127     {
128 1         globus_libc_free(info->type->Namespace);
129     }
130 1     if (info->type->local != NULL)
131     {
132 1         globus_libc_free(info->type->local);
133     }
134 1     globus_libc_free(info->type);
135 1     globus_libc_free(info);
136
137 error:
138 2     GlobusSoapMessageDebugExit();
139 2     return;
140 }