aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2023-02-18 02:37:43 +0100
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2023-02-18 02:45:14 +0100
commit4c761ba30438f573d5a21448e59105292dc83d4f (patch)
tree3e4b80dfe6208040ff918efbbc573a33718910cd
parented4e7dbf86860a727f8cd6ca7ca03dfb20e3bfca (diff)
add osmo_scu_prim_name_c() / _buf()
Add non-legacy string functions for osmo_scu_prim_name in the form of _buf() and _c() signatures. So far there is only osmo_scu_prim_name() using a static buffer. Implement that using osmo_scu_prim_name_buf(). Change-Id: I4c1998fd7fee7282d107846dae2cff4b5ceb3a7b
-rw-r--r--include/osmocom/sigtran/sccp_sap.h2
-rw-r--r--src/sccp_sap.c23
2 files changed, 21 insertions, 4 deletions
diff --git a/include/osmocom/sigtran/sccp_sap.h b/include/osmocom/sigtran/sccp_sap.h
index 5624d33..3930111 100644
--- a/include/osmocom/sigtran/sccp_sap.h
+++ b/include/osmocom/sigtran/sccp_sap.h
@@ -274,6 +274,8 @@ struct osmo_scu_prim {
#define msgb_scu_prim(msg) ((struct osmo_scu_prim *)(msg)->l1h)
char *osmo_scu_prim_name(const struct osmo_prim_hdr *oph);
+int osmo_scu_prim_name_buf(char *buf, size_t buflen, const struct osmo_prim_hdr *oph);
+char *osmo_scu_prim_name_c(void *ctx, const struct osmo_prim_hdr *oph);
struct osmo_ss7_instance;
struct osmo_sccp_instance;
diff --git a/src/sccp_sap.c b/src/sccp_sap.c
index cdf0acc..c0a42c6 100644
--- a/src/sccp_sap.c
+++ b/src/sccp_sap.c
@@ -45,14 +45,29 @@ static char prim_name_buf[128];
char *osmo_scu_prim_name(const struct osmo_prim_hdr *oph)
{
- const char *name = get_value_string(osmo_scu_prim_names, oph->primitive);
+ osmo_scu_prim_name_buf(prim_name_buf, sizeof(prim_name_buf), oph);
+ return prim_name_buf;
+}
- snprintf(prim_name_buf, sizeof(prim_name_buf), "%s.%s", name,
- get_value_string(osmo_prim_op_names, oph->operation));
+int osmo_scu_prim_name_buf(char *buf, size_t buflen, const struct osmo_prim_hdr *oph)
+{
+ struct osmo_strbuf sb = { .buf = buf, .len = buflen };
- return prim_name_buf;
+ if (!oph) {
+ OSMO_STRBUF_PRINTF(sb, "null");
+ return sb.chars_needed;
+ }
+
+ OSMO_STRBUF_PRINTF(sb, "%s.%s",
+ get_value_string(osmo_scu_prim_names, oph->primitive),
+ get_value_string(osmo_prim_op_names, oph->operation));
+ return sb.chars_needed;
}
+char *osmo_scu_prim_name_c(void *ctx, const struct osmo_prim_hdr *oph)
+{
+ OSMO_NAME_C_IMPL(ctx, 32, "ERROR", osmo_scu_prim_name_buf, oph)
+}
#include <osmocom/sigtran/sigtran_sap.h>