1--TEST--
2ldap_get_option() and ldap_set_option() tests related to ldap controls
3--CREDITS--
4Côme Chilliet <mcmic@php.net>
5--SKIPIF--
6<?php
7require_once('skipif.inc');
8require_once('skipifbindfailure.inc');
9?>
10--FILE--
11<?php
12include "connect.inc";
13
14$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
15insert_dummy_data($link, $base);
16
17function build_ctrl_paged_value($int, $cookie)
18{
19	// This is basic and will only work for small values
20	$hex = '';
21	if (!empty($int)) {
22		$str = sprintf("%'.02x", $int);
23		$hex .= '02'.sprintf("%'.02x%s", strlen($str)/2, $str);
24	}
25	$hex .= '04'.sprintf("%'.02x", strlen($cookie)).bin2hex($cookie);
26	return hex2bin('30'.sprintf("%'.02x", strlen($hex)/2).$hex);
27}
28
29$controls_set = array(
30	array(
31		'oid' => LDAP_CONTROL_PAGEDRESULTS,
32		'iscritical' => TRUE,
33		'value' => build_ctrl_paged_value(1, '')
34	)
35);
36var_dump(
37	bin2hex($controls_set[0]['value']),
38	ldap_get_option($link, LDAP_OPT_SERVER_CONTROLS, $controls_get),
39	ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, $controls_set),
40	ldap_get_option($link, LDAP_OPT_SERVER_CONTROLS, $controls_get),
41	count($controls_get),
42	$controls_get[0]['oid'],
43	$controls_get[0]['iscritical'],
44	bin2hex($controls_get[0]['value']),
45	$result = ldap_search($link, $base, "(objectClass=person)", array('cn')),
46	ldap_get_entries($link, $result)['count'],
47	ldap_set_option($link, LDAP_OPT_SERVER_CONTROLS, array()),
48	ldap_get_option($link, LDAP_OPT_SERVER_CONTROLS, $controls_get)
49);
50?>
51===DONE===
52--CLEAN--
53<?php
54include "connect.inc";
55
56$link = ldap_connect_and_bind($host, $port, $user, $passwd, $protocol_version);
57remove_dummy_data($link, $base);
58?>
59--EXPECTF--
60string(14) "30050201010400"
61bool(false)
62bool(true)
63bool(true)
64int(1)
65string(22) "1.2.840.113556.1.4.319"
66bool(true)
67string(14) "30050201010400"
68resource(%d) of type (ldap result)
69int(1)
70bool(true)
71bool(false)
72===DONE===
73