Ruby GTK3移行後のメインリポジトリ
リビジョン | f3a285c88cb27e5b805166739d86d35ac8f7242e (tree) |
---|---|
日時 | 2015-05-23 21:35:15 |
作者 | Shyouzou Sugitani <shy@user...> |
コミッター | Shyouzou Sugitani |
assorted fixes(24)
@@ -938,9 +938,9 @@ module Balloon | ||
938 | 938 | while 1 |
939 | 939 | i += 1 |
940 | 940 | s = message[0, i] + '... (' + sender + ')' |
941 | - @sstp_layout.set_text(s, -1) | |
941 | + @sstp_layout.set_text(s) | |
942 | 942 | message_width, message_height = \ |
943 | - @sstp_layout.get_pixel_size() | |
943 | + @sstp_layout.pixel_size | |
944 | 944 | if message_width > w |
945 | 945 | break |
946 | 946 | end |
@@ -1105,8 +1105,8 @@ module Balloon | ||
1105 | 1105 | if l == i |
1106 | 1106 | mw = @sstp_surface.width |
1107 | 1107 | mh = @sstp_surface.height |
1108 | - @layout.set_text(@text_buffer[i][0, c], -1) | |
1109 | - text_w, text_h = @layout.get_pixel_size() | |
1108 | + @layout.set_text(@text_buffer[i][0, c]) | |
1109 | + text_w, text_h = @layout.pixel_size | |
1110 | 1110 | mx = x + text_w |
1111 | 1111 | my = y + (@font_height + @line_space) / 2 |
1112 | 1112 | my = my - mh / 2 |
@@ -1144,36 +1144,36 @@ module Balloon | ||
1144 | 1144 | if sl == el |
1145 | 1145 | markup = set_markup(n, @text_buffer[n][0, sn]) |
1146 | 1146 | @layout.set_markup(markup, -1) |
1147 | - text_w, text_h = @layout.get_pixel_size() | |
1147 | + text_w, text_h = @layout.pixel_size | |
1148 | 1148 | x += text_w |
1149 | 1149 | markup = set_markup(n, @text_buffer[n][sn, en]) |
1150 | 1150 | @layout.set_markup(markup, -1) |
1151 | - text_w, text_h = @layout.get_pixel_size() | |
1151 | + text_w, text_h = @layout.pixel_size | |
1152 | 1152 | w = text_w |
1153 | 1153 | start = sn |
1154 | 1154 | end_ = en |
1155 | 1155 | elsif n == sl |
1156 | 1156 | markup = set_markup(n, @text_buffer[n][0, sn]) |
1157 | 1157 | @layout.set_markup(markup, -1) |
1158 | - text_w, text_h = @layout.get_pixel_size() | |
1158 | + text_w, text_h = @layout.pixel_size | |
1159 | 1159 | x += text_w |
1160 | 1160 | markup = set_markup(n, @text_buffer[n][sn, @text_buffer.length]) |
1161 | 1161 | @layout.set_markup(markup, -1) |
1162 | - text_w, text_h = @layout.get_pixel_size() | |
1162 | + text_w, text_h = @layout.pixel_size | |
1163 | 1163 | w = text_w |
1164 | 1164 | start = sn |
1165 | 1165 | end_ = @text_buffer[n].length |
1166 | 1166 | elsif n == el |
1167 | 1167 | markup = set_markup(n, @text_buffer[n][0, en]) |
1168 | 1168 | @layout.set_markup(markup, -1) |
1169 | - text_w, text_h = @layout.get_pixel_size() | |
1169 | + text_w, text_h = @layout.pixel_size | |
1170 | 1170 | w = text_w |
1171 | 1171 | start = 0 |
1172 | 1172 | end_ = en |
1173 | 1173 | else |
1174 | 1174 | markup = set_markup(n, @text_buffer[n]) |
1175 | 1175 | @layout.set_markup(markup, -1) |
1176 | - text_w, text_h = @layout.get_pixel_size() | |
1176 | + text_w, text_h = @layout.pixel_size | |
1177 | 1177 | w = text_w |
1178 | 1178 | start = 0 |
1179 | 1179 | end_ = @text_buffer[n].length |
@@ -1208,7 +1208,7 @@ module Balloon | ||
1208 | 1208 | if n == sl |
1209 | 1209 | markup = set_markup(n, @text_buffer[n][0, sn]) |
1210 | 1210 | @layout.set_markup(markup, -1) |
1211 | - text_w, text_h = @layout.get_pixel_size() | |
1211 | + text_w, text_h = @layout.pixel_size | |
1212 | 1212 | x += text_w |
1213 | 1213 | end |
1214 | 1214 | if n == sl and n == el |
@@ -1219,7 +1219,7 @@ module Balloon | ||
1219 | 1219 | markup = set_markup(n, @text_buffer[n]) |
1220 | 1220 | end |
1221 | 1221 | @layout.set_markup(markup, -1) |
1222 | - text_w, text_h = @layout.get_pixel_size() | |
1222 | + text_w, text_h = @layout.pixel_size | |
1223 | 1223 | w = text_w |
1224 | 1224 | if x <= px and px < x + w and y <= py and py < y + h |
1225 | 1225 | new_selection = i |
@@ -1469,8 +1469,8 @@ module Balloon | ||
1469 | 1469 | i = 1 |
1470 | 1470 | while 1 |
1471 | 1471 | space = '\u3000' * i ## FIXME |
1472 | - @layout.set_text(space, -1) | |
1473 | - text_w, text_h = @layout.get_pixel_size() | |
1472 | + @layout.set_text(space) | |
1473 | + text_w, text_h = @layout.pixel_size | |
1474 | 1474 | if text_w > w |
1475 | 1475 | break |
1476 | 1476 | else |
@@ -1559,8 +1559,8 @@ module Balloon | ||
1559 | 1559 | if l == line |
1560 | 1560 | mw = @sstp_surface.width |
1561 | 1561 | mh = @sstp_surface.height |
1562 | - @layout.set_text(@text_buffer[l][0, c], -1) | |
1563 | - text_w, text_h = @layout.get_pixel_size() | |
1562 | + @layout.set_text(@text_buffer[l][0, c]) | |
1563 | + text_w, text_h = @layout.pixel_size | |
1564 | 1564 | mx = x + text_w |
1565 | 1565 | my = y + (@font_height + @line_space) / 2 |
1566 | 1566 | my = my - mh / 2 |
@@ -1804,7 +1804,7 @@ module Sakura | ||
1804 | 1804 | event, script, sender, @sstp_handle, \ |
1805 | 1805 | host, show_sstp_marker, use_translator, \ |
1806 | 1806 | @sstp_entry_db, @sstp_request_handler = \ |
1807 | - script_queue.shift | |
1807 | + @script_queue.shift | |
1808 | 1808 | if @cantalk |
1809 | 1809 | if show_sstp_marker |
1810 | 1810 | @balloon.show_sstp_message(sender, host) |
@@ -21,6 +21,7 @@ require "ninix/sstplib" | ||
21 | 21 | module SSTP |
22 | 22 | |
23 | 23 | class SSTPServer < SSTPLib::AsynchronousSSTPServer |
24 | + attr_reader :socket | |
24 | 25 | |
25 | 26 | def initialize(address) |
26 | 27 | @parent = nil |
@@ -41,9 +42,9 @@ module SSTP | ||
41 | 42 | @parent = parent |
42 | 43 | end |
43 | 44 | |
44 | - def handle_request(event_type, event, *arglist, **argdict) | |
45 | + def handle_request(event_type, event, *arglist) | |
45 | 46 | if @parent != nil |
46 | - @parent.handle_request(event_type, event, *arglist, **argdict) | |
47 | + @parent.handle_request(event_type, event, *arglist) | |
47 | 48 | end |
48 | 49 | end |
49 | 50 |
@@ -93,7 +94,7 @@ module SSTP | ||
93 | 94 | end |
94 | 95 | |
95 | 96 | def close |
96 | - socket.close() | |
97 | + # NOP | |
97 | 98 | end |
98 | 99 | end |
99 | 100 |
@@ -183,6 +184,7 @@ module SSTP | ||
183 | 184 | end |
184 | 185 | |
185 | 186 | def handle_notify(version) |
187 | + script_odict = {} | |
186 | 188 | if not check_decoder() |
187 | 189 | return |
188 | 190 | end |
@@ -239,7 +241,7 @@ module SSTP | ||
239 | 241 | if not local_request() |
240 | 242 | parser = Script::Parser.new |
241 | 243 | nodes = [] |
242 | - while 1 | |
244 | + while true | |
243 | 245 | begin |
244 | 246 | nodes.concat(parser.parse(script)) |
245 | 247 | rescue #except ninix.script.ParserError as e: |
@@ -109,11 +109,11 @@ module SSTPLib | ||
109 | 109 | if not match |
110 | 110 | @equestline = '-' |
111 | 111 | send_error(400, :message => 'Bad Request ' + requestline.to_s) |
112 | - return 0 | |
112 | + return false | |
113 | 113 | end |
114 | 114 | @command, @version = match[1, 2] |
115 | 115 | @headers = parse_headers() |
116 | - return 1 | |
116 | + return true | |
117 | 117 | end |
118 | 118 | |
119 | 119 | def handle(line) |
@@ -197,16 +197,19 @@ module Ninix_Main | ||
197 | 197 | @parent = parent |
198 | 198 | end |
199 | 199 | |
200 | - def handle_request(event_type, event, *arglist, **argdict) | |
200 | + def handle_request(event_type, event, *arglist) | |
201 | 201 | #assert ['GET', 'NOTIFY'].include?(event_type) |
202 | 202 | handlers = { |
203 | 203 | } |
204 | - handler = handlers.get(event, getattr(self, event, nil)) | |
205 | - if handler == nil | |
206 | - result = self.request_parent( | |
207 | - event_type, event, *arglist, **argdict) | |
204 | + if not handlers.include?(event) | |
205 | + if SSTPControler.method_defined?(event) | |
206 | + result = method(event).call(*arglist) | |
207 | + else | |
208 | + result = @parent.handle_request( | |
209 | + event_type, event, *arglist) | |
210 | + end | |
208 | 211 | else |
209 | - result = handler(*arglist, **argdict) | |
212 | + result = method(handlers[event]).call(*arglist) | |
210 | 213 | end |
211 | 214 | if event_type == 'GET' |
212 | 215 | return result |
@@ -251,19 +254,19 @@ module Ninix_Main | ||
251 | 254 | end |
252 | 255 | event, script_odict, sender, handle, address, \ |
253 | 256 | show_sstp_marker, use_translator, \ |
254 | - entry_db, request_handler = @__sstp_queue.pop(0) | |
257 | + entry_db, request_handler = @__sstp_queue.shift | |
255 | 258 | working = (event != nil) |
256 | 259 | break_flag = false |
257 | 260 | for if_ghost in script_odict.keys() |
258 | - if if_ghost and request_parent('GET', 'if_ghost', if_ghost, :working => working) | |
259 | - request_parent('NOTIFY', 'select_current_sakura', :if_ghost => if_ghost) | |
261 | + if not if_ghost.empty? and @parent.handle_request('GET', 'if_ghost', if_ghost, :working => working) | |
262 | + @parent.handle_request('NOTIFY', 'select_current_sakura', :if_ghost => if_ghost) | |
260 | 263 | default_script = script_odict[if_ghost] |
261 | 264 | break_flag = true |
262 | 265 | break |
263 | 266 | end |
264 | 267 | end |
265 | 268 | if not break_flag |
266 | - if request_parent('GET', 'get_preference', 'allowembryo') == 0 | |
269 | + if @parent.handle_request('GET', 'get_preference', 'allowembryo') == 0 | |
267 | 270 | if event == nil |
268 | 271 | if request_handler |
269 | 272 | request_handler.send_response(420) # Refuse |
@@ -280,7 +283,7 @@ module Ninix_Main | ||
280 | 283 | end |
281 | 284 | end |
282 | 285 | if event != nil |
283 | - script = request_parent('GET', 'get_event_response', event) | |
286 | + script = @parent.handle_request('GET', 'get_event_response', event) | |
284 | 287 | else |
285 | 288 | script = nil |
286 | 289 | end |
@@ -294,7 +297,7 @@ module Ninix_Main | ||
294 | 297 | return |
295 | 298 | end |
296 | 299 | set_sstp_flag(sender) |
297 | - request_parent( | |
300 | + @parent.handle_request( | |
298 | 301 | 'NOTIFY', 'enqueue_script', |
299 | 302 | event, script, sender, handle, address, |
300 | 303 | show_sstp_marker, use_translator, :db => entry_db, |
@@ -303,15 +306,21 @@ module Ninix_Main | ||
303 | 306 | end |
304 | 307 | |
305 | 308 | def receive_sstp_request |
306 | - begin | |
307 | - for sstp_server in self.sstp_servers | |
308 | - sstp_server.handle_request() | |
309 | + for sstp_server in @sstp_servers | |
310 | + begin | |
311 | + socket = sstp_server.accept_nonblock | |
312 | + rescue | |
313 | + next | |
314 | + #rescue # except socket.error as e: | |
315 | + #code, message = e.args | |
316 | + #logging.error('socket.error: {0} ({1:d})'.format(message, code)) | |
317 | + #rescue # except ValueError: # may happen when ninix is terminated | |
318 | + #return | |
309 | 319 | end |
310 | - rescue # except socket.error as e: | |
311 | - #code, message = e.args | |
312 | - #logging.error('socket.error: {0} ({1:d})'.format(message, code)) | |
313 | - rescue # except ValueError: # may happen when ninix is terminated | |
314 | - return | |
320 | + handler = SSTP::SSTPRequestHandler.new(sstp_server, socket) | |
321 | + buffer = socket.gets | |
322 | + handler.handle(buffer) | |
323 | + socket.close | |
315 | 324 | end |
316 | 325 | end |
317 | 326 |
@@ -331,14 +340,14 @@ module Ninix_Main | ||
331 | 340 | def start_servers |
332 | 341 | for port in @sstp_port |
333 | 342 | begin |
334 | - server = SSTP.SSTPServer.new(port) | |
343 | + server = SSTP::SSTPServer.new(port) | |
335 | 344 | rescue # except socket.error as e: |
336 | 345 | #code, message = e.args |
337 | 346 | #logging.warning( |
338 | 347 | # 'Port {0:d}: {1} (ignored)'.format(port, message)) |
339 | 348 | next |
340 | 349 | end |
341 | - server.set_responsible(self.handle_request) | |
350 | + server.set_responsible(self) | |
342 | 351 | @sstp_servers << server |
343 | 352 | #logging.info('Serving SSTP on port {0:d}'.format(port)) |
344 | 353 | end |
@@ -544,7 +553,7 @@ module Ninix_Main | ||
544 | 553 | if plugin_module == nil |
545 | 554 | return |
546 | 555 | end |
547 | - port = self.request_parent('GET', 'get_sstp_port') | |
556 | + port = @parent.handle_request('GET', 'get_sstp_port') | |
548 | 557 | queue = multiprocessing.JoinableQueue() |
549 | 558 | if not @data.include?(plugin_dir) |
550 | 559 | @data[plugin_dir] = load_data(plugin_dir) |
@@ -1269,7 +1278,7 @@ module Ninix_Main | ||
1269 | 1278 | instance_list = [] |
1270 | 1279 | for value in @ghosts.values() |
1271 | 1280 | if value.instance != nil |
1272 | - instance_list << value | |
1281 | + instance_list << value.instance | |
1273 | 1282 | end |
1274 | 1283 | end |
1275 | 1284 | for sakura in instance_list |