Net-FreeDB-0.10/0000755000175000017500000000000012417546133011431 5ustar dxsdxsNet-FreeDB-0.10/FreeDB.xs.win320000755000175000017500000000304012417531137014033 0ustar dxsdxs// Copyright (c) 2014 David J. Shultz // This software is covered by the GPL. #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "lib/discid.h" #include #include static int not_here(char *s) { croak("%s not implemented on this architecture", s); return -1; } static double constant(char *name, int len, int arg) { errno = EINVAL; return 0; } MODULE = Net::FreeDB PACKAGE = Net::FreeDB double constant(sv,arg) PREINIT: STRLEN len; INPUT: SV * sv char * s = SvPV(sv, len); int arg CODE: RETVAL = constant(s,len,arg); OUTPUT: RETVAL char* xs_discid(int driveNo) INIT: char id[30]; CODE: sprintf(id, "%08x", discid(driveNo)); RETVAL = id; OUTPUT: RETVAL SV* xs_discinfo(int driveNo) INIT: int i; char id[30]; struct discdata data; HV* hash = newHV(); AV* tracks = newAV(); PPCODE: data = get_disc_id(driveNo); for (i = 0; i < (data.num_of_trks); i++) { av_push(tracks, newSVnv(data.track_offsets[i])); } sprintf(id, "%08x", (unsigned int)data.discid); hv_store(hash, "ID", 2, newSVpv(id, 0), 0); hv_store(hash, "NUM_TRKS", 8, newSVnv(data.num_of_trks), 0); hv_store(hash, "TRACKS", 6, newRV_inc((SV*)tracks), 0); hv_store(hash, "SECONDS", 7, newSVnv(data.seconds), 0); XPUSHs(newRV((SV*)hash)); int getNumDrives() INIT: int numDrives; CODE: initTool(); numDrives = getNumDrives(); RETVAL = numDrives; OUTPUT: RETVAL Net-FreeDB-0.10/Changes0000755000175000017500000000273712417531377012744 0ustar dxsdxsRevision history for Perl extension Net::FreeDB. 0.10 Tue Oct 14 09:33:00 2014 - Major rewrite, interface is NOT backward compatible - Fixed many issues that caused most of the funtionality to not work - Is now CDDB Protocol Level 6 compliant, this includes many new methods - Code no longer requires regular expressions to parse data, is much more sane 0.09 Mon Oct 13 13:26:00 2014 - Applied patch for FreeBSD from Daniel Lintott for kFreeBSD-* systems - Applied patch for FreeBSD from Gregor Herrmann to disable some tests when no net access is available - Applied patch to fix POD error from Gregor Herrmann 0.08 Thu Sep 28 11:02:51 2006 - Fix the use of CDDB::File in the read() method. Reported by Kaloyan Dimitrov - Remove an unreferenced variable in the XS files. Closes: CPAN RT #4191 - Add the Changes file to the packing manifest. 0.07 Tue Jan 3 15:57:08 2006 - Add FreeBSD support various minor cleanups release as 0.07 by Peter Pentchev after e-mail silence by David Shultz for a couple of months 0.06 Tue Feb 26 10:27:00 2002 - Merging query and inexact methods changing return of query method to return an array of hashes 0.05 Wed Feb 20 12:00:00 2002 - Various changes including adding CDDB::File support more tests for method and static calls and various bug fixes 0.01 Wed Aug 1 11:28:11 2001 - original version; created by h2xs 1.21 with options -n Net::FreeDB -d -x discid.h Net-FreeDB-0.10/FreeDB.pm0000755000175000017500000004327312417546101013065 0ustar dxsdxspackage Net::FreeDB; use Moo; use Net::FreeDBConnection; use Net::Cmd qw/CMD_OK CMD_MORE/; use CDDB::File; use File::Temp; has hostname => (is => 'ro', default => $ENV{HOSTNAME} // 'unknown'); has remote_host => (is => 'rw', default => 'freedb.freedb.org'); has remote_port => (is => 'rw', default => 8880); has user => (is => 'rw', default => $ENV{USER} // 'unknown'); has timeout => (is => 'rw', default => 120); has debug => (is => 'rw', default => 0); has current_protocol_level => (is => 'rw'); has max_protocol_level => (is => 'rw'); has obj => (is => 'rw', lazy => 1, builder => '_create_obj'); has error => (is => 'rw'); require DynaLoader; extends 'DynaLoader'; our $VERSION = '0.10'; bootstrap Net::FreeDB $VERSION; sub _create_obj { my $self = shift; my $obj = Net::FreeDBConnection->new( PeerAddr => $self->remote_host, PeerPort => $self->remote_port, Proto => 'tcp', Timeout => $self->timeout, ); if ($obj) { my $res = $obj->response(); if ($res == CMD_OK) { $obj->debug($self->debug); if ($obj->command(join(' ', ("CDDB HELLO ", $self->user, $self->hostname, ref($self), $self->VERSION)))) { my $response_code = $obj->response(); if ($response_code != CMD_OK) { $self->error($obj->message()); } } } else { $obj = undef; } } return $obj; } sub lscat { my $self = shift; my @categories = (); if ($self->_run_command('CDDB LSCAT') == CMD_OK) { my $data = $self->_read(); if ($data) { map { my $line = $_; chomp($line); push @categories, $line; } @$data; } } return @categories; } sub query { my $self = shift; my @results = (); if ($self->_run_command('CDDB QUERY', @_) == CMD_OK) { if ($self->obj->code() == 200) { my $data = $self->obj->message(); push @results, _query_line_to_hash($data); } elsif ($self->obj->code() == 211) { my $lines = $self->_read(); foreach my $line (@$lines) { push @results, _query_line_to_hash($line); } } } return @results; } sub read { my $self = shift; my $result = undef; if ($self->_run_command('CDDB READ', @_) == CMD_OK) { my $data = $self->_read(); my $fh = File::Temp->new(); print $fh join('', @$data); seek($fh, 0, 0); my $cddb_file_obj = CDDB::File->new($fh->filename); $fh->close; $result = $cddb_file_obj; } return $result; } sub unlink { my $self = shift; my $response = undef; if ($self->_run_command('CDDB UNLINK', @_) == CMD_OK) { $response = 1; } return $response; } sub write { my $self = shift; my $response = undef; my $category = shift; my $disc_id = shift; if ($self->_run_command('CDDB WRITE', $category, $disc_id) == CMD_MORE) { if ($self->_run_command(@_, ".\n") == CMD_OK) { $response = 1; } } return $response; } sub discid { my $self = shift; my $response = undef; if ($self->_run_command('DISCID', @_) == CMD_OK) { $response = $self->obj->message(); chomp($response); my (undef, undef, undef, $disc_id) = split(/\s/, $response); $response = $disc_id; } return $response; } sub get { my $self = shift; my $filename = shift; my $file_contents = undef; if ($self->_run_command('GET', $filename) == CMD_OK) { $file_contents = $self->_read(); } return $file_contents; } sub log { my $self = shift; my @log_lines = (); if ($self->_run_command('LOG -l', @_) == CMD_OK) { my $lines = $self->_read(); foreach my $line (@$lines) { chomp($line); push @log_lines, $line; } } return @log_lines; } sub motd { my $self = shift; my @motd = (); if ($self->_run_command('MOTD') == CMD_OK) { push @motd, $self->obj->message(); my $lines = $self->_read(); foreach my $line (@$lines) { chomp($line); push @motd, $line; } } return @motd; } sub proto { my $self = shift; my ($current_level, $max_level); if ($self->_run_command("PROTO", @_) == CMD_OK) { my $message = $self->obj->message(); if ($message =~ /OK/) { $message =~ /OK, CDDB protocol level now: (\d)/; $self->current_protocol_level($1); } else { $message =~ /CDDB protocol level: current (\d), supported (\d)/; $self->current_protocol_level($1); $self->max_protocol_level($2); } } return $self->current_protocol_level(); } sub put { my $self = shift; my $type = shift; if ($self->_run_command('PUT', $type) == CMD_MORE) { $self->obj->datasend(@_); } } sub quit { my $self = shift; $self->_run_command('QUIT'); } sub sites { my $self = shift; my @sites = (); if ($self->_run_command('SITES') == CMD_OK) { my $lines = $self->_read(); foreach my $line (@$lines) { chomp($line); my ($hostname, $port, $latitude, $longitude, $description) = split(/\s/, $line, 5); push @sites, { hostname => $hostname, port => $port, latitude => $latitude, longitude => $longitude, description => $description, }; } } return @sites; } sub stat { my $self = shift; my $response = {}; if ($self->_run_command('STAT') == CMD_OK) { my $lines = $self->_read(); foreach my $line (@$lines) { chomp($line); my ($key, $value) = split(/:/, $line); if ($key && $value) { $key =~ s/\s*(.+)\s*/$1/; $value =~ s/\s*(.+)\s*/$1/; $response->{$key} = $value; } } } return $response; } sub update { my $self = shift; my $response = undef; if ($self->_run_command('UPDATE') == CMD_OK) { $response = 1; } return $response; } sub validate { my $self = shift; my $response = undef; if ($self->_run_command('VALIDATE') == CMD_MORE) { if ($self->run_command(@_ . "\n") == CMD_OK) { $response = 1; } } return $response; } sub ver { my $self = shift; my $response = undef; if ($self->_run_command('VER') == CMD_OK) { $response = $self->obj->message(); } return $response; } sub whom { my $self = shift; my @users = (); if ($self->_run_command('WHOM') == CMD_OK) { my $lines = $self->_read(); foreach my $line (@$lines) { chomp($line); push @users, $line; } } return @users; } sub get_local_disc_id { my $self = shift; my $device = shift; my $disc_id = undef; if ($device) { $disc_id = xs_discid($device); if ($disc_id eq 'UNDEF' || $disc_id eq '') { $self->error('Drive Error: no disc found'); $disc_id = undef; } } return $disc_id; } sub get_local_disc_data { my $self = shift; my $device = shift; my $disc_data = undef; if ($device) { $disc_data = xs_discinfo($device); if (!$disc_data) { $self->error('Drive Error: no disc found'); } } return $disc_data; } sub _read { my $self = shift; my $data = $self->obj->read_until_dot or return undef; return $data; } sub _query_line_to_hash { my $line = shift; chomp($line); my ($category, $disc_id, $the_rest) = split(/\s/, $line, 3); my ($artist, $album) = split(/\s\/\s/, $the_rest); return { Category => $category, DiscID => $disc_id, Artist => $artist, Album => $album, }; } sub _run_command { my ($self, @arguments) = @_; my $response_code = undef; if ($self->obj->command(@arguments)) { $response_code = $self->obj->response(); if ($response_code != CMD_OK) { my $error = $self->obj->message(); chomp($error); $self->error($error); } } return $response_code; } 1; __END__ =head1 NAME Net::FreeDB - Perl interface to freedb server(s) =head1 SYNOPSIS use Net::FreeDB; $freedb = Net::FreeDB->new(); $discdata = $freedb->getdiscdata('/dev/cdrom'); my $cddb_file_object = $freedb->read('rock', $discdata->{ID}); print $cddb_file_object->id; =head1 DESCRIPTION Net::FreeDB was inspired by Net::CDDB. And in-fact was designed as a replacement in-part by Net::CDDB's author Jeremy D. Zawodny. Net::FreeDB allows an oop interface to the freedb server(s) as well as some basic cdrom functionality like determining disc ids, track offsets, etc. =head2 METHODS =over =item new(remote_host => $h, remote_port => $p, user => $u, hostname => $hn, timeout => $to) Constructor: Creates a new Net::FreeDB object. Parameters: Set to username or user-string you'd like to be logged as. Defaults to $ENV{USER} HOSTNAME: (optional) Set to the hostname you'd like to be known as. Defaults to $ENV{HOSTNAME} TIMEOUT: (optional) Set to the number of seconds to timeout on freedb server. Defaults to 120 new() creates and returns a new Net::FreeDB object that is connected to either the given host or freedb.freedb.org as default. =item lscat Returns a list of all available categories on the server. Sets $obj->error on error =item query($id, $num_trks, $trk_offset1, $trk_offset2, $trk_offset3...) Parameters: query($$$...) takes: 1: a discid 2: the number of tracks 3: first track offset 4: second track offset... etc. Query expects $num_trks number of extra params after the first two. query() returns an array of hashes. The hashes looks like: { Category => 'newage', DiscID => 'discid', Artist => 'artist', Album => 'title' } Sets $obj->error on error NOTE: query() can return 'inexact' matches and/or 'multiple exact' matches. The returned array is the given returned match(es). =item read($server_category_string, $disc_id) Parameters: read($$) takes 2 parameters, the first being a server category name. This can be any string either that you make up yourself or that you believe the disc to be. The second is the disc id. This may be generated for the current cd in your drive by calling get_local_disc_id() Sets $obj->error on error NOTE: Using an incorrect category will result in either no return or an incorrect return. Please check the CDDB::File documentation for information on this module. read() requests a freedb record for the given information and returns a CDDB::File object. =item unlink($server_category_string, $disc_id) Parameters: 1: a server category name 2: a valid disc_id This will delete the given entry on the server (if you have permission). Check the docs for the read() method to get more information on the parameters. Sets $obj->error on error. =item write($server_category_string, $disc_id, $cddb_formatted_data) Parameters: 1: a server category name 2: a valid disc_id 3: a properly formatted array of lines from a cddb file Returns true on success, otherwise $obj->error will be set. =item discid($number_of_tracks, $track_1_offset, $track_2_offset, ..., $total_number_of_seconds_of_disc) Parameters: 1: The total number of tracks of the current disc 2: An array of the track offsets in seconds 3: The total number of seconds of the disc. Returns a valid disc_id if found, otherwise $obj->error will be set. =item get($filename) Parameters: 1: The filename to retrieve from the server. Returns a scalar containing raw file contents. Returns $obj->error on error. =item log($number_of_lines_per_section, start_date, end_date, 'day', $number_of_days, 'get') Parameters: 1: The number of lines per section desired 2: (Optional) A date after which statistics should be calculated in the format of hh[mm[ss[MM[DD[[CC]YY]]]]] 3: (Optional) Must pass a start_date if passing this. A date after start date at which time statistics to not be calculated in the format of hh[mm[ss[MM[DD[[CC]YY]]]]] 4: (Optional) The string 'day' to indicate that statistics should be calcuated for today. 5: (Optional) A number of days to be calculated, default is 1 6: (Optional) The string 'get' which will cause the log data to be recorded on the server's machine. NOTE: You must provide at least one of the optional options (2,3,4). Sets $obj->error on error. =item motd Parameters: None Returns the message of the day as a string. Sets $obj->error on error. =item proto($desired_protocol_level) Parameters: (Optional) The desired protocol level as a number. When called with NO parameters, will set the current and maximum allowed procotol levels, when called with a desired protocol level it will be set, $obj->errror will be set if an error occurs. Returns the currently selected protocol level. =item put($type, $file) Parameters: 1: type is either sites or motd 2: based on param 1, an array of lines, either a list of mirror sites or a new message of the day Assuming you have permission to do so the server content will be updated. Sets $obj->error on error. =item quit Parameters: None Disconnects from the server. =item sites() Parameters: None sites() returns an array reference of urls that can be used as a new remote_host. =item stat Parameters: None Returns undef on error (and sets $obj->error). Otherwise returns a hashref where the keys/values are: max proto => An integer representing the server's current operating protocol level. gets => The maximum protocol level. updates => Whether or not the client is allowed to initiate a database update. posting => Whether or not the client is allowed to post new entries. quotes => Whether or not quoted arguments are enabled. current users => The number of users currently connected to the server. max users => The number of users that can concurrently connect to the server. strip ext => Whether or not extended data is stripped by the server before presented to the user. Database entries => The total number of entries in the database. The total number of entries in the database by category. =item update Parameters: None Tells the server to update the database (if you have permission). Sets $obj->error on error. =item validate($validating_string) Parameters: 1: A string to be validated. If you have permission, given a string the server will validate the string as valid for use in a write call or not. Sets $obj->error on error. =item ver Parameters: None Returns a string of the server's version. =item whom Parameters: None If you have permission, returns a list of usernames of all connected users. Sets $obj->error on error. =item get_local_disc_id Parameters: getdiscid($) takes the device you want to use. Basically this means '/dev/cdrom' or whatever on linux machines but it's an array index in the number of cdrom drives on windows machines starting at 0. (Sorry, I may change this at a later time). So, if you have only 1 cdrom drive then getdiscid(0) would work fine. getdiscid() returns the discid of the current disc in the given drive. NOTE: See BUGS =item get_local_disc_data Parameters: getdiscdata($) takes the device you want to use. See getdiscid() for full description. getdiscdata() returns a hash of the given disc data as you would require for a call to query. The returns hash look like: { ID => 'd00b3d10', NUM_TRKS => '3', TRACKS => [ '150', '18082', '29172' ], SECONDS => '2879' } NOTE: A different return type/design may be developed. =back =head1 BUGS The current version of getdiscid() and getdiscdata() on the Windows platform takes ANY string in a single cdrom configuration and works fine. That is if you only have 1 cdrom drive; you can pass in ANY string and it will still scan that cdrom drive and return the correct data. If you have more then 1 cdrom drive giving the correct drive number will return in an accurate return. =head1 Resources The current version of the CDDB Server Protocol can be found at: http://ftp.freedb.org/pub/freedb/latest/CDDBPROTO =head1 AUTHOR David Shultz Edshultz@cpan.orgE Peter Pentchev Eroam@ringlet.netE =head1 CREDITS Jeremy D. Zawodny Ejzawodn@users.sourceforge.netE Pete Jordon Eramtops@users.sourceforge.netE =head1 COPYRIGHT Copyright (c) 2002, 2014 David Shultz. Copyright (c) 2005, 2006 Peter Pentchev. All rights reserved. This program is free software; you can redistribute it and/or modify if under the same terms as Perl itself. =cut Net-FreeDB-0.10/lib/0000755000175000017500000000000012417546133012177 5ustar dxsdxsNet-FreeDB-0.10/lib/linux.h0000755000175000017500000001006212417527117013512 0ustar dxsdxs /********************************************* NAME: linux.h FUNCTION: linux based cddb id generation code CREATED BY: David Shultz CREATED ON: 08/03/2001 *********************************************/ #ifndef LINUX_H #define LINUX_H struct toc { int min, sec, frame; } cdtoc[100]; struct discdata { unsigned long discid; int num_of_trks; int track_offsets[100]; int seconds; }; unsigned int cddb_sum(int n) { unsigned int ret; ret = 0; while (n > 0) { ret += (n % 10); n /= 10; } return ret; } unsigned long cddb_discid(int tot_trks) { unsigned int i = 0; unsigned int t = 0; unsigned int n = 0; while (i < tot_trks) { n = n + cddb_sum((cdtoc[i].min * 60) + cdtoc[i].sec); i++; } t = ((cdtoc[tot_trks].min * 60) + cdtoc[tot_trks].sec) - ((cdtoc[0].min * 60) + cdtoc[0].sec); return ((n % 0xff) << 24 | t << 8 | tot_trks); } struct discdata get_disc_id(char* dev) { struct discdata data; int i; data.num_of_trks = read_toc(dev); if (data.num_of_trks == -1) { return data; } data.discid = cddb_discid(data.num_of_trks); for (i = 0; i < data.num_of_trks; i++) { data.track_offsets[i] = (cdtoc[i].frame); } data.seconds = (cdtoc[data.num_of_trks].frame)/75; return data; } int read_toc(char* dev) { int drive, i, status; struct cdrom_tochdr tochdr; struct cdrom_tocentry tocentry; drive = open(dev, O_RDONLY | O_NONBLOCK); if (drive == -1) { printf("Device Error: %d\n", errno); return(-1); } status = ioctl(drive, CDROM_DRIVE_STATUS, CDSL_CURRENT); if (status < 0) { printf("Error: Error getting drive status\n"); return(-1); } else { switch(status) { case CDS_DISC_OK: printf("Disc ok, moving on\n"); break; case CDS_TRAY_OPEN: printf("Error: Drive reporting tray open...exiting\n"); close(drive); return(-1); case CDS_DRIVE_NOT_READY: printf("Error: Drive Not Ready...exiting\n"); close(drive); return(-1); default: printf("This shouldn't happen\n"); close(drive); return(-1); } } if (ioctl(drive, CDROMREADTOCHDR, &tochdr) == -1) { switch(errno) { case EBADF: printf("Error: Invalid device...exiting\n"); break; case EFAULT: printf("Error: Memory Write Error...exiting\n"); break; case ENOTTY: printf("Error: Invalid device or Request type...exiting\n"); break; case EINVAL: printf("Error: Invalid REQUEST...exiting\n"); break; case EAGAIN: printf("Error: Drive not ready...exiting\n"); break; default: printf("Error: %d\n", errno); break; } } for (i = tochdr.cdth_trk0; i <= tochdr.cdth_trk1; i++) { tocentry.cdte_track = i; tocentry.cdte_format = CDROM_MSF; ioctl(drive, CDROMREADTOCENTRY, &tocentry); cdtoc[i-1].min = tocentry.cdte_addr.msf.minute; cdtoc[i-1].sec = tocentry.cdte_addr.msf.second; cdtoc[i-1].frame = tocentry.cdte_addr.msf.frame; cdtoc[i-1].frame += cdtoc[i-1].min*60*75; cdtoc[i-1].frame += cdtoc[i-1].sec*75; } tocentry.cdte_track = 0xAA; tocentry.cdte_format = CDROM_MSF; ioctl(drive, CDROMREADTOCENTRY, &tocentry); cdtoc[tochdr.cdth_trk1].min = tocentry.cdte_addr.msf.minute; cdtoc[tochdr.cdth_trk1].sec = tocentry.cdte_addr.msf.second; cdtoc[tochdr.cdth_trk1].frame = tocentry.cdte_addr.msf.frame; cdtoc[tochdr.cdth_trk1].frame += cdtoc[tochdr.cdth_trk1].min*60*75; cdtoc[tochdr.cdth_trk1].frame += cdtoc[tochdr.cdth_trk1].sec*75; close(drive); return tochdr.cdth_trk1; } #endif //LINUX_H Net-FreeDB-0.10/lib/discid.h0000755000175000017500000000202012417525517013607 0ustar dxsdxs/* Modified by David Shultz for Net::FreeDB on 08/01/2001 */ /* Code to get discid for a cddb query. *** Linux Version *** $Id: discid.h,v 1.1 2001/08/08 18:22:12 arnuga Exp $ Copyright (c) 1998-2000 Jeremy D. Zawodny This software is covered by the GPL. Is is based on code found in: To: code-review@azure.humbug.org.au Subject: CDDB database reader From: Byron Ellacott Date: Fri, 5 Jun 1998 17:32:40 +1000 */ /* Stripped net code, 'cause I only care about the discid */ #include #include #ifdef __linux__ #include #include #include #include #include #include #include #include #include #include "linux.h" #endif //__linux__ #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) #include #include "freebsd.h" #endif // __FreeBSD__ || __FreeBSD_kernel__ #ifdef WIN32 #include "win32.h" #endif //WIN32 Net-FreeDB-0.10/lib/win32.h0000755000175000017500000001757012417527114013325 0ustar dxsdxs/******************************** FILE: win32.h Created On: 08/04/2001 Creadted By: David Shultz ********************************/ #ifndef WIN32_H #define WIN32_H #include #include #include #include #include "toctool.h" #include "scsidefs.h" // Variable inits BOOL bInit; INTERFACE interfaces[NUM_INTERFACE]; int iActiveInterface; int iOSVer; DWORD (*GetASPI32SupportInfo)(void); DWORD (*SendASPI32Command)(LPSRB); int numDrives; TOC toc; DRIVELIST driveList; HINSTANCE hDll; struct discdata { unsigned long discid; int num_of_trks; int track_offsets[100]; int seconds; }; // Function defs unsigned long CDDBSum(unsigned long); static int getNumAdapters(void); static int aspiGetNumDrives(void); static int ntGetNumDrives(void); int aspiReadTOC(int, TOC*); void* genCddbQuery(TOC*); // Funcs unsigned long genCddbId(TOC *toc) { unsigned long t, n; TOCTRACK *t1, *t2; int i, numTracks; if (!toc) return 0; t = n = 0; numTracks = (int)(toc->lastTrack - toc->firstTrack + 1); for(i = 0; i < numTracks; i++) { t1 = &(toc->tracks[i]); n += CDDBSum(60 * t1->addr[1] + t1->addr[2]); } t2 = &(toc->tracks[numTracks]); t = 60 * t2->addr[1] + t2->addr[2]; t2 = &(toc->tracks[0]); t -= (60 * t2->addr[1] + t2->addr[2]); return (unsigned long)( ((n % 0xFF) << 24) | (t << 8) | ((unsigned long)numTracks)); } unsigned long CDDBSum(unsigned long n) { unsigned long retVal = 0; while(n > 0) { retVal += (n % 10); n /= 10; } return retVal; } void* genCddbQuery(TOC* toc) { struct discdata* cd = (struct discdata*)malloc(sizeof(struct discdata)); int numTracks, i, ofs; TOCTRACK *t1; if (!toc) return cd; numTracks = (int)(toc->lastTrack - toc->firstTrack + 1); // cddbid cd->discid = genCddbId(toc); // number of tracks cd->num_of_trks = numTracks; // track offsets (not including lead-out) for(i = 0; i < numTracks; i++) { t1 = &(toc->tracks[i]); ofs = (((t1->addr[1] * 60) + t1->addr[2]) * 75) + t1->addr[3]; cd->track_offsets[i] = ofs; } // disc length t1 = &toc->tracks[i]; ofs = t1->addr[1]*60 + t1->addr[2]; cd->seconds = ofs; return (void*)cd; } int getNumDrives(void) { if (!bInit) return 0; return aspiGetNumDrives(); } void getDriveDesc(int driveNo, char *szBuf, int bufLen) { if (!szBuf) return; ZeroMemory(szBuf, bufLen); if (!bInit) return; if (driveNo > driveList.num) return; lstrcpyn(szBuf, driveList.drive[driveNo].a.desc, bufLen); } static int aspiGetNumDrives( void ) { SRB_HAInquiry sh; SRB_GDEVBlock sd; BYTE numAdapters, maxTgt; BYTE i, j, k; int idx = 0; // initialize the drive list; ZeroMemory( &driveList, sizeof(driveList) ); numAdapters = (BYTE)getNumAdapters(); if ( numAdapters == 0 ) return 0; for( i = 0; i < numAdapters; i++ ) { ZeroMemory( &sh, sizeof(sh) ); sh.SRB_Cmd = SC_HA_INQUIRY; sh.SRB_HaID = i; SendASPI32Command( (LPSRB)&sh ); // in case of error, skip to next adapter if ( sh.SRB_Status != SS_COMP ) continue; // determine the max target number for the adapter from offset 3 // if it's zero, then assume the max is 8 maxTgt = sh.HA_Unique[3]; if ( maxTgt == 0 ) maxTgt = 8; for( j = 0; j < maxTgt; j++ ) { // try all 8 values for LUN for( k = 0; k < 8; k++ ) { ZeroMemory( &sd, sizeof(sd) ); sd.SRB_Cmd = SC_GET_DEV_TYPE; sd.SRB_HaID = i; sd.SRB_Target = j; sd.SRB_Lun = k; SendASPI32Command( (LPSRB)&sd ); if ( sd.SRB_Status == SS_COMP ) { if ( sd.SRB_DeviceType == DTYPE_CDROM && driveList.num <= MAX_DRIVE_LIST ) { idx = driveList.num++; driveList.drive[idx].a.ha = i; driveList.drive[idx].a.tgt = j; driveList.drive[idx].a.lun = k; wsprintf( driveList.drive[idx].a.desc, "ASPI[%d:%d:%d]", i, j, k ); } } } } } return driveList.num; } /************************************************************************ * ASPI layer ************************************************************************/ static int getNumAdapters( void ) { DWORD d; BYTE bCount, bStatus; d = GetASPI32SupportInfo(); bCount = LOBYTE(LOWORD(d)); bStatus = HIBYTE(LOWORD(d)); if ( bStatus != SS_COMP && bStatus != SS_NO_ADAPTERS ) return -1; return (int)bCount; } int readTOC(int driveNo, TOC* t) { if (!bInit || (driveNo > driveList.num)) return -1; return aspiReadTOC(driveNo, t); } int aspiReadTOC(int driveNo, TOC* t) { HANDLE hEvent; SRB_ExecSCSICmd s; DWORD dwStatus; if (driveNo > driveList.num) return -2; hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); ZeroMemory(&s, sizeof(s)); s.SRB_Cmd = SC_EXEC_SCSI_CMD; s.SRB_HaID = driveList.drive[driveNo].a.ha; s.SRB_Target = driveList.drive[driveNo].a.tgt; s.SRB_Lun = driveList.drive[driveNo].a.lun; s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY; s.SRB_BufLen = 0x324; s.SRB_BufPointer = (BYTE FAR*)t; s.SRB_SenseLen = 0x0E; s.SRB_CDBLen = 0x0A; s.SRB_PostProc = (LPVOID)hEvent; s.CDBByte[0] = 0x43; s.CDBByte[1] = 0x02; s.CDBByte[7] = 0x03; s.CDBByte[8] = 0x24; ResetEvent(hEvent); dwStatus = SendASPI32Command((LPSRB)&s); if (dwStatus == SS_PENDING) WaitForSingleObject(hEvent, 10000); // wait up to 10 secs. CloseHandle(hEvent); if (s.SRB_Status != SS_COMP) return -3; return 0; } /* * Initialize functions according to whether we're using ASPI (Win95/98) * or the CDROM ioctls (NT/2000); */ int initTool(void) { if (bInit) return 0; ZeroMemory(interfaces, sizeof(interfaces)); lstrcpy(interfaces[INTERFACE_ASPI].name, "ASPI"); iOSVer = getOsVersion(); if (iOSVer == OS_UNKNOWN) return -1; // check if aspi is available hDll = LoadLibrary("WNASPI32.DLL"); GetASPI32SupportInfo = (DWORD(*)(void))GetProcAddress(hDll, "GetASPI32SupportInfo"); SendASPI32Command = (DWORD(*)(LPSRB))GetProcAddress(hDll, "SendASPI32Command"); // make sure that we've got both function addresses if (GetASPI32SupportInfo && SendASPI32Command) { interfaces[INTERFACE_ASPI].avail = TRUE; } bInit = TRUE; return 0; } /* * Returns the current OS system, one of OS_WIN95, OS_WIN98, * OS_WINNT35, OS_WINNT4, OS_WIN2K, or if an error occurs, * OS_UNKNOWN */ int getOsVersion(void) { OSVERSIONINFO os; ZeroMemory(&os, sizeof(os)); os.dwOSVersionInfoSize = sizeof(os); GetVersionEx(&os); if (os.dwPlatformId == VER_PLATFORM_WIN32_NT) { if (os.dwMajorVersion == 3 && os.dwMinorVersion >= 50) return OS_WINNT35; else if (os.dwMajorVersion == 4) return OS_WINNT4; else if (os.dwMajorVersion == 5) return OS_WIN2K; } else if (os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) { if (os.dwMinorVersion == 0) return OS_WIN95; else return OS_WIN98; } return OS_UNKNOWN; } unsigned long discid(int drive) { struct discdata* cd; int i, numTracks; unsigned long id; i = initTool(); getNumDrives(); ZeroMemory(&toc, sizeof(toc)); readTOC(drive, &toc); if (!toc.firstTrack && !toc.lastTrack) numTracks = 0; else numTracks = (int)(toc.lastTrack - toc.firstTrack + 1); if (numTracks > 0) { // calculate the cddbId cd = genCddbQuery(&toc); id = cd->discid; free(cd); } return id; } struct discdata get_disc_id(int drive) { struct discdata* cd; struct discdata data; int i, numTracks; unsigned long id; i = initTool(); getNumDrives(); ZeroMemory(&toc, sizeof(toc)); readTOC(drive, &toc); if (!toc.firstTrack && !toc.lastTrack) { static char foo[2048]; numTracks = 0; } else numTracks = (int)(toc.lastTrack - toc.firstTrack + 1); if (numTracks > 0) { // calculate the cddbId cd = genCddbQuery(&toc); } free(cd); data = *cd; return data; } #endif //WIN32_H Net-FreeDB-0.10/lib/freebsd.h0000755000175000017500000000644110316526243013766 0ustar dxsdxs /********************************************* NAME: freebsd.h FUNCTION: FreeBSD based cddb id generation code ORIGINALLY CREATED BY: David Shultz ORIGINALLY CREATED ON: 08/03/2001 ADAPTED BY: Peter Pentchev ADAPTED ON: 09/28/2005 *********************************************/ #ifndef FREEBSD_H #define FREEBSD_H struct discdata { unsigned long discid; int num_of_trks; int track_offsets[100]; int seconds; }; /* * The following has been blatantly stolen from FreeBSD 5.4's * cdcontrol(8) utility. */ int msf; struct cd_toc_entry toc_buffer[100]; int read_toc_entrys (int fd, int len) { struct ioc_read_toc_entry t; t.address_format = msf ? CD_MSF_FORMAT : CD_LBA_FORMAT; t.starting_track = 0; t.data_len = len; t.data = toc_buffer; return (ioctl (fd, CDIOREADTOCENTRYS, (char *) &t)); } void lba2msf (unsigned long lba, u_char *m, u_char *s, u_char *f) { lba += 150; /* block start offset */ lba &= 0xffffff; /* negative lbas use only 24 bits */ *m = lba / (60 * 75); lba %= (60 * 75); *s = lba / 75; *f = lba % 75; } /* * dbprog_sum * Convert an integer to its text string representation, and * compute its checksum. Used by dbprog_discid to derive the * disc ID. * * Args: * n - The integer value. * * Return: * The integer checksum. */ static int dbprog_sum(int n) { char buf[12], *p; int ret = 0; /* For backward compatibility this algorithm must not change */ sprintf(buf, "%u", n); for (p = buf; *p != '\0'; p++) ret += (*p - '0'); return(ret); } /* * dbprog_discid * Compute a magic disc ID based on the number of tracks, * the length of each track, and a checksum of the string * that represents the offset of each track. * * Args: * s - Pointer to the curstat_t structure. * * Return: * The integer disc ID. */ int dbprog_discid(int fd, struct discdata *d) { struct ioc_toc_header h; int rc; int i, ntr, t = 0, n = 0; long block; u_char m, s, f; rc = ioctl (fd, CDIOREADTOCHEADER, &h); if (rc < 0) return (0); ntr = h.ending_track - h.starting_track + 1; i = msf; msf = 1; rc = read_toc_entrys (fd, (ntr + 1) * sizeof (struct cd_toc_entry)); msf = i; if (rc < 0) return (0); d->num_of_trks = ntr; /* For backward compatibility this algorithm must not change */ d->track_offsets[0] = 150; for (i = 0; i < ntr; i++) { #define TC_FR(a) toc_buffer[a].addr.msf.frame #define TC_MM(a) toc_buffer[a].addr.msf.minute #define TC_SS(a) toc_buffer[a].addr.msf.second n += dbprog_sum((TC_MM(i) * 60) + TC_SS(i)); t += ((TC_MM(i+1) * 60) + TC_SS(i+1)) - ((TC_MM(i) * 60) + TC_SS(i)); d->track_offsets[i + 1] = TC_FR(i + 1) + TC_MM(i + 1) * 60 * 75 + TC_SS(i+1)*75; fprintf(stderr, "i %d mm %d ss %d fr %d ofs %ld\n", i + 1, TC_MM(i + 1), TC_SS(i + 1), TC_FR(i + 1), d->track_offsets[i]); } d->discid = (n % 0xff) << 24 | t << 8 | ntr; /* block = ntohl(toc_buffer[ntr - 1].addr.lba); d->seconds = ((block + 150) & 0xfffff) / 75; */ d->seconds = TC_SS(ntr) + TC_MM(ntr) * 60; fprintf(stderr, "block is %ld, seconds are %ld\n", block, d->seconds); return (d->discid); } struct discdata get_disc_id(const char *dev) { int fd; struct discdata d; fd = open(dev, O_RDONLY | O_NONBLOCK); if (fd < 0) { memset(&d, 0, sizeof(d)); return (d); } dbprog_discid(fd, &d); close(fd); return (d); } #endif //FREEBSD_H Net-FreeDB-0.10/lib/toc.h0000755000175000017500000000065412417532411013137 0ustar dxsdxs/******************************** FILE: toc.h ********************************/ #ifndef __TOC_H_INC #define __TOC_H_INC #pragma pack(1) typedef struct { BYTE rsvd; BYTE ADR; BYTE trackNumber; BYTE rsvd2; BYTE addr[4]; } TOCTRACK; typedef struct { WORD tocLen; BYTE firstTrack; BYTE lastTrack; TOCTRACK tracks[100]; } TOC, *PTOC, FAR *LPTOC; #pragma pack() #endif Net-FreeDB-0.10/lib/scsidefs.h0000755000175000017500000003446512417532360014167 0ustar dxsdxs /********************************************* NAME: scsidefs.h FUNCTION: windows scsi constants *********************************************/ //*************************************************************************** // %%% TARGET STATUS VALUES %%% //*************************************************************************** #define STATUS_GOOD 0x00 // Status Good #define STATUS_CHKCOND 0x02 // Check Condition #define STATUS_CONDMET 0x04 // Condition Met #define STATUS_BUSY 0x08 // Busy #define STATUS_INTERM 0x10 // Intermediate #define STATUS_INTCDMET 0x14 // Intermediate-condition met #define STATUS_RESCONF 0x18 // Reservation conflict #define STATUS_COMTERM 0x22 // Command Terminated #define STATUS_QFULL 0x28 // Queue full //*************************************************************************** // %%% SCSI MISCELLANEOUS EQUATES %%% //*************************************************************************** #define MAXLUN 7 // Maximum Logical Unit Id #define MAXTARG 7 // Maximum Target Id #define MAX_SCSI_LUNS 64 // Maximum Number of SCSI LUNs #define MAX_NUM_HA 8 // Maximum Number of SCSI HA's //\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ // // %%% SCSI COMMAND OPCODES %%% // ///\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ //*************************************************************************** // %%% Commands for all Device Types %%% //*************************************************************************** #define SCSI_CHANGE_DEF 0x40 // Change Definition (Optional) #define SCSI_COMPARE 0x39 // Compare (O) #define SCSI_COPY 0x18 // Copy (O) #define SCSI_COP_VERIFY 0x3A // Copy and Verify (O) #define SCSI_INQUIRY 0x12 // Inquiry (MANDATORY) #define SCSI_LOG_SELECT 0x4C // Log Select (O) #define SCSI_LOG_SENSE 0x4D // Log Sense (O) #define SCSI_MODE_SEL6 0x15 // Mode Select 6-byte (Device Specific) #define SCSI_MODE_SEL10 0x55 // Mode Select 10-byte (Device Specific) #define SCSI_MODE_SEN6 0x1A // Mode Sense 6-byte (Device Specific) #define SCSI_MODE_SEN10 0x5A // Mode Sense 10-byte (Device Specific) #define SCSI_READ_BUFF 0x3C // Read Buffer (O) #define SCSI_REQ_SENSE 0x03 // Request Sense (MANDATORY) #define SCSI_SEND_DIAG 0x1D // Send Diagnostic (O) #define SCSI_TST_U_RDY 0x00 // Test Unit Ready (MANDATORY) #define SCSI_WRITE_BUFF 0x3B // Write Buffer (O) //*************************************************************************** // %%% Commands Unique to Direct Access Devices %%% //*************************************************************************** #define SCSI_COMPARE 0x39 // Compare (O) #define SCSI_FORMAT 0x04 // Format Unit (MANDATORY) #define SCSI_LCK_UN_CAC 0x36 // Lock Unlock Cache (O) #define SCSI_PREFETCH 0x34 // Prefetch (O) #define SCSI_MED_REMOVL 0x1E // Prevent/Allow medium Removal (O) #define SCSI_READ6 0x08 // Read 6-byte (MANDATORY) #define SCSI_READ10 0x28 // Read 10-byte (MANDATORY) #define SCSI_RD_CAPAC 0x25 // Read Capacity (MANDATORY) #define SCSI_RD_DEFECT 0x37 // Read Defect Data (O) #define SCSI_READ_LONG 0x3E // Read Long (O) #define SCSI_REASS_BLK 0x07 // Reassign Blocks (O) #define SCSI_RCV_DIAG 0x1C // Receive Diagnostic Results (O) #define SCSI_RELEASE 0x17 // Release Unit (MANDATORY) #define SCSI_REZERO 0x01 // Rezero Unit (O) #define SCSI_SRCH_DAT_E 0x31 // Search Data Equal (O) #define SCSI_SRCH_DAT_H 0x30 // Search Data High (O) #define SCSI_SRCH_DAT_L 0x32 // Search Data Low (O) #define SCSI_SEEK6 0x0B // Seek 6-Byte (O) #define SCSI_SEEK10 0x2B // Seek 10-Byte (O) #define SCSI_SEND_DIAG 0x1D // Send Diagnostics (MANDATORY) #define SCSI_SET_LIMIT 0x33 // Set Limits (O) #define SCSI_START_STP 0x1B // Start/Stop Unit (O) #define SCSI_SYNC_CACHE 0x35 // Synchronize Cache (O) #define SCSI_VERIFY 0x2F // Verify (O) #define SCSI_WRITE6 0x0A // Write 6-Byte (MANDATORY) #define SCSI_WRITE10 0x2A // Write 10-Byte (MANDATORY) #define SCSI_WRT_VERIFY 0x2E // Write and Verify (O) #define SCSI_WRITE_LONG 0x3F // Write Long (O) #define SCSI_WRITE_SAME 0x41 // Write Same (O) //*************************************************************************** // %%% Commands Unique to Sequential Access Devices %%% //*************************************************************************** #define SCSI_ERASE 0x19 // Erase (MANDATORY) #define SCSI_LOAD_UN 0x1B // Load/Unload (O) #define SCSI_LOCATE 0x2B // Locate (O) #define SCSI_RD_BLK_LIM 0x05 // Read Block Limits (MANDATORY) #define SCSI_READ_POS 0x34 // Read Position (O) #define SCSI_READ_REV 0x0F // Read Reverse (O) #define SCSI_REC_BF_DAT 0x14 // Recover Buffer Data (O) #define SCSI_RESERVE 0x16 // Reserve Unit (MANDATORY) #define SCSI_REWIND 0x01 // Rewind (MANDATORY) #define SCSI_SPACE 0x11 // Space (MANDATORY) #define SCSI_VERIFY_T 0x13 // Verify (Tape) (O) #define SCSI_WRT_FILE 0x10 // Write Filemarks (MANDATORY) //*************************************************************************** // %%% Commands Unique to Printer Devices %%% //*************************************************************************** #define SCSI_PRINT 0x0A // Print (MANDATORY) #define SCSI_SLEW_PNT 0x0B // Slew and Print (O) #define SCSI_STOP_PNT 0x1B // Stop Print (O) #define SCSI_SYNC_BUFF 0x10 // Synchronize Buffer (O) //*************************************************************************** // %%% Commands Unique to Processor Devices %%% //*************************************************************************** #define SCSI_RECEIVE 0x08 // Receive (O) #define SCSI_SEND 0x0A // Send (O) //*************************************************************************** // %%% Commands Unique to Write-Once Devices %%% //*************************************************************************** #define SCSI_MEDIUM_SCN 0x38 // Medium Scan (O) #define SCSI_SRCHDATE10 0x31 // Search Data Equal 10-Byte (O) #define SCSI_SRCHDATE12 0xB1 // Search Data Equal 12-Byte (O) #define SCSI_SRCHDATH10 0x30 // Search Data High 10-Byte (O) #define SCSI_SRCHDATH12 0xB0 // Search Data High 12-Byte (O) #define SCSI_SRCHDATL10 0x32 // Search Data Low 10-Byte (O) #define SCSI_SRCHDATL12 0xB2 // Search Data Low 12-Byte (O) #define SCSI_SET_LIM_10 0x33 // Set Limits 10-Byte (O) #define SCSI_SET_LIM_12 0xB3 // Set Limits 10-Byte (O) #define SCSI_VERIFY10 0x2F // Verify 10-Byte (O) #define SCSI_VERIFY12 0xAF // Verify 12-Byte (O) #define SCSI_WRITE12 0xAA // Write 12-Byte (O) #define SCSI_WRT_VER10 0x2E // Write and Verify 10-Byte (O) #define SCSI_WRT_VER12 0xAE // Write and Verify 12-Byte (O) //*************************************************************************** // %%% Commands Unique to CD-ROM Devices %%% //*************************************************************************** #define SCSI_PLAYAUD_10 0x45 // Play Audio 10-Byte (O) #define SCSI_PLAYAUD_12 0xA5 // Play Audio 12-Byte 12-Byte (O) #define SCSI_PLAYAUDMSF 0x47 // Play Audio MSF (O) #define SCSI_PLAYA_TKIN 0x48 // Play Audio Track/Index (O) #define SCSI_PLYTKREL10 0x49 // Play Track Relative 10-Byte (O) #define SCSI_PLYTKREL12 0xA9 // Play Track Relative 12-Byte (O) #define SCSI_READCDCAP 0x25 // Read CD-ROM Capacity (MANDATORY) #define SCSI_READHEADER 0x44 // Read Header (O) #define SCSI_SUBCHANNEL 0x42 // Read Subchannel (O) #define SCSI_READ_TOC 0x43 // Read TOC (O) //*************************************************************************** // %%% Commands Unique to Scanner Devices %%% //*************************************************************************** #define SCSI_GETDBSTAT 0x34 // Get Data Buffer Status (O) #define SCSI_GETWINDOW 0x25 // Get Window (O) #define SCSI_OBJECTPOS 0x31 // Object Postion (O) #define SCSI_SCAN 0x1B // Scan (O) #define SCSI_SETWINDOW 0x24 // Set Window (MANDATORY) //*************************************************************************** // %%% Commands Unique to Optical Memory Devices %%% //*************************************************************************** #define SCSI_UpdateBlk 0x3D // Update Block (O) //*************************************************************************** // %%% Commands Unique to Medium Changer Devices %%% //*************************************************************************** #define SCSI_EXCHMEDIUM 0xA6 // Exchange Medium (O) #define SCSI_INITELSTAT 0x07 // Initialize Element Status (O) #define SCSI_POSTOELEM 0x2B // Position to Element (O) #define SCSI_REQ_VE_ADD 0xB5 // Request Volume Element Address (O) #define SCSI_SENDVOLTAG 0xB6 // Send Volume Tag (O) //*************************************************************************** // %%% Commands Unique to Communication Devices %%% //*************************************************************************** #define SCSI_GET_MSG_6 0x08 // Get Message 6-Byte (MANDATORY) #define SCSI_GET_MSG_10 0x28 // Get Message 10-Byte (O) #define SCSI_GET_MSG_12 0xA8 // Get Message 12-Byte (O) #define SCSI_SND_MSG_6 0x0A // Send Message 6-Byte (MANDATORY) #define SCSI_SND_MSG_10 0x2A // Send Message 10-Byte (O) #define SCSI_SND_MSG_12 0xAA // Send Message 12-Byte (O) //\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ // // %%% END OF SCSI COMMAND OPCODES %%% // ///\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ //*************************************************************************** // %%% Request Sense Data Format %%% //*************************************************************************** typedef struct { BYTE ErrorCode; // Error Code (70H or 71H) BYTE SegmentNum; // Number of current segment descriptor BYTE SenseKey; // Sense Key(See bit definitions too) BYTE InfoByte0; // Information MSB BYTE InfoByte1; // Information MID BYTE InfoByte2; // Information MID BYTE InfoByte3; // Information LSB BYTE AddSenLen; // Additional Sense Length BYTE ComSpecInf0; // Command Specific Information MSB BYTE ComSpecInf1; // Command Specific Information MID BYTE ComSpecInf2; // Command Specific Information MID BYTE ComSpecInf3; // Command Specific Information LSB BYTE AddSenseCode; // Additional Sense Code BYTE AddSenQual; // Additional Sense Code Qualifier BYTE FieldRepUCode; // Field Replaceable Unit Code BYTE SenKeySpec15; // Sense Key Specific 15th byte BYTE SenKeySpec16; // Sense Key Specific 16th byte BYTE SenKeySpec17; // Sense Key Specific 17th byte BYTE AddSenseBytes; // Additional Sense Bytes } SENSE_DATA_FMT; //*************************************************************************** // %%% REQUEST SENSE ERROR CODE %%% //*************************************************************************** #define SERROR_CURRENT 0x70 // Current Errors #define SERROR_DEFERED 0x71 // Deferred Errors //*************************************************************************** // %%% REQUEST SENSE BIT DEFINITIONS %%% //*************************************************************************** #define SENSE_VALID 0x80 // Byte 0 Bit 7 #define SENSE_FILEMRK 0x80 // Byte 2 Bit 7 #define SENSE_EOM 0x40 // Byte 2 Bit 6 #define SENSE_ILI 0x20 // Byte 2 Bit 5 //*************************************************************************** // %%% REQUEST SENSE SENSE KEY DEFINITIONS %%% //*************************************************************************** #define KEY_NOSENSE 0x00 // No Sense #define KEY_RECERROR 0x01 // Recovered Error #define KEY_NOTREADY 0x02 // Not Ready #define KEY_MEDIUMERR 0x03 // Medium Error #define KEY_HARDERROR 0x04 // Hardware Error #define KEY_ILLGLREQ 0x05 // Illegal Request #define KEY_UNITATT 0x06 // Unit Attention #define KEY_DATAPROT 0x07 // Data Protect #define KEY_BLANKCHK 0x08 // Blank Check #define KEY_VENDSPEC 0x09 // Vendor Specific #define KEY_COPYABORT 0x0A // Copy Abort #define KEY_EQUAL 0x0C // Equal (Search) #define KEY_VOLOVRFLW 0x0D // Volume Overflow #define KEY_MISCOMP 0x0E // Miscompare (Search) #define KEY_RESERVED 0x0F // Reserved //*************************************************************************** // %%% PERIPHERAL DEVICE TYPE DEFINITIONS %%% //*************************************************************************** #define DTYPE_DASD 0x00 // Disk Device #define DTYPE_SEQD 0x01 // Tape Device #define DTYPE_PRNT 0x02 // Printer #define DTYPE_PROC 0x03 // Processor #define DTYPE_WORM 0x04 // Write-once read-multiple #define DTYPE_CROM 0x05 // CD-ROM device #define DTYPE_CDROM 0x05 // CD-ROM device #define DTYPE_SCAN 0x06 // Scanner device #define DTYPE_OPTI 0x07 // Optical memory device #define DTYPE_JUKE 0x08 // Medium Changer device #define DTYPE_COMM 0x09 // Communications device #define DTYPE_RESL 0x0A // Reserved (low) #define DTYPE_RESH 0x1E // Reserved (high) #define DTYPE_UNKNOWN 0x1F // Unknown or no device type //*************************************************************************** // %%% ANSI APPROVED VERSION DEFINITIONS %%% //*************************************************************************** #define ANSI_MAYBE 0x0 // Device may or may not be ANSI approved stand #define ANSI_SCSI1 0x1 // Device complies to ANSI X3.131-1986 (SCSI-1) #define ANSI_SCSI2 0x2 // Device complies to SCSI-2 #define ANSI_RESLO 0x3 // Reserved (low) #define ANSI_RESHI 0x7 // Reserved (high) Net-FreeDB-0.10/lib/myaspi32.h0000755000175000017500000002652412417532421014026 0ustar dxsdxs /********************************************* NAME: myaspi32.h FUNCTION: windows aspi methods and constants *********************************************/ #ifndef __MYASPI32_H_ #define __MYASPI32_H_ #ifndef __GNUC__ #define PACKED #endif /*************************************************************************** ** SCSI MISCELLANEOUS EQUATES ***************************************************************************/ #define SENSE_LEN 14 /* Default sense buffer length */ #define SRB_DIR_SCSI 0x00 /* Direction determined by SCSI */ #define SRB_POSTING 0x01 /* Enable ASPI posting */ #define SRB_ENABLE_RESIDUAL_COUNT 0x04 /* Enable residual byte count */ /* reporting */ #define SRB_DIR_IN 0x08 /* Transfer from SCSI target to */ /* host */ #define SRB_DIR_OUT 0x10 /* Transfer from host to SCSI */ /* target */ #define SRB_EVENT_NOTIFY 0x40 /* Enable ASPI event notification */ #define RESIDUAL_COUNT_SUPPORTED 0x02 /* Extended buffer flag */ #define MAX_SRB_TIMEOUT 1080001u /* 30 hour maximum timeout in sec */ #define DEFAULT_SRB_TIMEOUT 1080001u /* use max.timeout by default */ /*************************************************************************** ** ASPI command definitions ***************************************************************************/ #define SC_HA_INQUIRY 0x00 /* Host adapter inquiry */ #define SC_GET_DEV_TYPE 0x01 /* Get device type */ #define SC_EXEC_SCSI_CMD 0x02 /* Execute SCSI command */ #define SC_ABORT_SRB 0x03 /* Abort an SRB */ #define SC_RESET_DEV 0x04 /* SCSI bus device reset */ #define SC_SET_HA_PARMS 0x05 /* Set HA parameters */ #define SC_GET_DISK_INFO 0x06 /* Get Disk */ #define SC_RESCAN_SCSI_BUS 0x07 /* Rebuild SCSI device map */ #define SC_GETSET_TIMEOUTS 0x08 /* Get/Set target timeouts */ /*************************************************************************** ** SRB Status ***************************************************************************/ #define SS_PENDING 0x00 /* SRB being processed */ #define SS_COMP 0x01 /* SRB completed without error */ #define SS_ABORTED 0x02 /* SRB aborted */ #define SS_ABORT_FAIL 0x03 /* Unable to abort SRB */ #define SS_ERR 0x04 /* SRB completed with error */ #define SS_INVALID_CMD 0x80 /* Invalid ASPI command */ #define SS_INVALID_HA 0x81 /* Invalid host adapter number */ #define SS_NO_DEVICE 0x82 /* SCSI device not installed */ #define SS_INVALID_SRB 0xE0 /* Invalid parameter set in SRB */ #define SS_OLD_MANAGER 0xE1 /* ASPI manager doesn't support */ /* windows */ #define SS_BUFFER_ALIGN 0xE1 /* Buffer not aligned (replaces */ /* SS_OLD_MANAGER in Win32) */ #define SS_ILLEGAL_MODE 0xE2 /* Unsupported Windows mode */ #define SS_NO_ASPI 0xE3 /* No ASPI managers */ #define SS_FAILED_INIT 0xE4 /* ASPI for windows failed init */ #define SS_ASPI_IS_BUSY 0xE5 /* No resources available to */ /* execute command */ #define SS_BUFFER_TO_BIG 0xE6 /* Buffer size too big to handle */ #define SS_BUFFER_TOO_BIG 0xE6 /* Correct spelling of 'too' */ #define SS_MISMATCHED_COMPONENTS 0xE7 /* The DLLs/EXEs of ASPI don't */ /* version check */ #define SS_NO_ADAPTERS 0xE8 /* No host adapters to manager */ #define SS_INSUFFICIENT_RESOURCES 0xE9 /* Couldn't allocate resources */ /* needed to init */ #define SS_ASPI_IS_SHUTDOWN 0xEA /* Call came to ASPI after */ /* PROCESS_DETACH */ #define SS_BAD_INSTALL 0xEB /* The DLL or other components */ /* are installed wrong */ /*************************************************************************** ** Host Adapter Status ***************************************************************************/ #define HASTAT_OK 0x00 /* No error detected by HA */ #define HASTAT_SEL_TO 0x11 /* Selection Timeout */ #define HASTAT_DO_DU 0x12 /* Data overrun/data underrun */ #define HASTAT_BUS_FREE 0x13 /* Unexpected bus free */ #define HASTAT_PHASE_ERR 0x14 /* Target bus phase sequence */ #define HASTAT_TIMEOUT 0x09 /* Timed out while SRB was */ /* waiting to be processed */ #define HASTAT_COMMAND_TIMEOUT 0x0B /* Adapter timed out while */ /* processing SRB */ #define HASTAT_MESSAGE_REJECT 0x0D /* While processing the SRB, the */ /* adapter received a MESSAGE */ #define HASTAT_BUS_RESET 0x0E /* A bus reset was detected */ #define HASTAT_PARITY_ERROR 0x0F /* A parity error was detected */ #define HASTAT_REQUEST_SENSE_FAILED 0x10 /* The adapter failed in issuing */ #ifndef __GNUC__ #pragma pack(1) #endif /*************************************************************************** ** SRB - HOST ADAPTER INQUIRIY - SC_HA_INQUIRY (0) ***************************************************************************/ typedef struct { BYTE SRB_Cmd; /* 00/000 ASPI command code == SC_HA_INQUIRY */ BYTE SRB_Status; /* 01/001 ASPI command status byte */ BYTE SRB_HaID; /* 02/002 ASPI host adapter number */ BYTE SRB_Flags; /* 03/003 ASPI request flags */ DWORD SRB_Hdr_Rsvd; /* 04/004 Reserved, must = 0 */ BYTE HA_Count; /* 08/008 Number of host adapters present */ BYTE HA_SCSI_ID; /* 09/009 SCSI ID of host adapter */ BYTE HA_ManagerId[16]; /* 0a/010 String describing the manager */ BYTE HA_Identifier[16]; /* 1a/026 String describing the host adapter */ BYTE HA_Unique[16]; /* 2a/042 Host Adapter Unique parameters */ WORD HA_Rsvd1; /* 3a/058 Reserved, must = 0 */ BYTE pad[20]; } PACKED SRB_HAInquiry, *PSRB_HAInquiry, FAR *LPSRB_HAInquiry; /*************************************************************************** ** SRB - GET DEVICE TYPE - SC_GET_DEV_TYPE (1) ***************************************************************************/ typedef struct { BYTE SRB_Cmd; /* 00/000 ASPI cmd code == SC_GET_DEV_TYPE */ BYTE SRB_Status; /* 01/001 ASPI command status byte */ BYTE SRB_HaID; /* 02/002 ASPI host adapter number */ BYTE SRB_Flags; /* 03/003 Reserved, must = 0 */ DWORD SRB_Hdr_Rsvd; /* 04/004 Reserved, must = 0 */ BYTE SRB_Target; /* 08/008 Target's SCSI ID */ BYTE SRB_Lun; /* 09/009 Target's LUN number */ BYTE SRB_DeviceType; /* 0a/010 Target's peripheral device type */ BYTE SRB_Rsvd1; /* 0b/011 Reserved, must = 0 */ BYTE pad[68]; } PACKED SRB_GDEVBlock, *PSRB_GDEVBlock, FAR *LPSRB_GDEVBlock; /*************************************************************************** ** SRB - EXECUTE SCSI COMMAND - SC_EXEC_SCSI_CMD (2) ***************************************************************************/ typedef struct { BYTE SRB_Cmd; /* 00/000 ASPI cmd code == SC_EXEC_SCSI_CMD */ BYTE SRB_Status; /* 01/001 ASPI command status byte */ BYTE SRB_HaID; /* 02/002 ASPI host adapter number */ BYTE SRB_Flags; /* 03/003 Reserved, must = 0 */ DWORD SRB_Hdr_Rsvd; /* 04/004 Reserved, must = 0 */ BYTE SRB_Target; /* 08/008 Target's SCSI ID */ BYTE SRB_Lun; /* 09/009 Target's LUN */ WORD SRB_Rsvd1; /* 0a/010 Reserved for alignment */ DWORD SRB_BufLen; /* 0c/012 Data Allocation Length */ BYTE FAR *SRB_BufPointer; /* 10/016 Data Buffer Pointer */ BYTE SRB_SenseLen; /* 14/020 Sense Allocation Length */ BYTE SRB_CDBLen; /* 15/021 CDB Length */ BYTE SRB_HaStat; /* 16/022 Host Adapter Status */ BYTE SRB_TargStat; /* 17/023 Target Status */ VOID FAR *SRB_PostProc; /* 18/024 Post routine */ BYTE SRB_Rsvd2[20]; /* 1c/028 Reserved, must = 0 */ BYTE CDBByte[16]; /* 30/048 SCSI CDB */ BYTE SenseArea[SENSE_LEN+2]; /* 40/064 Request Sense buffer */ } PACKED SRB_ExecSCSICmd, *PSRB_ExecSCSICmd, FAR *LPSRB_ExecSCSICmd; /*************************************************************************** ** SRB - BUS DEVICE RESET - SC_RESET_DEV (4) ***************************************************************************/ typedef struct { BYTE SRB_Cmd; /* 00/000 ASPI cmd code == SC_RESET_DEV */ BYTE SRB_Status; /* 01/001 ASPI command status byte */ BYTE SRB_HaId; /* 02/002 ASPI host adapter number */ BYTE SRB_Flags; /* 03/003 Reserved, must = 0 */ DWORD SRB_Hdr_Rsvd; /* 04/004 Reserved */ BYTE SRB_Target; /* 08/008 Target's SCSI ID */ BYTE SRB_Lun; /* 09/009 Target's LUN number */ BYTE SRB_Rsvd1[12]; /* 0A/010 Reserved for alignment */ BYTE SRB_HaStat; /* 16/022 Host Adapter Status */ BYTE SRB_TargStat; /* 17/023 Target Status */ VOID FAR *SRB_PostProc; /* 18/024 Post routine */ BYTE SRB_Rsvd2[36]; /* 1C/028 Reserved, must = 0 */ BYTE pad[16]; } SRB_BusDeviceReset, *PSRB_BusDeviceReset, FAR *LPSRB_BusDeviceReset; typedef struct tag_ASPI32BUFF { PBYTE AB_BufPointer; DWORD AB_BufLen; DWORD AB_ZeroFill; DWORD AB_Reserved; } PACKED ASPI32BUFF, *PASPI32BUFF, FAR *LPASPI32BUFF; typedef struct { BYTE SRB_Cmd; BYTE SRB_Status; BYTE SRB_HaId; BYTE SRB_Flags; DWORD SRB_Hdr_Rsvd; } PACKED SRB, *PSRB, FAR *LPSRB; #ifndef __GNUC__ #pragma pack() #endif #endif Net-FreeDB-0.10/lib/toctool.h0000755000175000017500000000201312417532402014024 0ustar dxsdxs/******************************** FILE: toctool.h ********************************/ #ifndef __TOCTOOL_H_INC #define __TOCTOOL_H_INC #include "myaspi32.h" #include "toc.h" #define OS_UNKNOWN -1 #define OS_WIN95 0 #define OS_WIN98 1 #define OS_WINNT35 2 #define OS_WINNT4 3 #define OS_WIN2K 4 #define INTERFACE_ASPI 0 #define NUM_INTERFACE (1) typedef struct { char name[32]; BOOL avail; } INTERFACE; #ifndef __INIT_C extern BOOL bInit; extern INTERFACE interfaces[NUM_INTERFACE]; extern int iActiveInterface; extern int iOSVer; extern DWORD (*GetASPI32SupportInfo)(void); extern DWORD (*SendASPI32Command)(LPSRB); #endif typedef struct { BYTE ha; BYTE tgt; BYTE lun; char desc[32]; } ASPIDRV; typedef struct { char driveLetter; char desc[32]; } NTDRV; typedef union { ASPIDRV a; NTDRV n; } DRIVESTRUCT; #define MAX_DRIVE_LIST 8 typedef struct { DRIVESTRUCT drive[MAX_DRIVE_LIST]; int num; } DRIVELIST; #ifndef __DRIVELST_C extern DRIVELIST driveList; #endif #endif Net-FreeDB-0.10/t/0000755000175000017500000000000012417546133011674 5ustar dxsdxsNet-FreeDB-0.10/t/04-unlink.t0000644000175000017500000000046712417534426013613 0ustar dxsdxsuse Test::Most; require_ok('Net::FreeDB'); my $freedb = new Net::FreeDB(); ok($freedb, 'Unable to create instance'); if ($ENV{HAVE_INTERNET}) { ok(!$freedb->unlink('newage', '940a040c')); ok($freedb->error eq 'Permission denied.', "Error: Unexpected error '@{[ $freedb->error ]}'"); } done_testing; Net-FreeDB-0.10/t/05-write.t0000644000175000017500000000046612417534442013443 0ustar dxsdxsuse Test::Most; require_ok('Net::FreeDB'); my $freedb = new Net::FreeDB(); ok($freedb, 'Unable to create instance'); if ($ENV{HAVE_INTERNET}) { ok(!$freedb->write('newage', '940a040c')); ok($freedb->error eq 'Permission denied.', "Error: Unexpected error '@{[ $freedb->error ]}'"); } done_testing; Net-FreeDB-0.10/t/11-stat.t0000644000175000017500000000130712417534555013261 0ustar dxsdxsuse Test::Most; require_ok('Net::FreeDB'); my $freedb = new Net::FreeDB(); ok($freedb, 'Unable to create instance'); if ($ENV{HAVE_INTERNET}) { my $server_stats; ok($server_stats = $freedb->stat()); ok($server_stats->{"current proto"} == 1); ok($server_stats->{"max proto"} == 6); ok($server_stats->{interface} eq 'cddbp'); ok($server_stats->{gets} eq 'no'); ok($server_stats->{puts} eq 'no'); ok($server_stats->{updates} eq 'no'); ok($server_stats->{posting} eq 'no'); ok($server_stats->{validation} eq 'accepted'); ok($server_stats->{quotes} eq 'no'); ok($server_stats->{"strip ext"} eq 'no'); ok($server_stats->{secure} eq 'yes'); } done_testing; Net-FreeDB-0.10/t/15-whom.t0000644000175000017500000000045112417534631013256 0ustar dxsdxs use Test::Most; require_ok('Net::FreeDB'); my $freedb = new Net::FreeDB(); ok($freedb, 'Unable to create instance'); if ($ENV{HAVE_INTERNET}) { ok(!$freedb->whom()); ok($freedb->error eq 'No user information available.', "Error: actual error not the expected error"); } done_testing; Net-FreeDB-0.10/t/08-motd.t0000644000175000017500000000040512417534503013246 0ustar dxsdxsuse Test::Most; require_ok('Net::FreeDB'); my $freedb = new Net::FreeDB(); ok($freedb, 'Unable to create instance'); if ($ENV{HAVE_INTERNET}) { my @motd_lines = (); ok(@motd_lines = $freedb->motd()); ok(scalar(@motd_lines) > 1); } done_testing; Net-FreeDB-0.10/t/10-sites.t0000644000175000017500000000073512417534536013437 0ustar dxsdxsuse Test::Most; require_ok('Net::FreeDB'); my $freedb = new Net::FreeDB(); ok($freedb, 'Unable to create instance'); if ($ENV{HAVE_INTERNET}) { my @sites = (); ok(@sites = $freedb->sites()); ok(scalar(@sites) == 1); eq_or_diff($sites[0], { hostname => 'freedb.freedb.org', port => 8880, latitude => 'N000.00', longitude => 'W000.00', description => 'Random freedb server', }); } done_testing; Net-FreeDB-0.10/t/12-update.t0000644000175000017500000000043612417534570013570 0ustar dxsdxsuse Test::Most; require_ok('Net::FreeDB'); my $freedb = new Net::FreeDB(); ok($freedb, 'Unable to create instance'); if ($ENV{HAVE_INTERNET}) { ok(!$freedb->update()); ok($freedb->error eq 'Permission denied.', "Error: actual error not the expected error"); } done_testing; Net-FreeDB-0.10/t/17-get_local_disc_data.t0000644000175000017500000000076412417534663016246 0ustar dxsdxsuse Test::Most; require_ok('Net::FreeDB'); my $freedb = new Net::FreeDB(); ok($freedb, 'Unable to create instance'); if ($ENV{HAVE_INTERNET}) { my $disc_data = undef; my $device = undef; $device = '/dev/cdrom' if ($^O =~ /linux/); $device = 0 if ($^O =~ /MSWin32/); $device = '/dev/acd0' if ($^O =~ /freebsd/); if ($device) { ok($disc_data = $freedb->get_local_disc_data($device), "Unable to scan local disc drive"); } } done_testing; Net-FreeDB-0.10/t/07-log.t0000644000175000017500000000047412417534467013102 0ustar dxsdxsuse Test::Most; require_ok('Net::FreeDB'); my $freedb = new Net::FreeDB(); ok($freedb, 'Unable to create instance'); if ($ENV{HAVE_INTERNET}) { my @log_lines = (); ok(!$freedb->log(10, 'day')); ok($freedb->error eq 'Permission denied.', "Error: actual error not the expected error"); } done_testing; Net-FreeDB-0.10/t/16-get_local_disc_id.t0000644000175000017500000000074612417534646015731 0ustar dxsdxsuse Test::Most; require_ok('Net::FreeDB'); my $freedb = new Net::FreeDB(); ok($freedb, 'Unable to create instance'); if ($ENV{HAVE_INTERNET}) { my $disc_id = undef; my $device = undef; $device = '/dev/cdrom' if ($^O =~ /linux/); $device = 0 if ($^O =~ /MSWin32/); $device = '/dev/acd0' if ($^O =~ /freebsd/); if ($device) { ok($disc_id = $freedb->get_local_disc_id($device), "Unable to scan local disc drive"); } } done_testing; Net-FreeDB-0.10/t/13-validate.t0000644000175000017500000000046212417534602014073 0ustar dxsdxsuse Test::Most; require_ok('Net::FreeDB'); my $freedb = new Net::FreeDB(); ok($freedb, 'Unable to create instance'); if ($ENV{HAVE_INTERNET}) { ok(!$freedb->validate("salt=12345")); ok($freedb->error eq 'Validation not required.', "Error: actual error not the expected error"); } done_testing; Net-FreeDB-0.10/t/01-lscat.t0000644000175000017500000000047412417534351013411 0ustar dxsdxsuse Test::Most; require_ok('Net::FreeDB'); my $freedb = new Net::FreeDB(); ok($freedb, 'Unable to create instance'); if ($ENV{HAVE_INTERNET}) { my @categories = $freedb->lscat(); eq_or_diff(sort @categories, qw/blues classical country data folk jazz misc newage reggae rock soundtrack/); } done_testing; Net-FreeDB-0.10/t/03-read.t0000644000175000017500000000146412417534414013220 0ustar dxsdxsuse Test::Most; require_ok('Net::FreeDB'); my $freedb = new Net::FreeDB(); ok($freedb, 'Unable to create instance'); if ($ENV{HAVE_INTERNET}) { my $response; ok($response = $freedb->read('newage', '940a040c')); isa_ok($response, 'CDDB::File', 'Error, object type is unexpected'); ok($response->id eq '940a040c', "Error: @{[ $response->id ]} is NOT the expected 940a040c"); ok($response->artist eq 'Deep Forest', "Error: @{[ $response->artist ]} is NOT the expected Deep Forest"); ok($response->title eq 'Boheme', "Error: @{[ $response->title ]} is NOT the expected Boheme"); ok($response->length == 2566, "Error: @{[ $response->length ]} is NOT the expected 2566"); ok($response->track_count == 12, "Error: @{[ $response->track_count ]} is NOT the expected 12"); } done_testing; Net-FreeDB-0.10/t/14-ver.t0000644000175000017500000000051712417534617013106 0ustar dxsdxsuse Test::Most; require_ok('Net::FreeDB'); my $freedb = new Net::FreeDB(); ok($freedb, 'Unable to create instance'); if ($ENV{HAVE_INTERNET}) { my $server_description; ok($server_description = $freedb->ver()); ok($server_description =~ /cddbd v[^\s]+ Copyright \(c\) \d{4}-\d{4} Steve Scherf et al\./); } done_testing; Net-FreeDB-0.10/t/06-discid.t0000644000175000017500000000061312417534454013546 0ustar dxsdxsuse Test::Most; require_ok('Net::FreeDB'); my $freedb = new Net::FreeDB(); ok($freedb, 'Unable to create instance'); if ($ENV{HAVE_INTERNET}) { my $disc_id; ok($disc_id = $freedb->discid(12, 150, 8292, 32047, 50992, 71957, 86200, 100302, 105897, 120897, 139437, 158775, 171760, 2566)); ok($disc_id eq '9a0a040c', "DiscID: $disc_id is NOT the expected 9a0a040c"); } done_testing; Net-FreeDB-0.10/t/02-query.t0000644000175000017500000000152112417534374013450 0ustar dxsdxsuse Test::Most; require_ok('Net::FreeDB'); my $freedb = new Net::FreeDB(); ok($freedb, 'Unable to create instance'); if ($ENV{HAVE_INTERNET}) { my @response = (); ok(@response = $freedb->query('940a070c', 12, 150, 8285, 32097, 51042, 71992, 86235, 100345, 105935, 120932, 139472, 158810, 171795, 2567)); ok(scalar(@response) eq 1); eq_or_diff($response[0], { Category => 'newage', DiscID => '940a070c', Artist => 'Deep Forest', Album => 'Boheme', }); my @multiple_responses = (); ok(@multiple_responses = $freedb->query('860aec0b', 11, 150, 19539, 34753, 52608, 69426, 86636, 112972, 130586, 151446, 172365, 191628, 2798)); ok(scalar(@multiple_responses) >= 10); map { ok($_->{Artist} eq 'Foo Fighters') } @multiple_responses; } done_testing; Net-FreeDB-0.10/t/00-basic.t0000644000175000017500000000126212417534314013356 0ustar dxsdxsuse Test::Most; use_ok('Net::FreeDB'); my $freedb = new_ok("Net::FreeDB"); if ($ENV{HOSTNAME}) { ok($freedb->hostname eq $ENV{HOSTNAME}, 'Error setting hostname'); } else { ok($freedb->hostname eq 'unknown', 'Error setting hostname'); } ok($freedb->remote_host eq 'freedb.freedb.org', 'Error setting default host'); ok($freedb->remote_port == 8880, 'Error setting default port'); if ($ENV{USER}) { ok($freedb->user eq $ENV{USER}, 'Error setting user'); } else { ok($freedb->user eq 'unknown', 'Error setting default user'); } ok($freedb->timeout == 120, 'Error setting default timeout'); ok(!$freedb->debug, 'Error: debug was set but shouldn\'t be'); done_testing; Net-FreeDB-0.10/t/09-proto.t0000644000175000017500000000055212417534521013452 0ustar dxsdxsuse Test::Most; require_ok('Net::FreeDB'); my $freedb = new Net::FreeDB(); ok($freedb, 'Unable to create instance'); if ($ENV{HAVE_INTERNET}) { ok($freedb->proto()); ok($freedb->current_protocol_level() == 1); ok($freedb->max_protocol_level() == 6); ok($freedb->proto(6)); ok($freedb->current_protocol_level() == 6); } done_testing; Net-FreeDB-0.10/README0000755000175000017500000000201612417533654012317 0ustar dxsdxsNet/FreeDB version 0.10 ======================= Net::FreeDB is an oo-based module to interface with FreeDB servers. As of version 0.10, Net::FreeDB is CDDB Protocol Level 6 compliant. It also includes some basic cdrom methods to generate a cddbid and get the required disc information required for a FreeDB query call. These cdrom-based methods are provided as both static and method calls. Currently this functionality only works on Linux, FreeBSD and Windows. If you have an OS you'd like to add, please let me know. INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES This module requires these other modules and libraries: Moo: any version Net::Cmd: 2.12 or higher IO::Socket::INET: any version CDDB::File: 1.01 or higher File::Temp: 0.05 or higher COPYRIGHT AND LICENCE Copyright (C) 2001, 2014 David Shultz Copyright (C) 2005, 2006 Peter Pentchev Net-FreeDB-0.10/MANIFEST0000755000175000017500000000116512417546133012570 0ustar dxsdxsChanges FreeDB.xs.linux FreeDB.xs.win32 FreeDB.pm FreeDBConnection.pm MANIFEST Makefile.PL README TODO lib/discid.h lib/freebsd.h lib/linux.h lib/myaspi32.h lib/scsidefs.h lib/toc.h lib/toctool.h lib/win32.h t/00-basic.t t/01-lscat.t t/02-query.t t/03-read.t t/04-unlink.t t/05-write.t t/06-discid.t t/07-log.t t/08-motd.t t/09-proto.t t/10-sites.t t/11-stat.t t/12-update.t t/13-validate.t t/14-ver.t t/15-whom.t t/16-get_local_disc_id.t t/17-get_local_disc_data.t META.yml Module meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) Net-FreeDB-0.10/META.yml0000664000175000017500000000112612417546133012704 0ustar dxsdxs--- abstract: 'OOP Interface to FreeDB Server(s)' author: - 'David Shultz , Peter Pentchev ' build_requires: ExtUtils::MakeMaker: 0 configure_requires: ExtUtils::MakeMaker: 0 dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 6.84, CPAN::Meta::Converter version 2.133380' license: unknown meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Net-FreeDB no_index: directory: - t - inc requires: CDDB::File: 1.01 File::Temp: 0.05 IO::Socket::INET: 0 Moo: 0 Net::Cmd: 2.12 version: 0.10 Net-FreeDB-0.10/FreeDBConnection.pm0000755000175000017500000000014512417052503015072 0ustar dxsdxspackage Net::FreeDBConnection; use parent qw/Net::Cmd IO::Socket::INET/; our $VERSION = '0.01'; 1; Net-FreeDB-0.10/FreeDB.xs.linux0000755000175000017500000000276112417531130014232 0ustar dxsdxs// Copyright (c) 2014 David J. Shultz // This software is covered by the GPL. #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "lib/discid.h" #include #include static int not_here(char *s) { croak("%s not implemented on this architecture", s); return -1; } static double constant(char *name, int len, int arg) { errno = EINVAL; return 0; } MODULE = Net::FreeDB PACKAGE = Net::FreeDB PROTOTYPES: ENABLE double constant(sv,arg) PREINIT: STRLEN len; INPUT: SV * sv char * s = SvPV(sv, len); int arg CODE: RETVAL = constant(s,len,arg); OUTPUT: RETVAL char* xs_discid(char* dev) INIT: char id[30]; struct discdata data; CODE: data = get_disc_id(dev); POST_CALL: if (data.num_of_trks == -1) { RETVAL = ""; } else { sprintf(id, "%08x", (unsigned int)data.discid); RETVAL = id; } OUTPUT: RETVAL SV* xs_discinfo(char* dev) INIT: int i; char id[30]; struct discdata data; HV* hash = newHV(); AV* tracks = newAV(); PPCODE: data = get_disc_id(dev); for (i = 0; i < (data.num_of_trks); i++) { av_push(tracks, newSVnv(data.track_offsets[i])); } sprintf(id, "%08x", (unsigned int)data.discid); hv_store(hash, "ID", 2, newSVpv(id, 0), 0); hv_store(hash, "NUM_TRKS", 8, newSVnv(data.num_of_trks), 0); hv_store(hash, "TRACKS", 6, newRV_inc((SV*)tracks), 0); hv_store(hash, "SECONDS", 7, newSVnv(data.seconds), 0); XPUSHs(newRV((SV*)hash)); Net-FreeDB-0.10/TODO0000755000175000017500000000013412417534023012115 0ustar dxsdxsCreate mock freedb server and write more tests for various currently untested functionality Net-FreeDB-0.10/Makefile.PL0000755000175000017500000000566412417534203013414 0ustar dxsdxsuse ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. print "###############################################################\n"; print "# This update is NOT compatible with version 0.9 or earlier!! #\n"; print "###############################################################\n"; if ($^O =~ /linux/) { print "OS: $^O, copying XS file: "; system("cp FreeDB.xs.linux FreeDB.xs") && die "Copying failed\n"; print "1 file copied\n"; } elsif ($^O =~ /freebsd/) { print "OS: $^O, copying XS file: "; system("cp FreeDB.xs.linux FreeDB.xs") && die "Copying failed\n"; print "1 file copied\n"; } elsif ($^O =~ /MSWin32/) { print "OS: $^O, copying XS file:"; system("copy FreeDB.xs.win32 FreeDB.xs") && die "Copying failed\n"; } else { print "Unable to determine OS, Exiting\n"; exit(0); } #--- MY package sub MY::libscan { my($self,$path) = @_; return '' if($path =~ m:/(RCS|CVS|SCCS)/: || $path =~ m:[~%]$: || $path =~ m:\.(orig|rej|nfs|h)$: ); $path; } #--- Installation check sub chk_version { my($pkg,$wanted,$msg) = @_; local($|) = 1; print "Checking for $pkg..."; eval { my $p; ($p = $pkg . ".pm") =~ s#::#/#g; require $p; }; my $vstr = ${"${pkg}::VERSION"} ? "found v" . ${"${pkg}::VERSION"} : "not found"; my $vnum = ${"${pkg}::VERSION"} || 0; print $vnum >= $wanted ? "ok\n" : " " . $vstr . "\n"; $vnum >= $wanted; } sub MY::post_initialize { my ($self) = @_; } #--- Check for Socket chk_version(Net::Cmd => '2.12') or warn "\n" . "*** For Net::FreeDB to work you require version 2.12, or later,\n" . " of Net::Cmd available on CPAN\n\n"; chk_version(CDDB::File => '1.01') or warn "\n" . "*** For Net::FreeDB to work you require version 1.01, or later,\n" . " of CDDB::File available on CPAN\n\n"; #--- Write the Makefile WriteMakefile( 'NAME' => 'Net::FreeDB', 'VERSION_FROM' => 'FreeDB.pm', # finds $VERSION 'PREREQ_PM' => { Moo => 0, CDDB::File => 1.01, File::Temp => 0.05, IO::Socket::INET => 0, Net::Cmd => 2.12, }, # e.g., Module::Name => 1.1 ($] >= 5.005 ? ## Add these new keywords supported since 5.005 (AUTHOR => 'David Shultz , Peter Pentchev ', ABSTRACT => 'OOP Interface to FreeDB Server(s)' ) : ()), 'LIBS' => [''], # e.g., '-lm' 'DEFINE' => '', # e.g., '-DHAVE_SOMETHING' # Insert -I. if you add *.h files later: 'INC' => '-Ilib', # e.g., '-I/usr/include/other' # Un-comment this if you add C files to link with later: # 'OBJECT' => '$(O_FILES)', # link all the C files too 'clean' => { 'FILES' => 'FreeDB.xs' }, ); Net-FreeDB-0.10/META.json0000664000175000017500000000203012417546133013047 0ustar dxsdxs{ "abstract" : "OOP Interface to FreeDB Server(s)", "author" : [ "David Shultz , Peter Pentchev " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.84, CPAN::Meta::Converter version 2.133380", "license" : [ "unknown" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Net-FreeDB", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "CDDB::File" : "1.01", "File::Temp" : "0.05", "IO::Socket::INET" : "0", "Moo" : "0", "Net::Cmd" : "2.12" } } }, "release_status" : "stable", "version" : "0.10" }