4 include("xmlrpcs.inc");
6 $addcomment_sig=array(array($xmlrpcInt, $xmlrpcString, $xmlrpcString, $xmlrpcString));
8 $addcomment_doc='Adds a comment to an item. The first parameter
9 is the item ID, the second the name of the commenter, and the third
10 is the comment itself. Returns the number of comments against that
13 function addcomment($m)
15 global $xmlrpcerruser;
17 // since validation has already been carried out for us,
18 // we know we got exactly 3 string values
19 $n = php_xmlrpc_decode($m);
24 $dbh=dba_open("/tmp/comments.db", "c", "db2");
27 $countID="${msgID}_count";
28 if(dba_exists($countID, $dbh))
30 $count=dba_fetch($countID, $dbh);
36 // add the new comment in
37 dba_insert($msgID . "_comment_${count}", $comment, $dbh);
38 dba_insert($msgID . "_name_${count}", $name, $dbh);
40 dba_replace($countID, $count, $dbh);
45 $err="Unable to open comments database.";
47 // if we generated an error, create an error return response
50 return new xmlrpcresp(0, $xmlrpcerruser, $err);
54 // otherwise, we create the right response
55 // with the state name
56 return new xmlrpcresp(new xmlrpcval($count, "int"));
60 $getcomments_sig=array(array($xmlrpcArray, $xmlrpcString));
62 $getcomments_doc='Returns an array of comments for a given ID, which
63 is the sole argument. Each array item is a struct containing name
66 function getcomments($m)
68 global $xmlrpcerruser;
71 $msgID=php_xmlrpc_decode($m->getParam(0));
72 $dbh=dba_open("/tmp/comments.db", "r", "db2");
75 $countID="${msgID}_count";
76 if(dba_exists($countID, $dbh))
78 $count=dba_fetch($countID, $dbh);
79 for($i=0; $i<$count; $i++)
81 $name=dba_fetch("${msgID}_name_${i}", $dbh);
82 $comment=dba_fetch("${msgID}_comment_${i}", $dbh);
83 // push a new struct onto the return array
91 // if we generated an error, create an error return response
94 return new xmlrpcresp(0, $xmlrpcerruser, $err);
98 // otherwise, we create the right response
99 // with the state name
100 return new xmlrpcresp(php_xmlrpc_encode($ra));
104 $s = new xmlrpc_server(array(
105 "discuss.addComment" => array(
106 "function" => "addcomment",
107 "signature" => $addcomment_sig,
108 "docstring" => $addcomment_doc
110 "discuss.getComments" => array(
111 "function" => "getcomments",
112 "signature" => $getcomments_sig,
113 "docstring" => $getcomments_doc