fixed the handling of level II oplocks in samba4, especially when
[samba.git] / source4 / libcli / raw / clioplock.c
1 /* 
2    Unix SMB/CIFS implementation.
3    SMB client oplock functions
4    Copyright (C) Andrew Tridgell 2001
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "includes.h"
22
23 /****************************************************************************
24 send an ack for an oplock break request
25 ****************************************************************************/
26 BOOL cli_oplock_ack(struct cli_tree *tree, uint16 fnum, uint16 ack_level)
27 {
28         BOOL ret;
29         struct cli_request *req;
30
31         req = cli_request_setup(tree, SMBlockingX, 8, 0);
32
33         SSVAL(req->out.vwv,VWV(0),0xFF);
34         SSVAL(req->out.vwv,VWV(1),0);
35         SSVAL(req->out.vwv,VWV(2),fnum);
36         SCVAL(req->out.vwv,VWV(3),LOCKING_ANDX_OPLOCK_RELEASE);
37         SCVAL(req->out.vwv,VWV(3)+1,ack_level);
38         SIVAL(req->out.vwv,VWV(4),0);
39         SSVAL(req->out.vwv,VWV(6),0);
40         SSVAL(req->out.vwv,VWV(7),0);
41
42         ret = cli_request_send(req);    
43         cli_request_destroy(req);
44
45         return ret;
46 }
47
48
49 /****************************************************************************
50 set the oplock handler for a connection
51 ****************************************************************************/
52 void cli_oplock_handler(struct cli_transport *transport, 
53                         BOOL (*handler)(struct cli_transport *, uint16, uint16, uint8, void *),
54                         void *private)
55 {
56         transport->oplock.handler = handler;
57         transport->oplock.private = private;
58 }