Changeset 2762


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)

Location:
pjproject/trunk/pjsip
Files:
6 edited

Legend:

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

    r2394 r2762  
    9090        pj_str_t        id;             /**< Tuple id.                      */ 
    9191        pj_str_t        contact;        /**< Optional contact address.      */ 
     92 
     93        pj_xml_node    *tuple_node;     /**< Pointer to tuple XML node of 
     94                                             parsed PIDF body received from 
     95                                             remote agent. Only valid for 
     96                                             client subscription. If the 
     97                                             last received NOTIFY request 
     98                                             does not contain any PIDF body, 
     99                                             this valud will be set to NULL */ 
    92100 
    93101    } info[PJSIP_PRES_STATUS_MAX_INFO]; /**< Array of info.                 */ 
  • pjproject/trunk/pjsip/include/pjsip/sip_config.h

    r2756 r2762  
    873873 
    874874 
     875/** 
     876 * Add "timestamp" information in generated PIDF document for both server 
     877 * subscription and presence publication. 
     878 * 
     879 * Default: 1 (yes) 
     880 */ 
     881#ifndef PJSIP_PRES_PIDF_ADD_TIMESTAMP 
     882#   define PJSIP_PRES_PIDF_ADD_TIMESTAMP        1 
     883#endif 
     884 
     885 
    875886PJ_END_DECL 
    876887 
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h

    r2738 r2762  
    29082908 
    29092909    /** 
     2910     * Extended presence info. 
     2911     */ 
     2912    pjsip_pres_status   pres_status; 
     2913 
     2914    /** 
    29102915     * Internal buffer. 
    29112916     */ 
  • 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 */ 
  • pjproject/trunk/pjsip/src/pjsip-simple/presence_body.c

    r2394 r2762  
    101101        pjpidf_status_set_basic_open(pidf_status,  
    102102                                     status->info[i].basic_open); 
     103 
     104        /* Add <timestamp> if configured */ 
     105#if defined(PJSIP_PRES_PIDF_ADD_TIMESTAMP) && PJSIP_PRES_PIDF_ADD_TIMESTAMP 
     106        if (PJSIP_PRES_PIDF_ADD_TIMESTAMP) { 
     107          char buf[50]; 
     108          int tslen = 0; 
     109          pj_time_val tv; 
     110          pj_parsed_time pt; 
     111 
     112          pj_gettimeofday(&tv); 
     113          /* TODO: convert time to GMT! (unsupported by pjlib) */ 
     114          pj_time_decode( &tv, &pt); 
     115 
     116          tslen = pj_ansi_snprintf(buf, sizeof(buf), 
     117                                   "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", 
     118                                   pt.year, pt.mon, pt.day,  
     119                                   pt.hour, pt.min, pt.sec, pt.msec); 
     120          if (tslen > 0 && tslen < sizeof(buf)) { 
     121              pj_str_t time = pj_str(buf); 
     122              pjpidf_tuple_set_timestamp(pool, pidf_tuple, &time); 
     123          } 
     124        } 
     125#endif 
    103126    } 
    104127 
     
    180203 
    181204    pidf_tuple = pjpidf_pres_get_first_tuple(pidf); 
    182     while (pidf_tuple) { 
     205    while (pidf_tuple && pres_status->info_cnt < PJSIP_PRES_STATUS_MAX_INFO) { 
    183206        pjpidf_status *pidf_status; 
     207 
     208        pres_status->info[pres_status->info_cnt].tuple_node =  
     209            pj_xml_clone(pool, pidf_tuple); 
    184210 
    185211        pj_strdup(pool,  
     
    232258    pres_status->info[0].basic_open = pjxpidf_get_status(xpidf); 
    233259    pres_status->info[0].id.slen = 0; 
     260    pres_status->info[0].tuple_node = NULL; 
    234261 
    235262    return PJ_SUCCESS; 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_pres.c

    r2661 r2762  
    167167    total += info->contact.slen; 
    168168 
     169    /* Presence status */ 
     170    pj_memcpy(&info->pres_status, &buddy->status, sizeof(pjsip_pres_status)); 
     171 
    169172    /* status and status text */     
    170173    if (buddy->sub == NULL || buddy->status.info_cnt==0) { 
Note: See TracChangeset for help on using the changeset viewer.