| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | # Copyright (c) 1998 Graham Barr . All rights reserved. | 
| 2 |  |  |  |  |  |  | # This program is free software; you can redistribute it and/or | 
| 3 |  |  |  |  |  |  | # modify it under the same terms as Perl itself. | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | package URI::_ldap; | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 1 |  |  | 1 |  | 454 | use strict; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 28 |  | 
| 8 | 1 |  |  | 1 |  | 4 | use warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 37 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | our $VERSION = '5.21'; | 
| 11 |  |  |  |  |  |  |  | 
| 12 | 1 |  |  | 1 |  | 5 | use URI::Escape qw(uri_unescape); | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 1261 |  | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | sub _ldap_elem { | 
| 15 | 39 |  |  | 39 |  | 49 | my $self  = shift; | 
| 16 | 39 |  |  |  |  | 51 | my $elem  = shift; | 
| 17 | 39 |  |  |  |  | 79 | my $query = $self->query; | 
| 18 | 39 | 100 |  |  |  | 153 | my @bits  = (split(/\?/,defined($query) ? $query : ""),("")x4); | 
| 19 | 39 |  |  |  |  | 64 | my $old   = $bits[$elem]; | 
| 20 |  |  |  |  |  |  |  | 
| 21 | 39 | 100 |  |  |  | 67 | if (@_) { | 
| 22 | 17 |  |  |  |  | 21 | my $new = shift; | 
| 23 | 17 |  |  |  |  | 28 | $new =~ s/\?/%3F/g; | 
| 24 | 17 |  |  |  |  | 26 | $bits[$elem] = $new; | 
| 25 | 17 |  |  |  |  | 44 | $query = join("?",@bits); | 
| 26 | 17 |  |  |  |  | 60 | $query =~ s/\?+$//; | 
| 27 | 17 | 100 |  |  |  | 36 | $query = undef unless length($query); | 
| 28 | 17 |  |  |  |  | 35 | $self->query($query); | 
| 29 |  |  |  |  |  |  | } | 
| 30 |  |  |  |  |  |  |  | 
| 31 | 39 |  |  |  |  | 80 | $old; | 
| 32 |  |  |  |  |  |  | } | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | sub dn { | 
| 35 | 8 |  |  | 8 | 0 | 38 | my $old = shift->path(@_); | 
| 36 | 8 |  |  |  |  | 23 | $old =~ s:^/::; | 
| 37 | 8 |  |  |  |  | 21 | uri_unescape($old); | 
| 38 |  |  |  |  |  |  | } | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | sub attributes { | 
| 41 | 11 |  |  | 11 | 0 | 20 | my $self = shift; | 
| 42 | 11 | 100 |  |  |  | 25 | my $old = _ldap_elem($self,0, @_ ? join(",", map { my $tmp = $_; $tmp =~ s/,/%2C/g; $tmp } @_) : ()); | 
|  | 11 |  |  |  |  | 14 |  | 
|  | 11 |  |  |  |  | 16 |  | 
|  | 11 |  |  |  |  | 27 |  | 
| 43 | 11 | 100 |  |  |  | 25 | return $old unless wantarray; | 
| 44 | 5 |  |  |  |  | 12 | map { uri_unescape($_) } split(/,/,$old); | 
|  | 12 |  |  |  |  | 20 |  | 
| 45 |  |  |  |  |  |  | } | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | sub _scope { | 
| 48 | 10 |  |  | 10 |  | 15 | my $self = shift; | 
| 49 | 10 |  |  |  |  | 15 | my $old = _ldap_elem($self,1, @_); | 
| 50 | 10 | 50 | 33 |  |  | 33 | return undef unless defined wantarray && defined $old; | 
| 51 | 10 |  |  |  |  | 23 | uri_unescape($old); | 
| 52 |  |  |  |  |  |  | } | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | sub scope { | 
| 55 | 9 |  |  | 9 | 0 | 20 | my $old = &_scope; | 
| 56 | 9 | 100 |  |  |  | 18 | $old = "base" unless length $old; | 
| 57 | 9 |  |  |  |  | 16 | $old; | 
| 58 |  |  |  |  |  |  | } | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | sub _filter { | 
| 61 | 11 |  |  | 11 |  | 15 | my $self = shift; | 
| 62 | 11 |  |  |  |  | 19 | my $old = _ldap_elem($self,2, @_); | 
| 63 | 11 | 50 | 33 |  |  | 39 | return undef unless defined wantarray && defined $old; | 
| 64 | 11 |  |  |  |  | 22 | uri_unescape($old); # || "(objectClass=*)"; | 
| 65 |  |  |  |  |  |  | } | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | sub filter { | 
| 68 | 10 |  |  | 10 | 0 | 21 | my $old = &_filter; | 
| 69 | 10 | 100 |  |  |  | 21 | $old = "(objectClass=*)" unless length $old; | 
| 70 | 10 |  |  |  |  | 27 | $old; | 
| 71 |  |  |  |  |  |  | } | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | sub extensions { | 
| 74 | 7 |  |  | 7 | 0 | 9 | my $self = shift; | 
| 75 | 7 |  |  |  |  | 11 | my @ext; | 
| 76 | 7 |  |  |  |  | 16 | while (@_) { | 
| 77 | 5 |  |  |  |  | 7 | my $key = shift; | 
| 78 | 5 |  |  |  |  | 7 | my $value = shift; | 
| 79 | 5 | 50 |  |  |  | 8 | push(@ext, join("=", map { $_="" unless defined; s/,/%2C/g; $_ } $key, $value)); | 
|  | 10 |  |  |  |  | 17 |  | 
|  | 10 |  |  |  |  | 14 |  | 
|  | 10 |  |  |  |  | 28 |  | 
| 80 |  |  |  |  |  |  | } | 
| 81 | 7 | 100 |  |  |  | 19 | @ext = join(",", @ext) if @ext; | 
| 82 | 7 |  |  |  |  | 11 | my $old = _ldap_elem($self,3, @ext); | 
| 83 | 7 | 100 |  |  |  | 16 | return $old unless wantarray; | 
| 84 | 4 |  |  |  |  | 9 | map { uri_unescape($_) } map { /^([^=]+)=(.*)$/ } split(/,/,$old); | 
|  | 12 |  |  |  |  | 23 |  | 
|  | 6 |  |  |  |  | 27 |  | 
| 85 |  |  |  |  |  |  | } | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | sub canonical | 
| 88 |  |  |  |  |  |  | { | 
| 89 | 2 |  |  | 2 | 0 | 13 | my $self = shift; | 
| 90 | 2 |  |  |  |  | 6 | my $other = $self->_nonldap_canonical; | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | # The stuff below is not as efficient as one might hope... | 
| 93 |  |  |  |  |  |  |  | 
| 94 | 2 | 50 |  |  |  | 6 | $other = $other->clone if $other == $self; | 
| 95 |  |  |  |  |  |  |  | 
| 96 | 2 |  |  |  |  | 18 | $other->dn(_normalize_dn($other->dn)); | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | # Should really know about mixed case "postalAddress", etc... | 
| 99 | 2 |  |  |  |  | 5 | $other->attributes(map lc, $other->attributes); | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | # Lowercase scope, remove default | 
| 102 | 2 |  |  |  |  | 5 | my $old_scope = $other->scope; | 
| 103 | 2 |  |  |  |  | 42 | my $new_scope = lc($old_scope); | 
| 104 | 2 | 50 |  |  |  | 42 | $new_scope = "" if $new_scope eq "base"; | 
| 105 | 2 | 50 |  |  |  | 9 | $other->scope($new_scope) if $new_scope ne $old_scope; | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | # Remove filter if default | 
| 108 | 2 |  |  |  |  | 5 | my $old_filter = $other->filter; | 
| 109 | 2 | 50 | 33 |  |  | 12 | $other->filter("") if lc($old_filter) eq "(objectclass=*)" || | 
| 110 |  |  |  |  |  |  | lc($old_filter) eq "objectclass=*"; | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | # Lowercase extensions types and deal with known extension values | 
| 113 | 2 |  |  |  |  | 5 | my @ext = $other->extensions; | 
| 114 | 2 |  |  |  |  | 7 | for (my $i = 0; $i < @ext; $i += 2) { | 
| 115 | 4 |  |  |  |  | 7 | my $etype = $ext[$i] = lc($ext[$i]); | 
| 116 | 4 | 100 |  |  |  | 15 | if ($etype =~ /^!?bindname$/) { | 
| 117 | 2 |  |  |  |  | 5 | $ext[$i+1] = _normalize_dn($ext[$i+1]); | 
| 118 |  |  |  |  |  |  | } | 
| 119 |  |  |  |  |  |  | } | 
| 120 | 2 | 50 |  |  |  | 8 | $other->extensions(@ext) if @ext; | 
| 121 |  |  |  |  |  |  |  | 
| 122 | 2 |  |  |  |  | 10 | $other; | 
| 123 |  |  |  |  |  |  | } | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | sub _normalize_dn  # RFC 2253 | 
| 126 |  |  |  |  |  |  | { | 
| 127 | 4 |  |  | 4 |  | 5 | my $dn = shift; | 
| 128 |  |  |  |  |  |  |  | 
| 129 | 4 |  |  |  |  | 22 | return $dn; | 
| 130 |  |  |  |  |  |  | # The code below will fail if the "+" or "," is embedding in a quoted | 
| 131 |  |  |  |  |  |  | # string or simply escaped... | 
| 132 |  |  |  |  |  |  |  | 
| 133 | 0 |  |  |  |  |  | my @dn = split(/([+,])/, $dn); | 
| 134 | 0 |  |  |  |  |  | for (@dn) { | 
| 135 | 0 |  |  |  |  |  | s/^([a-zA-Z]+=)/lc($1)/e; | 
|  | 0 |  |  |  |  |  |  | 
| 136 |  |  |  |  |  |  | } | 
| 137 | 0 |  |  |  |  |  | join("", @dn); | 
| 138 |  |  |  |  |  |  | } | 
| 139 |  |  |  |  |  |  |  | 
| 140 |  |  |  |  |  |  | 1; |