summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2010-11-10 12:13:46 +0000
committerBenny Prijono <bennylp@teluu.com>2010-11-10 12:13:46 +0000
commitb0b535bf4c71c8b9c54ca6186a2bcd3b5f790fb5 (patch)
tree656196469d1d60f2fd142ce900577763258c8818
parent324711515d7bbd4f5470c54e081bfc0091c8848a (diff)
Fixed #1156: New option to ignore bad NOTIFY presence message body (thanks Johan Lantz for the suggestion)
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@3363 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r--pjsip/include/pjsip/sip_config.h18
-rw-r--r--pjsip/src/pjsip-simple/presence.c54
2 files changed, 53 insertions, 19 deletions
diff --git a/pjsip/include/pjsip/sip_config.h b/pjsip/include/pjsip/sip_config.h
index 6fd371a4..73cce7f1 100644
--- a/pjsip/include/pjsip/sip_config.h
+++ b/pjsip/include/pjsip/sip_config.h
@@ -901,6 +901,24 @@ PJ_INLINE(pjsip_cfg_t*) pjsip_cfg(void)
/**
+ * Specify the status code value to respond to bad message body in NOTIFY
+ * request for presence. Scenarios that are considered bad include non-
+ * PIDF/XML and non-XPIDF/XML body, multipart message bodies without PIDF/XML
+ * nor XPIDF/XML part, and bad (parsing error) PIDF and X-PIDF bodies
+ * themselves.
+ *
+ * Default value is 488. Application may change this to 200 to ignore the
+ * unrecognised content (this is useful if the application wishes to handle
+ * the content itself). Only non-3xx final response code is allowed here.
+ *
+ * Default: 488 (Not Acceptable Here)
+ */
+#ifndef PJSIP_PRES_BAD_CONTENT_RESPONSE
+# define PJSIP_PRES_BAD_CONTENT_RESPONSE 488
+#endif
+
+
+/**
* Add "timestamp" information in generated PIDF document for both server
* subscription and presence publication.
*
diff --git a/pjsip/src/pjsip-simple/presence.c b/pjsip/src/pjsip-simple/presence.c
index b2f48262..59a6bc8b 100644
--- a/pjsip/src/pjsip-simple/presence.c
+++ b/pjsip/src/pjsip-simple/presence.c
@@ -35,6 +35,12 @@
#define THIS_FILE "presence.c"
#define PRES_DEFAULT_EXPIRES PJSIP_PRES_DEFAULT_EXPIRES
+#if PJSIP_PRES_BAD_CONTENT_RESPONSE < 200 || \
+ PJSIP_PRES_BAD_CONTENT_RESPONSE > 699 || \
+ PJSIP_PRES_BAD_CONTENT_RESPONSE/100 == 3
+# error Invalid PJSIP_PRES_BAD_CONTENT_RESPONSE value
+#endif
+
/*
* Presence module (mod-presence)
*/
@@ -759,25 +765,35 @@ static pj_status_t pres_process_rx_notify( pjsip_pres *pres,
if (status != PJ_SUCCESS) {
/* Unsupported or bad Content-Type */
- pjsip_accept_hdr *accept_hdr;
- pjsip_warning_hdr *warn_hdr;
-
- *p_st_code = PJSIP_SC_NOT_ACCEPTABLE_HERE;
-
- /* Add Accept header */
- accept_hdr = pjsip_accept_hdr_create(rdata->tp_info.pool);
- accept_hdr->values[accept_hdr->count++] = STR_APP_PIDF_XML;
- accept_hdr->values[accept_hdr->count++] = STR_APP_XPIDF_XML;
- pj_list_push_back(res_hdr, accept_hdr);
-
- /* Add Warning header */
- warn_hdr = pjsip_warning_hdr_create_from_status(
- rdata->tp_info.pool,
- pjsip_endpt_name(pres->dlg->endpt),
- status);
- pj_list_push_back(res_hdr, warn_hdr);
-
- return status;
+ if (PJSIP_PRES_BAD_CONTENT_RESPONSE >= 300) {
+ pjsip_accept_hdr *accept_hdr;
+ pjsip_warning_hdr *warn_hdr;
+
+ *p_st_code = PJSIP_PRES_BAD_CONTENT_RESPONSE;
+
+ /* Add Accept header */
+ accept_hdr = pjsip_accept_hdr_create(rdata->tp_info.pool);
+ accept_hdr->values[accept_hdr->count++] = STR_APP_PIDF_XML;
+ accept_hdr->values[accept_hdr->count++] = STR_APP_XPIDF_XML;
+ pj_list_push_back(res_hdr, accept_hdr);
+
+ /* Add Warning header */
+ warn_hdr = pjsip_warning_hdr_create_from_status(
+ rdata->tp_info.pool,
+ pjsip_endpt_name(pres->dlg->endpt),
+ status);
+ pj_list_push_back(res_hdr, warn_hdr);
+
+ return status;
+ } else {
+ pj_assert(PJSIP_PRES_BAD_CONTENT_RESPONSE/100 == 2);
+ PJ_PERROR(4,(THIS_FILE, status,
+ "Ignoring presence error due to "
+ "PJSIP_PRES_BAD_CONTENT_RESPONSE setting [%d]",
+ PJSIP_PRES_BAD_CONTENT_RESPONSE));
+ *p_st_code = PJSIP_PRES_BAD_CONTENT_RESPONSE;
+ status = PJ_SUCCESS;
+ }
}
/* If application calls pres_get_status(), redirect the call to