533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
|
# File 'lib/freedb.rb', line 533
def send_cmd(cmd, args)
case cmd
when "hello"
a = args.split(" ")
@res << "200 Hello and welcome #{a[0]}@#{a[1]} running #{a[2]} #{a[3]}."
when "query"
discid = args.split(" ")[0]
match = []
if @win
good_line = "#FILENAME=#{discid}\n"
find_files_win(discid).each do |f, categ|
content = []
catch(:finish) do
started = false
File.foreach(f) do |line|
if line == good_line
started = true
elsif started
if line =~ /^#FILENAME=/
match << categ + " " + discid + " " + disc_name(content)
@temp_results[categ] = content
throw(:finish)
end
content << line
end
end
end
end
else
@categs.each do |dir, categ|
filename = File.join(dir, discid)
if File.file?(filename)
@temp_results[categ] = File.readlines(filename)
match << categ + " " + discid + " " + disc_name(@temp_results[categ])
end
end
end
if match.size == 1
@res << "200 #{match[0]}"
elsif match.size > 1
@res << "211 Multiple match found"
match.each { |m|
@res << m
}
@res << "."
else
@res << "202 No match found"
end
when "read"
categ, discid = args.split(" ")
@res << "210 #{categ} #{discid}"
if @win
lines = @temp_results[categ]
else
filename = File.join(@basedir, categ, discid)
lines = File.readlines(filename)
end
@res.concat(lines.collect { |l| l.chop })
@res << "."
when "proto"
@res << "200 CDDB protocol level: current #{PROTO_LEVEL}, supported #{PROTO_LEVEL}"
else
@res << "501"
end
end
|