[Slim-Checkins] r12613 - in /trunk/server/Slim: Control/Request.pm Web/Cometd.pm
andy at svn.slimdevices.com
andy at svn.slimdevices.com
Sun Aug 19 22:00:00 PDT 2007
Author: andy
Date: Sun Aug 19 22:00:00 2007
New Revision: 12613
URL: http://svn.slimdevices.com?rev=12613&view=rev
Log:
Go back to using JSON.pm for Cometd
Modified:
trunk/server/Slim/Control/Request.pm
trunk/server/Slim/Web/Cometd.pm
Modified: trunk/server/Slim/Control/Request.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Control/Request.pm?rev=12613&r1=12612&r2=12613&view=diff
==============================================================================
--- trunk/server/Slim/Control/Request.pm (original)
+++ trunk/server/Slim/Control/Request.pm Sun Aug 19 22:00:00 2007
@@ -860,7 +860,6 @@
'_ae_callback' => undef,
'_ae_filter' => undef,
'_private' => undef,
- '_disableTied' => 0,
};
bless $self, $class;
@@ -871,17 +870,6 @@
$self->validate();
return $self;
-}
-
-# Disable tied hashes
-sub disableTiedHashes {
- my $self = shift;
-
- $self->{_disableTied} = 1;
-
- # Copy tied hashes back into normal hashes
- $self->{_params} = { %{ $self->{_params} } };
- $self->{_results} = { %{ $self->{_results} } };
}
# makes a request out of another one, discarding results and callback data.
@@ -902,7 +890,6 @@
$copy->{'_ae_callback'} = $self->{'_ae_callback'};
$copy->{'_ae_filter'} = $self->{'_ae_filter'};
$copy->{'_curparam'} = $self->{'_curparam'};
- $copy->{'_disableTied'} = $self->{'_disableTied'};
# duplicate the arrays and hashes
my @request = @{$self->{'_request'}};
@@ -1293,11 +1280,7 @@
sub getParamsCopy {
my $self = shift;
- my %paramHash;
-
- if ( !$self->{'_disableTied'} ) {
- tie %paramHash, 'Tie::IxHash';
- }
+ tie my %paramHash, 'Tie::IxHash';
while (my ($key, $val) = each %{$self->{'_params'}}) {
$paramHash{$key} = $val;
@@ -1348,10 +1331,7 @@
}
if (!defined ${$self->{'_results'}}{$loop}->[$loopidx]) {
- my %paramHash;
- if ( !$self->{'_disableTied'} ) {
- tie %paramHash, 'Tie::IxHash';
- }
+ tie my %paramHash, 'Tie::IxHash';
${$self->{'_results'}}{$loop}->[$loopidx] = \%paramHash;
}
@@ -1495,11 +1475,7 @@
sub cleanResults {
my $self = shift;
- my %resultHash;
-
- if ( !$self->{'_disableTied'} ) {
- tie %resultHash, 'Tie::IxHash';
- }
+ tie my %resultHash, 'Tie::IxHash';
# not sure this helps release memory, but can't hurt
delete $self->{'_results'};
Modified: trunk/server/Slim/Web/Cometd.pm
URL: http://svn.slimdevices.com/trunk/server/Slim/Web/Cometd.pm?rev=12613&r1=12612&r2=12613&view=diff
==============================================================================
--- trunk/server/Slim/Web/Cometd.pm (original)
+++ trunk/server/Slim/Web/Cometd.pm Sun Aug 19 22:00:00 2007
@@ -11,7 +11,7 @@
# The primary purpose is for handling Jive connections, but it may also
# be used in the future for real-time updates to the web interface.
#
-# Much of this code is thanks to David Davis' cometd-perl implementation.
+# Some of this code is thanks to David Davis' cometd-perl implementation.
#
# Current protocol documentation is available at
# http://svn.xantus.org/shortbus/trunk/bayeux/bayeux.html
@@ -21,7 +21,8 @@
use bytes;
use Digest::SHA1 qw(sha1_hex);
use HTTP::Date;
-use JSON::XS qw(to_json from_json);
+use JSON;
+use JSON::XS qw(from_json);
use Scalar::Util qw(blessed);
use URI::Escape qw(uri_unescape);
@@ -37,7 +38,6 @@
my $manager = Slim::Web::Cometd::Manager->new;
use constant PROTOCOL_VERSION => '1.0';
-use constant HASH_KEY => 'sl1ms3rv3r';
use constant RETRY_DELAY => 5000;
sub init {
@@ -91,7 +91,7 @@
sendResponse(
$httpClient,
$httpResponse,
- [ { successful => JSON::XS::false, error => 'no bayeux message found' } ]
+ [ { successful => JSON::False, error => 'no bayeux message found' } ]
);
return;
}
@@ -101,7 +101,7 @@
sendResponse(
$httpClient,
$httpResponse,
- [ { successful => JSON::XS::false, error => "$@" } ]
+ [ { successful => JSON::False, error => "$@" } ]
);
return;
}
@@ -110,7 +110,7 @@
sendResponse(
$httpClient,
$httpResponse,
- [ { successful => JSON::XS::false, error => 'bayeux message not an array' } ]
+ [ { successful => JSON::False, error => 'bayeux message not an array' } ]
);
return;
}
@@ -128,7 +128,7 @@
sendResponse(
$httpClient,
$httpResponse,
- [ { successful => JSON::XS::false, error => 'bayeux event not a hash' } ]
+ [ { successful => JSON::False, error => 'bayeux event not a hash' } ]
);
return;
}
@@ -161,7 +161,7 @@
version => PROTOCOL_VERSION,
supportedConnectionTypes => [ 'long-polling', 'streaming' ],
clientId => $clid,
- successful => JSON::XS::true,
+ successful => JSON::True,
advice => {
reconnect => 'retry', # one of "none", "retry", "handshake", "recover"
interval => RETRY_DELAY, # retry delay in ms
@@ -176,7 +176,7 @@
push @{$events}, {
channel => '/meta/connect',
clientId => undef,
- successful => JSON::XS::false,
+ successful => JSON::False,
timestamp => time2str( time() ),
error => 'invalid clientId',
advice => {
@@ -191,7 +191,7 @@
push @{$events}, {
channel => '/meta/connect',
clientId => $clid,
- successful => JSON::XS::true,
+ successful => JSON::True,
timestamp => time2str( time() ),
};
@@ -224,7 +224,7 @@
push @{$events}, {
channel => '/meta/reconnect',
- successful => JSON::XS::false,
+ successful => JSON::False,
timestamp => time2str( time() ),
error => 'invalid clientId',
advice => {
@@ -240,7 +240,7 @@
push @{$events}, {
channel => '/meta/reconnect',
- successful => JSON::XS::true,
+ successful => JSON::True,
timestamp => time2str( time() ),
};
@@ -277,7 +277,7 @@
push @{$events}, {
channel => '/meta/disconnect',
clientId => undef,
- successful => JSON::XS::false,
+ successful => JSON::False,
error => 'invalid clientId',
};
}
@@ -287,7 +287,7 @@
push @{$events}, {
channel => '/meta/disconnect',
clientId => $clid,
- successful => JSON::XS::true,
+ successful => JSON::True,
timestamp => time2str( time() ),
};
@@ -314,7 +314,7 @@
push @{$events}, {
channel => '/meta/subscribe',
clientId => $clid,
- successful => JSON::XS::true,
+ successful => JSON::True,
ext => $obj->{ext},
};
@@ -351,7 +351,7 @@
channel => '/slim/request',
clientId => $clid,
id => $id,
- successful => JSON::XS::true,
+ successful => JSON::True,
ext => $obj->{data},
};
@@ -370,7 +370,7 @@
for my $error ( @errors ) {
push @{$out}, {
channel => $error->[0],
- successful => JSON::XS::false,
+ successful => JSON::False,
error => $error->[1],
};
}
@@ -396,9 +396,9 @@
$httpResponse->header( 'Cache-Control' => 'no-cache' );
$httpResponse->header( 'Content-Type' => 'application/json' );
- $out = eval { to_json( $out ) };
+ $out = eval { objToJson( $out, { utf8 => 1, autoconv => 0 } ) };
if ( $@ ) {
- $out = to_json( [ { successful => JSON::XS::false, error => "$@" } ] );
+ $out = objToJson( [ { successful => JSON::False, error => "$@" } ] );
}
my $sendheaders = 1; # should we send headers?
@@ -459,9 +459,6 @@
# fix the encoding and/or manage charset param
$request->fixEncoding;
- # We don't want tied hashes
- $request->disableTiedHashes;
-
# remember channel, request id and client id
$request->source( "$channel|$id" );
$request->connectionID( $clid );
More information about the checkins
mailing list