Module: kamailio
Branch: master
Commit: afb1c8eff3e9ea53baf7efadbe3aae7be9422e47
URL: 
https://github.com/kamailio/kamailio/commit/afb1c8eff3e9ea53baf7efadbe3aae7be9422e47

Author: fprdkhti <f.pk...@gmail.com>
Committer: Victor Seva <linuxman...@torreviejawireless.org>
Date: 2025-07-31T10:15:38+02:00

pv_headers: Add remove all header function

---

Modified: src/modules/pv_headers/doc/functions.xml
Modified: src/modules/pv_headers/pv_headers.c
Modified: src/modules/pv_headers/pvh_func.c
Modified: src/modules/pv_headers/pvh_func.h

---

Diff:  
https://github.com/kamailio/kamailio/commit/afb1c8eff3e9ea53baf7efadbe3aae7be9422e47.diff
Patch: 
https://github.com/kamailio/kamailio/commit/afb1c8eff3e9ea53baf7efadbe3aae7be9422e47.patch

---

diff --git a/src/modules/pv_headers/doc/functions.xml 
b/src/modules/pv_headers/doc/functions.xml
index 317da53b8c5..d4f14482ce0 100644
--- a/src/modules/pv_headers/doc/functions.xml
+++ b/src/modules/pv_headers/doc/functions.xml
@@ -128,6 +128,18 @@
                pvh_collect_headers()</link> or with <quote>auto_msg</quote> 
parameter enabled.
                </para>
        </section>
+       <section id="pv_headers.f.pvh_remove_all_headers">
+               <title>
+               <function moreinfo="none">pvh_remove_all_headers()</function>
+               </title>
+               <para>
+               Removes all sip message headers. 
+               </para>
+               <para>
+               This function can be used from ANY_ROUTE but only after <link 
linked="pv_headers.f.pvh_collect_headers">
+               pvh_collect_headers()</link> or with <quote>auto_msg</quote> 
parameter enabled.
+               </para>
+       </section>
        <section id="pv_headers.f.pvh_header_param_exists">
                <title>
                        <function moreinfo="none">pvh_value_exists(hname, 
hparameter)</function>
diff --git a/src/modules/pv_headers/pv_headers.c 
b/src/modules/pv_headers/pv_headers.c
index 190bc7abc96..809b6b21794 100644
--- a/src/modules/pv_headers/pv_headers.c
+++ b/src/modules/pv_headers/pv_headers.c
@@ -211,6 +211,12 @@ static int w_pvh_remove_header(
        return pvh_remove_header(msg, &hname, indx);
 }
 
+static int w_pvh_remove_all_headers(struct sip_msg *msg, char *p1, char *p2)
+{
+       int indx = -1;
+       return pvh_remove_all_headers(msg, indx);
+}
+
 static int w_pvh_header_param_exists(struct sip_msg *msg, char *p1, char *p2)
 {
        str hname = STR_NULL;
@@ -311,6 +317,8 @@ static cmd_export_t mod_cmds[] = {
                        fixup_spve_null, fixup_free_spve_null, ANY_ROUTE},
        {"pvh_remove_header", (cmd_function)w_pvh_remove_header, 2,
                        fixup_spve_spve, fixup_free_spve_spve, ANY_ROUTE},
+       {"pvh_remove_all_headers", (cmd_function)w_pvh_remove_all_headers, 0,
+                       0, 0, ANY_ROUTE},
        {"pvh_header_param_exists", (cmd_function)w_pvh_header_param_exists, 2,
                        fixup_spve_spve, fixup_free_spve_spve, ANY_ROUTE},
        {"pvh_remove_header_param", (cmd_function)w_pvh_remove_header_param, 2,
diff --git a/src/modules/pv_headers/pvh_func.c 
b/src/modules/pv_headers/pvh_func.c
index 5cbeb143113..c0b5d28001a 100644
--- a/src/modules/pv_headers/pvh_func.c
+++ b/src/modules/pv_headers/pvh_func.c
@@ -374,6 +374,22 @@ int pvh_remove_header(struct sip_msg *msg, str *hname, int 
indx)
        return 1;
 }
 
+int pvh_remove_all_headers(struct sip_msg *msg, int indx)
+{
+       str name = STR_NULL;
+       struct hdr_field *hf = NULL;
+
+       for(hf = msg->headers; hf; hf = hf->next) {
+               name.len = hf->name.len;
+               name.s = hf->name.s;
+               if(pvh_remove_header(msg, &name, indx) < 0) {
+                       LM_ERR("could not remove %.*s header", name.len, 
name.s);
+                       return -1;
+               }
+       }
+       return 1;
+}
+
 int pvh_header_param_exists(struct sip_msg *msg, str *hname, str *hvalue)
 {
        sr_xavp_t *avi = NULL;
diff --git a/src/modules/pv_headers/pvh_func.h 
b/src/modules/pv_headers/pvh_func.h
index c68558a90fb..e2e88c899e7 100644
--- a/src/modules/pv_headers/pvh_func.h
+++ b/src/modules/pv_headers/pvh_func.h
@@ -40,6 +40,7 @@ int pvh_check_header(struct sip_msg *msg, str *hname);
 int pvh_append_header(struct sip_msg *msg, str *hname, str *hvalue);
 int pvh_modify_header(struct sip_msg *msg, str *hname, str *hvalue, int indx);
 int pvh_remove_header(struct sip_msg *msg, str *hname, int indx);
+int pvh_remove_all_headers(struct sip_msg *msg, int indx);
 int pvh_header_param_exists(struct sip_msg *msg, str *hname, str *hvalue);
 int pvh_remove_header_param_helper(str *orig, const str *toRemove, str *dst);
 

_______________________________________________
Kamailio - Development Mailing List -- sr-dev@lists.kamailio.org
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to