mgw: Add backpointer from pdata to req to have context available

This will also allow eg. parsing/validating differently based on the
command being parsed, or incrementing rate counters per cmd group.

Change-Id: I464258ca1a8817d58ae5c5426dfc3b7cee6763d3
This commit is contained in:
Pau Espin Pedrol
2025-03-06 19:45:03 +01:00
committed by pespin
parent 741d0ece37
commit f63ef75d9f
3 changed files with 5 additions and 2 deletions

View File

@@ -71,7 +71,9 @@ static inline void mgcp_parse_hdr_pars_init(struct mgcp_parse_hdr_pars *hpars)
}
/* Internal structure while parsing a request */
struct mgcp_request_data;
struct mgcp_parse_data {
struct mgcp_request_data *rq; /* backpointer to request context */
char *save;
/* MGCP Header: */
char *epname;

View File

@@ -36,7 +36,7 @@
/* (same fmt as LOGPENDP()) */
#define LOG_MGCP_PDATA(PDATA, LEVEL, FMT, ARGS...) \
LOGP(DLMGCP, LEVEL, "endpoint:%s " FMT, (PDATA) ? ((PDATA)->epname ? : "null-epname") : "null-pdata", ##ARGS)
LOGP(DLMGCP, LEVEL, "%s: endpoint(%s) " FMT, (PDATA)->rq->name, (PDATA)->epname ? : "null-epname", ##ARGS)
/*! Display an mgcp message on the log output.
* \param[in] message mgcp message string
@@ -212,7 +212,7 @@ int mgcp_parse_hdr_pars(struct mgcp_parse_data *pdata)
hp->have_sdp = true;
goto mgcp_header_done;
default:
LOG_MGCP_PDATA(pdata, LOGL_NOTICE, "CRCX: unhandled option: '%c'/%d\n", *line, *line);
LOG_MGCP_PDATA(pdata, LOGL_NOTICE, "unhandled option: '%c'/%d\n", *line, *line);
return -539;
}
}

View File

@@ -332,6 +332,7 @@ struct msgb *mgcp_handle_message(struct mgcp_config *cfg, struct msgb *msg)
memset(&rq, 0, sizeof(rq));
rq.cfg = cfg;
memset(&pdata, 0, sizeof(pdata));
pdata.rq = &rq;
/* Parse command name: */
memcpy(rq.name, (const char *)&msg->l2h[0], sizeof(rq.name)-1);