WHATSNEW: Update changes since rc1.
[Samba/gbeck.git] / source3 / libsmb / clistr.c
blob6e45799c3624eb2aaff2ec1c739476759ad2624e
1 /*
2 Unix SMB/CIFS implementation.
3 client string routines
4 Copyright (C) Andrew Tridgell 2001
5 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2003
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.
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.
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/>.
21 #include "includes.h"
22 #include "libsmb/libsmb.h"
24 size_t clistr_push_fn(const char *function,
25 unsigned int line,
26 struct cli_state *cli,
27 void *dest,
28 const char *src,
29 int dest_len,
30 int flags)
32 size_t buf_used = PTR_DIFF(dest, cli->outbuf);
33 if (dest_len == -1) {
34 if (((ptrdiff_t)dest < (ptrdiff_t)cli->outbuf) || (buf_used > cli->bufsize)) {
35 DEBUG(0, ("Pushing string of 'unlimited' length into non-SMB buffer!\n"));
36 return push_string_base(function, line,
37 cli->outbuf,
38 (uint16_t)(cli_ucs2(cli) ? FLAGS2_UNICODE_STRINGS : 0),
39 dest, src, -1, flags);
41 return push_string_base(function, line,
42 cli->outbuf,
43 (uint16_t)(cli_ucs2(cli) ? FLAGS2_UNICODE_STRINGS : 0),
44 dest, src, cli->bufsize - buf_used,
45 flags);
48 /* 'normal' push into size-specified buffer */
49 return push_string_base(function, line,
50 cli->outbuf,
51 (uint16_t)(cli_ucs2(cli) ? FLAGS2_UNICODE_STRINGS : 0),
52 dest, src, dest_len, flags);
55 size_t clistr_pull_fn(const char *function,
56 unsigned int line,
57 const char *inbuf,
58 char *dest,
59 const void *src,
60 int dest_len,
61 int src_len,
62 int flags)
64 return pull_string_fn(function, line, inbuf,
65 SVAL(inbuf, smb_flg2), dest, src, dest_len,
66 src_len, flags);
69 size_t clistr_pull_talloc_fn(const char *function,
70 unsigned int line,
71 TALLOC_CTX *ctx,
72 const char *base,
73 uint16_t flags2,
74 char **pp_dest,
75 const void *src,
76 int src_len,
77 int flags)
79 return pull_string_talloc_fn(function,
80 line,
81 ctx,
82 base,
83 flags2,
84 pp_dest,
85 src,
86 src_len,
87 flags);
90 size_t clistr_align_out(struct cli_state *cli, const void *p, int flags)
92 return align_string(cli->outbuf, (const char *)p, flags);