Ignore:
Timestamp:
Jan 18, 2006 11:34:15 PM (18 years ago)
Author:
bennylp
Message:

Complete tsx layer selftest, implemented authentication framework

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsip-ua/sip_ua.c

    r65 r123  
    4242 * Static prototypes. 
    4343 */ 
    44 static pj_status_t ua_init( pjsip_endpoint *endpt, 
    45                             struct pjsip_module *mod, pj_uint32_t id ); 
    46 static pj_status_t ua_start( struct pjsip_module *mod ); 
    47 static pj_status_t ua_deinit( struct pjsip_module *mod ); 
     44static pj_status_t ua_load(pjsip_endpoint *endpt); 
     45static pj_status_t ua_unload(void); 
    4846static void ua_tsx_handler( struct pjsip_module *mod, pjsip_event *evt ); 
    4947static pjsip_dlg *find_dialog( pjsip_user_agent *ua, 
     
    5452 
    5553/* 
    56  * Default UA instance. 
    57  */ 
    58 static pjsip_user_agent ua_instance; 
    59  
    60 /* 
    6154 * Module interface. 
    6255 */ 
    63 static struct pjsip_module mod_ua =  
    64 { 
    65     { "User-Agent", 10 },   /* Name.            */ 
    66     0,                      /* Flag             */ 
    67     128,                    /* Priority         */ 
    68     NULL,                   /* User agent instance, initialized by APP. */ 
    69     0,                      /* Number of methods supported (will be initialized later). */ 
    70     { 0 },                  /* Array of methods (will be initialized later) */ 
    71     &ua_init,               /* init_module()    */ 
    72     &ua_start,              /* start_module()   */ 
    73     &ua_deinit,             /* deinit_module()  */ 
    74     &ua_tsx_handler,        /* tsx_handler()    */ 
     56static struct user_agent 
     57{ 
     58    pjsip_module         mod; 
     59    pj_pool_t           *pool; 
     60    pjsip_endpoint      *endpt; 
     61    pj_mutex_t          *mutex; 
     62    pj_hash_table_t     *dlg_table; 
     63    pjsip_dialog         dlg_list; 
     64 
     65} mod_ua =  
     66{ 
     67  { 
     68    NULL, NULL,             /* prev, next.                      */ 
     69    { "mod-ua", 6 },        /* Name.                            */ 
     70    -1,                     /* Id                               */ 
     71    PJSIP_MOD_PRIORITY_UA_PROXY_LAYER,  /* Priority             */ 
     72    NULL,                   /* User data.                       */ 
     73    0,                      /* Number of methods supported.     */ 
     74    { 0 },                  /* Array of methods                 */ 
     75    &ua_load,               /* load()                           */ 
     76    NULL,                   /* start()                          */ 
     77    NULL,                   /* stop()                           */ 
     78    &ua_unload,             /* unload()                         */ 
     79    NULL,                   /* on_rx_request()                  */ 
     80    NULL,                   /* on_rx_response()                 */ 
     81    NULL,                   /* on_tx_request.                   */ 
     82    NULL,                   /* on_tx_response()                 */ 
     83    NULL,                   /* on_tsx_state()                   */ 
     84  } 
    7585}; 
    7686 
     
    7888 * Initialize user agent instance. 
    7989 */ 
    80 static pj_status_t ua_init( pjsip_endpoint *endpt, 
    81                             struct pjsip_module *mod, pj_uint32_t id ) 
    82 { 
    83     static pjsip_method m_invite, m_ack, m_cancel, m_bye; 
    84     pjsip_user_agent *ua = mod->mod_data; 
     90static pj_status_t ua_load( pjsip_endpoint *endpt ) 
     91{ 
    8592    extern int pjsip_dlg_lock_tls_id;   /* defined in sip_dialog.c */ 
    86  
    87     pjsip_method_set( &m_invite, PJSIP_INVITE_METHOD ); 
    88     pjsip_method_set( &m_ack, PJSIP_ACK_METHOD ); 
    89     pjsip_method_set( &m_cancel, PJSIP_CANCEL_METHOD ); 
    90     pjsip_method_set( &m_bye, PJSIP_BYE_METHOD ); 
    91  
    92     mod->method_cnt = 4; 
    93     mod->methods[0] = &m_invite; 
    94     mod->methods[1] = &m_ack; 
    95     mod->methods[2] = &m_cancel; 
    96     mod->methods[3] = &m_bye; 
     93    pj_status_t status; 
    9794 
    9895    /* Initialize the user agent. */ 
    99     ua->endpt = endpt; 
    100     ua->pool = pjsip_endpt_create_pool(endpt, "pua%p", PJSIP_POOL_LEN_UA,  
    101                                        PJSIP_POOL_INC_UA); 
    102     if (!ua->pool) { 
    103         return -1; 
    104     } 
    105     ua->mod_id = id; 
    106     ua->mutex = pj_mutex_create(ua->pool, " ua%p", 0); 
    107     if (!ua->mutex) { 
    108         return -1; 
    109     } 
    110     ua->dlg_table = pj_hash_create(ua->pool, PJSIP_MAX_DIALOG_COUNT); 
    111     if (ua->dlg_table == NULL) { 
    112         return -1; 
    113     } 
    114     pj_list_init(&ua->dlg_list); 
     96    mod_ua.endpt = endpt; 
     97    status = pjsip_endpt_create_pool( endpt, "pua%p", PJSIP_POOL_LEN_UA,  
     98                                      PJSIP_POOL_INC_UA, &mod_ua.pool); 
     99    if (status != PJ_SUCCESS) 
     100        return status; 
     101 
     102    status = pj_mutex_create_recursive(mod_ua.pool, " ua%p", &mod_ua.mutex); 
     103    if (status != PJ_SUCCESS) 
     104        return status; 
     105 
     106    mod_ua.dlg_table = pj_hash_create(mod_ua.pool, PJSIP_MAX_DIALOG_COUNT); 
     107    if (ua->dlg_table == NULL) 
     108        return PJ_ENOMEM; 
     109 
     110    pj_list_init(&mod_ua.dlg_list); 
    115111 
    116112    /* Initialize dialog lock. */ 
     
    121117    pj_thread_local_set(pjsip_dlg_lock_tls_id, NULL); 
    122118 
    123     return 0; 
    124 } 
    125  
    126 /* 
    127  * Start user agent instance. 
    128  */ 
    129 static pj_status_t ua_start( struct pjsip_module *mod ) 
    130 { 
    131     PJ_UNUSED_ARG(mod) 
    132     return 0; 
     119    return PJ_SUCCESS; 
    133120} 
    134121 
     
    136123 * Destroy user agent. 
    137124 */ 
    138 static pj_status_t ua_deinit( struct pjsip_module *mod ) 
    139 { 
    140     pjsip_user_agent *ua = mod->mod_data; 
    141  
    142     pj_mutex_unlock(ua->mutex); 
     125static pj_status_t ua_unload() 
     126{ 
     127    pj_mutex_unlock(mod_ua.mutex); 
    143128 
    144129    /* Release pool */ 
    145     if (ua->pool) { 
    146         pjsip_endpt_destroy_pool( ua->endpt, ua->pool ); 
    147     } 
    148     return 0; 
    149 } 
    150  
    151 /* 
    152  * Get the module interface for the UA module. 
    153  */ 
    154 PJ_DEF(pjsip_module*) pjsip_ua_get_module(void) 
    155 { 
    156     mod_ua.mod_data = &ua_instance; 
    157     return &mod_ua; 
    158 } 
    159  
    160 /* 
    161  * Register callback to receive dialog notifications. 
    162  */ 
    163 PJ_DEF(void) pjsip_ua_set_dialog_callback( pjsip_user_agent *ua,  
    164                                            pjsip_dlg_callback *cb ) 
    165 { 
    166     ua->dlg_cb = cb; 
     130    if (mod_ua.pool) { 
     131        pjsip_endpt_destroy_pool( mod_ua.endpt, mod_ua.pool ); 
     132    } 
     133    return PJ_SUCCESS; 
    167134} 
    168135 
Note: See TracChangeset for help on using the changeset viewer.