MEDIUM: filters: Add attch/detach and stream_set_backend callbacks

New callbacks have been added to handle creation and destruction of filter
instances:

* 'attach' callback is called after a filter instance creation, when it is
  attached to a stream. This happens when the stream is started for filters
  defined on the stream's frontend and when the backend is set for filters
  declared on the stream's backend. It is possible to ignore the filter, if
  needed, by returning 0. This could be useful to have conditional filtering.

* 'detach' callback is called when a filter instance is detached from a stream,
  before its destruction. This happens when the stream is stopped for filters
  defined on the stream's frontend and when the analyze ends for filters defined
  on the stream's backend.

In addition, the callback 'stream_set_backend' has been added to know when a
backend is set for a stream. It is only called when the frontend and the backend
are not the same. And it is called for all filters attached to a stream
(frontend and backend).

Finally, the TRACE filter has been updated.
diff --git a/src/filters.c b/src/filters.c
index 7f8fae4..a1b36ba 100644
--- a/src/filters.c
+++ b/src/filters.c
@@ -304,11 +304,21 @@
 flt_stream_add_filter(struct stream *s, struct flt_conf *fconf, unsigned int flags)
 {
 	struct filter *f = pool_alloc2(pool2_filter);
+
 	if (!f) /* not enough memory */
 		return -1;
 	memset(f, 0, sizeof(*f));
 	f->config = fconf;
 	f->flags |= flags;
+
+	if (FLT_OPS(f)->attach) {
+		int ret = FLT_OPS(f)->attach(s, f);
+		if (ret <= 0) {
+			pool_free2(pool2_filter, f);
+			return ret;
+		}
+	}
+
 	LIST_ADDQ(&strm_flt(s)->filters, &f->list);
 	strm_flt(s)->flags |= STRM_FLT_FL_HAS_FILTERS;
 	return 0;
@@ -345,6 +355,8 @@
 
 	list_for_each_entry_safe(filter, back, &strm_flt(s)->filters, list) {
 		if (!only_backend || (filter->flags & FLT_FL_IS_BACKEND_FILTER)) {
+			if (FLT_OPS(filter)->detach)
+				FLT_OPS(filter)->detach(s, filter);
 			LIST_DEL(&filter->list);
 			pool_free2(pool2_filter, filter);
 		}
@@ -387,21 +399,30 @@
 
 /*
  * Called when a backend is set for a stream. If the frontend and the backend
- * are the same, this function does nothing. Else it attaches all backend
- * filters to the stream. Returns -1 if an error occurs, 0 otherwise.
+ * are not the same, this function attaches all backend filters to the
+ * stream. Returns -1 if an error occurs, 0 otherwise.
  */
 int
 flt_set_stream_backend(struct stream *s, struct proxy *be)
 {
 	struct flt_conf *fconf;
+	struct filter   *filter;
 
 	if (strm_fe(s) == be)
-		return 0;
+		goto end;
 
 	list_for_each_entry(fconf, &be->filter_configs, list) {
 		if (flt_stream_add_filter(s, fconf, FLT_FL_IS_BACKEND_FILTER) < 0)
 			return -1;
 	}
+
+  end:
+	list_for_each_entry(filter, &strm_flt(s)->filters, list) {
+		if (FLT_OPS(filter)->stream_set_backend &&
+		    FLT_OPS(filter)->stream_set_backend(s, filter, be) < 0)
+			return -1;
+	}
+
 	return 0;
 }