[MINOR] checks: add PostgreSQL health check

I have written a small patch to enable a correct PostgreSQL health check
It works similar to mysql-check with the very same parameters.

E.g.:
listen pgsql 127.0.0.1:5432
   mode tcp
   option pgsql-check user pgsql
   server masterdb pgsql.server.com:5432 check inter 10000
diff --git a/src/cfgparse.c b/src/cfgparse.c
index 28eb1ca..dd266af 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -3312,6 +3312,7 @@
 			curproxy->options &= ~PR_O_SMTP_CHK;
 			curproxy->options2 &= ~PR_O2_SSL3_CHK;
 			curproxy->options2 &= ~PR_O2_MYSQL_CHK;
+			curproxy->options2 &= ~PR_O2_PGSQL_CHK;
 			curproxy->options2 &= ~PR_O2_LDAP_CHK;
 			curproxy->options |= PR_O_HTTP_CHK;
 			if (!*args[2]) { /* no argument */
@@ -3344,6 +3345,7 @@
 			curproxy->options &= ~PR_O_HTTP_CHK;
 			curproxy->options &= ~PR_O_SMTP_CHK;
 			curproxy->options2 &= ~PR_O2_MYSQL_CHK;
+			curproxy->options2 &= ~PR_O2_PGSQL_CHK;
 			curproxy->options2 &= ~PR_O2_LDAP_CHK;
 			curproxy->options2 |= PR_O2_SSL3_CHK;
 		}
@@ -3354,6 +3356,7 @@
 			curproxy->options &= ~PR_O_HTTP_CHK;
 			curproxy->options2 &= ~PR_O2_SSL3_CHK;
 			curproxy->options2 &= ~PR_O2_MYSQL_CHK;
+			curproxy->options2 &= ~PR_O2_PGSQL_CHK;
 			curproxy->options2 &= ~PR_O2_LDAP_CHK;
 			curproxy->options |= PR_O_SMTP_CHK;
 
@@ -3374,6 +3377,69 @@
 				}
 			}
 		}
+		else if (!strcmp(args[1], "pgsql-check")) {
+			/* use PostgreSQL request to check servers' health */
+			if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
+				err_code |= ERR_WARN;
+
+			free(curproxy->check_req);
+			curproxy->check_req = NULL;
+			curproxy->options &= ~PR_O_HTTP_CHK;
+			curproxy->options &= ~PR_O_SMTP_CHK;
+			curproxy->options2 &= ~PR_O2_SSL3_CHK;
+			curproxy->options2 &= ~PR_O2_LDAP_CHK;
+			curproxy->options2 &= ~PR_O2_MYSQL_CHK;
+			curproxy->options2 |= PR_O2_PGSQL_CHK;
+
+			if (*(args[2])) {
+				int cur_arg = 2;
+
+				while (*(args[cur_arg])) {
+					if (strcmp(args[cur_arg], "user") == 0) {
+						char * packet;
+						uint32_t packet_len;
+						uint32_t pv;
+
+						/* suboption header - needs additional argument for it */
+						if (*(args[cur_arg+1]) == 0) {
+							Alert("parsing [%s:%d] : '%s %s %s' expects <username> as argument.\n",
+							      file, linenum, args[0], args[1], args[cur_arg]);
+							err_code |= ERR_ALERT | ERR_FATAL;
+							goto out;
+						}
+
+						/* uint32_t + uint32_t + strlen("user")+1 + strlen(username)+1 + 1 */
+						packet_len = 4 + 4 + 5 + strlen(args[cur_arg + 1])+1 +1;
+						pv = htonl(0x30000); /* protocol version 3.0 */
+
+						packet = (char*) calloc(1, packet_len);
+
+						memcpy(packet + 4, &pv, 4);
+
+						/* copy "user" */
+						memcpy(packet + 8, "user", 4);
+
+						/* copy username */
+						memcpy(packet + 13, args[cur_arg+1], strlen(args[cur_arg+1]));
+
+						free(curproxy->check_req);
+						curproxy->check_req = packet;
+						curproxy->check_len = packet_len;
+
+						packet_len = htonl(packet_len);
+						memcpy(packet, &packet_len, 4);
+						cur_arg += 2;
+					} else {
+						/* unknown suboption - catchall */
+						Alert("parsing [%s:%d] : '%s %s' only supports optional values: 'user'.\n",
+						      file, linenum, args[0], args[1]);
+						err_code |= ERR_ALERT | ERR_FATAL;
+						goto out;
+					}
+				} /* end while loop */
+			}
+		}
+
 		else if (!strcmp(args[1], "mysql-check")) {
 			/* use MYSQL request to check servers' health */
 			if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[1], NULL))
@@ -3385,6 +3451,7 @@
 			curproxy->options &= ~PR_O_SMTP_CHK;
 			curproxy->options2 &= ~PR_O2_SSL3_CHK;
 			curproxy->options2 &= ~PR_O2_LDAP_CHK;
+			curproxy->options2 &= ~PR_O2_PGSQL_CHK;
 			curproxy->options2 |= PR_O2_MYSQL_CHK;
 
 			/* This is an exemple of an MySQL >=4.0 client Authentication packet kindly provided by Cyril Bonte.
@@ -3454,6 +3521,7 @@
 			curproxy->options &= ~PR_O_SMTP_CHK;
 			curproxy->options2 &= ~PR_O2_SSL3_CHK;
 			curproxy->options2 &= ~PR_O2_MYSQL_CHK;
+			curproxy->options2 &= ~PR_O2_PGSQL_CHK;
 			curproxy->options2 |= PR_O2_LDAP_CHK;
 
 			curproxy->check_req = (char *) malloc(sizeof(DEF_LDAP_CHECK_REQ) - 1);