Change in osmo-msc[master]: libmsc/db.c: introduce and use parse_sm_ud_from_result()

Vadim Yanitskiy gerrit-no-reply at lists.osmocom.org
Tue Apr 2 11:32:01 UTC 2019


Vadim Yanitskiy has uploaded this change for review. ( https://gerrit.osmocom.org/13488


Change subject: libmsc/db.c: introduce and use parse_sm_ud_from_result()
......................................................................

libmsc/db.c: introduce and use parse_sm_ud_from_result()

The following functions:

  - sms_from_result(),
  - sms_from_result_v3(),
  - sms_from_result_v4(),

do retrieve the TP-UD, TP-UDL and text in the same way,
so let's avoid code duplication.

Change-Id: If67dfb9f7d2a55fa3d45dc4689a2acff9909faf6
---
M src/libmsc/db.c
1 file changed, 35 insertions(+), 48 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-msc refs/changes/88/13488/1

diff --git a/src/libmsc/db.c b/src/libmsc/db.c
index ae9b114..bf57ec8 100644
--- a/src/libmsc/db.c
+++ b/src/libmsc/db.c
@@ -225,6 +225,32 @@
 	return 0;
 }
 
+static void parse_tp_ud_from_result(struct gsm_sms *sms, dbi_result result)
+{
+	const unsigned char *user_data;
+	unsigned int user_data_len;
+	const char *text;
+
+	/* Retrieve TP-UDL (User-Data-Length) in octets (regardless of DCS) */
+	user_data_len = dbi_result_get_field_length(result, "user_data");
+	if (user_data_len > sizeof(sms->user_data)) {
+		LOGP(DDB, LOGL_ERROR,
+		     "SMS TP-UD length %u is too big, truncating to %zu\n",
+		     user_data_len, sizeof(sms->user_data));
+		user_data_len = (uint8_t) sizeof(sms->user_data);
+	}
+	sms->user_data_len = user_data_len;
+
+	/* Retrieve the TP-UD (User-Data) itself */
+	user_data = dbi_result_get_binary(result, "user_data");
+	memcpy(sms->user_data, user_data, user_data_len);
+
+	/* Retrieve the text parsed from TP-UD (User-Data) */
+	text = dbi_result_get_string(result, "text");
+	if (text)
+		OSMO_STRLCPY_ARRAY(sms->text, text);
+}
+
 /**
  * Copied from the normal sms_from_result_v3 to avoid having
  * to make sure that the real routine will remain backward
@@ -234,9 +260,7 @@
 {
 	struct gsm_sms *sms = sms_alloc();
 	long long unsigned int sender_id;
-	const char *text, *daddr;
-	const unsigned char *user_data;
-	unsigned int user_data_len;
+	const char *daddr;
 	char buf[32];
 	char *quoted;
 	dbi_result result2;
@@ -274,20 +298,9 @@
 	if (daddr)
 		OSMO_STRLCPY_ARRAY(sms->dst.addr, daddr);
 
-	user_data_len = dbi_result_get_field_length(result, "user_data");
-	user_data = dbi_result_get_binary(result, "user_data");
-	if (user_data_len > sizeof(sms->user_data)) {
-		LOGP(DDB, LOGL_ERROR,
-		     "SMS TP-UD length %u is too big, truncating to %zu\n",
-		     user_data_len, sizeof(sms->user_data));
-		user_data_len = (uint8_t) sizeof(sms->user_data);
-	}
-	sms->user_data_len = user_data_len;
-	memcpy(sms->user_data, user_data, sms->user_data_len);
+	/* Parse TP-UD, TP-UDL and decoded text */
+	parse_tp_ud_from_result(sms, result);
 
-	text = dbi_result_get_string(result, "text");
-	if (text)
-		OSMO_STRLCPY_ARRAY(sms->text, text);
 	return sms;
 }
 
@@ -400,9 +413,7 @@
 static struct gsm_sms *sms_from_result_v4(dbi_result result)
 {
 	struct gsm_sms *sms = sms_alloc();
-	const unsigned char *user_data;
-	unsigned int user_data_len;
-	const char *text, *addr;
+	const char *addr;
 
 	if (!sms)
 		return NULL;
@@ -426,20 +437,9 @@
 	sms->dst.ton = dbi_result_get_ulonglong(result, "dest_ton");
 	sms->dst.npi = dbi_result_get_ulonglong(result, "dest_npi");
 
-	user_data_len = dbi_result_get_field_length(result, "user_data");
-	user_data = dbi_result_get_binary(result, "user_data");
-	if (user_data_len > sizeof(sms->user_data)) {
-		LOGP(DDB, LOGL_ERROR,
-		     "SMS TP-UD length %u is too big, truncating to %zu\n",
-		     user_data_len, sizeof(sms->user_data));
-		user_data_len = (uint8_t) sizeof(sms->user_data);
-	}
-	sms->user_data_len = user_data_len;
-	memcpy(sms->user_data, user_data, sms->user_data_len);
+	/* Parse TP-UD, TP-UDL and decoded text */
+	parse_tp_ud_from_result(sms, result);
 
-	text = dbi_result_get_string(result, "text");
-	if (text)
-		OSMO_STRLCPY_ARRAY(sms->text, text);
 	return sms;
 }
 
@@ -754,9 +754,7 @@
 static struct gsm_sms *sms_from_result(struct gsm_network *net, dbi_result result)
 {
 	struct gsm_sms *sms = sms_alloc();
-	const char *text, *daddr, *saddr;
-	const unsigned char *user_data;
-	unsigned int user_data_len;
+	const char *daddr, *saddr;
 	time_t validity_timestamp;
 
 	if (!sms)
@@ -790,20 +788,9 @@
 	if (saddr)
 		OSMO_STRLCPY_ARRAY(sms->src.addr, saddr);
 
-	user_data_len = dbi_result_get_field_length(result, "user_data");
-	user_data = dbi_result_get_binary(result, "user_data");
-	if (user_data_len > sizeof(sms->user_data)) {
-		LOGP(DDB, LOGL_ERROR,
-		     "SMS TP-UD length %u is too big, truncating to %zu\n",
-		     user_data_len, sizeof(sms->user_data));
-		user_data_len = (uint8_t) sizeof(sms->user_data);
-	}
-	sms->user_data_len = user_data_len;
-	memcpy(sms->user_data, user_data, sms->user_data_len);
+	/* Parse TP-UD, TP-UDL and decoded text */
+	parse_tp_ud_from_result(sms, result);
 
-	text = dbi_result_get_string(result, "text");
-	if (text)
-		OSMO_STRLCPY_ARRAY(sms->text, text);
 	return sms;
 }
 

-- 
To view, visit https://gerrit.osmocom.org/13488
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-msc
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: If67dfb9f7d2a55fa3d45dc4689a2acff9909faf6
Gerrit-Change-Number: 13488
Gerrit-PatchSet: 1
Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190402/3a320058/attachment.html>


More information about the gerrit-log mailing list