/* * Function obex_response_request (self, opcode) * * Send a response to peer device * */ void obex_response_request(obex_t *self, uint8_t opcode) { buf_t *msg; obex_return_if_fail(self != NULL); msg = buf_reuse(self->tx_msg); obex_data_request(self, msg, opcode | OBEX_FINAL); }
/* * Function obex_response_request (self, opcode) * * Send a response to peer device * */ void obex_response_request(obex_t *self, uint8_t opcode) { GNetBuf *msg; obex_return_if_fail(self != NULL); msg = g_netbuf_recycle(self->tx_msg); g_netbuf_reserve(msg, sizeof(obex_common_hdr_t)); obex_data_request(self, msg, opcode | OBEX_FINAL); }
/* * Function obex_object_send() * * Send away all headers attached to an object. Returns: * 1 on sucessfully done * 0 on progress made * < 0 on error */ int obex_object_send(obex_t *self, obex_object_t *object, int allowfinalcmd, int forcefinalbit) { struct obex_header_element *h; buf_t *txmsg; int actual, finished = 0; uint16_t tx_left; int addmore = TRUE; int real_opcode; DEBUG(4, "\n"); /* Don't do anything of object is suspended */ if (object->suspend) return 0; /* Calc how many bytes of headers we can fit in this package */ tx_left = self->mtu_tx - sizeof(struct obex_common_hdr); switch (self->trans.type) { #ifdef HAVE_IRDA case OBEX_TRANS_IRDA: if (self->trans.mtu > 0 && self->mtu_tx > self->trans.mtu) tx_left -= self->mtu_tx%self->trans.mtu; break; #endif /*HAVE_IRDA*/ default: break; } /* Reuse transmit buffer */ txmsg = buf_reuse(self->tx_msg); /* Add nonheader-data first if any (SETPATH, CONNECT)*/ if (object->tx_nonhdr_data) { DEBUG(4, "Adding %d bytes of non-headerdata\n", object->tx_nonhdr_data->data_size); buf_insert_end(txmsg, object->tx_nonhdr_data->data, object->tx_nonhdr_data->data_size); buf_free(object->tx_nonhdr_data); object->tx_nonhdr_data = NULL; } DEBUG(4, "4\n"); /* Take headers from the tx queue and try to stuff as many as possible into the tx-msg */ while (addmore == TRUE && object->tx_headerq != NULL) { h = object->tx_headerq->data; if (h->stream) { /* This is a streaming body */ if (h->flags & OBEX_FL_SUSPEND) object->suspend = 1; actual = send_stream(self, h, txmsg, tx_left); if (actual < 0 ) return -1; tx_left -= actual; } else if (h->hi == OBEX_HDR_BODY) { /* The body may be fragmented over several packets. */ if (h->flags & OBEX_FL_SUSPEND) object->suspend = 1; tx_left -= send_body(object, h, txmsg, tx_left); } else if(h->hi == OBEX_HDR_EMPTY) { if (h->flags & OBEX_FL_SUSPEND) object->suspend = 1; object->tx_headerq = slist_remove(object->tx_headerq, h); free(h); } else if (h->length <= tx_left) { /* There is room for more data in tx msg */ DEBUG(4, "Adding non-body header\n"); buf_insert_end(txmsg, h->buf->data, h->length); tx_left -= h->length; if (h->flags & OBEX_FL_SUSPEND) object->suspend = 1; /* Remove from tx-queue */ object->tx_headerq = slist_remove(object->tx_headerq, h); buf_free(h->buf); free(h); } else if (h->length > self->mtu_tx) { /* Header is bigger than MTU. This should not happen, because OBEX_ObjectAddHeader() rejects headers bigger than the MTU */ DEBUG(0, "ERROR! header to big for MTU\n"); return -1; } else { /* This header won't fit. */ addmore = FALSE; } if (object->suspend) addmore = FALSE; if (tx_left == 0) addmore = FALSE; }; /* Decide which command to use, and if to use final-bit */ if (object->tx_headerq) { /* Have more headers (or body) to send */ /* In server, final bit is always set. * In client, final bit is set only when we finish sending. * Jean II */ if (forcefinalbit) real_opcode = object->opcode | OBEX_FINAL; else real_opcode = object->opcode; finished = 0; } else if (allowfinalcmd == FALSE) { /* Have no yet any headers to send, but not allowed to send * final command (== server, receiving incomming request) */ real_opcode = object->opcode | OBEX_FINAL; finished = 0; } else { /* Have no more headers to send, and allowed to send final * command (== end data we are sending) */ real_opcode = object->lastopcode | OBEX_FINAL; finished = 1; } DEBUG(4, "Sending package with opcode %d\n", real_opcode); actual = obex_data_request(self, txmsg, real_opcode); if (actual < 0) { DEBUG(4, "Send error\n"); return actual; } else return finished; }