summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2006-06-06 17:04:30 +0000
committerBenny Prijono <bennylp@teluu.com>2006-06-06 17:04:30 +0000
commit40d75a0cb404fc0bafa20934e992befd0eab673b (patch)
tree0d0976d1cd51c2bbfe2906900bd5b390ad74b9f8
parentf5e5d9d039d9664e6f90fb6297e372d58371f7fa (diff)
More information in error reporting on parsing error
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@491 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r--pjsip/include/pjsip/sip_config.h2
-rw-r--r--pjsip/include/pjsip/sip_errno.h5
-rw-r--r--pjsip/src/pjsip/sip_endpoint.c43
-rw-r--r--pjsip/src/pjsip/sip_errno.c3
-rw-r--r--pjsip/src/pjsip/sip_msg.c8
-rw-r--r--pjsip/src/pjsip/sip_parser.c5
-rw-r--r--pjsip/src/pjsip/sip_transaction.c4
-rw-r--r--pjsip/src/pjsip/sip_transport.c36
-rw-r--r--pjsip/src/pjsip/sip_util.c3
9 files changed, 92 insertions, 17 deletions
diff --git a/pjsip/include/pjsip/sip_config.h b/pjsip/include/pjsip/sip_config.h
index 1ee128eb..593e539a 100644
--- a/pjsip/include/pjsip/sip_config.h
+++ b/pjsip/include/pjsip/sip_config.h
@@ -115,7 +115,7 @@
/* Message/URL related constants. */
#define PJSIP_MAX_CALL_ID_LEN PJ_GUID_STRING_LENGTH
#define PJSIP_MAX_TAG_LEN PJ_GUID_STRING_LENGTH
-#define PJSIP_MAX_BRANCH_LEN (PJSIP_RFC3261_BRANCH_LEN + PJ_GUID_STRING_LENGTH)
+#define PJSIP_MAX_BRANCH_LEN (PJSIP_RFC3261_BRANCH_LEN + PJ_GUID_STRING_LENGTH + 2)
#define PJSIP_MAX_HNAME_LEN 64
/* Dialog related constants. */
diff --git a/pjsip/include/pjsip/sip_errno.h b/pjsip/include/pjsip/sip_errno.h
index c4195a13..4fc9d4bd 100644
--- a/pjsip/include/pjsip/sip_errno.h
+++ b/pjsip/include/pjsip/sip_errno.h
@@ -371,6 +371,11 @@ PJ_BEGIN_DECL
* Session already terminated.
*/
#define PJSIP_ESESSIONTERMINATED (PJSIP_ERRNO_START_PJSIP+140) /* 171140 */
+/**
+ * @hideinitializer
+ * Invalid session state for the specified operation.
+ */
+#define PJSIP_ESESSIONSTATE (PJSIP_ERRNO_START_PJSIP+141) /* 171141 */
diff --git a/pjsip/src/pjsip/sip_endpoint.c b/pjsip/src/pjsip/sip_endpoint.c
index e04485dc..f27fb032 100644
--- a/pjsip/src/pjsip/sip_endpoint.c
+++ b/pjsip/src/pjsip/sip_endpoint.c
@@ -671,13 +671,42 @@ static void endpt_on_rx_msg( pjsip_endpoint *endpt,
pjsip_msg *msg = rdata->msg_info.msg;
if (status != PJ_SUCCESS) {
- PJSIP_ENDPT_LOG_ERROR((endpt, "transport", status,
- "Error processing packet from %s:%d, packet:--\n"
- "%s\n"
- "-- end of packet.",
- rdata->pkt_info.src_name,
- rdata->pkt_info.src_port,
- rdata->msg_info.msg_buf));
+ char info[30];
+ char errmsg[PJ_ERR_MSG_SIZE];
+
+ info[0] = '\0';
+
+ if (status == PJSIP_EMISSINGHDR) {
+ pj_str_t p;
+
+ p.ptr = info; p.slen = 0;
+
+ if (rdata->msg_info.cid == NULL || rdata->msg_info.cid->id.slen)
+ pj_strcpy2(&p, "Call-ID");
+ if (rdata->msg_info.from == NULL)
+ pj_strcpy2(&p, " From");
+ if (rdata->msg_info.to == NULL)
+ pj_strcpy2(&p, " To");
+ if (rdata->msg_info.via == NULL)
+ pj_strcpy2(&p, " Via");
+ if (rdata->msg_info.cseq == NULL)
+ pj_strcpy2(&p, " CSeq");
+
+ p.ptr[p.slen] = '\0';
+ }
+
+ pj_strerror(status, errmsg, sizeof(errmsg));
+
+ PJ_LOG(1, (THIS_FILE,
+ "Error processing packet from %s:%d: %s %s [code %d]:\n"
+ "%s\n"
+ "-- end of packet.",
+ rdata->pkt_info.src_name,
+ rdata->pkt_info.src_port,
+ errmsg,
+ info,
+ status,
+ rdata->msg_info.msg_buf));
return;
}
diff --git a/pjsip/src/pjsip/sip_errno.c b/pjsip/src/pjsip/sip_errno.c
index 5a07e7c9..c9b74acf 100644
--- a/pjsip/src/pjsip/sip_errno.c
+++ b/pjsip/src/pjsip/sip_errno.c
@@ -106,7 +106,8 @@ static const struct
{ PJSIP_ENOREFERSESSION, "Not associated with REFER subscription"},
/* Invite session. */
- { PJSIP_ESESSIONTERMINATED, "Session already terminated" },
+ { PJSIP_ESESSIONTERMINATED, "INVITE session already terminated" },
+ { PJSIP_ESESSIONSTATE, "Invalid INVITE session state" },
};
diff --git a/pjsip/src/pjsip/sip_msg.c b/pjsip/src/pjsip/sip_msg.c
index 75dfd7b5..25a5ae19 100644
--- a/pjsip/src/pjsip/sip_msg.c
+++ b/pjsip/src/pjsip/sip_msg.c
@@ -364,7 +364,7 @@ PJ_DEF(pj_ssize_t) pjsip_msg_print( const pjsip_msg *msg,
/* Process message body. */
if (msg->body) {
- enum { CLEN_SPACE = 12 };
+ enum { CLEN_SPACE = 5 };
char *clen_pos = NULL;
/* Automaticly adds Content-Type and Content-Length headers, only
@@ -393,7 +393,7 @@ PJ_DEF(pj_ssize_t) pjsip_msg_print( const pjsip_msg *msg,
pj_memcpy(p, clen_hdr.ptr, clen_hdr.slen);
p += clen_hdr.slen;
- /* Print blanks after "Content-Type:", this is where we'll put
+ /* Print blanks after "Content-Length:", this is where we'll put
* the content length value after we know the length of the
* body.
*/
@@ -419,8 +419,9 @@ PJ_DEF(pj_ssize_t) pjsip_msg_print( const pjsip_msg *msg,
* Content-Length header.
*/
if (clen_pos) {
- char tmp[CLEN_SPACE];
+ char tmp[16];
len = pj_utoa(len, tmp);
+ if (len > CLEN_SPACE) len = CLEN_SPACE;
pj_memcpy(clen_pos+CLEN_SPACE-len, tmp, len);
}
@@ -433,6 +434,7 @@ PJ_DEF(pj_ssize_t) pjsip_msg_print( const pjsip_msg *msg,
}
pj_memcpy(p, clen_hdr.ptr, clen_hdr.slen);
p += clen_hdr.slen;
+ *p++ = ' ';
*p++ = '0';
*p++ = '\r';
*p++ = '\n';
diff --git a/pjsip/src/pjsip/sip_parser.c b/pjsip/src/pjsip/sip_parser.c
index 9b820ae0..2272cd37 100644
--- a/pjsip/src/pjsip/sip_parser.c
+++ b/pjsip/src/pjsip/sip_parser.c
@@ -264,7 +264,7 @@ static pj_status_t init_parser()
/*
* Syntax error exception number.
*/
- status = pj_exception_id_alloc("PJSIP: syntax error",
+ status = pj_exception_id_alloc("PJSIP syntax error",
&PJSIP_SYN_ERR_EXCEPTION);
PJ_ASSERT_RETURN(status == PJ_SUCCESS, status);
@@ -909,7 +909,8 @@ parse_headers:
err_info = pj_pool_alloc(pool, sizeof(*err_info));
err_info->except_code = PJ_GET_EXCEPTION();
err_info->line = scanner->line;
- err_info->col = pj_scan_get_col(scanner);
+ /* Scanner's column is zero based, so add 1 */
+ err_info->col = pj_scan_get_col(scanner) + 1;
if (parsing_headers)
err_info->hname = hname;
else
diff --git a/pjsip/src/pjsip/sip_transaction.c b/pjsip/src/pjsip/sip_transaction.c
index b3c0609b..8fe2a23a 100644
--- a/pjsip/src/pjsip/sip_transaction.c
+++ b/pjsip/src/pjsip/sip_transaction.c
@@ -1125,8 +1125,8 @@ PJ_DEF(pj_status_t) pjsip_tsx_create_uac( pjsip_module *tsx_user,
via->branch_param.slen = PJSIP_MAX_BRANCH_LEN;
pj_memcpy(via->branch_param.ptr, PJSIP_RFC3261_BRANCH_ID,
PJSIP_RFC3261_BRANCH_LEN);
-
- tmp.ptr = via->branch_param.ptr + PJSIP_RFC3261_BRANCH_LEN;
+ tmp.ptr = via->branch_param.ptr + PJSIP_RFC3261_BRANCH_LEN + 2;
+ *(tmp.ptr-2) = 80; *(tmp.ptr-1) = 106;
pj_generate_unique_string( &tmp );
/* Save branch parameter. */
diff --git a/pjsip/src/pjsip/sip_transport.c b/pjsip/src/pjsip/sip_transport.c
index 6468d912..10d11007 100644
--- a/pjsip/src/pjsip/sip_transport.c
+++ b/pjsip/src/pjsip/sip_transport.c
@@ -23,6 +23,7 @@
#include <pjsip/sip_private.h>
#include <pjsip/sip_errno.h>
#include <pjsip/sip_module.h>
+#include <pj/except.h>
#include <pj/os.h>
#include <pj/log.h>
#include <pj/ioqueue.h>
@@ -878,6 +879,41 @@ PJ_DEF(pj_ssize_t) pjsip_tpmgr_receive_packet( pjsip_tpmgr *mgr,
goto finish_process_fragment;
}
+ /* Check for parsing syntax error */
+ if (!pj_list_empty(&rdata->msg_info.parse_err)) {
+ pjsip_parser_err_report *err;
+ char buf[128];
+ pj_str_t tmp;
+
+ /* Gather syntax error information */
+ tmp.ptr = buf; tmp.slen = 0;
+ err = rdata->msg_info.parse_err.next;
+ while (err != &rdata->msg_info.parse_err) {
+ int len;
+ len = pj_ansi_snprintf(tmp.ptr+tmp.slen, sizeof(buf)-tmp.slen,
+ ": %s exception when parsing %.*s "
+ "header on line %d col %d",
+ pj_exception_id_name(err->except_code),
+ (int)err->hname.slen, err->hname.ptr,
+ err->line, err->col);
+ if (len > 0 && len < (int) (sizeof(buf)-tmp.slen)) {
+ tmp.slen += len;
+ }
+ err = err->next;
+ }
+
+ PJ_LOG(1, (THIS_FILE,
+ "Error processing packet from %s:%d %.*s:\n"
+ "%s\n"
+ "-- end of packet.",
+ rdata->pkt_info.src_name,
+ rdata->pkt_info.src_port,
+ (int)tmp.slen, tmp.ptr,
+ rdata->msg_info.msg_buf));
+
+ goto finish_process_fragment;
+ }
+
/* Perform basic header checking. */
if (rdata->msg_info.cid == NULL ||
rdata->msg_info.cid->id.slen == 0 ||
diff --git a/pjsip/src/pjsip/sip_util.c b/pjsip/src/pjsip/sip_util.c
index d4f2dbac..66efd9e0 100644
--- a/pjsip/src/pjsip/sip_util.c
+++ b/pjsip/src/pjsip/sip_util.c
@@ -862,7 +862,8 @@ static void stateless_send_transport_cb( void *token,
via->branch_param.slen = PJSIP_MAX_BRANCH_LEN;
pj_memcpy(via->branch_param.ptr, PJSIP_RFC3261_BRANCH_ID,
PJSIP_RFC3261_BRANCH_LEN);
- tmp.ptr = via->branch_param.ptr + PJSIP_RFC3261_BRANCH_LEN;
+ tmp.ptr = via->branch_param.ptr + PJSIP_RFC3261_BRANCH_LEN + 2;
+ *(tmp.ptr-2) = 80; *(tmp.ptr-1) = 106;
pj_generate_unique_string(&tmp);
}