Changeset 3477 for pjproject


Ignore:
Timestamp:
Mar 23, 2011 6:08:25 AM (14 years ago)
Author:
bennylp
Message:

Re #1214 (apps): added registrar functionality in pjsua for easier testing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/2.0-dev/pjsip-apps/src/pjsua/pjsua_app.c

    r3472 r3477  
    45784578} 
    45794579 
     4580/* 
     4581 * A simple registrar, invoked by default_mod_on_rx_request() 
     4582 */ 
     4583static void simple_registrar(pjsip_rx_data *rdata) 
     4584{ 
     4585    pjsip_tx_data *tdata; 
     4586    const pjsip_expires_hdr *exp; 
     4587    const pjsip_hdr *h; 
     4588    unsigned cnt = 0; 
     4589    pjsip_generic_string_hdr *srv; 
     4590    pj_status_t status; 
     4591 
     4592    status = pjsip_endpt_create_response(pjsua_get_pjsip_endpt(), 
     4593                                 rdata, 200, NULL, &tdata); 
     4594    if (status != PJ_SUCCESS) 
     4595    return; 
     4596 
     4597    exp = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_EXPIRES, NULL); 
     4598 
     4599    h = rdata->msg_info.msg->hdr.next; 
     4600    while (h != &rdata->msg_info.msg->hdr) { 
     4601    if (h->type == PJSIP_H_CONTACT) { 
     4602    const pjsip_contact_hdr *c = (const pjsip_contact_hdr*)h; 
     4603    int e = c->expires; 
     4604 
     4605    if (e < 0) { 
     4606        if (exp) 
     4607            e = exp->ivalue; 
     4608        else 
     4609            e = 3600; 
     4610    } 
     4611 
     4612    if (e > 0) { 
     4613        pjsip_contact_hdr *nc = pjsip_hdr_clone(tdata->pool, h); 
     4614        nc->expires = e; 
     4615        pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)nc); 
     4616        ++cnt; 
     4617    } 
     4618    } 
     4619    h = h->next; 
     4620    } 
     4621 
     4622    srv = pjsip_generic_string_hdr_create(tdata->pool, NULL, NULL); 
     4623    srv->name = pj_str("Server"); 
     4624    srv->hvalue = pj_str("pjsua simple registrar"); 
     4625    pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)srv); 
     4626 
     4627    pjsip_endpt_send_response2(pjsua_get_pjsip_endpt(), 
     4628                       rdata, tdata, NULL, NULL); 
     4629} 
     4630 
     4631 
     4632 
    45804633/***************************************************************************** 
    45814634 * A simple module to handle otherwise unhandled request. We will register 
     
    45914644 
    45924645    /* Don't respond to ACK! */ 
    4593     if (pjsip_method_cmp(&rdata->msg_info.msg->line.req.method,  
     4646    if (pjsip_method_cmp(&rdata->msg_info.msg->line.req.method, 
    45944647                         &pjsip_ack_method) == 0) 
    45954648        return PJ_TRUE; 
     4649 
     4650    /* Simple registrar */ 
     4651    if (pjsip_method_cmp(&rdata->msg_info.msg->line.req.method, 
     4652                         &pjsip_register_method) == 0) 
     4653    { 
     4654        simple_registrar(rdata); 
     4655        return PJ_TRUE; 
     4656    } 
    45964657 
    45974658    /* Create basic response. */ 
Note: See TracChangeset for help on using the changeset viewer.