Skip to content
Snippets Groups Projects
Commit 583d3cca authored by Martin Haase's avatar Martin Haase
Browse files

* Use the tgResourceCounterDaemon if available.

git-svn-id: https://textgridlab.org/svn/textgrid/trunk/middleware/tgauth@3196 7c539038-3410-0410-b1ec-0f2a7bf1c452
parent 9ecec3ac
No related branches found
No related tags found
No related merge requests found
...@@ -1159,7 +1159,7 @@ class TgExtra { ...@@ -1159,7 +1159,7 @@ class TgExtra {
$arrResource = $this->connection['resource']->search( $this->rbac->getConfiguration()->getValue( "resource", "base" ), $filter, "sub" ); $arrResource = $this->connection['resource']->search( $this->rbac->getConfiguration()->getValue( "resource", "base" ), $filter, "sub" );
if( sizeof( $arrResource ) == 1 ) { if( sizeof( $arrResource ) == 1 ) {
$result->result = $this->connection['resource']->delete( $arrResource[0]['dn'] ); $result->result = $this->connection['resource']->delete( $arrResource[0]['dn'] );
...@@ -1221,6 +1221,7 @@ class TgExtra { ...@@ -1221,6 +1221,7 @@ class TgExtra {
$registerTry = 10; // The number of tries of registering the resource $registerTry = 10; // The number of tries of registering the resource
$resourceNamingAttribute = ""; // The naming-attribute of the resource $resourceNamingAttribute = ""; // The naming-attribute of the resource
$arrCounter = false; // The counter entry $arrCounter = false; // The counter entry
$askedDaemon = false;
$result = new booleanResponse(); // The return-result $result = new booleanResponse(); // The return-result
...@@ -1229,35 +1230,60 @@ class TgExtra { ...@@ -1229,35 +1230,60 @@ class TgExtra {
// The TextGrid-resource naming-attribute // The TextGrid-resource naming-attribute
$resourceNamingAttribute = $this->rbac->getConfiguration()->getValue( "resource", "namingattribute" ); $resourceNamingAttribute = $this->rbac->getConfiguration()->getValue( "resource", "namingattribute" );
$sock = socket_create( AF_INET, SOCK_STREAM, SOL_TCP );
// Look for the counter entry for resources. if( socket_connect( $sock, '127.0.0.1', 6645 ) ) {
$arrCounter = $this->connection['counter']->getEntry( "cn=resource," . $this->config->getValue( "counter", "base" ) );
// socket_write( $sock, $arrQuery, strlen( $arrQuery ) );
// socket_write( $sock, "\r\n", strlen( "\r\n" ) );
// If there is a counter entry, use it
if( isset( $arrCounter['dn'] ) ) {
$freeNumber = $arrCounter['sn'][0] + 1; $freeNumber = socket_read( $sock, 1024 );
if( $freeNumber > 0 ) {
$askedDaemon = true;
$registerTry = 1;
}
socket_shutdown( $sock, 2 );
socket_close( $sock );
} }
else { else {
$arrResourceName = $this->connection['resource']->search( $this->config->getValue( "textGridResource", "base" ), // Look for the counter entry for resources.
"(objectClass=textGridResource)", $arrCounter = $this->connection['counter']->getEntry( "cn=resource," . $this->config->getValue( "counter", "base" ) );
"one", $resourceNamingAttribute );
// Every returned resource has to be examined for // If there is a counter entry, use it
// its number to get the next free one. if( isset( $arrCounter['dn'] ) ) {
for( $i = 0; $i < sizeof( $arrResourceName ); $i++ ) {
$resourceName = preg_replace( "/^TGRS/i", "", $arrResourceName[$i][$resourceNamingAttribute][0] ); $freeNumber = $arrCounter['sn'][0] + 1;
$maxNumber = max( $maxNumber, intval( $resourceName ) );
} }
else {
$arrResourceName = $this->connection['resource']->search( $this->config->getValue( "textGridResource", "base" ),
"(objectClass=textGridResource)",
"one", $resourceNamingAttribute );
// Every returned resource has to be examined for
// its number to get the next free one.
for( $i = 0; $i < sizeof( $arrResourceName ); $i++ ) {
$resourceName = preg_replace( "/^TGRS/i", "", $arrResourceName[$i][$resourceNamingAttribute][0] );
$maxNumber = max( $maxNumber, intval( $resourceName ) );
}
$freeNumber = $maxNumber + 1;
$freeNumber = $maxNumber + 1; }
} }
...@@ -1322,22 +1348,26 @@ class TgExtra { ...@@ -1322,22 +1348,26 @@ class TgExtra {
} }
// This entry will add or modify the directory that way if( !$askedDaemon ) {
// that there is a counter entry.
$arrEntry = Array();
$arrEntry['objectclass'][] = "person";
$arrEntry['cn'][] = "resource";
$arrEntry['sn'][] = $freeNumber;
// This entry will add or modify the directory that way
// that there is a counter entry.
$arrEntry = Array();
$arrEntry['objectclass'][] = "person";
$arrEntry['cn'][] = "resource";
$arrEntry['sn'][] = $freeNumber;
if( !isset( $arrCounter['dn'] ) ) {
$this->connection['counter']->add( "cn=resource," . $this->config->getValue( "counter", "base" ), $arrEntry ); if( !isset( $arrCounter['dn'] ) ) {
} $this->connection['counter']->add( "cn=resource," . $this->config->getValue( "counter", "base" ), $arrEntry );
else {
}
else {
$this->connection['counter']->modify( "cn=resource," . $this->config->getValue( "counter", "base" ), $arrEntry ); $this->connection['counter']->modify( "cn=resource," . $this->config->getValue( "counter", "base" ), $arrEntry );
}
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment