diff options
author | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2015-06-15 09:40:43 +0200 |
---|---|---|
committer | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2015-06-15 09:40:43 +0200 |
commit | a9c411ec8cb594775bbfc9faefcf8c8d21080402 (patch) | |
tree | e1e03fdf88740c7755d9db67e3deb2bb30e4773a | |
parent | b89e03de226aa2fcfb331cd8ad6de828a718bb58 (diff) |
sccp: Allow to specify the context of the incoming message
At the time a SCCP CREF is sent there is no context anymore
and the user of the API might not know where to return the
message to. Allow to specify the incoming context and use it
on the way out.
There are no more callers of _send_msg which passes a NULL
connection and a NULL context.
-rw-r--r-- | include/sccp/sccp.h | 1 | ||||
-rw-r--r-- | src/sccp.c | 19 |
2 files changed, 13 insertions, 7 deletions
diff --git a/include/sccp/sccp.h b/include/sccp/sccp.h index 9a616c7..36b424f 100644 --- a/include/sccp/sccp.h +++ b/include/sccp/sccp.h @@ -110,6 +110,7 @@ struct sccp_connection { * The conn is NULL for UDT and other messages without a connection */ int sccp_system_init(void (*outgoing)(struct sccp_connection *conn, struct msgb *data, void *gctx, void *ctx), void *context); +int sccp_system_incoming_ctx(struct msgb *data, void *ctx); int sccp_system_incoming(struct msgb *data); /** @@ -692,13 +692,13 @@ struct msgb *sccp_create_refuse(struct sccp_source_reference *src_ref, int cause return msgb; } -static int _sccp_send_refuse(struct sccp_source_reference *src_ref, int cause) +static int _sccp_send_refuse(struct sccp_source_reference *src_ref, int cause, void *ctx) { struct msgb *msgb = sccp_create_refuse(src_ref, cause, NULL, 0); if (!msgb) return -1; - _send_msg(NULL, msgb, NULL); + _send_msg(NULL, msgb, ctx); return 0; } @@ -949,7 +949,7 @@ static int _sccp_send_connection_released(struct sccp_connection *conn, int caus * - Try to open the connection by assigning a source local reference * and sending the packet */ -static int _sccp_handle_connection_request(struct msgb *msgb) +static int _sccp_handle_connection_request(struct msgb *msgb, void *ctx) { struct sccp_parse_result result; @@ -981,7 +981,7 @@ static int _sccp_handle_connection_request(struct msgb *msgb) */ if (destination_local_reference_is_free(result.source_local_reference) != 0) { LOGP(DSCCP, LOGL_ERROR, "Need to reject connection with existing reference\n"); - _sccp_send_refuse(result.source_local_reference, SCCP_REFUSAL_SCCP_FAILURE); + _sccp_send_refuse(result.source_local_reference, SCCP_REFUSAL_SCCP_FAILURE, ctx); talloc_free(connection); return -1; } @@ -990,7 +990,7 @@ static int _sccp_handle_connection_request(struct msgb *msgb) connection->destination_local_reference = *result.source_local_reference; if (cb->accept_cb(connection, cb->accept_context) != 0) { - _sccp_send_refuse(result.source_local_reference, SCCP_REFUSAL_END_USER_ORIGINATED); + _sccp_send_refuse(result.source_local_reference, SCCP_REFUSAL_END_USER_ORIGINATED, ctx); _sccp_set_connection_state(connection, SCCP_CONNECTION_STATE_REFUSED); talloc_free(connection); return 0; @@ -1002,7 +1002,7 @@ static int _sccp_handle_connection_request(struct msgb *msgb) if (_sccp_send_connection_confirm(connection) != 0) { LOGP(DSCCP, LOGL_ERROR, "Sending confirm failed... no available source reference?\n"); - _sccp_send_refuse(result.source_local_reference, SCCP_REFUSAL_SCCP_FAILURE); + _sccp_send_refuse(result.source_local_reference, SCCP_REFUSAL_SCCP_FAILURE, ctx); _sccp_set_connection_state(connection, SCCP_CONNECTION_STATE_REFUSED); llist_del(&connection->list); talloc_free(connection); @@ -1228,6 +1228,11 @@ int sccp_system_init(void (*outgoing)(struct sccp_connection *conn, struct msgb /* oh my god a real SCCP packet. need to dispatch it now */ int sccp_system_incoming(struct msgb *msgb) { + return sccp_system_incoming_ctx(msgb, NULL); +} + +int sccp_system_incoming_ctx(struct msgb *msgb, void *ctx) +{ if (msgb_l2len(msgb) < 1 ) { LOGP(DSCCP, LOGL_ERROR, "Too short packet\n"); return -1; @@ -1237,7 +1242,7 @@ int sccp_system_incoming(struct msgb *msgb) switch(type) { case SCCP_MSG_TYPE_CR: - return _sccp_handle_connection_request(msgb); + return _sccp_handle_connection_request(msgb, ctx); break; case SCCP_MSG_TYPE_RLSD: return _sccp_handle_connection_released(msgb); |