All pastes #29171 Raw Edit

Stuff

public text v1 · immutable
#29171 ·published 2005-11-19 01:30 UTC
rendered paste body
/*--- action_redirect: The redirect manager command */
static int action_redirect(struct mansession *s, struct message *m)
{
        char *name = astman_get_header(m, "Channel");
        char *name2 = astman_get_header(m, "ExtraChannel");
        char *exten = astman_get_header(m, "Exten");
        char *context = astman_get_header(m, "Context");
        char *priority = astman_get_header(m, "Priority");
        struct opbx_channel *chan, *chan2 = NULL;
        int pi = 0;
        int res;

        if (!name || opbx_strlen_zero(name)) {
                astman_send_error(s, m, "Channel not specified");
                return 0;
        }
        if (!opbx_strlen_zero(priority) && (sscanf(priority, "%d", &pi) != 1)) {
                astman_send_error(s, m, "Invalid priority\n");
                return 0;
        }
        chan = opbx_get_channel_by_name_locked(name);
        if (!chan) {
                char buf[BUFSIZ];
                snprintf(buf, sizeof(buf), "Channel does not exist: %s", name);
                astman_send_error(s, m, buf);
                return 0;
        }
        if (!opbx_strlen_zero(name2))
                chan2 = opbx_get_channel_by_name_locked(name2);
        res = opbx_async_goto(chan, context, exten, pi);
        if (!res) {
                if (!opbx_strlen_zero(name2)) {
                        if (chan2)
                                res = opbx_async_goto(chan2, context, exten, pi);
                        else
                                res = -1;
                        if (!res)
                                astman_send_ack(s, m, "Dual Redirect successful");
                        else
                                astman_send_error(s, m, "Secondary redirect failed");
                } else
                        astman_send_ack(s, m, "Redirect successful");
        } else
                astman_send_error(s, m, "Redirect failed");
        if (chan)
                opbx_mutex_unlock(&chan->lock);
        if (chan2)
                opbx_mutex_unlock(&chan2->lock);
        return 0;
}