blob: 91170a18847023b02a6863f9359dd2d8691f9443 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
/*
* connstrings.c
* connecting string processing functions
*
* Copyright (c) 2012-2015, PostgreSQL Global Development Group
*
* src/include/common/connstrings.c
*/
#include "postgres_fe.h"
#include <string.h>
#include "common/connstrings.h"
/* The connection URI must start with either of the following designators: */
static const char uri_designator[] = "postgresql://";
static const char short_uri_designator[] = "postgres://";
/*
* Checks if connection string starts with either of the valid URI prefix
* designators.
*
* Returns the URI prefix length, 0 if the string doesn't contain a URI prefix.
*/
int
libpq_connstring_uri_prefix_length(const char *connstr)
{
if (strncmp(connstr, uri_designator,
sizeof(uri_designator) - 1) == 0)
return sizeof(uri_designator) - 1;
if (strncmp(connstr, short_uri_designator,
sizeof(short_uri_designator) - 1) == 0)
return sizeof(short_uri_designator) - 1;
return 0;
}
/*
* Recognized connection string either starts with a valid URI prefix or
* contains a "=" in it.
*
* Must be consistent with parse_connection_string: anything for which this
* returns true should at least look like it's parseable by that routine.
*/
bool
libpq_connstring_is_recognized(const char *connstr)
{
return libpq_connstring_uri_prefix_length(connstr) != 0 ||
strchr(connstr, '=') != NULL;
}
|