paraslash 0.7.3
[paraslash.git] / client.c
index 68d8a7efed285891653adfd5d68faaae06d41c1a..84b7580cf9554c433651da1f3eed28a6f1f39a74 100644 (file)
--- a/client.c
+++ b/client.c
@@ -1,8 +1,4 @@
-/*
- * Copyright (C) 1997 Andre Noll <maan@tuebingen.mpg.de>
- *
- * Licensed under the GPL v2. For licencing details see COPYING.
- */
+/* Copyright (C) 1997 Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */
 
 /** \file client.c The client program used to connect to para_server. */
 
@@ -46,7 +42,7 @@ struct exec_task {
        size_t result_size;
 };
 
-static void exec_pre_select(struct sched *s, void *context)
+static void exec_pre_monitor(struct sched *s, void *context)
 {
        struct exec_task *et = context;
        int ret = btr_node_status(et->btrn, 0, BTR_NT_LEAF);
@@ -55,7 +51,7 @@ static void exec_pre_select(struct sched *s, void *context)
                sched_min_delay(s);
 }
 
-static int exec_post_select(__a_unused struct sched *s, void *context)
+static int exec_post_monitor(__a_unused struct sched *s, void *context)
 {
        struct exec_task *et = context;
        struct btr_node *btrn = et->btrn;
@@ -104,7 +100,7 @@ static int create_merged_lpr(const char *line)
        /*
         * The original lpr for the interactive session has no non-option
         * arguments. We create a fresh lpr from the words in "line" and merge
-        * it with the orignal lpr.
+        * it with the original lpr.
         */
        ret = lls(lls_parse(argc, argv, cmd, &argv_lpr, &errctx));
        free_argv(argv);
@@ -127,7 +123,7 @@ fail:
 static int execute_client_command(const char *cmd, char **result)
 {
        int ret;
-       struct sched command_sched = {.default_timeout = {.tv_sec = 1}};
+       struct sched command_sched = {.default_timeout = 1000};
        struct exec_task exec_task = {
                .result_buf = para_strdup(""),
                .result_size = 1,
@@ -142,8 +138,8 @@ static int execute_client_command(const char *cmd, char **result)
                EMBRACE(.name = "exec_collect"));
        exec_task.task = task_register(&(struct task_info) {
                .name = "client exec",
-               .pre_select = exec_pre_select,
-               .post_select = exec_post_select,
+               .pre_monitor = exec_pre_monitor,
+               .post_monitor = exec_post_monitor,
                .context = &exec_task,
        }, &command_sched);
        ret = client_connect(ct, &command_sched, NULL, exec_task.btrn);
@@ -247,14 +243,25 @@ I9E_DUMMY_COMPLETER(term);
 I9E_DUMMY_COMPLETER(stop);
 I9E_DUMMY_COMPLETER(addatt);
 I9E_DUMMY_COMPLETER(init);
-I9E_DUMMY_COMPLETER(tasks);
 
 static struct i9e_completer completers[];
 
+static void ll_completer(struct i9e_completion_info *ci,
+               struct i9e_completion_result *cr)
+{
+       i9e_ll_completer(ci, cr);
+}
+
 static void help_completer(struct i9e_completion_info *ci,
-               struct i9e_completion_result *result)
+               struct i9e_completion_result *cr)
 {
-       result->matches = i9e_complete_commands(ci->word, completers);
+       char *opts[] = {LSG_SERVER_CMD_HELP_OPTS, NULL};
+
+       if (ci->word[0] == '-') {
+               i9e_complete_option(opts, ci, cr);
+               return;
+       }
+       cr->matches = i9e_complete_commands(ci->word, completers);
 }
 
 static void stat_completer(struct i9e_completion_info *ci,
@@ -340,7 +347,7 @@ static void setatt_completer(struct i9e_completion_info *ci,
        if (ret < 0)
                goto out;
        num_atts = ret;
-       sl = para_realloc(sl, (2 * num_atts + 1) * sizeof(char *));
+       sl = arr_realloc(sl, 2 * num_atts + 1, sizeof(char *));
        for (i = 0; i < num_atts; i++) {
                char *orig = sl[i];
                sl[i] = make_message("%s+", orig);
@@ -434,7 +441,7 @@ static void select_completer(struct i9e_completion_info *ci,
                goto free_moods;
        num_pl = ret;
        n = num_moods + num_pl;
-       mops = para_malloc((n + 1) * sizeof(char *));
+       mops = arr_alloc(n + 1, sizeof(char *));
        for (i = 0; i < num_moods; i++)
                mops[i] = make_message("m/%s", moods[i]);
        for (i = 0; i < num_pl; i++)
@@ -497,7 +504,6 @@ static int client_i9e_line_handler(char *line)
        return 1;
 }
 
-I9E_DUMMY_COMPLETER(SUPERCOMMAND_UNAVAILABLE);
 static struct i9e_completer completers[] = {
 #define LSG_SERVER_CMD_CMD(_name) {.name = #_name, \
        .completer = _name ## _completer}
@@ -532,7 +538,7 @@ __noreturn static void interactive_session(void)
        sigemptyset(&act.sa_mask);
        act.sa_flags = 0;
        sigaction(SIGINT, &act, NULL);
-       sched.select_function = i9e_select;
+       sched.poll_function = i9e_poll;
 
        ret = i9e_open(&ici, &sched);
        if (ret < 0)
@@ -578,7 +584,7 @@ struct supervisor_task {
        struct task *task;
 };
 
-static int supervisor_post_select(struct sched *s, void *context)
+static int supervisor_post_monitor(struct sched *s, void *context)
 {
        struct supervisor_task *svt = context;
        int ret = task_status(ct->task);
@@ -616,14 +622,15 @@ static struct supervisor_task supervisor_task;
  *
  * \return EXIT_SUCCESS or EXIT_FAILURE
  *
- * \sa client_open(), stdin.c, stdout.c, para_client(1), para_server(1)
+ * \sa \ref client_open(), \ref stdin.c, \ref stdout.c, para_client(1),
+ * para_server(1).
  */
 int main(int argc, char *argv[])
 {
        int ret;
 
-       init_random_seed_or_die();
-       sched.default_timeout.tv_sec = 1;
+       crypt_init();
+       sched.default_timeout = 1000;
 
        ret = client_parse_config(argc, argv, &ct, &client_loglevel);
        if (ret < 0)
@@ -647,7 +654,7 @@ int main(int argc, char *argv[])
                EMBRACE(.name = "stdout", .parent = ct->btrn[0]));
        supervisor_task.task = task_register(&(struct task_info) {
                .name = "supervisor",
-               .post_select = supervisor_post_select,
+               .post_monitor = supervisor_post_monitor,
                .context = &supervisor_task,
        }, &sched);
 
@@ -659,8 +666,6 @@ int main(int argc, char *argv[])
                        /* these are not errors */
                        case -E_SERVER_CMD_SUCCESS:
                        case -E_EOF:
-                       case -E_SERVER_EOF:
-                       case -E_BTR_EOF:
                                ret = 0;
                                break;
                        default: ret = -E_SERVER_CMD_FAILURE;
@@ -668,6 +673,7 @@ int main(int argc, char *argv[])
                }
        }
        sched_shutdown(&sched);
+       crypt_shutdown();
 out:
        if (ret < 0)
                PARA_ERROR_LOG("%s\n", para_strerror(-ret));