xref: /onnv-gate/usr/src/uts/common/smbsrv/msgbuf.h (revision 10966:37e5dcdf36d3)
15331Samw /*
25331Samw  * CDDL HEADER START
35331Samw  *
45331Samw  * The contents of this file are subject to the terms of the
55331Samw  * Common Development and Distribution License (the "License").
65331Samw  * You may not use this file except in compliance with the License.
75331Samw  *
85331Samw  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95331Samw  * or http://www.opensolaris.org/os/licensing.
105331Samw  * See the License for the specific language governing permissions
115331Samw  * and limitations under the License.
125331Samw  *
135331Samw  * When distributing Covered Code, include this CDDL HEADER in each
145331Samw  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155331Samw  * If applicable, add the following below this CDDL HEADER, with the
165331Samw  * fields enclosed by brackets "[]" replaced with your own identifying
175331Samw  * information: Portions Copyright [yyyy] [name of copyright owner]
185331Samw  *
195331Samw  * CDDL HEADER END
205331Samw  */
215331Samw /*
22*10966SJordan.Brown@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
235331Samw  * Use is subject to license terms.
245331Samw  */
255331Samw 
265331Samw #ifndef _SMBSRV_MSGBUF_H
275331Samw #define	_SMBSRV_MSGBUF_H
285331Samw 
295331Samw /*
305331Samw  * Definition and interface for smb_msgbuf buffer management.  The
315331Samw  * smb_msgbuf interface is typically used to encode or decode SMB
325331Samw  * data using sprintf/scanf style operations.  It can also be used
335331Samw  * for general purpose encoding and decoding.
345331Samw  */
355331Samw 
365331Samw #include <sys/types.h>
37*10966SJordan.Brown@Sun.COM #include <smbsrv/string.h>
385331Samw 
395331Samw #ifdef __cplusplus
405331Samw extern "C" {
415331Samw #endif
425331Samw 
435331Samw /*
445331Samw  * When unicode strings are decoded, the resultant UTF-8 strings are
455331Samw  * stored in dynamically allocated areas, which are held on a linked
465331Samw  * list anchored at smb_msgbuf.mlist.  The list is deallocated by
475331Samw  * smb_msgbuf_term.
485331Samw  */
495331Samw typedef struct smb_msgbuf_mlist {
505331Samw     struct smb_msgbuf_mlist *next;
515331Samw     size_t size;
525331Samw } smb_msgbuf_mlist_t;
535331Samw 
545331Samw /*
555331Samw  * smb_smgbuf flags
565331Samw  *
575331Samw  * SMB_MSGBUF_UNICODE	When there is a choice between unicode or ascii
585331Samw  *			formatting, select unicode processing.
595331Samw  * SMB_MSGBUF_NOTERM	Do not null terminate strings.
605331Samw  */
615331Samw #define	SMB_MSGBUF_UNICODE		0x00000001
625331Samw #define	SMB_MSGBUF_NOTERM		0x00000002
635331Samw 
645331Samw /*
655331Samw  * base:   points to the beginning of the buffer
665331Samw  * end:    points to the limit of the buffer.
675331Samw  * scan:   points to the current offset.
685331Samw  * max:    holds the number of bytes in the buffer.
695331Samw  * count:  unused.
705331Samw  * mlist:  anchors the dynamically allocated memory list.
715331Samw  * flags:  see SMB_SMGBUF flags.
725331Samw  */
735331Samw typedef struct smb_msgbuf {
745331Samw 	uint8_t *base;
755331Samw 	uint8_t *end;
765331Samw 	uint8_t *scan;
775331Samw 	size_t count;
785331Samw 	size_t max;
795331Samw 	smb_msgbuf_mlist_t mlist;
805331Samw 	uint32_t flags;
815331Samw } smb_msgbuf_t;
825331Samw 
835331Samw /*
845331Samw  * List of smb_msgbuf_decode and smb_msgbuf_encode return values.
855331Samw  */
865331Samw #define	SMB_MSGBUF_SUCCESS		0
875331Samw #define	SMB_MSGBUF_UNDERFLOW		-1
885331Samw #define	SMB_MSGBUF_OVERFLOW		SMB_MSGBUF_UNDERFLOW
895331Samw #define	SMB_MSGBUF_INVALID_FORMAT	-2
905331Samw #define	SMB_MSGBUF_INVALID_HEADER	-3
915331Samw #define	SMB_MSGBUF_DATA_ERROR		-4
925331Samw 
935331Samw /*
945331Samw  * smb_msgbuf_init must be called to associate the smb_msgbuf_t with
955331Samw  * a buffer before any encode or decode operations may be performed.
965331Samw  *
975331Samw  * smb_msgbuf_term must be called to free any dynamically allocated memory
985331Samw  * that was acquired during encode or decode operations. At this time
995331Samw  * the only operation that allocates memory is a unicode string decode.
1005331Samw  *
1015331Samw  * If there are no errors, smb_msgbuf_decode and smb_msgbuf_encode return
1025331Samw  * the number of bytes decoded or encoded.  If there is a problem they
1035331Samw  * return -ve error codes.
1045331Samw  */
1055331Samw extern void smb_msgbuf_init(smb_msgbuf_t *, uint8_t *, size_t, uint32_t);
1065331Samw extern void smb_msgbuf_term(smb_msgbuf_t *);
1075331Samw extern int smb_msgbuf_decode(smb_msgbuf_t *, char *, ...);
1085331Samw extern int smb_msgbuf_encode(smb_msgbuf_t *, char *, ...);
1095331Samw extern size_t smb_msgbuf_used(smb_msgbuf_t *);
1105331Samw extern size_t smb_msgbuf_size(smb_msgbuf_t *);
1115331Samw extern uint8_t *smb_msgbuf_base(smb_msgbuf_t *);
1125331Samw extern void smb_msgbuf_word_align(smb_msgbuf_t *);
1135331Samw extern void smb_msgbuf_dword_align(smb_msgbuf_t *);
1145331Samw extern int smb_msgbuf_has_space(smb_msgbuf_t *, size_t);
1155331Samw extern void smb_msgbuf_fset(smb_msgbuf_t *, uint32_t);
1165331Samw extern void smb_msgbuf_fclear(smb_msgbuf_t *, uint32_t);
1175331Samw 
1185331Samw #ifdef __cplusplus
1195331Samw }
1205331Samw #endif
1215331Samw 
1225331Samw #endif /* _SMBSRV_MSGBUF_H */
123