Ignore:
Timestamp:
Feb 21, 2006 11:47:00 PM (18 years ago)
Author:
bennylp
Message:

Implemented major feature: call hold and transfer

File:
1 edited

Legend:

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

    r201 r212  
    198198    pjsip_dialog         *dlg;          /**< Underlying dialog.             */ 
    199199    struct evpkg         *pkg;          /**< The event package.             */ 
     200    unsigned              option;       /**< Options.                       */ 
    200201    pjsip_evsub_user      user;         /**< Callback.                      */ 
    201202    pjsip_role_e          role;         /**< UAC=subscriber, UAS=notifier   */ 
     
    236237static const pj_str_t STR_TIMEOUT    = { "timeout", 7}; 
    237238 
     239 
    238240/* 
    239241 * On unload module. 
     
    246248    return PJ_SUCCESS; 
    247249} 
     250 
     251/* Proto for pjsipsimple_strerror(). 
     252 * Defined in errno.c 
     253 */ 
     254PJ_DECL(pj_str_t) pjsipsimple_strerror( pj_status_t statcode,  
     255                                        char *buf, pj_size_t bufsize ); 
    248256 
    249257/* 
     
    257265        { "NOTIFY", 6} 
    258266    }; 
     267 
     268    pj_register_strerror(PJSIP_SIMPLE_ERRNO_START, PJ_ERRNO_SPACE_SIZE, 
     269                         &pjsipsimple_strerror); 
    259270 
    260271    PJ_ASSERT_RETURN(endpt != NULL, PJ_EINVAL); 
     
    619630                                 const pjsip_evsub_user *user_cb, 
    620631                                 const pj_str_t *event, 
     632                                 unsigned option, 
    621633                                 pjsip_evsub **p_evsub ) 
    622634{ 
     
    641653    sub->pkg = pkg; 
    642654    sub->role = role; 
     655    sub->option = option; 
    643656    sub->state = PJSIP_EVSUB_STATE_NULL; 
    644657    sub->state_str = evsub_state_names[sub->state]; 
     
    698711                                            const pjsip_evsub_user *user_cb, 
    699712                                            const pj_str_t *event, 
     713                                            unsigned option, 
    700714                                            pjsip_evsub **p_evsub) 
    701715{ 
     
    706720 
    707721    pjsip_dlg_inc_lock(dlg); 
    708     status = evsub_create(dlg, PJSIP_UAC_ROLE, user_cb, event, &sub); 
     722    status = evsub_create(dlg, PJSIP_UAC_ROLE, user_cb, event, option, &sub); 
    709723    if (status != PJ_SUCCESS) 
    710724        goto on_return; 
    711725 
    712     /* Add unique Id to Event header */ 
    713     pj_create_unique_string(sub->pool, &sub->event->id_param); 
     726    /* Add unique Id to Event header, only when PJSIP_EVSUB_NO_EVENT_ID 
     727     * is not specified. 
     728     */ 
     729    if ((option & PJSIP_EVSUB_NO_EVENT_ID) == 0) { 
     730        pj_create_unique_string(sub->pool, &sub->event->id_param); 
     731    } 
    714732 
    715733    /* Increment dlg session. */ 
     
    731749                                            const pjsip_evsub_user *user_cb, 
    732750                                            pjsip_rx_data *rdata, 
     751                                            unsigned option, 
    733752                                            pjsip_evsub **p_evsub) 
    734753{ 
     
    758777    PJ_ASSERT_RETURN(user_cb->on_rx_refresh, PJ_EINVALIDOP); 
    759778 
    760     /* Request MUST have "Event" header: */ 
    761  
     779    /* Request MUST have "Event" header. We need the Event header to get  
     780     * the package name (don't want to add more arguments in the function). 
     781     */ 
    762782    event_hdr = (pjsip_event_hdr*)  
    763783        pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &STR_EVENT, NULL); 
     
    773793 
    774794    status = evsub_create(dlg, PJSIP_UAS_ROLE, user_cb,  
    775                           &event_hdr->event_type, &sub); 
     795                          &event_hdr->event_type, option, &sub); 
    776796    if (status != PJ_SUCCESS) 
    777797        goto on_return; 
     
    11481168    } 
    11491169 
     1170 
    11501171    switch (event->body.tsx_state.type) { 
    11511172    case PJSIP_EVENT_RX_MSG: 
     
    11641185     
    11651186    if (!msg) { 
    1166         pj_assert(!"First transaction event is not TX or RX!"); 
     1187        //Note: 
     1188        // this transaction can be other transaction in the dialog. 
     1189        // The assertion below probably only valid for dialog that 
     1190        // only has one event subscription usage. 
     1191        //pj_assert(!"First transaction event is not TX or RX!"); 
    11671192        return NULL; 
    11681193    } 
     
    11881213    while (dlgsub != dlgsub_head) { 
    11891214 
    1190         /* Match event type and Id */ 
    1191         if (pj_strcmp(&dlgsub->sub->event->id_param, &event_hdr->id_param)==0 && 
    1192             pj_stricmp(&dlgsub->sub->event->event_type, &event_hdr->event_type)==0) 
     1215        if (pj_stricmp(&dlgsub->sub->event->event_type,  
     1216                       &event_hdr->event_type)==0) 
    11931217        { 
    1194             break; 
    1195         } 
     1218            /* Event type matched.  
     1219             * Check if event ID matched too. 
     1220             */ 
     1221            if (pj_strcmp(&dlgsub->sub->event->id_param,  
     1222                          &event_hdr->id_param)==0) 
     1223            { 
     1224                 
     1225                break; 
     1226 
     1227            } 
     1228            /* 
     1229             * Otherwise if it is an UAC subscription, AND 
     1230             * PJSIP_EVSUB_NO_EVENT_ID flag is set, AND 
     1231             * the session's event id is NULL, AND 
     1232             * the incoming request is NOTIFY with event ID, then 
     1233             * we consider it as a match, and update the 
     1234             * session's event id. 
     1235             */ 
     1236            else if (dlgsub->sub->role == PJSIP_ROLE_UAC && 
     1237                     (dlgsub->sub->option & PJSIP_EVSUB_NO_EVENT_ID)!=0 && 
     1238                     dlgsub->sub->event->id_param.slen==0 && 
     1239                     !pjsip_method_cmp(&tsx->method, &pjsip_notify_method)) 
     1240            { 
     1241                /* Update session's event id. */ 
     1242                pj_strdup(dlgsub->sub->pool,  
     1243                          &dlgsub->sub->event->id_param, 
     1244                          &event_hdr->id_param); 
     1245 
     1246                break; 
     1247            } 
     1248        } 
     1249         
     1250 
     1251 
    11961252        dlgsub = dlgsub->next; 
    11971253    } 
     
    12011257        PJ_LOG(4,(THIS_FILE,  
    12021258                  "Subscription not found for %.*s, event=%.*s;id=%.*s", 
     1259                  (int)tsx->method.name.slen, 
     1260                  tsx->method.name.ptr, 
    12031261                  (int)event_hdr->event_type.slen, 
    12041262                  event_hdr->event_type.ptr, 
     
    17381796                set_state(sub, PJSIP_EVSUB_STATE_TERMINATED, NULL, NULL); 
    17391797            } 
    1740         }  
     1798 
     1799        } 
     1800        /* 
     1801         * Terminate event usage if we receive 481, 408, and 7 class 
     1802         * responses. 
     1803         */ 
     1804        if (sub->state != PJSIP_EVSUB_STATE_TERMINATED && 
     1805            (tsx->status_code==481 || tsx->status_code==408 || 
     1806             tsx->status_code/100 == 7)) 
     1807        { 
     1808            set_state(sub, PJSIP_EVSUB_STATE_TERMINATED, NULL, event); 
     1809        } 
    17411810 
    17421811    } else { 
Note: See TracChangeset for help on using the changeset viewer.