| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Net::FreeDB2::Connection::CDDBP; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | # Copyright 2002, Vincenzo Zocca. | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | # See LICENSE section for usage and distribution rights. | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | require 5.005_62; | 
| 8 | 1 |  |  | 1 |  | 6 | use strict; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 42 |  | 
| 9 | 1 |  |  | 1 |  | 5 | use warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 45 |  | 
| 10 | 1 |  |  | 1 |  | 1012 | use Error qw (:try); | 
|  | 1 |  |  |  |  | 7424 |  | 
|  | 1 |  |  |  |  | 7 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | require Exporter; | 
| 13 | 1 |  |  | 1 |  | 1364 | use AutoLoader qw(AUTOLOAD); | 
|  | 1 |  |  |  |  | 1941 |  | 
|  | 1 |  |  |  |  | 7 |  | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | #our @ISA = qw(Net::FreeDB2::Connection Exporter); | 
| 16 | 1 |  |  | 1 |  | 44 | use base qw(Net::FreeDB2::Connection Exporter); | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 611 |  | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | # Items to export into callers namespace by default. Note: do not export | 
| 19 |  |  |  |  |  |  | # names by default without a very good reason. Use EXPORT_OK instead. | 
| 20 |  |  |  |  |  |  | # Do not simply export all your public functions/methods/constants. | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | # This allows declaration	use Net::FreeDB2::Connection::CDDBP ':all'; | 
| 23 |  |  |  |  |  |  | # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK | 
| 24 |  |  |  |  |  |  | # will save memory. | 
| 25 |  |  |  |  |  |  | our %EXPORT_TAGS = ( 'all' => [ qw( | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | ) ] ); | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | our @EXPORT = qw( | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | ); | 
| 34 |  |  |  |  |  |  | our ( $VERSION ) = '$Revision: 0.8.2.4 $ ' =~ /\$Revision:\s+([^\s]+)/; | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | my $FINAL_EOL_RX = '[\r\n]'; | 
| 37 |  |  |  |  |  |  | my $FINAL_DOT_RX = '[\r\n]\.[\r\n]'; | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | sub new { | 
| 40 |  |  |  |  |  |  | # Call constructor of super class | 
| 41 | 0 |  |  | 0 | 1 |  | my $self = &Net::FreeDB2::Connection::new (@_); | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | # Shift out this class specification | 
| 44 | 0 |  |  |  |  |  | shift; | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | # Return object | 
| 47 | 0 |  |  |  |  |  | return ($self); | 
| 48 |  |  |  |  |  |  | } | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | sub _initialize { | 
| 51 | 0 |  |  | 0 |  |  | my $self = shift; | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | # Get options | 
| 54 | 0 |  | 0 |  |  |  | my $opt = shift || {}; | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | # Proxy on CDDBP not yet defined | 
| 57 | 0 | 0 |  |  |  |  | defined ($opt->{proxy_host}) && | 
| 58 |  |  |  |  |  |  | throw Error::Simple ("ERROR: Net::FreeDB2::Connection::CDDBP::_initialize, CDDBP access through proxy not (yet) implemented."); | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | # Initialize super class | 
| 61 | 0 |  |  |  |  |  | return ($self->SUPER::_initialize ($opt)); | 
| 62 |  |  |  |  |  |  | } | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | sub connect { | 
| 65 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | # Make socket connection | 
| 68 | 1 |  |  | 1 |  | 1269 | use IO::Socket::INET; | 
|  | 1 |  |  |  |  | 25784 |  | 
|  | 1 |  |  |  |  | 9 |  | 
| 69 | 0 |  | 0 |  |  |  | my $connection = IO::Socket::INET->new ( | 
| 70 |  |  |  |  |  |  | PeerAddr => $self->getFreeDBHost (), | 
| 71 |  |  |  |  |  |  | PeerPort => $self->getFreeDBPort () || 8880, | 
| 72 |  |  |  |  |  |  | ); | 
| 73 | 0 | 0 |  |  |  |  | defined ($connection) || throw Error::Simple ('ERROR: Net::FreeDB2::Connection::CDDBP::connect, Failed to instanciate an \'IO::Socket::INET\' object.'); | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | # Set the connection | 
| 76 | 0 |  |  |  |  |  | $self->setConnection ($connection); | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | # Send command and wait for reply | 
| 79 | 0 |  |  |  |  |  | my $content_ref = $self->waitCommandReply (undef, { | 
| 80 |  |  |  |  |  |  | 200 => $FINAL_EOL_RX, | 
| 81 |  |  |  |  |  |  | 201 => $FINAL_EOL_RX, | 
| 82 |  |  |  |  |  |  | 432 => $FINAL_EOL_RX, | 
| 83 |  |  |  |  |  |  | 433 => $FINAL_EOL_RX, | 
| 84 |  |  |  |  |  |  | 434 => $FINAL_EOL_RX, | 
| 85 |  |  |  |  |  |  | }); | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | # Parse the result and store it | 
| 88 | 1 |  |  | 1 |  | 1676 | use Net::FreeDB2::Response::SignOn; | 
|  | 1 |  |  |  |  | 4 |  | 
|  | 1 |  |  |  |  | 320 |  | 
| 89 | 0 |  |  |  |  |  | $self->setSignOnResponse (Net::FreeDB2::Response::SignOn->new ({ | 
| 90 |  |  |  |  |  |  | content_ref => $content_ref | 
| 91 |  |  |  |  |  |  | })); | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | # Send a hello | 
| 94 | 0 |  |  |  |  |  | my $res = $self->hello (); | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | # Disconnect and throw exception if error | 
| 97 | 0 | 0 |  |  |  |  | if ($res->hasError ()) { | 
| 98 | 0 |  |  |  |  |  | $self->setConnection (); | 
| 99 | 0 |  |  |  |  |  | throw Error::Simple ('ERROR: Net::FreeDB2::Connection::CDDBP::connect, handshake failed.'); | 
| 100 |  |  |  |  |  |  | } | 
| 101 |  |  |  |  |  |  | } | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | sub lscat { | 
| 104 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | # Send command and wait for reply | 
| 107 | 0 |  |  |  |  |  | my $content_ref = $self->waitCommandReply ('cddb lscat', { | 
| 108 |  |  |  |  |  |  | 210 => $FINAL_DOT_RX, | 
| 109 |  |  |  |  |  |  | }); | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | # Parse the result | 
| 112 | 0 |  |  |  |  |  | my @content = split (/[\n\r]+/, ${$content_ref}); | 
|  | 0 |  |  |  |  |  |  | 
| 113 | 0 |  |  |  |  |  | shift (@content); | 
| 114 | 0 |  |  |  |  |  | my @cat = (); | 
| 115 | 0 |  |  |  |  |  | foreach my $cat (@content) { | 
| 116 | 0 | 0 |  |  |  |  | last if ($cat eq '.'); | 
| 117 | 0 |  |  |  |  |  | push (@cat, $cat); | 
| 118 |  |  |  |  |  |  | } | 
| 119 | 0 |  |  |  |  |  | return (@cat); | 
| 120 |  |  |  |  |  |  | } | 
| 121 |  |  |  |  |  |  |  | 
| 122 |  |  |  |  |  |  | sub query { | 
| 123 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 124 | 0 |  |  |  |  |  | my $entity = shift; | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | # Send command and wait for reply | 
| 127 | 0 |  |  |  |  |  | my $cmd = 'cddb query ' . $entity->mkQuery (); | 
| 128 | 0 |  |  |  |  |  | my $content_ref = $self->waitCommandReply ($cmd, { | 
| 129 |  |  |  |  |  |  | 200 => $FINAL_EOL_RX, | 
| 130 |  |  |  |  |  |  | 211 => $FINAL_DOT_RX, | 
| 131 |  |  |  |  |  |  | 202 => $FINAL_EOL_RX, | 
| 132 |  |  |  |  |  |  | 403 => $FINAL_EOL_RX, | 
| 133 |  |  |  |  |  |  | 409 => $FINAL_EOL_RX, | 
| 134 |  |  |  |  |  |  | }); | 
| 135 |  |  |  |  |  |  |  | 
| 136 |  |  |  |  |  |  | # Parse the result | 
| 137 | 1 |  |  | 1 |  | 680 | use Net::FreeDB2::Response::Query; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 167 |  | 
| 138 | 0 |  |  |  |  |  | return Net::FreeDB2::Response::Query->new ({ | 
| 139 |  |  |  |  |  |  | content_ref => $content_ref, | 
| 140 |  |  |  |  |  |  | }); | 
| 141 |  |  |  |  |  |  | } | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | sub read { | 
| 144 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 145 | 0 |  |  |  |  |  | my $match = shift; | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | # Send command and wait for reply | 
| 148 | 0 |  |  |  |  |  | my $cmd = 'cddb read ' . $match->getCateg () . ' '  . $match->getDiscid (); | 
| 149 | 0 |  |  |  |  |  | my $content_ref = $self->waitCommandReply ($cmd, { | 
| 150 |  |  |  |  |  |  | 210 => $FINAL_DOT_RX, | 
| 151 |  |  |  |  |  |  | 401 => $FINAL_EOL_RX, | 
| 152 |  |  |  |  |  |  | 402 => $FINAL_EOL_RX, | 
| 153 |  |  |  |  |  |  | 403 => $FINAL_EOL_RX, | 
| 154 |  |  |  |  |  |  | 409 => $FINAL_EOL_RX, | 
| 155 |  |  |  |  |  |  | }); | 
| 156 |  |  |  |  |  |  |  | 
| 157 |  |  |  |  |  |  | # Parse the result | 
| 158 | 1 |  |  | 1 |  | 749 | use Net::FreeDB2::Response::Read; | 
|  | 1 |  |  |  |  | 4 |  | 
|  | 1 |  |  |  |  | 535 |  | 
| 159 | 0 |  |  |  |  |  | return Net::FreeDB2::Response::Read->new ({ | 
| 160 |  |  |  |  |  |  | content_ref => $content_ref, | 
| 161 |  |  |  |  |  |  | }); | 
| 162 |  |  |  |  |  |  | } | 
| 163 |  |  |  |  |  |  |  | 
| 164 |  |  |  |  |  |  | sub write { | 
| 165 | 0 |  |  | 0 | 1 |  | throw Error::Simple ("ERROR: Net::FreeDB2::Connection::CDDBP::write, to be implemented."); | 
| 166 |  |  |  |  |  |  | } | 
| 167 |  |  |  |  |  |  |  | 
| 168 |  |  |  |  |  |  | sub log { | 
| 169 | 0 |  |  | 0 | 1 |  | throw Error::Simple ("ERROR: Net::FreeDB2::CDDBP::log, to be implemented."); | 
| 170 |  |  |  |  |  |  | } | 
| 171 |  |  |  |  |  |  |  | 
| 172 |  |  |  |  |  |  | sub motd { | 
| 173 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 174 |  |  |  |  |  |  |  | 
| 175 |  |  |  |  |  |  | # Send command and wait for reply | 
| 176 | 0 |  |  |  |  |  | my $content_ref = $self->waitCommandReply ('motd', { | 
| 177 |  |  |  |  |  |  | 210 => $FINAL_DOT_RX, | 
| 178 |  |  |  |  |  |  | 401 => $FINAL_EOL_RX, | 
| 179 |  |  |  |  |  |  | }); | 
| 180 |  |  |  |  |  |  |  | 
| 181 |  |  |  |  |  |  | # Parse the result | 
| 182 | 0 |  |  |  |  |  | my @content = split (/[\n\r]+/, ${$content_ref}); | 
|  | 0 |  |  |  |  |  |  | 
| 183 | 0 |  |  |  |  |  | my $head = shift (@content); | 
| 184 | 0 |  |  |  |  |  | my @motd = (); | 
| 185 | 0 |  |  |  |  |  | foreach my $motd (@content) { | 
| 186 | 0 | 0 |  |  |  |  | last if ($motd eq '.'); | 
| 187 | 0 |  |  |  |  |  | push (@motd, $motd); | 
| 188 |  |  |  |  |  |  | } | 
| 189 | 0 |  |  |  |  |  | return (@motd); | 
| 190 |  |  |  |  |  |  | } | 
| 191 |  |  |  |  |  |  |  | 
| 192 |  |  |  |  |  |  | sub discid { | 
| 193 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 194 | 0 |  |  |  |  |  | my $entity = shift; | 
| 195 |  |  |  |  |  |  |  | 
| 196 |  |  |  |  |  |  | # Send command and wait for reply | 
| 197 | 0 |  |  |  |  |  | my $cmd = 'discid ' . $entity->mkQuery (); | 
| 198 | 0 |  |  |  |  |  | my $content_ref = $self->waitCommandReply ($cmd, { | 
| 199 |  |  |  |  |  |  | 200 => $FINAL_EOL_RX, | 
| 200 |  |  |  |  |  |  | 500 => $FINAL_EOL_RX, | 
| 201 |  |  |  |  |  |  | }); | 
| 202 |  |  |  |  |  |  |  | 
| 203 |  |  |  |  |  |  | # Parse the result | 
| 204 | 0 |  |  |  |  |  | my @content = split (/[\n\r]+/, ${$content_ref}); | 
|  | 0 |  |  |  |  |  |  | 
| 205 | 0 |  |  |  |  |  | my $head = shift (@content); | 
| 206 | 0 |  |  |  |  |  | my ($code) = $head =~ /^\s*(\d{3})\s+/; | 
| 207 | 0 | 0 |  |  |  |  | $code == 500 && throw Error::Simple ("ERROR: Net::FreeDB2::Connection::CDDBP::discid, Command Syntax error."); | 
| 208 | 0 |  |  |  |  |  | my @head = split (/\s+/, $head); | 
| 209 | 0 |  |  |  |  |  | return ($head[4]); | 
| 210 |  |  |  |  |  |  | } | 
| 211 |  |  |  |  |  |  |  | 
| 212 |  |  |  |  |  |  | sub proto { | 
| 213 | 0 |  |  | 0 | 1 |  | throw Error::Simple ("ERROR: Net::FreeDB2::CDDBP::proto, to be implemented."); | 
| 214 |  |  |  |  |  |  | } | 
| 215 |  |  |  |  |  |  |  | 
| 216 |  |  |  |  |  |  | sub sites { | 
| 217 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 218 |  |  |  |  |  |  |  | 
| 219 |  |  |  |  |  |  | # Send command and wait for reply | 
| 220 | 0 |  |  |  |  |  | my $content_ref = $self->waitCommandReply ('sites', { | 
| 221 |  |  |  |  |  |  | 210 => $FINAL_DOT_RX, | 
| 222 |  |  |  |  |  |  | 401 => $FINAL_EOL_RX, | 
| 223 |  |  |  |  |  |  | }); | 
| 224 |  |  |  |  |  |  |  | 
| 225 |  |  |  |  |  |  | # Parse the result | 
| 226 | 1 |  |  | 1 |  | 680 | use Net::FreeDB2::Response::Sites; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 347 |  | 
| 227 | 0 |  |  |  |  |  | return Net::FreeDB2::Response::Sites->new ({ | 
| 228 |  |  |  |  |  |  | content_ref => $content_ref, | 
| 229 |  |  |  |  |  |  | }); | 
| 230 |  |  |  |  |  |  | } | 
| 231 |  |  |  |  |  |  |  | 
| 232 |  |  |  |  |  |  | sub stat { | 
| 233 | 0 |  |  | 0 | 1 |  | throw Error::Simple ("ERROR: Net::FreeDB2::CDDBP::stat, to be implemented."); | 
| 234 |  |  |  |  |  |  | } | 
| 235 |  |  |  |  |  |  |  | 
| 236 |  |  |  |  |  |  | sub ver { | 
| 237 | 0 |  |  | 0 | 1 |  | throw Error::Simple ("ERROR: Net::FreeDB2::CDDBP::ver, to be implemented."); | 
| 238 |  |  |  |  |  |  | } | 
| 239 |  |  |  |  |  |  |  | 
| 240 |  |  |  |  |  |  | sub update { | 
| 241 | 0 |  |  | 0 | 1 |  | throw Error::Simple ("ERROR: Net::FreeDB2::CDDBP::update, to be implemented."); | 
| 242 |  |  |  |  |  |  | } | 
| 243 |  |  |  |  |  |  |  | 
| 244 |  |  |  |  |  |  | sub whom { | 
| 245 | 0 |  |  | 0 | 1 |  | throw Error::Simple ("ERROR: Net::FreeDB2::CDDBP::whom, to be implemented."); | 
| 246 |  |  |  |  |  |  | } | 
| 247 |  |  |  |  |  |  |  | 
| 248 |  |  |  |  |  |  | sub setSignOnResponse { | 
| 249 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 250 |  |  |  |  |  |  |  | 
| 251 |  |  |  |  |  |  | # Set FreeDB/CDDB sign-on response | 
| 252 | 0 |  |  |  |  |  | $self->{Net_FreeDB2_Connection_CDDBP}{sign_on_response} = shift; | 
| 253 |  |  |  |  |  |  | } | 
| 254 |  |  |  |  |  |  |  | 
| 255 |  |  |  |  |  |  | sub getSignOnResponse { | 
| 256 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 257 |  |  |  |  |  |  |  | 
| 258 |  |  |  |  |  |  | # Return FreeDB/CDDB sign-on response | 
| 259 | 0 |  |  |  |  |  | return ($self->{Net_FreeDB2_Connection_CDDBP}{sign_on_response}); | 
| 260 |  |  |  |  |  |  | } | 
| 261 |  |  |  |  |  |  |  | 
| 262 |  |  |  |  |  |  | sub hello { | 
| 263 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 264 |  |  |  |  |  |  |  | 
| 265 |  |  |  |  |  |  | # Send command and wait for reply | 
| 266 | 0 |  |  |  |  |  | my $cmd = 'cddb ' . $self->mkHello (); | 
| 267 | 0 |  |  |  |  |  | my $content_ref = $self->waitCommandReply ($cmd, { | 
| 268 |  |  |  |  |  |  | 200 => $FINAL_EOL_RX, | 
| 269 |  |  |  |  |  |  | 431 => $FINAL_EOL_RX, | 
| 270 |  |  |  |  |  |  | 402 => $FINAL_EOL_RX, | 
| 271 |  |  |  |  |  |  | }); | 
| 272 |  |  |  |  |  |  |  | 
| 273 |  |  |  |  |  |  | # Parse the result and return it | 
| 274 | 1 |  |  | 1 |  | 717 | use Net::FreeDB2::Response::Hello; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 544 |  | 
| 275 | 0 |  |  |  |  |  | return (Net::FreeDB2::Response::Hello->new ({ | 
| 276 |  |  |  |  |  |  | content_ref => $content_ref | 
| 277 |  |  |  |  |  |  | })); | 
| 278 |  |  |  |  |  |  | } | 
| 279 |  |  |  |  |  |  |  | 
| 280 |  |  |  |  |  |  | sub quit { | 
| 281 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 282 |  |  |  |  |  |  |  | 
| 283 |  |  |  |  |  |  | # Send command and wait for reply | 
| 284 | 0 |  |  |  |  |  | my $content_ref = $self->waitCommandReply ('quit', { | 
| 285 |  |  |  |  |  |  | 230 => $FINAL_EOL_RX, | 
| 286 |  |  |  |  |  |  | }); | 
| 287 |  |  |  |  |  |  |  | 
| 288 |  |  |  |  |  |  | # Disconnect | 
| 289 | 0 |  |  |  |  |  | $self->setConnection (); | 
| 290 |  |  |  |  |  |  | } | 
| 291 |  |  |  |  |  |  |  | 
| 292 |  |  |  |  |  |  | sub waitCommandReply { | 
| 293 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 294 | 0 |  |  |  |  |  | my $cmd = shift; | 
| 295 | 0 |  |  |  |  |  | my $rx = shift; | 
| 296 |  |  |  |  |  |  |  | 
| 297 |  |  |  |  |  |  | # Check if connection is defined | 
| 298 | 0 | 0 |  |  |  |  | defined ($self->getConnection ()) || throw Error::Simple ('ERROR: Net::FreeDB2::Connection::CDDBP::waitCommandReply, no connection available.'); | 
| 299 |  |  |  |  |  |  |  | 
| 300 |  |  |  |  |  |  | # Set blocking | 
| 301 | 0 |  |  |  |  |  | $self->getConnection->blocking (1); | 
| 302 |  |  |  |  |  |  |  | 
| 303 |  |  |  |  |  |  | # Send command | 
| 304 | 0 | 0 |  |  |  |  | defined ($cmd) && $self->getConnection ()->write ($cmd . "\r\n"); | 
| 305 |  |  |  |  |  |  |  | 
| 306 |  |  |  |  |  |  | # Wait for code | 
| 307 | 0 |  |  |  |  |  | $self->getConnection->read (my $head, 5); | 
| 308 | 0 |  |  |  |  |  | $head =~ s/^\s+//; | 
| 309 | 0 |  |  |  |  |  | my ($code) = $head =~ /(\d{3})/; | 
| 310 | 0 | 0 |  |  |  |  | exists ($rx->{$code}) || throw Error::Simple ("ERROR: Net::FreeDB2::Connection::CDDBP::waitCommandReply, unknown code '$code' returned."); | 
| 311 |  |  |  |  |  |  |  | 
| 312 |  |  |  |  |  |  | # Wait for the final DOT or EOL | 
| 313 | 0 |  |  |  |  |  | my $content .= $head; | 
| 314 | 0 |  |  |  |  |  | $self->getConnection->blocking (0); | 
| 315 | 0 |  |  |  |  |  | while (1) { | 
| 316 | 0 |  |  |  |  |  | $self->getConnection->read (my $rest, 1024); | 
| 317 | 0 |  |  |  |  |  | $content .= $rest; | 
| 318 | 0 | 0 |  |  |  |  | $content =~ /$rx->{$code}/ && last; | 
| 319 | 0 |  |  |  |  |  | sleep (1); | 
| 320 |  |  |  |  |  |  | } | 
| 321 |  |  |  |  |  |  |  | 
| 322 |  |  |  |  |  |  | # Return the content reference | 
| 323 | 0 |  |  |  |  |  | return (\$content); | 
| 324 |  |  |  |  |  |  | } | 
| 325 |  |  |  |  |  |  |  | 
| 326 |  |  |  |  |  |  | sub mkHello { | 
| 327 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 328 |  |  |  |  |  |  |  | 
| 329 | 0 | 0 |  |  |  |  | defined ($self->getClientName ()) || throw Error::Simple ('ERROR: Net::FreeDB2::Connection::CDDBP::mkHello, \'client_name\' not set.'); | 
| 330 | 0 | 0 |  |  |  |  | defined ($self->getClientVersion ()) || throw Error::Simple ('ERROR: Net::FreeDB2::Connection::CDDBP::mkHello, \'client_version\' not set.'); | 
| 331 | 0 | 0 |  |  |  |  | defined ($self->getClientHost ()) || throw Error::Simple ('ERROR: Net::FreeDB2::Connection::CDDBP::mkHello, \'client_host\' not set.'); | 
| 332 | 0 | 0 |  |  |  |  | defined ($self->getClientUser ()) || throw Error::Simple ('ERROR: Net::FreeDB2::Connection::CDDBP::mkHello, \'client_user\' not set.'); | 
| 333 |  |  |  |  |  |  |  | 
| 334 | 0 |  |  |  |  |  | return ('hello ' . join (' ', | 
| 335 |  |  |  |  |  |  | $self->getClientUser (), | 
| 336 |  |  |  |  |  |  | $self->getClientHost (), | 
| 337 |  |  |  |  |  |  | $self->getClientName (), | 
| 338 |  |  |  |  |  |  | $self->getClientVersion (), | 
| 339 |  |  |  |  |  |  | ) | 
| 340 |  |  |  |  |  |  | ); | 
| 341 |  |  |  |  |  |  | } | 
| 342 |  |  |  |  |  |  |  | 
| 343 |  |  |  |  |  |  | 1; | 
| 344 |  |  |  |  |  |  | __END__ |