From: Jens Rehsack <jr_extern@vfnet.de>
To: ofono@ofono.org
Subject: Re: [PATCH] Add WSP_VALUE_TYPE_TEXT support in wsp_decode_application_id()
Date: Wed, 30 May 2012 09:11:37 +0200 [thread overview]
Message-ID: <4FC5C829.1040900@vfnet.de> (raw)
In-Reply-To: <4FBB49C5.70508@vfnet.de>
[-- Attachment #1: Type: text/plain, Size: 5302 bytes --]
On 22.05.2012 10:09, Jens Rehsack wrote:
> On 21.05.2012 18:23, Ronald Tessier wrote:
>> Hi Jens,
>>
>> On 05/21/2012 12:54 PM, Jens Rehsack wrote:
>>> From: Jens Rehsack<sno@NetBSD.org>
>>>
>>> ---
>>> src/wsputil.c | 43 ++++++++++++++++++++++++++-----------------
>>> 1 Datei geändert, 26 Zeilen hinzugefügt(+), 17 Zeilen entfernt(-)
>>>
>>> diff --git a/src/wsputil.c b/src/wsputil.c
>>> index 1b2b2b7..5611ed2 100644
>>> --- a/src/wsputil.c
>>> +++ b/src/wsputil.c
>>> @@ -486,28 +486,37 @@ gboolean wsp_decode_application_id(struct
>>> wsp_header_iter *iter,
>>> const void **out_value)
>>> {
>>> const unsigned char *pdu_val = wsp_header_iter_get_val(iter);
>>> - unsigned int val;
>>> - unsigned int val_len;
>>> - unsigned int i;
>>>
>>> - /*
>>> - * Well-known field values MUST be encoded using the
>>> - * compact binary formats
>>> - */
>>> - if (wsp_header_iter_get_val_type(iter) == WSP_VALUE_TYPE_SHORT) {
>>> - val = *pdu_val& 0x7f;
>>> + if (wsp_header_iter_get_val_type(iter) == WSP_VALUE_TYPE_TEXT) {
>>> + wsp_header_iter_get_val_len(iter);
>>> +
>>> + if (out_value)
>>> + *out_value = pdu_val;
>>
>> Why not just returning if the type is TEXT ?
>> Something like :
>>
>> const unsigned char *pdu_val = wsp_header_iter_get_val(iter);
>> unsigned int val;
>> unsigned int val_len;
>> unsigned int i;
>>
>> + if (wsp_header_iter_get_val_type(iter) == WSP_VALUE_TYPE_TEXT) {
>> + if (out_value)
>> + *out_value = pdu_val;
>> +
>> + return TRUE;
>> + }
>> +
>> /*
>> * Well-known field values MUST be encoded using the
>> * compact binary formats
>> */
>> if (wsp_header_iter_get_val_type(iter) == WSP_VALUE_TYPE_SHORT) {
>>
>
> I do not like several returns in a longer subroutine. The way
> you format code makes code longer - fair enough, but for me to
> long to introduce early return statements.
>
>> I think it does the same thing but more readable (you don't break the 80
>> col. limit).
>
> I'm fine with your way to do it, too. But I wouldn't want my name being
> assigned with it (because of the early return ...). I strongly
> distinguish between readable and understandable, and I prefer the
> understandable way.
>
> How about:
>
> diff --git a/src/wsputil.c b/src/wsputil.c
> index 1b2b2b7..385acaa 100644
> --- a/src/wsputil.c
> +++ b/src/wsputil.c
> @@ -490,13 +490,26 @@ gboolean wsp_decode_application_id(struct
> wsp_header_iter *iter,
> unsigned int val_len;
> unsigned int i;
>
> + switch (wsp_header_iter_get_val_type(iter)) {
> + case WSP_VALUE_TYPE_TEXT:
> + if (out_value)
> + *out_value = pdu_val;
> +
> + break;
> +
> /*
> * Well-known field values MUST be encoded using the
> * compact binary formats
> */
> - if (wsp_header_iter_get_val_type(iter) == WSP_VALUE_TYPE_SHORT) {
> + case WSP_VALUE_TYPE_SHORT:
> val = *pdu_val & 0x7f;
> - } else {
> +
> + if (out_value)
> + *out_value = get_text_entry(val, app_id);
> +
> + break;
> +
> + default:
> val_len = wsp_header_iter_get_val_len(iter);
>
> if (val_len > 2)
> @@ -504,10 +517,13 @@ gboolean wsp_decode_application_id(struct
> wsp_header_iter *iter,
>
> for (i = 0, val = 0; i < val_len && i < sizeof(val); i++)
> val = (val << 8) | pdu_val[i];
> +
> + if (out_value)
> + *out_value = get_text_entry(val, app_id);
> +
> + break;
> }
>
> - if (out_value)
> - *out_value = get_text_entry(val, app_id);
>
> return TRUE;
> }
>
>
>> Best regards,
>>
>> Ronald
>
> Best regards,
> Jens
>
>>> } else {
>>> - val_len = wsp_header_iter_get_val_len(iter);
>>> + unsigned int val;
>>>
>>> - if (val_len> 2)
>>> - return FALSE;
>>> + /*
>>> + * Well-known field values MUST be encoded using the
>>> + * compact binary formats
>>> + */
>>> + if (wsp_header_iter_get_val_type(iter) ==
>>> WSP_VALUE_TYPE_SHORT) {
>>> + val = *pdu_val& 0x7f;
>>> + } else {
>>> + unsigned int val_len;
>>> + unsigned int i;
>>>
>>> - for (i = 0, val = 0; i< val_len&& i< sizeof(val); i++)
>>> - val = (val<< 8) | pdu_val[i];
>>> - }
>>> + val_len = wsp_header_iter_get_val_len(iter);
>>>
>>> - if (out_value)
>>> - *out_value = get_text_entry(val, app_id);
>>> + if (val_len> 2)
>>> + return FALSE;
>>> +
>>> + for (i = 0, val = 0; i< val_len&& i< sizeof(val); i++)
>>> + val = (val<< 8) | pdu_val[i];
>>> + }
>>> +
>>> + if (out_value)
>>> + *out_value = get_text_entry(val, app_id);
>>> + }
>>>
>>> return TRUE;
>>> }
What's the state?
/Jens
next prev parent reply other threads:[~2012-05-30 7:11 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-21 10:54 [PATCH] Add WSP_VALUE_TYPE_TEXT support in wsp_decode_application_id() Jens Rehsack
2012-05-21 16:23 ` Ronald Tessier
2012-05-22 8:09 ` Jens Rehsack
2012-05-30 7:11 ` Jens Rehsack [this message]
-- strict thread matches above, loose matches on Subject: below --
2012-05-30 8:59 Jens Rehsack
2012-05-30 13:49 ` Denis Kenzior
2012-05-16 14:03 Jens Rehsack
2012-05-16 15:45 ` Ronald Tessier
2012-05-16 16:18 ` Jens Rehsack
2012-05-18 12:59 ` Ronald Tessier
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=4FC5C829.1040900@vfnet.de \
--to=jr_extern@vfnet.de \
--cc=ofono@ofono.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox