CLEANUP: proxy: make the proxy lookup functions more user-friendly

First, findproxy() was renamed proxy_find_by_name() so that its explicit
that a name is required for the lookup. Second, we give this function
the ability to search for tables if needed. Third we now provide inline
wrappers to pass the appropriate PR_CAP_* flags and to explicitly look
up a frontend, backend or table.
diff --git a/src/cfgparse.c b/src/cfgparse.c
index d4fac8c..84420d1 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -7080,7 +7080,7 @@
 				curproxy->be_rsp_ana |= AN_RES_STORE_RULES;
 
 			if (mrule->table.name)
-				target = findproxy(mrule->table.name, 0);
+				target = proxy_tbl_by_name(mrule->table.name);
 			else
 				target = curproxy;
 
@@ -7113,7 +7113,7 @@
 			curproxy->be_rsp_ana |= AN_RES_STORE_RULES;
 
 			if (mrule->table.name)
-				target = findproxy(mrule->table.name, 0);
+				target = proxy_tbl_by_name(mrule->table.name);
 			else
 				target = curproxy;
 
@@ -7147,7 +7147,7 @@
 				continue;
 
 			if (trule->act_prm.trk_ctr.table.n)
-				target = findproxy(trule->act_prm.trk_ctr.table.n, 0);
+				target = proxy_tbl_by_name(trule->act_prm.trk_ctr.table.n);
 			else
 				target = curproxy;
 
@@ -7186,7 +7186,7 @@
 				continue;
 
 			if (trule->act_prm.trk_ctr.table.n)
-				target = findproxy(trule->act_prm.trk_ctr.table.n, 0);
+				target = proxy_tbl_by_name(trule->act_prm.trk_ctr.table.n);
 			else
 				target = curproxy;
 
@@ -7225,7 +7225,7 @@
 				continue;
 
 			if (hrqrule->act_prm.trk_ctr.table.n)
-				target = findproxy(hrqrule->act_prm.trk_ctr.table.n, 0);
+				target = proxy_tbl_by_name(hrqrule->act_prm.trk_ctr.table.n);
 			else
 				target = curproxy;
 
