Conversation
+1 |
+1 Great work Ryan. |
@ryanpetris I'm hoping to dive deeply in to this soon, but off the cuff I see that there's a lot of rudimentary https://code.hq.twilio.com/shawn/OpenVBX/blob/develop/OpenVBX/helpers/format_helper.php Can you cherry-pick this work from your master in to your develop branch instead and resubmit the pull request against develop? You can read a bit more about the repo layout here: https://github.com/twilio/OpenVBX/wiki as well as get a link in to the git-flow methodology. It makes pull requests from forks a bit tedious but the workflow itself is solid. |
@@ -101,9 +101,12 @@ public function make_call($from, $to, $callerid, $rest_access) | |||
{ | |||
try | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This entire try {} catch() {}
block is old, rickety, and needs to be reworked. PhoneNumber::validatePhoneNumber()
will throw a validation exception that we catch and re-raise as a VBX_CallException()
. This should be smarter about the different formats that are passed in and throw context appropriate exceptions.
I can work on this after merging the request, but if you want to take a whack at it my preliminary thought is that it should be something like:
try {
foreach (array('from' => $from, 'to' => $to) as $type => $value)
{
// to
if (PhoneNumber::analyzePhoneNumber($value) != PhoneNumber::TYPE_UNKNOWN)
{
PhoneNumber::validatePhoneNumber($value);
}
elseif (strpos($value, 'sip') !== false && !validate_sip_address($value))
{
throw new Exception(sprintf('%s phone number %s is not a valid sip address', $type, $value));
}
elseif (strpos($value, '@') !== false && !filter_var($value, FILTER_VALIDATE_EMAIL))
{
throw new Exception(sprintf('%s phone number %s is not a valid email address', $type, $value));
}
else
{
throw new Exception(sprintf('Could not validate %s phone number: %s' $type, $value));
}
}
} catch (Exception $e) {
throw new VBX_CallException($e->getMessage);
}
Its a lot more strict and more informative on malformed data.
Looking back at my earlier comment about the number of times we use |
I needed/wanted this for my own OpenVBX installation so I added some very rudimentary support for SIP urls in both the devices page and in the dial applet. If anything you could use this as a base for adding proper SIP support.