1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is the Netscape security libraries.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 1994-2000
19 * the Initial Developer. All Rights Reserved.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
40 * Build Params Object Functions
44 #include "pkix_buildparams.h"
46 /* --Private-Functions-------------------------------------------- */
49 * FUNCTION: pkix_BuildParams_Destroy
50 * (see comments for PKIX_PL_DestructorCallback in pkix_pl_system.h)
53 pkix_BuildParams_Destroy(
54 PKIX_PL_Object
*object
,
57 PKIX_BuildParams
*params
= NULL
;
59 PKIX_ENTER(BUILDPARAMS
, "pkix_BuildParams_Destroy");
60 PKIX_NULLCHECK_ONE(object
);
62 /* Check that this object is a build params object */
63 PKIX_CHECK(pkix_CheckType(object
, PKIX_BUILDPARAMS_TYPE
, plContext
),
64 "Object is not a build params object");
66 params
= (PKIX_BuildParams
*)object
;
68 PKIX_DECREF(params
->procParams
);
72 PKIX_RETURN(BUILDPARAMS
);
76 * FUNCTION: pkix_BuildParams_Equals
77 * (see comments for PKIX_PL_EqualsCallback in pkix_pl_system.h)
80 pkix_BuildParams_Equals(
81 PKIX_PL_Object
*first
,
82 PKIX_PL_Object
*second
,
83 PKIX_Boolean
*pResult
,
86 PKIX_UInt32 secondType
;
87 PKIX_Boolean cmpResult
;
88 PKIX_BuildParams
*firstBuildParams
= NULL
;
89 PKIX_BuildParams
*secondBuildParams
= NULL
;
91 PKIX_ENTER(BUILDPARAMS
, "pkix_BuildParams_Equals");
92 PKIX_NULLCHECK_THREE(first
, second
, pResult
);
94 PKIX_CHECK(pkix_CheckType(first
, PKIX_BUILDPARAMS_TYPE
, plContext
),
95 "First Argument is not a BuildParams object");
97 PKIX_CHECK(PKIX_PL_Object_GetType(second
, &secondType
, plContext
),
98 PKIX_COULDNOTGETTYPEOFSECONDARGUMENT
);
100 *pResult
= PKIX_FALSE
;
102 if (secondType
!= PKIX_BUILDPARAMS_TYPE
) goto cleanup
;
104 firstBuildParams
= (PKIX_BuildParams
*)first
;
105 secondBuildParams
= (PKIX_BuildParams
*)second
;
107 PKIX_CHECK(PKIX_PL_Object_Equals
108 ((PKIX_PL_Object
*)firstBuildParams
->procParams
,
109 (PKIX_PL_Object
*)secondBuildParams
->procParams
,
112 PKIX_OBJECTEQUALSFAILED
);
114 if (!cmpResult
) goto cleanup
;
116 *pResult
= cmpResult
;
120 PKIX_RETURN(BUILDPARAMS
);
124 * FUNCTION: pkix_BuildParams_Hashcode
125 * (see comments for PKIX_PL_HashcodeCallback in pkix_pl_system.h)
128 pkix_BuildParams_Hashcode(
129 PKIX_PL_Object
*object
,
130 PKIX_UInt32
*pHashcode
,
133 PKIX_BuildParams
*buildParams
= NULL
;
134 PKIX_UInt32 hash
= 0;
135 PKIX_UInt32 procParamsHash
= 0;
137 PKIX_ENTER(BUILDPARAMS
, "pkix_BuildParams_Hashcode");
138 PKIX_NULLCHECK_TWO(object
, pHashcode
);
140 PKIX_CHECK(pkix_CheckType(object
, PKIX_BUILDPARAMS_TYPE
, plContext
),
141 "Object is not a processingParams object");
143 buildParams
= (PKIX_BuildParams
*)object
;
145 PKIX_CHECK(PKIX_PL_Object_Hashcode
146 ((PKIX_PL_Object
*)buildParams
->procParams
,
149 PKIX_OBJECTHASHCODEFAILED
);
151 hash
= 31 * procParamsHash
;
157 PKIX_RETURN(BUILDPARAMS
);
161 * FUNCTION: pkix_BuildParams_ToString
162 * (see comments for PKIX_PL_ToStringCallback in pkix_pl_system.h)
165 pkix_BuildParams_ToString(
166 PKIX_PL_Object
*object
,
167 PKIX_PL_String
**pString
,
170 PKIX_BuildParams
*buildParams
= NULL
;
171 char *asciiFormat
= NULL
;
172 PKIX_PL_String
*formatString
= NULL
;
173 PKIX_PL_String
*buildParamsString
= NULL
;
175 PKIX_PL_String
*procParamsString
= NULL
;
177 PKIX_ENTER(BUILDPARAMS
, "pkix_BuildParams_ToString");
178 PKIX_NULLCHECK_TWO(object
, pString
);
180 PKIX_CHECK(pkix_CheckType(object
, PKIX_BUILDPARAMS_TYPE
, plContext
),
181 PKIX_OBJECTNOTBUILDPARAMS
);
185 "\tProcessing Params: \n"
186 "\t********BEGIN PROCESSING PARAMS********\n"
188 "\t********END PROCESSING PARAMS********\n"
191 PKIX_CHECK(PKIX_PL_String_Create
197 PKIX_STRINGCREATEFAILED
);
199 buildParams
= (PKIX_BuildParams
*)object
;
201 PKIX_CHECK(PKIX_PL_Object_ToString
202 ((PKIX_PL_Object
*)buildParams
->procParams
,
205 PKIX_OBJECTTOSTRINGFAILED
);
207 PKIX_CHECK(PKIX_PL_Sprintf
214 *pString
= buildParamsString
;
218 PKIX_DECREF(formatString
);
219 PKIX_DECREF(procParamsString
);
221 PKIX_RETURN(BUILDPARAMS
);
225 * FUNCTION: pkix_BuildParams_RegisterSelf
227 * Registers PKIX_BUILDPARAMS_TYPE and its related functions with
230 * Not Thread Safe - for performance and complexity reasons
232 * Since this function is only called by PKIX_PL_Initialize, which should
233 * only be called once, it is acceptable that this function is not
237 pkix_BuildParams_RegisterSelf(void *plContext
)
240 extern pkix_ClassTable_Entry systemClasses
[PKIX_NUMTYPES
];
241 pkix_ClassTable_Entry entry
;
243 PKIX_ENTER(BUILDPARAMS
, "pkix_BuildParams_RegisterSelf");
245 entry
.description
= "BuildParams";
246 entry
.destructor
= pkix_BuildParams_Destroy
;
247 entry
.equalsFunction
= pkix_BuildParams_Equals
;
248 entry
.hashcodeFunction
= pkix_BuildParams_Hashcode
;
249 entry
.toStringFunction
= pkix_BuildParams_ToString
;
250 entry
.comparator
= NULL
;
251 entry
.duplicateFunction
= NULL
;
253 systemClasses
[PKIX_BUILDPARAMS_TYPE
] = entry
;
255 PKIX_RETURN(BUILDPARAMS
);
258 /* --Public-Functions--------------------------------------------- */
261 * FUNCTION: PKIX_BuildParams_Create (see comments in pkix_params.h)
264 PKIX_BuildParams_Create(
265 PKIX_ProcessingParams
*procParams
,
266 PKIX_BuildParams
**pParams
,
269 PKIX_BuildParams
*params
= NULL
;
271 PKIX_ENTER(BUILDPARAMS
, "PKIX_BuildParams_Create");
272 PKIX_NULLCHECK_TWO(procParams
, pParams
);
274 PKIX_CHECK(PKIX_PL_Object_Alloc
275 (PKIX_BUILDPARAMS_TYPE
,
276 sizeof (PKIX_BuildParams
),
277 (PKIX_PL_Object
**)¶ms
,
279 PKIX_COULDNOTCREATEBUILDPARAMSOBJECT
);
281 /* initialize fields */
282 PKIX_INCREF(procParams
);
283 params
->procParams
= procParams
;
289 PKIX_RETURN(BUILDPARAMS
);
294 * FUNCTION: PKIX_BuildParams_GetProcessingParams
295 * (see comments in pkix_params.h)
298 PKIX_BuildParams_GetProcessingParams(
299 PKIX_BuildParams
*buildParams
,
300 PKIX_ProcessingParams
**pProcParams
,
303 PKIX_ENTER(BUILDPARAMS
, "PKIX_BuildParams_GetProcessingParams");
304 PKIX_NULLCHECK_TWO(buildParams
, pProcParams
);
306 PKIX_INCREF(buildParams
->procParams
);
308 *pProcParams
= buildParams
->procParams
;
310 PKIX_RETURN(BUILDPARAMS
);