Open Source Telephony
 help / color / mirror / Atom feed
* [PATCH v4 1/3] smsutil: Fix style issues
@ 2012-08-31 15:03 Philippe Nunes
  2012-08-31 15:03 ` [PATCH v4 2/3] smsutil: <CR> is not necessarily a CBS padding character Philippe Nunes
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Philippe Nunes @ 2012-08-31 15:03 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 3727 bytes --]

---
 src/smsutil.c |   28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/src/smsutil.c b/src/smsutil.c
index a541964..b4d129f 100644
--- a/src/smsutil.c
+++ b/src/smsutil.c
@@ -81,11 +81,11 @@ void extract_bcd_number(const unsigned char *buf, int len, char *out)
 	for (i = 0; i < len; i++) {
 		oct = buf[i];
 
-		out[i*2] = digit_lut[oct & 0x0f];
-		out[i*2+1] = digit_lut[(oct & 0xf0) >> 4];
+		out[i * 2] = digit_lut[oct & 0x0f];
+		out[i * 2 + 1] = digit_lut[(oct & 0xf0) >> 4];
 	}
 
-	out[i*2] = '\0';
+	out[i * 2] = '\0';
 }
 
 static inline int to_semi_oct(char in)
@@ -600,7 +600,7 @@ gboolean sms_encode_address_field(const struct sms_address *in, gboolean sc,
 out:
 	pdu[0] = addr_len;
 	pdu[1] = (in->number_type << 4) | in->numbering_plan | 0x80;
-	memcpy(pdu+2, p, (sc ? addr_len - 1 : (addr_len + 1) / 2));
+	memcpy(pdu + 2, p, (sc ? addr_len - 1 : (addr_len + 1) / 2));
 
 	*offset = *offset + 2 + (sc ? addr_len - 1 : (addr_len + 1) / 2);
 
@@ -768,7 +768,7 @@ static gboolean decode_deliver(const unsigned char *pdu, int len,
 	if ((len - offset) < expected)
 		return FALSE;
 
-	memcpy(out->deliver.ud, pdu+offset, expected);
+	memcpy(out->deliver.ud, pdu + offset, expected);
 
 	return TRUE;
 }
@@ -929,11 +929,11 @@ static gboolean decode_submit_report(const unsigned char *pdu, int len,
 		if (out->type == SMS_TYPE_SUBMIT_REPORT_ERROR) {
 			out->submit_err_report.udl = udl;
 			memcpy(out->submit_err_report.ud,
-					pdu+offset, expected);
+					pdu + offset, expected);
 		} else {
 			out->submit_ack_report.udl = udl;
 			memcpy(out->submit_ack_report.ud,
-					pdu+offset, expected);
+					pdu + offset, expected);
 		}
 	}
 
@@ -1063,7 +1063,7 @@ static gboolean decode_status_report(const unsigned char *pdu, int len,
 		if ((len - offset) < expected)
 			return FALSE;
 
-		memcpy(out->status_report.ud, pdu+offset, expected);
+		memcpy(out->status_report.ud, pdu + offset, expected);
 	}
 
 	return TRUE;
@@ -1214,11 +1214,11 @@ static gboolean decode_deliver_report(const unsigned char *pdu, int len,
 		if (out->type == SMS_TYPE_DELIVER_REPORT_ERROR) {
 			out->deliver_err_report.udl = udl;
 			memcpy(out->deliver_err_report.ud,
-					pdu+offset, expected);
+					pdu + offset, expected);
 		} else {
 			out->deliver_ack_report.udl = udl;
 			memcpy(out->deliver_ack_report.ud,
-					pdu+offset, expected);
+					pdu + offset, expected);
 		}
 	}
 
@@ -1371,7 +1371,7 @@ static gboolean decode_submit(const unsigned char *pdu, int len,
 	if (expected > (int) sizeof(out->submit.ud))
 		return FALSE;
 
-	memcpy(out->submit.ud, pdu+offset, expected);
+	memcpy(out->submit.ud, pdu + offset, expected);
 
 	return TRUE;
 }
@@ -1450,7 +1450,7 @@ static gboolean decode_command(const unsigned char *pdu, int len,
 	if ((len - offset) < out->command.cdl)
 		return FALSE;
 
-	memcpy(out->command.cd, pdu+offset, out->command.cdl);
+	memcpy(out->command.cd, pdu + offset, out->command.cdl);
 
 	return TRUE;
 }
@@ -1866,7 +1866,7 @@ void sms_address_from_string(struct sms_address *addr, const char *str)
 	addr->numbering_plan = SMS_NUMBERING_PLAN_ISDN;
 	if (str[0] == '+') {
 		addr->number_type = SMS_NUMBER_TYPE_INTERNATIONAL;
-		strcpy(addr->address, str+1);
+		strcpy(addr->address, str + 1);
 	} else {
 		addr->number_type = SMS_NUMBER_TYPE_UNKNOWN;
 		strcpy(addr->address, str);
@@ -4139,7 +4139,7 @@ char *cbs_decode_text(GSList *cbs_list, char *iso639_lang)
 					break;
 
 				buf[bufsize] = ud[i];
-				buf[bufsize + 1] = ud[i+1];
+				buf[bufsize + 1] = ud[i + 1];
 
 				bufsize += 2;
 				i += 2;
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v4 2/3] smsutil: <CR> is not necessarily a CBS padding character
  2012-08-31 15:03 [PATCH v4 1/3] smsutil: Fix style issues Philippe Nunes
@ 2012-08-31 15:03 ` Philippe Nunes
  2012-09-17 16:58   ` Denis Kenzior
  2012-08-31 15:03 ` [PATCH v4 3/3] unit: Add test to check " Philippe Nunes
  2012-09-17 16:57 ` [PATCH v4 1/3] smsutil: Fix style issues Denis Kenzior
  2 siblings, 1 reply; 6+ messages in thread
From: Philippe Nunes @ 2012-08-31 15:03 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1776 bytes --]

---
 src/smsutil.c |   36 +++++++++++++++++++++++++++++-------
 1 file changed, 29 insertions(+), 7 deletions(-)

diff --git a/src/smsutil.c b/src/smsutil.c
index b4d129f..7569c63 100644
--- a/src/smsutil.c
+++ b/src/smsutil.c
@@ -4090,7 +4090,7 @@ char *cbs_decode_text(GSList *cbs_list, char *iso639_lang)
 			unsigned char unpacked[CBS_MAX_GSM_CHARS];
 			long written;
 			int max_chars;
-			int i;
+			int i, j;
 
 			max_chars =
 				sms_text_capacity_gsm(CBS_MAX_GSM_CHARS, taken);
@@ -4102,12 +4102,24 @@ char *cbs_decode_text(GSList *cbs_list, char *iso639_lang)
 			i = iso639 ? 3 : 0;
 
 			/*
-			 * CR is a padding character, which means we can
-			 * safely discard everything afterwards
+			 * CR can be used as a padding character, which means
+			 * we can safely discard everything afterwards
 			 */
+
 			for (; i < written; i++, bufsize++) {
-				if (unpacked[i] == '\r')
-					break;
+				if (unpacked[i] == '\r') {
+					/*
+					 * check if this is a padding character
+					 * or if it is a wanted <CR>
+					 */
+					for (j = i + 1; j < written; j++)
+						if (unpacked[j] != '\r')
+							break;
+
+					if (j == written)
+						break;
+				}
+
 
 				buf[bufsize] = unpacked[i];
 			}
@@ -4135,8 +4147,18 @@ char *cbs_decode_text(GSList *cbs_list, char *iso639_lang)
 			}
 
 			while (i < max_offset) {
-				if (ud[i] == 0x00 && ud[i+1] == '\r')
-					break;
+				if (ud[i] == 0x00 && ud[i+1] == '\r') {
+					int j = i + 2;
+
+					for (; j < max_offset; j = j + 2)
+						if (ud[j] != 0x00 ||
+								ud[j + 1] !=
+									'\r')
+							break;
+
+					if (j == max_offset)
+						break;
+				}
 
 				buf[bufsize] = ud[i];
 				buf[bufsize + 1] = ud[i + 1];
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v4 3/3] unit: Add test to check CBS padding character
  2012-08-31 15:03 [PATCH v4 1/3] smsutil: Fix style issues Philippe Nunes
  2012-08-31 15:03 ` [PATCH v4 2/3] smsutil: <CR> is not necessarily a CBS padding character Philippe Nunes
