Re: Free CDDB

Gary D. Foster (Gary.Foster nospam at Corp.Sun.COM)
10 Mar 1999 13:13:02 -0800

Ok, in the interest of "put up working code or shut the hell up",
here's my contribution. I emailed this to a few people, but I'm
getting more requests so I figured what the hell, I'd just post it.
I'm sorry I don't have a web server or FTP space right at hand just
now to post it on.

I'm leaving for the day (meeting-itis is rearing its ugly head) but
here's some really ugly and hacked together perl code to handle cddb
query requests. It passes them off to a cddb server and should work
against the older versions. It should be a drop-in replacement for
the cddb.cgi scripts that cddb.org uses, although I haven't seen the
code and have only written something that seems to work based on their
published howto's and such. It takes a request, makes sure it's
reasonably valid, and then opens a connection to another cddb server
(in the test implementation, it's running on localhost...) and returns
the responses.

Please rip it apart, test it out, and provide me with feedback,
patches, etc. I'll be back in tomorrow and will bring a pair of
asbestos underwear with me.

DISCLAIMER!!!

This was implemented in clean room fashion using published documents
at the cddb.org website. I have seen no actual code except the
published older GPL'd versions of the CDDB server and have done
nothing except test query responses against working servers and my own
CGI script to make sure they match where appropriate. If escient
wants to sue me, they'd better pack a lunch.

This work is my own and my employer should not be held responsible for
it if it is used for any purpose, including but not limited to
starting a nuclear war which ends civilization as we know it.

-- Gary F.

--- begin cddb.pl ---
#!/usr/local/bin/perl

# Quick and dirty script to gateway http requests to CDDDB lookups
# Written by Gary D. Foster <fosterg nospam at earthlink.net>
# Date: March 10, 1999
# Distribution terms: GPL version 2

use CGI qw/:standard :html3 :shortcuts/;
use Net::TCP;

$cddb_server="localhost";
$cddb_port="888";

sub error;

autoEscape(undef);

unless ( param() ) {
my $error_text="510 Command syntax error, explanation follows (until terminating `.')\n".
"You have reached the Free CDDB server in HTTP mode.\n".
"This URL is intended for CDDB-compatible client applications only ".
"and not for direct use.\n\n".
"If you are testing connectivity in HTTP mode, you have succeeded.";
error($error_text);
};

unless (
param('cmd') &&
param('hello') &&
param('proto') ) {
error('500 Command syntax error: incorrect arguments');
};

# Ok, we got the right number of commands, let's go ahead and toss them at
# the local CD database server using the cddp protocol

# First, tie the connection

tie $x,Net::TCP,$cddb_server,$cddb_port or error('500 Connect Error');

$foo=$x; # get the connect banner

# Throw the hello and the proto commands at the server

$bar=param('hello');

$x="cddb hello $bar\n";

$response=$x;

error($response) unless $response=~/^2/;

# Throw the proto command at the server

$bar=param('proto');
$x="proto $bar\n";

$response=$x;

error($response) unless $response=~/^2/;

# throw the real command at the server

$bar=param('cmd');
$x="$bar\n";
$response=$x;

error($response) unless $response=~/^2/;

$entry=$response;

until ($foo =~ /^\./) {
$foo=$x;
$entry.=$foo;
}

untie $x;

error($entry);

sub error {
my $error_text=shift;
print header('text/plain'),
$error_text;
exit;
}
--- end cddb.pl ---