Ignore:
Timestamp:
Nov 27, 2008 12:06:46 AM (15 years ago)
Author:
bennylp
Message:

Ticket #10: handle redirection response in the invite session

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsip/sip_util.c

    r2103 r2370  
    4949static pj_str_t str_TEXT = { "text", 4}, 
    5050                str_PLAIN = { "plain", 5 }; 
     51 
     52/* Add URI to target-set */ 
     53PJ_DEF(pj_status_t) pjsip_target_set_add_uri( pjsip_target_set *tset, 
     54                                              pj_pool_t *pool, 
     55                                              const pjsip_uri *uri, 
     56                                              int q1000) 
     57{ 
     58    pjsip_target *t, *pos = NULL; 
     59 
     60    PJ_ASSERT_RETURN(tset && pool && uri, PJ_EINVAL); 
     61 
     62    /* Set q-value to 1 if it is not set */ 
     63    if (q1000 <= 0) 
     64        q1000 = 1000; 
     65 
     66    /* Scan all the elements to see for duplicates, and at the same time 
     67     * get the position where the new element should be inserted to 
     68     * based on the q-value. 
     69     */ 
     70    t = tset->head.next; 
     71    while (t != &tset->head) { 
     72        if (pjsip_uri_cmp(PJSIP_URI_IN_REQ_URI, t->uri, uri)==PJ_SUCCESS) 
     73            return PJ_EEXISTS; 
     74        if (pos==NULL && t->q1000 < q1000) 
     75            pos = t; 
     76        t = t->next; 
     77    } 
     78 
     79    /* Create new element */ 
     80    t = PJ_POOL_ZALLOC_T(pool, pjsip_target); 
     81    t->uri = pjsip_uri_clone(pool, uri); 
     82    t->q1000 = q1000; 
     83 
     84    /* Insert */ 
     85    if (pos == NULL) 
     86        pj_list_push_back(&tset->head, t); 
     87    else 
     88        pj_list_insert_before(pos, t); 
     89 
     90    /* Set current target if this is the first URI */ 
     91    if (tset->current == NULL) 
     92        tset->current = t; 
     93 
     94    return PJ_SUCCESS; 
     95} 
     96 
     97/* Add URI's in the Contact header in the message to target-set */ 
     98PJ_DEF(pj_status_t) pjsip_target_set_add_from_msg( pjsip_target_set *tset, 
     99                                                   pj_pool_t *pool, 
     100                                                   const pjsip_msg *msg) 
     101{ 
     102    const pjsip_hdr *hdr; 
     103    unsigned added = 0; 
     104 
     105    PJ_ASSERT_RETURN(tset && pool && msg, PJ_EINVAL); 
     106 
     107    /* Scan for Contact headers and add the URI */ 
     108    hdr = msg->hdr.next; 
     109    while (hdr != &msg->hdr) { 
     110        if (hdr->type == PJSIP_H_CONTACT) { 
     111            const pjsip_contact_hdr *cn_hdr = (const pjsip_contact_hdr*)hdr; 
     112 
     113            if (!cn_hdr->star) { 
     114                pj_status_t rc; 
     115                rc = pjsip_target_set_add_uri(tset, pool, cn_hdr->uri,  
     116                                              cn_hdr->q1000); 
     117                if (rc == PJ_SUCCESS) 
     118                    ++added; 
     119            } 
     120        } 
     121        hdr = hdr->next; 
     122    } 
     123 
     124    return added ? PJ_SUCCESS : PJ_EEXISTS; 
     125} 
     126 
     127 
     128/* Get next target, if any */ 
     129PJ_DEF(pjsip_target*) pjsip_target_set_get_next(const pjsip_target_set *tset) 
     130{ 
     131    const pjsip_target *t, *next = NULL; 
     132 
     133    t = tset->head.next; 
     134    while (t != &tset->head) { 
     135        if (PJSIP_IS_STATUS_IN_CLASS(t->code, 200)) { 
     136            /* No more target since one target has been successful */ 
     137            return NULL; 
     138        } 
     139        if (PJSIP_IS_STATUS_IN_CLASS(t->code, 600)) { 
     140            /* No more target since one target returned global error */ 
     141            return NULL; 
     142        } 
     143        if (t->code==0 && next==NULL) { 
     144            /* This would be the next target as long as we don't find 
     145             * targets with 2xx or 6xx status after this. 
     146             */ 
     147            next = t; 
     148        } 
     149        t = t->next; 
     150    } 
     151 
     152    return (pjsip_target*)next; 
     153} 
     154 
     155 
     156/* Set current target */ 
     157PJ_DEF(pj_status_t) pjsip_target_set_set_current( pjsip_target_set *tset, 
     158                                                  pjsip_target *target) 
     159{ 
     160    PJ_ASSERT_RETURN(tset && target, PJ_EINVAL); 
     161    PJ_ASSERT_RETURN(pj_list_find_node(tset, target) != NULL, PJ_ENOTFOUND); 
     162 
     163    tset->current = target; 
     164 
     165    return PJ_SUCCESS; 
     166} 
     167 
     168 
     169/* Assign status to a target */ 
     170PJ_DEF(pj_status_t) pjsip_target_assign_status( pjsip_target *target, 
     171                                                pj_pool_t *pool, 
     172                                                int status_code, 
     173                                                const pj_str_t *reason) 
     174{ 
     175    PJ_ASSERT_RETURN(target && pool && status_code && reason, PJ_EINVAL); 
     176 
     177    target->code = status_code; 
     178    pj_strdup(pool, &target->reason, reason); 
     179 
     180    return PJ_SUCCESS; 
     181} 
     182 
     183 
    51184 
    52185/* 
Note: See TracChangeset for help on using the changeset viewer.