Merge "res_pjsip_caller_id: Add "party" parameter to RPID header."
[asterisk/asterisk.git] / res / res_pjsip_t38.c
index 3f4110f..52dfd75 100644 (file)
@@ -507,21 +507,42 @@ static struct ast_frame *t38_framehook(struct ast_channel *chan, struct ast_fram
                return f;
        }
 
-       if (f->frametype == AST_FRAME_CONTROL && f->subclass.integer == AST_CONTROL_T38_PARAMETERS) {
+       if (f->frametype == AST_FRAME_CONTROL
+               && f->subclass.integer == AST_CONTROL_T38_PARAMETERS) {
                if (channel->session->endpoint->media.t38.enabled) {
-                       struct t38_parameters_task_data *data = t38_parameters_task_data_alloc(channel->session, f);
+                       struct t38_parameters_task_data *data;
 
-                       if (!data) {
-                               return f;
-                       }
-
-                       if (ast_sip_push_task(channel->session->serializer, t38_interpret_parameters, data)) {
+                       data = t38_parameters_task_data_alloc(channel->session, f);
+                       if (data
+                               && ast_sip_push_task(channel->session->serializer,
+                                       t38_interpret_parameters, data)) {
                                ao2_ref(data, -1);
                        }
                } else {
-                       struct ast_control_t38_parameters parameters = { .request_response = AST_T38_REFUSED, };
-                       ast_debug(2, "T.38 support not enabled, rejecting T.38 control packet\n");
-                       ast_queue_control_data(chan, AST_CONTROL_T38_PARAMETERS, &parameters, sizeof(parameters));
+                       static const struct ast_control_t38_parameters rsp_refused = {
+                               .request_response = AST_T38_REFUSED,
+                       };
+                       static const struct ast_control_t38_parameters rsp_terminated = {
+                               .request_response = AST_T38_TERMINATED,
+                       };
+                       const struct ast_control_t38_parameters *parameters = f->data.ptr;
+
+                       switch (parameters->request_response) {
+                       case AST_T38_REQUEST_NEGOTIATE:
+                               ast_debug(2, "T.38 support not enabled on %s, refusing T.38 negotiation\n",
+                                       ast_channel_name(chan));
+                               ast_queue_control_data(chan, AST_CONTROL_T38_PARAMETERS,
+                                       &rsp_refused, sizeof(rsp_refused));
+                               break;
+                       case AST_T38_REQUEST_TERMINATE:
+                               ast_debug(2, "T.38 support not enabled on %s, 'terminating' T.38 session\n",
+                                       ast_channel_name(chan));
+                               ast_queue_control_data(chan, AST_CONTROL_T38_PARAMETERS,
+                                       &rsp_terminated, sizeof(rsp_terminated));
+                               break;
+                       default:
+                               break;
+                       }
                }
        }
 
@@ -749,17 +770,17 @@ static int negotiate_incoming_sdp_stream(struct ast_sip_session *session,
 
        if (!session->endpoint->media.t38.enabled) {
                ast_debug(3, "Declining; T.38 not enabled on session\n");
-               return -1;
+               return 0;
        }
 
        if (!(state = t38_state_get_or_alloc(session))) {
-               return -1;
+               return 0;
        }
 
        if ((session->t38state == T38_REJECTED) || (session->t38state == T38_DISABLED)) {
                ast_debug(3, "Declining; T.38 state is rejected or declined\n");
                t38_change_state(session, session_media, state, T38_DISABLED);
-               return -1;
+               return 0;
        }
 
        ast_copy_pj_str(host, stream->conn ? &stream->conn->addr : &sdp->conn->addr, sizeof(host));
@@ -768,7 +789,7 @@ static int negotiate_incoming_sdp_stream(struct ast_sip_session *session,
        if (ast_sockaddr_resolve(&addrs, host, PARSE_PORT_FORBID, AST_AF_INET) <= 0) {
                /* The provided host was actually invalid so we error out this negotiation */
                ast_debug(3, "Declining; provided host is invalid\n");
-               return -1;
+               return 0;
        }
 
        /* Check the address family to make sure it matches configured */
@@ -776,7 +797,7 @@ static int negotiate_incoming_sdp_stream(struct ast_sip_session *session,
                (ast_sockaddr_is_ipv4(addrs) && session->endpoint->media.t38.ipv6)) {
                /* The address does not match configured */
                ast_debug(3, "Declining, provided host does not match configured address family\n");
-               return -1;
+               return 0;
        }
 
        return 1;