Changeset 2661


Ignore:
Timestamp:
Apr 28, 2009 10:19:49 PM (10 years ago)
Author:
bennylp
Message:

Ticket #760: Enhancements to PUBLISH management (thanks Johan Lantz for the suggestion)

  • Changes in PJSUA-LIB
    • retry with fresh request on 412/Conditional Request Failed response
    • changed default Expires in PUBLISH request to none (we will not put Expires), to avoid getting 423/Interval Too Brief response
    • if the PUBLISH fails for any reason, it will be retried on every PJSUA_PRES_TIMER (default 300 seconds), similar to how failed SUBSCRIBE will be retried
  • Changes to publish.h:
    • added API to add headers in every PUBLISH request
  • Added test scenario in Python unit tests
Location:
pjproject/trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/include/pjsip-simple/publish.h

    r2394 r2661  
    7979    pj_str_t             reason;    /**< SIP reason phrase received.        */ 
    8080    pjsip_rx_data       *rdata;     /**< The complete received response.    */ 
    81     int                  expiration;/**< Next expiration interval.          */ 
     81    int                  expiration;/**< Next expiration interval. If the 
     82                                         value is -1, it means the session 
     83                                         will not renew itself.             */ 
    8284}; 
    8385 
     
    191193 
    192194/** 
     195 * Set list of headers to be added to each PUBLISH request generated by 
     196 * the client publication session. Note that application can also add 
     197 * the headers to the request after calling #pjsip_publishc_publish() 
     198 * or #pjsip_publishc_unpublish(), but the benefit of this function is 
     199 * the headers will also be added to requests generated internally by 
     200 * the session, such as during session renewal/refresh. 
     201 * 
     202 * Note that calling this function will clear the previously added list 
     203 * of headers. 
     204 * 
     205 * @param pubc      The client publication structure. 
     206 * @param hdr_list  The list of headers. 
     207 * 
     208 * @return          PJ_SUCCESS on success. 
     209 */ 
     210PJ_DECL(pj_status_t) pjsip_publishc_set_headers(pjsip_publishc *pubc, 
     211                                                const pjsip_hdr *hdr_list); 
     212 
     213/** 
    193214 * Create PUBLISH request for the specified client publication structure. 
    194215 * Application can use this function to both create initial publication 
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h

    r2506 r2661  
    20382038 */ 
    20392039#ifndef PJSUA_PUBLISH_EXPIRATION 
    2040 #   define PJSUA_PUBLISH_EXPIRATION 600 
     2040#   define PJSUA_PUBLISH_EXPIRATION PJSIP_PUBC_EXPIRATION_NOT_SPECIFIED 
    20412041#endif 
    20422042 
     
    34943494/** 
    34953495 * This specifies how long the library should retry resending SUBSCRIBE 
    3496  * if the previous SUBSCRIBE failed. 
     3496 * if the previous SUBSCRIBE failed. This also controls the duration  
     3497 * before failed PUBLISH request will be retried. 
    34973498 * 
    34983499 * Default: 300 seconds 
  • pjproject/trunk/pjsip/src/pjsip-simple/publishc.c

    r2394 r2661  
    8282    pj_uint32_t                  expires; 
    8383    pjsip_route_hdr              route_set; 
     84    pjsip_hdr                    usr_hdr; 
    8485 
    8586    /* Authorization sessions. */ 
     
    158159 
    159160    pj_list_init(&pubc->route_set); 
     161    pj_list_init(&pubc->usr_hdr); 
    160162 
    161163    /* Done */ 
     
    187189static void set_expires( pjsip_publishc *pubc, pj_uint32_t expires) 
    188190{ 
    189     if (expires != pubc->expires) { 
     191    if (expires != pubc->expires &&  
     192        expires != PJSIP_PUBC_EXPIRATION_NOT_SPECIFIED)  
     193    { 
    190194        pubc->expires_hdr = pjsip_expires_hdr_create(pubc->pool, expires); 
    191195    } else { 
     
    277281        pj_list_push_back(&pubc->route_set, pjsip_hdr_clone(pubc->pool, chdr)); 
    278282        chdr = chdr->next; 
     283    } 
     284 
     285    return PJ_SUCCESS; 
     286} 
     287 
     288PJ_DEF(pj_status_t) pjsip_publishc_set_headers( pjsip_publishc *pubc, 
     289                                                const pjsip_hdr *hdr_list) 
     290{ 
     291    const pjsip_hdr *h; 
     292 
     293    PJ_ASSERT_RETURN(pubc && hdr_list, PJ_EINVAL); 
     294 
     295    pj_list_init(&pubc->usr_hdr); 
     296    h = hdr_list->next; 
     297    while (h != hdr_list) { 
     298        pj_list_push_back(&pubc->usr_hdr, pjsip_hdr_clone(pubc->pool, h)); 
     299        h = h->next; 
    279300    } 
    280301 
     
    346367    } 
    347368 
     369    /* Add user headers */ 
     370    if (!pj_list_empty(&pubc->usr_hdr)) { 
     371        const pjsip_hdr *hdr; 
     372 
     373        hdr = pubc->usr_hdr.next; 
     374        while (hdr != &pubc->usr_hdr) { 
     375            pjsip_hdr *new_hdr = (pjsip_hdr*) 
     376                                 pjsip_hdr_shallow_clone(tdata->pool, hdr); 
     377            pjsip_msg_add_hdr(tdata->msg, new_hdr); 
     378            hdr = hdr->next; 
     379        } 
     380    } 
     381 
    348382 
    349383    /* Done. */ 
     
    531565                      pjsip_msg_find_hdr(msg, PJSIP_H_EXPIRES, NULL); 
    532566 
    533             if (expires) 
     567            if (pubc->auto_refresh && expires) 
    534568                expiration = expires->ivalue; 
    535569             
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_pres.c

    r2596 r2661  
    962962 
    963963    if (param->code/100 != 2 || param->status != PJ_SUCCESS) { 
     964 
     965        pjsip_publishc_destroy(param->pubc); 
     966        acc->publish_sess = NULL; 
     967 
    964968        if (param->status != PJ_SUCCESS) { 
    965969            char errmsg[PJ_ERR_MSG_SIZE]; 
     
    969973                      "Client publication (PUBLISH) failed, status=%d, msg=%s", 
    970974                       param->status, errmsg)); 
     975        } else if (param->code == 412) { 
     976            /* 412 (Conditional Request Failed) 
     977             * The PUBLISH refresh has failed, retry with new one. 
     978             */ 
     979            pjsua_pres_init_publish_acc(acc->index); 
     980             
    971981        } else { 
    972982            PJ_LOG(1,(THIS_FILE,  
     
    976986        } 
    977987 
    978         pjsip_publishc_destroy(param->pubc); 
    979         acc->publish_sess = NULL; 
     988    } else { 
     989        if (param->expiration == -1) { 
     990            /* Could happen if server "forgot" to include Expires header 
     991             * in the response. We will not renew, so destroy the pubc. 
     992             */ 
     993            pjsip_publishc_destroy(param->pubc); 
     994            acc->publish_sess = NULL; 
     995        } 
    980996    } 
    981997} 
     
    10921108                                     &acc_cfg->id, &acc_cfg->id, 
    10931109                                     &acc_cfg->id,  
    1094                                      PJSUA_PRES_TIMER); 
     1110                                     PJSUA_PUBLISH_EXPIRATION); 
    10951111        if (status != PJ_SUCCESS) { 
    10961112            acc->publish_sess = NULL; 
     
    16071623                          pj_timer_entry *entry) 
    16081624{ 
     1625    unsigned i; 
    16091626    pj_time_val delay = { PJSUA_PRES_TIMER, 0 }; 
     1627 
     1628    /* Retry failed PUBLISH requests */ 
     1629    for (i=0; i<PJ_ARRAY_SIZE(pjsua_var.acc); ++i) { 
     1630        pjsua_acc *acc = &pjsua_var.acc[i]; 
     1631        if (acc->cfg.publish_enabled && acc->publish_sess==NULL) 
     1632            pjsua_pres_init_publish_acc(acc->index); 
     1633    } 
    16101634 
    16111635    entry->id = PJ_FALSE; 
Note: See TracChangeset for help on using the changeset viewer.