Summary:ASTERISK-03016: [patch] Second Newchannel event in manager interface
Reporter:drfrancky (drfrancky)Labels:
Date Opened:2004-12-16 13:58:18.000-0600Date Closed:2011-06-07 14:05:04
Versions:Frequency of
Environment:Attachments:( 0) Newchannel.patch.txt
( 1) Newchannel.patch2.txt
Description:when you make Dial(SIP/angel) you recieve this event in manager interface:

Event: Newchannel
Channel: SIP/angel-b563
State: Down
Callerid: <unknown>
Uniqueid: 1103208585.32

Event: Newchannel
Channel: SIP/angel-b563
State: Ringing
Callerid: "devil" <666>
Uniqueid: 1103208585.32

why we recieve second Newchannel event instead of Newstate ?
is this correct or it must be Newstate ?
in channels.c i change the code of int ast_setstate(struct ast_channel *chan, int state)

int ast_setstate(struct ast_channel *chan, int state)
    if (chan->_state != state) {
         int oldstate = chan->_state;
         chan->_state = state;
         // Added  && (state != AST_STATE_RINGING) by drfrancky because of manager event Newchannel
         if ((oldstate == AST_STATE_DOWN) && (state != AST_STATE_RINGING) ) {
              manager_event(EVENT_FLAG_CALL, "Newchannel",
              "Channel: %s\r\n"
              "State: %s\r\n"
              "Callerid: %s\r\n"
              "Uniqueid: %s\r\n",
              chan->name, ast_state2str(chan->_state), chan->callerid ? chan->callerid : "<unknown>", chan->uniqueid);
         } else {
              manager_event(EVENT_FLAG_CALL, "Newstate",
                   "Channel: %s\r\n"
                   "State: %s\r\n"
                   "Callerid: %s\r\n"
                   "Uniqueid: %s\r\n",
                   chan->name, ast_state2str(chan->_state), chan->callerid ? chan->callerid : "<unknown>", chan->uniqueid);
         // Added by drfrancky because i dont know what ast_device_state_changed does :-))
         // start
         if ( (oldstate == AST_STATE_DOWN) && (state == AST_STATE_RINGING) ) {
         // end
    return 0;

and now it prints Newstate. I am no C coder so my voodoo can be completly wrong so please somebody to check the source
and i will be very happy if somebody explain this to me

Comments:By: Mark Spencer (markster) 2004-12-16 14:30:24.000-0600

Please post a cvs diff -u of your changes and confirm you have a disclaimer on file (or submit one if you don't).

By: Olle Johansson (oej) 2004-12-16 14:34:54.000-0600

And read coding guidelines, no comments with // please.

By: zoa (zoa) 2004-12-17 11:13:12.000-0600

I just uploaded a .diff, i have a disclaimer on file and i have the legal authority to disclaim this small patch done by drfrancky.

Please not that he is not a C programmer, we tested this patch, its seems to do what its supposed to do without sideeffects but some real programmer might want to  have a closer look at it.

This is a diff against the current CVS-stable, not against CVS-head.
(No idea if this is also a problem on cvs-head, but i suppose it will be - don't have the time to install cvs-head.)

edited on: 12-17-04 11:27

By: twisted (twisted) 2004-12-19 03:54:55.000-0600

This patch does what it says it does..   Looks like another trivial bug that can be solved in v1-0.

By: zoa (zoa) 2004-12-23 02:34:33.000-0600

just wanted to bring this back to the top of the list to get the attention from one of the people with cvs voodoo magic :p

By: Mark Spencer (markster) 2004-12-24 03:54:16.000-0600

How about we just use a flag in include/asterisk/channel.h to indicate if we've sent an event now that we have a flag bitmask there.

By: zoa (zoa) 2004-12-24 17:08:06.000-0600

no idea what those flags do exactly, noticed a lot of added flag support on the cvs mailinglist.

Anyway, im not able to patch anything for that, its way out of my league.

By: zoa (zoa) 2004-12-29 16:02:43.000-0600

i had a talk with mark about the flag things.

This wont work in -stable.
We found a second bug in this, patch following soon.

By: zoa (zoa) 2005-01-02 09:33:05.000-0600

new version of the patch uploaded. this fixes another situation where it says newchannel instead of newstate.

Flags would be easier patches indeed, but im not using -cvs.

By: Mark Spencer (markster) 2005-01-07 00:16:42.000-0600

I won't merge it into head unless it's flags based.  Not sure russell will want to merge it into stable either, not sure it really counts as a bug.

By: twisted (twisted) 2005-01-09 22:21:08.000-0600

zoa - gonna convert this to a flags based patch?

By: Mark Spencer (markster) 2005-01-16 02:24:31.000-0600

One more time, seeking conversion to flags based patch, else we'll go ahead and close this one out since it's not that huge a deal to get two newextens :)

By: zoa (zoa) 2005-01-16 02:57:35.000-0600

we will install -head and give patching a try...

By: zoa (zoa) 2005-01-25 16:44:56.000-0600

dont have time for it now, will reopen when i find the time to provide a patch for -head