@ 2012-08-31 15:03 ` Philippe Nunes
  2012-09-17 16:58   ` Denis Kenzior
  2012-09-17 16:57 ` [PATCH v4 1/3] smsutil: Fix style issues Denis Kenzior
  2 siblings, 1 reply; 6+ messages in thread
From: Philippe Nunes @ 2012-08-31 15:03 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2880 bytes --]

From: Guillaume Zajac <guillaume.zajac@linux.intel.com>

This CBS unit test is used to check that the <CR> character can
be interpreted as a wanted carriage return and not necessarily
as a padding character.
---
 unit/test-sms.c |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/unit/test-sms.c b/unit/test-sms.c
index e510554..31e18f8 100644
--- a/unit/test-sms.c
+++ b/unit/test-sms.c
@@ -1236,6 +1236,10 @@ static const char *cbs2 = "0110003201114679785E96371A8D46A3D168341A8D46A3D1683"
 	"41A8D46A3D168341A8D46A3D168341A8D46A3D168341A8D46A3D168341A8D46A3D168"
 	"341A8D46A3D168341A8D46A3D168341A8D46A3D168341A8D46A3D100";
 
+static const char *cbs3 = "001000000111E280604028180E888462C168381E90886442A95"
+	"82E988C66C3E9783EA09068442A994EA8946AC56AB95EB0986C46ABD96EB89C6EC7EBF"
+	"97EC0A070482C1A8FC8A472C96C3A9FD0A8744AAD5AAFD8AC76CB05";
+
 static void test_cbs_encode_decode(void)
 {
 	unsigned char *decoded_pdu;
@@ -1389,6 +1393,58 @@ static void test_cbs_assembly(void)
 	cbs_assembly_free(assembly);
 }
 
+static void test_cbs_padding_character(void)
+{
+	unsigned char *decoded_pdu;
+	long pdu_len;
+	gboolean ret;
+	struct cbs cbs;
+	GSList *l;
+	char iso639_lang[3];
+	char *utf8;
+
+	decoded_pdu = decode_hex(cbs3, -1, &pdu_len, 0);
+
+	g_assert(decoded_pdu);
+	g_assert(pdu_len == 88);
+
+	ret = cbs_decode(decoded_pdu, pdu_len, &cbs);
+
+	g_free(decoded_pdu);
+
+	g_assert(ret);
+
+	g_assert(cbs.gs == CBS_GEO_SCOPE_CELL_IMMEDIATE);
+	g_assert(cbs.message_code == 1);
+	g_assert(cbs.update_number == 0);
+	g_assert(cbs.message_identifier == 0);
+	g_assert(cbs.dcs == 1);
+	g_assert(cbs.max_pages == 1);
+	g_assert(cbs.page == 1);
+
+	l = g_slist_append(NULL, &cbs);
+
+	utf8 = cbs_decode_text(l, iso639_lang);
+
+	g_assert(utf8);
+
+	if (g_test_verbose()) {
+		g_printf("%s\n", utf8);
+		if (iso639_lang[0] == '\0')
+			g_printf("Lang: Unspecified\n");
+		else
+			g_printf("Lang: %s\n", iso639_lang);
+	}
+
+	g_assert(strcmp(utf8, "b£$¥èéùìòÇ\x0AØø\x0DÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ !\"#¤"
+				"\x25&'()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLM"
+				"NOPQRSTUVWXYZÄÖ") == 0);
+	g_assert(strcmp(iso639_lang, "en") == 0);
+
+	g_free(utf8);
+	g_slist_free(l);
+}
+
 static const char *ranges[] = { "1-5, 2, 3, 600, 569-900, 999",
 				"0-20, 33, 44, 50-60, 20-50, 1-5, 5, 3, 5",
 				NULL };
@@ -1679,6 +1735,9 @@ int main(int argc, char **argv)
 			test_cbs_encode_decode);
 	g_test_add_func("/testsms/Test CBS Assembly", test_cbs_assembly);
 
+	g_test_add_func("/testsms/Test CBS Padding Character",
+			test_cbs_padding_character);
+
 	g_test_add_func("/testsms/Range minimizer", test_range_minimizer);
 
 	g_test_add_func("/testsms/Status Report Assembly", test_sr_assembly);
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v4 1/3] smsutil: Fix style issues
  2012-08-31 15:03 [PATCH v4 1/3] smsutil: Fix style issues Philippe Nunes
  2012-08-31 15:03 ` [PATCH v4 2/3] smsutil: <CR> is not necessarily a CBS padding character Philippe Nunes
  2012-08-31 15:03 ` [PATCH v4 3/3] unit: Add test to check " Philippe Nunes
@ 2012-09-17 16:57 ` Denis Kenzior
  2 siblings, 0 replies; 6+ messages in thread
From: Denis Kenzior @ 2012-09-17 16:57 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 240 bytes --]

Hi Philippe,

On 08/31/2012 10:03 AM, Philippe Nunes wrote:
> ---
>   src/smsutil.c |   28 ++++++++++++++--------------
>   1 file changed, 14 insertions(+), 14 deletions(-)
>

Patch has been applied, thanks.

Regards,
-Denis


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v4 2/3] smsutil: <CR> is not necessarily a CBS padding character
  2012-08-31 15:03 ` [PATCH v4 2/3] smsutil: <CR> is not necessarily a CBS padding character Philippe Nunes
@ 2012-09-17 16:58   ` Denis Kenzior
  0 siblings, 0 replies; 6+ messages in thread
From: Denis Kenzior @ 2012-09-17 16:58 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2099 bytes --]

Hi Philippe,

On 08/31/2012 10:03 AM, Philippe Nunes wrote:
> ---
>   src/smsutil.c |   36 +++++++++++++++++++++++++++++-------
>   1 file changed, 29 insertions(+), 7 deletions(-)
>
> diff --git a/src/smsutil.c b/src/smsutil.c
> index b4d129f..7569c63 100644
> --- a/src/smsutil.c
> +++ b/src/smsutil.c
> @@ -4090,7 +4090,7 @@ char *cbs_decode_text(GSList *cbs_list, char *iso639_lang)
>   			unsigned char unpacked[CBS_MAX_GSM_CHARS];
>   			long written;
>   			int max_chars;
> -			int i;
> +			int i, j;
>
>   			max_chars =
>   				sms_text_capacity_gsm(CBS_MAX_GSM_CHARS, taken);
> @@ -4102,12 +4102,24 @@ char *cbs_decode_text(GSList *cbs_list, char *iso639_lang)
>   			i = iso639 ? 3 : 0;
>
>   			/*
> -			 * CR is a padding character, which means we can
> -			 * safely discard everything afterwards
> +			 * CR can be used as a padding character, which means
> +			 * we can safely discard everything afterwards
>   			 */
> +
>   			for (; i<  written; i++, bufsize++) {
> -				if (unpacked[i] == '\r')
> -					break;
> +				if (unpacked[i] == '\r') {
> +					/*
> +					 * check if this is a padding character
> +					 * or if it is a wanted<CR>
> +					 */
> +					for (j = i + 1; j<  written; j++)
> +						if (unpacked[j] != '\r')
> +							break;
> +
> +					if (j == written)
> +						break;
> +				}
> +
>
>   				buf[bufsize] = unpacked[i];
>   			}

I skipped the first two chunks and fixed this slightly differently.

> @@ -4135,8 +4147,18 @@ char *cbs_decode_text(GSList *cbs_list, char *iso639_lang)
>   			}
>
>   			while (i<  max_offset) {
> -				if (ud[i] == 0x00&&  ud[i+1] == '\r')
> -					break;
> +				if (ud[i] == 0x00&&  ud[i+1] == '\r') {
> +					int j = i + 2;
> +
> +					for (; j<  max_offset; j = j + 2)
> +						if (ud[j] != 0x00 ||
> +								ud[j + 1] !=
> +									'\r')
> +							break;
> +
> +					if (j == max_offset)
> +						break;
> +				}
>
>   				buf[bufsize] = ud[i];
>   				buf[bufsize + 1] = ud[i + 1];

The last chunk has been applied, thanks.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v4 3/3] unit: Add test to check CBS padding character
  2012-08-31 15:03 ` [PATCH v4 3/3] unit: Add test to check " Philippe Nunes
@ 2012-09-17 16:58   ` Denis Kenzior
  0 siblings, 0 replies; 6+ messages in thread
From: Denis Kenzior @ 2012-09-17 16:58 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 505 bytes --]

Hi Philippe,

On 08/31/2012 10:03 AM, Philippe Nunes wrote:
> From: Guillaume Zajac<guillaume.zajac@linux.intel.com>
>
> This CBS unit test is used to check that the<CR>  character can
> be interpreted as a wanted carriage return and not necessarily
> as a padding character.
> ---
>   unit/test-sms.c |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 59 insertions(+)
>

Patch has been applied.  Do you have test data for the UCS2 case?

Regards,
-Denis

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-09-17 16:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-31 15:03 [PATCH v4 1/3] smsutil: Fix style issues Philippe Nunes
2012-08-31 15:03 ` [PATCH v4 2/3] smsutil: <CR> is not necessarily a CBS padding character Philippe Nunes
2012-09-17 16:58   ` Denis Kenzior
2012-08-31 15:03 ` [PATCH v4 3/3] unit: Add test to check " Philippe Nunes
2012-09-17 16:58   ` Denis Kenzior
2012-09-17 16:57 ` [PATCH v4 1/3] smsutil: Fix style issues Denis Kenzior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox