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
1.6.0
Russell Bryant 19 years ago
parent 2b2693499d
commit 74b6314d50

@ -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 */) { ((trans->dtrans == (ntohs(hdr->strans) & 32767)) && (!hdr->dtrans))) /* We match their destination */) {
if (hdr->strans) if (hdr->strans)
trans->dtrans = ntohs(hdr->strans) & 32767; trans->dtrans = ntohs(hdr->strans) & 32767;
break; return trans;
} }
} }
if (!trans) {
switch(hdr->cmdresp & 0x7f) { switch(hdr->cmdresp & 0x7f) {
case DUNDI_COMMAND_DPDISCOVER: case DUNDI_COMMAND_DPDISCOVER:
case DUNDI_COMMAND_EIDQUERY: case DUNDI_COMMAND_EIDQUERY:
case DUNDI_COMMAND_PRECACHERQ: case DUNDI_COMMAND_PRECACHERQ:
case DUNDI_COMMAND_REGREQ: case DUNDI_COMMAND_REGREQ:
case DUNDI_COMMAND_NULL: case DUNDI_COMMAND_NULL:
case DUNDI_COMMAND_ENCRYPT: case DUNDI_COMMAND_ENCRYPT:
if (hdr->strans) { 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");
}
break; break;
default: /* Create new transaction */
if (!(trans = create_transaction(NULL)))
break; break;
} memcpy(&trans->addr, sin, sizeof(trans->addr));
trans->dtrans = ntohs(hdr->strans) & 32767;
default:
break;
} }
return trans; return trans;
} }
@ -1985,8 +1982,8 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
int res; int res;
struct dundi_hdr *h; struct dundi_hdr *h;
char buf[MAX_PACKET_SIZE]; char buf[MAX_PACKET_SIZE];
socklen_t len; socklen_t len = sizeof(sin);
len = sizeof(sin);
res = recvfrom(netsocket, buf, sizeof(buf) - 1, 0,(struct sockaddr *) &sin, &len); res = recvfrom(netsocket, buf, sizeof(buf) - 1, 0,(struct sockaddr *) &sin, &len);
if (res < 0) { if (res < 0) {
if (errno != ECONNREFUSED) if (errno != ECONNREFUSED)
@ -1994,11 +1991,11 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
return 1; return 1;
} }
if (res < sizeof(struct dundi_hdr)) { 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; return 1;
} }
buf[res] = '\0'; buf[res] = '\0';
h = (struct dundi_hdr *)buf; h = (struct dundi_hdr *) buf;
if (dundidebug) if (dundidebug)
dundi_showframe(h, 1, &sin, res - sizeof(struct dundi_hdr)); dundi_showframe(h, 1, &sin, res - sizeof(struct dundi_hdr));
AST_LIST_LOCK(&peers); AST_LIST_LOCK(&peers);
@ -2777,22 +2774,23 @@ static struct dundi_transaction *create_transaction(struct dundi_peer *p)
tid = get_trans_id(); tid = get_trans_id();
if (tid < 1) if (tid < 1)
return NULL; return NULL;
trans = ast_calloc(1, sizeof(*trans)); if (!(trans = ast_calloc(1, sizeof(*trans))))
if (trans) { return NULL;
if (global_storehistory) {
trans->start = ast_tvnow(); if (global_storehistory) {
ast_set_flag(trans, FLAG_STOREHIST); trans->start = ast_tvnow();
} ast_set_flag(trans, FLAG_STOREHIST);
trans->retranstimer = DUNDI_DEFAULT_RETRANS_TIMER; }
trans->autokillid = -1; trans->retranstimer = DUNDI_DEFAULT_RETRANS_TIMER;
if (p) { trans->autokillid = -1;
apply_peer(trans, p); if (p) {
if (!p->sentfullkey) apply_peer(trans, p);
ast_set_flag(trans, FLAG_SENDFULLKEY); if (!p->sentfullkey)
} ast_set_flag(trans, FLAG_SENDFULLKEY);
trans->strans = tid;
AST_LIST_INSERT_HEAD(&alltrans, trans, all);
} }
trans->strans = tid;
AST_LIST_INSERT_HEAD(&alltrans, trans, all);
return trans; return trans;
} }

Loading…
Cancel
Save