changelog_bot (changelog_bot) wrote in changelog,
changelog_bot
changelog_bot
changelog

[livejournal] r16801: LJSUP-6014 New XC3::Event::RemoteProcedu...

Committer: dnikolaev
LJSUP-6014 New XC3::Event::RemoteProcedureCall was added.

U   trunk/cgi-bin/ljprotocol.pl
Modified: trunk/cgi-bin/ljprotocol.pl
===================================================================
--- trunk/cgi-bin/ljprotocol.pl	2010-06-11 11:00:08 UTC (rev 16800)
+++ trunk/cgi-bin/ljprotocol.pl	2010-06-15 07:12:59 UTC (rev 16801)
@@ -129,6 +129,33 @@
      "506" => [ E_TEMP, "Journal sync temporarily unavailable." ],
 );
 
+my %HANDLERS = (
+    login             => \&login,
+    getfriendgroups   => \&getfriendgroups,
+    getfriends        => \&getfriends,
+    friendof          => \&friendof,
+    checkfriends      => \&checkfriends,
+    getdaycounts      => \&getdaycounts,
+    postevent         => \&postevent,
+    editevent         => \&editevent,
+    syncitems         => \&syncitems,
+    getevents         => \&getevents,
+    editfriends       => \&editfriends,
+    editfriendgroups  => \&editfriendgroups,
+    consolecommand    => \&consolecommand,
+    getchallenge      => \&getchallenge,
+    sessiongenerate   => \&sessiongenerate,
+    sessionexpire     => \&sessionexpire,
+    getusertags       => \&getusertags,
+    getfriendspage    => \&getfriendspage,
+    getinbox          => \&getinbox,
+    sendmessage       => \&sendmessage,
+    setmessageread    => \&setmessageread,
+    addcomment        => \&addcomment,
+    checksession      => \&checksession,
+    getrecentcomments => \&getrecentcomments
+);
+
 sub translate
 {
     my ($u, $msg, $vars) = @_;
@@ -190,33 +217,48 @@
     LJ::Request->notes("codepath" => "protocol.$method")
         if LJ::Request->is_inited && ! LJ::Request->notes("codepath");
 
-    if ($method eq "login")            { return login(@args);            }
-    if ($method eq "getfriendgroups")  { return getfriendgroups(@args);  }
-    if ($method eq "getfriends")       { return getfriends(@args);       }
-    if ($method eq "friendof")         { return friendof(@args);         }
-    if ($method eq "checkfriends")     { return checkfriends(@args);     }
-    if ($method eq "getdaycounts")     { return getdaycounts(@args);     }
-    if ($method eq "postevent")        { return postevent(@args);        }
-    if ($method eq "editevent")        { return editevent(@args);        }
-    if ($method eq "syncitems")        { return syncitems(@args);        }
-    if ($method eq "getevents")        { return getevents(@args);        }
-    if ($method eq "editfriends")      { return editfriends(@args);      }
-    if ($method eq "editfriendgroups") { return editfriendgroups(@args); }
-    if ($method eq "consolecommand")   { return consolecommand(@args);   }
-    if ($method eq "getchallenge")     { return getchallenge(@args);     }
-    if ($method eq "sessiongenerate")  { return sessiongenerate(@args);  }
-    if ($method eq "sessionexpire")    { return sessionexpire(@args);    }
-    if ($method eq "getusertags")      { return getusertags(@args);      }
-    if ($method eq "getfriendspage")   { return getfriendspage(@args);   }
-    if ($method eq "getinbox")         { return getinbox(@args);         }
-    if ($method eq "sendmessage")      { return sendmessage(@args);      }
-    if ($method eq "setmessageread")   { return setmessageread(@args);   }
-    if ($method eq "addcomment")       { return addcomment(@args);   }
-    if ($method eq 'checksession')     { return checksession(@args);     }
-    if ($method eq "getrecentcomments")       { return getrecentcomments(@args);   }
+    my $method_ref = $HANDLERS{$method};
 
+    if ($method_ref)
+    {
+        my $result = $method_ref->(@args);
+
+        if ($result && exists $result->{xc3})
+        {
+            my $xc3 = delete $result->{xc3};
+
+            if ($req->{props}->{interface} eq 'xml-rpc')
+            {
+                my $ua = eval { LJ::Request->header_in("User-Agent") };
+                Encode::from_to($ua, 'utf8', 'utf8') if $ua;
+
+                my ($ip_class, $country) = LJ::GeoLocation->ip_class();
+
+                my $args = {
+                    function => $method || ''
+                };
+
+                if ($xc3->{u})
+                {
+                    my $u = $xc3->{u};
+                    $args->{userid} = $u->userid;
+                    $args->{usercaps} = $u->caps;
+                }
+
+                $args->{useragent} = $ua if $ua;
+                $args->{country}   = $country if $country;
+                $args->{post}      = $xc3->{post} if $xc3->{post};
+                $args->{comment}   = $xc3->{comment} if $xc3->{comment};
+
+                LJ::run_hooks("remote_procedure_call", $args);
+            }
+        }
+
+        return $result;
+    }
+
     LJ::Request->notes("codepath" => "") if LJ::Request->is_inited;
-    return fail($err,201);
+    return fail($err, 201);
 }
 
 sub checksession {
@@ -234,10 +276,12 @@
         session     => $u->id.":".$session->id.":".$session->auth,
         caps        => $u->caps,
         usejournals => list_usejournals($u),
+        xc3 => {
+            u => $u
+        }
     }
 }
 
