summaryrefslogtreecommitdiff
path: root/pbx
diff options
context:
space:
mode:
authorRussell Bryant <russell@russellbryant.com>2006-11-10 04:30:23 +0000
committerRussell Bryant <russell@russellbryant.com>2006-11-10 04:30:23 +0000
commit74b6314d5008ec50e1e770aa01adbfe31df1dfc8 (patch)
treed660f4a2cbcee14c452d20aea308c67e864c0ddf /pbx
parent2b2693499d1cc61376540b7138acadc7eff443da (diff)
Various little bits of code cleanup to reduce nesting, remove useless casts,
and to remove a duplicated error message after a memory allocation error git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@47410 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'pbx')
-rw-r--r--pbx/pbx_dundi.c76
1 files changed, 37 insertions, 39 deletions
diff --git a/pbx/pbx_dundi.c b/pbx/pbx_dundi.c
index 87a13af53..b8ebf1b13 100644
--- a/pbx/pbx_dundi.c
+++ b/pbx/pbx_dundi.c
@@ -330,31 +330,28 @@ static struct dundi_transaction *find_transaction(struct dundi_hdr *hdr, struct
((trans->dtrans == (ntohs(hdr->strans) & 32767)) && (!hdr->dtrans))) /* We match their destination */) {
if (hdr->strans)
trans->dtrans = ntohs(hdr->strans) & 32767;
- break;
+ return trans;
}
}
- if (!trans) {
- switch(hdr->cmdresp & 0x7f) {
- case DUNDI_COMMAND_DPDISCOVER:
- case DUNDI_COMMAND_EIDQUERY:
- case DUNDI_COMMAND_PRECACHERQ:
- case DUNDI_COMMAND_REGREQ:
- case DUNDI_COMMAND_NULL:
- case DUNDI_COMMAND_ENCRYPT:
- if (hdr->strans) {
- /* Create new transaction */
- trans = create_transaction(NULL);
- if (trans) {
- memcpy(&trans->addr, sin, sizeof(trans->addr));
- trans->dtrans = ntohs(hdr->strans) & 32767;
- } else
- ast_log(LOG_WARNING, "Out of memory!\n");
- }
+
+ switch(hdr->cmdresp & 0x7f) {
+ case DUNDI_COMMAND_DPDISCOVER:
+ case DUNDI_COMMAND_EIDQUERY:
+ case DUNDI_COMMAND_PRECACHERQ:
+ case DUNDI_COMMAND_REGREQ:
+ case DUNDI_COMMAND_NULL:
+ case DUNDI_COMMAND_ENCRYPT:
+ if (!hdr->strans)
break;
- default:
+ /* Create new transaction */
+ if (!(trans = create_transaction(NULL)))
break;
- }
+ memcpy(&trans->addr, sin, sizeof(trans->addr));
+ trans->dtrans = ntohs(hdr->strans) & 32767;
+ default:
+ break;
}
+
return trans;
}
@@ -1985,8 +1982,8 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
int res;
struct dundi_hdr *h;
char buf[MAX_PACKET_SIZE];
- socklen_t len;
- len = sizeof(sin);
+ socklen_t len = sizeof(sin);
+
res = recvfrom(netsocket, buf, sizeof(buf) - 1, 0,(struct sockaddr *) &sin, &len);
if (res < 0) {
if (errno != ECONNREFUSED)
@@ -1994,11 +1991,11 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
return 1;
}
if (res < sizeof(struct dundi_hdr)) {
- ast_log(LOG_WARNING, "midget packet received (%d of %d min)\n", res, (int)sizeof(struct dundi_hdr));
+ ast_log(LOG_WARNING, "midget packet received (%d of %d min)\n", res, sizeof(struct dundi_hdr));
return 1;
}
buf[res] = '\0';
- h = (struct dundi_hdr *)buf;
+ h = (struct dundi_hdr *) buf;
if (dundidebug)
dundi_showframe(h, 1, &sin, res - sizeof(struct dundi_hdr));
AST_LIST_LOCK(&peers);
@@ -2777,22 +2774,23 @@ static struct dundi_transaction *create_transaction(struct dundi_peer *p)
tid = get_trans_id();
if (tid < 1)
return NULL;
- trans = ast_calloc(1, sizeof(*trans));
- if (trans) {
- if (global_storehistory) {
- trans->start = ast_tvnow();
- ast_set_flag(trans, FLAG_STOREHIST);
- }
- trans->retranstimer = DUNDI_DEFAULT_RETRANS_TIMER;
- trans->autokillid = -1;
- if (p) {
- apply_peer(trans, p);
- if (!p->sentfullkey)
- ast_set_flag(trans, FLAG_SENDFULLKEY);
- }
- trans->strans = tid;
- AST_LIST_INSERT_HEAD(&alltrans, trans, all);
+ if (!(trans = ast_calloc(1, sizeof(*trans))))
+ return NULL;
+
+ if (global_storehistory) {
+ trans->start = ast_tvnow();
+ ast_set_flag(trans, FLAG_STOREHIST);
+ }
+ trans->retranstimer = DUNDI_DEFAULT_RETRANS_TIMER;
+ trans->autokillid = -1;
+ if (p) {
+ apply_peer(trans, p);
+ if (!p->sentfullkey)
+ ast_set_flag(trans, FLAG_SENDFULLKEY);
}
+ trans->strans = tid;
+ AST_LIST_INSERT_HEAD(&alltrans, trans, all);
+
return trans;
}