gobex: Translate posix error code to proper OBEX response opcode

This patch create a map between posix errors code and OBEX response
opcode and use it to generate a proper response in case a transfer
failed instead of always responding with internal error.
This commit is contained in:
Luiz Augusto von Dentz 2012-02-18 17:18:57 +02:00 committed by Marcel Holtmann
parent 9e1e47425e
commit faac92a4cb
3 changed files with 29 additions and 2 deletions

View File

@ -501,6 +501,7 @@ static gssize get_get_data(void *buf, gsize len, gpointer user_data)
GObexPacket *req, *rsp;
GError *err = NULL;
gssize ret;
guint8 op;
g_obex_debug(G_OBEX_DEBUG_TRANSFER, "transfer %u", transfer->id);
@ -530,8 +531,9 @@ static gssize get_get_data(void *buf, gsize len, gpointer user_data)
return ret;
}
req = g_obex_packet_new(G_OBEX_RSP_INTERNAL_SERVER_ERROR, TRUE,
G_OBEX_HDR_INVALID);
op = g_obex_errno_to_rsp(ret);
req = g_obex_packet_new(op, TRUE, G_OBEX_HDR_INVALID);
g_obex_send(transfer->obex, req, NULL);
err = g_error_new(G_OBEX_ERROR, G_OBEX_ERROR_CANCELLED,

View File

@ -1471,3 +1471,27 @@ guint g_obex_move(GObex *obex, const char *name, const char *dest,
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 -EBADR:
return G_OBEX_RSP_BAD_REQUEST;
case -EFAULT:
return G_OBEX_RSP_SERVICE_UNAVAILABLE;
case -EINVAL:
return G_OBEX_RSP_NOT_IMPLEMENTED;
case -ENOTEMPTY:
case -EEXIST:
return G_OBEX_RSP_PRECONDITION_FAILED;
default:
return G_OBEX_RSP_INTERNAL_SERVER_ERROR;
}
}

View File

@ -125,5 +125,6 @@ guint g_obex_get_rsp_pkt(GObex *obex, GObexPacket *rsp,
gboolean g_obex_cancel_transfer(guint id);
const char *g_obex_strerror(guint8 err_code);
guint8 g_obex_errno_to_rsp(int err);
#endif /* __GOBEX_H */