This file is indexed.

/usr/lib/ruby/1.8/ecasound.rb is in libecasound-ruby1.8 2.8.1-5build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# This is a native implementation of Ecasound's control interface for Ruby.
# Copyright (C) 2003 - 2004  Jan Weil <jan.weil@web.de>
# 
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
# ---------------------------------------------------------------------------
=begin
= ruby-ecasound

Example:

require "ecasound"
eci = Ecasound::ControlInterface.new(ecasound_args)
ecasound-response = eci.command("iam-command-here")
...

TODO:
Is there a chance that the ecasound process gets zombified?

=end

require "timeout"
require "thread"

class File
    def self::which(prog, path=ENV['PATH'])
        path.split(File::PATH_SEPARATOR).each do |dir|
            f = File::join(dir, prog)
            if File::executable?(f) && ! File::directory?(f)
                return f
            end
        end
    end
end # File

class VersionString < String
    attr_reader :numbers

    def initialize(str)
        if str.split(".").length() != 3
            raise("Versioning scheme must be major.minor.micro")
        end
        super(str)
        @numbers = []
        str.split(".").each {|s| @numbers.push(s.to_i())}
    end
    
    def <=>(other)
        numbers.each_index do |i|
            if numbers[i] < other.numbers[i]
                return -1
            elsif numbers[i] > other.numbers[i]
                return 1
            elsif i < 2
                next
            end
        end
        return 0
    end
end # VersionString

module Ecasound

REQUIRED_VERSION = VersionString.new("2.2.0")
TIMEOUT = 15 # seconds before sync is called 'lost'

class EcasoundError < RuntimeError; end
class EcasoundCommandError < EcasoundError
    attr_accessor :command, :error
    def initialize(command, error)
        @command = command
        @error = error
    end
end

class ControlInterface
    @@ecasound = ENV['ECASOUND'] || File::which("ecasound")
    
    if not File::executable?(@@ecasound.to_s)
        raise("ecasound executable not found")
    else
        @@version = VersionString.new(`#{@@ecasound} --version`.split("\n")[0][/\d\.\d\.\d/])
        if @@version < REQUIRED_VERSION
            raise("ecasound version #{REQUIRED_VERSION} or newer required, found: #{@@version}")
        end
    end
    
    def initialize(args = nil)
        @mutex = Mutex.new()
        @ecapipe = IO.popen("-", "r+") # fork!
        
        if @ecapipe.nil?
            # child
            $stderr.reopen(open("/dev/null", "w"))
            exec("#{@@ecasound} #{args.to_s} -c -D -d:256 ")
        else
            @ecapipe.sync = true
            # parent
            command("int-output-mode-wellformed")
        end
    end

    def cleanup()
        @ecapipe.close()
    end

    def command(cmd)
        @mutex.synchronize do
            cmd.strip!()
            #puts "command: #{cmd}"
            
            @ecapipe.write(cmd + "\n")

            # ugly hack but the process gets stuck otherwise -kvehmanen
            if cmd == "quit"
                return nil
            end

            response = ""
            begin
                # TimeoutError is raised unless response is complete
                timeout(TIMEOUT) do
                    loop do
                        response += read()
                        break if response =~ /256 ([0-9]{1,5}) (\-|i|li|f|s|S|e)\r\n(.*)\r\n\r\n/m
                    end
                end
            rescue TimeoutError
                raise(EcasoundError, "lost synchronisation to ecasound subprocess\nlast command was: '#{cmd}'")
            end
            
            content = $3[0, $1.to_i()]

            #puts "type: '#{$2}'"
            #puts "length: #{$1}"
            #puts "content: #{content}"

            case $2
                when "e"
                    raise(EcasoundCommandError.new(cmd, content))
                when "-"
                    return nil
                when "s"
                    return content
                when "S"
                    return content.split(",")
                when "f"
                    return content.to_f()
                when "i", "li"
                    return content.to_i()
                else
                    raise(EcasoundError, "parsing of ecasound's output produced an unknown return type")
            end
        end
    end

    private

    def read()
        buffer = ""
        while select([@ecapipe], nil, nil, 0)
            buffer += @ecapipe.read(1) || ""
        end
        return buffer
    end
end # ControlInterface

end # Ecasound::