/*******************************************************************

Copyright (c) 2004 Open Mobile Alliance, Ltd.  All Rights Reserved.

This software is made available under the usage and distribution terms 
covered by the Common Public License 1.0 and by using this software you
are bound by the terms and conditions of the same.

EXCEPT AS EXPRESSLY SET FORTH IN THE COMMON PUBLIC LICENSE,
THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, 
ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, 
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
   
Each recipient is solely responsible for determining the 
appropriateness of using and distributing this program and assumes 
all risks associated with its exercise of rights under the Common 
Public License, including but not limited to the risks and 
costs of program errors, compliance with applicable laws, 
damage to or loss of data, programs or equipment, and 
unavailability or interruption of operations.

********************************************************************/
#ifndef OBEXHEADER_H
#define OBEXHEADER_H
#include <constants.h>

#ifdef __cplusplus
extern "C" {
#endif

/*
** There are two general ways to create a header:
**
** From a buffer containing data.
**
**    The primary use of this interface is by the transport layer.  Data inbound from
**    a peer obex is taken off the network and headers are created using this function
**    call.  The inbound data is assumed to be in network byte order with regard to lengths.
**
** Through seperate function calls.
**
**    This is the intended way for users to create header objects.
**
*/

/*
** Creates a new, empty header.
*/
ObxHeader *iobxHeaderNew( unsigned char opcode );

/*
** The following functions set the value associated with the
** header.  Attempts to use a function call with an inappropriate opcode or
** passing a null header pointer will result in a OBX_RC_ERROR_INAPPROPRIATE return code.
*/
ObxRc     iobxHeaderSetIntValue( ObxHeader *header, unsigned int value );
ObxRc     iobxHeaderSetByteValue( ObxHeader *header, unsigned char value );
ObxRc     iobxHeaderSetUnicodeValue( ObxHeader *header, ObxBuffer *value );
ObxRc     iobxHeaderSetByteSequenceValue( ObxHeader *header, ObxBuffer *value );

/*
** Given the bytes sitting in the passed buffer, create a header.
** The buffer is 'consumed' by doing this.  It's assumed that the inbound
** buffer contains atleast the amount of data required to form the header and
** is positioned to begin header creation.
*/
 ObxHeader   *iobxHeaderNewFromBuffer( ObxBuffer *buffer, ObxObject *object );

/*
** The passed header is free()'ed.  All contents of the header are also free()'ed.
*/
 void        iobxHeaderFree( ObxHeader *header );

/*
** Using the passed transport, this method sends data associated with this header.
** The 'bytes' argument only has meaning with the 'body' header and is ignored by
** others (they send all bytes).  The 'body' header may need to fragment iff bytes
** is less than the number of bytes actually contained within the header.
** This argument indicates the number of bytes it's safe to send.  Another call will
** be made indicating that more (possibly the remainder) of the bytes may be sent.
** Numerous invocations may be made (enough to exaust the header).
*/
ObxRc       iobxHeaderSend( ObxHeader *header, ObxHandle *handle, int bytes );

/*
** How large is this header right now?
** This is the size of the header if 'put on the wire' right now.  Including identifier,
** any lengths, data, etc.
*/
int         iobxHeaderSize( ObxHeader *header );

/*
** The following routines are called during the creation of the header using a buffer.
*/
ObxRc       iobxHeaderAddIntBuffer( ObxHeader *header, ObxBuffer *buf );
ObxRc       iobxHeaderAddByteBuffer( ObxHeader *header, ObxBuffer *buf );
ObxRc       iobxHeaderAddUnicodeBuffer( ObxHeader *header, ObxBuffer *buf );
ObxRc       iobxHeaderAddByteSequenceBuffer( ObxHeader *header, ObxBuffer *buf );

#ifdef __cplusplus
}
#endif

#endif
