Skip to content

Commit

Permalink
Item14033: json method from pathinfo lost
Browse files Browse the repository at this point in the history
- fixed parsing the json method
- removed debug left-overs
- fixed build.pl to use https
- fixed crash in TRACE mode
  • Loading branch information
MichaelDaum committed Jun 3, 2016
1 parent 7750451 commit dbe0224
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 39 deletions.
Expand Up @@ -2,7 +2,11 @@
# ---++ JsonRpcContrib
# **PERL H LABEL="SwitchBoard - jsonrpc"**
# This setting is required to enable executing jsonrpc from the bin directory
$Foswiki::cfg{SwitchBoard}{jsonrpc} = ['Foswiki::Contrib::JsonRpcContrib', 'dispatch', {jsonrpc => 1}];
$Foswiki::cfg{SwitchBoard}{jsonrpc} = {
package => 'Foswiki::Contrib::JsonRpcContrib',
function => 'dispatch',
context => {jsonrpc => 1}
};
# ---++ JQueryPlugin
# ---+++ Extra plugins
# **BOOLEAN LABEL="JsonRPC"**
Expand Down
9 changes: 0 additions & 9 deletions JsonRpcContrib/lib/Foswiki/Contrib/JsonRpcContrib/Request.pm
Expand Up @@ -152,31 +152,22 @@ sub param {
my ( $this, @p ) = @_;
my ( $key, $value ) = @p;

print STDERR "Jsonrpc::Request::param() entered\n";
print STDERR Data::Dumper::Dumper( \@p );

return unless $key;

print STDERR Data::Dumper::Dumper( \$this->{data}{params}{$key} );

$this->{data}{params}{$key} = $value if defined $value;
return $this->{data}{params}{$key};
}

##############################################################################
sub params {
print STDERR "Jsonrpc::Request::params() entered\n";
print STDERR Data::Dumper::Dumper( \$_[0]->{data}{params} );
return $_[0]->{data}{params};
}

##############################################################################
sub method {
my ( $this, $value ) = @_;

print STDERR "Jsonrpc::Request::method() entered\n";
$this->{data}{method} = $value if defined $value;
print STDERR Data::Dumper::Dumper( \$_[0]->{data}{method} );
return $this->{data}{method};
}

Expand Down
19 changes: 1 addition & 18 deletions JsonRpcContrib/lib/Foswiki/Contrib/JsonRpcContrib/build.pl
@@ -1,27 +1,10 @@
#!/usr/bin/perl -w
#!/usr/bin/env perl
BEGIN { unshift @INC, split( /:/, $ENV{FOSWIKI_LIBS} ); }
use Foswiki::Contrib::Build;

# Create the build object
$build = new Foswiki::Contrib::Build('JsonRpcContrib');

# (Optional) Set the details of the repository for uploads.
# This can be any web on any accessible Foswiki installation.
# These defaults will be used when expanding tokens in .txt
# files, but be warned, they can be overridden at upload time!

# name of web to upload to
$build->{UPLOADTARGETWEB} = 'Extensions';

# Full URL of pub directory
$build->{UPLOADTARGETPUB} = 'http://foswiki.org/pub';

# Full URL of bin directory
$build->{UPLOADTARGETSCRIPT} = 'http://foswiki.org/bin';

# Script extension
$build->{UPLOADTARGETSUFFIX} = '';

# Build the target on the command line, or the default target
$build->build( $build->{target} );

26 changes: 15 additions & 11 deletions JsonRpcContrib/lib/Foswiki/Request/JSON.pm
Expand Up @@ -71,7 +71,7 @@ optional method from the path. eg: bin/jsonrpc/SomeNamespace/themethod
sub pathInfo {
my ( $this, $pathInfo ) = @_;

print STDERR " pathInfo entered " . Data::Dumper::Dumper( \$pathInfo )
_writeDebug("pathInfo entered " . Data::Dumper::Dumper( \$pathInfo ))
if Foswiki::Request::TRACE;

return $_[0]->SUPER::pathInfo() if @_ == 1;
Expand Down Expand Up @@ -152,7 +152,7 @@ Call SUPER::method() to access the http method.
sub method {
my ( $this, $value ) = @_;

print STDERR "method entered " . Data::Dumper::Dumper( \$value )
_writeDebug("method entered " . Data::Dumper::Dumper( \$value ))
if Foswiki::Request::TRACE;

if ( defined $value && !defined $this->{_jsondata} && lc($value) ne 'post' )
Expand Down Expand Up @@ -195,7 +195,7 @@ sub _establishJSON {
$data = ( ref($foo) eq 'ARRAY' ) ? shift @$foo : $foo;

$data ||= '{"jsonrpc":"2.0"}'; # Minimal setup
writeDebug("data=$data") if Foswiki::Request::TRACE;
_writeDebug("data=$data") if Foswiki::Request::TRACE;

$this->initFromString($data);

Expand All @@ -214,7 +214,7 @@ sub _establishJSON {
"Invalid JSON-RPC request - no method" )
unless defined $this->jsonmethod();

writeDebug( "method=" . $this->jsonmethod() || 'undef' )
_writeDebug( "jsonmethod=" . ($this->jsonmethod() || 'undef' ))
if Foswiki::Request::TRACE;

# must not have any other keys other than these
Expand All @@ -237,11 +237,11 @@ Initializes the {_jsondata} hash by processing the POSTDATA from the request.
sub initFromString {
my ( $this, $data ) = @_;

print STDERR "initFromString\n$data\n"
if Foswiki::Request::TRACE;
_writeDebug("initFromString\n$data") if Foswiki::Request::TRACE;

# parse json-rpc request
eval { $this->{_jsondata} = $this->json->decode($data); };
eval { %{$this->{_jsondata}} = (%{$this->{_jsondata}}, %{$this->json->decode($data)}); };
_writeDebug("after jsondata=".Data::Dumper::Dumper($this->{_jsondata}));

if ($@) {
my $error = $@;
Expand Down Expand Up @@ -350,7 +350,7 @@ can both read and write.
sub jsonmethod {
my ( $this, $value ) = @_;

print STDERR "jsonmethod entered " . Data::Dumper::Dumper( \$value )
_writeDebug("jsonmethod entered (this=$this)" . Data::Dumper::Dumper( \$value ))
if Foswiki::Request::TRACE;

$this->{_jsondata}{method} = $value if defined $value;
Expand Down Expand Up @@ -439,7 +439,7 @@ sub web {
$this->_establishAddress();
}

print STDERR "Request->web() returns " . ( $this->{web} || 'undef' ) . "\n"
_writeDebug("Request->web() returns " . ( $this->{web} || 'undef' ))
if Foswiki::Request::TRACE;
return $this->{web};

Expand All @@ -466,13 +466,17 @@ sub topic {
$this->_establishAddress();
}

print STDERR "Request->topic() returns "
. ( $this->{topic} || 'undef' ) . "\n"
_writeDebug("Request->topic() returns " . ( $this->{topic} || 'undef' ))
if Foswiki::Request::TRACE;
return $this->{topic};

}

# static
sub _writeDebug {
Foswiki::Func::writeDebug("- JsonRpcContrib::Request - $_[0]");
}

1;

__END__
Expand Down

0 comments on commit dbe0224

Please sign in to comment.