tmp->pvt = pvt;
/* Initial state */
tmp->_state = AST_STATE_DOWN;
- tmp->stack = -1;
tmp->streamid = -1;
tmp->appl = NULL;
tmp->data = NULL;
} else if (chan->timingfd > -1) {
ioctl(chan->timingfd, ZT_TIMERPING, &blah);
#endif
- } else if (chan->blocking) {
+ } else if (ast_test_flag(chan, AST_FLAG_BLOCKING)) {
pthread_kill(chan->blocker, SIGURG);
}
ast_mutex_unlock(&chan->lock);
{
int pre = 0;
if (chan) {
- pre = chan->deferdtmf;
- chan->deferdtmf = 1;
+ pre = ast_test_flag(chan, AST_FLAG_DEFER_DTMF);
+ ast_set_flag(chan, AST_FLAG_DEFER_DTMF);
}
return pre;
}
void ast_channel_undefer_dtmf(struct ast_channel *chan)
{
if (chan)
- chan->deferdtmf = 0;
+ ast_clear_flag(chan, AST_FLAG_DEFER_DTMF);
}
struct ast_channel *ast_channel_walk_locked(struct ast_channel *prev)
chan->_softhangup |= cause;
ast_queue_frame(chan, &f);
/* Interrupt any poll call or such */
- if (chan->blocking)
+ if (ast_test_flag(chan, AST_FLAG_BLOCKING))
pthread_kill(chan->blocker, SIGURG);
return res;
}
/* If this channel is one which will be masqueraded into something,
mark it as a zombie already, so we know to free it later */
if (chan->masqr) {
- chan->zombie=1;
+ ast_set_flag(chan, AST_FLAG_ZOMBIE);
ast_mutex_unlock(&chan->lock);
return 0;
}
ast_cdr_post(chan->cdr);
ast_cdr_free(chan->cdr);
}
- if (chan->blocking) {
+ if (ast_test_flag(chan, AST_FLAG_BLOCKING)) {
ast_log(LOG_WARNING, "Hard hangup called by thread %ld on %s, while fd "
"is blocked by thread %ld in procedure %s! Expect a failure\n",
(long)pthread_self(), chan->name, (long)chan->blocker, chan->blockproc);
CRASH;
}
- if (!chan->zombie) {
+ if (!ast_test_flag(chan, AST_FLAG_ZOMBIE)) {
if (option_debug)
ast_log(LOG_DEBUG, "Hanging up channel '%s'\n", chan->name);
if (chan->pvt->hangup)
int res = 0;
ast_mutex_lock(&chan->lock);
/* Stop if we're a zombie or need a soft hangup */
- if (chan->zombie || ast_check_hangup(chan)) {
+ if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) {
ast_mutex_unlock(&chan->lock);
return -1;
}
chan->generator->release(chan, chan->generatordata);
chan->generatordata = NULL;
chan->generator = NULL;
- chan->writeinterrupt = 0;
+ ast_clear_flag(chan, AST_FLAG_WRITE_INT);
ast_settimeout(chan, 0, NULL, NULL);
}
ast_mutex_unlock(&chan->lock);
res = poll(pfds, max, rms);
if (res < 0) {
for (x=0;x<n;x++)
- c[x]->blocking = 0;
+ ast_clear_flag(c[x], AST_FLAG_BLOCKING);
/* Simulate a timeout if we were interrupted */
if (errno != EINTR)
*ms = -1;
time(&now);
spoint = 0;
for (x=0;x<n;x++) {
- c[x]->blocking = 0;
+ ast_clear_flag(c[x], AST_FLAG_BLOCKING);
if (havewhen && c[x]->whentohangup && (now > c[x]->whentohangup)) {
c[x]->_softhangup |= AST_SOFTHANGUP_TIMEOUT;
if (!winner)
if (c[x]->fds[y] > -1) {
if ((res = ast_fdisset(pfds, c[x]->fds[y], max, &spoint))) {
if (res & POLLPRI)
- c[x]->exception = -1;
+ ast_set_flag(c[x], AST_FLAG_EXCEPTION);
else
- c[x]->exception = 0;
+ ast_clear_flag(c[x], AST_FLAG_EXCEPTION);
c[x]->fdno = y;
winner = c[x];
}
struct ast_frame *f;
char result = 0;
/* Stop if we're a zombie or need a soft hangup */
- if (c->zombie || ast_check_hangup(c))
+ if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c))
return -1;
/* Wait for a digit, no more than ms milliseconds total. */
while(ms && !result) {
int outfd;
int res;
/* Stop if we're a zombie or need a soft hangup */
- if (c->zombie || ast_check_hangup(c))
+ if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c))
return -1;
/* Wait for a digit, no more than ms milliseconds total. */
while(ms) {
}
/* Stop if we're a zombie or need a soft hangup */
- if (chan->zombie || ast_check_hangup(chan)) {
+ if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) {
if (chan->generator)
ast_deactivate_generator(chan);
ast_mutex_unlock(&chan->lock);
return NULL;
}
- if (!chan->deferdtmf && !ast_strlen_zero(chan->dtmfq)) {
+ if (!ast_test_flag(chan, AST_FLAG_DEFER_DTMF) && !ast_strlen_zero(chan->dtmfq)) {
/* We have DTMF that has been deferred. Return it now */
chan->dtmff.frametype = AST_FRAME_DTMF;
chan->dtmff.subclass = chan->dtmfq[0];
read(chan->pvt->alertpipe[0], &blah, sizeof(blah));
}
#ifdef ZAPTEL_OPTIMIZATIONS
- if ((chan->timingfd > -1) && (chan->fdno == AST_MAX_FDS - 2) && chan->exception) {
- chan->exception = 0;
+ if ((chan->timingfd > -1) && (chan->fdno == AST_MAX_FDS - 2) && ast_test_flag(chan, AST_FLAG_EXCEPTION)) {
+ ast_clear_flag(chan, AST_FLAG_EXCEPTION);
blah = -1;
/* IF we can't get event, assume it's an expired as-per the old interface */
res = ioctl(chan->timingfd, ZT_GETEVENT, &blah);
}
} else {
chan->blocker = pthread_self();
- if (chan->exception) {
+ if (ast_test_flag(chan, AST_FLAG_EXCEPTION)) {
if (chan->pvt->exception)
f = chan->pvt->exception(chan);
else {
f = &null_frame;
}
/* Clear the exception flag */
- chan->exception = 0;
+ ast_clear_flag(chan, AST_FLAG_EXCEPTION);
} else
if (chan->pvt->read)
f = chan->pvt->read(chan);
/* End the CDR if appropriate */
if (chan->cdr)
ast_cdr_end(chan->cdr);
- } else if (chan->deferdtmf && f->frametype == AST_FRAME_DTMF) {
+ } else if (ast_test_flag(chan, AST_FLAG_DEFER_DTMF) && f->frametype == AST_FRAME_DTMF) {
if (strlen(chan->dtmfq) < sizeof(chan->dtmfq) - 2)
chan->dtmfq[strlen(chan->dtmfq)] = f->subclass;
else
{
int res = -1;
/* Stop if we're a zombie or need a soft hangup */
- if (chan->zombie || ast_check_hangup(chan))
+ if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan))
return -1;
ast_mutex_lock(&chan->lock);
if (chan->pvt->indicate)
{
int res = 0;
/* Stop if we're a zombie or need a soft hangup */
- if (chan->zombie || ast_check_hangup(chan))
+ if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan))
return -1;
CHECK_BLOCKING(chan);
if (chan->pvt->send_text)
res = chan->pvt->send_text(chan, text);
- chan->blocking = 0;
+ ast_clear_flag(chan, AST_FLAG_BLOCKING);
return res;
}
struct ast_frame *f = NULL;
/* Stop if we're a zombie or need a soft hangup */
ast_mutex_lock(&chan->lock);
- if (chan->zombie || ast_check_hangup(chan)) {
+ if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) {
ast_mutex_unlock(&chan->lock);
return -1;
}
return 0;
}
if (chan->generatordata) {
- if (chan->writeinterrupt)
+ if (ast_test_flag(chan, AST_FLAG_WRITE_INT))
ast_deactivate_generator(chan);
else {
ast_mutex_unlock(&chan->lock);
ast_log(LOG_WARNING, "Don't know how to handle control frames yet\n");
break;
case AST_FRAME_DTMF:
- chan->blocking = 0;
+ ast_clear_flag(chan, AST_FLAG_BLOCKING);
ast_mutex_unlock(&chan->lock);
res = do_senddigit(chan,fr->subclass);
ast_mutex_lock(&chan->lock);
}
if (f && (f != fr))
ast_frfree(f);
- chan->blocking = 0;
+ ast_clear_flag(chan, AST_FLAG_BLOCKING);
/* Consider a write failure to force a soft hangup */
if (res < 0)
chan->_softhangup |= AST_SOFTHANGUP_DEV;
int res = -1;
/* Stop if we're a zombie or need a soft hangup */
ast_mutex_lock(&chan->lock);
- if (!chan->zombie && !ast_check_hangup(chan))
+ if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan))
if (chan->pvt->call)
res = chan->pvt->call(chan, addr, timeout);
ast_mutex_unlock(&chan->lock);
int res = -1;
/* Stop if we're a zombie or need a soft hangup */
ast_mutex_lock(&chan->lock);
- if (!chan->zombie && !ast_check_hangup(chan)) {
+ if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) {
if (chan->pvt->transfer) {
res = chan->pvt->transfer(chan, dest);
if (!res)
char d;
/* XXX Merge with full version? XXX */
/* Stop if we're a zombie or need a soft hangup */
- if (c->zombie || ast_check_hangup(c))
+ if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c))
return -1;
if (!len)
return -1;
int to = ftimeout;
char d;
/* Stop if we're a zombie or need a soft hangup */
- if (c->zombie || ast_check_hangup(c))
+ if (ast_test_flag(c, AST_FLAG_ZOMBIE) || ast_check_hangup(c))
return -1;
if (!len)
return -1;
/* XXX What about blocking, softhangup, blocker, and lock and blockproc? XXX */
/* Application and data remain the same */
/* Clone exception becomes real one, as with fdno */
- original->exception = clone->exception;
+ ast_copy_flags(original, clone, AST_FLAG_EXCEPTION);
original->fdno = clone->fdno;
/* Schedule context remains the same */
/* Stream stuff stays the same */
/* Now, at this point, the "clone" channel is totally F'd up. We mark it as
a zombie so nothing tries to touch it. If it's already been marked as a
zombie, then free it now (since it already is considered invalid). */
- if (clone->zombie) {
+ if (ast_test_flag(clone, AST_FLAG_ZOMBIE)) {
ast_log(LOG_DEBUG, "Destroying clone '%s'\n", clone->name);
ast_mutex_unlock(&clone->lock);
ast_channel_free(clone);
manager_event(EVENT_FLAG_CALL, "Hangup", "Channel: %s\r\n", zombn);
} else {
ast_log(LOG_DEBUG, "Released clone lock on '%s'\n", clone->name);
- clone->zombie=1;
+ ast_set_flag(clone, AST_FLAG_ZOMBIE);
ast_mutex_unlock(&clone->lock);
}
/* Signal any blocker */
- if (original->blocking)
+ if (ast_test_flag(original, AST_FLAG_BLOCKING))
pthread_kill(original->blocker, SIGURG);
ast_log(LOG_DEBUG, "Done Masquerading %s (%d)\n",
original->name, original->_state);
bridge_playfile(c1,c0,config->start_sound,time_left_ms / 1000);
/* Stop if we're a zombie or need a soft hangup */
- if (c0->zombie || ast_check_hangup_locked(c0) || c1->zombie || ast_check_hangup_locked(c1))
+ if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) || ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1))
return -1;
if (c0->_bridge) {
ast_log(LOG_WARNING, "%s is already in a bridge with %s\n",
}
/* Stop if we're a zombie or need a soft hangup */
- if (c0->zombie || ast_check_hangup_locked(c0) || c1->zombie || ast_check_hangup_locked(c1)) {
+ if (ast_test_flag(c0, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c0) || ast_test_flag(c1, AST_FLAG_ZOMBIE) || ast_check_hangup_locked(c1)) {
*fo = NULL;
if (who) *rc = who;
res = 0;
- ast_log(LOG_DEBUG, "Bridge stops because we're zombie or need a soft hangup: c0=%s, c1=%s, flags: %s,%s,%s,%s\n",c0->name,c1->name,c0->zombie?"Yes":"No",ast_check_hangup(c0)?"Yes":"No",c1->zombie?"Yes":"No",ast_check_hangup(c1)?"Yes":"No");
+ ast_log(LOG_DEBUG, "Bridge stops because we're zombie or need a soft hangup: c0=%s, c1=%s, flags: %s,%s,%s,%s\n",c0->name,c1->name,ast_test_flag(c0, AST_FLAG_ZOMBIE)?"Yes":"No",ast_check_hangup(c0)?"Yes":"No",ast_test_flag(c1, AST_FLAG_ZOMBIE)?"Yes":"No",ast_check_hangup(c1)?"Yes":"No");
break;
}
if (c0->pvt->bridge && config->timelimit==0 &&
ts->vol = td->vol;
}
/* Let interrupts interrupt :) */
- chan->writeinterrupt = 1;
+ ast_set_flag(chan, AST_FLAG_WRITE_INT);
return ts;
}
#define AST_CHANNEL_NAME 80
-#define AST_CHANNEL_MAX_STACK 32
#define MAX_LANGUAGE 20
void *generatordata;
/*! Current active data generator */
struct ast_generator *generator;
- /*! Whether or not the generator should be interrupted by write */
- int writeinterrupt;
/*! Who are we bridged to, if we're bridged Do not access directly,
use ast_bridged_channel(chan) */
struct ast_channel *dialed;
/*! Who called us? */
struct ast_channel *dialing;
- /*! Reverse the dialed link (0 false, 1 true) */
- int reversedialed;
/*! Channel that will masquerade as us */
struct ast_channel *masq;
/*! Who we are masquerading as */
struct ast_channel *masqr;
/*! Call Detail Record Flags */
int cdrflags;
- /*! Whether or not we're blocking */
- int blocking;
/*! Whether or not we have been hung up... Do not set this value
directly, use ast_softhangup */
int _softhangup;
- /*! Non-zero if this is a zombie channel */
- int zombie;
/*! Non-zero, set to actual time when channel is to be hung up */
time_t whentohangup;
/*! If anyone is blocking, this is them */
/*! Data passed to current application */
char *data;
- /*! Has an exception been detected */
- int exception;
/*! Which fd had an event detected on */
int fdno;
/*! Schedule context */
int _state;
/*! Number of rings so far */
int rings;
- /*! Current level of application */
- int stack;
-
/*! Kinds of data this channel can natively handle */
int nativeformats;
char exten[AST_MAX_EXTENSION];
/* Current extension priority */
int priority;
- /*! Application information -- see assigned numbers */
- void *app[AST_CHANNEL_MAX_STACK];
/*! Any/all queued DTMF characters */
char dtmfq[AST_MAX_EXTENSION];
- /*! Are DTMF digits being deferred */
- int deferdtmf;
/*! DTMF frame */
struct ast_frame dtmff;
/*! Private channel implementation details */
struct ast_channel_pvt *pvt;
-
- /*! Jump buffer used for returning from applications */
- jmp_buf jmp[AST_CHANNEL_MAX_STACK];
-
+ /*! PBX private structure */
struct ast_pbx *pbx;
/*! Set BEFORE PBX is started to determine AMA flags */
int amaflags;
unsigned int pickupgroup;
/*! channel flags of AST_FLAG_ type */
- int flag;
+ int flags;
/*! For easy linking */
struct ast_channel *next;
};
-#define AST_FLAG_DIGITAL 1 /* if the call is a digital ISDN call */
+#define AST_FLAG_DIGITAL (1 << 0) /* if the call is a digital ISDN call */
+#define AST_FLAG_DEFER_DTMF (1 << 1) /* if dtmf should be deferred */
+#define AST_FLAG_WRITE_INT (1 << 2) /* if write should be interrupt generator */
+#define AST_FLAG_BLOCKING (1 << 3) /* if we are blocking */
+#define AST_FLAG_ZOMBIE (1 << 4) /* if we are a zombie */
+#define AST_FLAG_EXCEPTION (1 << 5) /* if there is a pending exception */
static inline int ast_test_flag(struct ast_channel *chan, int mode)
{
- return chan->flag & mode;
+ return chan->flags & mode;
}
static inline void ast_set_flag(struct ast_channel *chan, int mode)
{
- chan->flag |= mode;
+ chan->flags |= mode;
}
static inline void ast_clear_flag(struct ast_channel *chan, int mode)
{
- chan->flag &= ~mode;
+ chan->flags &= ~mode;
+}
+
+static inline void ast_copy_flags(struct ast_channel *dest, struct ast_channel *src, int flags)
+{
+ dest->flags &= ~flags;
+ dest->flags |= (src->flags & flags);
}
static inline void ast_set2_flag(struct ast_channel *chan, int value, int mode)
#endif
#define CHECK_BLOCKING(c) { \
- if ((c)->blocking) {\
+ if (ast_test_flag(c, AST_FLAG_BLOCKING)) {\
ast_log(LOG_WARNING, "Thread %ld Blocking '%s', already blocked by thread %ld in procedure %s\n", (long) pthread_self(), (c)->name, (long) (c)->blocker, (c)->blockproc); \
CRASH; \
} else { \
(c)->blocker = pthread_self(); \
(c)->blockproc = __PRETTY_FUNCTION__; \
- c->blocking = -1; \
+ ast_set_flag(c, AST_FLAG_BLOCKING); \
} }
extern unsigned int ast_get_group(char *s);