dispatch.c revision 28075
1/*
2 * The new sysinstall program.
3 *
4 * This is probably the last program in the `sysinstall' line - the next
5 * generation being essentially a complete rewrite.
6 *
7 * $Id: dispatch.c,v 1.20 1997/07/16 05:22:40 jkh Exp $
8 *
9 * Copyright (c) 1995
10 *	Jordan Hubbard.  All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 *    notice, this list of conditions and the following disclaimer,
17 *    verbatim and that no modifications are made prior to this
18 *    point in the file.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 *    notice, this list of conditions and the following disclaimer in the
21 *    documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY JORDAN HUBBARD ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED.  IN NO EVENT SHALL JORDAN HUBBARD OR HIS PETS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 */
36
37#include "sysinstall.h"
38#include <ctype.h>
39
40static int _shutdown(dialogMenuItem *unused);
41static int _systemExecute(dialogMenuItem *unused);
42
43static struct _word {
44    char *name;
45    int (*handler)(dialogMenuItem *self);
46} resWords[] = {
47    { "configAnonFTP",		configAnonFTP		},
48    { "configRouter",		configRouter		},
49    { "configNFSServer",	configNFSServer		},
50    { "configNTP",		configNTP		},
51    { "configPCNFSD",		configPCNFSD		},
52    { "configPackages",		configPackages		},
53    { "configRegister",		configRegister		},
54    { "configUsers",		configUsers		},
55    { "configXEnvironment",	configXEnvironment	},
56    { "diskPartitionEditor",	diskPartitionEditor	},
57    { "diskPartitionWrite",	diskPartitionWrite	},
58    { "diskLabelEditor",	diskLabelEditor		},
59    { "diskLabelCommit",	diskLabelCommit		},
60    { "distReset",		distReset		},
61    { "distSetCustom",		distSetCustom		},
62    { "distSetDeveloper",	distSetDeveloper	},
63    { "distSetXDeveloper",	distSetXDeveloper	},
64    { "distSetKernDeveloper",	distSetKernDeveloper	},
65    { "distSetUser",		distSetUser		},
66    { "distSetXUser",		distSetXUser		},
67    { "distSetMinimum",		distSetMinimum		},
68    { "distSetEverything",	distSetEverything	},
69    { "distSetDES",		distSetDES		},
70    { "distSetSrc",		distSetSrc		},
71    { "distSetXF86",		distSetXF86		},
72    { "distExtractAll",		distExtractAll		},
73    { "docBrowser",		docBrowser		},
74    { "docShowDocument",	docShowDocument		},
75    { "installCommit",		installCommit		},
76    { "installExpress",		installExpress		},
77    { "installNovice",		installNovice		},
78    { "installUpgrade",		installUpgrade		},
79    { "installFixup",		installFixup		},
80    { "installFixitHoloShell",	installFixitHoloShell	},
81    { "installFixitCDROM",	installFixitCDROM	},
82    { "installFixitFloppy",	installFixitFloppy	},
83    { "installFilesystems",	installFilesystems	},
84    { "installVarDefaults",	installVarDefaults	},
85    { "mediaSetCDROM",		mediaSetCDROM		},
86    { "mediaSetFloppy",		mediaSetFloppy		},
87    { "mediaSetDOS",		mediaSetDOS		},
88    { "mediaSetTape",		mediaSetTape		},
89    { "mediaSetFTP",		mediaSetFTP		},
90    { "mediaSetFTPActive",	mediaSetFTPActive	},
91    { "mediaSetFTPPassive",	mediaSetFTPPassive	},
92    { "mediaSetUFS",		mediaSetUFS		},
93    { "mediaSetNFS",		mediaSetNFS		},
94    { "mediaSetFTPUserPass",	mediaSetFTPUserPass	},
95    { "mediaSetCPIOVerbosity",	mediaSetCPIOVerbosity	},
96    { "mediaGetType",		mediaGetType		},
97    { "optionsEditor",		optionsEditor		},
98    { "register",		configRegister		},	/* Alias */
99    { "packageAdd",		packageAdd		},
100    { "addGroup",		userAddGroup		},
101    { "addUser",		userAddUser		},
102    { "shutdown",		_shutdown 		},
103    { "system",			_systemExecute 		},
104    { NULL, NULL },
105};
106
107static int
108call_possible_resword(char *name, dialogMenuItem *value, int *status)
109{
110    int i, rval;
111
112    rval = 0;
113    for (i = 0; resWords[i].name; i++) {
114	if (!strcmp(name, resWords[i].name)) {
115	    *status = resWords[i].handler(value);
116	    rval = 1;
117	    break;
118	}
119    }
120    return rval;
121}
122
123/* Just convenience */
124static int
125_shutdown(dialogMenuItem *unused)
126{
127    systemShutdown(0);
128    return DITEM_FAILURE;
129}
130
131static int
132_systemExecute(dialogMenuItem *unused)
133{
134    char *cmd = variable_get("command");
135
136    if (cmd)
137	return systemExecute(cmd) ? DITEM_FAILURE : DITEM_SUCCESS;
138    else
139	msgDebug("_systemExecute: No command passed in `command' variable.\n");
140    return DITEM_FAILURE;
141}
142
143/* For a given string, call it or spit out an undefined command diagnostic */
144int
145dispatchCommand(char *str)
146{
147    int i;
148    char *cp;
149
150    if (!str || !*str) {
151	msgConfirm("Null or zero-length string passed to dispatchCommand");
152	return DITEM_FAILURE;
153    }
154    /* If it's got a newline, trim it */
155    if ((cp = index(str, '\n')) != NULL)
156	*cp = '\0';
157
158    /* If it's got a `=' sign in there, assume it's a variable setting */
159    if (index(str, '=')) {
160	if (isDebug())
161	    msgDebug("dispatch: setting variable `%s'\n", str);
162	variable_set(str);
163	i = DITEM_SUCCESS;
164    }
165    else {
166	/* A command might be a pathname if it's encoded in argv[0], which we also support */
167	if ((cp = rindex(str, '/')) != NULL)
168	    str = cp + 1;
169	if (isDebug())
170	    msgDebug("dispatch: calling resword `%s'\n", str);
171	if (!call_possible_resword(str, NULL, &i)) {
172	    msgNotify("Warning: No such command ``%s''", str);
173	    i = DITEM_FAILURE;
174	}
175    }
176    return i;
177}
178