-
 sub addcomment
 {
     my ($req, $err, $flags) = @_;
@@ -260,24 +304,30 @@
     
     # create
     my $comment = LJ::Comment->create(
-                        journal      => $journal,
-                        ditemid      => $req->{ditemid},
-                        parenttalkid => ($req->{parenttalkid} || int($req->{parent} / 256)),
+        journal      => $journal,
+        ditemid      => $req->{ditemid},
+        parenttalkid => ($req->{parenttalkid} || int($req->{parent} / 256)),
 
-                        poster       => $u,
+        poster       => $u,
 
-                        body         => $req->{body},
-                        subject      => $req->{subject},
+        body         => $req->{body},
+        subject      => $req->{subject},
 
-                        props        => { picture_keyword => $req->{prop_picture_keyword} }
-                        );
+        props        => { picture_keyword => $req->{prop_picture_keyword} }
+    );
 
     # OK
     return {
-             status      => "OK",
-             commentlink => $comment->url,
-             dtalkid     => $comment->dtalkid,
-             };
+        status      => "OK",
+        commentlink => $comment->url,
+        dtalkid     => $comment->dtalkid,
+        xc3 => {
+            u => $u,
+            comment => {
+                toplevel => ($comment->parenttalkid == 0 ? 1 : 0),
+            }
+        }
+    };
 }
 
 sub getrecentcomments {
@@ -311,7 +361,14 @@
         $comment->{postername} = $users->{$comment->{posterid}}
             && $users->{$comment->{posterid}}->username;
     }
-    return  { status => 'OK', comments => [ @recv ] };
+
+    return {
+        status => 'OK',
+        comments => [ @recv ],
+        xc3 => {
+            u => $u
+        }
+    };
 }
 
 
@@ -425,9 +482,15 @@
         delete $_->{posterid};
     }
 
-    LJ::run_hooks("getfriendspage", { 'userid' => $u->userid, });
-
-    return { entries => [ @res ], skip => $skip };
+    LJ::run_hooks("getfriendspage", {userid => $u->userid, });
+    
+    return {
+        entries => [ @res ],
+        skip => $skip,
+        xc3 => {
+            u => $u
+        }
+    };
 }
 
 sub getinbox
@@ -524,10 +587,15 @@
                    };
     }
 
-    return { 'skip'  => $skip,
-             'items' => \@res,
-             'login' => $u->user,
-             'journaltype' => $u->journaltype };
+    return {
+        'skip'  => $skip,
+        'items' => \@res,
+        'login' => $u->user,
+        'journaltype' => $u->journaltype,
+        xc3 => {
+            u => $u
+        }
+    };
 }
 
 sub setmessageread {
@@ -572,9 +640,11 @@
     }
 
     return {
-        result => \@result
+        result => \@result,
+        xc3 => {
+            u => $u
+        }
     };
-
 }
 
 sub sendmessage
@@ -643,9 +713,14 @@
         $msg->send(\@errors);
     }
 
-    return { 'sent_count' => scalar @msg, 'msgid' => [ grep { $_ } map { $_->msgid } @msg ],
-             (@errors ? ('last_errors' => \@errors) : () ),
-           };
+    return {
+        'sent_count' => scalar @msg,
+        'msgid' => [ grep { $_ } map { $_->msgid } @msg ],
+        (@errors ? ('last_errors' => \@errors) : () ),
+        xc3 => {
+            u => $u
+        }
+    };
 }
 
 sub login
@@ -654,7 +729,11 @@
     return undef unless authenticate($req, $err, $flags);
 
     my $u = $flags->{'u'};
-    my $res = {};
+    my $res = {
+        xc3 => {
+            u => $u
+        }
+    };
     my $ver = $req->{'ver'};
 
     ## check for version mismatches
@@ -767,7 +846,7 @@
             $sth->execute;
         }
     }
-
+    
     return $res;
 }
 
@@ -776,7 +855,12 @@
     my ($req, $err, $flags) = @_;
     return undef unless authenticate($req, $err, $flags);
     my $u = $flags->{'u'};
