summaryrefslogtreecommitdiff
path: root/source3/utils/net_util.c
diff options
context:
space:
mode:
authorKai Blin <kai@samba.org>2008-05-18 10:56:32 +0200
committerKai Blin <kai@samba.org>2008-06-10 09:45:14 +0200
commit6fd35d25bff4e1ceef07613c732dd7800afda35f (patch)
treec2414234758346b1873f30cfd3b5e944522897a9 /source3/utils/net_util.c
parent4d9748e44dc58e026136ce0c28526ba4cf1d4f3e (diff)
downloadsamba-6fd35d25bff4e1ceef07613c732dd7800afda35f.tar.gz
samba-6fd35d25bff4e1ceef07613c732dd7800afda35f.tar.bz2
samba-6fd35d25bff4e1ceef07613c732dd7800afda35f.zip
net: Move net_run_function/net_run_function2 to net_util.c
(This used to be commit 73fb5f392dbc1966ec34217e39d565200e071aaf)
Diffstat (limited to 'source3/utils/net_util.c')
-rw-r--r--source3/utils/net_util.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/source3/utils/net_util.c b/source3/utils/net_util.c
index 771c7e4f46..20f004b790 100644
--- a/source3/utils/net_util.c
+++ b/source3/utils/net_util.c
@@ -546,3 +546,49 @@ const char *net_prompt_pass(struct net_context *c, const char *user)
return pass;
}
+/*
+ run a function from a function table. If not found then
+ call the specified usage function
+*/
+int net_run_function(struct net_context *c, int argc, const char **argv,
+ struct functable *table,
+ int (*usage_fn)(struct net_context *c,
+ int argc, const char **argv))
+{
+ int i;
+
+ if (argc < 1) {
+ d_printf("\nUsage: \n");
+ return usage_fn(c, argc, argv);
+ }
+ for (i=0; table[i].funcname; i++) {
+ if (StrCaseCmp(argv[0], table[i].funcname) == 0)
+ return table[i].fn(c, argc-1, argv+1);
+ }
+ d_fprintf(stderr, "No command: %s\n", argv[0]);
+ return usage_fn(c, argc, argv);
+}
+
+/*
+ * run a function from a function table.
+ */
+int net_run_function2(struct net_context *c, int argc, const char **argv,
+ const char *whoami, struct functable2 *table)
+{
+ int i;
+
+ if (argc != 0) {
+ for (i=0; table[i].funcname; i++) {
+ if (StrCaseCmp(argv[0], table[i].funcname) == 0)
+ return table[i].fn(c, argc-1, argv+1);
+ }
+ }
+
+ for (i=0; table[i].funcname != NULL; i++) {
+ d_printf("%s %-15s %s\n", whoami, table[i].funcname,
+ table[i].helptext);
+ }
+
+ return -1;
+}
+