[CLEANUP] stream_interface: use inline functions to manipulate targets

The connection target involves a type and a union of pointers, let's
make the code cleaner using simple wrappers.
diff --git a/include/proto/stream_interface.h b/include/proto/stream_interface.h
index 0b90fcb..5c198dc 100644
--- a/include/proto/stream_interface.h
+++ b/include/proto/stream_interface.h
@@ -47,6 +47,47 @@
 					      struct task *(*fct)(struct task *));
 void stream_int_unregister_handler(struct stream_interface *si);
 
+static inline void clear_target(struct target *dest)
+{
+	dest->type = TARG_TYPE_NONE;
+	dest->ptr.v = NULL;
+}
+
+static inline void set_target_server(struct target *dest, struct server *s)
+{
+	dest->type = TARG_TYPE_SERVER;
+	dest->ptr.s = s;
+}
+
+static inline void set_target_proxy(struct target *dest, struct proxy *p)
+{
+	dest->type = TARG_TYPE_PROXY;
+	dest->ptr.p = p;
+}
+
+static inline void set_target_applet(struct target *dest, struct si_applet *a)
+{
+	dest->type = TARG_TYPE_APPLET;
+	dest->ptr.a = a;
+}
+
+static inline void set_target_task(struct target *dest, struct task *t)
+{
+	dest->type = TARG_TYPE_TASK;
+	dest->ptr.t = t;
+}
+
+static inline struct target *copy_target(struct target *dest, struct target *src)
+{
+	*dest = *src;
+	return dest;
+}
+
+static inline int target_match(struct target *a, struct target *b)
+{
+	return a->type == b->type && a->ptr.v == b->ptr.v;
+}
+
 #endif /* _PROTO_STREAM_INTERFACE_H */
 
 /*
diff --git a/src/backend.c b/src/backend.c
index 2d6e6ea..8367328 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -39,6 +39,7 @@
 #include <proto/queue.h>
 #include <proto/server.h>
 #include <proto/session.h>
+#include <proto/stream_interface.h>
 #include <proto/stream_sock.h>
 #include <proto/task.h>
 
@@ -493,8 +494,7 @@
 	 */
 
 	s->srv = NULL;
-	s->target.type = TARG_TYPE_NONE;
-	s->target.ptr.v = NULL;
+	clear_target(&s->target);
 
 	if (s->be->lbprm.algo & BE_LB_KIND) {
 		int len;
@@ -617,17 +617,14 @@
 			s->srv->counters.cum_lbconn++;
 		}
 
-		s->target.type = TARG_TYPE_SERVER;
-		s->target.ptr.s = s->srv;
+		set_target_server(&s->target, s->srv);
 	}
 	else if ((s->be->options2 & PR_O2_DISPATCH) || (s->be->options & PR_O_TRANSP)) {
-		s->target.type = TARG_TYPE_PROXY;
-		s->target.ptr.p = s->be;
+		set_target_proxy(&s->target, s->be);
 	}
 	else if ((s->be->options & PR_O_HTTP_PROXY) && s->req->cons->addr.s.to.sin_addr.s_addr) {
 		/* in proxy mode, we need a valid destination address */
-		s->target.type = TARG_TYPE_PROXY;
-		s->target.ptr.p = s->be;
+		set_target_proxy(&s->target, s->be);
 	}
 	else {
 		err = SRV_STATUS_NOSRV;
@@ -951,7 +948,7 @@
 	 */
 	stream_sock_prepare_interface(s->req->cons);
 	s->req->cons->connect = tcpv4_connect_server;
-	s->req->cons->target = s->target;
+	copy_target(&s->req->cons->target, &s->target);
 
 	assign_tproxy_address(s);
 
@@ -1107,16 +1104,14 @@
 	if (*p != '.')
 		goto no_cookie;
 
-	s->target.type = TARG_TYPE_NONE;
-	s->target.ptr.v = NULL;
+	clear_target(&s->target);
 	while (srv) {
 		if (memcmp(&addr, &(srv->addr), sizeof(addr)) == 0) {
 			if ((srv->state & SRV_RUNNING) || (px->options & PR_O_PERSIST)) {
 				/* we found the server and it is usable */
 				s->flags |= SN_DIRECT | SN_ASSIGNED;
 				s->srv = srv;
-				s->target.type = TARG_TYPE_SERVER;
-				s->target.ptr.s = s->srv;
+				set_target_server(&s->target, srv);
 				break;
 			}
 		}
diff --git a/src/checks.c b/src/checks.c
index 628f3e5..521de1d 100644
--- a/src/checks.c
+++ b/src/checks.c
@@ -45,6 +45,7 @@
 #include <proto/proto_tcp.h>
 #include <proto/proxy.h>
 #include <proto/server.h>
+#include <proto/stream_interface.h>
 #include <proto/task.h>
 
 static int httpchk_expect(struct server *s, int done);
@@ -349,8 +350,7 @@
 		if (!p)
 			break;
 		p->sess->srv = s;
-		p->sess->target.ptr.s = s;
-		p->sess->target.type = TARG_TYPE_SERVER;
+		set_target_server(&p->sess->target, s);
 		sess = p->sess;
 		pendconn_free(p);
 		task_wakeup(sess->task, TASK_WOKEN_RES);
diff --git a/src/peers.c b/src/peers.c
index 06ad244..3e07a27 100644
--- a/src/peers.c
+++ b/src/peers.c
@@ -1157,8 +1157,7 @@
 	s->si[0].err_type = SI_ET_NONE;
 	s->si[0].err_loc = NULL;
 	s->si[0].connect   = NULL;
-	s->si[0].target.ptr.v = NULL;
-	s->si[0].target.type = TARG_TYPE_NONE;
+	clear_target(&s->si[0].target);
 	s->si[0].exp = TICK_ETERNITY;
 	s->si[0].flags = SI_FL_NONE;
 	if (s->fe->options2 & PR_O2_INDEPSTR)
@@ -1176,8 +1175,7 @@
 	s->si[1].err_type = SI_ET_NONE;
 	s->si[1].err_loc = NULL;
 	s->si[1].connect = tcpv4_connect_server;
-	s->si[1].target.ptr.p = s->be;
-	s->si[1].target.type = TARG_TYPE_PROXY;
+	set_target_proxy(&s->si[1].target, s->be);
 	s->si[1].exp = TICK_ETERNITY;
 	s->si[1].flags = SI_FL_NONE;
 	if (s->be->options2 & PR_O2_INDEPSTR)
@@ -1187,8 +1185,7 @@
 	s->si[1].release = NULL;
 
 	s->srv = s->srv_conn = NULL;
-	s->target.type = TARG_TYPE_NONE;
-	s->target.ptr.v = NULL;
+	clear_target(&s->target);
 	s->pend_pos = NULL;
 
 	/* init store persistence */
diff --git a/src/proto_http.c b/src/proto_http.c
index 72f0a41..5275f2f 100644
--- a/src/proto_http.c
+++ b/src/proto_http.c
@@ -3949,8 +3949,7 @@
 	if (unlikely(s->srv_conn))
 		sess_change_server(s, NULL);
 	s->srv = NULL;
-	s->target.type = TARG_TYPE_NONE;
-	s->target.ptr.v = NULL;
+	clear_target(&s->target);
 
 	s->req->cons->state     = s->req->cons->prev_state = SI_ST_INI;
 	s->req->cons->fd        = -1; /* just to help with debugging */
@@ -5964,8 +5963,7 @@
 						txn->flags |= (srv->state & SRV_RUNNING) ? TX_CK_VALID : TX_CK_DOWN;
 						t->flags |= SN_DIRECT | SN_ASSIGNED;
 						t->srv = srv;
-						t->target.type = TARG_TYPE_SERVER;
-						t->target.ptr.s = srv;
+						set_target_server(&t->target, srv);
 
 						break;
 					} else {
@@ -6376,8 +6374,7 @@
 							txn->flags |= (srv->state & SRV_RUNNING) ? TX_CK_VALID : TX_CK_DOWN;
 							t->flags |= SN_DIRECT | SN_ASSIGNED;
 							t->srv = srv;
-							t->target.type = TARG_TYPE_SERVER;
-							t->target.ptr.s = srv;
+							set_target_server(&t->target, srv);
 							break;
 						} else {
 							/* we found a server, but it's down,
@@ -7542,8 +7539,7 @@
 	s->be = s->fe;
 	s->logs.logwait = s->fe->to_log;
 	s->srv = s->srv_conn = NULL;
-	s->target.type = TARG_TYPE_NONE;
-	s->target.ptr.v = NULL;
+	clear_target(&s->target);
 	/* re-init store persistence */
 	s->store_count = 0;
 
diff --git a/src/queue.c b/src/queue.c
index c66aa6b..4994181 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -16,6 +16,7 @@
 
 #include <proto/queue.h>
 #include <proto/server.h>
+#include <proto/stream_interface.h>
 #include <proto/task.h>
 
 
@@ -122,8 +123,7 @@
 
 	/* we want to note that the session has now been assigned a server */
 	sess->flags |= SN_ASSIGNED;
-	sess->target.type = TARG_TYPE_SERVER;
-	sess->target.ptr.s = srv;
+	set_target_server(&sess->target, srv);
 	sess->srv = srv;
 	sess->srv_conn = srv;
 	srv->served++;
diff --git a/src/session.c b/src/session.c
index b8ae690..864b788 100644
--- a/src/session.c
+++ b/src/session.c
@@ -168,8 +168,7 @@
 	s->si[0].err_loc   = NULL;
 	s->si[0].connect   = NULL;
 	s->si[0].release   = NULL;
-	s->si[0].target.type  = TARG_TYPE_NONE;
-	s->si[0].target.ptr.v = NULL;
+	clear_target(&s->si[0].target);
 	s->si[0].exp       = TICK_ETERNITY;
 	s->si[0].flags     = SI_FL_NONE;
 
@@ -192,8 +191,7 @@
 	s->si[1].err_loc   = NULL;
 	s->si[1].connect   = NULL;
 	s->si[1].release   = NULL;
-	s->si[1].target.type  = TARG_TYPE_NONE;
-	s->si[1].target.ptr.v = NULL;
+	clear_target(&s->si[1].target);
 	s->si[1].shutr     = stream_int_shutr;
 	s->si[1].shutw     = stream_int_shutw;
 	s->si[1].exp       = TICK_ETERNITY;
@@ -203,8 +201,7 @@
 		s->si[1].flags |= SI_FL_INDEP_STR;
 
 	s->srv = s->srv_conn = NULL;
-	s->target.type = TARG_TYPE_NONE;
-	s->target.ptr.v = NULL;
+	clear_target(&s->target);
 	s->pend_pos = NULL;
 
 	/* init store persistence */
@@ -1067,8 +1064,7 @@
 							    (s->flags & SN_FORCE_PRST)) {
 								s->flags |= SN_DIRECT | SN_ASSIGNED;
 								s->srv = srv;
-								s->target.type = TARG_TYPE_SERVER;
-								s->target.ptr.s = srv;
+								set_target_server(&s->target, srv);
 							}
 						}
 					}
