Ignore:
Timestamp:
Jun 15, 2009 4:03:40 PM (15 years ago)
Author:
bennylp
Message:

Ticket #873: Include the parsed XML tuple in the pjsip_pres_status, and include it in the pjsua_buddy_info in PJSUA-LIB, in case the PIDF document contains other info that is needed by application (thanks Johan Lantz for the suggestion)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsip-simple/presence.c

    r2730 r2762  
    7474    pjsip_dialog        *dlg;           /**< The dialog.                    */ 
    7575    content_type_e       content_type;  /**< Content-Type.                  */ 
     76    pj_pool_t           *status_pool;   /**< Pool for pres_status           */ 
    7677    pjsip_pres_status    status;        /**< Presence status.               */ 
     78    pj_pool_t           *tmp_pool;      /**< Pool for tmp_status            */ 
    7779    pjsip_pres_status    tmp_status;    /**< Temp, before NOTIFY is answred.*/ 
    7880    pjsip_evsub_user     user_cb;       /**< The user callback.             */ 
     
    186188    pj_status_t status; 
    187189    pjsip_pres *pres; 
     190    char obj_name[PJ_MAX_OBJ_NAME]; 
    188191    pjsip_evsub *sub; 
    189192 
     
    205208        pj_memcpy(&pres->user_cb, user_cb, sizeof(pjsip_evsub_user)); 
    206209 
     210    pj_ansi_snprintf(obj_name, PJ_MAX_OBJ_NAME, "pres%p", dlg->pool); 
     211    pres->status_pool = pj_pool_create(dlg->pool->factory, obj_name,  
     212                                       512, 512, NULL); 
     213    pj_ansi_snprintf(obj_name, PJ_MAX_OBJ_NAME, "tmpres%p", dlg->pool); 
     214    pres->tmp_pool = pj_pool_create(dlg->pool->factory, obj_name,  
     215                                    512, 512, NULL); 
     216 
    207217    /* Attach to evsub */ 
    208218    pjsip_evsub_set_mod_data(sub, mod_presence.id, pres); 
     
    229239    pjsip_evsub *sub; 
    230240    pjsip_pres *pres; 
     241    char obj_name[PJ_MAX_OBJ_NAME]; 
    231242    pj_status_t status; 
    232243 
     
    298309        pj_memcpy(&pres->user_cb, user_cb, sizeof(pjsip_evsub_user)); 
    299310 
     311    pj_ansi_snprintf(obj_name, PJ_MAX_OBJ_NAME, "pres%p", dlg->pool); 
     312    pres->status_pool = pj_pool_create(dlg->pool->factory, obj_name,  
     313                                       512, 512, NULL); 
     314    pj_ansi_snprintf(obj_name, PJ_MAX_OBJ_NAME, "tmpres%p", dlg->pool); 
     315    pres->tmp_pool = pj_pool_create(dlg->pool->factory, obj_name,  
     316                                    512, 512, NULL); 
     317 
    300318    /* Attach to evsub */ 
    301319    pjsip_evsub_set_mod_data(sub, mod_presence.id, pres); 
     
    356374    PJ_ASSERT_RETURN(pres!=NULL, PJSIP_SIMPLE_ENOPRESENCE); 
    357375 
    358     if (pres->tmp_status._is_valid) 
     376    if (pres->tmp_status._is_valid) { 
     377        PJ_ASSERT_RETURN(pres->tmp_pool!=NULL, PJSIP_SIMPLE_ENOPRESENCE); 
    359378        pj_memcpy(status, &pres->tmp_status, sizeof(pjsip_pres_status)); 
    360     else 
     379    } else { 
     380        PJ_ASSERT_RETURN(pres->status_pool!=NULL, PJSIP_SIMPLE_ENOPRESENCE); 
    361381        pj_memcpy(status, &pres->status, sizeof(pjsip_pres_status)); 
     382    } 
    362383 
    363384    return PJ_SUCCESS; 
     
    372393{ 
    373394    unsigned i; 
     395    pj_pool_t *tmp; 
    374396    pjsip_pres *pres; 
    375397 
     
    381403    for (i=0; i<status->info_cnt; ++i) { 
    382404        pres->status.info[i].basic_open = status->info[i].basic_open; 
    383         if (status->info[i].id.slen == 0) { 
     405        if (pres->status.info[i].id.slen) { 
     406            /* Id already set */ 
     407        } else if (status->info[i].id.slen == 0) { 
    384408            pj_create_unique_string(pres->dlg->pool,  
    385409                                    &pres->status.info[i].id); 
     
    389413                      &status->info[i].id); 
    390414        } 
    391         pj_strdup(pres->dlg->pool,  
     415        pj_strdup(pres->tmp_pool,  
    392416                  &pres->status.info[i].contact, 
    393417                  &status->info[i].contact); 
     
    396420        pres->status.info[i].rpid.activity =  
    397421            status->info[i].rpid.activity; 
    398         pj_strdup(pres->dlg->pool,  
     422        pj_strdup(pres->tmp_pool,  
    399423                  &pres->status.info[i].rpid.id, 
    400424                  &status->info[i].rpid.id); 
    401         pj_strdup(pres->dlg->pool, 
     425        pj_strdup(pres->tmp_pool, 
    402426                  &pres->status.info[i].rpid.note, 
    403427                  &status->info[i].rpid.note); 
     
    406430 
    407431    pres->status.info_cnt = status->info_cnt; 
     432 
     433    /* Swap pools */ 
     434    tmp = pres->tmp_pool; 
     435    pres->tmp_pool = pres->status_pool; 
     436    pres->status_pool = tmp; 
     437    pj_pool_reset(pres->tmp_pool); 
    408438 
    409439    return PJ_SUCCESS; 
     
    573603    if (pres->user_cb.on_evsub_state) 
    574604        (*pres->user_cb.on_evsub_state)(sub, event); 
     605 
     606    if (pjsip_evsub_get_state(sub) == PJSIP_EVSUB_STATE_TERMINATED) { 
     607        if (pres->status_pool) { 
     608            pj_pool_release(pres->status_pool); 
     609            pres->status_pool = NULL; 
     610        } 
     611        if (pres->tmp_pool) { 
     612            pj_pool_release(pres->tmp_pool); 
     613            pres->tmp_pool = NULL; 
     614        } 
     615    } 
    575616} 
    576617 
     
    671712        pj_stricmp(&ctype_hdr->media.subtype, &STR_PIDF_XML)==0) 
    672713    { 
    673         status = pjsip_pres_parse_pidf( rdata, pres->dlg->pool, 
     714        status = pjsip_pres_parse_pidf( rdata, pres->tmp_pool, 
    674715                                        &pres->tmp_status); 
    675716    } 
     
    678719        pj_stricmp(&ctype_hdr->media.subtype, &STR_XPIDF_XML)==0) 
    679720    { 
    680         status = pjsip_pres_parse_xpidf( rdata, pres->dlg->pool, 
     721        status = pjsip_pres_parse_xpidf( rdata, pres->tmp_pool, 
    681722                                         &pres->tmp_status); 
    682723    } 
     
    741782 
    742783    } else { 
     784#if 1 
     785        /* This is the newest change, http://trac.pjsip.org/repos/ticket/873 
     786         * Some app want to be notified about the empty NOTIFY, e.g. to  
     787         * decide whether it should consider the buddy as offline. 
     788         * In this case, leave the buddy state unchanged, but set the 
     789         * "tuple_node" in pjsip_pres_status to NULL. 
     790         */ 
     791        unsigned i; 
     792        for (i=0; i<pres->status.info_cnt; ++i) { 
     793            pres->status.info[i].tuple_node = NULL; 
     794        } 
     795 
     796#elif 0 
    743797        /* This has just been changed. Previously, we treat incoming NOTIFY 
    744798         * with no message body as having the presence subscription closed. 
    745799         * Now we treat it as no change in presence status (ref: EyeBeam). 
    746800         */ 
    747 #if 1 
    748801        *p_st_code = 200; 
    749802        return; 
     
    768821     */ 
    769822    if ((*p_st_code)/100 == 2) { 
     823        pj_pool_t *tmp; 
     824 
    770825        pj_memcpy(&pres->status, &pres->tmp_status, sizeof(pjsip_pres_status)); 
     826 
     827        /* Swap the pool */ 
     828        tmp = pres->tmp_pool; 
     829        pres->tmp_pool = pres->status_pool; 
     830        pres->status_pool = tmp; 
    771831    } 
    772832 
    773833    pres->tmp_status._is_valid = PJ_FALSE; 
     834    pj_pool_reset(pres->tmp_pool); 
    774835 
    775836    /* Done */ 
Note: See TracChangeset for help on using the changeset viewer.