pq connection string parsing from other project
This commit is contained in:
parent
9a5feb9d54
commit
d803cd8003
10 changed files with 529 additions and 0 deletions
|
|
@ -0,0 +1,78 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue