Marcel Holtmann | c787259 | 2004-03-31 20:37:21 +0000 | [diff] [blame] | 1 | /* |
Marcel Holtmann | e343e0f | 2004-04-28 12:15:04 +0000 | [diff] [blame] | 2 | * |
| 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 Holtmann | c787259 | 2004-03-31 20:37:21 +0000 | [diff] [blame] | 30 | */ |
| 31 | |
Marcel Holtmann | e343e0f | 2004-04-28 12:15:04 +0000 | [diff] [blame] | 32 | #ifdef HAVE_CONFIG_H |
| 33 | #include <config.h> |
| 34 | #endif |
| 35 | |
Marcel Holtmann | fa8b3a2 | 2005-02-22 15:21:59 +0000 | [diff] [blame] | 36 | #include <stdio.h> |
Marcel Holtmann | c787259 | 2004-03-31 20:37:21 +0000 | [diff] [blame] | 37 | #include <malloc.h> |
| 38 | #include <sys/time.h> |
Marcel Holtmann | cfb680f | 2005-03-09 17:27:17 +0000 | [diff] [blame] | 39 | #include <sys/socket.h> |
Marcel Holtmann | c787259 | 2004-03-31 20:37:21 +0000 | [diff] [blame] | 40 | |
Marcel Holtmann | cfb680f | 2005-03-09 17:27:17 +0000 | [diff] [blame] | 41 | #include <bluetooth/bluetooth.h> |
Marcel Holtmann | c787259 | 2004-03-31 20:37:21 +0000 | [diff] [blame] | 42 | #include <bluetooth/sdp.h> |
| 43 | #include <bluetooth/sdp_lib.h> |
Marcel Holtmann | c787259 | 2004-03-31 20:37:21 +0000 | [diff] [blame] | 44 | |
| 45 | #include "sdpd.h" |
| 46 | |
| 47 | typedef struct _sdp_cstate_list sdp_cstate_list_t; |
| 48 | |
| 49 | struct _sdp_cstate_list { |
| 50 | sdp_cstate_list_t *next; |
Marcel Holtmann | cfb680f | 2005-03-09 17:27:17 +0000 | [diff] [blame] | 51 | uint32_t timestamp; |
Marcel Holtmann | e343e0f | 2004-04-28 12:15:04 +0000 | [diff] [blame] | 52 | sdp_buf_t buf; |
Marcel Holtmann | c787259 | 2004-03-31 20:37:21 +0000 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | static sdp_cstate_list_t *cstates; |
| 56 | |
| 57 | // FIXME: should probably remove it when it's found |
| 58 | sdp_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 Holtmann | cfb680f | 2005-03-09 17:27:17 +0000 | [diff] [blame] | 68 | uint32_t sdp_cstate_alloc_buf(sdp_buf_t *buf) |
Marcel Holtmann | c787259 | 2004-03-31 20:37:21 +0000 | [diff] [blame] | 69 | { |
| 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 Holtmann | cfb680f | 2005-03-09 17:27:17 +0000 | [diff] [blame] | 89 | uint32_t sdp_get_time() |
Marcel Holtmann | c787259 | 2004-03-31 20:37:21 +0000 | [diff] [blame] | 90 | { |
| 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 Holtmann | cfb680f | 2005-03-09 17:27:17 +0000 | [diff] [blame] | 98 | return (uint32_t) tm.tv_sec; |
Marcel Holtmann | c787259 | 2004-03-31 20:37:21 +0000 | [diff] [blame] | 99 | } |