def serve( sock )
command_list = []
in_cmd_list = false
in_ok_list = false
the_error = nil
sock.puts 'OK MPD 0.11.5'
begin
while line = sock.gets
args = build_args line
cmd = args.shift
if cmd == 'command_list_begin' and args.length == 0 and !in_cmd_list
in_cmd_list = true
log 'MPD: Starting Command List' if audit
elsif cmd == 'command_list_ok_begin' and args.length == 0 and !in_cmd_list
in_cmd_list = true
in_ok_list = true
log 'MPD: Starting Command OK List' if audit
elsif cmd == 'command_list_end' and in_cmd_list
log 'MPD: Running Command List' if audit
the_ret = true
command_list.each_with_index do |set,i|
the_ret = do_cmd sock, set[0], set[1]
if audit
log "MPD Command List: CMD ##{i}: \"#{set[0]}(#{set[1].join(', ')})\": " + (the_ret ? 'successful' : 'failed')
end
break unless the_ret
sock.puts 'list_OK' if in_ok_list
end
sock.puts 'OK' if the_ret
command_list.clear
in_cmd_list = false
in_ok_list = false
else
if in_cmd_list
command_list << [cmd, args]
else
ret = do_cmd sock, cmd, args
sock.puts 'OK' if ret
if audit
log "MPD Command \"#{cmd}(#{args.join(', ')})\": " + (ret ? 'successful' : 'failed')
end
end
end
end
rescue
end
end