#include <errno.h>
#include "gobex.h"
-#include "glib-helper.h"
#include "gobex-debug.h"
#define G_OBEX_DEFAULT_MTU 4096
g_obex_debug(G_OBEX_DEBUG_ERROR, "%s", err->message);
-#ifndef TIZEN_PATCH
- obex->pending_req = NULL;
-#endif
-
if (p->rsp_func)
p->rsp_func(obex, err, NULL, p->rsp_data);
return TRUE;
}
+static void set_srmp(GObex *obex, guint8 srmp, gboolean outgoing)
+{
+ struct srm_config *config = obex->srm;
+
+ if (config == NULL)
+ return;
+
+ /* Dont't reset if direction doesn't match */
+ if (srmp > G_OBEX_SRMP_NEXT_WAIT && config->outgoing != outgoing)
+ return;
+
+ config->srmp = srmp;
+ config->outgoing = outgoing;
+}
+
+static void set_srm(GObex *obex, guint8 op, guint8 srm)
+{
+ struct srm_config *config = obex->srm;
+ gboolean enable;
+
+ if (config == NULL) {
+ if (srm == G_OBEX_SRM_DISABLE)
+ return;
+
+ config = g_new0(struct srm_config, 1);
+ config->op = op;
+ config->srm = srm;
+ obex->srm = config;
+ return;
+ }
+
+ /* Indicate response, treat it as request */
+ if (config->srm == G_OBEX_SRM_INDICATE) {
+ if (srm != G_OBEX_SRM_ENABLE)
+ goto done;
+ config->srm = srm;
+ return;
+ }
+
+ enable = (srm == G_OBEX_SRM_ENABLE);
+ if (config->enabled == enable)
+ goto done;
+
+ config->enabled = enable;
+
+ g_obex_debug(G_OBEX_DEBUG_COMMAND, "SRM %s", config->enabled ?
+ "Enabled" : "Disabled");
+
+done:
+ if (config->enabled)
+ return;
+
+ g_free(obex->srm);
+ obex->srm = NULL;
+}
+
+static void check_srm_final(GObex *obex, guint8 op)
+{
+ if (obex->srm == NULL || !obex->srm->enabled)
+ return;
+
+ switch (obex->srm->op) {
+ case G_OBEX_OP_CONNECT:
+ return;
+ default:
+ if (op <= G_OBEX_RSP_CONTINUE)
+ return;
+ }
+
+ set_srm(obex, op, G_OBEX_SRM_DISABLE);
+}
+
+static void setup_srm(GObex *obex, GObexPacket *pkt, gboolean outgoing)
+{
+ GObexHeader *hdr;
+ guint8 op;
+ gboolean final;
+
+ if (!obex->use_srm)
+ return;
+
+ op = g_obex_packet_get_operation(pkt, &final);
+
+ hdr = g_obex_packet_get_header(pkt, G_OBEX_HDR_SRM);
+ if (hdr != NULL) {
+ guint8 srm;
+ g_obex_header_get_uint8(hdr, &srm);
+ g_obex_debug(G_OBEX_DEBUG_COMMAND, "srm 0x%02x", srm);
+ set_srm(obex, op, srm);
+ }
+
+ hdr = g_obex_packet_get_header(pkt, G_OBEX_HDR_SRMP);
+ if (hdr != NULL) {
+ guint8 srmp;
+ g_obex_header_get_uint8(hdr, &srmp);
+ g_obex_debug(G_OBEX_DEBUG_COMMAND, "srmp 0x%02x", srmp);
+ set_srmp(obex, srmp, outgoing);
+ } else
+ set_srmp(obex, -1, outgoing);
+
+ if (final)
+ check_srm_final(obex, op);
+}
+
static gboolean write_data(GIOChannel *io, GIOCondition cond,
gpointer user_data)
{
if (p == NULL)
goto stop_tx;
+ setup_srm(obex, p->pkt, TRUE);
+
if (g_obex_srm_active(obex))
goto encode;
obex->pending_req = p;
p->timeout_id = g_timeout_add_seconds(p->timeout,
req_timeout, obex);
- } else
+ } else {
+ /* During packet encode final bit can be set */
+ if (obex->tx_buf[0] & FINAL_BIT)
+ check_srm_final(obex,
+ obex->tx_buf[0] & ~FINAL_BIT);
pending_pkt_free(p);
+ }
obex->tx_data = len;
obex->tx_sent = 0;
g_obex_packet_prepend_header(rsp, connid);
}
-static void set_srmp(GObex *obex, guint8 srmp, gboolean outgoing)
-{
- struct srm_config *config = obex->srm;
-
- if (config == NULL)
- return;
-
- /* Dont't reset if direction doesn't match */
- if (srmp > G_OBEX_SRMP_NEXT_WAIT && config->outgoing != outgoing)
- return;
-
- config->srmp = srmp;
- config->outgoing = outgoing;
-}
-
-static void set_srm(GObex *obex, guint8 op, guint8 srm)
-{
- struct srm_config *config = obex->srm;
- gboolean enable;
-
- if (config == NULL) {
- if (srm == G_OBEX_SRM_DISABLE)
- return;
-
- config = g_new0(struct srm_config, 1);
- config->op = op;
- config->srm = srm;
- obex->srm = config;
- return;
- }
-
- /* Indicate response, treat it as request */
- if (config->srm == G_OBEX_SRM_INDICATE) {
- if (srm != G_OBEX_SRM_ENABLE)
- goto done;
- config->srm = srm;
- return;
- }
-
- enable = (srm == G_OBEX_SRM_ENABLE);
- if (config->enabled == enable)
- goto done;
-
- config->enabled = enable;
-
- g_obex_debug(G_OBEX_DEBUG_COMMAND, "SRM %s", config->enabled ?
- "Enabled" : "Disabled");
-
-done:
- if (config->enabled)
- return;
-
- g_free(obex->srm);
- obex->srm = NULL;
-}
-
-static void setup_srm(GObex *obex, GObexPacket *pkt, gboolean outgoing)
-{
- GObexHeader *hdr;
- guint8 op;
- gboolean final;
-
- if (!obex->use_srm)
- return;
-
- op = g_obex_packet_get_operation(pkt, &final);
-
- hdr = g_obex_packet_get_header(pkt, G_OBEX_HDR_SRM);
- if (hdr != NULL) {
- guint8 srm;
- g_obex_header_get_uint8(hdr, &srm);
- g_obex_debug(G_OBEX_DEBUG_COMMAND, "srm 0x%02x", srm);
- set_srm(obex, op, srm);
- }
-
- hdr = g_obex_packet_get_header(pkt, G_OBEX_HDR_SRMP);
- if (hdr != NULL) {
- guint8 srmp;
- g_obex_header_get_uint8(hdr, &srmp);
- g_obex_debug(G_OBEX_DEBUG_COMMAND, "srmp 0x%02x", srmp);
- set_srmp(obex, srmp, outgoing);
- } else
- set_srmp(obex, -1, outgoing);
-
- if (obex->srm == NULL || !obex->srm->enabled || !final)
- return;
-
- switch (obex->srm->op) {
- case G_OBEX_OP_CONNECT:
- return;
- default:
- if (op <= G_OBEX_RSP_CONTINUE)
- return;
- }
-
- set_srm(obex, op, G_OBEX_SRM_DISABLE);
-}
-
static void prepare_srm_rsp(GObex *obex, GObexPacket *pkt)
{
GObexHeader *hdr;
switch (obex->rx_last_op) {
case G_OBEX_OP_CONNECT:
prepare_connect_rsp(obex, pkt);
+ break;
case G_OBEX_OP_GET:
case G_OBEX_OP_PUT:
prepare_srm_rsp(obex, pkt);
break;
}
- setup_srm(obex, pkt, TRUE);
-
p = g_new0(struct pending_pkt, 1);
p->pkt = pkt;
prepare_srm_req(obex, req);
}
- setup_srm(obex, req, TRUE);
-
if (obex->conn_id == CONNID_INVALID)
goto create_pending;
return (p->id - id);
}
-static gboolean pending_req_abort(GObex *obex, GError **err)
+gboolean g_obex_pending_req_abort(GObex *obex, GError **err)
{
struct pending_pkt *p = obex->pending_req;
GObexPacket *req;
struct pending_pkt *p;
if (obex->pending_req && obex->pending_req->id == req_id) {
- if (!pending_req_abort(obex, NULL)) {
+ if (!g_obex_pending_req_abort(obex, NULL)) {
p = obex->pending_req;
obex->pending_req = NULL;
goto immediate_completion;
}
+ if (remove_callback)
+ obex->pending_req->rsp_func = NULL;
+
return TRUE;
}
{
gboolean ret = FALSE;
+ if (!obex->use_srm)
+ return FALSE;
+
if (obex->srm == NULL || !obex->srm->enabled)
goto done;
} else {
opcode = obex->rx_last_op;
/* Unexpected response -- fail silently */
-#ifdef TIZEN_PATCH
if (opcode > 0x1f && opcode != G_OBEX_OP_ABORT) {
-#else
- if (opcode > 0x1f && opcode < 0xff) {
-#endif
obex->rx_data = 0;
return TRUE;
}
void g_obex_unref(GObex *obex)
{
-#ifdef TIZEN_PATCH
- gboolean last_ref, ret;
-#else
gboolean last_ref;
-#endif
last_ref = g_atomic_int_dec_and_test(&obex->ref_count);
g_slist_free_full(obex->req_handlers, g_free);
-#ifdef TIZEN_PATCH
- do {
- ret = write_data(obex->io, G_IO_OUT, obex);
- if (obex->pending_req && obex->pending_req->cancelled)
- break;
- } while(ret);
-#endif
-
g_queue_foreach(obex->tx_queue, (GFunc) pending_pkt_free, NULL);
g_queue_free(obex->tx_queue);
return g_obex_send_req(obex, req, -1, func, user_data, err);
}
+
+guint8 g_obex_errno_to_rsp(int err)
+{
+ switch (err) {
+ case 0:
+ return G_OBEX_RSP_SUCCESS;
+ case -EPERM:
+ case -EACCES:
+ return G_OBEX_RSP_FORBIDDEN;
+ case -ENOENT:
+ return G_OBEX_RSP_NOT_FOUND;
+ case -EINVAL:
+ case -EBADR:
+ return G_OBEX_RSP_BAD_REQUEST;
+ case -EFAULT:
+ return G_OBEX_RSP_SERVICE_UNAVAILABLE;
+ case -ENOSYS:
+ return G_OBEX_RSP_NOT_IMPLEMENTED;
+ case -ENOTEMPTY:
+ case -EEXIST:
+ return G_OBEX_RSP_PRECONDITION_FAILED;
+ default:
+ return G_OBEX_RSP_INTERNAL_SERVER_ERROR;
+ }
+}