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