mirror of
				https://github.com/asterisk/asterisk.git
				synced 2025-10-26 22:30:28 +00:00 
			
		
		
		
	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
This commit is contained in:
		| @@ -330,10 +330,10 @@ 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: | ||||||
| @@ -341,20 +341,17 @@ static struct dundi_transaction *find_transaction(struct dundi_hdr *hdr, struct | |||||||
| 	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) | ||||||
|  | 			break; | ||||||
| 		/* Create new transaction */ | 		/* Create new transaction */ | ||||||
| 				trans = create_transaction(NULL); | 		if (!(trans = create_transaction(NULL))) | ||||||
| 				if (trans) { | 			break; | ||||||
| 		memcpy(&trans->addr, sin, sizeof(trans->addr)); | 		memcpy(&trans->addr, sin, sizeof(trans->addr)); | ||||||
| 		trans->dtrans = ntohs(hdr->strans) & 32767; | 		trans->dtrans = ntohs(hdr->strans) & 32767; | ||||||
| 				} else |  | ||||||
| 					ast_log(LOG_WARNING, "Out of memory!\n"); |  | ||||||
| 			} |  | ||||||
| 			break; |  | ||||||
| 	default: | 	default: | ||||||
| 		break; | 		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,8 +2774,9 @@ 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) { | 	if (global_storehistory) { | ||||||
| 		trans->start = ast_tvnow(); | 		trans->start = ast_tvnow(); | ||||||
| 		ast_set_flag(trans, FLAG_STOREHIST); | 		ast_set_flag(trans, FLAG_STOREHIST); | ||||||
| @@ -2792,7 +2790,7 @@ static struct dundi_transaction *create_transaction(struct dundi_peer *p) | |||||||
| 	} | 	} | ||||||
| 	trans->strans = tid; | 	trans->strans = tid; | ||||||
| 	AST_LIST_INSERT_HEAD(&alltrans, trans, all); | 	AST_LIST_INSERT_HEAD(&alltrans, trans, all); | ||||||
| 	} | 	 | ||||||
| 	return trans; | 	return trans; | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user