#!/usr/local/bin/perl 
use Net::DSML;
use Net::DSML::Filter;
use Net::DSML::Control;

# 
# Be sure to set up the first line to point to your perl executable location.
#
# Fill in the server, base, attribute and value variables with values that
# match your configuration.
#
# 
# This script shows how to seach for an entry.
# The search filter used is the subString.
# 
my $server = "http://dsml.yourcompany.com:8080/dsml";
my $base = "ou=people,dc=yourcompany,dc=com";
my $attribute = "uid"; 
my $value = "clif";

#
# search request
#   
   #
   # Create the Net::DSML::Filter object
   #
   $webfilter = Net::DSML::Filter->new();

   #
   # Create the Net::DSM object
   #
   $webdsml = Net::DSML->new(  { url => $server } );
   #

   #
   # list of attributes from the entry.
   #
   @name = ();

   push(@name,"cn");
   push(@name,"givenname");
   push(@name,"objectClass");
   push(@name,"sn");
   push(@name,"title");
   push(@name,"gecos");
   push(@name,"uid");
   push(@name,"homeDirectory");
   push(@name,"uidNumber");

   $webdsml->setBase( { base => $base } );

   if ( !($webfilter->subString( { 
             type =>"initial", 
             attribute => $attribute, 
             value => $value } )))
   {
      print "Filter error; ", $webfilter->error(), "\n";
      exit;
   }

   #
   # Examples of other filters
   #
   # $webfilter->equalityMatch( { attribute => $attribute, value => $value } );
   # $webfilter->present( { attribute => $attribute } );
   # $webfilter->greaterOrEqual( { attribute => $attribute, value => $value } );
   # $webfilter->lessOrEqual( { attribute => $attribute, value => $value } );
   #
   # Complex filters
   #
   # $webfilter->and();
   # $webfilter->equalityMatch( { attribute => $attribute, value => $value" } );
   #$webfilter->not();
   # $webfilter->equalityMatch( { attribute => $attribute, value => $value } );
   #$webfilter->endnot();
   # $webfilter->endand();


   if ( !( $webdsml->search( { 
           sfilter => $webfilter->getFilter(), 
           attributes => \@name } ) ) )
   {
      print "Search error.", "\n";
      print $webdsml->error, "\n";
      exit;
    }

   if (!($webdsml->send()))
   {
      print "Search send request error.\n";
      print $webdsml->error(),"\n";
      exit;
   }

# get the return xml content, should be the status of the dsml request.
$postData = $webdsml->content();
print $postData, "\n";

