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

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.

********************************************************************/
/*
** Defines internal obex constants.
*/

#ifndef OBEXINTERNALCONSTANTS_H
#define OBEXINTERNALCONSTANTS_H

#ifdef _WIN32
 #define WIN32_LEAN_AND_MEAN

 #include <windows.h>
 #include <winsock.h>
 #include <stdlib.h>
 #include <limits.h>

 #define serror() _describeWin32SocketError();
 #define sclose closesocket
 #define sread(fd, buf, len)  recv((fd), (buf), (len), 0)
 #define swrite(fd, buf, len) send((fd), (buf), (len), 0)
 #define sleep(seconds) SleepEx((seconds) * 1000, TRUE)
#else
 #include <unistd.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
 #include <sys/types.h>
 #include <arpa/inet.h>
 #include <netinet/in.h>
 #include <netdb.h>
 #include <limits.h>
 #include <stdlib.h>
 #include <math.h>
 #include <stdio.h>
 #include <tcpd.h>

 #define serror perror
 #define sclose close
 #define sread read
 #define swrite write

 #undef max
 #define max(a,b) ((a) > (b) ? (a) : (b))
 #undef min
 #define min(a,b) ((a) < (b) ? (a) : (b))

 #define SOCKET_ERROR   -1

#endif


/*
** Grab general obex constants.
*/
#include <constants.h>
#include <buffer.h>

/*
** Debug output.
*/
#include <debug.h>

/*
** Errors
*/
#include <error.h>

#define OBEX_HEADER_SEND_ALL                 INT_MAX

#define OBX_CONNECT_META_FLAGS               0x00
#define OBX_CONNECT_META_VERSION             OBEX_VERSION
#define OBX_CONNECT_META_MAX_PACKET_LENGTH   OBEX_DEFAULT_PACKET_LENGTH

#define OBX_SETPATH_META_CONSTANTS           0x00
#define OBX_SETPATH_META_FLAGS               0x00

/*
** Every frame begins thus
*/
struct iobxCommonFrameHeader {
	unsigned char  opcode;  /* 8 bits         */
	unsigned short length;  /* 16 bits        */
};

/*
** Connect header
*/
struct iobxConnectHeader {
	unsigned char  version; /* 8 bits         */
	unsigned char  flags;   /* 8 bits         */
	unsigned short mtu;     /* 16 bits        */
};

/*
** Stream
*/
typedef enum {
   STREAM_UNOPEN,
   STREAM_SENDING,
   STREAM_RECEIVING,
   STREAM_FINISHED,
   STREAM_CLOSED
} ObxStreamState;

struct iobxStream {
   ObxCommand     cmd;			      /* Command associated with the stream           */
   ObxHandle      *handle;          /* Where we get our fd                          */
   ObxBuffer      *data;            /* Data waiting to go...                        */
   ObxObject      *request;         /* Our, private request.                        */
   ObxStreamState state;            /* UNOPEN, SENDING, RECEIVING, FINISHED, CLOSED */
};

#endif
