madeon (madeon) wrote in changelog,
madeon
madeon
changelog

[livejournal] r21995: LJSUP-12148: JSON-RPC

Committer: sbelyaev
LJSUP-12148: JSON-RPC
U   trunk/cgi-bin/LJ/JSON/RPC/Item.pm
U   trunk/cgi-bin/LJ/JSON/RPC.pm
Modified: trunk/cgi-bin/LJ/JSON/RPC/Item.pm
===================================================================
--- trunk/cgi-bin/LJ/JSON/RPC/Item.pm	2012-05-18 12:28:50 UTC (rev 21994)
+++ trunk/cgi-bin/LJ/JSON/RPC/Item.pm	2012-05-18 12:47:34 UTC (rev 21995)
@@ -24,6 +24,9 @@
     my $jsonrpc = $data->{'jsonrpc'};
     my $method  = $data->{'method'};
     my $params  = $data->{'params'};
+    if (exists $data->{'id'}) {
+        $self->{'id'} = $data->{'id'};
+    }
 
     $self->{'fatal'} = { 'error_code' => -32602, 'error_message' => 'Invalid params' } unless $params;
     $self->{'fatal'} = { 'error_code' => -32602, 'error_message' => 'Invalid params' } if ref $params eq 'ARRAY';
@@ -32,8 +35,8 @@
     }
 
     my $remote  = LJ::get_remote;
-    my $auth    = delete $params->{'auth'};
-    if (!$auth) {
+    my $auth    = delete $params->{'auth_token'};
+    if (!$auth || !$remote) {
         $self->{'fatal'} = { 'error_code' => -12600, 'error_message' => 'Auth is missed' };
     } else {
         if (!LJ::Auth->check_ajax_auth_token($remote, $uri, 'auth_token' => $auth)) {
@@ -44,7 +47,6 @@
         return $self;
     }
 
-
     $self->{'fatal'} = { 'error_code' => -32600, 'error_message' => 'Invalid Request' } unless $method;
     $self->{'fatal'} = { 'error_code' => -32600, 'error_message' => 'Invalid Request' } if !$jsonrpc || $jsonrpc ne '2.0';
 

Modified: trunk/cgi-bin/LJ/JSON/RPC.pm
===================================================================
--- trunk/cgi-bin/LJ/JSON/RPC.pm	2012-05-18 12:28:50 UTC (rev 21994)
+++ trunk/cgi-bin/LJ/JSON/RPC.pm	2012-05-18 12:47:34 UTC (rev 21995)
@@ -29,7 +29,7 @@
     };
 
     if ($@) {
-        warn $@;
+        warn $@ if $LJ::IS_DEV_SERVER;
         my $fatal = { 'error_code' => -32700, 'error_message' => 'Parse error' };
         $self->{'items'} = { 'item' => LJ::JSON::RPC::Item->new({ 'fatal' =>  $fatal })};
     }
@@ -41,6 +41,10 @@
     my ($self, $callback) = @_;
     my $items = $self->{'items'};
 
+    my $call_info = { 
+        'source' => 'jsonrpc',
+    };
+
     if (ref $items eq 'ARRAY') {
         foreach my $entry (@$items) {
             my $item = $entry->{'item'};
@@ -49,7 +53,7 @@
             my $method = $item->method;
             my $params = $item->params;
 
-            $entry->{'result'} = $callback->($method, $params);
+            $entry->{'result'} = $callback->($method, $params, $call_info);
         }
     } else {
         my $item   = $items->{'item'};
@@ -58,7 +62,7 @@
         my $method = $item->method;
         my $params = $item->params;
 
-       $items->{'result'} = $callback->($method, $params);
+       $items->{'result'} = $callback->($method, $params, $call_info);
     }
 }
 

Tags: livejournal, madeon, pm, sbelyaev
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments