Accept postgres:// URIs in libpq connection functions
postgres:// URIs are an attempt to "stop the bleeding" in this general
area that has been said to occur due to external projects adopting their
own syntaxes. The syntaxes supported by this patch:
postgres://[user[:pwd]@][unix-socket][:port[/dbname]][?param1=value1&...]
postgres://[user[:pwd]@][net-location][:port][/dbname][?param1=value1&...]
should be enough to cover most interesting cases without having to
resort to "param=value" pairs, but those are provided for the cases that
need them regardless.
libpq documentation has been shuffled around a bit, to avoid stuffing
all the format details into the PQconnectdbParams description, which was
already a bit overwhelming. The list of keywords has moved to its own
subsection, and the details on the URI format live in another subsection.
This includes a simple test program, as requested in discussion, to
ensure that interesting corner cases continue to work appropriately in
the future.
Author: Alexander Shulgin
Some tweaking by Álvaro Herrera, Greg Smith, Daniel Farina, Peter Eisentraut
Reviewed by Robert Haas, Alexey Klyukin (offlist), Heikki Linnakangas,
Marko Kreen, and others
Oh, it also supports postgresql:// but that's probably just an accident.
2012-04-11 08:59:32 +02:00
|
|
|
/*
|
2022-05-04 14:15:25 +02:00
|
|
|
* libpq_uri_regress.c
|
Accept postgres:// URIs in libpq connection functions
postgres:// URIs are an attempt to "stop the bleeding" in this general
area that has been said to occur due to external projects adopting their
own syntaxes. The syntaxes supported by this patch:
postgres://[user[:pwd]@][unix-socket][:port[/dbname]][?param1=value1&...]
postgres://[user[:pwd]@][net-location][:port][/dbname][?param1=value1&...]
should be enough to cover most interesting cases without having to
resort to "param=value" pairs, but those are provided for the cases that
need them regardless.
libpq documentation has been shuffled around a bit, to avoid stuffing
all the format details into the PQconnectdbParams description, which was
already a bit overwhelming. The list of keywords has moved to its own
subsection, and the details on the URI format live in another subsection.
This includes a simple test program, as requested in discussion, to
ensure that interesting corner cases continue to work appropriately in
the future.
Author: Alexander Shulgin
Some tweaking by Álvaro Herrera, Greg Smith, Daniel Farina, Peter Eisentraut
Reviewed by Robert Haas, Alexey Klyukin (offlist), Heikki Linnakangas,
Marko Kreen, and others
Oh, it also supports postgresql:// but that's probably just an accident.
2012-04-11 08:59:32 +02:00
|
|
|
* A test program for libpq URI format
|
|
|
|
*
|
|
|
|
* This is a helper for libpq conninfo regression testing. It takes a single
|
|
|
|
* conninfo string as a parameter, parses it using PQconninfoParse, and then
|
|
|
|
* prints out the values from the parsed PQconninfoOption struct that differ
|
|
|
|
* from the defaults (obtained from PQconndefaults).
|
|
|
|
*
|
2024-01-04 02:49:05 +01:00
|
|
|
* Portions Copyright (c) 2012-2024, PostgreSQL Global Development Group
|
Accept postgres:// URIs in libpq connection functions
postgres:// URIs are an attempt to "stop the bleeding" in this general
area that has been said to occur due to external projects adopting their
own syntaxes. The syntaxes supported by this patch:
postgres://[user[:pwd]@][unix-socket][:port[/dbname]][?param1=value1&...]
postgres://[user[:pwd]@][net-location][:port][/dbname][?param1=value1&...]
should be enough to cover most interesting cases without having to
resort to "param=value" pairs, but those are provided for the cases that
need them regardless.
libpq documentation has been shuffled around a bit, to avoid stuffing
all the format details into the PQconnectdbParams description, which was
already a bit overwhelming. The list of keywords has moved to its own
subsection, and the details on the URI format live in another subsection.
This includes a simple test program, as requested in discussion, to
ensure that interesting corner cases continue to work appropriately in
the future.
Author: Alexander Shulgin
Some tweaking by Álvaro Herrera, Greg Smith, Daniel Farina, Peter Eisentraut
Reviewed by Robert Haas, Alexey Klyukin (offlist), Heikki Linnakangas,
Marko Kreen, and others
Oh, it also supports postgresql:// but that's probably just an accident.
2012-04-11 08:59:32 +02:00
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2022-05-04 14:15:25 +02:00
|
|
|
* src/interfaces/libpq/test/libpq_uri_regress.c
|
Accept postgres:// URIs in libpq connection functions
postgres:// URIs are an attempt to "stop the bleeding" in this general
area that has been said to occur due to external projects adopting their
own syntaxes. The syntaxes supported by this patch:
postgres://[user[:pwd]@][unix-socket][:port[/dbname]][?param1=value1&...]
postgres://[user[:pwd]@][net-location][:port][/dbname][?param1=value1&...]
should be enough to cover most interesting cases without having to
resort to "param=value" pairs, but those are provided for the cases that
need them regardless.
libpq documentation has been shuffled around a bit, to avoid stuffing
all the format details into the PQconnectdbParams description, which was
already a bit overwhelming. The list of keywords has moved to its own
subsection, and the details on the URI format live in another subsection.
This includes a simple test program, as requested in discussion, to
ensure that interesting corner cases continue to work appropriately in
the future.
Author: Alexander Shulgin
Some tweaking by Álvaro Herrera, Greg Smith, Daniel Farina, Peter Eisentraut
Reviewed by Robert Haas, Alexey Klyukin (offlist), Heikki Linnakangas,
Marko Kreen, and others
Oh, it also supports postgresql:// but that's probably just an accident.
2012-04-11 08:59:32 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "postgres_fe.h"
|
|
|
|
|
|
|
|
#include "libpq-fe.h"
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
PQconninfoOption *opts;
|
|
|
|
PQconninfoOption *defs;
|
|
|
|
PQconninfoOption *opt;
|
|
|
|
PQconninfoOption *def;
|
|
|
|
char *errmsg = NULL;
|
|
|
|
bool local = true;
|
|
|
|
|
|
|
|
if (argc != 2)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
opts = PQconninfoParse(argv[1], &errmsg);
|
|
|
|
if (opts == NULL)
|
|
|
|
{
|
2022-05-04 14:15:25 +02:00
|
|
|
fprintf(stderr, "libpq_uri_regress: %s", errmsg);
|
Accept postgres:// URIs in libpq connection functions
postgres:// URIs are an attempt to "stop the bleeding" in this general
area that has been said to occur due to external projects adopting their
own syntaxes. The syntaxes supported by this patch:
postgres://[user[:pwd]@][unix-socket][:port[/dbname]][?param1=value1&...]
postgres://[user[:pwd]@][net-location][:port][/dbname][?param1=value1&...]
should be enough to cover most interesting cases without having to
resort to "param=value" pairs, but those are provided for the cases that
need them regardless.
libpq documentation has been shuffled around a bit, to avoid stuffing
all the format details into the PQconnectdbParams description, which was
already a bit overwhelming. The list of keywords has moved to its own
subsection, and the details on the URI format live in another subsection.
This includes a simple test program, as requested in discussion, to
ensure that interesting corner cases continue to work appropriately in
the future.
Author: Alexander Shulgin
Some tweaking by Álvaro Herrera, Greg Smith, Daniel Farina, Peter Eisentraut
Reviewed by Robert Haas, Alexey Klyukin (offlist), Heikki Linnakangas,
Marko Kreen, and others
Oh, it also supports postgresql:// but that's probably just an accident.
2012-04-11 08:59:32 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
defs = PQconndefaults();
|
|
|
|
if (defs == NULL)
|
|
|
|
{
|
2022-05-04 14:15:25 +02:00
|
|
|
fprintf(stderr, "libpq_uri_regress: cannot fetch default options\n");
|
Accept postgres:// URIs in libpq connection functions
postgres:// URIs are an attempt to "stop the bleeding" in this general
area that has been said to occur due to external projects adopting their
own syntaxes. The syntaxes supported by this patch:
postgres://[user[:pwd]@][unix-socket][:port[/dbname]][?param1=value1&...]
postgres://[user[:pwd]@][net-location][:port][/dbname][?param1=value1&...]
should be enough to cover most interesting cases without having to
resort to "param=value" pairs, but those are provided for the cases that
need them regardless.
libpq documentation has been shuffled around a bit, to avoid stuffing
all the format details into the PQconnectdbParams description, which was
already a bit overwhelming. The list of keywords has moved to its own
subsection, and the details on the URI format live in another subsection.
This includes a simple test program, as requested in discussion, to
ensure that interesting corner cases continue to work appropriately in
the future.
Author: Alexander Shulgin
Some tweaking by Álvaro Herrera, Greg Smith, Daniel Farina, Peter Eisentraut
Reviewed by Robert Haas, Alexey Klyukin (offlist), Heikki Linnakangas,
Marko Kreen, and others
Oh, it also supports postgresql:// but that's probably just an accident.
2012-04-11 08:59:32 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Loop on the options, and print the value of each if not the default.
|
|
|
|
*
|
|
|
|
* XXX this coding assumes that PQconninfoOption structs always have the
|
|
|
|
* keywords in the same order.
|
|
|
|
*/
|
|
|
|
for (opt = opts, def = defs; opt->keyword; ++opt, ++def)
|
|
|
|
{
|
|
|
|
if (opt->val != NULL)
|
|
|
|
{
|
|
|
|
if (def->val == NULL || strcmp(opt->val, def->val) != 0)
|
|
|
|
printf("%s='%s' ", opt->keyword, opt->val);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to detect if this is a Unix-domain socket or inet. This is
|
|
|
|
* a bit grotty but it's the same thing that libpq itself does.
|
|
|
|
*
|
|
|
|
* Note that we directly test for '/' instead of using
|
|
|
|
* is_absolute_path, as that would be considerably more messy.
|
|
|
|
* This would fail on Windows, but that platform doesn't have
|
|
|
|
* Unix-domain sockets anyway.
|
|
|
|
*/
|
|
|
|
if (*opt->val &&
|
|
|
|
(strcmp(opt->keyword, "hostaddr") == 0 ||
|
|
|
|
(strcmp(opt->keyword, "host") == 0 && *opt->val != '/')))
|
|
|
|
{
|
|
|
|
local = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (local)
|
|
|
|
printf("(local)\n");
|
|
|
|
else
|
|
|
|
printf("(inet)\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|