postgres-pr 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/postgres-pr/connection.rb +28 -3
- data/lib/postgres-pr/message.rb +47 -0
- metadata +2 -2
@@ -14,7 +14,7 @@ class Connection
|
|
14
14
|
|
15
15
|
# sync
|
16
16
|
|
17
|
-
def initialize(database, user,
|
17
|
+
def initialize(database, user, password=nil, uri = nil)
|
18
18
|
uri ||= "unix:/tmp/.s.PGSQL.5432"
|
19
19
|
|
20
20
|
raise unless @mutex.nil?
|
@@ -29,10 +29,31 @@ class Connection
|
|
29
29
|
|
30
30
|
loop do
|
31
31
|
msg = Message.read(@conn)
|
32
|
+
|
32
33
|
case msg
|
34
|
+
when AuthentificationClearTextPassword
|
35
|
+
raise ArgumentError, "no password specified" if password.nil?
|
36
|
+
@conn << PasswordMessage.new(password).dump
|
37
|
+
|
38
|
+
when AuthentificationCryptPassword
|
39
|
+
raise ArgumentError, "no password specified" if password.nil?
|
40
|
+
@conn << PasswordMessage.new(password.crypt(msg.salt)).dump
|
41
|
+
|
42
|
+
when AuthentificationMD5Password
|
43
|
+
raise ArgumentError, "no password specified" if password.nil?
|
44
|
+
require 'digest/md5'
|
45
|
+
|
46
|
+
m = Digest::MD5.hexdigest(password + user)
|
47
|
+
m = Digest::MD5.hexdigest(m + msg.salt)
|
48
|
+
m = 'md5' + m
|
49
|
+
@conn << PasswordMessage.new(m).dump
|
50
|
+
|
51
|
+
when AuthentificationKerberosV4, AuthentificationKerberosV5, AuthentificationSCMCredential
|
52
|
+
raise "unsupported authentification"
|
53
|
+
|
33
54
|
when AuthentificationOk
|
34
55
|
when ErrorResponse
|
35
|
-
raise
|
56
|
+
raise "authentification failed"
|
36
57
|
when NoticeResponse
|
37
58
|
# TODO
|
38
59
|
when ParameterStatus
|
@@ -62,6 +83,7 @@ class Connection
|
|
62
83
|
@conn << Query.dump(sql)
|
63
84
|
|
64
85
|
result = Result.new
|
86
|
+
errors = []
|
65
87
|
|
66
88
|
loop do
|
67
89
|
msg = Message.read(@conn)
|
@@ -78,13 +100,16 @@ class Connection
|
|
78
100
|
when EmptyQueryResponse
|
79
101
|
when ErrorResponse
|
80
102
|
# TODO
|
81
|
-
|
103
|
+
errors << msg
|
82
104
|
when NoticeResponse
|
83
105
|
p msg
|
84
106
|
else
|
85
107
|
# TODO
|
86
108
|
end
|
87
109
|
end
|
110
|
+
|
111
|
+
raise errors.map{|e| e.inspect}.join(" ") unless errors.empty?
|
112
|
+
|
88
113
|
result
|
89
114
|
}
|
90
115
|
end
|
data/lib/postgres-pr/message.rb
CHANGED
@@ -183,6 +183,23 @@ class AuthentificationSCMCredential < Authentification
|
|
183
183
|
register_auth_type 6
|
184
184
|
end
|
185
185
|
|
186
|
+
class PasswordMessage < Message
|
187
|
+
register_message_type ?p
|
188
|
+
fields :password
|
189
|
+
|
190
|
+
def dump
|
191
|
+
super(@password.size + 1) do |buffer|
|
192
|
+
buffer.write_cstring(@password)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
def parse(buffer)
|
197
|
+
super do
|
198
|
+
@password = buffer.read_cstring
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
186
203
|
class ParameterStatus < Message
|
187
204
|
register_message_type ?S
|
188
205
|
fields :key, :value
|
@@ -473,3 +490,33 @@ class StartupMessage < Message
|
|
473
490
|
raise ParseError unless buffer.at_end?
|
474
491
|
end
|
475
492
|
end
|
493
|
+
|
494
|
+
class SSLRequest < Message
|
495
|
+
fields :ssl_request_code
|
496
|
+
|
497
|
+
def dump
|
498
|
+
sz = 4 + 4
|
499
|
+
buffer = Buffer.new(sz)
|
500
|
+
buffer.write_int32_network(sz)
|
501
|
+
buffer.write_int32_network(@ssl_request_code)
|
502
|
+
raise DumpError unless buffer.at_end?
|
503
|
+
return buffer.content
|
504
|
+
end
|
505
|
+
|
506
|
+
def parse(buffer)
|
507
|
+
buffer.position = 4
|
508
|
+
@ssl_request_code = buffer.read_int32_network
|
509
|
+
raise ParseError unless buffer.at_end?
|
510
|
+
end
|
511
|
+
end
|
512
|
+
|
513
|
+
=begin
|
514
|
+
# TODO: duplicate message-type, split into client/server messages
|
515
|
+
class Sync < Message
|
516
|
+
register_message_type ?S
|
517
|
+
end
|
518
|
+
=end
|
519
|
+
|
520
|
+
class Terminate < Message
|
521
|
+
register_message_type ?X
|
522
|
+
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.1
|
|
3
3
|
specification_version: 1
|
4
4
|
name: postgres-pr
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2004-11-
|
6
|
+
version: 0.2.0
|
7
|
+
date: 2004-11-19
|
8
8
|
summary: A pure Ruby interface to the PostgreSQL database
|
9
9
|
require_paths:
|
10
10
|
- lib
|