diff --git a/src/stream_interface.c b/src/stream_interface.c
index d462308..d4bf1b8 100644
--- a/src/stream_interface.c
+++ b/src/stream_interface.c
@@ -314,8 +314,7 @@
 	si->chk_rcv = stream_int_chk_rcv;
 	si->chk_snd = stream_int_chk_snd;
 	si->connect = NULL;
-	si->target.type = TARG_TYPE_APPLET;
-	si->target.ptr.a = app;
+	set_target_applet(&si->target, app);
 	si->applet.state = 0;
 	si->release   = NULL;
 	si->flags |= SI_FL_WAIT_DATA;
@@ -342,8 +341,7 @@
 	si->chk_rcv = stream_int_chk_rcv;
 	si->chk_snd = stream_int_chk_snd;
 	si->connect = NULL;
-	si->target.type = TARG_TYPE_NONE;
-	si->target.ptr.v   = NULL;
+	clear_target(&si->target);
 	si->release   = NULL;
 	si->flags |= SI_FL_WAIT_DATA;
 
@@ -352,8 +350,7 @@
 	if (!t)
 		return t;
 
-	si->target.type = TARG_TYPE_TASK;
-	si->target.ptr.t = t;
+	set_target_task(&si->target, t);
 
 	t->process = fct;
 	t->context = si;
@@ -375,8 +372,7 @@
 	}
 	si->release   = NULL;
 	si->owner = NULL;
-	si->target.type = TARG_TYPE_NONE;
-	si->target.ptr.v = NULL;
+	clear_target(&si->target);
 }
 
 /*