r23792: convert Samba4 to GPLv3
[sfrench/samba-autobuild/.git] / source4 / 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 3 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, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "includes.h"
22 #include "libcli/raw/libcliraw.h"
23
24
25 /****************************************************************************
26 start a message sequence
27 ****************************************************************************/
28 BOOL smbcli_message_start(struct smbcli_tree *tree, const char *host, const char *username, 
29                        int *grp)
30 {
31         struct smbcli_request *req; 
32         
33         req = smbcli_request_setup(tree, SMBsendstrt, 0, 0);
34         smbcli_req_append_string(req, username, STR_TERMINATE);
35         smbcli_req_append_string(req, host, STR_TERMINATE);
36         if (!smbcli_request_send(req) || 
37             !smbcli_request_receive(req) ||
38             smbcli_is_error(tree)) {
39                 smbcli_request_destroy(req);
40                 return False;
41         }
42
43         *grp = SVAL(req->in.vwv, VWV(0));
44         smbcli_request_destroy(req);
45
46         return True;
47 }
48
49
50 /****************************************************************************
51 send a message 
52 ****************************************************************************/
53 BOOL smbcli_message_text(struct smbcli_tree *tree, char *msg, int len, int grp)
54 {
55         struct smbcli_request *req; 
56         
57         req = smbcli_request_setup(tree, SMBsendtxt, 1, 0);
58         SSVAL(req->out.vwv, VWV(0), grp);
59
60         smbcli_req_append_bytes(req, (const uint8_t *)msg, len);
61
62         if (!smbcli_request_send(req) || 
63             !smbcli_request_receive(req) ||
64             smbcli_is_error(tree)) {
65                 smbcli_request_destroy(req);
66                 return False;
67         }
68
69         smbcli_request_destroy(req);
70         return True;
71 }      
72
73 /****************************************************************************
74 end a message 
75 ****************************************************************************/
76 BOOL smbcli_message_end(struct smbcli_tree *tree, int grp)
77 {
78         struct smbcli_request *req; 
79         
80         req = smbcli_request_setup(tree, SMBsendend, 1, 0);
81         SSVAL(req->out.vwv, VWV(0), grp);
82
83         if (!smbcli_request_send(req) || 
84             !smbcli_request_receive(req) ||
85             smbcli_is_error(tree)) {
86                 smbcli_request_destroy(req);
87                 return False;
88         }
89
90         smbcli_request_destroy(req);
91         return True;
92 }      
93