Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Gpdb
提交
e9ce658b
G
Gpdb
项目概览
Greenplum
/
Gpdb
通知
7
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
Gpdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e9ce658b
编写于
3月 22, 2012
作者:
T
Tom Lane
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor to eliminate duplicate copies of conninfo default-finding code.
Alex Shulgin, lightly edited by me
上级
04dfc877
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
84 addition
and
101 deletion
+84
-101
src/interfaces/libpq/fe-connect.c
src/interfaces/libpq/fe-connect.c
+84
-101
未找到文件。
src/interfaces/libpq/fe-connect.c
浏览文件 @
e9ce658b
...
...
@@ -121,9 +121,9 @@ static int ldapServiceLookup(const char *purl, PQconninfoOption *options,
* fallback is available. If after all no value can be determined
* for an option, an error is returned.
*
* The value for the username is treated specially in conninfo_
parse
.
* If the
Compiled-in resource is specified as a NULL value, the
*
user is determined
by pg_fe_getauthname().
* The value for the username is treated specially in conninfo_
add_defaults
.
* If the
value is not obtained any other way, the username is determined
* by pg_fe_getauthname().
*
* The Label and Disp-Char entries are provided for applications that
* want to use PQconndefaults() to create a generic database connection
...
...
@@ -292,11 +292,14 @@ static PGconn *makeEmptyPGconn(void);
static
void
fillPGconn
(
PGconn
*
conn
,
PQconninfoOption
*
connOptions
);
static
void
freePGconn
(
PGconn
*
conn
);
static
void
closePGconn
(
PGconn
*
conn
);
static
PQconninfoOption
*
conninfo_init
(
PQExpBuffer
errorMessage
);
static
PQconninfoOption
*
conninfo_parse
(
const
char
*
conninfo
,
PQExpBuffer
errorMessage
,
bool
use_defaults
);
static
PQconninfoOption
*
conninfo_array_parse
(
const
char
*
const
*
keywords
,
const
char
*
const
*
values
,
PQExpBuffer
errorMessage
,
bool
use_defaults
,
int
expand_dbname
);
static
bool
conninfo_add_defaults
(
PQconninfoOption
*
options
,
PQExpBuffer
errorMessage
);
static
char
*
conninfo_getval
(
PQconninfoOption
*
connOptions
,
const
char
*
keyword
);
static
void
defaultNoticeReceiver
(
void
*
arg
,
const
PGresult
*
res
);
...
...
@@ -813,10 +816,9 @@ connectOptions2(PGconn *conn)
/*
* PQconndefaults
*
* Parse an empty string like PQconnectdb() would do and return the
* resulting connection options array, ie, all the default values that are
* available from the environment etc. On error (eg out of memory),
* NULL is returned.
* Construct a default connection options array, which identifies all the
* available options and shows any default values that are available from the
* environment etc. On error (eg out of memory), NULL is returned.
*
* Using this function, an application may determine all possible options
* and their current default values.
...
...
@@ -833,10 +835,21 @@ PQconndefaults(void)
PQExpBufferData
errorBuf
;
PQconninfoOption
*
connOptions
;
/* We don't actually report any errors here, but callees want a buffer */
initPQExpBuffer
(
&
errorBuf
);
if
(
PQExpBufferDataBroken
(
errorBuf
))
return
NULL
;
/* out of memory already :-( */
connOptions
=
conninfo_parse
(
""
,
&
errorBuf
,
true
);
connOptions
=
conninfo_init
(
&
errorBuf
);
if
(
connOptions
!=
NULL
)
{
if
(
!
conninfo_add_defaults
(
connOptions
,
&
errorBuf
))
{
PQconninfoFree
(
connOptions
);
connOptions
=
NULL
;
}
}
termPQExpBuffer
(
&
errorBuf
);
return
connOptions
;
}
...
...
@@ -3986,6 +3999,25 @@ PQconninfoParse(const char *conninfo, char **errmsg)
return
connOptions
;
}
/*
* Build a working copy of the constant PQconninfoOptions array.
*/
static
PQconninfoOption
*
conninfo_init
(
PQExpBuffer
errorMessage
)
{
PQconninfoOption
*
options
;
options
=
(
PQconninfoOption
*
)
malloc
(
sizeof
(
PQconninfoOptions
));
if
(
options
==
NULL
)
{
printfPQExpBuffer
(
errorMessage
,
libpq_gettext
(
"out of memory
\n
"
));
return
NULL
;
}
memcpy
(
options
,
PQconninfoOptions
,
sizeof
(
PQconninfoOptions
));
return
options
;
}
/*
* Conninfo parser routine
*
...
...
@@ -4002,21 +4034,15 @@ conninfo_parse(const char *conninfo, PQExpBuffer errorMessage,
char
*
pname
;
char
*
pval
;
char
*
buf
;
char
*
tmp
;
char
*
cp
;
char
*
cp2
;
PQconninfoOption
*
options
;
PQconninfoOption
*
option
;
/* Make a working copy of PQconninfoOptions */
options
=
malloc
(
sizeof
(
PQconninfoOptions
)
);
options
=
conninfo_init
(
errorMessage
);
if
(
options
==
NULL
)
{
printfPQExpBuffer
(
errorMessage
,
libpq_gettext
(
"out of memory
\n
"
));
return
NULL
;
}
memcpy
(
options
,
PQconninfoOptions
,
sizeof
(
PQconninfoOptions
));
/* Need a modifiable copy of the input string */
if
((
buf
=
strdup
(
conninfo
))
==
NULL
)
...
...
@@ -4170,73 +4196,14 @@ conninfo_parse(const char *conninfo, PQExpBuffer errorMessage,
free
(
buf
);
/*
* Stop here if caller doesn't want defaults filled in.
*/
if
(
!
use_defaults
)
return
options
;
/*
* If there's a service spec, use it to obtain any not-explicitly-given
* parameters.
*/
if
(
parseServiceInfo
(
options
,
errorMessage
))
{
PQconninfoFree
(
options
);
return
NULL
;
}
/*
* Get the fallback resources for parameters not specified in the conninfo
* string nor the service.
* Add in defaults if the caller wants that.
*/
for
(
option
=
options
;
option
->
keyword
!=
NULL
;
option
++
)
if
(
use_defaults
)
{
if
(
option
->
val
!=
NULL
)
continue
;
/* Value was in conninfo or service */
/*
* Try to get the environment variable fallback
*/
if
(
option
->
envvar
!=
NULL
)
if
(
!
conninfo_add_defaults
(
options
,
errorMessage
))
{
if
((
tmp
=
getenv
(
option
->
envvar
))
!=
NULL
)
{
option
->
val
=
strdup
(
tmp
);
if
(
!
option
->
val
)
{
printfPQExpBuffer
(
errorMessage
,
libpq_gettext
(
"out of memory
\n
"
));
PQconninfoFree
(
options
);
return
NULL
;
}
continue
;
}
}
/*
* No environment variable specified or this one isn't set - try
* compiled in
*/
if
(
option
->
compiled
!=
NULL
)
{
option
->
val
=
strdup
(
option
->
compiled
);
if
(
!
option
->
val
)
{
printfPQExpBuffer
(
errorMessage
,
libpq_gettext
(
"out of memory
\n
"
));
PQconninfoFree
(
options
);
return
NULL
;
}
continue
;
}
/*
* Special handling for user
*/
if
(
strcmp
(
option
->
keyword
,
"user"
)
==
0
)
{
option
->
val
=
pg_fe_getauthname
(
errorMessage
);
continue
;
PQconninfoFree
(
options
);
return
NULL
;
}
}
...
...
@@ -4262,7 +4229,6 @@ conninfo_array_parse(const char *const * keywords, const char *const * values,
PQExpBuffer
errorMessage
,
bool
use_defaults
,
int
expand_dbname
)
{
char
*
tmp
;
PQconninfoOption
*
options
;
PQconninfoOption
*
str_options
=
NULL
;
PQconninfoOption
*
option
;
...
...
@@ -4298,18 +4264,15 @@ conninfo_array_parse(const char *const * keywords, const char *const * values,
}
/* Make a working copy of PQconninfoOptions */
options
=
malloc
(
sizeof
(
PQconninfoOptions
)
);
options
=
conninfo_init
(
errorMessage
);
if
(
options
==
NULL
)
{
printfPQExpBuffer
(
errorMessage
,
libpq_gettext
(
"out of memory
\n
"
));
PQconninfoFree
(
str_options
);
return
NULL
;
}
memcpy
(
options
,
PQconninfoOptions
,
sizeof
(
PQconninfoOptions
));
i
=
0
;
/* Parse the keywords/values arrays */
i
=
0
;
while
(
keywords
[
i
])
{
const
char
*
pname
=
keywords
[
i
];
...
...
@@ -4386,20 +4349,42 @@ conninfo_array_parse(const char *const * keywords, const char *const * values,
PQconninfoFree
(
str_options
);
/*
*
Stop here if caller doesn't want defaults filled in
.
*
Add in defaults if the caller wants that
.
*/
if
(
!
use_defaults
)
return
options
;
if
(
use_defaults
)
{
if
(
!
conninfo_add_defaults
(
options
,
errorMessage
))
{
PQconninfoFree
(
options
);
return
NULL
;
}
}
return
options
;
}
/*
* Add the default values for any unspecified options to the connection
* options array.
*
* Defaults are obtained from a service file, environment variables, etc.
*
* Returns TRUE if successful, otherwise FALSE; errorMessage is filled in
* upon failure. Note that failure to locate a default value is not an
* error condition here --- we just leave the option's value as NULL.
*/
static
bool
conninfo_add_defaults
(
PQconninfoOption
*
options
,
PQExpBuffer
errorMessage
)
{
PQconninfoOption
*
option
;
char
*
tmp
;
/*
* If there's a service spec, use it to obtain any not-explicitly-given
* parameters.
*/
if
(
parseServiceInfo
(
options
,
errorMessage
))
{
PQconninfoFree
(
options
);
return
NULL
;
}
if
(
parseServiceInfo
(
options
,
errorMessage
)
!=
0
)
return
false
;
/*
* Get the fallback resources for parameters not specified in the conninfo
...
...
@@ -4422,16 +4407,15 @@ conninfo_array_parse(const char *const * keywords, const char *const * values,
{
printfPQExpBuffer
(
errorMessage
,
libpq_gettext
(
"out of memory
\n
"
));
PQconninfoFree
(
options
);
return
NULL
;
return
false
;
}
continue
;
}
}
/*
* No environment variable specified or th
is on
e isn't set - try
* compiled
in
* No environment variable specified or th
e variabl
e isn't set - try
* compiled
-in default
*/
if
(
option
->
compiled
!=
NULL
)
{
...
...
@@ -4440,14 +4424,13 @@ conninfo_array_parse(const char *const * keywords, const char *const * values,
{
printfPQExpBuffer
(
errorMessage
,
libpq_gettext
(
"out of memory
\n
"
));
PQconninfoFree
(
options
);
return
NULL
;
return
false
;
}
continue
;
}
/*
* Special handling for
user
* Special handling for
"user" option
*/
if
(
strcmp
(
option
->
keyword
,
"user"
)
==
0
)
{
...
...
@@ -4456,7 +4439,7 @@ conninfo_array_parse(const char *const * keywords, const char *const * values,
}
}
return
options
;
return
true
;
}
static
char
*
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录