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


Change subject: gsupclient: add osmo_gsup_msg_enc_send() helper
......................................................................

gsupclient: add osmo_gsup_msg_enc_send() helper

This change introduces a helper for encoding and sending GSUP
messages using a given abstract 'osmo_gsup_message' structure.

Change-Id: I0589ff27933e9bca2bcf93b8259004935778db8f
---
M include/osmocom/gsupclient/gsup_client.h
M src/gsupclient/gsup_client.c
2 files changed, 38 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-hlr refs/changes/89/11989/1

diff --git a/include/osmocom/gsupclient/gsup_client.h 
b/include/osmocom/gsupclient/gsup_client.h
index 981751b..7a47f98 100644
--- a/include/osmocom/gsupclient/gsup_client.h
+++ b/include/osmocom/gsupclient/gsup_client.h
@@ -23,6 +23,7 @@

 #include <osmocom/core/timer.h>
 #include <osmocom/gsm/oap_client.h>
+#include <osmocom/gsm/gsup.h>

 /* a loss of GSUP between MSC and HLR is considered quite serious, let's try 
to recover as quickly as
  * possible.  Even one new connection attempt per second should be quite 
acceptable until the link is
@@ -61,5 +62,7 @@

 void osmo_gsup_client_destroy(struct osmo_gsup_client *gsupc);
 int osmo_gsup_client_send(struct osmo_gsup_client *gsupc, struct msgb *msg);
+int osmo_gsup_msg_enc_send(struct osmo_gsup_client *gsupc,
+                          struct osmo_gsup_message *gsup_msg);
 struct msgb *osmo_gsup_client_msgb_alloc(void);

diff --git a/src/gsupclient/gsup_client.c b/src/gsupclient/gsup_client.c
index d34a22d..d54aa37 100644
--- a/src/gsupclient/gsup_client.c
+++ b/src/gsupclient/gsup_client.c
@@ -339,6 +339,41 @@
        return 0;
 }

+/* Helper for encoding and sending GSUP messages */
+int osmo_gsup_msg_enc_send(struct osmo_gsup_client *gsupc,
+                          struct osmo_gsup_message *gsup_msg)
+{
+       struct msgb *gsup_msgb;
+       int rc;
+
+       /* Allocate GSUP message buffer */
+       gsup_msgb = osmo_gsup_client_msgb_alloc();
+       if (!gsup_msgb) {
+               LOGP(DLGSUP, LOGL_ERROR, "Couldn't allocate GSUP message\n");
+               return -ENOMEM;
+       }
+
+       /* Encode GSUP message */
+       rc = osmo_gsup_encode(gsup_msgb, gsup_msg);
+       if (rc) {
+               LOGP(DLGSUP, LOGL_ERROR, "Couldn't encode GSUP message\n");
+               goto error;
+       }
+
+       /* Finally send */
+       rc = osmo_gsup_client_send(gsupc, gsup_msgb);
+       if (rc) {
+               LOGP(DLGSUP, LOGL_ERROR, "Couldn't send GSUP message\n");
+               goto error;
+       }
+
+       return 0;
+
+error:
+       talloc_free(gsup_msgb);
+       return rc;
+}
+
 struct msgb *osmo_gsup_client_msgb_alloc(void)
 {
        return msgb_alloc_headroom(4000, 64, __func__);

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

Gerrit-Project: osmo-hlr
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0589ff27933e9bca2bcf93b8259004935778db8f
Gerrit-Change-Number: 11989
Gerrit-PatchSet: 1
Gerrit-Owner: Vadim Yanitskiy <[email protected]>

Reply via email to