@@ -7579,7 +7579,7 @@
 				}
 
 				if (pname) {
-					px = findproxy(pname, PR_CAP_BE);
+					px = proxy_be_by_name(pname);
 					if (!px) {
 						Alert("config : %s '%s', server '%s': unable to find required proxy '%s' for tracking.\n",
 							proxy_type_str(curproxy), curproxy->id,
diff --git a/src/dumpstats.c b/src/dumpstats.c
index 885a159..559f229 100644
--- a/src/dumpstats.c
+++ b/src/dumpstats.c
@@ -924,7 +924,7 @@
 		return NULL;
 	}
 
-	px = findproxy(arg, PR_CAP_FE);
+	px = proxy_fe_by_name(arg);
 	if (!px) {
 		appctx->ctx.cli.msg = "No such frontend.\n";
 		appctx->st0 = STAT_CLI_PRINT;
@@ -4622,7 +4622,7 @@
 
 			/* Now we can check the key to see what to do */
 			if (!px && (strcmp(key, "b") == 0)) {
-				if ((px = findproxy(value, PR_CAP_BE)) == NULL) {
+				if ((px = proxy_be_by_name(value)) == NULL) {
 					/* the backend name is unknown or ambiguous (duplicate names) */
 					appctx->ctx.stats.st_code = STAT_STATUS_ERRP;
 					goto out;
diff --git a/src/hlua.c b/src/hlua.c
index a937e4f..5e1bdc3 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -632,7 +632,7 @@
 				WILL_LJMP(luaL_argerror(L, first + idx, "string expected"));
 			memcpy(trash.str, argp[idx].data.str.str, argp[idx].data.str.len);
 			trash.str[argp[idx].data.str.len] = 0;
-			argp[idx].data.prx = findproxy(trash.str, PR_CAP_FE);
+			argp[idx].data.prx = proxy_fe_by_name(trash.str);
 			if (!argp[idx].data.prx)
 				WILL_LJMP(luaL_argerror(L, first + idx, "frontend doesn't exist"));
 			argp[idx].type = ARGT_FE;
@@ -643,7 +643,7 @@
 				WILL_LJMP(luaL_argerror(L, first + idx, "string expected"));
 			memcpy(trash.str, argp[idx].data.str.str, argp[idx].data.str.len);
 			trash.str[argp[idx].data.str.len] = 0;
-			argp[idx].data.prx = findproxy(trash.str, PR_CAP_BE);
+			argp[idx].data.prx = proxy_be_by_name(trash.str);
 			if (!argp[idx].data.prx)
 				WILL_LJMP(luaL_argerror(L, first + idx, "backend doesn't exist"));
 			argp[idx].type = ARGT_BE;
@@ -669,7 +669,7 @@
 			if (sname) {
 				*sname++ = '\0';
 				pname = trash.str;
-				px = findproxy(pname, PR_CAP_BE);
+				px = proxy_be_by_name(pname);
 				if (!px)
 					WILL_LJMP(luaL_argerror(L, first + idx, "backend doesn't exist"));
 			}
diff --git a/src/proxy.c b/src/proxy.c
index ed3b582..56af782 100644
--- a/src/proxy.c
+++ b/src/proxy.c
@@ -106,7 +106,7 @@
 	if (*sv_name == '#')
 		sid = atoi(sv_name + 1);
 
-	p = findproxy(bk_name, PR_CAP_BE);
+	p = proxy_be_by_name(bk_name);
 	if (bk)
 		*bk = p;
 	if (!p)
@@ -390,10 +390,11 @@
 
 /* Returns a pointer to the proxy matching either name <name>, or id <name> if
  * <name> begins with a '#'. NULL is returned if no match is found, as well as
- * if multiple matches are found (eg: too large capabilities mask).
+ * if multiple matches are found (eg: too large capabilities mask). If <table>
+ * is non-zero, it only considers proxies having a table.
  */
-struct proxy *findproxy(const char *name, int cap) {
-
+struct proxy *proxy_find_by_name(const char *name, int cap, int table)
+{
 	struct proxy *curproxy, *target = NULL;
 	int pid = -1;
 
@@ -411,6 +412,9 @@
 			if ((curproxy->cap & cap) != cap)
 				continue;
 
+			if (table && !curproxy->table.size)
+				continue;
+
 			if (target)
 				return NULL;
 
@@ -429,6 +433,9 @@
 			if ((curproxy->cap & cap) != cap)
 				continue;
 
+			if (table && !curproxy->table.size)
+				continue;
+
 			if (target)
 				return NULL;
 
diff --git a/src/sample.c b/src/sample.c
index 03540e1..3ad2d20 100644
--- a/src/sample.c
+++ b/src/sample.c
@@ -1128,7 +1128,7 @@
 				*sname++ = '\0';
 				pname = arg->data.str.str;
 
-				px = findproxy(pname, PR_CAP_BE);
+				px = proxy_be_by_name(pname);
 				if (!px) {
 					Alert("parsing [%s:%d] : unable to find proxy '%s' referenced in arg %d of %s%s%s%s '%s' %s proxy '%s'.\n",
 					      cur->file, cur->line, pname,
@@ -1158,7 +1158,7 @@
 		case ARGT_FE:
 			if (arg->data.str.len) {
 				pname = arg->data.str.str;
-				px = findproxy(pname, PR_CAP_FE);
+				px = proxy_fe_by_name(pname);
 			}
 
 			if (!px) {
@@ -1186,7 +1186,7 @@
 		case ARGT_BE:
 			if (arg->data.str.len) {
 				pname = arg->data.str.str;
-				px = findproxy(pname, PR_CAP_BE);
+				px = proxy_be_by_name(pname);
 			}
 
 			if (!px) {
diff --git a/src/stream.c b/src/stream.c
index 4d62c71..0f9fbe2 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -1053,7 +1053,7 @@
 					struct chunk *tmp = get_trash_chunk();
 					if (!build_logline(s, tmp->str, tmp->size, &rule->be.expr))
 						break;
-					backend = findproxy(tmp->str, PR_CAP_BE);
+					backend = proxy_be_by_name(tmp->str);
 					if (!backend)
 						break;
 				}