Browse Source

pv: added new PV: $bs

- return body size computed from structure, not from Content Lenght
- $cl stays shortcut to $hdr(Content-Lenght) for backward compatibility
Daniel-Constantin Mierla 16 years ago
parent
commit
b70650026f
3 changed files with 23 additions and 0 deletions
  1. 3 0
      modules_k/pv/pv.c
  2. 17 0
      modules_k/pv/pv_core.c
  3. 3 0
      modules_k/pv/pv_core.h

+ 3 - 0
modules_k/pv/pv.c

@@ -104,6 +104,9 @@ static pv_export_t mod_pvs[] = {
 	{{"bR", (sizeof("bR")-1)}, /* */
 	{{"bR", (sizeof("bR")-1)}, /* */
 		PVT_CONTEXT, pv_get_branches, 0,
 		PVT_CONTEXT, pv_get_branches, 0,
 		0, 0, 0, 0},
 		0, 0, 0, 0},
+	{{"bs", (sizeof("bs")-1)}, /* */
+		PVT_OTHER, pv_get_body_size, 0,
+		0, 0, 0, 0},
 	{{"ci", (sizeof("ci")-1)}, /* */
 	{{"ci", (sizeof("ci")-1)}, /* */
 		PVT_OTHER, pv_get_callid, 0,
 		PVT_OTHER, pv_get_callid, 0,
 		0, 0, 0, 0},
 		0, 0, 0, 0},

+ 17 - 0
modules_k/pv/pv_core.c

@@ -896,6 +896,7 @@ int pv_get_content_type(struct sip_msg *msg, pv_param_t *param,
 	return pv_get_strval(msg, param, res, &msg->content_type->body);
 	return pv_get_strval(msg, param, res, &msg->content_type->body);
 }
 }
 
 
+
 int pv_get_content_length(struct sip_msg *msg, pv_param_t *param,
 int pv_get_content_length(struct sip_msg *msg, pv_param_t *param,
 		pv_value_t *res)
 		pv_value_t *res)
 {
 {
@@ -939,6 +940,22 @@ int pv_get_msg_body(struct sip_msg *msg, pv_param_t *param,
 }
 }
 
 
 
 
+int pv_get_body_size(struct sip_msg *msg, pv_param_t *param,
+		pv_value_t *res)
+{
+	str s;
+    if(msg==NULL)
+		return -1;
+    
+	s.s = get_body( msg );
+
+	s.len = 0;
+	if (s.s != NULL)
+		s.len = msg->buf + msg->len - s.s;
+	return pv_get_sintval(msg, param, res, s.len);
+}
+
+
 int pv_get_authattr(struct sip_msg *msg, pv_param_t *param,
 int pv_get_authattr(struct sip_msg *msg, pv_param_t *param,
 		pv_value_t *res)
 		pv_value_t *res)
 {
 {

+ 3 - 0
modules_k/pv/pv_core.h

@@ -165,6 +165,9 @@ int pv_get_content_length(struct sip_msg *msg, pv_param_t *param,
 int pv_get_msg_body(struct sip_msg *msg, pv_param_t *param,
 int pv_get_msg_body(struct sip_msg *msg, pv_param_t *param,
 		pv_value_t *res);
 		pv_value_t *res);
 
 
+int pv_get_body_size(struct sip_msg *msg, pv_param_t *param,
+		pv_value_t *res);
+
 int pv_get_authattr(struct sip_msg *msg, pv_param_t *param,
 int pv_get_authattr(struct sip_msg *msg, pv_param_t *param,
 		pv_value_t *res);
 		pv_value_t *res);