Convert libcli routines to use cli_tree instead of cli_state. Port
[jelmer/samba4-debian.git] / source / libcli / climessage.c
1 /* 
2    Unix SMB/CIFS implementation.
3    client message handling routines
4    Copyright (C) Andrew Tridgell 1994-1998
5    Copyright (C) James J Myers 2003  <myersjj@samba.org>
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23
24
25 /****************************************************************************
26 start a message sequence
27 ****************************************************************************/
28 BOOL cli_message_start(struct cli_tree *tree, char *host, char *username, 
29                        int *grp)
30 {
31         struct cli_request *req; 
32         
33         req = cli_request_setup(tree, SMBsendstrt, 0, 0);
34         cli_req_append_string(req, username, STR_TERMINATE);
35         cli_req_append_string(req, host, STR_TERMINATE);
36         if (!cli_request_send(req) || 
37             !cli_request_receive(req) ||
38             cli_is_error(tree)) {
39                 cli_request_destroy(req);
40                 return False;
41         }
42
43         *grp = SVAL(req->in.vwv, VWV(0));
44         cli_request_destroy(req);
45
46         return True;
47 }
48
49
50 /****************************************************************************
51 send a message 
52 ****************************************************************************/
53 BOOL cli_message_text(struct cli_tree *tree, char *msg, int len, int grp)
54 {
55         struct cli_request *req; 
56         
57         req = cli_request_setup(tree, SMBsendtxt, 1, 0);
58         SSVAL(req->out.vwv, VWV(0), grp);
59
60         cli_req_append_bytes(req, msg, len);
61
62         if (!cli_request_send(req) || 
63             !cli_request_receive(req) ||
64             cli_is_error(tree)) {
65                 cli_request_destroy(req);
66                 return False;
67         }
68
69         cli_request_destroy(req);
70         return True;
71 }      
72
73 /****************************************************************************
74 end a message 
75 ****************************************************************************/
76 BOOL cli_message_end(struct cli_tree *tree, int grp)
77 {
78         struct cli_request *req; 
79         
80         req = cli_request_setup(tree, SMBsendend, 1, 0);
81         SSVAL(req->out.vwv, VWV(0), grp);
82
83         if (!cli_request_send(req) || 
84             !cli_request_receive(req) ||
85             cli_is_error(tree)) {
86                 cli_request_destroy(req);
87                 return False;
88         }
89
90         cli_request_destroy(req);
91         return True;
92 }      
93