add port property to App

allow origins in flash policy server
dont start a flash policy server if one is already running
better CURIE support
on CALL URI should be un prefixed
WampConnection callResult should allow an object to be encoded and sent
This commit is contained in:
Ben Connito 2014-08-07 11:56:13 -04:00
parent 6c0d0178b7
commit 72b1a44e38
4 changed files with 52 additions and 13 deletions

2
.gitignore vendored
View File

@ -3,3 +3,5 @@ reports
sandbox
vendor
composer.lock
/nbproject/private/
/nbproject/

View File

@ -43,6 +43,12 @@ class App {
*/
protected $httpHost;
/***
* The port the socket is listening
* @var int
*/
protected $port;
/**
* @var int
*/
@ -68,6 +74,7 @@ class App {
}
$this->httpHost = $httpHost;
$this->port = $port;
$socket = new Reactor($loop);
$socket->listen($port, $address);
@ -81,10 +88,20 @@ class App {
$flashSock = new Reactor($loop);
$this->flashServer = new IoServer($policy, $flashSock);
if (80 == $port) {
$flashSock->listen(843, '0.0.0.0');
} else {
$flashSock->listen(8843);
//check if another App is already running a flash policy server on 843
$test = @fsockopen('127.0.0.1', 843, $errno, $errstr, 5);
//if not start a flash policy serever
if(is_resource($test) === false){
$policy = new FlashPolicy;
$policy->addAllowedAccess($httpHost, 80);
$policy->addAllowedAccess($httpHost, $port);
$flashSock = new Reactor($loop);
$this->flashServer = new IoServer($policy, $flashSock);
$flashSock->listen(843, '0.0.0.0');
}else{
fclose($test);
}
}
@ -119,6 +136,13 @@ class App {
$decorated = new OriginCheck($decorated, $allowedOrigins);
}
//allow origins in flash policy server
if(empty($this->flashServer) === false){
foreach($allowedOrigins as $allowedOrgin){
$this->flashServer->app->addAllowedAccess($allowedOrgin, $this->port);
}
}
$this->routes->add('rr-' . ++$this->_routeCounter, new Route($path, array('_controller' => $decorated), array('Origin' => $this->httpHost), array(), $httpHost));
return $decorated;

View File

@ -107,7 +107,8 @@ class ServerProtocol implements MessageComponentInterface, WsServerInterface {
$json = $json[0];
}
$this->_decorating->onCall($from, $callID, $procURI, $json);
//procURI should be un prefixed
$this->_decorating->onCall($from, $callID, $from->getUri($procURI), $json);
break;
case static::MSG_SUBSCRIBE:

View File

@ -26,10 +26,10 @@ class WampConnection extends AbstractConnectionDecorator {
/**
* Successfully respond to a call made by the client
* @param string $id The unique ID given by the client to respond to
* @param array $data An array of data to return to the client
* @param array $data an object or array
* @return WampConnection
*/
public function callResult($id, array $data = array()) {
public function callResult($id, $data = array()) {
return $this->send(json_encode(array(WAMP::MSG_CALL_RESULT, $id, $data)));
}
@ -77,11 +77,23 @@ class WampConnection extends AbstractConnectionDecorator {
/**
* Get the full request URI from the connection object if a prefix has been established for it
* Compliant with WAMP Spec for curie URIs
* @param string $uri
* @return string
*/
public function getUri($uri) {
return (array_key_exists($uri, $this->WAMP->prefixes) ? $this->WAMP->prefixes[$uri] : $uri);
$seperator = ':';
if(preg_match('/http(s*)\:\/\//', $uri) === false){
if(strpos($uri, $seperator) !== false){
list($prefix, $action) = explode(':', $uri);
$expandedPrefix = isset($this->WAMP->prefixes[$prefix]) ? $this->WAMP->prefixes[$prefix] : $prefix;
return $expandedPrefix . '#' . $action;
}
}
return $uri;
}
/**