Ignore:
Timestamp:
Mar 23, 2009 1:14:26 PM (15 years ago)
Author:
bennylp
Message:

Ticket #748: backported changes from ticket #747

Location:
pjproject/branches/1.0
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/1.0

  • pjproject/branches/1.0/pjsip-apps/src/pjsua/pjsua_app.c

    r2408 r2538  
    40164016} 
    40174017 
     4018/***************************************************************************** 
     4019 * A simple module to handle otherwise unhandled request. We will register 
     4020 * this with the lowest priority. 
     4021 */ 
     4022 
     4023/* Notification on incoming request */ 
     4024static pj_bool_t default_mod_on_rx_request(pjsip_rx_data *rdata) 
     4025{ 
     4026    pjsip_tx_data *tdata; 
     4027    pjsip_status_code status_code; 
     4028    pj_status_t status; 
     4029 
     4030    /* Don't respond to ACK! */ 
     4031    if (pjsip_method_cmp(&rdata->msg_info.msg->line.req.method,  
     4032                         &pjsip_ack_method) == 0) 
     4033        return PJ_TRUE; 
     4034 
     4035    /* Create basic response. */ 
     4036    if (pjsip_method_cmp(&rdata->msg_info.msg->line.req.method,  
     4037                         &pjsip_notify_method) == 0) 
     4038    { 
     4039        /* Unsolicited NOTIFY's, send with Bad Request */ 
     4040        status_code = PJSIP_SC_BAD_REQUEST; 
     4041    } else { 
     4042        /* Probably unknown method */ 
     4043        status_code = PJSIP_SC_METHOD_NOT_ALLOWED; 
     4044    } 
     4045    status = pjsip_endpt_create_response(pjsua_get_pjsip_endpt(),  
     4046                                         rdata, status_code,  
     4047                                         NULL, &tdata); 
     4048    if (status != PJ_SUCCESS) { 
     4049        pjsua_perror(THIS_FILE, "Unable to create response", status); 
     4050        return PJ_TRUE; 
     4051    } 
     4052 
     4053    /* Add Allow if we're responding with 405 */ 
     4054    if (status_code == PJSIP_SC_METHOD_NOT_ALLOWED) { 
     4055        const pjsip_hdr *cap_hdr; 
     4056        cap_hdr = pjsip_endpt_get_capability(pjsua_get_pjsip_endpt(),  
     4057                                             PJSIP_H_ALLOW, NULL); 
     4058        if (cap_hdr) { 
     4059            pjsip_msg_add_hdr(tdata->msg, pjsip_hdr_clone(tdata->pool,  
     4060                                                           cap_hdr)); 
     4061        } 
     4062    } 
     4063 
     4064    /* Add User-Agent header */ 
     4065    { 
     4066        pj_str_t user_agent; 
     4067        char tmp[80]; 
     4068        const pj_str_t USER_AGENT = { "User-Agent", 10}; 
     4069        pjsip_hdr *h; 
     4070 
     4071        pj_ansi_snprintf(tmp, sizeof(tmp), "PJSUA v%s/%s",  
     4072                         pj_get_version(), PJ_OS_NAME); 
     4073        pj_strdup2_with_null(tdata->pool, &user_agent, tmp); 
     4074 
     4075        h = (pjsip_hdr*) pjsip_generic_string_hdr_create(tdata->pool, 
     4076                                                         &USER_AGENT, 
     4077                                                         &user_agent); 
     4078        pjsip_msg_add_hdr(tdata->msg, h); 
     4079    } 
     4080 
     4081    pjsip_endpt_send_response2(pjsua_get_pjsip_endpt(), rdata, tdata,  
     4082                               NULL, NULL); 
     4083 
     4084    return PJ_TRUE; 
     4085} 
     4086 
     4087 
     4088/* The module instance. */ 
     4089static pjsip_module mod_default_handler =  
     4090{ 
     4091    NULL, NULL,                         /* prev, next.          */ 
     4092    { "mod-default-handler", 19 },      /* Name.                */ 
     4093    -1,                                 /* Id                   */ 
     4094    PJSIP_MOD_PRIORITY_APPLICATION+99,  /* Priority             */ 
     4095    NULL,                               /* load()               */ 
     4096    NULL,                               /* start()              */ 
     4097    NULL,                               /* stop()               */ 
     4098    NULL,                               /* unload()             */ 
     4099    &default_mod_on_rx_request,         /* on_rx_request()      */ 
     4100    NULL,                               /* on_rx_response()     */ 
     4101    NULL,                               /* on_tx_request.       */ 
     4102    NULL,                               /* on_tx_response()     */ 
     4103    NULL,                               /* on_tsx_state()       */ 
     4104 
     4105}; 
     4106 
     4107 
     4108 
    40184109 
    40194110/***************************************************************************** 
     
    40664157        return status; 
    40674158 
     4159    /* Initialize our module to handle otherwise unhandled request */ 
     4160    status = pjsip_endpt_register_module(pjsua_get_pjsip_endpt(), 
     4161                                         &mod_default_handler); 
     4162    if (status != PJ_SUCCESS) 
     4163        return status; 
     4164 
    40684165#ifdef STEREO_DEMO 
    40694166    stereo_demo(); 
Note: See TracChangeset for help on using the changeset viewer.