[Asterisk-code-review] res pjsip: better logging failed request (asterisk[13])
Alexei Gradinari
asteriskteam at digium.com
Thu Apr 7 13:53:36 CDT 2016
Alexei Gradinari has uploaded a new change for review.
https://gerrit.asterisk.org/2550
Change subject: res_pjsip: better logging failed request
......................................................................
res_pjsip: better logging failed request
Add custom message instead of "No matching endpoint found".
Add method to logging.
Do not log OPTIONS/NOTIFY requests which can be used for ping.
Change-Id: I7ac95e9b0a8943b1f2cf899d65972f542daaa1a9
---
M res/res_pjsip/pjsip_distributor.c
1 file changed, 20 insertions(+), 7 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/50/2550/1
diff --git a/res/res_pjsip/pjsip_distributor.c b/res/res_pjsip/pjsip_distributor.c
index 3e33367..f9a2856 100644
--- a/res/res_pjsip/pjsip_distributor.c
+++ b/res/res_pjsip/pjsip_distributor.c
@@ -22,6 +22,8 @@
#include "asterisk/res_pjsip.h"
#include "asterisk/acl.h"
+/* Needed for SUBSCRIBE, NOTIFY, and PUBLISH method definitions */
+#include <pjsip_simple.h>
#include "include/res_pjsip_private.h"
#include "asterisk/taskprocessor.h"
#include "asterisk/threadpool.h"
@@ -360,14 +362,16 @@
return artificial_endpoint;
}
-static void log_unidentified_request(pjsip_rx_data *rdata)
+static void log_failed_request(pjsip_rx_data *rdata, char *msg)
{
char from_buf[PJSIP_MAX_URL_SIZE];
char callid_buf[PJSIP_MAX_URL_SIZE];
+ char method_buf[PJSIP_MAX_URL_SIZE];
pjsip_uri_print(PJSIP_URI_IN_FROMTO_HDR, rdata->msg_info.from->uri, from_buf, PJSIP_MAX_URL_SIZE);
ast_copy_pj_str(callid_buf, &rdata->msg_info.cid->id, PJSIP_MAX_URL_SIZE);
- ast_log(LOG_NOTICE, "Request from '%s' failed for '%s:%d' (callid: %s) - No matching endpoint found\n",
- from_buf, rdata->pkt_info.src_name, rdata->pkt_info.src_port, callid_buf);
+ ast_copy_pj_str(method_buf, &rdata->msg_info.msg->line.req.method.name, PJSIP_MAX_URL_SIZE);
+ ast_log(LOG_NOTICE, "Request '%s' from '%s' failed for '%s:%d' (callid: %s) - %s\n",
+ method_buf, from_buf, rdata->pkt_info.src_name, rdata->pkt_info.src_port, callid_buf, msg);
}
static pj_bool_t endpoint_lookup(pjsip_rx_data *rdata)
@@ -398,8 +402,11 @@
ast_copy_pj_str(name, &sip_from->user, sizeof(name));
}
- log_unidentified_request(rdata);
- ast_sip_report_invalid_endpoint(name, rdata);
+ if (pjsip_method_cmp(&rdata->msg_info.msg->line.req.method, &pjsip_options_method) &&
+ pjsip_method_cmp(&rdata->msg_info.msg->line.req.method, &pjsip_notify_method)) {
+ log_failed_request(rdata, "No matching endpoint found");
+ ast_sip_report_invalid_endpoint(name, rdata);
+ }
}
rdata->endpt_info.mod_data[endpoint_mod.id] = endpoint;
return PJ_FALSE;
@@ -508,11 +515,17 @@
pjsip_tx_data_dec_ref(tdata);
return PJ_FALSE;
case AST_SIP_AUTHENTICATION_FAILED:
- ast_sip_report_auth_failed_challenge_response(endpoint, rdata);
+ if (endpoint!=artificial_endpoint) {
+ log_failed_request(rdata, "Failed to authenticate");
+ ast_sip_report_auth_failed_challenge_response(endpoint, rdata);
+ }
pjsip_endpt_send_response2(ast_sip_get_pjsip_endpoint(), rdata, tdata, NULL, NULL);
return PJ_TRUE;
case AST_SIP_AUTHENTICATION_ERROR:
- ast_sip_report_auth_failed_challenge_response(endpoint, rdata);
+ if (endpoint!=artificial_endpoint) {
+ log_failed_request(rdata, "Error to authenticate");
+ ast_sip_report_auth_failed_challenge_response(endpoint, rdata);
+ }
pjsip_tx_data_dec_ref(tdata);
pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 500, NULL, NULL, NULL);
return PJ_TRUE;
--
To view, visit https://gerrit.asterisk.org/2550
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7ac95e9b0a8943b1f2cf899d65972f542daaa1a9
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Alexei Gradinari <alex2grad at gmail.com>
More information about the asterisk-code-review
mailing list