formatting cleanup (bug #4330)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5737 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.2-netsec
Kevin P. Fleming 21 years ago
parent 6ac98c6724
commit d5b50fc83d

@ -1356,22 +1356,23 @@ static struct sip_peer *realtime_peer(const char *peername, struct sockaddr_in *
/* Peer found in realtime, now build it in memory */ /* Peer found in realtime, now build it in memory */
peer = build_peer(newpeername, var, !ast_test_flag((&global_flags_page2), SIP_PAGE2_RTCACHEFRIENDS)); peer = build_peer(newpeername, var, !ast_test_flag((&global_flags_page2), SIP_PAGE2_RTCACHEFRIENDS));
if (peer) { if (!peer) {
if (ast_test_flag((&global_flags_page2), SIP_PAGE2_RTCACHEFRIENDS)) { ast_variables_destroy(var);
/* Cache peer */ return (struct sip_peer *) NULL;
ast_copy_flags((&peer->flags_page2),(&global_flags_page2), SIP_PAGE2_RTAUTOCLEAR|SIP_PAGE2_RTCACHEFRIENDS); }
if (ast_test_flag((&global_flags_page2), SIP_PAGE2_RTAUTOCLEAR)) { if (ast_test_flag((&global_flags_page2), SIP_PAGE2_RTCACHEFRIENDS)) {
if (peer->expire > -1) { /* Cache peer */
ast_sched_del(sched, peer->expire); ast_copy_flags((&peer->flags_page2),(&global_flags_page2), SIP_PAGE2_RTAUTOCLEAR|SIP_PAGE2_RTCACHEFRIENDS);
} if (ast_test_flag((&global_flags_page2), SIP_PAGE2_RTAUTOCLEAR)) {
peer->expire = ast_sched_add(sched, (global_rtautoclear) * 1000, expire_register, (void *)peer); if (peer->expire > -1) {
ast_sched_del(sched, peer->expire);
} }
ASTOBJ_CONTAINER_LINK(&peerl,peer); peer->expire = ast_sched_add(sched, (global_rtautoclear) * 1000, expire_register, (void *)peer);
} else {
ast_set_flag(peer, SIP_REALTIME);
} }
ASTOBJ_CONTAINER_LINK(&peerl,peer);
} else {
ast_set_flag(peer, SIP_REALTIME);
} }
ast_variables_destroy(var); ast_variables_destroy(var);
return peer; return peer;
} }
@ -1448,17 +1449,20 @@ static struct sip_user *realtime_user(const char *username)
user = build_user(username, var, !ast_test_flag((&global_flags_page2), SIP_PAGE2_RTCACHEFRIENDS)); user = build_user(username, var, !ast_test_flag((&global_flags_page2), SIP_PAGE2_RTCACHEFRIENDS));
if (user) { if (!user) { /* No user found */
if (ast_test_flag((&global_flags_page2), SIP_PAGE2_RTCACHEFRIENDS)) { ast_variables_destroy(var);
ast_set_flag((&user->flags_page2), SIP_PAGE2_RTCACHEFRIENDS); return NULL;
suserobjs++; }
ASTOBJ_CONTAINER_LINK(&userl,user);
} else { if (ast_test_flag((&global_flags_page2), SIP_PAGE2_RTCACHEFRIENDS)) {
/* Move counter from s to r... */ ast_set_flag((&user->flags_page2), SIP_PAGE2_RTCACHEFRIENDS);
suserobjs--; suserobjs++;
ruserobjs++; ASTOBJ_CONTAINER_LINK(&userl,user);
ast_set_flag(user, SIP_REALTIME); } else {
} /* Move counter from s to r... */
suserobjs--;
ruserobjs++;
ast_set_flag(user, SIP_REALTIME);
} }
ast_variables_destroy(var); ast_variables_destroy(var);
return user; return user;
@ -2608,7 +2612,7 @@ static void build_callid(char *callid, int len, struct in_addr ourip, char *from
int val; int val;
int x; int x;
char iabuf[INET_ADDRSTRLEN]; char iabuf[INET_ADDRSTRLEN];
for (x=0;x<4;x++) { for (x=0; x<4; x++) {
val = rand(); val = rand();
res = snprintf(callid, len, "%08x", val); res = snprintf(callid, len, "%08x", val);
len -= res; len -= res;
@ -2698,6 +2702,7 @@ static struct sip_pvt *sip_alloc(char *callid, struct sockaddr_in *sin, int useg
if (ast_test_flag(p, SIP_DTMF) == SIP_DTMF_RFC2833) if (ast_test_flag(p, SIP_DTMF) == SIP_DTMF_RFC2833)
p->noncodeccapability |= AST_RTP_DTMF; p->noncodeccapability |= AST_RTP_DTMF;
strcpy(p->context, default_context); strcpy(p->context, default_context);
/* Add to active dialog list */ /* Add to active dialog list */
ast_mutex_lock(&iflock); ast_mutex_lock(&iflock);
p->next = iflist; p->next = iflist;
@ -2981,6 +2986,7 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req)
int sendonly = 0; int sendonly = 0;
int x,y; int x,y;
int debug=sip_debug_test_pvt(p); int debug=sip_debug_test_pvt(p);
struct ast_channel *bridgepeer = NULL;
/* Update our last rtprx when we receive an SDP, too */ /* Update our last rtprx when we receive an SDP, too */
time(&p->lastrtprx); time(&p->lastrtprx);
@ -3166,40 +3172,42 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req)
ast_log(LOG_NOTICE, "No compatible codecs!\n"); ast_log(LOG_NOTICE, "No compatible codecs!\n");
return -1; return -1;
} }
if (p->owner) { /* There's an open channel owning us */
struct ast_channel *bridgepeer = NULL; if (!p->owner) /* There's no open channel owning us */
if (!(p->owner->nativeformats & p->jointcapability)) { return 0;
const unsigned slen=512;
char s1[slen], s2[slen]; if (!(p->owner->nativeformats & p->jointcapability)) {
ast_log(LOG_DEBUG, "Oooh, we need to change our formats since our peer supports only %s and not %s\n", const unsigned slen=512;
ast_getformatname_multiple(s1, slen, p->jointcapability), char s1[slen], s2[slen];
ast_getformatname_multiple(s2, slen, p->owner->nativeformats)); ast_log(LOG_DEBUG, "Oooh, we need to change our formats since our peer supports only %s and not %s\n",
p->owner->nativeformats = ast_codec_choose(&p->prefs, p->jointcapability, 1); ast_getformatname_multiple(s1, slen, p->jointcapability),
ast_set_read_format(p->owner, p->owner->readformat); ast_getformatname_multiple(s2, slen, p->owner->nativeformats));
ast_set_write_format(p->owner, p->owner->writeformat); p->owner->nativeformats = ast_codec_choose(&p->prefs, p->jointcapability, 1);
} ast_set_read_format(p->owner, p->owner->readformat);
if ((bridgepeer=ast_bridged_channel(p->owner))) { ast_set_write_format(p->owner, p->owner->writeformat);
/* We have a bridge */ }
/* Turn on/off music on hold if we are holding/unholding */ if ((bridgepeer=ast_bridged_channel(p->owner))) {
if (sin.sin_addr.s_addr && !sendonly) { /* We have a bridge */
ast_moh_stop(bridgepeer); /* Turn on/off music on hold if we are holding/unholding */
/* Indicate UNHOLD status to the other channel */ if (sin.sin_addr.s_addr && !sendonly) {
ast_indicate(bridgepeer, AST_CONTROL_UNHOLD); ast_moh_stop(bridgepeer);
append_history(p, "Unhold", req->data); /* Indicate UNHOLD status to the other channel */
if (callevents && ast_test_flag(p, SIP_CALL_ONHOLD)) { ast_indicate(bridgepeer, AST_CONTROL_UNHOLD);
manager_event(EVENT_FLAG_CALL, "Unhold", append_history(p, "Unhold", req->data);
"Channel: %s\r\n" if (callevents && ast_test_flag(p, SIP_CALL_ONHOLD)) {
"Uniqueid: %s\r\n", manager_event(EVENT_FLAG_CALL, "Unhold",
p->owner->name, "Channel: %s\r\n"
p->owner->uniqueid); "Uniqueid: %s\r\n",
} p->owner->name,
ast_clear_flag(p, SIP_CALL_ONHOLD); p->owner->uniqueid);
/* Somehow, we need to check if we need to re-invite here */ }
/* If this call had a native bridge, it's broken ast_clear_flag(p, SIP_CALL_ONHOLD);
now and we need to start all over again. /* Somehow, we need to check if we need to re-invite here */
The bridged peer, if SIP, now listens /* If this call had a external native bridge, it's broken
to RTP from Asterisk instead of from now and we need to start all over again.
the peer The bridged peer, if SIP, now listens
to RTP from Asterisk instead of from
the peer
So IF we had a native bridge before So IF we had a native bridge before
the HOLD, we need to somehow re-invite the HOLD, we need to somehow re-invite
@ -3207,27 +3215,25 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req)
*/ */
} else { } else {
/* No address for RTP, we're on hold */ /* No address for RTP, we're on hold */
append_history(p, "Hold", req->data); append_history(p, "Hold", req->data);
if (callevents && !ast_test_flag(p, SIP_CALL_ONHOLD)) { if (callevents && !ast_test_flag(p, SIP_CALL_ONHOLD)) {
manager_event(EVENT_FLAG_CALL, "Hold", manager_event(EVENT_FLAG_CALL, "Hold",
"Channel: %s\r\n" "Channel: %s\r\n"
"Uniqueid: %s\r\n", "Uniqueid: %s\r\n",
p->owner->name, p->owner->name,
p->owner->uniqueid); p->owner->uniqueid);
}
ast_set_flag(p, SIP_CALL_ONHOLD);
/* Indicate HOLD status to the other channel */
ast_indicate(bridgepeer, AST_CONTROL_HOLD);
ast_moh_start(bridgepeer, NULL);
if (sendonly)
ast_rtp_stop(p->rtp);
} }
ast_set_flag(p, SIP_CALL_ONHOLD);
/* Indicate HOLD status to the other channel */
ast_indicate(bridgepeer, AST_CONTROL_HOLD);
ast_moh_start(bridgepeer, NULL);
if (sendonly)
ast_rtp_stop(p->rtp);
} }
} }
return 0; return 0;
} }
/*--- add_header: Add header to SIP message */ /*--- add_header: Add header to SIP message */
@ -3256,12 +3262,11 @@ static int add_header(struct sip_request *req, char *var, char *value)
snprintf(req->header[req->headers], sizeof(req->data) - req->len - 4, "%s: %s\r\n", var, value); snprintf(req->header[req->headers], sizeof(req->data) - req->len - 4, "%s: %s\r\n", var, value);
} }
req->len += strlen(req->header[req->headers]); req->len += strlen(req->header[req->headers]);
if (req->headers < SIP_MAX_HEADERS) if (req->headers == SIP_MAX_HEADERS) {
req->headers++; ast_log(LOG_WARNING, "Out of SIP header space\n");
else {
ast_log(LOG_WARNING, "Out of header space\n");
return -1; return -1;
} }
req->headers++;
return 0; return 0;
} }
@ -3279,12 +3284,11 @@ static int add_blank_header(struct sip_request *req)
req->header[req->headers] = req->data + req->len; req->header[req->headers] = req->data + req->len;
snprintf(req->header[req->headers], sizeof(req->data) - req->len, "\r\n"); snprintf(req->header[req->headers], sizeof(req->data) - req->len, "\r\n");
req->len += strlen(req->header[req->headers]); req->len += strlen(req->header[req->headers]);
if (req->headers < SIP_MAX_HEADERS) if (req->headers == SIP_MAX_HEADERS) {
req->headers++; ast_log(LOG_WARNING, "Out of SIP header space\n");
else {
ast_log(LOG_WARNING, "Out of header space\n");
return -1; return -1;
} }
req->headers++;
return 0; return 0;
} }
@ -3303,12 +3307,11 @@ static int add_line(struct sip_request *req, const char *line)
req->line[req->lines] = req->data + req->len; req->line[req->lines] = req->data + req->len;
snprintf(req->line[req->lines], sizeof(req->data) - req->len, "%s", line); snprintf(req->line[req->lines], sizeof(req->data) - req->len, "%s", line);
req->len += strlen(req->line[req->lines]); req->len += strlen(req->line[req->lines]);
if (req->lines < SIP_MAX_LINES) if (req->lines == SIP_MAX_LINES) {
req->lines++; ast_log(LOG_WARNING, "Out of SIP line space\n");
else {
ast_log(LOG_WARNING, "Out of line space\n");
return -1; return -1;
} }
req->lines++;
return 0; return 0;
} }

Loading…
Cancel
Save