[Freeswitch-trunk] [commit] r6338 - in freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua: bnf http ipt iptsec msg nua sip su su/sofia-sip url
Freeswitch SVN
mikej at freeswitch.org
Mon Nov 19 13:09:16 EST 2007
Author: mikej
Date: Mon Nov 19 13:09:15 2007
New Revision: 6338
Modified:
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/bnf/bnf.c
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/http/http_extra.c
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/ipt/token64.c
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/iptsec/auth_client.c
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/iptsec/auth_common.c
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/iptsec/auth_digest.c
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/msg/msg_auth.c
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/nua_register.c
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/test_basic_call.c
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/test_proxy.c
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/test_proxy.h
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/test_register.c
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_event.c
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_extra.c
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_feature.c
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_mime.c
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_pref_util.c
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_reason.c
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_refer.c
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_security.c
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_tag_class.c
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_util.c
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/sofia-sip/htable2.h
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/sofia-sip/su_alloc.h
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/su_alloc.c
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/su_alloc_lock.c
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/su_log.c
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/su_pthread_port.c
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/su_strlst.c
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/torture_su_alloc.c
freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/url/url.c
Log:
Merge up to current sofia-sip darcs.
Thu Nov 15 08:40:38 EST 2007 Pekka.Pessi at nokia.com
* htable2.h: fixed usize_t/size_t confusion
Fri Nov 16 06:38:51 EST 2007 Youness Alaoui <youness.alaoui at collabora.co.uk>
* Added #include <stdio.h>
Fri Nov 16 10:27:58 EST 2007 Pekka.Pessi at nokia.com
* auth_client.c: allow multiple challenges in auc_credentials() or auc_all_credentials()
Fri Nov 16 10:29:00 EST 2007 Pekka.Pessi at nokia.com
* nua/test_proxy.[hc], nua/test_register.c: test support of multiple realms.
Fri Nov 16 11:17:09 EST 2007 Pekka.Pessi at nokia.com
* sofia-sip/su_alloc.h, su_alloc.c: added su_home_lock(), su_home_trylock(), su_home_unlock()
Added test in torture_su_alloc.c. Using in su_pthread_port.c.
Fri Nov 16 12:29:55 EST 2007 Pekka.Pessi at nokia.com
* test_register.c, test_proxy.c: use realm "test-proxy" during normal tests
Fri Nov 16 12:34:00 EST 2007 Pekka.Pessi at nokia.com
* nua_register.c: sf.net bug #1816647: Outbound contact does not make it to dialogs
Now use Contact from first registration instead of Contact generated from
transport.
Mon Nov 19 12:00:06 EST 2007 Pekka Pessi <Pekka.Pessi at nokia.com>
* su_alloc.c: silenced warnings on Sun CC
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/bnf/bnf.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/bnf/bnf.c (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/bnf/bnf.c Mon Nov 19 13:09:15 2007
@@ -35,6 +35,7 @@
#include "sofia-sip/bnf.h"
+#include <stdio.h>
#include <assert.h>
#define ws bnf_ws
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/http/http_extra.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/http/http_extra.c (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/http/http_extra.c Mon Nov 19 13:09:15 2007
@@ -33,6 +33,7 @@
#include "config.h"
+#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/ipt/token64.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/ipt/token64.c (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/ipt/token64.c Mon Nov 19 13:09:15 2007
@@ -33,6 +33,7 @@
#include "config.h"
+#include <stdio.h>
#include <stddef.h>
#include <assert.h>
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/iptsec/auth_client.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/iptsec/auth_client.c (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/iptsec/auth_client.c Mon Nov 19 13:09:15 2007
@@ -387,7 +387,7 @@
if ((scheme != NULL && strcasecmp(scheme, ca->ca_scheme)) ||
(realm != NULL && strcmp(realm, ca->ca_realm)))
- return -1;
+ return 0;
old_user = ca->ca_user, old_pass = ca->ca_pass;
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/iptsec/auth_common.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/iptsec/auth_common.c (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/iptsec/auth_common.c Mon Nov 19 13:09:15 2007
@@ -37,6 +37,7 @@
#include "sofia-sip/auth_common.h"
#include "sofia-sip/msg_header.h"
+#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <assert.h>
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/iptsec/auth_digest.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/iptsec/auth_digest.c (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/iptsec/auth_digest.c Mon Nov 19 13:09:15 2007
@@ -41,6 +41,7 @@
#include "iptsec_debug.h"
+#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <limits.h>
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/msg/msg_auth.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/msg/msg_auth.c (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/msg/msg_auth.c Mon Nov 19 13:09:15 2007
@@ -35,6 +35,7 @@
#include "config.h"
+#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/nua_register.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/nua_register.c (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/nua_register.c Mon Nov 19 13:09:15 2007
@@ -1426,6 +1426,7 @@
int sips_uri = remote_uri && remote_uri->url_type == url_sips;
nua_registration_t const *nr, *public = NULL, *any = NULL;
+ nua_registration_t const *registered = NULL;
nua_registration_t const *namewise = NULL, *sipswise = NULL;
int ip4 = remote_uri && host_is_ip4_address(remote_uri->url_host);
@@ -1444,11 +1445,15 @@
continue;
if (sips_uri ? nr->nr_secure : !nr->nr_secure)
return (nua_registration_t *)nr;
+ if (!registered && nr->nr_aor)
+ registered = nr;
if (!public && nr->nr_public)
public = nr;
if (!any)
any = nr;
}
+ if (registered)
+ return (nua_registration_t *)registered;
if (public)
return (nua_registration_t *)public;
if (any)
@@ -1456,8 +1461,11 @@
return NULL;
}
- if (!sips_aor && aor)
+ if (!sips_aor && aor) {
alt_aor = memcpy(_alt_aor, aor, sizeof _alt_aor);
+ alt_aor->a_url->url_type = url_sips;
+ alt_aor->a_url->url_scheme = "sips";
+ }
for (nr = list; nr; nr = nr->nr_next) {
if (!nr->nr_ready || !nr->nr_contact)
@@ -1468,11 +1476,12 @@
if (!namewise && alt_aor && url_cmp(nr->nr_aor->a_url, aor->a_url) == 0)
namewise = nr;
}
- else {
- if (!sipswise && ((sips_aor || sips_uri) ?
- nr->nr_secure : !nr->nr_secure))
- sipswise = nr;
- }
+
+ if (!sipswise && ((sips_aor || sips_uri) ?
+ nr->nr_secure : !nr->nr_secure))
+ sipswise = nr;
+ if (!registered)
+ registered = nr;
if (!public && nr->nr_public)
public = nr;
if (!any)
@@ -1483,7 +1492,9 @@
return (nua_registration_t *)namewise;
if (sipswise)
return (nua_registration_t *)sipswise;
-
+ if (registered)
+ return (nua_registration_t *)registered;
+
/* XXX -
should we do some policing whether sips_aor or sips_uri can be used
with sip contact?
@@ -1594,7 +1605,7 @@
*
* @param nh
* @param msg response message
- * @param sip response headers
+ * @param sip headers in response message
* @param record_route record-route from request
* @param remote_contact Contact from request
*/
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/test_basic_call.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/test_basic_call.c (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/test_basic_call.c Mon Nov 19 13:09:15 2007
@@ -457,8 +457,14 @@
TEST_S(sip->sip_content_type->c_type, "application/sdp");
TEST_1(sip->sip_payload); /* there is sdp in 200 OK */
TEST_1(sip->sip_contact);
+#if nomore
/* Test that B does not use application-specific contact */
TEST_1(!sip->sip_contact->m_url->url_user);
+#else
+ /* sf.net bug #1816647: Outbound contact does not make it to dialogs */
+ /* Now we use first registered contact if aor does not match */
+ TEST_S(sip->sip_contact->m_url->url_user, "b");
+#endif
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
TEST(callstate(e->data->e_tags), nua_callstate_ready); /* READY */
TEST_1(!is_answer_recv(e->data->e_tags)); /* but it is ignored */
@@ -989,6 +995,9 @@
}
/* Test changing from/to within dialog */
+/* Test that a proper Contact gets selected in response
+ * regardless of the To URI.
+ */
int test_basic_call_5(struct context *ctx)
{
BEGIN();
@@ -1004,13 +1013,15 @@
a_call->sdp = "m=audio 5008 RTP/AVP 8";
b_call->sdp = "m=audio 5010 RTP/AVP 0 8";
- TEST_1(a_call->nh = nua_handle(a->nua, a_call, SIPTAG_TO(b->to), TAG_END()));
+ TEST_1(a_call->nh = nua_handle(a->nua, a_call,
+ SIPTAG_TO_STR("<sips:b at x.org>"),
+ TAG_END()));
TEST_1(!nua_handle_has_active_call(a_call->nh));
TEST_1(!nua_handle_has_call_on_hold(a_call->nh));
INVITE(a, a_call, a_call->nh,
- TAG_IF(!ctx->proxy_tests, NUTAG_URL(b->contact->m_url)),
+ NUTAG_URL(b->contact->m_url),
SOATAG_USER_SDP_STR(a_call->sdp),
NUTAG_AUTOACK(0),
TAG_END());
@@ -1032,6 +1043,7 @@
TEST(e->data->e_status, 200);
TEST_1(sip = sip_object(e->data->e_msg));
TEST_1(sip->sip_contact);
+ TEST_S(sip->sip_contact->m_url->url_user, "b");
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
TEST(callstate(e->data->e_tags), nua_callstate_completing); /* COMPLETING */
TEST_1(e = e->next); TEST_E(e->data->e_event, nua_i_state);
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/test_proxy.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/test_proxy.c (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/test_proxy.c Mon Nov 19 13:09:15 2007
@@ -134,7 +134,7 @@
struct {
sip_time_t min_expires, expires, max_expires;
int outbound_tcp; /**< Use inbound TCP connection as outbound */
- int authorize;
+ char const *authorize; /**< Authorization realm to use */
} prefs;
tagi_t *tags;
@@ -216,6 +216,7 @@
auth_mod_t *am; /* Authentication module */
auth_status_t *as; /* Authentication status */
+ char const *realm; /* Authentication realm to use */
unsigned use_auth; /* Authentication method (401/407) to use */
unsigned rr:1;
@@ -473,20 +474,33 @@
}
}
-void test_proxy_domain_set_authorize(struct domain *d, int authorize)
+int test_proxy_domain_set_authorize(struct domain *d,
+ char const *realm)
{
if (d) {
- d->prefs.authorize = authorize;
+ if (realm) {
+ realm = su_strdup(d->home, realm);
+ if (!realm)
+ return -1;
+ }
+
+ d->prefs.authorize = realm;
+
+ return 0;
}
+ return -1;
}
-void test_proxy_domain_get_authorize(struct domain *d,
- int *return_authorize)
+int test_proxy_domain_get_authorize(struct domain *d,
+ char const **return_realm)
{
if (d) {
- if (return_authorize)
- *return_authorize = d->prefs.authorize;
+ if (return_realm) {
+ *return_realm = d->prefs.authorize;
+ return 0;
+ }
}
+ return -1;
}
int test_proxy_close_tports(struct proxy *p)
@@ -533,7 +547,7 @@
d->prefs.expires = 3600;
d->prefs.max_expires = 36000;
d->prefs.outbound_tcp = 0;
- d->prefs.authorize = 0;
+ d->prefs.authorize = NULL;
if (d->uri && d->tags &&
!su_task_execute(su_clone_task(p->clone), _domain_init, d, &init)) {
@@ -795,6 +809,7 @@
if (o && o->auth && o->prefs.authorize) {
t->am = o->auth;
+ t->realm = o->prefs.authorize;
t->use_auth = 407;
}
@@ -966,6 +981,7 @@
as->as_method = sip->sip_request->rq_method_name;
as->as_source = msg_addrinfo(t->msg);
+ as->as_realm = t->realm;
as->as_user_uri = sip->sip_from->a_url;
as->as_display = sip->sip_from->a_display;
@@ -1110,6 +1126,8 @@
if (t->domain->auth) {
t->am = t->domain->auth, t->use_auth = 401;
+ if (t->domain->prefs.authorize)
+ t->realm = t->domain->prefs.authorize;
if (challenge_transaction(t))
return t->status;
}
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/test_proxy.h
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/test_proxy.h (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/test_proxy.h Mon Nov 19 13:09:15 2007
@@ -64,8 +64,9 @@
sip_time_t *return_session_expires,
sip_time_t *return_min_se);
-void test_proxy_domain_set_authorize(struct domain *d, int authorize);
-void test_proxy_domain_get_authorize(struct domain *d, int *return_authorize);
+int test_proxy_domain_set_authorize(struct domain *, char const *realm);
+int test_proxy_domain_get_authorize(struct domain *,
+ char const **return_realm);
void test_proxy_domain_set_outbound(struct domain *d,
int use_outbound);
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/test_register.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/test_register.c (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/test_register.c Mon Nov 19 13:09:15 2007
@@ -426,7 +426,7 @@
printf("TEST NUA-2.3.3: REGISTER c\n");
test_proxy_domain_set_expiration(ctx->c.domain, 600, 3600, 36000);
- test_proxy_domain_set_authorize(ctx->c.domain, 2);
+ test_proxy_domain_set_authorize(ctx->c.domain, "test-proxy-0");
TEST_1(c_reg->nh = nua_handle(c->nua, c_reg, TAG_END()));
@@ -453,7 +453,7 @@
free_events_in_list(ctx, c->events);
AUTHENTICATE(c, c_reg, c_reg->nh,
- NUTAG_AUTH("Digest:\"test-proxy\":charlie:secret"), TAG_END());
+ NUTAG_AUTH("Digest:\"test-proxy-0\":charlie:secret"), TAG_END());
run_abc_until(ctx, -1, save_events, -1, save_events,
-1, save_until_final_response);
@@ -778,6 +778,23 @@
free_events_in_list(ctx, c->events);
+ /* Sneakily change the realm */
+
+ TEST(test_proxy_domain_set_authorize(ctx->c.domain, "test-proxy"), 0);
+
+ AUTHENTICATE(c, c_call, c_call->nh,
+ NUTAG_AUTH("Digest:\"test-proxy-0\":charlie:secret"),
+ TAG_END());
+
+ run_abc_until(ctx, -1, NULL, -1, NULL, -1, save_until_final_response);
+
+ /* Client events: nua_options(), nua_r_options */
+ TEST_1(e = c->events->head); TEST_E(e->data->e_event, nua_r_options);
+ TEST(e->data->e_status, 407);
+ TEST_1(!e->next);
+
+ free_events_in_list(ctx, c->events);
+
AUTHENTICATE(c, c_call, c_call->nh,
NUTAG_AUTH("Digest:\"test-proxy\":charlie:secret"),
TAG_END());
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_event.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_event.c (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_event.c Mon Nov 19 13:09:15 2007
@@ -41,6 +41,7 @@
#include "sofia-sip/sip_parser.h"
+#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_extra.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_extra.c (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_extra.c Mon Nov 19 13:09:15 2007
@@ -43,6 +43,7 @@
#include "sofia-sip/sip_parser.h"
#include "sofia-sip/sip_extra.h"
+#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_feature.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_feature.c (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_feature.c Mon Nov 19 13:09:15 2007
@@ -39,6 +39,7 @@
#include "sofia-sip/sip_parser.h"
+#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_mime.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_mime.c (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_mime.c Mon Nov 19 13:09:15 2007
@@ -40,6 +40,7 @@
#include "sofia-sip/sip_parser.h"
#include "sofia-sip/msg_mime_protos.h"
+#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_pref_util.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_pref_util.c (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_pref_util.c Mon Nov 19 13:09:15 2007
@@ -33,6 +33,7 @@
#include "config.h"
+#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_reason.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_reason.c (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_reason.c Mon Nov 19 13:09:15 2007
@@ -39,6 +39,7 @@
#include "sofia-sip/sip_parser.h"
+#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_refer.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_refer.c (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_refer.c Mon Nov 19 13:09:15 2007
@@ -42,6 +42,7 @@
#include "sofia-sip/sip_parser.h"
#include "sofia-sip/sip_extra.h"
+#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_security.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_security.c (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_security.c Mon Nov 19 13:09:15 2007
@@ -57,6 +57,7 @@
#include "sofia-sip/sip_parser.h"
+#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_tag_class.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_tag_class.c (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_tag_class.c Mon Nov 19 13:09:15 2007
@@ -42,6 +42,7 @@
#include <sofia-sip/su_tagarg.h>
#include <sofia-sip/su_strlst.h>
+#include <stdio.h>
#include <ctype.h>
#include <assert.h>
#include <stddef.h>
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_util.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_util.c (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/sip/sip_util.c Mon Nov 19 13:09:15 2007
@@ -50,6 +50,7 @@
#include <sofia-sip/hostdomain.h>
+#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/sofia-sip/htable2.h
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/sofia-sip/htable2.h (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/sofia-sip/htable2.h Mon Nov 19 13:09:15 2007
@@ -138,13 +138,13 @@
HTABLE2_SCOPE \
int prefix##_resize(void *realloc_arg, \
type pr[1], \
- usize_t new_size) \
+ size_t new_size) \
{ \
entrytype *new_hash; \
entrytype *old_hash = pr->pr##table; \
- usize_t old_size; \
- usize_t i, j, i0; \
- usize_t again = 0, used = 0, collisions = 0; \
+ size_t old_size; \
+ size_t i, j, i0; \
+ size_t again = 0, used = 0, collisions = 0; \
\
(void)realloc_arg; \
\
@@ -256,7 +256,7 @@
HTABLE2_SCOPE \
int prefix##_remove(type *pr, entrytype const e) \
{ \
- usize_t i, j, k, size = pr->pr##size; \
+ size_t i, j, k, size = pr->pr##size; \
entrytype *htable = pr->pr##table; \
\
/* Search for entry */ \
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/sofia-sip/su_alloc.h
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/sofia-sip/su_alloc.h (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/sofia-sip/su_alloc.h Mon Nov 19 13:09:15 2007
@@ -107,6 +107,10 @@
SU_DLL int su_home_mutex_unlock(su_home_t *home);
+SU_DLL int su_home_lock(su_home_t *home);
+SU_DLL int su_home_trylock(su_home_t *home);
+SU_DLL int su_home_unlock(su_home_t *home);
+
SU_DLL void *su_alloc(su_home_t *h, isize_t size)
__attribute__((__malloc__));
SU_DLL void *su_zalloc(su_home_t *h, isize_t size)
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/su_alloc.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/su_alloc.c (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/su_alloc.c Mon Nov 19 13:09:15 2007
@@ -186,6 +186,7 @@
#include "sofia-sip/su_alloc_stat.h"
#include "sofia-sip/su_errno.h"
+#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <memory.h>
@@ -193,17 +194,18 @@
#include <assert.h>
-void (*su_home_locker)(void *mutex);
-void (*su_home_unlocker)(void *mutex);
+int (*_su_home_locker)(void *mutex);
+int (*_su_home_unlocker)(void *mutex);
-void (*su_home_mutex_locker)(void *mutex);
-void (*su_home_mutex_unlocker)(void *mutex);
+int (*_su_home_mutex_locker)(void *mutex);
+int (*_su_home_mutex_trylocker)(void *mutex);
+int (*_su_home_mutex_unlocker)(void *mutex);
-void (*su_home_destroy_mutexes)(void *mutex);
+void (*_su_home_destroy_mutexes)(void *mutex);
#define MEMLOCK(h) \
- (((h) && (h)->suh_lock ? su_home_locker((h)->suh_lock) : (void)0), (h)->suh_blocks)
-#define UNLOCK(h) (((h) && (h)->suh_lock ? su_home_unlocker((h)->suh_lock) : (void)0), NULL)
+ ((void)((h) && (h)->suh_lock ? _su_home_locker((h)->suh_lock) : 0), (h)->suh_blocks)
+#define UNLOCK(h) ((void)((h) && (h)->suh_lock ? _su_home_unlocker((h)->suh_lock) : 0), NULL)
#ifdef NDEBUG
#define MEMCHECK 0
@@ -987,7 +989,7 @@
home->suh_blocks = NULL;
if (home->suh_lock)
- su_home_destroy_mutexes(home->suh_lock);
+ _su_home_destroy_mutexes(home->suh_lock);
}
home->suh_lock = NULL;
@@ -1462,42 +1464,108 @@
return home && home->suh_lock;
}
-/** Obtain exclusive lock on home (if home is threadsafe). */
+/** Increase refcount and obtain exclusive lock on home.
+ *
+ * @note The #su_home_t structure must be created with su_home_new() or
+ * su_home_clone(), or initialized with su_home_init() before using this
+ * function.
+ *
+ * In order to enable actual locking, use su_home_threadsafe(), too.
+ * Otherwise the su_home_mutex_lock() will just increase the reference
+ * count.
+ */
int su_home_mutex_lock(su_home_t *home)
{
+ int error;
+
if (home == NULL)
return su_seterrno(EFAULT);
- if (home->suh_lock) {
- su_home_ref(home);
- su_home_mutex_locker(home->suh_lock);
- }
- else if (home->suh_blocks) {
- if (!su_home_ref(home))
- return -1;
- }
+ if (home->suh_blocks == NULL || !su_home_ref(home))
+ return su_seterrno(EINVAL); /* Uninitialized home */
+
+ if (!home->suh_lock)
+ return 0; /* No-op */
+
+ error = _su_home_mutex_locker(home->suh_lock);
+ if (error)
+ return su_seterrno(error);
return 0;
}
-/** Release exclusive lock on home (if home is threadsafe) */
+/** Release exclusive lock on home and decrease refcount (if home is threadsafe) */
int su_home_mutex_unlock(su_home_t *home)
{
if (home == NULL)
return su_seterrno(EFAULT);
if (home->suh_lock) {
- su_home_mutex_unlocker(home->suh_lock);
- su_home_unref(home);
- }
- else if (home->suh_blocks) {
- su_home_unref(home);
+ int error = _su_home_mutex_unlocker(home->suh_lock);
+ if (error)
+ return su_seterrno(error);
}
+ if (home->suh_blocks == NULL)
+ return su_seterrno(EINVAL), -1; /* Uninitialized home */
+
+ su_home_unref(home);
+
return 0;
}
+/** Obtain exclusive lock on home without increasing refcount.
+ *
+ * @return 0 if successful, -1 if not threadsafe, error code otherwise.
+ *
+ */
+int su_home_lock(su_home_t *home)
+{
+ if (home == NULL)
+ return EFAULT;
+
+ if (home->suh_lock == NULL)
+ return -1; /* No-op */
+
+ return _su_home_mutex_locker(home->suh_lock);
+}
+
+
+/** Try to obtain exclusive lock on home without increasing refcount.
+ *
+ * @return 0 if successful, -1 if not threadsafe,
+ * EBUSY if already locked, error code otherwise.
+ *
+ */
+int su_home_trylock(su_home_t *home)
+{
+ if (home == NULL)
+ return EFAULT;
+
+ if (home->suh_lock == NULL)
+ return -1; /* No-op */
+
+ return _su_home_mutex_trylocker(home->suh_lock);
+}
+
+
+/** Release exclusive lock on home.
+ *
+ * @return 0 if successful, -1 if not threadsafe, error code otherwise.
+ */
+int su_home_unlock(su_home_t *home)
+{
+ if (home == NULL)
+ return EFAULT;
+
+ if (home->suh_lock == NULL)
+ return -1; /* No-op */
+
+ return _su_home_mutex_unlocker(home->suh_lock);
+}
+
+
/** Initialize statistics structure */
void su_home_init_stats(su_home_t *home)
{
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/su_alloc_lock.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/su_alloc_lock.c (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/su_alloc_lock.c Mon Nov 19 13:09:15 2007
@@ -41,25 +41,32 @@
#include <assert.h>
#include <stdlib.h>
-extern void (*su_home_locker)(void *mutex);
-extern void (*su_home_unlocker)(void *mutex);
+extern int (*_su_home_locker)(void *mutex);
+extern int (*_su_home_unlocker)(void *mutex);
-extern void (*su_home_mutex_locker)(void *mutex);
-extern void (*su_home_mutex_unlocker)(void *mutex);
+extern int (*_su_home_mutex_locker)(void *mutex);
+extern int (*_su_home_mutex_trylocker)(void *mutex);
+extern int (*_su_home_mutex_unlocker)(void *mutex);
-extern void (*su_home_destroy_mutexes)(void *mutex);
+extern void (*_su_home_destroy_mutexes)(void *mutex);
/** Mutex */
-static void mutex_locker(void *_mutex)
+static int mutex_locker(void *_mutex)
{
pthread_mutex_t *mutex = _mutex;
- pthread_mutex_lock(mutex + 1);
+ return pthread_mutex_lock(mutex + 1);
}
-static void mutex_unlocker(void *_mutex)
+int mutex_trylocker(void *_mutex)
{
pthread_mutex_t *mutex = _mutex;
- pthread_mutex_unlock(mutex + 1);
+ return pthread_mutex_trylock(mutex + 1);
+}
+
+static int mutex_unlocker(void *_mutex)
+{
+ pthread_mutex_t *mutex = _mutex;
+ return pthread_mutex_unlock(mutex + 1);
}
static void mutex_destroy(void *_mutex)
@@ -69,7 +76,6 @@
pthread_mutex_destroy(mutex + 1);
free(_mutex);
}
-
#endif
@@ -100,13 +106,14 @@
#endif
#if SU_HAVE_PTHREADS
- if (!su_home_unlocker) {
+ if (!_su_home_unlocker) {
/* Avoid linking pthread library just for memory management */
- su_home_mutex_locker = mutex_locker;
- su_home_mutex_unlocker = mutex_unlocker;
- su_home_locker = (void (*)(void *))pthread_mutex_lock;
- su_home_unlocker = (void (*)(void *))pthread_mutex_unlock;
- su_home_destroy_mutexes = mutex_destroy;
+ _su_home_mutex_locker = mutex_locker;
+ _su_home_mutex_trylocker = mutex_trylocker;
+ _su_home_mutex_unlocker = mutex_unlocker;
+ _su_home_locker = (int (*)(void *))pthread_mutex_lock;
+ _su_home_unlocker = (int (*)(void *))pthread_mutex_unlock;
+ _su_home_destroy_mutexes = mutex_destroy;
}
mutex = calloc(1, 2 * (sizeof *mutex));
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/su_log.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/su_log.c (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/su_log.c Mon Nov 19 13:09:15 2007
@@ -37,6 +37,7 @@
#include <sofia-sip/su_log.h>
#include <sofia-sip/su_errno.h>
+#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <assert.h>
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/su_pthread_port.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/su_pthread_port.c (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/su_pthread_port.c Mon Nov 19 13:09:15 2007
@@ -97,7 +97,7 @@
PORT_LOCK_DEBUG(("%p at %s locking(%p)...",
(void *)pthread_self(), who, self));
- su_home_mutex_lock(self->sup_base->sup_home);
+ su_home_lock(self->sup_base->sup_home);
PORT_LOCK_DEBUG((" ...%p at %s locked(%p)...",
(void *)pthread_self(), who, self));
@@ -105,7 +105,7 @@
void su_pthread_port_unlock(su_port_t *self, char const *who)
{
- su_home_mutex_unlock(self->sup_base->sup_home);
+ su_home_unlock(self->sup_base->sup_home);
PORT_LOCK_DEBUG((" ...%p at %s unlocked(%p)\n",
(void *)pthread_self(), who, self));
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/su_strlst.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/su_strlst.c (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/su_strlst.c Mon Nov 19 13:09:15 2007
@@ -79,6 +79,7 @@
#include "sofia-sip/su_config.h"
#include "sofia-sip/su_strlst.h"
+#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <memory.h>
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/torture_su_alloc.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/torture_su_alloc.c (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/su/torture_su_alloc.c Mon Nov 19 13:09:15 2007
@@ -39,6 +39,7 @@
#include <stdlib.h>
#include <sofia-sip/su_alloc.h>
+#include <sofia-sip/su_errno.h>
#include <sofia-sip/su_strlst.h>
#include <sofia-sip/su_alloc_stat.h>
@@ -194,6 +195,42 @@
END();
}
+static int test_lock(void)
+{
+ su_home_t home[1] = { SU_HOME_INIT(home) };
+
+ BEGIN();
+
+ TEST(su_home_mutex_lock(home), -1);
+ TEST(su_home_mutex_unlock(home), -1);
+
+ TEST(su_home_lock(home), -1);
+ TEST(su_home_trylock(home), -1);
+ TEST(su_home_unlock(home), -1);
+
+ TEST(su_home_init(home), 0);
+
+ TEST(su_home_mutex_lock(home), 0);
+ TEST(su_home_trylock(home), -1);
+ TEST(su_home_mutex_unlock(home), 0);
+ TEST(su_home_trylock(home), -1);
+
+ TEST(su_home_threadsafe(home), 0);
+
+ TEST(su_home_mutex_lock(home), 0);
+ TEST(su_home_trylock(home), EBUSY);
+ TEST(su_home_mutex_unlock(home), 0);
+
+ TEST(su_home_lock(home), 0);
+ TEST(su_home_trylock(home), EBUSY);
+ TEST(su_home_unlock(home), 0);
+
+ TEST(su_home_trylock(home), 0);
+ TEST(su_home_unlock(home), 0);
+
+ END();
+}
+
static int test_strdupcat(void)
{
su_home_t home[1] = { SU_HOME_INIT(home) };
@@ -708,6 +745,7 @@
#endif
retval |= test_alloc();
+ retval |= test_lock();
retval |= test_strdupcat();
retval |= test_sprintf("%s.%s", "foo", "bar");
retval |= test_strlst();
@@ -716,4 +754,3 @@
return retval;
}
-
Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/url/url.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/url/url.c (original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/url/url.c Mon Nov 19 13:09:15 2007
@@ -40,6 +40,7 @@
#include <sofia-sip/string0.h>
+#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
More information about the Freeswitch-trunk
mailing list