Ignore:
Timestamp:
Feb 7, 2006 6:48:01 PM (18 years ago)
Author:
bennylp
Message:

Tested initial implementation: basic UAC, client registration, authentication, etc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsip/sip_util_statefull.c

    r107 r141  
    2222#include <pjsip/sip_transaction.h> 
    2323#include <pjsip/sip_event.h> 
     24#include <pjsip/sip_errno.h> 
    2425#include <pj/pool.h> 
     26#include <pj/assert.h> 
    2527 
    26 struct aux_tsx_data 
     28struct tsx_data 
    2729{ 
    2830    void *token; 
    29     void (*cb)(void*,pjsip_event*); 
     31    void (*cb)(void*, pjsip_event*); 
    3032}; 
    3133 
    32 static void aux_tsx_handler( pjsip_transaction *tsx, pjsip_event *event ); 
     34static void mod_util_on_tsx_state(pjsip_transaction*, pjsip_event*); 
    3335 
    34 pjsip_module aux_tsx_module =  
     36/* This module will be registered in pjsip_endpt.c */ 
     37 
     38pjsip_module mod_stateful_util =  
    3539{ 
    36     NULL, NULL,                         /* prev and next        */ 
    37     { "Aux-Tsx", 7},                    /* Name.                */ 
    38     -1,                                 /* Id           */ 
    39     PJSIP_MOD_PRIORITY_APPLICATION-1,   /* Priority             */ 
    40     NULL,                               /* User data.   */ 
    41     0,                                  /* Number of methods supported (=0). */ 
    42     { 0 },                              /* Array of methods (none) */ 
    43     NULL,                               /* load()               */ 
    44     NULL,                               /* start()              */ 
    45     NULL,                               /* stop()               */ 
    46     NULL,                               /* unload()             */ 
    47     NULL,                               /* on_rx_request()      */ 
    48     NULL,                               /* on_rx_response()     */ 
    49     &aux_tsx_handler,                   /* tsx_handler()        */ 
     40    NULL, NULL,                     /* prev, next.                      */ 
     41    { "mod-stateful-util", 17 },    /* Name.                            */ 
     42    -1,                             /* Id                               */ 
     43    PJSIP_MOD_PRIORITY_APPLICATION, /* Priority                         */ 
     44    NULL,                           /* User data.                       */ 
     45    NULL,                           /* load()                           */ 
     46    NULL,                           /* start()                          */ 
     47    NULL,                           /* stop()                           */ 
     48    NULL,                           /* unload()                         */ 
     49    NULL,                           /* on_rx_request()                  */ 
     50    NULL,                           /* on_rx_response()                 */ 
     51    NULL,                           /* on_tx_request.                   */ 
     52    NULL,                           /* on_tx_response()                 */ 
     53    &mod_util_on_tsx_state,         /* on_tsx_state()                   */ 
    5054}; 
    5155 
    52 static void aux_tsx_handler( pjsip_transaction *tsx, pjsip_event *event ) 
     56static void mod_util_on_tsx_state(pjsip_transaction *tsx, pjsip_event *event) 
    5357{ 
    54     struct aux_tsx_data *tsx_data; 
     58    struct tsx_data *tsx_data; 
    5559 
    5660    if (event->type != PJSIP_EVENT_TSX_STATE) 
    5761        return; 
    58     if (tsx->module_data[aux_tsx_module.id] == NULL) 
     62 
     63    tsx_data = tsx->mod_data[mod_stateful_util.id]; 
     64    if (tsx_data == NULL) 
    5965        return; 
     66 
    6067    if (tsx->status_code < 200) 
    6168        return; 
     
    6471     * by clearing the transaction's module_data. 
    6572     */ 
    66     tsx_data = tsx->module_data[aux_tsx_module.id]; 
    67     tsx->module_data[aux_tsx_module.id] = NULL; 
     73    tsx->mod_data[mod_stateful_util.id] = NULL; 
    6874 
    6975    if (tsx_data->cb) { 
     
    8086{ 
    8187    pjsip_transaction *tsx; 
    82     struct aux_tsx_data *tsx_data; 
     88    struct tsx_data *tsx_data; 
    8389    pj_status_t status; 
    8490 
    85     status = pjsip_endpt_create_tsx(endpt, &tsx); 
    86     if (!tsx) { 
     91    PJ_ASSERT_RETURN(endpt && tdata && (timeout==-1 || timeout>0), PJ_EINVAL); 
     92 
     93    status = pjsip_tsx_create_uac(&mod_stateful_util, tdata, &tsx); 
     94    if (status != PJ_SUCCESS) { 
    8795        pjsip_tx_data_dec_ref(tdata); 
    88         return -1; 
     96        return status; 
    8997    } 
    9098 
    91     tsx_data = pj_pool_alloc(tsx->pool, sizeof(struct aux_tsx_data)); 
     99    tsx_data = pj_pool_alloc(tsx->pool, sizeof(struct tsx_data)); 
    92100    tsx_data->token = token; 
    93101    tsx_data->cb = cb; 
    94     tsx->module_data[aux_tsx_module.id] = tsx_data; 
     102    tsx->mod_data[mod_stateful_util.id] = tsx_data; 
    95103 
    96     if (pjsip_tsx_init_uac(tsx, tdata) != 0) { 
    97         pjsip_endpt_destroy_tsx(endpt, tsx); 
    98         pjsip_tx_data_dec_ref(tdata); 
    99         return -1; 
    100     } 
     104    PJ_TODO(IMPLEMENT_TIMEOUT_FOR_SEND_REQUEST); 
    101105 
    102     pjsip_endpt_register_tsx(endpt, tsx); 
    103     pjsip_tx_data_invalidate_msg(tdata); 
    104     pjsip_tsx_on_tx_msg(tsx, tdata); 
    105     pjsip_tx_data_dec_ref(tdata); 
    106     return 0; 
     106    return pjsip_tsx_send_msg(tsx, NULL); 
    107107} 
    108108 
Note: See TracChangeset for help on using the changeset viewer.