-    my $res = {};
+    my $res = {
+        xc3 => {
+            u => $u
+        }
+    };
+    
     $res->{'friendgroups'} = list_friendgroups($u);
     return fail($err, 502, "Error loading friend groups") unless $res->{'friendgroups'};
     if ($req->{'ver'} >= 1) {
@@ -784,6 +868,7 @@
             LJ::text_out(\$_->{'name'});
         }
     }
+
     return $res;
 }
 
@@ -798,7 +883,12 @@
     return fail($req, 502) unless $u && $uowner;
 
     my $tags = LJ::Tags::get_usertags($uowner, { remote => $u });
-    return { tags => [ values %$tags ] };
+    return {
+        tags => [ values %$tags ],
+        xc3 => {
+            u => $u
+        }
+    };
 }
 
 sub getfriends
@@ -807,7 +897,12 @@
     return undef unless authenticate($req, $err, $flags);
     return fail($req,502) unless LJ::get_db_reader();
     my $u = $flags->{'u'};
-    my $res = {};
+    my $res = {
+        xc3 => {
+            u => $u
+        }
+    };
+
     if ($req->{'includegroups'}) {
         $res->{'friendgroups'} = list_friendgroups($u);
         return fail($err, 502, "Error loading friend groups") unless $res->{'friendgroups'};
@@ -835,6 +930,7 @@
     if ($req->{'ver'} >= 1) {
         foreach(@{$res->{'friends'}}) { LJ::text_out(\$_->{'fullname'}) };
     }
+    
     return $res;
 }
 
@@ -844,7 +940,11 @@
     return undef unless authenticate($req, $err, $flags);
     return fail($req,502) unless LJ::get_db_reader();
     my $u = $flags->{'u'};
-    my $res = {};
+    my $res = {
+        xc3 => {
+            u => $u
+        }
+    };
 
     # TAG:FR:protocol:getfriends_of2 (same as TAG:FR:protocol:getfriends_of)
     $res->{'friendofs'} = list_friends($u, {
@@ -854,6 +954,7 @@
     if ($req->{'ver'} >= 1) {
         foreach(@{$res->{'friendofs'}}) { LJ::text_out(\$_->{'fullname'}) };
     }
+
     return $res;
 }
 
@@ -862,7 +963,11 @@
     my ($req, $err, $flags) = @_;
     return undef unless authenticate($req, $err, $flags);
     my $u = $flags->{'u'};
-    my $res = {};
+    my $res = {
+        xc3 => {
+            u => $u
+        }
+    };
 
     # return immediately if they can't use this mode
     unless (LJ::get_cap($u, "checkfriends")) {
@@ -932,6 +1037,7 @@
     }
 
     $res->{'lastupdate'} = $update;
+
     return $res;
 }
 
@@ -945,7 +1051,12 @@
     my $uowner = $flags->{'u_owner'} || $u;
     my $ownerid = $flags->{'ownerid'};
 
-    my $res = {};
+    my $res = {
+        xc3 => {
+            u => $u
+        }
+    };
+
     my $daycts = LJ::get_daycounts($uowner, $u);
     return fail($err,502) unless $daycts;
 
@@ -953,6 +1064,7 @@
         my $date = sprintf("%04d-%02d-%02d", $day->[0], $day->[1], $day->[2]);
         push @{$res->{'daycounts'}}, { 'date' => $date, 'count' => $day->[3] };
     }
+
     return $res;
 }
 
@@ -1143,6 +1255,7 @@
     my $uowner = $flags->{'u_owner'} || $u;
     # Make sure we have a real user object here
     $uowner = LJ::want_user($uowner) unless LJ::isu($uowner);
+    r($uowner) unless LJ::isu($uowner);
     my $clusterid = $uowner->{'clusterid'};
 
     my $dbh = LJ::get_db_writer();
@@ -1483,13 +1596,25 @@
             }
 
             my $msg = translate($u, "modpost", undef);
-            return { 'message' => $msg };
+            return {
+                'message' => $msg,
+                xc3 => {
+                    u => $u,
+                    post => {
+                        id          => 
+                        has_images  => ($req->{event} =~ /pics\.livejournal\.com/ ? 1 : 0),
+                        from_mobile => ($req->{event} =~ /m\.livejournal\.com/ ? 1 : 0)
+                    }
+                }
+            };
         }
     } # /moderated comms
 
     # posting:
 
-    $getlock->(); return $res if $res_done;
+    $getlock->();
+    
+    return $res if $res_done;
 
     # do rate-checking
     if ($u->{'journaltype'} ne "Y" && ! LJ::rate_log($u, "post", 1)) {
@@ -1718,6 +1843,15 @@
         # TODO: error on failure?  depends on the job I suppose?  property of the job?
     }
 
