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 // get the first param
72 if(XMLRPC_EPI_ENABLED == '1')
74 $msgID=xmlrpc_decode($m->getParam(0));
78 $msgID=php_xmlrpc_decode($m->getParam(0));
80 $dbh=dba_open("/tmp/comments.db", "r", "db2");
83 $countID="${msgID}_count";
84 if(dba_exists($countID, $dbh))
86 $count=dba_fetch($countID, $dbh);
87 for($i=0; $i<$count; $i++)
89 $name=dba_fetch("${msgID}_name_${i}", $dbh);
90 $comment=dba_fetch("${msgID}_comment_${i}", $dbh);
91 // push a new struct onto the return array
99 // if we generated an error, create an error return response
102 return new xmlrpcresp(0, $xmlrpcerruser, $err);
106 // otherwise, we create the right response
107 // with the state name
108 return new xmlrpcresp(php_xmlrpc_encode($ra));
112 $s = new xmlrpc_server(array(
113 "discuss.addComment" => array(
114 "function" => "addcomment",
115 "signature" => $addcomment_sig,
116 "docstring" => $addcomment_doc
118 "discuss.getComments" => array(
119 "function" => "getcomments",
120 "signature" => $getcomments_sig,
121 "docstring" => $getcomments_doc