summaryrefslogtreecommitdiffstats
path: root/sdpd/request.c
diff options
context:
space:
mode:
Diffstat (limited to 'sdpd/request.c')
-rw-r--r--sdpd/request.c99
1 files changed, 46 insertions, 53 deletions
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);