// At this point, no error checking is performed, instead the empty array is returned.
if ( ! $result ) return $aliases;
- while ( $row = mysql_fetch_assoc( $result ) )
+ while ( $row = @mysql_fetch_assoc( $result ) )
{
array_push( $aliases, array( 'destination' => $row['destination'], 'alias' => $row['alias'] ) );
}
// At this point, no error checking is performed, instead the empty array is returned.
if ( ! $result ) return $aliases;
- while ( $row = mysql_fetch_assoc( $result ) )
+ while ( $row = @mysql_fetch_assoc( $result ) )
{
array_push( $aliases, array( 'destination' => $row['destination'], 'alias' => $row['alias'] ) );
}
$result = sql_dbquery($config['kamailio_db'], $query);
if ( !$result ) return true; // This is an error. Better to fail claiming alias exists...
- $row = mysql_fetch_row($result);
+ $row = @mysql_fetch_row($result);
if ( !$row ) return true; // This is an error. Better to fail claiming alias exists...
$num_r = $row[0];
if ( $num_r == 1 )
$config['kamailio_alias_table'],
sql_clean($alias_username), sql_clean($alias_domain));
$result = sql_dbquery($config['kamailio_db'], $query);
- $row = mysql_fetch_row($result);
+ $row = @mysql_fetch_row($result);
if ( is_string( $row[0] ) ) return $row[0];
return true; // Failure mode..
}
$test = "SELECT COUNT(*) FROM " . $config['numbers_table'] . " WHERE number = '" . $number . "'";
$result = sql_dbquery($config['provision_db'], $test);
if ( !$result ) return false;
- $row = mysql_fetch_row($result);
+ $row = @mysql_fetch_row($result);
if ( !$row ) return false;
$num_r = $row[0];
if ( $num_r == 1 ) return true;
if ( $limit && is_numeric( $limit ) )
$query .= " LIMIT " . $limit;
$result = sql_dbquery( $config['provision_db'], $query );
- print mysql_error();
+
if ( !$result ) return null;
- if (mysql_num_rows($result) < 1 ) return null;
+ if ( @mysql_num_rows($result) < 1 ) return null;
$rows = array();
while ( $row = mysql_fetch_assoc( $result ) )
{
$result = sql_dbquery( $config['provision_db'], $query );
- print mysql_error();
+
if ( !$result ) return null;
- if (mysql_num_rows($result) < 1 ) return null;
+ if ( @mysql_num_rows($result) < 1 ) return null;
$rows = array();
while ( $row = mysql_fetch_assoc( $result ) )
{
$result = sql_dbquery( $config['provision_db'], $query );
if ( !$result ) return null;
- if (mysql_num_rows($result) < 1 ) return null;
+ if ( @mysql_num_rows($result) < 1 ) return null;
$rows = array();
while ( $row = mysql_fetch_assoc( $result ) )
array_push( $rows, $row['mac'] );
$result = sql_dbquery( $config['provision_db'], $query );
if ( !$result ) return null;
- if (mysql_num_rows($result) < 1 ) return null;
+ if ( @mysql_num_rows($result) < 1 ) return null;
$rows = array();
while ( $row = mysql_fetch_assoc( $result ) )
{
$result = sql_dbquery( $config['provision_db'], $query );
if ( !$result ) return null;
- if (mysql_num_rows($result) < 1 ) return null;
+ if ( @mysql_num_rows($result) < 1 ) return null;
$rows = array();
while ( $row = mysql_fetch_assoc( $result ) )
{
--- /dev/null
+#!/usr/bin/perl
+
+use Test::More 'no_plan';
+
+use strict;
+use LWP;
+use Data::Dumper;
+use JSON;
+
+my $api_base = "http://10.0.2.5/hermes/api/";
+my $api_key = "6327c08b70f9";
+my $api_user = "test";
+my $api_pass = "Very5ecr3t";
+
+my $test_domain = "example.com"; #TODO: Must fetch this from API
+
+# plan tests => 2;
+my ($g_ua, $response, $data, $temp);
+
+
+$g_ua = LWP::UserAgent->new;
+isa_ok( $g_ua, 'LWP::UserAgent', '$g_ua');
+
+$g_ua->cookie_jar({}); # In-memory jar, look at HTTP::Cookies for persistant
+isa_ok( $g_ua->cookie_jar, 'HTTP::Cookies', '$g_ua->cookies');
+
+TODO: {
+ local $TODO = 'auth/login not implemented yet';
+ $response = $g_ua->get( $api_base . "auth/login?username=" . $api_user .
+ "password=" . $api_pass . "&key=" . $api_key);
+
+ #$data = decode_json( $response->content);
+ is( $data->{'response'}, 'ok', 'auth/login');
+ undef $response; undef $data;
+}
+
+$response = $g_ua->get( $api_base . "domain/list");
+isa_ok( $response, 'HTTP::Response', 'domain/list $response');
+ok ($response->is_success, 'domain/list is_success');
+$data = decode_json( $response->content);
+ok($data, 'domain/list JSON decode');
+is( $data->{'response'}, 'ok', 'domain/list result');
+ok($data->{'list'}, 'domain/list array');
+undef $response; undef $data;
+
+TODO: {
+ local $TODO = 'not implemented yet';
+ $response = $g_ua->get( $api_base . "domain/get_servers");
+ isa_ok( $response, 'HTTP::Response', 'domain/list $response');
+ ok ($response->is_success, 'domain/list is_success');
+ $data = decode_json( $response->content);
+ ok($data, 'domain/get_servers JSON decode');
+ is( $data->{'response'}, 'ok', 'domain/get_servers result');
+ ok($data->{'server'}->{'domain'}, 'domain/get_servers - domain');
+ ok($data->{'server'}->{'registrar'}, 'domain/get_servers - registrar');
+ ok($data->{'server'}->{'r_port'}, 'domain/get_servers - r_port');
+ ok($data->{'server'}->{'proxy'}, 'domain/get_servers - proxy');
+ ok($data->{'server'}->{'p_port'}, 'domain/get_servers - p_port');
+ ok($data->{'server'}->{'prov_url'}, 'domain/get_servers - prov_url');
+ undef $response; undef $data;
+
+}
+
+TODO: {
+ local $TODO = 'not implemented yet';
+ $response = $g_ua->get( $api_base . "domain/set_servers" .
+ "?domain=" . $test_domain . # TODO This should be fetched from domain/list !!
+ "®istrar=registrar." . $test_domain .
+ "&r_port=5060" .
+ "&proxy=proxy." . $test_domain .
+ "&p_port=5060" .
+ "&prov_url=http://phone." . $test_domain );
+
+ isa_ok( $response, 'HTTP::Response', 'domain/list $response');
+ ok ($response->is_success, 'domain/list is_success');
+ $data = decode_json( $response->content);
+ ok($data, 'domain/get_servers JSON decode');
+ is( $data->{'response'}, 'ok', 'domain/get_servers result');
+ ok($data->{'server'}->{'domain'}, 'domain/get_servers - domain');
+ ok($data->{'server'}->{'registrar'}, 'domain/get_servers - registrar');
+ ok($data->{'server'}->{'r_port'}, 'domain/get_servers - r_port');
+ ok($data->{'server'}->{'proxy'}, 'domain/get_servers - proxy');
+ ok($data->{'server'}->{'p_port'}, 'domain/get_servers - p_port');
+ ok($data->{'server'}->{'prov_url'}, 'domain/get_servers - prov_url');
+ undef $response; undef $data;
+}