Convert receivers to lopsub.
[paraslash.git] / recv.c
diff --git a/recv.c b/recv.c
index d127882a8e02d72219140325460fd73d9e050794..abebbfc2dfd80a0d2373f7c0431395c03656433f 100644 (file)
--- a/recv.c
+++ b/recv.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2014 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2005 Andre Noll <maan@tuebingen.mpg.de>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
@@ -8,11 +8,13 @@
 
 #include <regex.h>
 #include <sys/types.h>
+#include <inttypes.h>
+#include <lopsub.h>
 
+#include "recv_cmd.lsg.h"
 #include "para.h"
 #include "list.h"
 #include "sched.h"
-#include "ggo.h"
 #include "buffer_tree.h"
 #include "recv.h"
 #include "recv.cmdline.h"
 #include "stdout.h"
 #include "version.h"
 
-extern void afh_recv_init(struct receiver *r);
-#undef AFH_RECEIVER
-#define AFH_RECEIVER {.name = "afh", .init = afh_recv_init},
-DEFINE_RECEIVER_ARRAY;
+/** Array of error strings. */
+DEFINE_PARA_ERRLIST;
 
 /** The gengetopt args info struct. */
 static struct recv_args_info conf;
@@ -34,17 +34,15 @@ static int loglevel;
 /** Always log to stderr. */
 INIT_STDERR_LOGGING(loglevel);
 
-/** init array of error codes used by para_recv */
-INIT_RECV_ERRLISTS;
-
 __noreturn static void print_help_and_die(void)
 {
-       struct ggo_help h = DEFINE_GGO_HELP(recv);
        bool d = conf.detailed_help_given;
-
-       ggo_print_help(&h, d? GPH_STANDARD_FLAGS_DETAILED : GPH_STANDARD_FLAGS);
-       print_receiver_helps(d? GPH_MODULE_FLAGS_DETAILED : GPH_MODULE_FLAGS);
-       exit(0);
+       if (d)
+               recv_cmdline_parser_print_detailed_help();
+       else
+               recv_cmdline_parser_print_help();
+       print_receiver_helps(d);
+       exit(EXIT_SUCCESS);
 }
 
 /**
@@ -60,12 +58,15 @@ __noreturn static void print_help_and_die(void)
  */
 int main(int argc, char *argv[])
 {
-       int ret, r_opened = 0, receiver_num;
-       struct receiver *r = NULL;
+       int ret;
+       bool r_opened = false;
+       const struct receiver *r = NULL;
        struct receiver_node rn;
        struct stdout_task sot = {.btrn = NULL};
        static struct sched s;
        struct task_info ti;
+       const struct lls_command *cmd;
+       struct lls_parse_result *receiver_lpr; /* receiver specific options */
 
        recv_cmdline_parser(argc, argv, &conf);
        loglevel = get_loglevel_by_name(conf.loglevel_arg);
@@ -75,26 +76,25 @@ int main(int argc, char *argv[])
                print_help_and_die();
 
        memset(&rn, 0, sizeof(struct receiver_node));
-       rn.conf = check_receiver_arg(conf.receiver_arg, &receiver_num);
-       if (!rn.conf) {
-               PARA_EMERG_LOG("invalid receiver specifier\n");
-               ret = -E_RECV_SYNTAX;
+       ret = check_receiver_arg(conf.receiver_arg, &receiver_lpr);
+       if (ret < 0)
                goto out;
-       }
-       r = &receivers[receiver_num];
+       cmd = lls_cmd(ret, recv_cmd_suite);
+       r = lls_user_data(cmd);
        rn.receiver = r;
+       rn.lpr = receiver_lpr;
        rn.btrn = btr_new_node(&(struct btr_node_description)
-               EMBRACE(.name = r->name));
+               EMBRACE(.name = lls_command_name(cmd)));
        ret = r->open(&rn);
        if (ret < 0)
-               goto out;
-       r_opened = 1;
+               goto free_receiver_lpr;
+       r_opened = true;
 
        sot.btrn = btr_new_node(&(struct btr_node_description)
                EMBRACE(.parent = rn.btrn, .name = "stdout"));
        stdout_task_register(&sot, &s);
 
-       ti.name = r->name;
+       ti.name = lls_command_name(cmd);
        ti.pre_select = r->pre_select;
        ti.post_select = r->post_select;
        ti.context = &rn;
@@ -104,13 +104,16 @@ int main(int argc, char *argv[])
        s.default_timeout.tv_usec = 0;
        ret = schedule(&s);
        sched_shutdown(&s);
+       r->close(&rn);
+       btr_remove_node(&sot.btrn);
+       btr_remove_node(&rn.btrn);
+free_receiver_lpr:
+       lls_free_parse_result(receiver_lpr, cmd);
 out:
        if (r_opened)
                r->close(&rn);
        btr_remove_node(&rn.btrn);
        btr_remove_node(&sot.btrn);
-       if (rn.conf)
-               r->free_config(rn.conf);
 
        if (ret < 0)
                PARA_ERROR_LOG("%s\n", para_strerror(-ret));