79 lines
1.6 KiB
C#
79 lines
1.6 KiB
C#
|
|
using System.Collections.ObjectModel;
|
|||
|
|
|
|||
|
|
namespace pgLabII.PgUtils.ConnectionStrings;
|
|||
|
|
|
|||
|
|
public class PqConnectionStringParser
|
|||
|
|
{
|
|||
|
|
// Note possible keywords
|
|||
|
|
// host
|
|||
|
|
//hostaddr
|
|||
|
|
//port
|
|||
|
|
//dbname
|
|||
|
|
//user
|
|||
|
|
//password
|
|||
|
|
//passfile
|
|||
|
|
//channel_binding
|
|||
|
|
//connect_timeout
|
|||
|
|
//client_encoding
|
|||
|
|
//options
|
|||
|
|
//application_name
|
|||
|
|
//fallback_application_name
|
|||
|
|
//keepalives
|
|||
|
|
//keepalives_idle
|
|||
|
|
//keepalives_interval
|
|||
|
|
//keepalives_count
|
|||
|
|
//tcp_user_timeout
|
|||
|
|
//replication
|
|||
|
|
//gssencmode
|
|||
|
|
//sslmode
|
|||
|
|
//requiresll
|
|||
|
|
//sslcompression
|
|||
|
|
//sslcert
|
|||
|
|
//sslkey
|
|||
|
|
//sslpassword
|
|||
|
|
//sslrootcert
|
|||
|
|
//sslcrl
|
|||
|
|
//sslcrldir
|
|||
|
|
//sslsni
|
|||
|
|
//requirepeer
|
|||
|
|
//ssl_min_protocol_version
|
|||
|
|
//ssl_max_protocol_version
|
|||
|
|
//krbsrvname
|
|||
|
|
//gsslib
|
|||
|
|
//service
|
|||
|
|
//target_session_attrs
|
|||
|
|
|
|||
|
|
public static IDictionary<string, string> Parse(string input)
|
|||
|
|
{
|
|||
|
|
return new PqConnectionStringParser(
|
|||
|
|
new PqConnectionStringTokenizer(input)
|
|||
|
|
).Parse();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private readonly IPqConnectionStringTokenizer tokenizer;
|
|||
|
|
private readonly Dictionary<string, string> result = new();
|
|||
|
|
|
|||
|
|
public PqConnectionStringParser(IPqConnectionStringTokenizer tokenizer)
|
|||
|
|
{
|
|||
|
|
this.tokenizer = tokenizer;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public IDictionary<string, string> Parse()
|
|||
|
|
{
|
|||
|
|
result.Clear();
|
|||
|
|
|
|||
|
|
while (!tokenizer.Eof)
|
|||
|
|
ParsePair();
|
|||
|
|
|
|||
|
|
return result;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void ParsePair()
|
|||
|
|
{
|
|||
|
|
string kw = tokenizer.GetKeyword();
|
|||
|
|
tokenizer.ConsumeEquals();
|
|||
|
|
string v = tokenizer.GetValue();
|
|||
|
|
result.Add(kw, v);
|
|||
|
|
}
|
|||
|
|
}
|