From: Johan Hedberg <johan.hedberg@gmail.com>
To: Bartosz Szatkowski <bulislaw@linux.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCHv2 obexd 3/4] Add response handling for MAP client
Date: Fri, 2 Dec 2011 16:37:13 +0200 [thread overview]
Message-ID: <20111202143713.GA24812@x220> (raw)
In-Reply-To: <1322829142-7855-3-git-send-email-bulislaw@linux.com>
Hi Bartosz,
On Fri, Dec 02, 2011, Bartosz Szatkowski wrote:
> +static struct error_code {
> + const char *name;
> + guint8 code;
> +} map_errors[] = {
> + {"Success", G_OBEX_RSP_SUCCESS},
> + {"Bad Request", G_OBEX_RSP_BAD_REQUEST},
> + {"Not Implemented", G_OBEX_RSP_NOT_IMPLEMENTED},
> + {"Service Unavailable", G_OBEX_RSP_SERVICE_UNAVAILABLE},
> + {"Forbidden", G_OBEX_RSP_FORBIDDEN},
> + {"Unauthorized", G_OBEX_RSP_UNAUTHORIZED},
> + {"Precondition Failed", G_OBEX_RSP_PRECONDITION_FAILED},
> + {"Not Acceptable", G_OBEX_RSP_NOT_ACCEPTABLE},
> + {"Not Found", G_OBEX_RSP_NOT_FOUND},
> + { }
The table is missing spaces on each line after { and before }
> +static const char *get_error_string(guint8 err_code)
> +{
> + struct error_code *error;
> +
> + for (error = map_errors; error != NULL; error++)
> + if (error->code == err_code)
> + return error->name;
> +
> + return NULL;
> +}
It'd probably make sense to make this kind of function more widely
available, maybe through gobex. However instead of a NULL return I'd
return "<unknown>" to avoid passing NULL pointers to %s format
specifiers like you're doing below (I know this will typically just work
and add a "(null)" to the string, but it's still not a very good
practice and can cause misleading logs:
> + reply = g_dbus_create_error(map->msg,
> + "org.openobex.Error.Response",
> + "%s(0x%X)", get_error_string(err_code),
> + err_code);
You're also missing a space between %s and ( and please use 0x%02x for
single byte values.
Johan
next prev parent reply other threads:[~2011-12-02 14:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-02 12:32 [PATCHv2 obexd 1/4] Add basic support for MAP client in obex-client Bartosz Szatkowski
2011-12-02 12:32 ` [PATCHv2 obexd 2/4] Add support for SetFolder in MAP client Bartosz Szatkowski
2011-12-02 12:32 ` [PATCHv2 obexd 3/4] Add response handling for " Bartosz Szatkowski
2011-12-02 14:37 ` Johan Hedberg [this message]
2011-12-02 14:43 ` Bartosz Szatkowski
2011-12-02 12:32 ` [PATCHv2 obexd 4/4] Add simple helper " Bartosz Szatkowski
2011-12-02 14:38 ` Johan Hedberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20111202143713.GA24812@x220 \
--to=johan.hedberg@gmail.com \
--cc=bulislaw@linux.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.