/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Iain Hibbert.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
ss->ibuf = malloc((size_t)(ss->imtu));
if (ss->ibuf == NULL)
goto fail;
return ss;
fail:
_sdp_close(ss);
return NULL;
}
/*
* close session and release all resources
*/
void
_sdp_close(struct sdp_session *ss)
{
if (ss == NULL)
return;
if (ss->s != -1)
close(ss->s);
if (ss->ibuf != NULL)
free(ss->ibuf);
if (ss->rbuf != NULL)
free(ss->rbuf);
free(ss);
}
/*
* internal function; send a PDU on session
*
* caller provides an iovec array with an empty slot at the beginning for
* PDU header, num is total iovec count.
*/
bool
_sdp_send_pdu(struct sdp_session *ss, uint8_t pid, struct iovec *iov, int num)
{
sdp_pdu_t pdu;
ssize_t len, nw;
int i;
for (len = 0, i = 1; i < num; i++)
len += iov[i].iov_len;
/*
* internal function; receive a PDU on session
*
* validate the PDU and transaction IDs and data length, stores
* received data in the session incoming buffer.
*/
ssize_t
_sdp_recv_pdu(struct sdp_session *ss, uint8_t pid)
{
struct iovec iov[2];
sdp_pdu_t pdu;
ssize_t nr;
/*
* translate ErrorCode to errno
*/
int
_sdp_errno(uint16_t ec)
{
switch (ec) {
case SDP_ERROR_CODE_INVALID_SERVICE_RECORD_HANDLE:
return ENOATTR;
case SDP_ERROR_CODE_INVALID_SDP_VERSION:
case SDP_ERROR_CODE_INVALID_REQUEST_SYNTAX:
case SDP_ERROR_CODE_INVALID_PDU_SIZE:
case SDP_ERROR_CODE_INVALID_CONTINUATION_STATE:
case SDP_ERROR_CODE_INSUFFICIENT_RESOURCES:
default:
return EIO;
}
}