/*****************************************************************************
 *  __________________    _________  _____            _____  .__         ._.
 *  \______   \______ \  /   _____/ /     \          /  _  \ |__| ____   | |
 *   |    |  _/|    |  \ \_____  \ /  \ /  \        /  /_\  \|  _/ __ \  | |
 *   |    |   \|    `   \/        /    Y    \      /    |    |  \  ___/   \|
 *   |______  /_______  /_______  \____|__  / /\   \____|__  |__|\___ |   __
 *          \/        \/        \/        \/  )/           \/        \/   \/
 *
 * This file is part of liBDSM. Copyright © 2014-2015 VideoLabs SAS
 *
 * Author: Julien 'Lta' BALLET <contact@lta.io>
 *
 * liBDSM is released under LGPLv2.1 (or later) and is also available
 * under a commercial license.
 *****************************************************************************
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

/*
 * Copyright (c) 2003-2017
 * Distributed Systems Software.  All rights reserved.
 *
 * $Id: smb_message.h 2958 2017-05-18 18:56:19Z brachman $
 */

#ifndef _LIBDSM_SMB_MESSAGE_H_
#define _LIBDSM_SMB_MESSAGE_H_

#include "smb_defs.h"
#include "smb_types.h"

#define SMB_MSG_INIT_PKT(pkt) do {				\
    memset(&pkt, 0, sizeof(pkt));				\
  } while (0)

#define SMB_MSG_INIT_PKT_ANDX(pkt) do {			\
    SMB_MSG_INIT_PKT(pkt);						\
    pkt.andx           = 0xff;					\
    pkt.andx_reserved  = 0;						\
    pkt.andx_offset    = 0;						\
  } while (0)

#define SMB_MSG_PUT_PKT(msg, pkt)				\
  smb_message_append(msg, &pkt, sizeof(pkt))

#define SMB_MSG_ADVANCE_PKT(msg, pkt)			\
  smb_message_advance(msg, sizeof(pkt))

#define SMB_MSG_INSERT_PKT(msg, cursor, pkt)			\
  smb_message_insert(msg, cursor, &pkt, sizeof(pkt))

#ifdef __cplusplus
extern "C" {
#endif

extern smb_message *smb_message_new(uint8_t cmd);
extern smb_message *smb_message_grow(smb_message *msg, size_t size);
extern void smb_message_destroy(smb_message *msg);
extern int smb_message_advance(smb_message *msg, size_t size);
extern int smb_message_append(smb_message *msg, const void *data,
							  size_t data_size);
extern int smb_message_insert(smb_message *msg, size_t cursor,
							  const void *data, size_t data_size);
extern int smb_message_put8(smb_message *msg, uint8_t data);
extern int smb_message_put16(smb_message *msg, uint16_t data);
extern int smb_message_put32(smb_message *msg, uint32_t data);
extern int smb_message_put64(smb_message *msg, uint64_t data);
extern size_t smb_message_put_utf16(smb_message *msg, const char *str,
									size_t str_len);
extern int smb_message_put_uuid(smb_message *msg, uint32_t a, uint16_t b,
								uint16_t c, const uint8_t e[8]);

extern void smb_message_set_andx_members(smb_message *msg);
extern void smb_message_flag(smb_message *msg, uint32_t flag, int value);

#ifdef __cplusplus
}
#endif

#endif
