+
+ case "/location":
+ if ( array_key_exists('user', $_POST) ||
+ ( array_key_exists('username', $_POST) && array_key_exists('domain', $_POST )))
+ {
+ $username = "";
+ $domain = "";
+ if ( array_key_exists('username', $_POST) )
+ {
+ $username = $_POST['username'];
+ $domain = $_POST['domain'];
+ }
+ else
+ {
+ $user = split_sipaddress($_POST['user']);
+ if ( !$user )
+ {
+ print json_encode ( array( 'response' => 'failed', 'cause' => 'invalid', 'detail' => 'Invalid SIP address') );
+ break;
+ }
+ list ( $username, $domain ) = $user;
+ }
+ $location = get_locations( $username, $domain );
+ if ( $location == null )
+ {
+ print json_encode( array( 'response' => 'failed', 'cause' => 'offline' ));
+ break;
+ }
+ print json_encode( array( 'response' => 'ok', 'locations' => $location ));
+ }
+ else
+ print json_encode ( array( 'response' => 'invalid') );
+ break;
+