Index: pjproject/trunk/pjsip/include/pjsip/sip_config.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip/sip_config.h	(revision 488)
+++ pjproject/trunk/pjsip/include/pjsip/sip_config.h	(revision 491)
@@ -116,5 +116,5 @@
 #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
 
Index: pjproject/trunk/pjsip/include/pjsip/sip_errno.h
===================================================================
--- pjproject/trunk/pjsip/include/pjsip/sip_errno.h	(revision 488)
+++ pjproject/trunk/pjsip/include/pjsip/sip_errno.h	(revision 491)
@@ -372,4 +372,9 @@
  */
 #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 */
 
 
Index: pjproject/trunk/pjsip/src/pjsip/sip_endpoint.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsip/sip_endpoint.c	(revision 488)
+++ pjproject/trunk/pjsip/src/pjsip/sip_endpoint.c	(revision 491)
@@ -672,11 +672,40 @@
 
     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;
     }
Index: pjproject/trunk/pjsip/src/pjsip/sip_errno.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsip/sip_errno.c	(revision 488)
+++ pjproject/trunk/pjsip/src/pjsip/sip_errno.c	(revision 491)
@@ -107,5 +107,6 @@
 
     /* Invite session. */
-    { PJSIP_ESESSIONTERMINATED,	"Session already terminated" },
+    { PJSIP_ESESSIONTERMINATED,	"INVITE session already terminated" },
+    { PJSIP_ESESSIONSTATE,      "Invalid INVITE session state" },
 };
 
Index: pjproject/trunk/pjsip/src/pjsip/sip_msg.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsip/sip_msg.c	(revision 488)
+++ pjproject/trunk/pjsip/src/pjsip/sip_msg.c	(revision 491)
@@ -365,5 +365,5 @@
     /* Process message body. */
     if (msg->body) {
-	enum { CLEN_SPACE = 12 };
+	enum { CLEN_SPACE = 5 };
 	char *clen_pos = NULL;
 
@@ -394,5 +394,5 @@
 	    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.
@@ -420,6 +420,7 @@
 	 */
 	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);
 	}
@@ -434,4 +435,5 @@
 	pj_memcpy(p, clen_hdr.ptr, clen_hdr.slen);
 	p += clen_hdr.slen;
+	*p++ = ' ';
 	*p++ = '0';
 	*p++ = '\r';
Index: pjproject/trunk/pjsip/src/pjsip/sip_parser.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsip/sip_parser.c	(revision 488)
+++ pjproject/trunk/pjsip/src/pjsip/sip_parser.c	(revision 491)
@@ -265,5 +265,5 @@
      * 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);
@@ -910,5 +910,6 @@
 	    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;
Index: pjproject/trunk/pjsip/src/pjsip/sip_transaction.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsip/sip_transaction.c	(revision 488)
+++ pjproject/trunk/pjsip/src/pjsip/sip_transaction.c	(revision 491)
@@ -1126,6 +1126,6 @@
 	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 );
 
Index: pjproject/trunk/pjsip/src/pjsip/sip_transport.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsip/sip_transport.c	(revision 488)
+++ pjproject/trunk/pjsip/src/pjsip/sip_transport.c	(revision 491)
@@ -24,4 +24,5 @@
 #include <pjsip/sip_errno.h>
 #include <pjsip/sip_module.h>
+#include <pj/except.h>
 #include <pj/os.h>
 #include <pj/log.h>
@@ -879,4 +880,39 @@
 	}
 
+	/* 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 ||
Index: pjproject/trunk/pjsip/src/pjsip/sip_util.c
===================================================================
--- pjproject/trunk/pjsip/src/pjsip/sip_util.c	(revision 488)
+++ pjproject/trunk/pjsip/src/pjsip/sip_util.c	(revision 491)
@@ -863,5 +863,6 @@
 	    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);
 	}
