diff options
-rw-r--r-- | sdpd/main.c | 2 | ||||
-rw-r--r-- | sdpd/request.c | 99 | ||||
-rw-r--r-- | sdpd/service.c | 30 | ||||
-rw-r--r-- | sdpd/servicedb.c | 16 |
4 files changed, 68 insertions, 79 deletions
diff --git a/sdpd/main.c b/sdpd/main.c index c21380cd..da14b967 100644 --- a/sdpd/main.c +++ b/sdpd/main.c @@ -307,7 +307,7 @@ static int init_server(uint16_t mtu, int master, int public) static void sig_term(int sig) { - info("terminating... \n"); + info("terminating..."); sdp_svcdb_reset(); close(l2cap_sock); close(unix_sock); diff --git a/sdpd/request.c b/sdpd/request.c index 059aec40..17aa9d99 100644 --- a/sdpd/request.c +++ b/sdpd/request.c @@ -67,28 +67,29 @@ static int extract_des(uint8_t *buf, int len, sdp_list_t **svcReqSeq, uint8_t *p scanned = sdp_extract_seqtype(buf, &seqType, &data_size); - debug("Seq type : %d\n", seqType); + debug("Seq type : %d", seqType); if (!scanned || (seqType != SDP_SEQ8 && seqType != SDP_SEQ16)) { - error("Unknown seq type \n"); + error("Unknown seq type"); return -1; } p = buf + scanned; - debug("Data size : %d\n", data_size); + debug("Data size : %d", data_size); + for (;;) { char *pElem = NULL; int localSeqLength = 0; dataType = *(uint8_t *)p; - debug("Data type: 0x%02x\n", dataType); + debug("Data type: 0x%02x", dataType); if (expectedType == SDP_TYPE_UUID) { if (dataType != SDP_UUID16 && dataType != SDP_UUID32 && dataType != SDP_UUID128) { - debug("->Unexpected Data type (expected UUID_ANY)\n"); + debug("->Unexpected Data type (expected UUID_ANY)"); return -1; } } else if (expectedType != SDP_TYPE_ANY && dataType != expectedType) { - debug("->Unexpected Data type (expected 0x%02x)\n", expectedType); + debug("->Unexpected Data type (expected 0x%02x)", expectedType); return -1; } @@ -125,7 +126,7 @@ static int extract_des(uint8_t *buf, int len, sdp_list_t **svcReqSeq, uint8_t *p if (status == 0) { pSeq = sdp_list_append(pSeq, pElem); numberOfElements++; - debug("No of elements : %d\n", numberOfElements); + debug("No of elements : %d", numberOfElements); if (seqlen == data_size) break; @@ -146,7 +147,7 @@ static int sdp_set_cstate_pdu(sdp_buf_t *buf, sdp_cont_state_t *cstate) int length = 0; if (cstate) { - debug("Non null sdp_cstate_t id : 0x%lx\n", cstate->timestamp); + debug("Non null sdp_cstate_t id : 0x%lx", cstate->timestamp); *(uint8_t *)pdata = sizeof(sdp_cont_state_t); pdata += sizeof(uint8_t); length += sizeof(uint8_t); @@ -171,13 +172,13 @@ static sdp_cont_state_t *sdp_cstate_get(uint8_t *buffer) * Check if continuation state exists, if yes attempt * to get response remainder from cache, else send error */ - debug("Continuation State size : %d\n", cStateSize); + debug("Continuation State size : %d", cStateSize); pdata += sizeof(uint8_t); if (cStateSize != 0) { sdp_cont_state_t *cstate = (sdp_cont_state_t *)pdata; - debug("Cstate TS : 0x%lx\n", cstate->timestamp); - debug("Bytes sent : %d\n", cstate->cStateValue.maxBytesSent); + debug("Cstate TS : 0x%lx", cstate->timestamp); + debug("Bytes sent : %d", cstate->cStateValue.maxBytesSent); return cstate; } return NULL; @@ -203,8 +204,6 @@ static int sdp_match_uuid(sdp_list_t *search, sdp_list_t *pattern) */ int patlen = sdp_list_len(pattern); - debug(""); - if (patlen < sdp_list_len(search)) return -1; for (; search; search = search->next) { @@ -243,8 +242,6 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf) short *pTotalRecordCount, *pCurrentRecordCount; uint8_t *pdata = req->buf + sizeof(sdp_pdu_hdr_t); - debug(""); - scanned = extract_des(pdata, req->len - sizeof(sdp_pdu_hdr_t), &pattern, &dtd, SDP_TYPE_UUID); @@ -264,8 +261,8 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf) expected = ntohs(sdp_get_unaligned((uint16_t *)pdata)); - debug("Expected count: %d\n", expected); - debug("Bytes scanned : %d\n", scanned); + debug("Expected count: %d", expected); + debug("Bytes scanned : %d", scanned); pdata += sizeof(uint16_t); @@ -301,7 +298,7 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf) for (; list && rsp_count < expected; list = list->next) { sdp_record_t *rec = (sdp_record_t *) list->data; - debug("Checking svcRec : 0x%x\n", rec->handle); + debug("Checking svcRec : 0x%x", rec->handle); if (sdp_match_uuid(pattern, rec->pattern) > 0 && sdp_check_access(rec->handle, &req->device)) { @@ -312,7 +309,7 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf) } } - debug("Match count: %d\n", rsp_count); + debug("Match count: %d", rsp_count); buf->data_size += handleSize; sdp_put_unaligned(htons(rsp_count), (uint16_t *)pTotalRecordCount); @@ -394,7 +391,7 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf) */ sdp_cont_state_t newState; - debug("Setting non-NULL sdp_cstate_t\n"); + debug("Setting non-NULL sdp_cstate_t"); if (cstate) memcpy((char *)&newState, cstate, sizeof(sdp_cont_state_t)); @@ -427,14 +424,14 @@ static int extract_attrs(sdp_record_t *rec, sdp_list_t *seq, uint8_t dtd, sdp_bu return SDP_INVALID_RECORD_HANDLE; if (seq) - debug("Entries in attr seq : %d\n", sdp_list_len(seq)); + debug("Entries in attr seq : %d", sdp_list_len(seq)); else - debug("NULL attribute descriptor\n"); + debug("NULL attribute descriptor"); - debug("AttrDataType : %d\n", dtd); + debug("AttrDataType : %d", dtd); if (seq == NULL) { - debug("Attribute sequence is NULL\n"); + debug("Attribute sequence is NULL"); return 0; } if (dtd == SDP_UINT16) @@ -454,9 +451,9 @@ static int extract_attrs(sdp_record_t *rec, sdp_list_t *seq, uint8_t dtd, sdp_bu uint16_t high = 0x0000ffff & range; sdp_data_t *data; - debug("attr range : 0x%x\n", range); - debug("Low id : 0x%x\n", low); - debug("High id : 0x%x\n", high); + debug("attr range : 0x%x", range); + debug("Low id : 0x%x", low); + debug("High id : 0x%x", high); if (low == 0x0000 && high == 0xffff && pdu.data_size <= buf->buf_size) { /* copy it */ @@ -476,8 +473,8 @@ static int extract_attrs(sdp_record_t *rec, sdp_list_t *seq, uint8_t dtd, sdp_bu } free(pdu.data); } else { - error("Unexpected data type : 0x%x\n", dtd); - error("Expect uint16_t or uint32_t\n"); + error("Unexpected data type : 0x%x", dtd); + error("Expect uint16_t or uint32_t"); return SDP_INVALID_SYNTAX; } return 0; @@ -502,8 +499,6 @@ static int service_attr_req(sdp_req_t *req, sdp_buf_t *buf) uint8_t *pdata = req->buf + sizeof(sdp_pdu_hdr_t); uint32_t handle = ntohl(sdp_get_unaligned((uint32_t *)pdata)); - debug(""); - pdata += sizeof(uint32_t); max_rsp_size = ntohs(sdp_get_unaligned((uint16_t *)pdata)); pdata += sizeof(uint16_t); @@ -531,8 +526,8 @@ static int service_attr_req(sdp_req_t *req, sdp_buf_t *buf) */ cstate = sdp_cstate_get(pdata); - debug("SvcRecHandle : 0x%x\n", handle); - debug("max_rsp_size : %d\n", max_rsp_size); + debug("SvcRecHandle : 0x%x", handle); + debug("max_rsp_size : %d", max_rsp_size); /* * Calculate Attribute size acording to MTU @@ -548,7 +543,7 @@ static int service_attr_req(sdp_req_t *req, sdp_buf_t *buf) if (cstate) { sdp_buf_t *pCache = sdp_get_cached_rsp(cstate); - debug("Obtained cached rsp : %p\n", pCache); + debug("Obtained cached rsp : %p", pCache); if (pCache) { short sent = MIN(max_rsp_size, pCache->data_size - cstate->cStateValue.maxBytesSent); @@ -557,7 +552,7 @@ static int service_attr_req(sdp_req_t *req, sdp_buf_t *buf) buf->data_size += sent; cstate->cStateValue.maxBytesSent += sent; - debug("Response size : %d sending now : %d bytes sent so far : %d\n", + debug("Response size : %d sending now : %d bytes sent so far : %d", pCache->data_size, sent, cstate->cStateValue.maxBytesSent); if (cstate->cStateValue.maxBytesSent == pCache->data_size) cstate_size = sdp_set_cstate_pdu(buf, NULL); @@ -565,7 +560,7 @@ static int service_attr_req(sdp_req_t *req, sdp_buf_t *buf) cstate_size = sdp_set_cstate_pdu(buf, cstate); } else { status = SDP_INVALID_CSTATE; - error("NULL cache buffer and non-NULL continuation state\n"); + error("NULL cache buffer and non-NULL continuation state"); } } else { sdp_record_t *rec = sdp_record_find(handle); @@ -579,7 +574,7 @@ static int service_attr_req(sdp_req_t *req, sdp_buf_t *buf) * Reset the buffer size to the maximum expected and * set the sdp_cont_state_t */ - debug("Creating continuation state of size : %d\n", buf->data_size); + debug("Creating continuation state of size : %d", buf->data_size); buf->data_size = max_rsp_size; newState.cStateValue.maxBytesSent = max_rsp_size; cstate_size = sdp_set_cstate_pdu(buf, &newState); @@ -687,10 +682,10 @@ static int service_search_attr_req(sdp_req_t *req, sdp_buf_t *buf) rsp_count++; status = extract_attrs(rec, seq, dtd, &tmpbuf); - debug("Response count : %d\n", rsp_count); - debug("Local PDU size : %d\n", tmpbuf.data_size); + debug("Response count : %d", rsp_count); + debug("Local PDU size : %d", tmpbuf.data_size); if (status) { - debug("Extract attr from record returns err\n"); + debug("Extract attr from record returns err"); break; } if (buf->data_size + tmpbuf.data_size < buf->buf_size) { @@ -699,10 +694,10 @@ static int service_search_attr_req(sdp_req_t *req, sdp_buf_t *buf) tmpbuf.data_size = 0; memset(tmpbuf.data, 0, USHRT_MAX); } else { - error("Relocation needed\n"); + error("Relocation needed"); break; } - debug("Net PDU size : %d\n", buf->data_size); + debug("Net PDU size : %d", buf->data_size); } } if (buf->data_size > max) { @@ -734,7 +729,7 @@ static int service_search_attr_req(sdp_req_t *req, sdp_buf_t *buf) cstate_size = sdp_set_cstate_pdu(buf, cstate); } else { status = SDP_INVALID_CSTATE; - debug("Non-null continuation state, but null cache buffer\n"); + debug("Non-null continuation state, but null cache buffer"); } } @@ -779,8 +774,6 @@ void process_request(sdp_req_t *req) int sent = 0; int status = SDP_INVALID_SYNTAX; - debug(""); - memset(buf, 0, USHRT_MAX); rsp.data = buf + sizeof(sdp_pdu_hdr_t); rsp.data_size = 0; @@ -793,44 +786,44 @@ void process_request(sdp_req_t *req) } switch (reqhdr->pdu_id) { case SDP_SVC_SEARCH_REQ: - debug("Got a svc srch req\n"); + debug("Got a svc srch req"); status = service_search_req(req, &rsp); rsphdr->pdu_id = SDP_SVC_SEARCH_RSP; break; case SDP_SVC_ATTR_REQ: - debug("Got a svc attr req\n"); + debug("Got a svc attr req"); status = service_attr_req(req, &rsp); rsphdr->pdu_id = SDP_SVC_ATTR_RSP; break; case SDP_SVC_SEARCH_ATTR_REQ: - debug("Got a svc srch attr req\n"); + debug("Got a svc srch attr req"); status = service_search_attr_req(req, &rsp); rsphdr->pdu_id = SDP_SVC_SEARCH_ATTR_RSP; break; /* Following requests are allowed only for local connections */ case SDP_SVC_REGISTER_REQ: - debug("Service register request\n"); + debug("Service register request"); if (req->local) { status = service_register_req(req, &rsp); rsphdr->pdu_id = SDP_SVC_REGISTER_RSP; } break; case SDP_SVC_UPDATE_REQ: - debug("Service update request\n"); + debug("Service update request"); if (req->local) { status = service_update_req(req, &rsp); rsphdr->pdu_id = SDP_SVC_UPDATE_RSP; } break; case SDP_SVC_REMOVE_REQ: - debug("Service removal request\n"); + debug("Service removal request"); if (req->local) { status = service_remove_req(req, &rsp); rsphdr->pdu_id = SDP_SVC_REMOVE_RSP; } break; default: - error("Unknown PDU ID : 0x%x received\n", reqhdr->pdu_id); + error("Unknown PDU ID : 0x%x received", reqhdr->pdu_id); status = SDP_INVALID_SYNTAX; break; } @@ -854,7 +847,7 @@ send_rsp: /* stream the rsp PDU */ sent = send(req->sock, rsp.data, rsp.data_size, 0); - debug("Bytes Sent : %d\n", sent); + debug("Bytes Sent : %d", sent); free(rsp.data); free(req->buf); diff --git a/sdpd/service.c b/sdpd/service.c index 276f4481..b6ac0ac1 100644 --- a/sdpd/service.c +++ b/sdpd/service.c @@ -58,13 +58,13 @@ static sdp_record_t *extract_pdu_server(bdaddr_t *device, uint8_t *p, uint32_t h p += *scanned; lookAheadAttrId = ntohs(sdp_get_unaligned((uint16_t *) (p + sizeof(uint8_t)))); - debug("Look ahead attr id : %d\n", lookAheadAttrId); + debug("Look ahead attr id : %d", lookAheadAttrId); if (lookAheadAttrId == SDP_ATTR_RECORD_HANDLE) { handle = ntohl(sdp_get_unaligned((uint32_t *) (p + sizeof(uint8_t) + sizeof(uint16_t) + sizeof(uint8_t)))); - debug("SvcRecHandle : 0x%x\n", handle); + debug("SvcRecHandle : 0x%x", handle); rec = sdp_record_find(handle); } else if (handleExpected != 0xffffffff) rec = sdp_record_find(handleExpected); @@ -91,11 +91,11 @@ static sdp_record_t *extract_pdu_server(bdaddr_t *device, uint8_t *p, uint32_t h attrId = ntohs(sdp_get_unaligned((uint16_t *) (p + attrSize))); attrSize += sizeof(uint16_t); - debug("DTD of attrId : %d Attr id : 0x%x \n", dtd, attrId); + debug("DTD of attrId : %d Attr id : 0x%x", dtd, attrId); pAttr = sdp_extract_attr(p + attrSize, &attrValueLength, rec); - debug("Attr id : 0x%x attrValueLength : %d\n", attrId, attrValueLength); + debug("Attr id : 0x%x attrValueLength : %d", attrId, attrValueLength); attrSize += attrValueLength; if (pAttr == NULL) { @@ -111,7 +111,7 @@ static sdp_record_t *extract_pdu_server(bdaddr_t *device, uint8_t *p, uint32_t h } if (extractStatus == 0) { - debug("Successful extracting of Svc Rec attributes\n"); + debug("Successful extracting of Svc Rec attributes"); #ifdef SDP_DEBUG sdp_print_service_attr(rec->attrlist); #endif @@ -192,26 +192,24 @@ int service_update_req(sdp_req_t *req, sdp_buf_t *rsp) uint8_t *p = req->buf + sizeof(sdp_pdu_hdr_t); uint32_t handle = ntohl(sdp_get_unaligned((uint32_t *) p)); - debug(""); - - debug("Svc Rec Handle: 0x%x\n", handle); + debug("Svc Rec Handle: 0x%x", handle); p += sizeof(uint32_t); orec = sdp_record_find(handle); - debug("SvcRecOld: %p\n", orec); + debug("SvcRecOld: %p", orec); if (orec) { sdp_record_t *nrec = extract_pdu_server(BDADDR_ANY, p, handle, &scanned); if (nrec && handle == nrec->handle) update_db_timestamp(); else { - debug("SvcRecHandle : 0x%x\n", handle); - debug("SvcRecHandleNew : 0x%x\n", nrec->handle); - debug("SvcRecNew : %p\n", nrec); - debug("SvcRecOld : %p\n", orec); - debug("Failure to update, restore old value\n"); + debug("SvcRecHandle : 0x%x", handle); + debug("SvcRecHandleNew : 0x%x", nrec->handle); + debug("SvcRecNew : %p", nrec); + debug("SvcRecOld : %p", orec); + debug("Failure to update, restore old value"); if (nrec) sdp_record_free(nrec); @@ -236,8 +234,6 @@ int service_remove_req(sdp_req_t *req, sdp_buf_t *rsp) sdp_record_t *rec; int status = 0; - debug(""); - /* extract service record handle */ p += sizeof(uint32_t); @@ -250,7 +246,7 @@ int service_remove_req(sdp_req_t *req, sdp_buf_t *rsp) update_db_timestamp(); } else { status = SDP_INVALID_RECORD_HANDLE; - debug("Could not find record : 0x%x\n", handle); + debug("Could not find record : 0x%x", handle); } p = rsp->data; diff --git a/sdpd/servicedb.c b/sdpd/servicedb.c index d4ebd7de..0ae62e99 100644 --- a/sdpd/servicedb.c +++ b/sdpd/servicedb.c @@ -60,7 +60,7 @@ static int record_sort(const void *r1, const void *r2) const sdp_record_t *rec2 = (const sdp_record_t *) r2; if (!rec1 || !rec2) { - error("NULL RECORD LIST FATAL\n"); + error("NULL RECORD LIST FATAL"); return -1; } @@ -73,7 +73,7 @@ static int access_sort(const void *r1, const void *r2) const sdp_access_t *rec2 = (const sdp_access_t *) r2; if (!rec1 || !rec2) { - error("NULL RECORD LIST FATAL\n"); + error("NULL RECORD LIST FATAL"); return -1; } @@ -169,8 +169,8 @@ void sdp_record_add(bdaddr_t *device, sdp_record_t *rec) { sdp_access_t *dev; - debug("Adding rec : 0x%lx\n", (long) rec); - debug("with handle : 0x%x\n", rec->handle); + debug("Adding rec : 0x%lx", (long) rec); + debug("with handle : 0x%x", rec->handle); service_db = sdp_list_insert_sorted(service_db, rec, record_sort); @@ -195,7 +195,7 @@ static sdp_list_t *record_locate(uint32_t handle) return p; } - debug("Could not find svcRec for : 0x%x\n", handle); + debug("Could not find svcRec for : 0x%x", handle); return NULL; } @@ -210,7 +210,7 @@ static sdp_list_t *access_locate(uint32_t handle) return p; } - debug("Could not find access data for : 0x%x\n", handle); + debug("Could not find access data for : 0x%x", handle); return NULL; } @@ -222,7 +222,7 @@ sdp_record_t *sdp_record_find(uint32_t handle) sdp_list_t *p = record_locate(handle); if (!p) { - debug("Couldn't find record for : 0x%x\n", handle); + debug("Couldn't find record for : 0x%x", handle); return 0; } @@ -239,7 +239,7 @@ int sdp_record_remove(uint32_t handle) sdp_access_t *a; if (!p) { - error("Remove : Couldn't find record for : 0x%x\n", handle); + error("Remove : Couldn't find record for : 0x%x", handle); return -1; } |