blob: 8f9db218ad022535d9f161aa6853d1dc1c1dc531 [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 Holtmannc7872592004-03-31 20:37:21 +000036#include <malloc.h>
37#include <sys/time.h>
38
39#include <bluetooth/sdp.h>
40#include <bluetooth/sdp_lib.h>
Marcel Holtmannc7872592004-03-31 20:37:21 +000041
42#include "sdpd.h"
43
44typedef struct _sdp_cstate_list sdp_cstate_list_t;
45
46struct _sdp_cstate_list {
47 sdp_cstate_list_t *next;
Marcel Holtmanne343e0f2004-04-28 12:15:04 +000048 long timestamp;
49 sdp_buf_t buf;
Marcel Holtmannc7872592004-03-31 20:37:21 +000050};
51
52static sdp_cstate_list_t *cstates;
53
54// FIXME: should probably remove it when it's found
55sdp_buf_t *sdp_get_cached_rsp(sdp_cont_state_t *cstate)
56{
57 sdp_cstate_list_t *p;
58
59 for (p = cstates; p; p = p->next)
60 if (p->timestamp == cstate->timestamp)
61 return &p->buf;
62 return 0;
63}
64
65long sdp_cstate_alloc_buf(sdp_buf_t *buf)
66{
67 sdp_cstate_list_t *cstate = (sdp_cstate_list_t *)malloc(sizeof(sdp_cstate_list_t));
68 char *data = (char *)malloc(buf->data_size);
69
70 memcpy(data, buf->data, buf->data_size);
71 memset((char *)cstate, 0, sizeof(sdp_cstate_list_t));
72 cstate->buf.data = data;
73 cstate->buf.data_size = buf->data_size;
74 cstate->buf.buf_size = buf->data_size;
75 cstate->timestamp = sdp_get_time();
76 cstate->next = cstates;
77 cstates = cstate;
78 return cstate->timestamp;
79}
80
81/*
82 * A simple function which returns the time of day in
83 * seconds. Used for updating the service db state
84 * attribute of the service record of the SDP server
85 */
86long sdp_get_time()
87{
88 /*
89 * To handle failure in gettimeofday, so an old
90 * value is returned and service does not fail
91 */
92 static struct timeval tm;
93
94 gettimeofday(&tm, NULL);
95 return tm.tv_sec;
96}