PJ_DEF(pjsip_target*) pjsip_target_set_get_next(const pjsip_target_set *tset)
{
    const pjsip_target *t, *next = NULL;

    t = tset->head.next;
    while (t != &tset->head) {
	if (PJSIP_IS_STATUS_IN_CLASS(t->code, 200)) {
	    /* No more target since one target has been successful */
	    return NULL;
	}
	if (PJSIP_IS_STATUS_IN_CLASS(t->code, 600)) {
	    /* No more target since one target returned global error */
	    return NULL;
	}
	if (t->code==0 && next==NULL) {
	    /* This would be the next target as long as we don't find
	     * targets with 2xx or 6xx status after this.
	     */
	    next = t;
	}
	t = t->next;
    }

    return (pjsip_target*)next;
}
PJ_DEF(pjsip_target*) pjsip_target_set_get_next(const pjsip_target_set *tset)
{
    const pjsip_target *t, *next = NULL;

    t = tset->head.next;
    while (t != &tset->head) {
	if (PJSIP_IS_STATUS_IN_CLASS(t->code, 200)) {
	     
	    return NULL;
	}
	if (PJSIP_IS_STATUS_IN_CLASS(t->code, 600)) {
	     
	    return NULL;
	}
	if (t->code==0 && next==NULL) {
	     
	    next = t;
	}
	t = t->next;
    }

    return (pjsip_target*)next;
}