NOLookup

 view release on metacpan or  search on metacpan

lib/NOLookup/RDAP/RDAPLookup.pm  view on Meta::CPAN



 * insert_page_info:
    - Text formatting option, insert page info in the text if set.

 Paging parameters set by lib, read them only:

 * total_no_pages:
   Total number of pages that can be fetched with a search combo.
   Calculated as total_size / page_size and set by lib as soon as
   we know the value.

 * page_number:
   The page number signalled by the rdap service.

 * first_page|cur_page|prev_page|next_page:
    - Page hrefs set by lib when a search is performed.

Various:

 * force_ipv:
   - force use of ip protocl version, 0/undef is default, else set to
     4 or 6

=cut

sub new {
    my ($self, $args)=@_;
    
    # defaults
    $args->{service_url} = $SERVICE_URL unless ($args->{service_url});
    
    if ($args->{norid_referral_ip} && $args->{norid_referral_ip} =~ m/^\d+$/) {
	# Set to true (a pure number) - then select a local ip-address
	delete($args->{norid_referral_ip});
	my $ip = get_my_ip_address();
	$args->{norid_referral_ip} = $ip if ($ip);
    }

    # This debug dumps everything using $Net::RDAP::UA::DEBUG
    if ($args->{'debug'} && $args->{debug} == 3) {
	$Net::RDAP::UA::DEBUG = $args->{'debug'};
    }

    my $ro = $self->SUPER::new($args);

    # Activate requested protocol, if set
    # https://metacpan.org/pod/IO::Socket::IP
    if ($args->{force_ipv}) {
	my $ua = $ro->ua;

	if ($args->{force_ipv} == 4) {
	    # Use ipv4 only sockets and addresses
	    print STDERR "RDAPLookup: Connecting forcibly over ipv4\n" if ($args->{debug});
	    $ua->ssl_opts(Domain => AF_INET);
	} elsif ($args->{force_ipv} == 6) {
	    print STDERR "RDAPLookup: Connecting forcibly over ipv6\n" if ($args->{debug});
	    $ua->ssl_opts(Domain => AF_INET6);
	}
	# Also, on force_ipv, disable ssl verify
	use IO::Socket::SSL;
	$ua->ssl_opts( verify_hostname => 0, SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE);
	print STDERR "RDAPLookup: Connecting forcibly, also turn of SSL verify mode\n" if ($args->{debug});
    }

    return $ro;
    
}

=head2 lookup

Do an RDAP lookup.

  - $query      : Specifies the query string.
  - $check      : Specifies if http 'head' shall be done, default is 'get'.
  - $nameservers: Must be set to 1 for nameserver_name search
                  and 2 for a domains by nameserver name search
  - $entity     : Must be set to true for entity lookup, in which case the query should 
                  identify an entity, like:
                   - a domain name or a handle
                  For a search, this is more complex:
                  - For identities (orgno, N.XXX.YYY or registrant handles),
                    a search domains by identity/registrant is done as default.
                    To force the search to search for entities by
                    identity/registrant instead, this option must be
                    set.

=cut

sub lookup {
    my ($self, $query, $check, $nameservers, $entity ) = @_;

    #print STDERR "RDAPLookup: lookup on query: $query, check: ", $check || 0, ", nameservers: ", $nameservers || 0, ", entity: ", $entity || 0, "\n";

    unless ($self->validate_and_analyze($query, $check, $nameservers, $entity)) {
	# errno has already been set
        return $self;
    }
    # _method (head or get) and args are set in $self
    $self->_lookup_rdap($query, $self->_method, $self->_uri);
    
}

=head2 _lookup_rdap

Do an RDAP HEAD or GET lookup.

  - $http_type: 'head' or 'get'
  - $uri      : full arguments to base URI, identifying the actual lookup
                method and args
  - other args as passed in $self.

=cut

sub _lookup_rdap {
    my ($self, $query, $http_type, $uri ) = @_;

    my $ua = $self->ua;

    my $debug = $self->{debug} || 0;

    # Debug >= 4: Use LWP::ConsoleLogger::Easy debug



( run in 0.598 second using v1.01-cache-2.11-cpan-6aa56a78535 )