mgcp_msg: add trunk parameter to mgcp_check_param for logging

There is not always an endp pointer present when mgcp_check_param() is
called but we always have a trunk pointer. Lets add a trunk parameter so
that the function can pick LOGPTRUNK when endp is not available.

Change-Id: I7327c5a105e7f0e20cabf64623ff9f36fd83bbb8
Related: SYS#5535
This commit is contained in:
Philipp Maier 2021-07-19 17:47:49 +02:00
parent 6bad138c96
commit 036612b035
3 changed files with 15 additions and 12 deletions

View File

@ -39,7 +39,7 @@ int mgcp_parse_header(struct mgcp_parse_data *pdata, char *data);
int mgcp_parse_osmux_cid(const char *line);
int mgcp_check_param(const struct mgcp_endpoint *endp, const char *line);
bool mgcp_check_param(const struct mgcp_endpoint *endp, struct mgcp_trunk *trunk, const char *line);
int mgcp_verify_call_id(struct mgcp_endpoint *endp, const char *callid);

View File

@ -31,6 +31,7 @@
#include <osmocom/mgcp/mgcp_msg.h>
#include <osmocom/mgcp/mgcp_conn.h>
#include <osmocom/mgcp/mgcp_endp.h>
#include <osmocom/mgcp/mgcp_trunk.h>
/*! Display an mgcp message on the log output.
* \param[in] message mgcp message string
@ -208,22 +209,24 @@ int mgcp_parse_osmux_cid(const char *line)
}
/*! Check MGCP parameter line (string) for plausibility.
* \param[in] endp pointer to endpoint (only used for log output)
* \param[in] endp pointer to endpoint (only used for log output, may be NULL)
* \param[in] trunk pointer to trunk (only used for log output, may be NULL if endp is not NULL)
* \param[in] line single parameter line from the MGCP message
* \returns 1 when line seems plausible, 0 on error */
int mgcp_check_param(const struct mgcp_endpoint *endp, const char *line)
* \returns true when line seems plausible, false on error */
bool mgcp_check_param(const struct mgcp_endpoint *endp, struct mgcp_trunk *trunk, const char *line)
{
const size_t line_len = strlen(line);
if (line[0] != '\0' && line_len < 2) {
LOGP(DLMGCP, LOGL_ERROR,
"Wrong MGCP option format: '%s' on %s\n",
line, endp->name);
return 0;
if (endp)
LOGPENDP(endp, DLMGCP, LOGL_NOTICE, "wrong MGCP option format: '%s'\n", line);
else
LOGPTRUNK(trunk, DLMGCP, LOGL_NOTICE, "wrong MGCP option format: '%s'\n", line);
return false;
}
/* FIXME: A couple more checks wouldn't hurt... */
return 1;
return true;
}
/*! Check if the specified callid seems plausible.

View File

@ -851,7 +851,7 @@ static struct msgb *handle_create_con(struct mgcp_request_data *rq)
/* parse CallID C: and LocalParameters L: */
for_each_line(line, pdata->save) {
if (!mgcp_check_param(endp, line))
if (!mgcp_check_param(endp, trunk, line))
continue;
switch (toupper(line[0])) {
@ -1143,7 +1143,7 @@ static struct msgb *handle_modify_con(struct mgcp_request_data *rq)
}
for_each_line(line, pdata->save) {
if (!mgcp_check_param(endp, line))
if (!mgcp_check_param(endp, trunk, line))
continue;
switch (toupper(line[0])) {
@ -1388,7 +1388,7 @@ static struct msgb *handle_delete_con(struct mgcp_request_data *rq)
}
for_each_line(line, pdata->save) {
if (!mgcp_check_param(endp, line))
if (!mgcp_check_param(endp, trunk, line))
continue;
switch (toupper(line[0])) {