Changeset 2505 for pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c
- Timestamp:
- Mar 12, 2009 11:25:11 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c
r2441 r2505 4024 4024 } 4025 4025 4026 /***************************************************************************** 4027 * A simple module to handle otherwise unhandled request. We will register 4028 * this with the lowest priority. 4029 */ 4030 4031 /* Notification on incoming request */ 4032 static pj_bool_t default_mod_on_rx_request(pjsip_rx_data *rdata) 4033 { 4034 pjsip_tx_data *tdata; 4035 pjsip_status_code status_code; 4036 pj_status_t status; 4037 4038 /* Don't respond to ACK! */ 4039 if (pjsip_method_cmp(&rdata->msg_info.msg->line.req.method, 4040 &pjsip_ack_method) == 0) 4041 return PJ_TRUE; 4042 4043 /* Create basic response. */ 4044 if (pjsip_method_cmp(&rdata->msg_info.msg->line.req.method, 4045 &pjsip_notify_method) == 0) 4046 { 4047 /* Unsolicited NOTIFY's, send with Bad Request */ 4048 status_code = PJSIP_SC_BAD_REQUEST; 4049 } else { 4050 /* Probably unknown method */ 4051 status_code = PJSIP_SC_METHOD_NOT_ALLOWED; 4052 } 4053 status = pjsip_endpt_create_response(pjsua_get_pjsip_endpt(), 4054 rdata, status_code, 4055 NULL, &tdata); 4056 if (status != PJ_SUCCESS) { 4057 pjsua_perror(THIS_FILE, "Unable to create response", status); 4058 return PJ_TRUE; 4059 } 4060 4061 /* Add Allow if we're responding with 405 */ 4062 if (status_code == PJSIP_SC_METHOD_NOT_ALLOWED) { 4063 const pjsip_hdr *cap_hdr; 4064 cap_hdr = pjsip_endpt_get_capability(pjsua_get_pjsip_endpt(), 4065 PJSIP_H_ALLOW, NULL); 4066 if (cap_hdr) { 4067 pjsip_msg_add_hdr(tdata->msg, pjsip_hdr_clone(tdata->pool, 4068 cap_hdr)); 4069 } 4070 } 4071 4072 /* Add User-Agent header */ 4073 { 4074 pj_str_t user_agent; 4075 char tmp[80]; 4076 const pj_str_t USER_AGENT = { "User-Agent", 10}; 4077 pjsip_hdr *h; 4078 4079 pj_ansi_snprintf(tmp, sizeof(tmp), "PJSUA v%s/%s", 4080 pj_get_version(), PJ_OS_NAME); 4081 pj_strdup2_with_null(tdata->pool, &user_agent, tmp); 4082 4083 h = (pjsip_hdr*) pjsip_generic_string_hdr_create(tdata->pool, 4084 &USER_AGENT, 4085 &user_agent); 4086 pjsip_msg_add_hdr(tdata->msg, h); 4087 } 4088 4089 pjsip_endpt_send_response2(pjsua_get_pjsip_endpt(), rdata, tdata, 4090 NULL, NULL); 4091 4092 return PJ_TRUE; 4093 } 4094 4095 4096 /* The module instance. */ 4097 static pjsip_module mod_default_handler = 4098 { 4099 NULL, NULL, /* prev, next. */ 4100 { "mod-default-handler", 19 }, /* Name. */ 4101 -1, /* Id */ 4102 PJSIP_MOD_PRIORITY_APPLICATION+99, /* Priority */ 4103 NULL, /* load() */ 4104 NULL, /* start() */ 4105 NULL, /* stop() */ 4106 NULL, /* unload() */ 4107 &default_mod_on_rx_request, /* on_rx_request() */ 4108 NULL, /* on_rx_response() */ 4109 NULL, /* on_tx_request. */ 4110 NULL, /* on_tx_response() */ 4111 NULL, /* on_tsx_state() */ 4112 4113 }; 4114 4115 4116 4026 4117 4027 4118 /***************************************************************************** … … 4074 4165 return status; 4075 4166 4167 /* Initialize our module to handle otherwise unhandled request */ 4168 status = pjsip_endpt_register_module(pjsua_get_pjsip_endpt(), 4169 &mod_default_handler); 4170 if (status != PJ_SUCCESS) 4171 return status; 4172 4076 4173 #ifdef STEREO_DEMO 4077 4174 stereo_demo();
Note: See TracChangeset
for help on using the changeset viewer.