Required parameters should be...
destination
*/
+ $list = array();
$dest_username = "";
$dest_domain = "";
$e164_only = false;
if ( array_key_exists( 'e164', $_GET ) )
{
if ( strtolower($_GET['e164']) == "true" ) $e164_only = true;
+ $list = get_e164_alias( $dest_username, $dest_domain );
+ }
+ else if ( $dest_username && $dest_domain )
+ {
+ $list = get_aliases( $dest_username, $dest_domain );
}
- // TODO: Well. Code. This is a stub
-
- print json_encode ( array( 'response' => 'failed', 'cause' => 'notimplemented', 'detail' => 'Requested feature valid, but not implemented' ) );
}
else if ( array_key_exists( 'alias', $_GET) )
{
}
list ( $alias_username, $alias_domain ) = $tmp;
- // TODO: Well. Code. This is a stub
-
- print json_encode ( array( 'response' => 'failed', 'cause' => 'notimplemented', 'detail' => 'Requested feature valid, but not implemented' ) );
+ $list = get_destination( $alias_username, $alias_domain );
}
else
- print json_encode( array( 'response' => 'invalid', 'cause' => 'parameters' ) );
+ $list = get_aliases( null, null );
+
+
+ print json_encode ( array( 'response' => 'ok', 'aliases' => $list ) );
break;
case "/add":
if ( array_key_exists( 'destination', $_GET)
'response' => 'failed',
'cause' => 'exists',
'detail' => 'User already has E164 number alias',
- 'alias' => $t ));
+ 'alias' => $t['alias'] ));
break;
}
}
alias/list?destination=foo@bar.bz
alias/list?destination=foo@bar.bz&e164=true
alias/list?alias=foo@bar.bz
- Currently not implemented
+ With no parameters, this will return all defined aliases (potentially a
+ huge list). With the destination parameter set, only aliases dfor that
+ destination will be listed, and with the e164 option set to true, only
+ an e164 alias will be returned (if one/it exists). The alias parameter
+ gives the same behaviour, butr looks up an alias address instead of the
+ destination. The e164 option is not valid for the alias search
+ (naturally).
+
+ Returns 'ok' on success, with an array of 'destination' and 'alias'
+ pairs.
+
+ Returns 'ok' with an empty array if the search gave no results.
+
+ Returns 'ok' with an empty array if the database search fails.
+
+ Returns 'failed' with 'cause' = 'invalid' on invalid SIP addresses.
alias/add?alias_username=foo&alias_domain=bar.bz&destination=bar@qux.zx
alias/add?alias=foo@bar.bz&destination=bar@qux.zx
TODO list:
---------------------
-Planned, but not implemented nodes/functions:
- user/update?username=foo&domain=bar
- alias/list
- alias/user?destination=foo@bar.bz
authentication-mechanism :)
function get_destination ( $alias_username, $alias_domain )
{
global $config;
+
+ $aliases = array();
+
+ // Terminate early on missing param.
+ if (!( $alias_username && $alias_domain)) return $aliases;
+
+ $query = sprintf("SELECT CONCAT(username, '@', domain ) AS destination, CONCAT( alias_username, '@', alias_domain) AS alias FROM %s"
+ . " WHERE alias_username = '%s' AND alias_domain = '%s'",
+ $config['kamailio_alias_table'],
+ sql_clean($alias_username),
+ sql_clean($alias_domain)
+ );
+
+ $result = sql_dbquery( $config['kamailio_db'], $query);
+ // If result is empty, there was either an SQL error, or simply no results.
+ // At this point, no error checking is performed, instead the empty array is returned.
+ if ( ! $result ) return $aliases;
+
+ while ( $row = mysql_fetch_assoc( $result ) )
+ {
+ array_push( $aliases, array( 'destination' => $row['destination'], 'alias' => $row['alias'] ) );
+ }
+ return $aliases;
}
+
function get_aliases ( $dest_username, $dest_domain )
{
global $config;
$aliases = array();
- $query = sprintf("SELECT CONCAT( alias_username, '@', alias_domain) AS alias FROM %s"
- . " WHERE username = '%s' AND domain = '%s'",
- $config['kamailio_alias_table'], $dest_username, $dest_domain);
+ $query = "";
+ if (( $dest_username == null ) && ( $dest_domain == null) )
+ {
+ $query = sprintf("SELECT CONCAT(username, '@', domain ) AS destination, CONCAT( alias_username, '@', alias_domain) AS alias FROM %s" ,
+ $config['kamailio_alias_table']);
+ }
+ else
+ {
+ $query = sprintf("SELECT '%s' AS destination, CONCAT( alias_username, '@', alias_domain) AS alias FROM %s"
+ . " WHERE username = '%s' AND domain = '%s'",
+ sql_clean($dest_username. '@' . $dest_domain),
+ $config['kamailio_alias_table'],
+ sql_clean($dest_username),
+ sql_clean($dest_domain));
+ }
$result = sql_dbquery( $config['kamailio_db'], $query);
// If result is empty, there was either an SQL error, or simply no results.
// At this point, no error checking is performed, instead the empty array is returned.
while ( $row = mysql_fetch_assoc( $result ) )
{
- array_push( $aliases, $row['alias'] );
+ array_push( $aliases, array( 'destination' => $row['destination'], 'alias' => $row['alias'] ) );
}
return $aliases;
}
$cur_aliases = get_aliases( $dest_username, $dest_domain );
foreach ( $cur_aliases as $testalias )
{
- list( $tau, $foo ) = split_sipaddress( $testalias );
+ list( $tau, $foo ) = split_sipaddress( $testalias['alias'] );
if ( verify_e164 ( $tau ) ) return $testalias;
}
return false;