Commit 3d7e0daa authored by Pekka Pessi's avatar Pekka Pessi

UNDO: torture_sip.c: added test for sip_header_as_string() producing string longer than 128

darcs-hash:20080418105545-65a35-fc0f5e268af53e138970dd71675793a6c1d28bea.gz
parent 1d1b74d7
......@@ -1675,7 +1675,7 @@ int accept_n_notifys(CONDITION_PARAMS)
/* ======================================================================== */
int save_until_substate_terminated(CONDITION_PARAMS);
int save_until_subscription_terminated(CONDITION_PARAMS);
int accept_subscription_until_terminated(CONDITION_PARAMS);
/* Timeout subscription */
......@@ -1705,7 +1705,7 @@ int test_subscription_timeout(struct context *ctx)
TAG_END());
run_ab_until(ctx,
-1, save_until_substate_terminated,
-1, save_until_subscription_terminated,
-1, accept_subscription_until_terminated);
/* Client events:
......@@ -1777,7 +1777,7 @@ int test_subscription_timeout(struct context *ctx)
END();
}
int save_until_substate_terminated(CONDITION_PARAMS)
int save_until_subscription_terminated(CONDITION_PARAMS)
{
void *with = nua_current_request(nua);
......@@ -1787,9 +1787,8 @@ int save_until_substate_terminated(CONDITION_PARAMS)
if (status < 200)
RESPOND(ep, call, nh, SIP_200_OK, NUTAG_WITH(with), TAG_END());
return
!sip->sip_subscription_state ||
!strcasecmp(sip->sip_subscription_state->ss_substate, "terminated");
tags = tl_find(tags, nutag_substate);
return tags && tags->t_value == nua_substate_terminated;
}
return 0;
......
......@@ -2247,31 +2247,6 @@ static int test_content_disposition(void)
END();
}
static int test_www_authenticate(void)
{
sip_www_authenticate_t *www;
su_home_t *home;
char const *s;
BEGIN();
TEST_1(home = su_home_create());
TEST_1(www = sip_www_authenticate_make
(home, "Digest realm=\"Registered_Subscribers\",\n"
"domain=\"sip:206.229.26.61\",\n"
"nonce=\"20dfb7e5a77abee7a02dbe53efe42cdd\", "
"opaque=\"423767123y723742376423762376423784623782a794e58\",\n"
"stale=FALSE,algorithm=MD5"));
TEST_S(www->au_scheme, "Digest");
TEST_1(www->au_params && www->au_params[0] && www->au_params[1] && www->au_params[2] &&
www->au_params[3] && www->au_params[4] && www->au_params[5] &&
!www->au_params[6]);
TEST_1(s = sip_header_as_string(home, (sip_header_t *)www));
TEST_1(strlen(s) >= 128);
su_home_unref(home);
END();
}
int test_retry_after(void)
{
/* Test Session-Expires header */
......@@ -3573,7 +3548,7 @@ int main(int argc, char *argv[])
retval |= test_caller_prefs(); fflush(stdout);
retval |= test_callerpref_scoring(); fflush(stdout);
retval |= test_warning(); fflush(stdout);
retval |= test_www_authenticate(); fflush(stdout);
retval |= test_sec_ext(); fflush(stdout);
retval |= test_utils(); fflush(stdout);
......
......@@ -50,7 +50,7 @@ SOFIA_BEGIN_DECLS
typedef SU_HOME_T su_home_t;
typedef struct su_block_s su_block_t;
/** Thread-locking structure. @internal */
/** Thread-locking function. @internal */
typedef struct su_alock su_alock_t;
/** Memory home structure */
......@@ -66,7 +66,6 @@ SU_DLL void *su_home_new(isize_t size)
__attribute__((__malloc__));
SU_DLL void *su_home_ref(su_home_t const *);
SU_DLL int su_home_unref(su_home_t *);
SU_DLL int su_home_zapref(su_home_t *);
SU_DLL size_t su_home_refcount(su_home_t *home);
......
......@@ -194,53 +194,24 @@
#include <assert.h>
v v v v v v v
int (*_su_home_locker)(void *mutex);
int (*_su_home_unlocker)(void *mutex);
*************
void (*su_home_locker)(void *alock);
void (*su_home_unlocker)(void *alock);
^ ^ ^ ^ ^ ^ ^
v v v v v v v
int (*_su_home_mutex_locker)(void *mutex);
int (*_su_home_mutex_trylocker)(void *mutex);
int (*_su_home_mutex_unlocker)(void *mutex);
*************
int (*su_home_wait)(void *alock);
^ ^ ^ ^ ^ ^ ^
v v v v v v v
void (*_su_home_destroy_mutexes)(void *mutex);
*************
void (*su_home_mutex_locker)(void *alock);
void (*su_home_mutex_unlocker)(void *alock);
^ ^ ^ ^ ^ ^ ^
v v v v v v v
#if HAVE_FREE_NULL
#define safefree(x) free((x))
#else
su_inline void safefree(void *b) { b ? free(b) : (void)0; }
#endif
*************
void (*su_home_destroy_mutexes)(void *alock);
/** @intenal Obtain home lock. @retval Pointer to #su_block_t */
^ ^ ^ ^ ^ ^ ^
#define MEMLOCK(h) \
v v v v v v v
(((h) && (h)->suh_lock ? su_home_locker((h)->suh_lock) : (void)0), (h)->suh_blocks)
/** @internal Release home lock. @retval 0 */
#define UNLOCK(h) (((h) && (h)->suh_lock ? su_home_unlocker((h)->suh_lock) : (void)0), 0)
/** @internal Wait for home lock to be used. @retval 1 if waited @retval 0 if not threadsafe */
#define WAIT(h) ((h)->suh_lock ? su_home_wait((h)->suh_lock) : 0)
*************
((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
......@@ -683,51 +654,6 @@ int su_home_unref(su_home_t *home)
sub = MEMLOCK(home);
if (sub == NULL) {
/* Xyzzy */
return 0;
}
else if (sub->sub_ref == REF_MAX) {
return UNLOCK(home);
}
else if (--sub->sub_ref > 0) {
return UNLOCK(home);
}
else if (sub->sub_parent) {
su_home_t *parent = sub->sub_parent;
UNLOCK(home);
su_free(parent, home);
return 1;
}
else {
int hauto = sub->sub_hauto;
_su_home_deinit(home);
if (!hauto)
free(home);
/* UNLOCK(home); */
return 1;
}
}
/**Wait until all other references to su_home_t object are removed and free home.
*
* Waits until all other references to su_home_t object are removed then free home.
* Requires that the home is threadsafe.
*
* @param home memory pool object to be zapped
*
* @retval 1 if object was freed
* @retval 0 if
*/
int su_home_zapref(su_home_t *home)
{
su_block_t *sub;
if (home == NULL)
return 0;
sub = MEMLOCK(home);
if (sub == NULL) {
/* Xyzzy */
return 0;
......@@ -736,17 +662,11 @@ int su_home_zapref(su_home_t *home)
UNLOCK(home);
return 0;
}
while (sub->sub_ref > 1 && WAIT(home))
;
sub->sub_ref--; assert(sub->sub_ref == 0);
if (sub->sub_ref > 0) {
else if (--sub->sub_ref > 0) {
UNLOCK(home);
return 0;
}
if (sub->sub_parent) {
else if (sub->sub_parent) {
su_home_t *parent = sub->sub_parent;
UNLOCK(home);
su_free(parent, home);
......@@ -1328,11 +1248,11 @@ void *su_realloc(su_home_t *home, void *data, isize_t size)
sua = su_block_find(sub, data);
if (!su_alloc_check(sub, sua))
return (void *)UNLOCK(home);
return UNLOCK(home);
assert(!sua->sua_home);
if (sua->sua_home)
return (void *)UNLOCK(home);
return UNLOCK(home);
if (!su_is_preloaded(sub, data)) {
ndata = realloc(data, size + MEMCHECK_EXTRA);
......
......@@ -41,75 +41,24 @@
#include <assert.h>
#include <stdlib.h>
v v v v v v v
extern int (*_su_home_locker)(void *mutex);
extern int (*_su_home_unlocker)(void *mutex);
*************
struct su_alock
{
pthread_mutex_t mutex[1]; /* Used by su_home_lock()/unlock */
pthread_mutex_t refmutex[1]; /* Used by reference counting */
pthread_cond_t cond[1];
int signal_on_unlock;
};
extern void (*su_home_locker)(void *alock);
extern void (*su_home_unlocker)(void *alock);
^ ^ ^ ^ ^ ^ ^
v v v v v v v
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 int (*su_home_wait)(void *alock);
^ ^ ^ ^ ^ ^ ^
v v v v v v v
extern void (*_su_home_destroy_mutexes)(void *mutex);
*************
extern void (*su_home_mutex_locker)(void *alock);
extern void (*su_home_mutex_unlocker)(void *alock);
extern void (*su_home_destroy_mutexes)(void *alock);
^ ^ ^ ^ ^ ^ ^
/** Mutex */
v v v v v v v
static int mutex_locker(void *_mutex)
*************
static void mutex_locker(void *alock)
{
struct su_alock *a = alock;
pthread_mutex_lock(a->refmutex);
}
static void mutex_unlocker(void *alock)
^ ^ ^ ^ ^ ^ ^
{
v v v v v v v
pthread_mutex_t *mutex = _mutex;
return pthread_mutex_lock(mutex + 1);
*************
struct su_alock *a = alock;
if (a->signal_on_unlock)
pthread_cond_signal(a->cond);
pthread_mutex_unlock(a->refmutex);
^ ^ ^ ^ ^ ^ ^
}
v v v v v v v
/** @internal
*
* Call after mutex_locker().
*/
static int mutex_wait(void *alock)
*************
int mutex_trylocker(void *_mutex)
^ ^ ^ ^ ^ ^ ^
{
v v v v v v v
pthread_mutex_t *mutex = _mutex;
return pthread_mutex_trylock(mutex + 1);
}
......@@ -118,27 +67,15 @@ static int mutex_unlocker(void *_mutex)
{
pthread_mutex_t *mutex = _mutex;
return pthread_mutex_unlock(mutex + 1);
*************
struct su_alock *a = alock;
a->signal_on_unlock = 1;
pthread_cond_wait(a->cond, a->refmutex);
return 1;
^ ^ ^ ^ ^ ^ ^
}
static void mutex_destroy(void *alock)
static void mutex_destroy(void *_mutex)
{
struct su_alock *a = alock;
pthread_cond_destroy(a->cond);
pthread_mutex_destroy(a->mutex);
pthread_mutex_destroy(a->refmutex);
free(a);
pthread_mutex_t *mutex = _mutex;
pthread_mutex_destroy(mutex + 0);
pthread_mutex_destroy(mutex + 1);
free(_mutex);
}
v v v v v v v
*************
^ ^ ^ ^ ^ ^ ^
#endif
......@@ -154,50 +91,44 @@ v v v v v v v
*/
int su_home_threadsafe(su_home_t *home)
{
struct su_alock *a;
pthread_mutex_t *mutex;
if (home == NULL)
return su_seterrno(EFAULT);
if (home->suh_lock) /* Already? */
return 0;
#if 0 /* Allow threadsafe subhomes */
assert(!su_home_has_parent(home));
if (su_home_has_parent(home))
return su_seterrno(EINVAL);
#endif
#if SU_HAVE_PTHREADS
if (!_su_home_unlocker) {
/* Avoid linking pthread library just for memory management */
v v v v v v v
_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;
*************
su_home_mutex_locker = (void (*)(void *))pthread_mutex_lock;
su_home_mutex_unlocker = (void (*)(void *))pthread_mutex_unlock;
su_home_locker = mutex_locker;
su_home_unlocker = mutex_unlocker;
su_home_wait = mutex_wait;
su_home_destroy_mutexes = mutex_destroy;
^ ^ ^ ^ ^ ^ ^
}
a = calloc(1, (sizeof *a)); assert(a);
if (!a)
return -1;
/* Mutex used for explicit locking */
pthread_mutex_init(a->mutex, NULL);
/* Mutex for memory operations */
pthread_mutex_init(a->refmutex, NULL);
pthread_cond_init(a->cond, NULL);
home->suh_lock = (void *)a;
return 0;
mutex = calloc(1, 2 * (sizeof *mutex));
assert(mutex);
if (mutex) {
/* Mutex for memory operations */
pthread_mutex_init(mutex, NULL);
/* Mutex used for explicit locking */
pthread_mutex_init(mutex + 1, NULL);
home->suh_lock = (void *)mutex;
return 0;
}
#else
(void *)a;
su_seterrno(ENOSYS);
return -1;
#endif
return -1;
}
......@@ -83,19 +83,15 @@ int main(int argc, char *argv[])
typedef struct hentry_s entry_t;
v v v v v v v
^ ^ ^ ^ ^ ^ ^
struct hentry_s
{
hash_value_t e_hash;
unsigned long e_n;
};
v v v v v v v
HTABLE2_DECLARE2(htable2_t, htable2_s, ht2_, entry_t, size_t);
HTABLE2_PROTOS2(htable2_t, htable2, ht2_, entry_t, size_t);
^ ^ ^ ^ ^ ^ ^
#define HENTRY_HASH(e) ((e).e_hash)
#define HENTRY_IS_USED(e) ((e).e_n != 0)
#define HENTRY_REMOVE(e) ((e)->e_n = 0, (e)->e_hash = 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment