cosmetics and some better error handling w/ strings and data structures
(NULL ptrs)
This commit is contained in:
parent
c45aa20f68
commit
6bb397118a
@ -102,7 +102,7 @@ int accesslist_check (struct sockaddr_in from) {
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* checks for a match of the 'from' address with the supplies
|
* checks for a match of the 'from' address with the supplied
|
||||||
* access list.
|
* access list.
|
||||||
*
|
*
|
||||||
* RETURNS
|
* RETURNS
|
||||||
|
|||||||
@ -80,7 +80,7 @@ int authenticate_proxy(sip_t *request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* authentication failed */
|
/* authentication failed */
|
||||||
DEBUGC(DBCLASS_AUTH,"proxy-auth failed");
|
WARN("authenticate_proxy failed");
|
||||||
return STS_FAILURE;
|
return STS_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
23
src/proxy.c
23
src/proxy.c
@ -185,23 +185,24 @@ int proxy_request (sip_t *request) {
|
|||||||
/* add my Via header line (outbound interface)*/
|
/* add my Via header line (outbound interface)*/
|
||||||
sts = proxy_add_myvia(request, 0);
|
sts = proxy_add_myvia(request, 0);
|
||||||
if (sts == STS_FAILURE) {
|
if (sts == STS_FAILURE) {
|
||||||
WARN("adding my outbound via failed!");
|
ERROR("adding my outbound via failed!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if this is CANCEL/BYE request, stop RTP proxying */
|
/* if this is CANCEL/BYE request, stop RTP proxying */
|
||||||
if (MSG_IS_BYE(request) || MSG_IS_CANCEL(request)) {
|
if (MSG_IS_BYE(request) || MSG_IS_CANCEL(request)) {
|
||||||
/* stop the RTP proxying stream */
|
|
||||||
rtp_stop_fwd(msg_getcall_id(request));
|
rtp_stop_fwd(msg_getcall_id(request));
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
DEBUGC(DBCLASS_PROXY,"request: refuse to proxy - UA not registered?");
|
DEBUGC(DBCLASS_PROXY,"proxy_request: refused to proxy");
|
||||||
WARN("request from/to unregistered UA (%s@%s)",
|
WARN("request from/to unregistered UA (%s@%s)",
|
||||||
request->from->url->username,
|
request->from->url->username,
|
||||||
request->from->url->host);
|
request->from->url->host);
|
||||||
/* some clients seem to run amok when passing back a negative response */
|
/* some clients seem to run amok when passing back a negative response
|
||||||
|
* so we simply drop the request silently
|
||||||
|
*/
|
||||||
// proxy_gen_response(request, 403 /*forbidden*/);
|
// proxy_gen_response(request, 403 /*forbidden*/);
|
||||||
return STS_FAILURE;
|
return STS_FAILURE;
|
||||||
}
|
}
|
||||||
@ -377,7 +378,10 @@ int proxy_response (sip_t *response) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
DEBUGC(DBCLASS_PROXY,"response: refuse to proxy - UA not registered?");
|
DEBUGC(DBCLASS_PROXY,"proxy_response: refused to proxy");
|
||||||
|
WARN("response from/to unregistered UA (%s@%s)",
|
||||||
|
request->from->url->username,
|
||||||
|
request->from->url->host);
|
||||||
/* some clients seem to run amok when passing back a negative response */
|
/* some clients seem to run amok when passing back a negative response */
|
||||||
// proxy_gen_response(request, 403 /*forbidden*/);
|
// proxy_gen_response(request, 403 /*forbidden*/);
|
||||||
return STS_FAILURE;
|
return STS_FAILURE;
|
||||||
@ -488,14 +492,16 @@ int proxy_add_myvia (sip_t *request, int interface) {
|
|||||||
sts = get_ip_by_host(configuration.inboundhost, &addr);
|
sts = get_ip_by_host(configuration.inboundhost, &addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf (tmp, "SIP/2.0/UDP %s:%i", inet_ntoa(addr),
|
sprintf(tmp, "SIP/2.0/UDP %s:%i", inet_ntoa(addr),
|
||||||
configuration.sip_listen_port);
|
configuration.sip_listen_port);
|
||||||
DEBUGC(DBCLASS_BABBLE,"adding VIA:%s",tmp);
|
DEBUGC(DBCLASS_BABBLE,"adding VIA:%s",tmp);
|
||||||
|
|
||||||
sts = via_init(&via);
|
sts = via_init(&via);
|
||||||
if (sts!=0) return STS_FAILURE; /* allocation failed */
|
if (sts!=0) return STS_FAILURE; /* allocation failed */
|
||||||
|
|
||||||
sts = via_parse(via, tmp);
|
sts = via_parse(via, tmp);
|
||||||
if (sts!=0) return STS_FAILURE;
|
if (sts!=0) return STS_FAILURE;
|
||||||
|
|
||||||
list_add(request->vias,via,0);
|
list_add(request->vias,via,0);
|
||||||
|
|
||||||
return STS_SUCCESS;
|
return STS_SUCCESS;
|
||||||
@ -694,9 +700,6 @@ int proxy_rewrite_invitation_body(sip_t *mymsg){
|
|||||||
memcpy (ptr, data2_c, strlen(data2_c));
|
memcpy (ptr, data2_c, strlen(data2_c));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* remove old body */
|
/* remove old body */
|
||||||
|
|||||||
@ -143,7 +143,7 @@ int register_client(sip_t *my_msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (i >= URLMAP_SIZE) {
|
if (i >= URLMAP_SIZE) {
|
||||||
/* entry no existing, create new one */
|
/* entry not existing, create new one */
|
||||||
i=j;
|
i=j;
|
||||||
DEBUGC(DBCLASS_REG,"create new entry for %s@%s at slot=%i",
|
DEBUGC(DBCLASS_REG,"create new entry for %s@%s at slot=%i",
|
||||||
url1_contact->username, url1_contact->host, i);
|
url1_contact->username, url1_contact->host, i);
|
||||||
|
|||||||
@ -138,7 +138,7 @@ int sipsock_send_udp(int *sock, struct in_addr addr, int port,
|
|||||||
DUMP_BUFFER(DBCLASS_NETTRAF, buffer, size);
|
DUMP_BUFFER(DBCLASS_NETTRAF, buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
sts = sendto (*sock, buffer, size, 0, &dst_addr, sizeof(dst_addr));
|
sts = sendto(*sock, buffer, size, 0, &dst_addr, sizeof(dst_addr));
|
||||||
|
|
||||||
if (sts == -1) {
|
if (sts == -1) {
|
||||||
if (errno != ECONNREFUSED) {
|
if (errno != ECONNREFUSED) {
|
||||||
|
|||||||
35
src/utils.c
35
src/utils.c
@ -63,6 +63,14 @@ sip_t *msg_make_template_reply (sip_t * request, int code) {
|
|||||||
msg_setstatuscode (response, tmp);
|
msg_setstatuscode (response, tmp);
|
||||||
msg_setreasonphrase (response, msg_getreason (code));
|
msg_setreasonphrase (response, msg_getreason (code));
|
||||||
|
|
||||||
|
if (request->to==NULL) {
|
||||||
|
ERROR("msg_make_template_reply: empty To in request header");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request->from==NULL) {
|
||||||
|
ERROR("msg_make_template_reply: empty From in request header");
|
||||||
|
}
|
||||||
|
|
||||||
to_clone (request->to, &response->to);
|
to_clone (request->to, &response->to);
|
||||||
from_clone (request->from, &response->from);
|
from_clone (request->from, &response->from);
|
||||||
|
|
||||||
@ -102,7 +110,7 @@ int check_vialoop (sip_t *my_msg) {
|
|||||||
|
|
||||||
found_own_via=0;
|
found_own_via=0;
|
||||||
pos = 1; /* for detecting a loop, don't check the first entry
|
pos = 1; /* for detecting a loop, don't check the first entry
|
||||||
as this is my VIA! */
|
as this is my own VIA! */
|
||||||
while (!list_eol (my_msg->vias, pos)) {
|
while (!list_eol (my_msg->vias, pos)) {
|
||||||
via_t *via;
|
via_t *via;
|
||||||
via = (via_t *) list_get (my_msg->vias, pos);
|
via = (via_t *) list_get (my_msg->vias, pos);
|
||||||
@ -179,7 +187,15 @@ int get_ip_by_host(char *hostname, struct in_addr *addr) {
|
|||||||
} dns_cache[DNS_CACHE_SIZE];
|
} dns_cache[DNS_CACHE_SIZE];
|
||||||
static int cache_initialized=0;
|
static int cache_initialized=0;
|
||||||
|
|
||||||
if (hostname == NULL) return STS_FAILURE;
|
if (hostname == NULL) {
|
||||||
|
ERROR("get_ip_by_host: NULL hostname requested");
|
||||||
|
return STS_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (addr == NULL) {
|
||||||
|
ERROR("get_ip_by_host: NULL in_addr passed");
|
||||||
|
return STS_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
/* first time: initialize DNS cache */
|
/* first time: initialize DNS cache */
|
||||||
if (cache_initialized == 0) {
|
if (cache_initialized == 0) {
|
||||||
@ -260,7 +276,20 @@ int get_ip_by_host(char *hostname, struct in_addr *addr) {
|
|||||||
int compare_url(url_t *url1, url_t *url2) {
|
int compare_url(url_t *url1, url_t *url2) {
|
||||||
int sts;
|
int sts;
|
||||||
|
|
||||||
if ((url1 == NULL) || (url2 == NULL)) return STS_FAILURE;
|
if ((url1 == NULL) || (url2 == NULL)) {
|
||||||
|
ERROR("compare_url: NULL ptr: url1=0x%p, url2=0x%p",url1, url2);
|
||||||
|
return STS_FAILURE;
|
||||||
|
}
|
||||||
|
if ((url1->username == NULL) || (url2->username == NULL)) {
|
||||||
|
ERROR("compare_url: NULL ptr: url1->username=0x%p, url2->username=0x%p",
|
||||||
|
url1->username, url2->username);
|
||||||
|
return STS_FAILURE;
|
||||||
|
}
|
||||||
|
if ((url1->host == NULL) || (url2->host == NULL)) {
|
||||||
|
ERROR("compare_url: NULL ptr: url1->host=0x%p, url2->host=0x%p",
|
||||||
|
url1->host, url2->host);
|
||||||
|
return STS_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
/* comparison of hosts should be based on IP addresses, no? */
|
/* comparison of hosts should be based on IP addresses, no? */
|
||||||
DEBUGC(DBCLASS_BABBLE, "comparing urls: %s@%s -> %s@%s",
|
DEBUGC(DBCLASS_BABBLE, "comparing urls: %s@%s -> %s@%s",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user