- some changes & enhancements inspired by Cris Ross:

* 183 Trying *may* contain SDP data
  * compare_url: now does compare the scheme,
    if a host is not resolveable hostnames will be
    compares as strings
This commit is contained in:
Thomas Ries 2003-12-05 18:16:28 +00:00
parent 0170015955
commit acbdb707ec
6 changed files with 100 additions and 54 deletions

View File

@ -1,5 +1,10 @@
0.5.1
=====
05-Dec-2003: - some changes & enhancements inspired by Cris Ross:
* 183 Trying *may* contain SDP data
* compare_url: now does compare the scheme,
if a host is not resolveable hostnames will be
compares as strings
04-Dec-2003: - have registrations persistent across restarts of
the daemon ('registration_file' config option)
29-Nov-2003: - some documentation & FAQ updates

View File

@ -1,4 +1,4 @@
/*
/* -*- Mode: C; c-basic-offset: 3 -*-
Copyright (C) 2002 Thomas Ries <tries@gmx.net>
This file is part of Siproxd.
@ -417,9 +417,11 @@ int proxy_response (osip_message_t *response) {
*/
case RESTYP_OUTGOING:
#define satoi atoi /* used in MSG_TEST_CODE macro ... */
/* If an 200 answer to an INVITE request, rewrite body */
/* If an 200 OK or 183 Trying answer to an INVITE request,
* rewrite body */
if ((MSG_IS_RESPONSE_FOR(response,"INVITE")) &&
(MSG_TEST_CODE(response, 200))) {
((MSG_TEST_CODE(response, 200)) ||
(MSG_TEST_CODE(response, 183)))) {
sts = proxy_rewrite_invitation_body(response);
}
@ -510,7 +512,7 @@ int proxy_response (osip_message_t *response) {
/*
* PROXY_REWRITE_INVITATION_BODY
*
* rewrites the outgoing INVITATION packet
* rewrites the outgoing INVITATION request or response packet
*
* RETURNS
* STS_SUCCESS on success
@ -533,8 +535,16 @@ int proxy_rewrite_invitation_body(osip_message_t *mymsg){
*/
sts = osip_message_get_body(mymsg, 0, &body);
if (sts != 0) {
ERROR("rewrite_invitation_body: no body found in message");
return STS_FAILURE;
if ((MSG_IS_RESPONSE_FOR(mymsg,"INVITE")) &&
(MSG_TEST_CODE(mymsg, 183))) {
/* 183 Trying *MAY* contain SDP data */
DEBUGC(DBCLASS_PROXY, "rewrite_invitation_body: "
"no body found in message");
} else {
/* INVITE request and 200 response *MUST* contain SDP data */
ERROR("rewrite_invitation_body: no body found in message");
return STS_FAILURE;
}
}
sts = osip_body_to_str(body, &bodybuff);

View File

@ -27,10 +27,6 @@
#include <string.h>
#include <sys/types.h>
#ifdef _SOLARIS
#include <sys/socket.h>
#endif
#include <netinet/in.h>
#include <arpa/inet.h>

View File

@ -1,4 +1,4 @@
/*
/* -*- Mode: C; c-basic-offset: 3 -*-
Copyright (C) 2002 Thomas Ries <tries@gmx.net>
This file is part of Siproxd.
@ -209,14 +209,14 @@ int is_via_local (osip_via_t *via) {
/*
* compares two URLs
* (by now, only hostname and username are compared)
* (by now, only scheme, hostname and username are compared)
*
* RETURNS
* STS_SUCCESS if equal
* STS_FAILURE if non equal or error
*/
int compare_url(osip_uri_t *url1, osip_uri_t *url2) {
int sts;
int sts1, sts2;
struct in_addr addr1, addr2;
/* sanity checks */
@ -232,49 +232,70 @@ int compare_url(osip_uri_t *url1, osip_uri_t *url2) {
return STS_FAILURE;
}
DEBUGC(DBCLASS_PROXY, "comparing urls: %s:%s@%s -> %s:%s@%s",
(url1->scheme) ? url1->scheme : "(null)",
(url1->username) ? url1->username : "(null)",
(url1->host) ? url1->host : "(null)",
(url2->scheme) ? url2->scheme : "(null)",
(url2->username) ? url2->username : "(null)",
(url2->host) ? url2->host : "(null)");
/* compare SCHEME (if present) case INsensitive */
if (url1->scheme && url2->scheme) {
if (strcasecmp(url1->scheme, url2->scheme) != 0) {
DEBUGC(DBCLASS_PROXY, "compare_url: scheme mismatch");
return STS_FAILURE;
} else {
WARN("compare_url: NULL scheme - ignoring");
}
}
/* compare username (if present) case sensitive */
if (url1->username && url2->username) {
if (strcmp(url1->username, url2->username) != 0) {
DEBUGC(DBCLASS_PROXY, "compare_url: username mismatch");
return STS_FAILURE;
} else {
WARN("compare_url: NULL username - ignoring");
}
}
/*
* now, try to resolve the host. If resolveable, compare
* IP addresses - if not resolveable, compare the host names
* itselfes
*/
/* get the IP addresses from the (possible) hostnames */
sts=get_ip_by_host(url1->host, &addr1);
if (sts == STS_FAILURE) {
sts1=get_ip_by_host(url1->host, &addr1);
if (sts1 == STS_FAILURE) {
DEBUGC(DBCLASS_PROXY, "compare_url: cannot resolve host [%s]",
url1->host);
return STS_FAILURE;
}
sts=get_ip_by_host(url2->host, &addr2);
if (sts == STS_FAILURE) {
sts2=get_ip_by_host(url2->host, &addr2);
if (sts2 == STS_FAILURE) {
DEBUGC(DBCLASS_PROXY, "compare_url: cannot resolve host [%s]",
url2->host);
return STS_FAILURE;
}
/* Broken(?) MSN messenger - does not supply a user name part.
So we simply compare the host part then */
if ((url1->username == NULL) || (url2->username == NULL)) {
/* let's be nice to Billy boy and don't complain evey time ;-)
// WARN("compare_url: NULL username pointer: MSN messenger is known to "
// "trigger this one!"); */
DEBUGC(DBCLASS_PROXY, "comparing broken urls (no user): "
"%s <-> %s", url1->host, url2->host);
if (memcmp(&addr1, &addr2, sizeof(addr1))==0) {
sts = STS_SUCCESS;
} else {
sts = STS_FAILURE;
if ((sts1 == STS_SUCCESS) && (sts2 == STS_SUCCESS)) {
/* compare IP addresses */
if (memcmp(&addr1, &addr2, sizeof(addr1))!=0) {
DEBUGC(DBCLASS_PROXY, "compare_url: IP mismatch");
return STS_FAILURE;
}
return sts;
}
/* we have a proper URL */
/* comparison of hosts should be based on IP addresses, no? */
DEBUGC(DBCLASS_PROXY, "comparing urls: %s@%s -> %s@%s",
url1->username, url1->host, url2->username, url2->host);
if ((strcmp(url1->username, url2->username)==0) &&
(memcmp(&addr1, &addr2, sizeof(addr1))==0)) {
sts = STS_SUCCESS;
} else {
sts = STS_FAILURE;
/* compare hostname strings case INsensitive */
if (osip_strcasecmp(url1->host, url2->host) != 0) {
DEBUGC(DBCLASS_PROXY, "compare_url: host name mismatch");
return STS_FAILURE;
}
}
return sts;
/* the two URLs did pass all tests successfully - MATCH */
return STS_SUCCESS;
}

View File

@ -1,4 +1,4 @@
/*
/* -*- Mode: C; c-basic-offset: 3 -*-
Copyright (C) 2002 Thomas Ries <tries@gmx.net>
This file is part of Siproxd.
@ -254,7 +254,7 @@ INFO("daemonizing done (pid=%i)", getpid());
{char tmp[32];
strncpy(tmp, buff, 30);
tmp[30]='\0';
INFO("got packet [%i bytes]from %s [%s]", i,
INFO("got packet [%i bytes] from %s [%s]", i,
utils_inet_ntoa(from.sin_addr), tmp);}
#endif
/* evaluate the access lists (IP based filter)*/
@ -307,11 +307,13 @@ INFO("got packet [%i bytes]from %s [%s]", i,
url = osip_message_get_uri(my_msg);
sts = get_ip_by_host(url->host, &addr1);
sts = get_ip_by_ifname(configuration.inbound_if,&addr2);
sts = get_ip_by_ifname(configuration.outbound_if,&addr3);
if ((memcmp(&addr1, &addr2, sizeof(addr1)) == 0) ||
(memcmp(&addr1, &addr3, sizeof(addr1)) == 0)) {
get_ip_by_ifname(configuration.inbound_if,&addr2);
get_ip_by_ifname(configuration.outbound_if,&addr3);
if ((sts == STS_SUCCESS) &&
((memcmp(&addr1, &addr2, sizeof(addr1)) == 0) ||
(memcmp(&addr1, &addr3, sizeof(addr1)) == 0))) {
/* I'm the registrar, send response myself */
sts = register_client(my_msg, 0);
sts = register_response(my_msg, sts);

View File

@ -147,7 +147,7 @@ int get_ip_by_host(char *hostname, struct in_addr *addr) {
&hostentry,
&error);
#else
#error "gethostbyname_s() with 3, 5 or 6 arguments supported only"
#error "gethostbyname_r() with 3, 5 or 6 arguments supported only"
#endif
}
#elif defined(HAVE_GETHOSTBYNAME)
@ -158,14 +158,26 @@ int get_ip_by_host(char *hostname, struct in_addr *addr) {
#endif
if (hostentry==NULL) {
if (h_errno == HOST_NOT_FOUND) {
/* this is actually not really an error */
/*
* Some errors just tell us that there was no IP resolvable.
* From the manpage:
* HOST_NOT_FOUND
* The specified host is unknown.
* HOST_NOT_FOUND
* The specified host is unknown.
* NO_ADDRESS or NO_DATA
* The requested name is valid but does not have an IP
* address.
*/
if ((error == HOST_NOT_FOUND) ||
(error == NO_ADDRESS) ||
(error == NO_DATA)) {
#ifdef HAVE_HSTRERROR
DEBUGC(DBCLASS_DNS, "gethostbyname(%s) failed: %s",
hostname, hstrerror(h_errno));
hostname, hstrerror(error));
#else
DEBUGC(DBCLASS_DNS, "gethostbyname(%s) failed: h_errno=%i",
hostname, h_errno);
hostname, error);
#endif
} else {
#ifdef HAVE_HSTRERROR