Changeset 1534


Ignore:
Timestamp:
Oct 31, 2007 10:20:31 AM (16 years ago)
Author:
bennylp
Message:

Ticket #405: Subscribe to buddy presence upon receiving incoming subscription from the buddy

Location:
pjproject/trunk/pjsip
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua.h

    r1533 r1534  
    30833083 
    30843084/** 
     3085 * This specifies how long the library should retry resending SUBSCRIBE 
     3086 * if the previous SUBSCRIBE failed. 
     3087 * 
     3088 * Default: 300 seconds 
     3089 */ 
     3090#ifndef PJSUA_PRES_TIMER 
     3091#   define PJSUA_PRES_TIMER         300 
     3092#endif 
     3093 
     3094 
     3095/** 
    30853096 * This structure describes buddy configuration when adding a buddy to 
    30863097 * the buddy list with #pjsua_buddy_add(). Application MUST initialize 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_pres.c

    r1424 r1534  
    2323#define THIS_FILE   "pjsua_pres.c" 
    2424 
    25 #ifndef PJSUA_PRES_TIMER 
    26 #   define PJSUA_PRES_TIMER     120 
    27 #endif 
     25 
     26static void subscribe_buddy_presence(unsigned index); 
     27 
     28 
     29/* 
     30 * Find buddy. 
     31 */ 
     32static pjsua_buddy_id pjsua_find_buddy(const pjsip_uri *uri) 
     33{ 
     34    const pjsip_sip_uri *sip_uri; 
     35    unsigned i; 
     36 
     37    uri = pjsip_uri_get_uri((pjsip_uri*)uri); 
     38 
     39    if (!PJSIP_URI_SCHEME_IS_SIP(uri) && !PJSIP_URI_SCHEME_IS_SIPS(uri)) 
     40        return PJSUA_INVALID_ID; 
     41 
     42    sip_uri = (const pjsip_sip_uri*) uri; 
     43 
     44    for (i=0; i<PJ_ARRAY_SIZE(pjsua_var.buddy); ++i) { 
     45        const pjsua_buddy *b = &pjsua_var.buddy[i]; 
     46 
     47        if (!pjsua_buddy_is_valid(i)) 
     48            continue; 
     49 
     50        if (pj_stricmp(&sip_uri->user, &b->name)==0 && 
     51            pj_stricmp(&sip_uri->host, &b->host)==0 && 
     52            (sip_uri->port==(int)b->port || (sip_uri->port==0 && b->port==5060))) 
     53        { 
     54            /* Match */ 
     55            return i; 
     56        } 
     57    } 
     58 
     59    return PJSUA_INVALID_ID; 
     60} 
    2861 
    2962 
     
    466499    pjsip_expires_hdr *expires_hdr; 
    467500    pjsip_evsub_state ev_state; 
     501    pjsua_buddy_id buddy_id; 
    468502    pj_status_t status; 
    469503 
     
    596630    } 
    597631 
     632 
     633    /* Subscribe to buddy's presence if we're not subscribed */ 
     634    buddy_id = pjsua_find_buddy(dlg->remote.info->uri); 
     635    if (buddy_id != PJSUA_INVALID_ID) { 
     636        pjsua_buddy *b = &pjsua_var.buddy[buddy_id]; 
     637        if (b->monitor && b->sub == NULL) { 
     638            PJ_LOG(4,(THIS_FILE, "Received SUBSCRIBE from buddy %d, " 
     639                      "activating outgoing subscription", buddy_id)); 
     640            subscribe_buddy_presence(buddy_id); 
     641        } 
     642    } 
    598643 
    599644    /* Done: */ 
Note: See TracChangeset for help on using the changeset viewer.