+    $res->{xc3} = {
+        u => $u,
+        post => {
+            url         => $res->{url},
+            has_images  => ($req->{event} =~ /pics\.livejournal\.com/ ? 1 : 0),
+            from_mobile => ($req->{event} =~ /m\.livejournal\.com/ ? 1 : 0)
+        }
+    };
+
     return $res;
 }
 
@@ -1877,8 +2011,14 @@
         # what they just deleted.  (or something... probably rare.)
         LJ::set_userprop($poster, "dupsig_post", undef) if $poster;
 
-        my $res = { 'itemid' => $itemid,
-                    'anum' => $oldevent->{'anum'} };
+        my $res = {
+            'itemid' => $itemid,
+            'anum' => $oldevent->{'anum'},
+            xc3 => {
+                u => $u
+            }
+        };
+
         return $res;
     }
 
@@ -2122,6 +2262,15 @@
         # TODO: error on failure?  depends on the job I suppose?  property of the job?
     }
 
+    $res->{xc3} = {
+        u => $u,
+        post => {
+            url         => $res->{url},
+            has_images  => ($req->{event} =~ /pics\.livejournal\.com/ ? 1 : 0),
+            from_mobile => ($req->{event} =~ /m\.livejournal\.com/ ? 1 : 0)
+        }
+    };
+
     return $res;
 }
 
@@ -2380,7 +2529,12 @@
 
     my $count = 0;
     my @itemids = ();
-    my $res = { skip => $skip };
+    my $res = {
+        skip => $skip,
+        xc3 => {
+            u => $u
+        }
+    };
     my $events = $res->{'events'} = [];
     my %evt_from_itemid;
 
@@ -2572,7 +2726,11 @@
 #            unless LJ::RateLimit->check($u, [ $cond ]);
 #    }
 
-    my $res = {};
+    my $res = {
+        xc3 => {
+            u => $u
+        }
+    };
 
     ## first, figure out who the current friends are to save us work later
     my %curfriend;
@@ -2904,26 +3062,38 @@
     LJ::mark_dirty($u, "friends");
 
     # return value for this is nothing.
-    return {};
+    return {
+        xc3 => {
+            u => $u
+        }
+    };
 }
 
 sub sessionexpire {
     my ($req, $err, $flags) = @_;
     return undef unless authenticate($req, $err, $flags);
     my $u = $flags->{u};
+    my $res = {
+        xc3 => {
+            u => $u
+        }
+    };
 
     # expunge one? or all?
     if ($req->{expireall}) {
         $u->kill_all_sessions;
-        return {};
+        return $res;
     }
 
     # just expire a list
     my $list = $req->{expire} || [];
-    return {} unless @$list;
+
+    return $res unless @$list;
+
     return fail($err,502) unless $u->writer;
-    $u->kill_sessions(@$list);
-    return {};
+    $u->killi_sessions(@$list);
+
+    return $res;
 }
 
 sub sessiongenerate {
@@ -2950,6 +3120,9 @@
     # return our hash
     return {
         ljsession => $sess->master_cookie_string,
+        xc3 => {
+            u => $u
+        }
     };
 }
 
@@ -3096,7 +3269,11 @@
 
     my @ev = sort { $a->[2] cmp $b->[2] } (values %item, values %cmt);
 
-    my $res = {};
+    my $res = {
+        xc3 => {
+            u => $flags->{'u'}
+        }
+    };
     my $list = $res->{'syncitems'} = [];
     $res->{'total'} = scalar @ev;
     my $ct = 0;
@@ -3108,6 +3285,7 @@
         last if $ct >= $LIMIT;
     }
     $res->{'count'} = $ct;
+
     return $res;
 }
 
@@ -3118,7 +3296,11 @@
     # logging in isn't necessary, but most console commands do require it
     LJ::set_remote($flags->{'u'}) if authenticate($req, $err, $flags);
 
-    my $res = {};
+    my $res = {
+        xc3 => {
+            u => $flags->{'u'}
+        }
+    };
     my $cmdout = $res->{'results'} = [];
 
     foreach my $cmd (@{$req->{'commands'}}) {
@@ -3146,11 +3328,13 @@
     my $res = {};
     my $now = time();
     my $etime = 60;
-    $res->{'challenge'} = LJ::challenge_generate($etime);
-    $res->{'server_time'} = $now;
-    $res->{'expire_time'} = $now + $etime;
-    $res->{'auth_scheme'} = "c0";  # fixed for now, might support others later
-    return $res;
+    return {
+        challenge   => LJ::challenge_generate($etime),
+        server_time => $now,
+        expire_time => $now + $etime,
+        auth_scheme => "c0",  # fixed for now, might support others later
+        xc3         => {}
+    };
 }
 
 sub login_message
@@ -3471,6 +3655,7 @@
     }
 }
 
+
 #### Old interface (flat key/values) -- wrapper aruond LJ::Protocol
 package LJ;
 

Tags: changelog_bot, livejournal, pl
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