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 2003 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 <errno.h>
30 #include "cmdgen.h"
31 #include "nfs_provider_names.h"
32 #include "util.h"
33 #include "cmdgen_include.h"
34 
35 /*
36  * Public methods
37  */
38 
39 /*
40  * Method: cmdgen_generate_command
41  *
42  * Description: Routes the calls to the command generator to the appropriate
43  * methods depending on the command type passed in.
44  *
45  * Parameters:
46  *	- int cmd_type - The command type to execute.  This command type must
47  *	be one of those defined in cmdgen.h.
48  *	- CCIMInstance *inst - The instance used to form the command.
49  *	- CCIMObjectPath *objPath - The object path used to form the command.
50  *	- CCIMPropertyList *paramList - The parameter list used to form the
51  *	command.
52  *	- int *errp - The error pointer.
53  *
54  * Returns:
55  *	- char * - the command formed from the input parameters.
56  *	- NULL if an error occurred.
57  */
58 
59 char *
cmdgen_generate_command(int cmd_type,CCIMInstance * inst,CCIMObjectPath * objPath,CCIMPropertyList * paramList,int * errp)60 cmdgen_generate_command(int cmd_type, CCIMInstance *inst,
61 	CCIMObjectPath *objPath, CCIMPropertyList *paramList, int *errp) {
62 
63 	char *cmd = NULL;
64 	int err;
65 
66 	if (inst == NULL && objPath == NULL && paramList == NULL) {
67 		util_handleError(COMMAND_GEN, CIM_ERR_INVALID_PARAMETER,
68 			NULL, NULL, &err);
69 		*errp = EINVAL;
70 		return (NULL);
71 	}
72 
73 	*errp = 0;
74 	switch (cmd_type) {
75 		case CMDGEN_MOUNTALL:
76 			cmd = cmdgen_mountall(paramList, errp);
77 			break;
78 		case CMDGEN_NFS_MOUNT:
79 			cmd = cmdgen_mount(CMDGEN_NFS, inst, objPath, errp);
80 			break;
81 		case CMDGEN_NFS_UMOUNT:
82 			cmd = cmdgen_umount(inst, objPath, errp);
83 			break;
84 		case CMDGEN_NFS_SHARE:
85 			cmd = cmdgen_share(CMDGEN_NFS, inst, objPath, errp);
86 			break;
87 		case CMDGEN_NFS_UNSHARE:
88 			cmd = cmdgen_unshare(CMDGEN_NFS, inst, objPath, errp);
89 			break;
90 		case CMDGEN_SHAREALL:
91 			cmd = cmdgen_shareall(paramList, errp);
92 			break;
93 		case CMDGEN_UNSHAREALL:
94 			cmd = cmdgen_unshareall(paramList, errp);
95 			break;
96 		case CMDGEN_UMOUNTALL:
97 			cmd = cmdgen_umountall(paramList, errp);
98 			break;
99 		default:
100 			*errp = EINVAL;
101 
102 	}
103 	return (cmd);
104 } /* cmdgen_generate_command */
105