class CTI::Driver
- Version
-
$Id: Driver.rb 902 2013-04-23 05:07:04Z miyabe $
ドライバクラスです。通常は直接使用する必要はありません。代わりに CTI#get_session メソッドを使用してください。
Public Instance Methods
Source
# File src/code/CTI/Driver.rb 21 def get_session(uri, options = {}, &block) 22 # uriの解析 23 host = 'localhost' 24 port = 8099 25 ssl = false 26 if /^ctips:\/\/([^:\/]+):([0-9]+)\/?$/ =~ uri then 27 ssl = true 28 host = $1 29 port = $2.to_i 30 elsif /^ctips:\/\/([^:\/]+)\/?$/ =~ uri then 31 ssl = true 32 host = $1 33 elsif /^ctip:\/\/([^:\/]+):([0-9]+)\/?$/ =~ uri then 34 host = $1 35 port = $2.to_i 36 elsif /^ctip:\/\/([^:\/]+)\/?$/ =~ uri then 37 host = $1 38 end 39 40 io = TCPSocket.open(host, port) 41 if ssl 42 # TLSを使う場合 43 # 44 # **証明書を検証し、SNIを送る。**素の SSLSocket.new(io) は 45 # 検証を一切しない(VERIFY_NONE)ので、TLSにしても相手が誰かを 46 # 確かめないまま話すことになる。SNIも送らないため、名前で証明書を 47 # 選ぶ中継(Traefik など)からは既定の自己署名証明書が返ってくる。 48 require 'openssl' 49 ctx = OpenSSL::SSL::SSLContext.new 50 ctx.set_params # 既定のCAと VERIFY_PEER を入れる 51 # 試験用の逃げ道: options の 'insecure' が真なら証明書を検証しない 52 # (自己署名の試験サーバー向け。本番では相手が誰かを確かめないまま 53 # 話すことになるので使わない。他言語版の Java --insecure / .NET ?insecure=1 / 54 # Node.js rejectUnauthorized:false に相当。2026-09-20) 55 insecure = [true, 'true', '1', 1].include?(options['insecure'] || options[:insecure]) 56 ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE if insecure 57 io = OpenSSL::SSL::SSLSocket.new(io, ctx) 58 io.hostname = host # SNI 59 io.sync_close = true 60 io.connect 61 io.post_connection_check(host) unless insecure # 証明書の名前がホストと一致するか 62 end 63 session = Session.new(io, options) 64 if block 65 # ブロック実行 66 begin 67 block.call(session) 68 ensure 69 session.close() 70 end 71 else 72 return session 73 end 74 end
指定されたURIに接続し、セッションを返します。
- uri
-
接続先アドレス
- options
-
接続オプション
- 返り値
-
CTI::Sessionオブジェクト