xref: /onnv-gate/usr/src/cmd/wbem/provider/c/wbem_disk/lib/libDispatch.c (revision 0:68f95e015346)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <pthread.h>
30 
31 #include "master.h"
32 #include "util.h"
33 #include "providerNames.h"
34 #include "messageStrings.h"
35 
36 /* local function declarations */
37 static int FindClassEntry(char *className);
38 static int FindAssocClassEntry(char *className);
39 
40 
41 /*
42  * Encodes the CIM schema and provider version
43  * into an unsigned long, use
44  * getProviderVersion & getCimVersion to decode
45  */
46 
47 unsigned long
cp_getVersion()48 cp_getVersion()
49 {
50 	return (MAKEVERSION(1.0, 2.3));
51 }
52 
53 
54 /*
55  * The function will take CCIMObjectPath
56  * and search the classNameTable[]
57  * for a className match, and then
58  * call the corresponding cp_enumInstance
59  * for that provider
60  */
61 
62 CCIMInstanceList*
cp_enumInstances(CCIMObjectPath * pOP)63 cp_enumInstances(CCIMObjectPath* pOP)
64 {
65 	CCIMInstanceList	*instList = NULL;
66 	int 			index = 0;
67 	int    			error;
68 
69 	/* Check if ObjectPath is NULL before continuing */
70 	if (pOP == NULL) {
71 	    /* Set error exception with localized message */
72 	    util_handleError(ENUM_INSTANCES, CIM_ERR_INVALID_PARAMETER,
73 		NULL, NULL, &error);
74 	    return (NULL);
75 	}
76 
77 	/* Object path is NOT NULL, so find the entry in the table */
78 	index = FindClassEntry(pOP->mName);
79 
80 	/* check for error (-1) */
81 	if (index < 0) {
82 	    util_handleError(ENUM_INSTANCES, CIM_ERR_INVALID_CLASS,
83 		NULL, NULL, &error);
84 	    return (NULL);
85 	}
86 
87 	/* OK, Find enumInstance */
88 	instList = (*enumInstanceTable[index])(pOP);
89 	return ((CCIMInstanceList*)instList);
90 
91 }  /* cp_enumInstances */
92 
93 /* creates an instance */
94 
95 /*
96  * The function will take CCIMObjectPath & CCIMInstance
97  * and search the classNameTable[]
98  * for a className match, and then
99  * call the corresponding cp_createInstance
100  * for that provider
101  */
102 
103 CCIMObjectPath*
cp_createInstance(CCIMObjectPath * pOP,CCIMInstance * pInst)104 cp_createInstance(CCIMObjectPath* pOP, CCIMInstance* pInst)
105 {
106 	CCIMObjectPath *objPath = NULL;
107 	int index = 0;
108 	int error;
109 
110 	/* check if NULL before finding the Instance to create */
111 	if (pInst == NULL) {
112 	    util_handleError(CREATE_INSTANCE,
113 		CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
114 	    return (NULL);
115 	}
116 
117 	/* find entry in the table */
118 	index = FindClassEntry(pInst->mClassName);
119 
120 	/* check for error (-1) */
121 	if (index < 0) {
122 	    util_handleError(CREATE_INSTANCE,
123 		CIM_ERR_INVALID_CLASS, NULL, NULL, &error);
124 	    return (NULL);
125 	}
126 
127 	objPath = (*createInstanceTable[index])(pOP, pInst);
128 
129 	return ((CCIMObjectPath*) objPath);
130 
131 } /* cp_createInstances */
132 
133 
134 /*
135  * returns an array of CCIMObjectPaths for the class
136  * params:
137  * char* - the classname to enum
138  */
139 
140 CCIMObjectPathList*
cp_enumInstanceNames(CCIMObjectPath * pOP)141 cp_enumInstanceNames(CCIMObjectPath* pOP)
142 {
143 	CCIMObjectPathList	*objList = NULL;
144 	CCIMInstanceList	*instList = NULL;
145 	int			error = 0;
146 
147 	/*
148 	 * create an instance list which contains all of the
149 	 * instances this provider will produce First check
150 	 * for valid ObjectPath
151 	 */
152 	if (pOP == NULL) {
153 	    util_handleError(ENUM_INSTANCENAMES,
154 		CIM_ERR_INVALID_PARAMETER, NULL, NULL, &error);
155 	    return (NULL);
156 	}
157 
158 	instList = cp_enumInstances(pOP);
159 
160 	if (instList == NULL) {
161 	    return ((CCIMObjectPathList *)NULL);
162 	}
163 
164 	objList = cim_createObjectPathList(instList);
165 
166 	/*
167 	 * we no longer need the instList so free
168 	 * the memory allocated for it
169 	 */
170 
171 	cim_freeInstanceList(instList);
172 	return (objList);
173 }
174 
175 /* get an instance */
176 
177 CCIMInstance*
cp_getInstance(CCIMObjectPath * pOP)178 cp_getInstance(CCIMObjectPath* pOP)
179 {
180 	CCIMInstance* inst = NULL;
181 	int	index = 0;
182 	int	error;
183 
184 	/* Check if ObjectPath is NULL before continuing */
185 	if (pOP == NULL) {
186 	    util_handleError(GET_INSTANCE, CIM_ERR_INVALID_PARAMETER,
187 		NULL, NULL, &error);
188 	    return (NULL);
189 	}
190 
191 	/* Object path is NOT NULL, so find the entry in the table */
192 	index = FindClassEntry(pOP->mName);
193 
194 	/* check for error (-1) */
195 	if (index < 0) {
196 	    util_handleError(GET_INSTANCE, CIM_ERR_INVALID_CLASS, NULL,
197 		NULL, &error);
198 	    return (NULL);
199 	}
200 
201 	inst = (*getInstanceTable[index])(pOP);
202 	return ((CCIMInstance *)inst);
203 }
204 
205 /*
206  * returns the specified property,
207  * should return NULL if not found
208  *
209  * params:
210  * CCIMObjectPath* - ObjectPath to get the property from
211  * char* - The property name to get
212  *
213  */
214 
215 CCIMProperty*
cp_getProperty(CCIMObjectPath * pOP,char * pPropName)216 cp_getProperty(CCIMObjectPath *pOP, char *pPropName)
217 {
218 	CCIMProperty*	prop = NULL;
219 	CCIMInstance*	inst = NULL;
220 	int		error;
221 
222 	/* See if ObjectPath is OK */
223 	if (pOP == NULL) {
224 	    util_handleError(GET_PROPERTY, CIM_ERR_INVALID_PARAMETER,
225 		NULL, NULL, &error);
226 	    return (NULL);
227 	}
228 
229 	/* Make sure property name isn't NULL */
230 	if (pPropName == NULL) {
231 	    util_handleError(GET_PROPERTY, CIM_ERR_INVALID_CLASS,
232 		NULL, NULL, &error);
233 	    return (NULL);
234 	}
235 
236 	/* see if we have any instances which match the obj path */
237 	inst = cp_getInstance(pOP);
238 
239 	/* check for valid instance */
240 	if (inst == NULL) {
241 	    util_handleError(GET_PROPERTY, CIM_ERR_FAILED,
242 		NULL, NULL, &error);
243 	    return (NULL);
244 	}
245 
246 	/* see if it has the specified property */
247 	prop = cim_getProperty(inst, pPropName);
248 
249 	/* free memory allocated for the instance */
250 	cim_freeInstance(inst);
251 
252 	/* return the property */
253 	return ((CCIMProperty *)prop);
254 }
255 
256 /*
257  * Sets the property in the passed in
258  * instance to the new values of the
259  * passed in property
260  *
261  * params:
262  * CCIMObjectPath* - the Object Path in which the property should be changed
263  * CCIMProperty* - a property structure which contains the new values
264  *
265  * return:
266  * cim_true if property was updated otherwise cim_false
267  *
268  *
269  * The function will take CCIMObjectPath & CCIMProperty
270  * and search the classNameTable[]
271  * for a className match, and then
272  * call the corresponding setProperty
273  * for that provider
274  */
275 
276 CIMBool
cp_setProperty(CCIMObjectPath * pObjPath,CCIMProperty * pProp)277 cp_setProperty(CCIMObjectPath* pObjPath, CCIMProperty* pProp)
278 {
279 	CIMBool retVal;
280 	int index = 0;
281 	int	error;
282 
283 	if (pObjPath == NULL) {
284 	    util_handleError(SET_PROPERTY, CIM_ERR_INVALID_PARAMETER,
285 		NULL, NULL, &error);
286 	    return (NULL);
287 	}
288 
289 	index = FindClassEntry(pObjPath->mName);
290 
291 	/* check for error (-1) */
292 	if (index < 0) {
293 	    util_handleError(SET_PROPERTY, CIM_ERR_INVALID_CLASS,
294 		NULL, NULL, &error);
295 	    return (NULL);
296 	}
297 
298 	retVal = (*setPropertyTable[index])(pObjPath, pProp);
299 	return ((CIMBool)retVal);
300 }
301 
302 
303 /* sets an instance */
304 
305 /*
306  * The function will take CCIMObjectPath & CCIMInstance
307  * and search the classNameTable[]
308  * for a className match, and then
309  * call the corresponding cp_setInstance
310  * for that provider
311  */
312 
313 CIMBool
cp_setInstance(CCIMObjectPath * pOP,CCIMInstance * pInst)314 cp_setInstance(CCIMObjectPath* pOP, CCIMInstance* pInst)
315 {
316 	CIMBool retVal;
317 	int index = 0;
318 	int	error;
319 
320 	if (pOP == NULL) {
321 	    util_handleError(SET_INSTANCE, CIM_ERR_INVALID_PARAMETER,
322 		NULL, NULL, &error);
323 	    return (NULL);
324 	}
325 
326 	if (pInst == NULL) {
327 	    util_handleError(SET_INSTANCE, CIM_ERR_INVALID_CLASS,
328 		NULL, NULL, &error);
329 	    return (NULL);
330 	}
331 
332 	/* get the index into the table */
333 	index = FindClassEntry(pInst->mClassName);
334 
335 	/* check for error (-1) */
336 	if (index < 0) {
337 	    util_handleError(SET_INSTANCE, CIM_ERR_INVALID_CLASS,
338 		NULL, NULL, &error);
339 	    return (NULL);
340 	}
341 
342 	retVal = (*setInstanceTable[index])(pOP, pInst);
343 	return ((CIMBool)retVal);
344 }
345 
346 
347 /*
348  * deletes an instance
349  *
350  * The function will take CCIMObjectPath
351  * and search the classNameTable[]
352  * for a className match, and then
353  * call the corresponding cp_deleteInstance
354  * for that provider
355  */
356 
357 CIMBool
cp_deleteInstance(CCIMObjectPath * pOP)358 cp_deleteInstance(CCIMObjectPath* pOP)
359 {
360 	CIMBool retVal;
361 	int index = 0;
362 	int	error;
363 
364 	/* Verify ObjectPath is NOT NULL */
365 	if (pOP == NULL) {
366 	    util_handleError(DELETE_INSTANCE, CIM_ERR_INVALID_PARAMETER,
367 		NULL, NULL, &error);
368 	    return (NULL);
369 	}
370 
371 	/* find Entry in table */
372 	index = FindClassEntry(pOP->mName);
373 
374 	/* check for error (-1) */
375 	if (index < 0) {
376 	    util_handleError(DELETE_INSTANCE, CIM_ERR_INVALID_CLASS,
377 		NULL, NULL, &error);
378 	    return (NULL);
379 	}
380 
381 	retVal = (*deleteInstanceTable[index])(pOP);
382 	return ((CIMBool)retVal);
383 }
384 
385 /*
386  * Invokes the method and returns the results
387  *   The caller is responsible for freeing the
388  * memory allocated for the returned object
389  *
390  *  params:
391  * CCIMObjectPath* - An object path of the instance
392  *		to invoke the function on
393  *  char* - name of the method to invoke
394  * CCIMPropertyList* - input parameters to the function
395  * CCIMPropertyList* - input/output parameters to the function
396  *
397  * returns:
398  * NULL if it failed otherwise a CCIMProperty*
399  *    which represents the return value of the function
400  */
401 
402 CCIMProperty*
cp_invokeMethod(CCIMObjectPath * pOP,cimchar * pName,CCIMPropertyList * pInParams,CCIMPropertyList * pInOutParams)403 cp_invokeMethod(CCIMObjectPath* pOP, cimchar* pName,
404     CCIMPropertyList* pInParams, CCIMPropertyList* pInOutParams)
405 {
406 	CCIMProperty *prop;
407 	int index = 0;
408 	int error;
409 
410 	/* First check for valid ObjectPath */
411 	if (pOP == NULL) {
412 	    util_handleError(INVOKE_METHOD, CIM_ERR_INVALID_PARAMETER,
413 		NULL, NULL, &error);
414 	    return (NULL);
415 	}
416 
417 	/* find entry in the table */
418 	index = FindClassEntry(pOP->mName);
419 
420 	/* check for error (-1) */
421 	if (index < 0) {
422 	    util_handleError(INVOKE_METHOD, CIM_ERR_INVALID_CLASS,
423 		NULL, NULL, &error);
424 	    return (NULL);
425 	}
426 
427 	prop = (*cpInvokeMethodTable[index])
428 	    (pOP, pName, pInParams, pInOutParams);
429 
430 	return ((CCIMProperty*)prop);
431 }
432 
433 /*
434  * cp_execQuery
435  */
436 
437 CCIMInstanceList*
cp_execQuery(CCIMObjectPath * pOP,char * selectList,char * nonJoinExp,char * queryExp,char * queryType)438 cp_execQuery(CCIMObjectPath *pOP, char *selectList,
439     char *nonJoinExp, char *queryExp, char *queryType)
440 {
441 	CCIMInstanceList 	*instList = NULL;
442 	int			index = 0;
443 	int			error = 0;
444 
445 
446 	/* First check for valid ObjectPath */
447 	if (pOP == NULL) {
448 	    util_handleError(EXEC_QUERY, CIM_ERR_INVALID_PARAMETER, NULL, NULL,
449 		&error);
450 	    return ((CCIMInstanceList *)NULL);
451 	}
452 
453 	/* find entry in the table */
454 	index = FindClassEntry(pOP->mName);
455 
456 	/* check for error (-1) */
457 	if (index < 0) {
458 	    /* Set error exception with localized message */
459 	    util_handleError(EXEC_QUERY, CIM_ERR_INVALID_CLASS, NULL,
460 		NULL, &error);
461 	    return ((CCIMInstanceList *)NULL);
462 	}
463 	instList = (*execQueryTable[index])(pOP, selectList, nonJoinExp,
464 	    queryExp, queryType);
465 
466 	return (instList);
467 }
468 
469 /*
470  * cp_associators
471  */
472 
473 CCIMInstanceList*
cp_associators(CCIMObjectPath * pAssocName,CCIMObjectPath * pObjectName,char * pResultClass,char * pRole,char * pResultRole)474 cp_associators(CCIMObjectPath *pAssocName, CCIMObjectPath *pObjectName,
475     char *pResultClass, char *pRole, char *pResultRole)
476 {
477 	CCIMInstanceList 	*instList;
478 	int			index = 0;
479 	int			error = 0;
480 
481 	/* First check for valid ObjectPath */
482 	if (pAssocName == NULL) {
483 	    /* Set error exception with localized message */
484 	    util_handleError(ASSOCIATORS, CIM_ERR_INVALID_PARAMETER, NULL,
485 		NULL, &error);
486 	    return ((CCIMInstanceList *)NULL);
487 	}
488 
489 	/* find entry in the table */
490 	index = FindAssocClassEntry(pAssocName->mName);
491 
492 	/* check for error (-1) */
493 	if (index < 0) {
494 	    /* Set error exception with localized message */
495 	    util_handleError(ASSOCIATORS, CIM_ERR_INVALID_CLASS, NULL,
496 		NULL, &error);
497 	    return ((CCIMInstanceList *)NULL);
498 	}
499 
500 	/*
501 	 * Call the appropriate associator function. Let the specific function
502 	 * in the c provider handle the checking for correctness of the
503 	 * other parameters.
504 	 */
505 
506 	instList = (*associatorsTable[index])(pAssocName, pObjectName,
507 	    pResultClass, pRole, pResultRole);
508 	return ((CCIMInstanceList *)instList);
509 }
510 
511 /*
512  * cp_associatorNames
513  */
514 
515 CCIMObjectPathList*
cp_associatorNames(CCIMObjectPath * pAssocName,CCIMObjectPath * pObjectName,char * pResultClass,char * pRole,char * pResultRole)516 cp_associatorNames(CCIMObjectPath *pAssocName, CCIMObjectPath *pObjectName,
517     char *pResultClass, char *pRole, char *pResultRole)
518 {
519 	CCIMObjectPathList 	*objList;
520 	int			index = 0;
521 	int			error = 0;
522 
523 	/* First check for valid ObjectPath */
524 	if (pAssocName == NULL) {
525 	    /* Set error exception with localized message */
526 	    util_handleError(ASSOCIATORS, CIM_ERR_INVALID_PARAMETER, NULL,
527 		NULL, &error);
528 	    return ((CCIMObjectPathList *)NULL);
529 	}
530 
531 	/* find entry in the table */
532 	index = FindAssocClassEntry(pAssocName->mName);
533 
534 	/* check for error (-1) */
535 	if (index < 0) {
536 	    /* Set error exception with localized message */
537 	    util_handleError(ASSOCIATORS, CIM_ERR_INVALID_CLASS, NULL,
538 		NULL, &error);
539 	    return ((CCIMObjectPathList *)NULL);
540 	}
541 
542 	/*
543 	 * Call the appropriate associatorName function. Let the specific
544 	 * function in the c provider handle the checking for correctness of
545 	 * the other parameters.
546 	 */
547 
548 	objList = (*associatorNamesTable[index])(pAssocName, pObjectName,
549 	    pResultClass, pRole, pResultRole);
550 	return ((CCIMObjectPathList *)objList);
551 }
552 
553 /*
554  * cp_references
555  */
556 
557 CCIMInstanceList*
cp_references(CCIMObjectPath * pAssocName,CCIMObjectPath * pObjectName,char * pRole)558 cp_references(CCIMObjectPath *pAssocName, CCIMObjectPath *pObjectName,
559     char *pRole)
560 {
561 	CCIMInstanceList 	*instList;
562 	int			index = 0;
563 	int			error = 0;
564 
565 	/* First check for valid ObjectPath */
566 	if (pAssocName == NULL) {
567 	    /* Set error exception with localized message */
568 	    util_handleError(REFERENCES, CIM_ERR_INVALID_PARAMETER, NULL,
569 		NULL, &error);
570 	    return ((CCIMInstanceList *)NULL);
571 	}
572 
573 	/* find entry in the table */
574 	index = FindAssocClassEntry(pAssocName->mName);
575 
576 	/* check for error (-1) */
577 	if (index < 0) {
578 	    /* Set error exception with localized message */
579 	    util_handleError(REFERENCES, CIM_ERR_INVALID_CLASS, NULL,
580 		NULL, &error);
581 	    return ((CCIMInstanceList *)NULL);
582 	}
583 
584 	/*
585 	 * Call the appropriate references function. Let the specific function
586 	 * in the c provider handle the checking for correctness of the
587 	 * other parameters.
588 	 */
589 
590 	instList = (*referencesTable[index])(pAssocName, pObjectName, pRole);
591 	return ((CCIMInstanceList *)instList);
592 }
593 
594 /*
595  * InParam: Class Name
596  * Returns: Index into Name Table
597  * If it hit libWBEMdisk, then we
598  * have hit bottom, return err (-1)
599  */
600 
601 static int
FindClassEntry(char * className)602 FindClassEntry(char *className)
603 {
604 	int i = 0;
605 
606 	while (strcasecmp(className, classNameTable[i])) {
607 		if (!strcasecmp(classNameTable[i], "libWBEMdisk")) {
608 			i = -1;
609 			break;
610 		}
611 		i++;
612 	}
613 
614 	return (i);
615 }
616 /*
617  * InParam: Class Name
618  * Returns: Index into Name Table
619  * If it hit libWBEMdisk, then we
620  * have hit bottom, return err (-1)
621  */
622 
623 static int
FindAssocClassEntry(char * className)624 FindAssocClassEntry(char *className)
625 {
626 	int i = 0;
627 
628 	while (strcasecmp(className, assocclassNameTable[i])) {
629 		if (!strcasecmp(assocclassNameTable[i], "libWBEMdisk")) {
630 			i = -1;
631 			break;
632 		}
633 		i++;
634 	}
635 
636 	return (i);
637 }
638 
639 /*
640  * cp_referenceNames
641  */
642 
643 CCIMObjectPathList*
cp_referenceNames(CCIMObjectPath * pAssocName,CCIMObjectPath * pObjectName,char * pRole)644 cp_referenceNames(CCIMObjectPath *pAssocName, CCIMObjectPath *pObjectName,
645     char *pRole)
646 {
647 	CCIMObjectPathList 	*objList;
648 	int			index = 0;
649 	int			error = 0;
650 
651 	/* First check for valid ObjectPath */
652 	if (pAssocName == NULL) {
653 	    /* Set error exception with localized message */
654 	    util_handleError(REFERENCE_NAMES, CIM_ERR_INVALID_PARAMETER,
655 		NULL, NULL, &error);
656 	    return ((CCIMObjectPathList *)NULL);
657 	}
658 
659 	/* find entry in the table */
660 	index = FindAssocClassEntry(pAssocName->mName);
661 
662 	/* check for error (-1) */
663 	if (index < 0) {
664 	    /* Set error exception with localized message */
665 	    util_handleError(REFERENCE_NAMES, CIM_ERR_INVALID_CLASS,
666 		NULL, NULL, &error);
667 	    return ((CCIMObjectPathList *)NULL);
668 	}
669 
670 	/*
671 	 * Call the appropriate referenceName function. Let the specific
672 	 * function in the c provider handle the checking for correctness of
673 	 * the other parameters.
674 	 */
675 
676 	objList = (*referenceNamesTable[index])(pAssocName, pObjectName, pRole);
677 	return ((CCIMObjectPathList *)objList);
678 }
679 
680 CIMBool
cp_isAssociatorProvider(CCIMObjectPath * pOp)681 cp_isAssociatorProvider(CCIMObjectPath *pOp)
682 {
683 
684 	int 		index = 0;
685 	int			error = 0;
686 
687 	/*
688 	 * If the object path coming in matches any in the associator table,
689 	 * return true, otherwise, return false.
690 	 */
691 
692 	/* First check for valid ObjectPath */
693 	if (pOp == NULL) {
694 	    /* Set error exception with localized message */
695 	    util_handleError(REFERENCE_NAMES, CIM_ERR_INVALID_PARAMETER,
696 		NULL, NULL, &error);
697 	    return (cim_false);
698 	}
699 
700 	/* find entry in the table */
701 	index = FindAssocClassEntry(pOp->mName);
702 
703 	if (index < 0) {
704 	    return (cim_false);
705 	}
706 	return (cim_true);
707 }
708