-
Notifications
You must be signed in to change notification settings - Fork 625
Expand file tree
/
Copy pathextended_server.php
More file actions
98 lines (84 loc) · 3.43 KB
/
Copy pathextended_server.php
File metadata and controls
98 lines (84 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
/**
* TestLink Open Source Project - http://testlink.sourceforge.net/
* This script is distributed under the GNU General Public License 2 or later.
*
* Filename $RCSfile: extended_server.php,v $
*
* Contribution - example of XMLRPC server extended using TestLink XMLRPC server
*
* @version $Revision: 1.1 $
* @modified $Date: 2010/05/14 20:07:40 $ by $Author: franciscom $
* @author rtessier
* @package TestlinkAPI
*/
require_once("lib/api/xmlrpc.class.php");
class SampleXMLRPCServer extends TestlinkXMLRPCServer {
public function __construct() {
openlog("testlink", LOG_ODELAY, LOG_LOCAL1);
$callbacks = array('tl.getTestSuiteIDByName' => 'this:getTestSuiteIDByName',
'tl.uploadStats' => 'this:uploadStats'
);
parent::__construct($callbacks);
}
private function _getTestSuiteByName($args) {
$status_ok=false;
$testSuiteName = $args[self::$testSuiteNameParamName];
$result = $this->tsuiteMgr->get_by_name($testSuiteName);
$num = sizeof((array)$result);
if ($num == 0) {
$msg = $msg_prefix . sprintf("Name %s does not belong to a test suite present on system!", $testSuiteName);
$this->errors[] = new IXR_Error(8004, $msg);
} else {
// Check project id
foreach ($result as $row) {
$projectid = $this->tsuiteMgr->getTestProjectFromTestSuite($row['id']);
if ($projectid == $args[self::$testProjectIDParamName]) {
$result[0] = $row;
$status_ok=true;
break;
}
}
if (!$status_ok) {
$tprojectInfo=$this->tprojectMgr->get_by_id($args[self::$testProjectIDParamName]);
$msg= sprintf(TESTSUITE_DONOTBELONGTO_TESTPROJECT_STR, $result[0]['id'],
$tprojectInfo['name'], $args[self::$testProjectIDParamName]);
$this->errors[] = new IXR_Error(TESTSUITE_DONOTBELONGTO_TESTPROJECT,$msg_prefix . $msg);
}
}
return $status_ok ? $result : $this->errors;
}
public function getTestSuiteIDByName($args) {
$msg_prefix="(" .__FUNCTION__. ") - ";
$status_ok=true;
$this->_setArgs($args);
$checkFunctions = array('authenticate','checkTestSuiteName');
$status_ok = $this->_runChecks($checkFunctions,$msg_prefix) && $this->userHasRight("mgt_view_tc");
if ($status_ok) {
$keys2check = array(self::$testSuiteNameParamName);
foreach ($keys2check as $key) {
if (!$this->_isParamPresent($key)) {
$this->errors[] = new IXR_Error(NO_TESTSUITENAME,
$msg_prefix . NO_TESTSUITENAME_STR);
$status_ok=false;
}
}
}
return $status_ok ? $this->_getTestSuiteByName($this->args) : $this->errors;
}
public function uploadStats($args) {
foreach ($args as $key => $value) {
switch ($key) {
case devKey:
break;
default:
$stat_msg = sprintf("%s: %s = %s\n",
$_SERVER['REMOTE_ADDR'], $key, $value);
syslog(LOG_INFO, $stat_msg);
break;
}
}
}
}
$XMLRPCServer = new SampleXMLRPCServer();
?>