4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #ifndef _SMBSRV_MSGBUF_H
27 #define _SMBSRV_MSGBUF_H
30 * Definition and interface for smb_msgbuf buffer management. The
31 * smb_msgbuf interface is typically used to encode or decode SMB
32 * data using sprintf/scanf style operations. It can also be used
33 * for general purpose encoding and decoding.
36 #include <sys/types.h>
37 #include <smbsrv/string.h>
44 * When unicode strings are decoded, the resultant UTF-8 strings are
45 * stored in dynamically allocated areas, which are held on a linked
46 * list anchored at smb_msgbuf.mlist. The list is deallocated by
49 typedef struct smb_msgbuf_mlist
{
50 struct smb_msgbuf_mlist
*next
;
57 * SMB_MSGBUF_UNICODE When there is a choice between unicode or ascii
58 * formatting, select unicode processing.
59 * SMB_MSGBUF_NOTERM Do not null terminate strings.
61 #define SMB_MSGBUF_UNICODE 0x00000001
62 #define SMB_MSGBUF_NOTERM 0x00000002
65 * base: points to the beginning of the buffer
66 * end: points to the limit of the buffer.
67 * scan: points to the current offset.
68 * max: holds the number of bytes in the buffer.
70 * mlist: anchors the dynamically allocated memory list.
71 * flags: see SMB_SMGBUF flags.
73 typedef struct smb_msgbuf
{
79 smb_msgbuf_mlist_t mlist
;
84 * List of smb_msgbuf_decode and smb_msgbuf_encode return values.
86 #define SMB_MSGBUF_SUCCESS 0
87 #define SMB_MSGBUF_UNDERFLOW -1
88 #define SMB_MSGBUF_OVERFLOW SMB_MSGBUF_UNDERFLOW
89 #define SMB_MSGBUF_INVALID_FORMAT -2
90 #define SMB_MSGBUF_INVALID_HEADER -3
91 #define SMB_MSGBUF_DATA_ERROR -4
94 * smb_msgbuf_init must be called to associate the smb_msgbuf_t with
95 * a buffer before any encode or decode operations may be performed.
97 * smb_msgbuf_term must be called to free any dynamically allocated memory
98 * that was acquired during encode or decode operations. At this time
99 * the only operation that allocates memory is a unicode string decode.
101 * If there are no errors, smb_msgbuf_decode and smb_msgbuf_encode return
102 * the number of bytes decoded or encoded. If there is a problem they
103 * return -ve error codes.
105 extern void smb_msgbuf_init(smb_msgbuf_t
*, uint8_t *, size_t, uint32_t);
106 extern void smb_msgbuf_term(smb_msgbuf_t
*);
107 extern int smb_msgbuf_decode(smb_msgbuf_t
*, char *, ...);
108 extern int smb_msgbuf_encode(smb_msgbuf_t
*, char *, ...);
109 extern size_t smb_msgbuf_used(smb_msgbuf_t
*);
110 extern size_t smb_msgbuf_size(smb_msgbuf_t
*);
111 extern uint8_t *smb_msgbuf_base(smb_msgbuf_t
*);
112 extern void smb_msgbuf_word_align(smb_msgbuf_t
*);
113 extern void smb_msgbuf_dword_align(smb_msgbuf_t
*);
114 extern int smb_msgbuf_has_space(smb_msgbuf_t
*, size_t);
115 extern void smb_msgbuf_fset(smb_msgbuf_t
*, uint32_t);
116 extern void smb_msgbuf_fclear(smb_msgbuf_t
*, uint32_t);
122 #endif /* _SMBSRV_MSGBUF_H */