blob: dd5329437d7c8a1fc532dd295535a269429d6592 [file] [log] [blame]
Marcel Holtmannc7872592004-03-31 20:37:21 +00001/*
Marcel Holtmanne343e0f2004-04-28 12:15:04 +00002 *
3 * BlueZ - Bluetooth protocol stack for Linux
4 *
5 * Copyright (C) 2001-2002 Nokia Corporation
6 * Copyright (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
7 * Copyright (C) 2002-2004 Marcel Holtmann <marcel@holtmann.org>
8 * Copyright (C) 2002-2003 Stephen Crane <steve.crane@rococosoft.com>
9 *
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation;
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
18 * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
19 * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
20 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
21 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
22 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 *
24 * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
25 * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
26 * SOFTWARE IS DISCLAIMED.
27 *
28 *
29 * $Id$
Marcel Holtmannc7872592004-03-31 20:37:21 +000030 */
31
Marcel Holtmanne343e0f2004-04-28 12:15:04 +000032#ifdef HAVE_CONFIG_H
33#include <config.h>
34#endif
35
Marcel Holtmannfa8b3a22005-02-22 15:21:59 +000036#include <stdio.h>
Marcel Holtmannc7872592004-03-31 20:37:21 +000037#include <malloc.h>
38#include <sys/time.h>
Marcel Holtmanncfb680f2005-03-09 17:27:17 +000039#include <sys/socket.h>
Marcel Holtmannc7872592004-03-31 20:37:21 +000040
Marcel Holtmanncfb680f2005-03-09 17:27:17 +000041#include <bluetooth/bluetooth.h>
Marcel Holtmannc7872592004-03-31 20:37:21 +000042#include <bluetooth/sdp.h>
43#include <bluetooth/sdp_lib.h>
Marcel Holtmannc7872592004-03-31 20:37:21 +000044
45#include "sdpd.h"
46
47typedef struct _sdp_cstate_list sdp_cstate_list_t;
48
49struct _sdp_cstate_list {
50 sdp_cstate_list_t *next;
Marcel Holtmanncfb680f2005-03-09 17:27:17 +000051 uint32_t timestamp;
Marcel Holtmanne343e0f2004-04-28 12:15:04 +000052 sdp_buf_t buf;
Marcel Holtmannc7872592004-03-31 20:37:21 +000053};
54
55static sdp_cstate_list_t *cstates;
56
57// FIXME: should probably remove it when it's found
58sdp_buf_t *sdp_get_cached_rsp(sdp_cont_state_t *cstate)
59{
60 sdp_cstate_list_t *p;
61
62 for (p = cstates; p; p = p->next)
63 if (p->timestamp == cstate->timestamp)
64 return &p->buf;
65 return 0;
66}
67
Marcel Holtmanncfb680f2005-03-09 17:27:17 +000068uint32_t sdp_cstate_alloc_buf(sdp_buf_t *buf)
Marcel Holtmannc7872592004-03-31 20:37:21 +000069{
70 sdp_cstate_list_t *cstate = (sdp_cstate_list_t *)malloc(sizeof(sdp_cstate_list_t));
71 char *data = (char *)malloc(buf->data_size);
72
73 memcpy(data, buf->data, buf->data_size);
74 memset((char *)cstate, 0, sizeof(sdp_cstate_list_t));
75 cstate->buf.data = data;
76 cstate->buf.data_size = buf->data_size;
77 cstate->buf.buf_size = buf->data_size;
78 cstate->timestamp = sdp_get_time();
79 cstate->next = cstates;
80 cstates = cstate;
81 return cstate->timestamp;
82}
83
84/*
85 * A simple function which returns the time of day in
86 * seconds. Used for updating the service db state
87 * attribute of the service record of the SDP server
88 */
Marcel Holtmanncfb680f2005-03-09 17:27:17 +000089uint32_t sdp_get_time()
Marcel Holtmannc7872592004-03-31 20:37:21 +000090{
91 /*
92 * To handle failure in gettimeofday, so an old
93 * value is returned and service does not fail
94 */
95 static struct timeval tm;
96
97 gettimeofday(&tm, NULL);
Marcel Holtmanncfb680f2005-03-09 17:27:17 +000098 return (uint32_t) tm.tv_sec;
Marcel Holtmannc7872592004-03-31 20:37:21 +000099}