log4ever 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +33 -0
- data/.project +11 -0
- data/README.md +36 -0
- data/config/evernote.auth.test.yml +1 -0
- data/config/log4r.xml +19 -0
- data/lib/log4r/evernote/lib/Evernote/EDAM/errors_constants.rb +14 -0
- data/lib/log4r/evernote/lib/Evernote/EDAM/errors_types.rb +128 -0
- data/lib/log4r/evernote/lib/Evernote/EDAM/limits_constants.rb +240 -0
- data/lib/log4r/evernote/lib/Evernote/EDAM/limits_types.rb +13 -0
- data/lib/log4r/evernote/lib/Evernote/EDAM/note_store.rb +5487 -0
- data/lib/log4r/evernote/lib/Evernote/EDAM/note_store_constants.rb +14 -0
- data/lib/log4r/evernote/lib/Evernote/EDAM/note_store_types.rb +1012 -0
- data/lib/log4r/evernote/lib/Evernote/EDAM/types_constants.rb +20 -0
- data/lib/log4r/evernote/lib/Evernote/EDAM/types_types.rb +1792 -0
- data/lib/log4r/evernote/lib/Evernote/EDAM/user_store.rb +549 -0
- data/lib/log4r/evernote/lib/Evernote/EDAM/user_store_constants.rb +18 -0
- data/lib/log4r/evernote/lib/Evernote/EDAM/user_store_types.rb +415 -0
- data/lib/log4r/evernote/lib/thrift/client.rb +62 -0
- data/lib/log4r/evernote/lib/thrift/core_ext/fixnum.rb +29 -0
- data/lib/log4r/evernote/lib/thrift/core_ext.rb +23 -0
- data/lib/log4r/evernote/lib/thrift/exceptions.rb +84 -0
- data/lib/log4r/evernote/lib/thrift/processor.rb +57 -0
- data/lib/log4r/evernote/lib/thrift/protocol/base_protocol.rb +290 -0
- data/lib/log4r/evernote/lib/thrift/protocol/binary_protocol.rb +229 -0
- data/lib/log4r/evernote/lib/thrift/protocol/binary_protocol_accelerated.rb +39 -0
- data/lib/log4r/evernote/lib/thrift/protocol/compact_protocol.rb +426 -0
- data/lib/log4r/evernote/lib/thrift/serializer/deserializer.rb +33 -0
- data/lib/log4r/evernote/lib/thrift/serializer/serializer.rb +34 -0
- data/lib/log4r/evernote/lib/thrift/server/base_server.rb +31 -0
- data/lib/log4r/evernote/lib/thrift/server/mongrel_http_server.rb +58 -0
- data/lib/log4r/evernote/lib/thrift/server/nonblocking_server.rb +305 -0
- data/lib/log4r/evernote/lib/thrift/server/simple_server.rb +43 -0
- data/lib/log4r/evernote/lib/thrift/server/thread_pool_server.rb +75 -0
- data/lib/log4r/evernote/lib/thrift/server/threaded_server.rb +47 -0
- data/lib/log4r/evernote/lib/thrift/struct.rb +237 -0
- data/lib/log4r/evernote/lib/thrift/struct_union.rb +192 -0
- data/lib/log4r/evernote/lib/thrift/thrift_native.rb +24 -0
- data/lib/log4r/evernote/lib/thrift/transport/base_server_transport.rb +37 -0
- data/lib/log4r/evernote/lib/thrift/transport/base_transport.rb +107 -0
- data/lib/log4r/evernote/lib/thrift/transport/buffered_transport.rb +108 -0
- data/lib/log4r/evernote/lib/thrift/transport/framed_transport.rb +116 -0
- data/lib/log4r/evernote/lib/thrift/transport/http_client_transport.rb +53 -0
- data/lib/log4r/evernote/lib/thrift/transport/io_stream_transport.rb +39 -0
- data/lib/log4r/evernote/lib/thrift/transport/memory_buffer_transport.rb +125 -0
- data/lib/log4r/evernote/lib/thrift/transport/server_socket.rb +63 -0
- data/lib/log4r/evernote/lib/thrift/transport/socket.rb +137 -0
- data/lib/log4r/evernote/lib/thrift/transport/unix_server_socket.rb +60 -0
- data/lib/log4r/evernote/lib/thrift/transport/unix_socket.rb +40 -0
- data/lib/log4r/evernote/lib/thrift/types.rb +101 -0
- data/lib/log4r/evernote/lib/thrift/union.rb +179 -0
- data/lib/log4r/evernote/lib/thrift.rb +64 -0
- data/lib/log4r/evernote.rb +206 -0
- data/lib/log4r/outputter/evernoteoutputter.rb +156 -0
- data/spec/log4ever_spec.rb +94 -0
- data/spec/spec_helper.rb +14 -0
- metadata +105 -0
@@ -0,0 +1,192 @@
|
|
1
|
+
#
|
2
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
3
|
+
# or more contributor license agreements. See the NOTICE file
|
4
|
+
# distributed with this work for additional information
|
5
|
+
# regarding copyright ownership. The ASF licenses this file
|
6
|
+
# to you under the Apache License, Version 2.0 (the
|
7
|
+
# "License"); you may not use this file except in compliance
|
8
|
+
# with the License. You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing,
|
13
|
+
# software distributed under the License is distributed on an
|
14
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
15
|
+
# KIND, either express or implied. See the License for the
|
16
|
+
# specific language governing permissions and limitations
|
17
|
+
# under the License.
|
18
|
+
#
|
19
|
+
require 'set'
|
20
|
+
|
21
|
+
module Thrift
|
22
|
+
module Struct_Union
|
23
|
+
def name_to_id(name)
|
24
|
+
names_to_ids = self.class.instance_variable_get(:@names_to_ids)
|
25
|
+
unless names_to_ids
|
26
|
+
names_to_ids = {}
|
27
|
+
struct_fields.each do |fid, field_def|
|
28
|
+
names_to_ids[field_def[:name]] = fid
|
29
|
+
end
|
30
|
+
self.class.instance_variable_set(:@names_to_ids, names_to_ids)
|
31
|
+
end
|
32
|
+
names_to_ids[name]
|
33
|
+
end
|
34
|
+
|
35
|
+
def sorted_field_ids
|
36
|
+
sorted_field_ids = self.class.instance_variable_get(:@sorted_field_ids)
|
37
|
+
unless sorted_field_ids
|
38
|
+
sorted_field_ids = struct_fields.keys.sort
|
39
|
+
self.class.instance_variable_set(:@sorted_field_ids, sorted_field_ids)
|
40
|
+
end
|
41
|
+
sorted_field_ids
|
42
|
+
end
|
43
|
+
|
44
|
+
def each_field
|
45
|
+
sorted_field_ids.each do |fid|
|
46
|
+
data = struct_fields[fid]
|
47
|
+
yield fid, data
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def read_field(iprot, field = {})
|
52
|
+
case field[:type]
|
53
|
+
when Types::STRUCT
|
54
|
+
value = field[:class].new
|
55
|
+
value.read(iprot)
|
56
|
+
when Types::MAP
|
57
|
+
key_type, val_type, size = iprot.read_map_begin
|
58
|
+
# Skip the map contents if the declared key or value types don't match the expected ones.
|
59
|
+
if (size != 0 && (key_type != field[:key][:type] || val_type != field[:value][:type]))
|
60
|
+
size.times do
|
61
|
+
iprot.skip(key_type)
|
62
|
+
iprot.skip(val_type)
|
63
|
+
end
|
64
|
+
value = nil
|
65
|
+
else
|
66
|
+
value = {}
|
67
|
+
size.times do
|
68
|
+
k = read_field(iprot, field_info(field[:key]))
|
69
|
+
v = read_field(iprot, field_info(field[:value]))
|
70
|
+
value[k] = v
|
71
|
+
end
|
72
|
+
end
|
73
|
+
iprot.read_map_end
|
74
|
+
when Types::LIST
|
75
|
+
e_type, size = iprot.read_list_begin
|
76
|
+
# Skip the list contents if the declared element type doesn't match the expected one.
|
77
|
+
if (e_type != field[:element][:type])
|
78
|
+
size.times do
|
79
|
+
iprot.skip(e_type)
|
80
|
+
end
|
81
|
+
value = nil
|
82
|
+
else
|
83
|
+
value = Array.new(size) do |n|
|
84
|
+
read_field(iprot, field_info(field[:element]))
|
85
|
+
end
|
86
|
+
end
|
87
|
+
iprot.read_list_end
|
88
|
+
when Types::SET
|
89
|
+
e_type, size = iprot.read_set_begin
|
90
|
+
# Skip the set contents if the declared element type doesn't match the expected one.
|
91
|
+
if (e_type != field[:element][:type])
|
92
|
+
size.times do
|
93
|
+
iprot.skip(e_type)
|
94
|
+
end
|
95
|
+
else
|
96
|
+
value = Set.new
|
97
|
+
size.times do
|
98
|
+
element = read_field(iprot, field_info(field[:element]))
|
99
|
+
value << element
|
100
|
+
end
|
101
|
+
end
|
102
|
+
iprot.read_set_end
|
103
|
+
else
|
104
|
+
value = iprot.read_type(field[:type])
|
105
|
+
end
|
106
|
+
value
|
107
|
+
end
|
108
|
+
|
109
|
+
def write_data(oprot, value, field)
|
110
|
+
if is_container? field[:type]
|
111
|
+
write_container(oprot, value, field)
|
112
|
+
else
|
113
|
+
oprot.write_type(field[:type], value)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def write_container(oprot, value, field = {})
|
118
|
+
case field[:type]
|
119
|
+
when Types::MAP
|
120
|
+
oprot.write_map_begin(field[:key][:type], field[:value][:type], value.size)
|
121
|
+
value.each do |k, v|
|
122
|
+
write_data(oprot, k, field[:key])
|
123
|
+
write_data(oprot, v, field[:value])
|
124
|
+
end
|
125
|
+
oprot.write_map_end
|
126
|
+
when Types::LIST
|
127
|
+
oprot.write_list_begin(field[:element][:type], value.size)
|
128
|
+
value.each do |elem|
|
129
|
+
write_data(oprot, elem, field[:element])
|
130
|
+
end
|
131
|
+
oprot.write_list_end
|
132
|
+
when Types::SET
|
133
|
+
oprot.write_set_begin(field[:element][:type], value.size)
|
134
|
+
value.each do |v,| # the , is to preserve compatibility with the old Hash-style sets
|
135
|
+
write_data(oprot, v, field[:element])
|
136
|
+
end
|
137
|
+
oprot.write_set_end
|
138
|
+
else
|
139
|
+
raise "Not a container type: #{field[:type]}"
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
CONTAINER_TYPES = []
|
144
|
+
CONTAINER_TYPES[Types::LIST] = true
|
145
|
+
CONTAINER_TYPES[Types::MAP] = true
|
146
|
+
CONTAINER_TYPES[Types::SET] = true
|
147
|
+
def is_container?(type)
|
148
|
+
CONTAINER_TYPES[type]
|
149
|
+
end
|
150
|
+
|
151
|
+
def field_info(field)
|
152
|
+
{ :type => field[:type],
|
153
|
+
:class => field[:class],
|
154
|
+
:key => field[:key],
|
155
|
+
:value => field[:value],
|
156
|
+
:element => field[:element] }
|
157
|
+
end
|
158
|
+
|
159
|
+
def inspect_field(value, field_info)
|
160
|
+
if enum_class = field_info[:enum_class]
|
161
|
+
"#{enum_class.const_get(:VALUE_MAP)[value]} (#{value})"
|
162
|
+
elsif value.is_a? Hash
|
163
|
+
if field_info[:type] == Types::MAP
|
164
|
+
map_buf = []
|
165
|
+
value.each do |k, v|
|
166
|
+
map_buf << inspect_field(k, field_info[:key]) + ": " + inspect_field(v, field_info[:value])
|
167
|
+
end
|
168
|
+
"{" + map_buf.join(", ") + "}"
|
169
|
+
else
|
170
|
+
# old-style set
|
171
|
+
inspect_collection(value.keys, field_info)
|
172
|
+
end
|
173
|
+
elsif value.is_a? Array
|
174
|
+
inspect_collection(value, field_info)
|
175
|
+
elsif value.is_a? Set
|
176
|
+
inspect_collection(value, field_info)
|
177
|
+
elsif value.is_a?(String) && field_info[:binary]
|
178
|
+
value.unpack("H*").first
|
179
|
+
else
|
180
|
+
value.inspect
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def inspect_collection(collection, field_info)
|
185
|
+
buf = []
|
186
|
+
collection.each do |k|
|
187
|
+
buf << inspect_field(k, field_info[:element])
|
188
|
+
end
|
189
|
+
"[" + buf.join(", ") + "]"
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#
|
2
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
3
|
+
# or more contributor license agreements. See the NOTICE file
|
4
|
+
# distributed with this work for additional information
|
5
|
+
# regarding copyright ownership. The ASF licenses this file
|
6
|
+
# to you under the Apache License, Version 2.0 (the
|
7
|
+
# "License"); you may not use this file except in compliance
|
8
|
+
# with the License. You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing,
|
13
|
+
# software distributed under the License is distributed on an
|
14
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
15
|
+
# KIND, either express or implied. See the License for the
|
16
|
+
# specific language governing permissions and limitations
|
17
|
+
# under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
begin
|
21
|
+
require "thrift_native"
|
22
|
+
rescue LoadError
|
23
|
+
puts "Unable to load thrift_native extension. Defaulting to pure Ruby libraries."
|
24
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
#
|
3
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
4
|
+
# or more contributor license agreements. See the NOTICE file
|
5
|
+
# distributed with this work for additional information
|
6
|
+
# regarding copyright ownership. The ASF licenses this file
|
7
|
+
# to you under the Apache License, Version 2.0 (the
|
8
|
+
# "License"); you may not use this file except in compliance
|
9
|
+
# with the License. You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing,
|
14
|
+
# software distributed under the License is distributed on an
|
15
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
16
|
+
# KIND, either express or implied. See the License for the
|
17
|
+
# specific language governing permissions and limitations
|
18
|
+
# under the License.
|
19
|
+
#
|
20
|
+
|
21
|
+
module Thrift
|
22
|
+
class BaseServerTransport
|
23
|
+
def listen
|
24
|
+
raise NotImplementedError
|
25
|
+
end
|
26
|
+
|
27
|
+
def accept
|
28
|
+
raise NotImplementedError
|
29
|
+
end
|
30
|
+
|
31
|
+
def close; nil; end
|
32
|
+
|
33
|
+
def closed?
|
34
|
+
raise NotImplementedError
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
#
|
3
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
4
|
+
# or more contributor license agreements. See the NOTICE file
|
5
|
+
# distributed with this work for additional information
|
6
|
+
# regarding copyright ownership. The ASF licenses this file
|
7
|
+
# to you under the Apache License, Version 2.0 (the
|
8
|
+
# "License"); you may not use this file except in compliance
|
9
|
+
# with the License. You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing,
|
14
|
+
# software distributed under the License is distributed on an
|
15
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
16
|
+
# KIND, either express or implied. See the License for the
|
17
|
+
# specific language governing permissions and limitations
|
18
|
+
# under the License.
|
19
|
+
#
|
20
|
+
|
21
|
+
module Thrift
|
22
|
+
class TransportException < Exception
|
23
|
+
UNKNOWN = 0
|
24
|
+
NOT_OPEN = 1
|
25
|
+
ALREADY_OPEN = 2
|
26
|
+
TIMED_OUT = 3
|
27
|
+
END_OF_FILE = 4
|
28
|
+
|
29
|
+
attr_reader :type
|
30
|
+
|
31
|
+
def initialize(type=UNKNOWN, message=nil)
|
32
|
+
super(message)
|
33
|
+
@type = type
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
module TransportUtils
|
38
|
+
if RUBY_VERSION >= '1.9'
|
39
|
+
def self.get_string_byte(string, index)
|
40
|
+
string.getbyte(index)
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.set_string_byte(string, index, byte)
|
44
|
+
string.setbyte(index, byte)
|
45
|
+
end
|
46
|
+
else
|
47
|
+
def self.get_string_byte(string, index)
|
48
|
+
string[index]
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.set_string_byte(string, index, byte)
|
52
|
+
string[index] = byte
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class BaseTransport
|
58
|
+
def open?; end
|
59
|
+
|
60
|
+
def open; end
|
61
|
+
|
62
|
+
def close; end
|
63
|
+
|
64
|
+
def read(sz)
|
65
|
+
raise NotImplementedError
|
66
|
+
end
|
67
|
+
|
68
|
+
# Returns an unsigned byte as a Fixnum in the range (0..255).
|
69
|
+
def read_byte
|
70
|
+
buf = read_all(1)
|
71
|
+
return ::Thrift::TransportUtils.get_string_byte(buf, 0)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Reads size bytes and copies them into buffer[0..size].
|
75
|
+
def read_into_buffer(buffer, size)
|
76
|
+
tmp = read_all(size)
|
77
|
+
i = 0
|
78
|
+
tmp.each_byte do |byte|
|
79
|
+
::Thrift::TransportUtils.set_string_byte(buffer, i, byte)
|
80
|
+
i += 1
|
81
|
+
end
|
82
|
+
i
|
83
|
+
end
|
84
|
+
|
85
|
+
def read_all(size)
|
86
|
+
return '' if size <= 0
|
87
|
+
buf = read(size)
|
88
|
+
while (buf.length < size)
|
89
|
+
chunk = read(size - buf.length)
|
90
|
+
buf << chunk
|
91
|
+
end
|
92
|
+
|
93
|
+
buf
|
94
|
+
end
|
95
|
+
|
96
|
+
def write(buf); end
|
97
|
+
alias_method :<<, :write
|
98
|
+
|
99
|
+
def flush; end
|
100
|
+
end
|
101
|
+
|
102
|
+
class BaseTransportFactory
|
103
|
+
def get_transport(trans)
|
104
|
+
return trans
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
#
|
3
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
4
|
+
# or more contributor license agreements. See the NOTICE file
|
5
|
+
# distributed with this work for additional information
|
6
|
+
# regarding copyright ownership. The ASF licenses this file
|
7
|
+
# to you under the Apache License, Version 2.0 (the
|
8
|
+
# "License"); you may not use this file except in compliance
|
9
|
+
# with the License. You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing,
|
14
|
+
# software distributed under the License is distributed on an
|
15
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
16
|
+
# KIND, either express or implied. See the License for the
|
17
|
+
# specific language governing permissions and limitations
|
18
|
+
# under the License.
|
19
|
+
#
|
20
|
+
|
21
|
+
module Thrift
|
22
|
+
class BufferedTransport < BaseTransport
|
23
|
+
DEFAULT_BUFFER = 4096
|
24
|
+
|
25
|
+
def initialize(transport)
|
26
|
+
@transport = transport
|
27
|
+
@wbuf = ''
|
28
|
+
@rbuf = ''
|
29
|
+
@index = 0
|
30
|
+
end
|
31
|
+
|
32
|
+
def open?
|
33
|
+
return @transport.open?
|
34
|
+
end
|
35
|
+
|
36
|
+
def open
|
37
|
+
@transport.open
|
38
|
+
end
|
39
|
+
|
40
|
+
def close
|
41
|
+
flush
|
42
|
+
@transport.close
|
43
|
+
end
|
44
|
+
|
45
|
+
def read(sz)
|
46
|
+
@index += sz
|
47
|
+
ret = @rbuf.slice(@index - sz, sz) || ''
|
48
|
+
|
49
|
+
if ret.length == 0
|
50
|
+
@rbuf = @transport.read([sz, DEFAULT_BUFFER].max)
|
51
|
+
@index = sz
|
52
|
+
ret = @rbuf.slice(0, sz) || ''
|
53
|
+
end
|
54
|
+
|
55
|
+
ret
|
56
|
+
end
|
57
|
+
|
58
|
+
def read_byte
|
59
|
+
# If the read buffer is exhausted, try to read up to DEFAULT_BUFFER more bytes into it.
|
60
|
+
if @index >= @rbuf.size
|
61
|
+
@rbuf = @transport.read(DEFAULT_BUFFER)
|
62
|
+
@index = 0
|
63
|
+
end
|
64
|
+
|
65
|
+
# The read buffer has some data now, read a single byte. Using get_string_byte() avoids
|
66
|
+
# allocating a temp string of size 1 unnecessarily.
|
67
|
+
@index += 1
|
68
|
+
return ::Thrift::TransportUtils.get_string_byte(@rbuf, @index - 1)
|
69
|
+
end
|
70
|
+
|
71
|
+
def read_into_buffer(buffer, size)
|
72
|
+
i = 0
|
73
|
+
while i < size
|
74
|
+
# If the read buffer is exhausted, try to read up to DEFAULT_BUFFER more bytes into it.
|
75
|
+
if @index >= @rbuf.size
|
76
|
+
@rbuf = @transport.read(DEFAULT_BUFFER)
|
77
|
+
@index = 0
|
78
|
+
end
|
79
|
+
|
80
|
+
# The read buffer has some data now, so copy bytes over to the output buffer.
|
81
|
+
byte = ::Thrift::TransportUtils.get_string_byte(@rbuf, @index)
|
82
|
+
::Thrift::TransportUtils.set_string_byte(buffer, i, byte)
|
83
|
+
@index += 1
|
84
|
+
i += 1
|
85
|
+
end
|
86
|
+
i
|
87
|
+
end
|
88
|
+
|
89
|
+
def write(buf)
|
90
|
+
@wbuf << buf
|
91
|
+
end
|
92
|
+
|
93
|
+
def flush
|
94
|
+
if @wbuf != ''
|
95
|
+
@transport.write(@wbuf)
|
96
|
+
@wbuf = ''
|
97
|
+
end
|
98
|
+
|
99
|
+
@transport.flush
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
class BufferedTransportFactory < BaseTransportFactory
|
104
|
+
def get_transport(transport)
|
105
|
+
return BufferedTransport.new(transport)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
#
|
3
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
4
|
+
# or more contributor license agreements. See the NOTICE file
|
5
|
+
# distributed with this work for additional information
|
6
|
+
# regarding copyright ownership. The ASF licenses this file
|
7
|
+
# to you under the Apache License, Version 2.0 (the
|
8
|
+
# "License"); you may not use this file except in compliance
|
9
|
+
# with the License. You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing,
|
14
|
+
# software distributed under the License is distributed on an
|
15
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
16
|
+
# KIND, either express or implied. See the License for the
|
17
|
+
# specific language governing permissions and limitations
|
18
|
+
# under the License.
|
19
|
+
#
|
20
|
+
|
21
|
+
module Thrift
|
22
|
+
class FramedTransport < BaseTransport
|
23
|
+
def initialize(transport, read=true, write=true)
|
24
|
+
@transport = transport
|
25
|
+
@rbuf = ''
|
26
|
+
@wbuf = ''
|
27
|
+
@read = read
|
28
|
+
@write = write
|
29
|
+
@index = 0
|
30
|
+
end
|
31
|
+
|
32
|
+
def open?
|
33
|
+
@transport.open?
|
34
|
+
end
|
35
|
+
|
36
|
+
def open
|
37
|
+
@transport.open
|
38
|
+
end
|
39
|
+
|
40
|
+
def close
|
41
|
+
@transport.close
|
42
|
+
end
|
43
|
+
|
44
|
+
def read(sz)
|
45
|
+
return @transport.read(sz) unless @read
|
46
|
+
|
47
|
+
return '' if sz <= 0
|
48
|
+
|
49
|
+
read_frame if @index >= @rbuf.length
|
50
|
+
|
51
|
+
@index += sz
|
52
|
+
@rbuf.slice(@index - sz, sz) || ''
|
53
|
+
end
|
54
|
+
|
55
|
+
def read_byte
|
56
|
+
return @transport.read_byte() unless @read
|
57
|
+
|
58
|
+
read_frame if @index >= @rbuf.length
|
59
|
+
|
60
|
+
# The read buffer has some data now, read a single byte. Using get_string_byte() avoids
|
61
|
+
# allocating a temp string of size 1 unnecessarily.
|
62
|
+
@index += 1
|
63
|
+
return ::Thrift::TransportUtils.get_string_byte(@rbuf, @index - 1)
|
64
|
+
end
|
65
|
+
|
66
|
+
def read_into_buffer(buffer, size)
|
67
|
+
i = 0
|
68
|
+
while i < size
|
69
|
+
read_frame if @index >= @rbuf.length
|
70
|
+
|
71
|
+
# The read buffer has some data now, so copy bytes over to the output buffer.
|
72
|
+
byte = ::Thrift::TransportUtils.get_string_byte(@rbuf, @index)
|
73
|
+
::Thrift::TransportUtils.set_string_byte(buffer, i, byte)
|
74
|
+
@index += 1
|
75
|
+
i += 1
|
76
|
+
end
|
77
|
+
i
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
def write(buf,sz=nil)
|
82
|
+
return @transport.write(buf) unless @write
|
83
|
+
|
84
|
+
@wbuf << (sz ? buf[0...sz] : buf)
|
85
|
+
end
|
86
|
+
|
87
|
+
#
|
88
|
+
# Writes the output buffer to the stream in the format of a 4-byte length
|
89
|
+
# followed by the actual data.
|
90
|
+
#
|
91
|
+
def flush
|
92
|
+
return @transport.flush unless @write
|
93
|
+
|
94
|
+
out = [@wbuf.length].pack('N')
|
95
|
+
out << @wbuf
|
96
|
+
@transport.write(out)
|
97
|
+
@transport.flush
|
98
|
+
@wbuf = ''
|
99
|
+
end
|
100
|
+
|
101
|
+
private
|
102
|
+
|
103
|
+
def read_frame
|
104
|
+
sz = @transport.read_all(4).unpack('N').first
|
105
|
+
|
106
|
+
@index = 0
|
107
|
+
@rbuf = @transport.read_all(sz)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
class FramedTransportFactory < BaseTransportFactory
|
112
|
+
def get_transport(transport)
|
113
|
+
return FramedTransport.new(transport)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
#
|
3
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
4
|
+
# or more contributor license agreements. See the NOTICE file
|
5
|
+
# distributed with this work for additional information
|
6
|
+
# regarding copyright ownership. The ASF licenses this file
|
7
|
+
# to you under the Apache License, Version 2.0 (the
|
8
|
+
# "License"); you may not use this file except in compliance
|
9
|
+
# with the License. You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing,
|
14
|
+
# software distributed under the License is distributed on an
|
15
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
16
|
+
# KIND, either express or implied. See the License for the
|
17
|
+
# specific language governing permissions and limitations
|
18
|
+
# under the License.
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'net/http'
|
22
|
+
require 'net/https'
|
23
|
+
require 'uri'
|
24
|
+
require 'stringio'
|
25
|
+
|
26
|
+
module Thrift
|
27
|
+
class HTTPClientTransport < BaseTransport
|
28
|
+
|
29
|
+
def initialize(url, proxy_addr = nil, proxy_port = nil)
|
30
|
+
@url = URI url
|
31
|
+
@headers = {'Content-Type' => 'application/x-thrift'}
|
32
|
+
@outbuf = ""
|
33
|
+
@proxy_addr = proxy_addr
|
34
|
+
@proxy_port = proxy_port
|
35
|
+
end
|
36
|
+
|
37
|
+
def open?; true end
|
38
|
+
def read(sz); @inbuf.read sz end
|
39
|
+
def write(buf); @outbuf << buf end
|
40
|
+
|
41
|
+
def add_headers(headers)
|
42
|
+
@headers = @headers.merge(headers)
|
43
|
+
end
|
44
|
+
|
45
|
+
def flush
|
46
|
+
http = Net::HTTP.new @url.host, @url.port, @proxy_addr, @proxy_port
|
47
|
+
http.use_ssl = @url.scheme == "https"
|
48
|
+
resp = http.post(@url.request_uri, @outbuf, @headers)
|
49
|
+
@inbuf = StringIO.new resp.body
|
50
|
+
@outbuf = ""
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
#
|
3
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
4
|
+
# or more contributor license agreements. See the NOTICE file
|
5
|
+
# distributed with this work for additional information
|
6
|
+
# regarding copyright ownership. The ASF licenses this file
|
7
|
+
# to you under the Apache License, Version 2.0 (the
|
8
|
+
# "License"); you may not use this file except in compliance
|
9
|
+
# with the License. You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing,
|
14
|
+
# software distributed under the License is distributed on an
|
15
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
16
|
+
# KIND, either express or implied. See the License for the
|
17
|
+
# specific language governing permissions and limitations
|
18
|
+
# under the License.
|
19
|
+
#
|
20
|
+
|
21
|
+
# Very very simple implementation of wrapping two objects, one with a #read
|
22
|
+
# method and one with a #write method, into a transport for thrift.
|
23
|
+
#
|
24
|
+
# Assumes both objects are open, remain open, don't require flushing, etc.
|
25
|
+
#
|
26
|
+
module Thrift
|
27
|
+
class IOStreamTransport < BaseTransport
|
28
|
+
def initialize(input, output)
|
29
|
+
@input = input
|
30
|
+
@output = output
|
31
|
+
end
|
32
|
+
|
33
|
+
def open?; not @input.closed? or not @output.closed? end
|
34
|
+
def read(sz); @input.read(sz) end
|
35
|
+
def write(buf); @output.write(buf) end
|
36
|
+
def close; @input.close; @output.close end
|
37
|
+
def to_io; @input end # we're assuming this is used in a IO.select for reading
|
38
|
+
end
|
39
|
+
end
|