drop_privileges_or_die(): Check return value of setuid().
[paraslash.git] / filter_common.c
index 45f576050c6f34a56dfb8f6cfff495478466f212..2fa774c0b57e614ec2e7493661d0e589e5c44d58 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2008 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2005-2009 Andre Noll <maan@systemlinux.org>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
@@ -23,17 +23,14 @@ struct filter filters[NUM_SUPPORTED_FILTERS] = {FILTER_ARRAY};
 
 /**
  * Call the init function of each supported filter.
- *
- * \param all_filters the array of all supported filters.
- *
  * \sa filter::init
  */
-void filter_init(struct filter *all_filters)
+void filter_init(void)
 {
        int i;
 
        FOR_EACH_SUPPORTED_FILTER(i)
-               all_filters[i].init(all_filters + i);
+               filters[i].init(filters + i);
 }
 
 /**
@@ -102,13 +99,13 @@ static void call_callbacks(struct filter_node *fn, char *inbuf, size_t inlen,
  * there is input available for the filter node in question. If the convert
  * function consumed some or all of its input data, all registered input
  * callbacks are called.  Similarly, if a convert function produced output, all
- * registerd output callbacks get called.
+ * registered output callbacks get called.
  *
  * On errors a (negative) error code is stored in t->error.
  *
  * \sa filter_node, filter#convert, filter_callback.
  */
-void filter_pre_select(__a_unused struct sched *s, struct task *t)
+void filter_post_select(__a_unused struct sched *s, struct task *t)
 {
        struct filter_chain *fc = container_of(t, struct filter_chain, task);
        struct filter_node *fn;
@@ -121,15 +118,13 @@ void filter_pre_select(__a_unused struct sched *s, struct task *t)
                return;
        }
 again:
-       ib = fc->inbuf;
+       ib = *fc->inbufp;
        loaded = fc->in_loaded;
        conv = 0;
        FOR_EACH_FILTER_NODE(fn, fc, i) {
                struct filter *f = filters + fn->filter_num;
                if (fn->loaded < fn->bufsize) {
                        size_t size, old_fn_loaded = fn->loaded;
-//                     PARA_DEBUG_LOG("fc %p loaded: %zd, calling %s convert\n",
-//                             fc, *loaded, fn->filter->name);
                        t->error = f->convert(ib, *loaded, fn);
                        if (t->error < 0)
                                return;
@@ -137,25 +132,17 @@ again:
                        call_callbacks(fn, ib, size, fn->buf + old_fn_loaded,
                                fn->loaded - old_fn_loaded);
                        *loaded -= size;
-                       conv += size;
-                       if (*loaded && size) {
-//                             PARA_DEBUG_LOG("moving %zd bytes in input "
-//                                     "buffer for %s filter\n",
-//                                     *loaded,  fn->filter->name);
+                       conv += size + fn->loaded - old_fn_loaded;
+                       if (*loaded && size)
                                memmove(ib, ib + size, *loaded);
-                       }
                }
                ib = fn->buf;
                loaded = &fn->loaded;
        }
        conv_total += conv;
-//     PARA_DEBUG_LOG("eof (in/out/fc): %d/%d/%d out_loaded: %zd, "
-//             "conv: %d, conv_total: %d\n", *fc->input_eof,
-//             fc->output_eof? *fc->output_eof : -42,
-//             fc->eof, *fc->out_loaded, conv, conv_total);
        if (conv)
                goto again;
-       if (!*fc->input_error)
+       if (*fc->input_error >= 0)
                return;
        if (*fc->out_loaded)
                return;
@@ -263,3 +250,22 @@ int check_filter_arg(char *fa, void **conf)
        return -E_UNSUPPORTED_FILTER;
 }
 
+void print_filter_helps(int detailed)
+{
+       int i;
+
+       printf_or_die("\nAvailable filters: \n\t");
+       FOR_EACH_SUPPORTED_FILTER(i)
+               printf_or_die("%s%s", i? " " : "", filters[i].name);
+       printf_or_die("\n\n");
+
+       FOR_EACH_SUPPORTED_FILTER(i) {
+               struct filter *f = filters + i;
+
+               if (!f->help.short_help)
+                       continue;
+               printf_or_die("Options for %s:\n", f->name);
+               ggo_print_help(&f->help, detailed);
+       }
+
+}