From 8d9e1439e96ed4412bdeed6cfacaedc0e91773e5 Mon Sep 17 00:00:00 2001 From: Marcelo Gornstein Date: Wed, 28 Mar 2012 14:03:44 -0300 Subject: [PATCH] added sip header manipulation routines --- src/mg/PAGI/Client/AbstractClient.php | 26 ++++++++++++--- src/mg/PAGI/Client/IClient.php | 48 +++++++++++++++++++++------ test/client/Test_Client.php | 36 ++++++++++++++++++++ 3 files changed, 95 insertions(+), 15 deletions(-) diff --git a/src/mg/PAGI/Client/AbstractClient.php b/src/mg/PAGI/Client/AbstractClient.php index 73f3feb..6a169a8 100644 --- a/src/mg/PAGI/Client/AbstractClient.php +++ b/src/mg/PAGI/Client/AbstractClient.php @@ -815,15 +815,31 @@ public function stopPlayingTones() } /** - * Convenient method to create a node. - * - * @param string $name - * - * @return Node + * (non-PHPdoc) + * @see IClient::createNode() */ public function createNode($name) { $node = new \PAGI\Node\Node(); return $node->setName($name)->setAgiClient($this); } + + /** + * (non-PHPdoc) + * @see IClient::sipHeaderAdd() + */ + public function sipHeaderAdd($name, $value) + { + $this->exec('SipAddHeader', array("$name: $value")); + } + + /** + * (non-PHPdoc) + * @see IClient::sipHeaderRemove() + */ + public function sipHeaderRemove($name) + { + $result = $this->exec('SipRemoveHeader', array($name)); + return $result->getData(); + } } diff --git a/src/mg/PAGI/Client/IClient.php b/src/mg/PAGI/Client/IClient.php index fb7aa1d..9cc6d48 100644 --- a/src/mg/PAGI/Client/IClient.php +++ b/src/mg/PAGI/Client/IClient.php @@ -349,7 +349,7 @@ public function setVariable($name, $value); * @param string[] $options Application arguments. * * @throws ExecuteCommandException - * @return ExecDecorator + * @return ExecResult */ public function exec($application, array $options = array()); @@ -483,7 +483,7 @@ public function faxReceive($tiffFile); /** * Indicates progress of a call, starting early audio. * - * @return ExecDecorator + * @return ExecResult */ public function indicateProgress(); /** @@ -491,7 +491,7 @@ public function indicateProgress(); * * @param integer $timeout Time in seconds to wait for hangup * - * @return ExecDecorator + * @return ExecResult */ public function indicateBusy($timeout); /** @@ -499,7 +499,7 @@ public function indicateBusy($timeout); * * @param integer $timeout Time in seconds to wait for hangup * - * @return ExecDecorator + * @return ExecResult */ public function indicateCongestion($timeout); /** @@ -507,7 +507,7 @@ public function indicateCongestion($timeout); * * @param string $tone Tone to play * - * @return ExecDecorator + * @return ExecResult */ public function playTone($tone); /** @@ -516,33 +516,61 @@ public function playTone($tone); * @param string[] $frequencies Frequencies for the tone: 425/50,0/50 or * !950/330,!1400/330,!1800/330,0 etc. * - * @return ExecDecorator + * @return ExecResult */ public function playCustomTones(array $frequencies); /** * Stop playing current played tones. * - * @return ExecDecorator + * @return ExecResult */ public function stopPlayingTones(); /** * Plays "Dial" tone, defined in indications.conf * - * @return ExecDecorator + * @return ExecResult */ public function playDialTone(); /** * Plays "Busy" tone, defined in indications.conf * - * @return ExecDecorator + * @return ExecResult */ public function playBusyTone(); /** * Plays "Congestion" tone, defined in indications.conf * - * @return ExecDecorator + * @return ExecResult */ public function playCongestionTone(); + + /** + * Convenient method to create a node. + * + * @param string $name + * + * @return Node + */ + public function createNode($name); + + /** + * Adds a SIP header to the first invite message in a dial command. + * + * @param string $name + * @param string $value + * + * @return ExecResult + */ + public function sipHeaderAdd($name, $value); + + /** + * Removes a header previously added with sipHeaderAdd. + * + * @param string $name + * + * @return ExecResult + */ + public function sipHeaderRemove($name); } diff --git a/test/client/Test_Client.php b/test/client/Test_Client.php index 3b95a7a..db42ecf 100644 --- a/test/client/Test_Client.php +++ b/test/client/Test_Client.php @@ -1634,5 +1634,41 @@ public function can_get_node() $this->assertTrue($node->getClient() instanceof \PAGI\Client\Impl\ClientImpl); $this->assertEquals($node->getName(), 'name'); } + + /** + * @test + */ + public function can_add_sip_header() + { + global $standardAGIStart; + setFgetsMock($standardAGIStart, array()); + $client = \PAGI\Client\Impl\ClientImpl::getInstance($this->_properties); + $write = array( + 'EXEC "SipAddHeader" "name: value"' + ); + $read = array( + '200 result=0', + ); + setFgetsMock($read, $write); + $result = $client->sipHeaderAdd('name', 'value'); + } + + /** + * @test + */ + public function can_add_sip_remove() + { + global $standardAGIStart; + setFgetsMock($standardAGIStart, array()); + $client = \PAGI\Client\Impl\ClientImpl::getInstance($this->_properties); + $write = array( + 'EXEC "SipRemoveHeader" "name"' + ); + $read = array( + '200 result=0', + ); + setFgetsMock($read, $write); + $result = $client->sipHeaderRemove('name'); + } } }