--- chan_sccp.c-org Thu Jul 14 08:38:54 2005 +++ chan_sccp.c Thu Jul 14 08:41:22 2005 @@ -694,6 +694,12 @@ } int unload_module() { +sccp_line_t * l; +sccp_device_t * d; +sccp_intercom_t * i; +sccp_session_t * s; +char iabuf[INET_ADDRSTRLEN]; + #ifdef CS_AST_HAVE_TECH_PVT ast_channel_unregister(&sccp_tech); #else @@ -707,7 +713,6 @@ sccp_channel_delete(GLOB(channels)); ast_mutex_lock(&GLOB(lines_lock)); - sccp_line_t * l; while (GLOB(lines)) { l = GLOB(lines); GLOB(lines) = l->next; @@ -717,7 +722,6 @@ ast_mutex_unlock(&GLOB(lines_lock)); ast_mutex_lock(&GLOB(devices_lock)); - sccp_device_t * d; while (GLOB(devices)) { d = GLOB(devices); GLOB(devices) = d->next; @@ -727,7 +731,6 @@ ast_mutex_unlock(&GLOB(devices_lock)); ast_mutex_lock(&GLOB(intercoms_lock)); - sccp_intercom_t * i; while (GLOB(intercoms)) { i = GLOB(intercoms); GLOB(intercoms) = i->next; @@ -737,8 +740,6 @@ ast_mutex_unlock(&GLOB(intercoms_lock)); ast_mutex_lock(&GLOB(sessions_lock)); - sccp_session_t * s; - char iabuf[INET_ADDRSTRLEN]; while (GLOB(sessions)) { s = GLOB(sessions); GLOB(sessions) = s->next; --- sccp_actions.c-org Thu Jul 14 08:42:04 2005 +++ sccp_actions.c Thu Jul 14 08:52:32 2005 @@ -119,12 +119,12 @@ void sccp_handle_unregister(sccp_session_t * s, sccp_moo_t * r) { +sccp_moo_t * r1; sccp_device_t * d = s->device; if (!d || !s || (s->fd < 0) ) return; /* we don't need to look for active channels. the phone does send unregister only when there are no channels */ - sccp_moo_t * r1; REQ(r1, UnregisterAckMessage) r1->msg.UnregisterAckMessage.lel_status = SKINNY_UNREGISTERSTATUS_OK; sccp_dev_send(d, r1); @@ -291,6 +291,8 @@ } void sccp_handle_stimulus(sccp_session_t * s, sccp_moo_t * r) { +uint8_t stimulus; +uint8_t line; sccp_line_t * l; sccp_speed_t * k = s->device->speed_dials; sccp_channel_t * c; @@ -299,8 +301,8 @@ if (!d) return; - uint8_t stimulus = letohl(r->msg.StimulusMessage.lel_stimulus); - uint8_t line = letohl(r->msg.StimulusMessage.lel_stimulusInstance); + stimulus = letohl(r->msg.StimulusMessage.lel_stimulus); + line = letohl(r->msg.StimulusMessage.lel_stimulusInstance); sccp_log(10)(VERBOSE_PREFIX_3 "%s: Got {StimulusMessage} stimulus=%s (%d) stimulusInstance=%d\n", d->id, skinny_stimulus2str(stimulus), stimulus, line); @@ -468,12 +470,14 @@ } void sccp_handle_onhook(sccp_session_t * s, sccp_moo_t * r) { +sccp_device_t * d; +sccp_channel_t * c; +sccp_channel_t * callwaiting; if (!s || !s->device) { ast_log(LOG_NOTICE, "No device to put OnHook\n"); return; } - sccp_channel_t * c; - sccp_device_t * d = s->device; + d = s->device; /* we need this for callwaiting, hold, answer and stuff */ d->state = SCCP_DEVICESTATE_ONHOOK; sccp_log(1)(VERBOSE_PREFIX_3 "%s is Onhook\n", s->device->id); @@ -497,7 +501,7 @@ /* we are on hook let's ring again the call transfer or the waiting call*/ - sccp_channel_t * callwaiting = sccp_channel_find_bystate_on_device(d, SCCP_CHANNELSTATE_CALLTRANSFER); + callwaiting = sccp_channel_find_bystate_on_device(d, SCCP_CHANNELSTATE_CALLTRANSFER); if (!callwaiting) callwaiting = sccp_channel_find_bystate_on_device(d, SCCP_CHANNELSTATE_CALLWAITING); @@ -625,6 +629,9 @@ } void sccp_handle_keypad_button(sccp_session_t * s, sccp_moo_t * r) { +int event; +char resp = '\0'; +int len = 0; sccp_channel_t * c = sccp_channel_get_active(s->device); if (!c) { @@ -632,9 +639,7 @@ return; } - int event = letohl(r->msg.KeypadButtonMessage.lel_kpButton); - char resp = '\0'; - int len = 0; + event = letohl(r->msg.KeypadButtonMessage.lel_kpButton); sccp_log(1)(VERBOSE_PREFIX_3 "%s: Cisco Digit: %08x (%d) on line %s\n", c->device->id, event, event, c->line->name); @@ -673,15 +678,20 @@ void sccp_handle_soft_key_event(sccp_session_t * s, sccp_moo_t * r) { +sccp_channel_t * c = NULL; +sccp_line_t * l = NULL; +uint32_t event; +uint32_t line; +uint32_t callid; + + sccp_device_t * d = s->device; if (!d) return; - sccp_channel_t * c = NULL; - sccp_line_t * l = NULL; - uint32_t event = letohl(r->msg.SoftKeyEventMessage.lel_softKeyEvent); - uint32_t line = letohl(r->msg.SoftKeyEventMessage.lel_lineInstance); - uint32_t callid = letohl(r->msg.SoftKeyEventMessage.lel_callReference); + event = letohl(r->msg.SoftKeyEventMessage.lel_softKeyEvent); + line = letohl(r->msg.SoftKeyEventMessage.lel_lineInstance); + callid = letohl(r->msg.SoftKeyEventMessage.lel_callReference); if ( event > sizeof(softkeysmap) ) ast_log(LOG_ERROR, "%s: Out of range for Softkey: %s (%d) line=%d callid=%d\n", d->id, skinny_lbl2str(event), event, line, callid); @@ -747,11 +757,12 @@ } void sccp_handle_open_receive_channel_ack(sccp_session_t * s, sccp_moo_t * r) { +struct sockaddr_in sin; +char iabuf[INET_ADDRSTRLEN]; +sccp_channel_t * c; + if (!s) return; - struct sockaddr_in sin; - char iabuf[INET_ADDRSTRLEN]; - sccp_channel_t * c; sin.sin_family = AF_INET; memcpy(&sin.sin_addr, &r->msg.OpenReceiveChannelAck.bel_ipAddr, sizeof(sin.sin_addr)); @@ -834,6 +845,8 @@ } void sccp_handle_forward_stat_req(sccp_session_t * s, sccp_moo_t * r) { +sccp_moo_t * r1 = NULL; + sccp_device_t * d = s->device; if (!d) @@ -841,7 +854,6 @@ sccp_log(10)(VERBOSE_PREFIX_3 "%s: Got Forward Status Request. Line: %d\n", d->id, letohl(r->msg.ForwardStatReqMessage.lel_lineNumber)); - sccp_moo_t * r1 = NULL; REQ(r1, ForwardStatMessage); r1->msg.ForwardStatReqMessage.lel_lineNumber = r->msg.ForwardStatReqMessage.lel_lineNumber; /* XXX add support */ --- sccp_channel.c-org Thu Jul 14 08:53:06 2005 +++ sccp_channel.c Thu Jul 14 09:46:56 2005 @@ -30,6 +30,8 @@ AST_MUTEX_DEFINE_STATIC(callCountLock); sccp_channel_t * sccp_channel_allocate(sccp_line_t * l) { +sccp_device_t * d; + /* this just allocate a sccp channel (not the asterisk channel, for that look at sccp_pbx_channel_allocate) */ sccp_channel_t * c = NULL; @@ -39,7 +41,7 @@ return NULL; } - sccp_device_t * d = l->device; + d = l->device; if (!d->session) { ast_log(LOG_ERROR, "SCCP: Tried to open channel on device %s without a session\n", d->id); @@ -145,12 +147,12 @@ // XXX:T: whoops - need to move to device. void sccp_channel_set_callstate(sccp_channel_t * c, uint8_t state) { +sccp_moo_t * r; c->callstate = state; if (c->device->type < 6 || (c->device->type > 8 && c->device->type <= 255)) return; /* only for telecaster */ - sccp_moo_t * r; REQ(r, CallStateMessage) r->msg.CallStateMessage.lel_callState = htolel(state); @@ -162,10 +164,11 @@ } void sccp_channel_set_callingparty(sccp_channel_t * c, char *name, char *number) { +sccp_device_t * d; if (!c) return; - sccp_device_t * d = c->device; + d = c->device; if (name && strncmp(name, c->callingPartyName, StationMaxNameSize - 1)) { sccp_copy_string(c->callingPartyName, name, StationMaxNameSize); @@ -182,10 +185,12 @@ } void sccp_channel_set_calledparty(sccp_channel_t * c, char *name, char *number) { +sccp_device_t * d; + if (!c) return; - sccp_device_t * d = c->device; + d = c->device; if (name && strncmp(name, c->calledPartyName, StationMaxNameSize - 1)) { sccp_copy_string(c->calledPartyName, name, StationMaxNameSize); @@ -292,12 +297,13 @@ } void sccp_channel_endcall(sccp_channel_t * c) { +sccp_device_t * d; if (!c) return; /* this is a station active endcall or onhook */ - sccp_device_t * d = c->device; + d = c->device; sccp_log(1)(VERBOSE_PREFIX_3 "%s: Ending call %d on line %s\n", d->id, c->callid, c->line->name); ast_mutex_lock(&c->lock); @@ -328,6 +334,10 @@ } void sccp_channel_newcall(sccp_line_t * l, char * dial) { +sccp_channel_t * c; +sccp_device_t * d; +pthread_attr_t attr; + /* handle outgoing calls */ pthread_t t; @@ -336,8 +346,7 @@ return; } - sccp_channel_t * c; - sccp_device_t * d = l->device; + d = l->device; /* look if we have a call to put on hold */ if ( (c = sccp_channel_get_active(d)) ) { @@ -378,7 +387,6 @@ sccp_channel_set_active(c); sccp_indicate_lock(c, SCCP_CHANNELSTATE_OFFHOOK); - pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); /* let's call it */ @@ -390,11 +398,14 @@ } void sccp_channel_answer(sccp_channel_t * c) { +sccp_line_t * l; +sccp_device_t * d; +sccp_channel_t * hold; + if (!c) return; - sccp_line_t * l = c->line; - sccp_device_t * d = c->line->device; - sccp_channel_t * hold; + l = c->line; + d = c->line->device; /* answering and incoming call */ /* look if we have a call to put on hold */ @@ -422,10 +433,14 @@ } int sccp_channel_hold(sccp_channel_t * c) { +sccp_line_t * l; +sccp_device_t * d; +struct ast_channel * peer; + if (!c) return 0; - sccp_line_t * l = c->line; - sccp_device_t * d = c->line->device; + l = c->line; + d = c->line->device; if (c->state == SCCP_CHANNELSTATE_HOLD) return 0; @@ -437,7 +452,7 @@ sccp_dev_displayprompt(NULL, c, "No active call to put on hold.",5); return 0; } - struct ast_channel * peer = CS_AST_BRIDGED_CHANNEL(c->owner); + peer = CS_AST_BRIDGED_CHANNEL(c->owner); if (!peer) { ast_log(LOG_ERROR, "%s can't put on hold this type of channel %s-%d\n", d->id, l->name, c->callid); @@ -461,12 +476,14 @@ } int sccp_channel_resume(sccp_channel_t * c) { +sccp_line_t * l; +sccp_device_t * d; +sccp_channel_t * hold; + if (!c) return 0; - sccp_line_t * l = c->line; - sccp_device_t * d = c->line->device; - - sccp_channel_t * hold; + l = c->line; + d = c->line->device; /* look if we have a call to put on hold */ if ( (hold = sccp_channel_get_active(d)) ) { @@ -512,11 +529,14 @@ } void sccp_channel_delete(sccp_channel_t * c) { +sccp_line_t * l; +sccp_device_t * d; + if (!c) return; - sccp_line_t * l = c->line; - sccp_device_t * d = c->device; + l = c->line; + d = c->device; sccp_log(10)(VERBOSE_PREFIX_3 "%s: Deleting channel %d from line %s\n", d->id, c->callid, c->line->name); @@ -651,13 +671,15 @@ } void sccp_channel_transfer_complete(sccp_channel_t * c) { - sccp_device_t * d = c->device; +sccp_device_t * d; +sccp_channel_t * peer; +struct ast_channel *chana = NULL, *chanb = NULL, * beep = NULL; + + d = c->device; ast_mutex_lock(&d->lock); - sccp_channel_t * peer = d->transfer_channel; + peer = d->transfer_channel; ast_mutex_unlock(&d->lock); - - struct ast_channel *chana = NULL, *chanb = NULL, * beep = NULL; if (!c->owner || !peer->owner) { sccp_log(1)(VERBOSE_PREFIX_3 "%s: Transfer error, asterisk channel error %s-%d and %s-%d\n", d->id, c->line->name, c->callid, peer->line->name, peer->callid); --- sccp_device.c-org Thu Jul 14 09:47:26 2005 +++ sccp_device.c Thu Jul 14 09:52:09 2005 @@ -31,6 +31,7 @@ } int sccp_session_send(sccp_session_t * s, sccp_moo_t * r) { +ssize_t res = 1; if (!s || s->fd <= 0) { ast_log(LOG_ERROR, "Tried to send packet over DOWN device.\n"); @@ -38,8 +39,6 @@ return -1; } - ssize_t res = 1; - /* sccp_log(10)(VERBOSE_PREFIX_3 "%s: Sending Packet Type %s (%d bytes)\n", s->device->id, sccpmsg2str(letohl(r->lel_messageId)), r->length); */ ast_mutex_lock(&s->lock); @@ -79,6 +78,8 @@ } void sccp_dev_set_keyset(sccp_device_t * d, uint8_t line, uint32_t callid, uint8_t opt) { +sccp_moo_t * r; + if (!d || !d->session) return; @@ -88,8 +89,6 @@ if (opt == KEYMODE_CONNECTED) opt = ( (d->transfer) ? KEYMODE_CONNTRANS : KEYMODE_CONNECTED ); - sccp_moo_t * r; - REQ(r, SelectSoftKeysMessage) r->msg.SelectSoftKeysMessage.lel_lineInstance = htolel(line); r->msg.SelectSoftKeysMessage.lel_callReference = htolel(callid); @@ -108,11 +107,11 @@ /* Turns the lamp on the handset of device 'd' into mode 'opt' */ // XXX:T: prehaps though should be sccp_line_set_mwi(l, 1) ? void sccp_dev_set_mwi(sccp_device_t * d, uint8_t line, uint8_t hasMail) { +sccp_moo_t * r; + if (!d->session) return; - sccp_moo_t * r; - REQ(r, SetLampMessage) r->msg.SetLampMessage.lel_stimulus = htolel(0xF); // 0xF == "SsVoiceMail" // XXX verify if instance needs to be 0 @@ -126,10 +125,11 @@ } void sccp_dev_set_ringer(sccp_device_t * d, uint8_t opt) { +sccp_moo_t * r; + if (!d->session) return; - sccp_moo_t * r; REQ(r, SetRingerMessage) r->msg.SetRingerMessage.lel_ringMode = htolel(opt); sccp_dev_send(d, r); @@ -137,10 +137,10 @@ } void sccp_dev_set_speaker(sccp_device_t * d, uint8_t mode) { +sccp_moo_t * r; if (!d->session) return; - sccp_moo_t * r; REQ(r, SetSpeakerModeMessage) r->msg.SetSpeakerModeMessage.lel_speakerMode = htolel(mode); sccp_dev_send(d, r); @@ -148,11 +148,11 @@ } void sccp_dev_set_microphone(sccp_device_t * d, uint8_t mode) { +sccp_moo_t * r; if (!d->session) return; - sccp_moo_t * r; REQ(r, SetMicroModeMessage) r->msg.SetMicroModeMessage.lel_micMode = htolel(mode); sccp_dev_send(d, r); @@ -160,14 +160,16 @@ } void sccp_dev_set_cplane(sccp_line_t * l, int status) { +sccp_device_t * d; +sccp_moo_t * r; + if (l->device->type < 6 || (l->device->type > 8 && l->device->type <= 255)) return; /* only for telecaster and new phones */ - sccp_device_t * d = l->device; + d = l->device; if (!d->session) return; - sccp_moo_t * r; REQ(r, ActivateCallPlaneMessage) if (status) r->msg.ActivateCallPlaneMessage.lel_lineInstance = htolel(l->instance); @@ -176,25 +178,28 @@ } void sccp_dev_set_deactivate_cplane(sccp_channel_t * c) { +sccp_device_t * d; +sccp_line_t * l; + if (c->device->type < 6 || (c->device->type > 8 && c->device->type <= 255)) return; /* only for telecaster and new phones */ - sccp_device_t * d = c->device; + d = c->device; if (!d->session) return; - sccp_line_t * l = c->line; + l = c->line; sccp_dev_sendmsg(d, DeactivateCallPlaneMessage); sccp_log(10)(VERBOSE_PREFIX_3 "%s: Send deactivate call plane on line %d\n", d->id, (l) ? l->instance : 0); } void sccp_dev_starttone(sccp_device_t * d, uint8_t tone) { +sccp_moo_t * r; + if (!d->session) return; - sccp_moo_t * r; - // sccp_dev_stoptone(d); /* 7910 need this */ REQ(r, StartToneMessage) @@ -209,9 +214,10 @@ } void sccp_dev_stoptone(sccp_device_t * d) { +sccp_moo_t * r; + if (!d) return; - sccp_moo_t * r; REQ(r, StopToneMessage); sccp_dev_send(d, r); d->currentTone = 0; @@ -226,6 +232,8 @@ } void sccp_dev_clearprompt(sccp_device_t * d, sccp_channel_t * c) { +sccp_moo_t * r; + if (c) d = c->device; if (!d->session) @@ -233,8 +241,6 @@ if (d->type < 6 || (d->type > 8 && d->type <= 255)) return; /* only for telecaster and new phones */ - sccp_moo_t * r; - REQ(r, ClearPromptStatusMessage) r->msg.ClearPromptStatusMessage.lel_callReference = htolel( (c) ? c->callid : 0); r->msg.ClearPromptStatusMessage.lel_lineInstance = htolel((c) ? c->line->instance : 0); @@ -245,14 +251,14 @@ void sccp_dev_displayprompt(sccp_device_t * d, sccp_channel_t * c, char * msg, int timeout) { +sccp_moo_t * r; + if (c) d = c->device; if (!d->session) return; if (d->type < 6 || (d->type > 8 && d->type <= 255)) return; /* only for telecaster and new phones */ - - sccp_moo_t * r; if (!msg || ast_strlen_zero(msg)) return; --- sccp_indicate.c-org Thu Jul 14 10:01:29 2005 +++ sccp_indicate.c Thu Jul 14 10:02:18 2005 @@ -30,6 +30,8 @@ } void sccp_indicate_nolock(sccp_channel_t * c, uint8_t state) { +sccp_device_t * d; +sccp_line_t * l; if (!c) { ast_log(LOG_ERROR, "SCCP: No channel, nothing to indicate?\n"); @@ -40,14 +42,14 @@ return; } - sccp_device_t * d = c->device; + d = c->device; if (!c->line) { ast_log(LOG_ERROR, "SCCP: The channel %d does not have a line\n",c->callid); return; } - sccp_line_t * l = c->line; + l = c->line; /* all the check are ok. We can safely run all the dev functions with no more checks */ sccp_log(10)(VERBOSE_PREFIX_3 "%s: Indicate state (%s) on call %s-%d\n",d->id, sccp_indicate2str(state), l->name, c->callid); --- sccp_pbx.c-org Thu Jul 14 09:56:26 2005 +++ sccp_pbx.c Thu Jul 14 09:58:18 2005 @@ -28,12 +28,13 @@ static struct ast_frame * sccp_rtp_read(sccp_channel_t * c) { /* Retrieve audio/etc from channel. Assumes c->lock is already held. */ +struct ast_frame * f; /* if c->rtp not null */ if (!c->rtp) return NULL; - struct ast_frame * f = ast_rtp_read(c->rtp); + f = ast_rtp_read(c->rtp); if (c->owner) { /* We already hold the channel lock */ @@ -133,6 +134,8 @@ static int sccp_pbx_hangup(struct ast_channel * ast) { sccp_channel_t * c; +sccp_line_t * l; +sccp_device_t * d; c = CS_AST_CHANNEL_PVT(ast); @@ -150,8 +153,8 @@ ast_mutex_lock(&c->lock); c->owner = NULL; - sccp_line_t * l = c->line; - sccp_device_t * d = l->device; + l = c->line; + d = l->device; sccp_log(1)(VERBOSE_PREFIX_3 "SCCP: Asterisk request to hangup %s channel %s\n", (c->isOutgoing) ? "outgoing" : "incoming", ast->name); @@ -191,6 +194,7 @@ } static int sccp_pbx_answer(struct ast_channel *ast) { +sccp_line_t * l; sccp_channel_t * c = CS_AST_CHANNEL_PVT(ast); if (!c) { @@ -198,7 +202,7 @@ return -1; } - sccp_line_t * l = c->line; + l = c->line; sccp_log(1)(VERBOSE_PREFIX_3 "SCCP: Outgoing call has been answered %s on %s@%s-%d\n", ast->name, l->name, l->device->id, c->callid); sccp_indicate_lock(c, SCCP_CHANNELSTATE_CONNECTED); --- sccp_socket.c-org Thu Jul 14 09:59:39 2005 +++ sccp_socket.c Thu Jul 14 10:01:13 2005 @@ -98,11 +98,13 @@ } static void destroy_session(sccp_session_t * s) { +sccp_line_t * l, * l1 = NULL; +sccp_device_t * d; +char iabuf[INET_ADDRSTRLEN]; + if (!s) return; - sccp_line_t * l, * l1 = NULL; - sccp_device_t * d = s->device; - char iabuf[INET_ADDRSTRLEN]; + d = s->device; ast_mutex_lock(&GLOB(devices_lock)); @@ -148,6 +150,9 @@ static void sccp_accept_connection(void) { +int on; +int tos; + /* called without GLOB(sessions_lock) */ struct sockaddr_in incoming; sccp_session_t * s; @@ -166,8 +171,8 @@ return; } - int on = 1; - int tos = IPTOS_LOWDELAY; + on = 1; + tos = IPTOS_LOWDELAY; if (setsockopt(new_socket, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0) ast_log(LOG_WARNING, "Failed to set SCCP socket to SO_REUSEADDR mode: %s\n", strerror(errno)); if (setsockopt(new_socket, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) < 0) --- sccp_softkeys.c-org Thu Jul 14 09:58:39 2005 +++ sccp_softkeys.c Thu Jul 14 09:59:22 2005 @@ -114,12 +114,14 @@ void sccp_sk_backspace(sccp_device_t * d, sccp_line_t * l, sccp_channel_t * c) { +int len; + if (!c) return; if (c->state != SCCP_CHANNELSTATE_DIALING) return; ast_mutex_lock(&c->lock); - int len = strlen(c->owner->exten)-1; + len = strlen(c->owner->exten)-1; if (len >= 0) c->owner->exten[len] = '\0'; sccp_log(10)(VERBOSE_PREFIX_3 "%s: backspacing dial number %s\n", c->device->id, c->owner->exten); --- sccp_utils.c-org Thu Jul 14 09:52:39 2005 +++ sccp_utils.c Thu Jul 14 09:56:05 2005 @@ -53,8 +53,8 @@ /* XXX check this */ sccp_line_t * sccp_line_find_byname(const char * name) { +sccp_line_t * l; sccp_log(10)(VERBOSE_PREFIX_3 "SCCP: Looking for line %s\n", name); - sccp_line_t * l; if (!(l = GLOB(lines) )) return NULL; @@ -69,10 +69,11 @@ } sccp_line_t * sccp_line_find_byid(sccp_device_t * d, uint8_t instance) { +sccp_line_t * l; + if (!d) return NULL; sccp_log(10)(VERBOSE_PREFIX_3 "%s: Looking for line by instance %d\n", d->id, instance); - sccp_line_t * l; ast_mutex_lock(&d->lock); l = d->lines; @@ -88,8 +89,8 @@ } sccp_channel_t * sccp_channel_find_byid(uint32_t id) { +sccp_channel_t * c; sccp_log(10)(VERBOSE_PREFIX_3 "SCCP: Looking for channel by id %d\n", id); - sccp_channel_t * c; ast_mutex_lock(&GLOB(channels_lock)); c = GLOB(channels); while (c) { @@ -104,8 +105,8 @@ } sccp_channel_t * sccp_channel_find_byid_on_line(sccp_line_t * l, uint32_t id) { +sccp_channel_t * c; sccp_log(10)(VERBOSE_PREFIX_3 "SCCP: Looking for channel by id %d\n", id); - sccp_channel_t * c; ast_mutex_lock(&l->lock); c = l->channels; while (c) { @@ -120,10 +121,11 @@ } sccp_channel_t * sccp_channel_find_bystate_on_line(sccp_line_t * l, uint8_t state) { +sccp_channel_t * c; + if (!l) return NULL; sccp_log(10)(VERBOSE_PREFIX_3 "%s: Looking for a channel with state \"%s\" (%d) on line %s\n", l->device->id, sccp_indicate2str(state), state, l->name); - sccp_channel_t * c; ast_mutex_lock(&l->lock); c = l->channels; while (c) { @@ -138,11 +140,12 @@ } sccp_channel_t * sccp_channel_find_bystate_on_device(sccp_device_t * d, uint8_t state) { +sccp_channel_t * c = NULL; +sccp_line_t * l = NULL; + if (!d) return NULL; sccp_log(10)(VERBOSE_PREFIX_3 "%s: Looking for a channel with state \"%s\" (%d) on device\n", d->id, sccp_indicate2str(state), state); - sccp_channel_t * c = NULL; - sccp_line_t * l = NULL; ast_mutex_lock(&d->lock); l = d->lines; while (l) { @@ -160,9 +163,9 @@ sccp_channel_t * sccp_channel_find_bypartyid(uint32_t id) { /* this is for openreceivechannelack */ /* XXX need to optimize this func */ +sccp_channel_t * c; sccp_log(10)(VERBOSE_PREFIX_3 "SCCP: Looking for a channel with pointer (%d)\n", id); - sccp_channel_t * c; ast_mutex_lock(&GLOB(channels_lock)); c = GLOB(channels); while (c) { @@ -178,12 +181,13 @@ } int sccp_line_hasmessages(sccp_line_t * l) { +sccp_device_t * d; int newmsgs, oldmsgs; int totalmsgs = 0; char tmp[AST_MAX_EXTENSION] = "", * mb, * cur; sccp_copy_string(tmp, l->mailbox, sizeof(tmp)); mb = tmp; - sccp_device_t * d = l->device; + d = l->device; while((cur = strsep(&mb, ","))) { if (strlen(cur)) { @@ -221,9 +225,9 @@ } void sccp_dev_dbput(sccp_device_t * d) { +char tmp[256]; if (!d) return; - char tmp[256]; snprintf(tmp, sizeof(tmp), "dnd=%d,cfwdall=,cfwdbusy=,cfwdnoanswer=", d->dnd); sccp_log(10)(VERBOSE_PREFIX_3 "%s: Storing device status (dnd, cfwd*) in the asterisk db\n", d->id); if (ast_db_put("SCCP", d->id, tmp)) @@ -231,10 +235,11 @@ } void sccp_dev_dbget(sccp_device_t * d) { +char result[256]="", *tmp, *tmp1, *r; +int i=0; + if (!d) return; - char result[256]="", *tmp, *tmp1, *r; - int i=0; sccp_log(10)(VERBOSE_PREFIX_3 "%s: Restoring device status (dnd, cfwd*) from the asterisk db\n", d->id); if (ast_db_get("SCCP", d->id, result, sizeof(result))) { return;