Skip to content

Instantly share code, notes, and snippets.

@mattvv
Created October 11, 2012 00:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattvv/3869317 to your computer and use it in GitHub Desktop.
Save mattvv/3869317 to your computer and use it in GitHub Desktop.
Check if a Subscriber is on a call for SipWise
=item B<check_live> { $username, $domain, \%data }
=back
=over
Checks if a certain subscriber is on a call. Returns true if they are and false if they are not.
=back
=cut
sub check_live {
my $self = shift;
my $data = shift;
$self->_require_userdom($data);
$self->_check_subscriber_data($$data{data});
my $dispatcher = Sipwise::Provisioning::XMLDispatcher->new;
my @results = $dispatcher->dispatch("proxy-ng", 1, 1, <<EOF);
<?xml version="1.0" ?>
<methodCall>
<methodName>dlg.list</methodName>
<params/>
</methodCall>
EOF
my $result = @results[0]->[2];
my $substring = "$$data{username}\@$$data{domain}";
if (index($result, $substring) != -1) {
return "true";
}
return "false";
}
... later on
elsif($function eq 'check_bool'
or $function eq 'check_username'
or $function eq 'check_ip'
or $function eq 'check_ip4'
or $function eq 'check_ip6'
or $function eq 'check_ip6_brackets'
or $function eq 'check_ipnet'
or $function eq 'check_domain'
or $function eq 'check_sip_uri'
or $function eq 'check_sip_uri_pattern'
or $function eq 'check_sip_uri_prefix'
or $function eq 'check_sip_username'
or $function eq 'check_email'
or $function eq 'check_cc'
or $function eq 'check_ac'
or $function eq 'check_sn'
or $function eq 'check_E164_number'
or $function eq 'check_E164_shell_pattern'
or $function eq 'check_sip_username_shell_pattern'
or $function eq 'check_vsc_format'
or $function eq 'check_date'
or $function eq 'check_time'
or $function eq 'check_timestamp'
or $function eq 'check_sip_transport_protocol'
or $function eq 'get_localized_string'
or $function eq 'check_selected_enum'
or $function eq 'check_regex_syntax'
or $function eq 'check_localpart'
or $function eq 'check_live'
)
sub check_live { typed $Voip->handle_request('check_live', pop) }
@dtiefnig
Copy link

Actually the function signature should be:

=item B<check_live> { $username, $domain }

There's no need for any subscriber data, we just need the username and domain. So the check_subscriber_data() call should be removed too. About the return values, the function should return boolean values, I'm not sure if the strings are parsed correctly. Would need to check how the SOAP::Lite serializer handles this.

Then let me add some missing bits, just so they're documented here if someone comes across this:

In Provisioning/Voip.pm (sub authorize_user):

[...]
 or $function eq 'dial_out'
 or $function eq 'check_live'
[...]

In SOAP/Voip.inc.pm:

sub check_live { typed $Voip->handle_request('check_live', pop->method()) }

And some parts for the WSDL (each block needs to be put in the correct location):

<message name="boolean_Response">
  <part name="data" type="xsd:boolean" />
</message>

<operation name="check_live">
  <documentation>
    Checks if a certain subscriber is on a call. Returns true if it is and false if not.
  </documentation>
  <input message="tns:by_userdom_Request" />
  <output message="tns:boolean_Response" />
</operation>

<operation name="get_voip_account_by_subscriber"> <soap:operation soapAction="urn:/SOAP/Provisioning#get_voip_account_by_subscriber" style="rpc" />
  <input><soap:body use="encoded" namespace="urn:/SOAP/Provisioning" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /></input>
  <output><soap:body use="encoded" namespace="urn:/SOAP/Provisioning" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /></output>
</operation>

@mattvv
Copy link
Author

mattvv commented Jan 2, 2013

Thanks Daniel! Any Idea on when this can be shipped with Sipwise also and not just a patch?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment