Another small patch for the xmlrpc event plugin

Creating and modifying plugins.
Post Reply
TimNiceBut
Regular
Posts: 6
Joined: Sat May 17, 2008 10:56 pm
Location: Ashford, Kent, UK

Another small patch for the xmlrpc event plugin

Post by TimNiceBut »

This is not a bug per se, but IMHO the xmlrpc event plugin appears to trust the sender a little to much, at least when it comes to sending correct data.

Background: I'm using Emacs's weblogger.el mode to post to my blog. This has been almost working for quite a while but there was one remaining annoyance. Namely, any new posts created in weblogger mode would show up as if they were 'older' than the first post to the blog. What was even odder was that they always displayed the current date and time instead of the creation timestamp. It turns out that weblogger (at the moment, but I intend to fix that sooner or later) sends rubbish data in the dateCreated node if you're posting via metaWeblog_newPost. Unfortunately this rubbish data is then interpreted as a bona fide timestamp, the function that decodes the timestamp returns 0 and I would guess 0 ends up in the database...

Anyway, the patch below fixes this by only accepting timestamps that are non-zero. A quick test on my blog suggests that this fixes the problem so it might be worth including this in the next release of the plugin.

Yes, I know that this is probably the wrong place to fix this issue but IMHO serendipity shouldn't really accept '0' as a timestamp via XML-RPC :D.

Code: Select all

--- serendipity_xmlrpc.inc.php.orig	2009-08-02 19:14:51.000000000 +0100
+++ serendipity_xmlrpc.inc.php	2009-08-02 19:16:55.000000000 +0100
@@ -448,7 +448,10 @@
     $entry['moderate_comments'] = serendipity_db_bool($serendipity['moderateCommentsDefault']);
 
     if (isset($post_array['dateCreated'])) {
-        $entry['timestamp']  = XML_RPC_iso8601_decode($post_array['dateCreated'],($post_array['dateCreated']{strlen($post_array['dateCreated'])-1} == "Z"));
+        $timestamp  = XML_RPC_iso8601_decode($post_array['dateCreated'],($post_array['dateCreated']{strlen($post_array['dateCreated'])-1} == "Z"));
+        /* Fix for broken clients that send rubbish in the dateCreated node */
+	if ($timestamp != 0)
+	    $entry['timestamp'] = $timestamp;
     }
 
     ob_start();
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Another small patch for the xmlrpc event plugin

Post by garvinhicking »

Hi!

I agree, it's good to catch those things. I've committed your patch, but modified it slightly to work in the universal_fixEntry() method instead.

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
TimNiceBut
Regular
Posts: 6
Joined: Sat May 17, 2008 10:56 pm
Location: Ashford, Kent, UK

Re: Another small patch for the xmlrpc event plugin

Post by TimNiceBut »

Thanks Gavin, much appreciated.
Post Reply