[MINOR] stream_interface: make use of an applet descriptor for IO handlers

I/O handlers are still delicate to manipulate. They have no type, they're
just raw functions which have no knowledge of themselves. Let's have them
declared as applets once for all. That way we can have multiple applets
share the same handler functions and we can store their names there. When
we later need to add more parameters (eg: usage stats), we'll be able to
do so in the applets themselves.

The CLI functions has been prefixed with "cli" instead of "stats" as it's
clearly what is going on there.

The applet descriptor in the stream interface should get all the applet
specific data (st0, ...) but this will be done in the next patch so that
we don't pollute this one too much.
diff --git a/include/proto/dumpstats.h b/include/proto/dumpstats.h
index 9cf5eec..e33fe94 100644
--- a/include/proto/dumpstats.h
+++ b/include/proto/dumpstats.h
@@ -3,7 +3,7 @@
  * This file contains definitions of some primitives to dedicated to
  * statistics output.
  *
- * Copyright (C) 2000-2010 Willy Tarreau - w@1wt.eu
+ * Copyright (C) 2000-2011 Willy Tarreau - w@1wt.eu
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -61,6 +61,8 @@
 #define STAT_STATUS_EXCD "EXCD"	/* an error occured becayse the buffer couldn't store all data */
 #define STAT_STATUS_DENY "DENY"	/* action denied */
 
+extern struct si_applet http_stats_applet;
+extern struct si_applet cli_applet;
 
 int stats_accept(struct session *s);
 int stats_sock_parse_request(struct stream_interface *si, char *line);
@@ -71,7 +73,6 @@
 int stats_dump_sess_to_buffer(struct session *s, struct buffer *rep);
 int stats_dump_table_to_buffer(struct session *s, struct buffer *rep);
 int stats_dump_errors_to_buffer(struct session *s, struct buffer *rep);
-void http_stats_io_handler(struct stream_interface *si);
 
 
 #endif /* _PROTO_DUMPSTATS_H */
diff --git a/include/proto/stream_interface.h b/include/proto/stream_interface.h
index 4e7f734..0b90fcb 100644
--- a/include/proto/stream_interface.h
+++ b/include/proto/stream_interface.h
@@ -2,7 +2,7 @@
  * include/proto/stream_interface.h
  * This file contains stream_interface function prototypes
  *
- * Copyright (C) 2000-2009 Willy Tarreau - w@1wt.eu
+ * Copyright (C) 2000-2011 Willy Tarreau - w@1wt.eu
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -42,7 +42,7 @@
 void stream_int_chk_snd(struct stream_interface *si);
 
 struct task *stream_int_register_handler(struct stream_interface *si,
-					 void (*fct)(struct stream_interface *));
+					 struct si_applet *app);
 struct task *stream_int_register_handler_task(struct stream_interface *si,
 					      struct task *(*fct)(struct task *));
 void stream_int_unregister_handler(struct stream_interface *si);
diff --git a/include/types/stream_interface.h b/include/types/stream_interface.h
index cfba687..6af0f63 100644
--- a/include/types/stream_interface.h
+++ b/include/types/stream_interface.h
@@ -2,7 +2,7 @@
  * include/types/stream_interface.h
  * This file describes the stream_interface struct and associated constants.
  *
- * Copyright (C) 2000-2010 Willy Tarreau - w@1wt.eu
+ * Copyright (C) 2000-2011 Willy Tarreau - w@1wt.eu
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -78,13 +78,11 @@
 
 struct server;
 struct proxy;
+struct si_applet;
 
-/* Note that if an iohandler is set, the update function will not be called by
- * the session handler, so it may be used to resync flags at the end of the I/O
- * handler. See stream_int_update_embedded() for reference.
- * This struct could be optimized, because :
- *   - connect(), fd, conn_retries are only used in stream_sock mode
- *   - iohandler(), private, st0, st1 are only used in iohandler mode
+/* Note that if an applet is registered, the update function will not be called
+ * by the session handler, so it may be used to resync flags at the end of the
+ * applet handler. See stream_int_update_embedded() for reference.
  */
 struct stream_interface {
 	unsigned int state;     /* SI_ST* */
@@ -101,15 +99,22 @@
 	int (*connect)(struct stream_interface *, struct proxy *, struct server *,
 		       struct sockaddr *, struct sockaddr *); /* connect function if any */
 	void (*release)(struct stream_interface *); /* handler to call after the last close() */
-	void (*iohandler)(struct stream_interface *);  /* internal I/O handler when embedded */
 	struct buffer *ib, *ob; /* input and output buffers */
 	int conn_retries;	/* number of connect retries left */
 	unsigned int err_type;  /* first error detected, one of SI_ET_* */
 	void *err_loc;          /* commonly the server, NULL when SI_ET_NONE */
+	struct {
+		struct si_applet *handler; /* applet to use instead of doing I/O */
+	} applet;
 	void *private;          /* may be used by any function above */
 	unsigned int st0, st1;  /* may be used by any function above */
 };
 
+/* An applet designed to run in a stream interface */
+struct si_applet {
+	char *name; /* applet's name to report in logs */
+	void (*fct)(struct stream_interface *);  /* internal I/O handler, may never be NULL */
+};
 
 #endif /* _TYPES_STREAM_INTERFACE_H */