mgcp_verify_ci(): return meaningful error codes

Instead of just -1, return RFC3435 error codes that can be used to compose a
FAIL message response. Note that the return value stays compatible in that it
returns 0 on a valid Connection Identifier, nonzero otherwise.

The idea is to be able to distinguish between "Conn ID not found" and "Conn ID
invalid" in mgcp_test.c's expected output, in upcoming change
I8d6cc96be252bb486e94f343a8c7cae641ff9429.

Change-Id: Ifc17f2893cc4b9a865f3ffcb9888bbf1039337a6
This commit is contained in:
Neels Hofmeyr 2018-09-03 23:00:07 +02:00
parent 8a91d2c04e
commit eb72ff058f
2 changed files with 12 additions and 11 deletions

View File

@ -430,16 +430,19 @@ int mgcp_verify_call_id(struct mgcp_endpoint *endp, const char *callid)
/*! Check if the specified connection id seems plausible.
* \param[in] endp pointer to endpoint
* \param{in] connection id to verify
* \returns 0 when connection id is valid and exists, nozero on error.
* \returns 0 when connection id is valid and exists, an RFC3435 error code on error.
*/
int mgcp_verify_ci(struct mgcp_endpoint *endp, const char *conn_id)
{
/* For invalid conn_ids, return 510 "The transaction could not be executed, because some
* unspecified protocol error was detected." */
/* Check for null identifiers */
if (!conn_id) {
LOGP(DLMGCP, LOGL_ERROR,
"endpoint:0x%x invalid ConnectionIdentifier (missing)\n",
ENDPOINT_NUMBER(endp));
return -1;
return 510;
}
/* Check for empty connection identifiers */
@ -447,7 +450,7 @@ int mgcp_verify_ci(struct mgcp_endpoint *endp, const char *conn_id)
LOGP(DLMGCP, LOGL_ERROR,
"endpoint:0x%x invalid ConnectionIdentifier (empty)\n",
ENDPOINT_NUMBER(endp));
return -1;
return 510;
}
/* Check for over long connection identifiers */
@ -455,7 +458,7 @@ int mgcp_verify_ci(struct mgcp_endpoint *endp, const char *conn_id)
LOGP(DLMGCP, LOGL_ERROR,
"endpoint:0x%x invalid ConnectionIdentifier (too long) 0x%s\n",
ENDPOINT_NUMBER(endp), conn_id);
return -1;
return 510;
}
/* Check if connection exists */
@ -466,7 +469,9 @@ int mgcp_verify_ci(struct mgcp_endpoint *endp, const char *conn_id)
"endpoint:0x%x no connection found under ConnectionIdentifier 0x%s\n",
ENDPOINT_NUMBER(endp), conn_id);
return -1;
/* When the conn_id was not found, return error code 515 "The transaction refers to an incorrect
* connection-id (may have been already deleted)." */
return 515;
}
/*! Extract individual lines from MCGP message.

View File

@ -999,10 +999,8 @@ static struct msgb *handle_modify_con(struct mgcp_parse_data *p)
break;
case 'I':
conn_id = (const char *)line + 3;
if (mgcp_verify_ci(endp, conn_id) != 0) {
error_code = 515;
if ((error_code = mgcp_verify_ci(endp, conn_id)))
goto error3;
}
break;
case 'L':
local_options = (const char *)line + 3;
@ -1185,10 +1183,8 @@ static struct msgb *handle_delete_con(struct mgcp_parse_data *p)
break;
case 'I':
conn_id = (const char *)line + 3;
if (mgcp_verify_ci(endp, conn_id) != 0) {
error_code = 515;
if ((error_code = mgcp_verify_ci(endp, conn_id)))
goto error3;
}
break;
case 'Z':
silent = strcmp("noanswer", line + 3) == 0;