Browse code

core: functions to get a fixup corresp. fixup_free function

Added functions that given a known fixup, returns its
corresponding fixup_free function.
The known fixups are the fparam style fixups and the kamailio
style fixups (from mod_fix.h).

Andrei Pelinescu-Onciul authored on 05/08/2010 21:09:26
Showing 4 changed files
... ...
@@ -497,3 +497,33 @@ FIXUP_F_SPVE_T(spve_spve, 1, 2, 2, 0)
497 497
 FIXUP_F_SPVE_T(spve_uint, 1, 2, 1, FPARAM_INT)
498 498
 FIXUP_F_SPVE_T(spve_str, 1, 2, 1, FPARAM_STR)
499 499
 FIXUP_F_SPVE_T(spve_null, 1, 1, 1, 0)
500
+
501
+/** get the corresp. fixup_free* function.
502
+ * @param f -fixup function pointer.
503
+ * @return  - pointer to free_fixup function if known, 0 otherwise.
504
+ */
505
+free_fixup_function mod_fix_get_fixup_free(fixup_function f)
506
+{
507
+	if (f == fixup_str_null) return fixup_free_str_null;
508
+	if (f == fixup_str_str) return fixup_free_str_str;
509
+	/* no free fixup for fixup_uint_* (they overwrite the pointer
510
+	   value with a number and the original value cannot be recovered) */
511
+	if (f == fixup_uint_null) return 0;
512
+	if (f == fixup_uint_uint) return 0;
513
+	if (f == fixup_regexp_null) return fixup_free_regexp_null;
514
+	if (f == fixup_pvar_null) return fixup_free_pvar_null;
515
+	if (f == fixup_pvar_pvar) return fixup_free_pvar_pvar;
516
+	if (f == fixup_pvar_str) return fixup_free_pvar_str;
517
+	if (f == fixup_pvar_str_str) return fixup_free_pvar_str_str;
518
+	if (f == fixup_igp_igp) return fixup_free_igp_igp;
519
+	if (f == fixup_igp_null) return fixup_free_igp_null;
520
+	if (f == fixup_igp_pvar) return fixup_free_igp_pvar;
521
+	if (f == fixup_igp_pvar_pvar) return fixup_free_igp_pvar_pvar;
522
+	if (f == fixup_spve_spve) return fixup_free_spve_spve;
523
+	if (f == fixup_spve_null) return fixup_free_spve_null;
524
+	/* no free fixup, because of the uint part (the uint cannot be freed,
525
+	   see above fixup_uint_null) */
526
+	if (f == fixup_spve_uint) return 0;
527
+	if (f == fixup_spve_str) return fixup_free_spve_str;
528
+	return 0;
529
+}
... ...
@@ -125,4 +125,8 @@ int fixup_spve_uint(void** param, int param_no);
125 125
 int fixup_spve_str(void** param, int param_no);
126 126
 int fixup_free_spve_str(void** param, int param_no);
127 127
 
128
+
129
+/** get the corresp. free fixup function.*/
130
+free_fixup_function mod_fix_get_fixup_free(fixup_function f);
131
+
128 132
 #endif
... ...
@@ -49,6 +49,7 @@
49 49
  */
50 50
 
51 51
 #include "sr_module.h"
52
+#include "mod_fix.h"
52 53
 #include "dprint.h"
53 54
 #include "error.h"
54 55
 #include "mem/mem.h"
... ...
@@ -1634,7 +1635,7 @@ int fixup_free_fparam_2(void** param, int param_no)
1634 1634
 
1635 1635
 
1636 1636
 /** returns true if a fixup is a fparam_t* one.
1637
- * Used to automatically detect fparam fixups that can be used with non
1637
+ * Used to automatically detect "pure" fparam fixups that can be used with non
1638 1638
  * contant RVEs.
1639 1639
  * @param f - function pointer
1640 1640
  * @return 1 for fparam fixups, 0 for others.
... ...
@@ -1652,7 +1653,54 @@ int is_fparam_rve_fixup(fixup_function f)
1652 1652
 		f == fixup_int_2 ||
1653 1653
 		f == fixup_str_12 ||
1654 1654
 		f == fixup_str_1 ||
1655
-		f == fixup_str_2)
1655
+		f == fixup_str_2 ||
1656
+		f == fixup_regex_12 ||
1657
+		f == fixup_regex_1 ||
1658
+		f == fixup_regex_2
1659
+		)
1656 1660
 		return 1;
1657 1661
 	return 0;
1658 1662
 }
1663
+
1664
+
1665
+
1666
+/** returns the corresponding fixup_free* for various known fixup types.
1667
+ * Used to automatically fill in free_fixup* functions.
1668
+ * @param f - fixup function pointer
1669
+ * @return - free fixup function pointer on success, 0 on failure (unknown
1670
+ *           fixup or no free fixup function).
1671
+ */
1672
+free_fixup_function get_fixup_free(fixup_function f)
1673
+{
1674
+	free_fixup_function ret;
1675
+	/* "pure" fparam, all parameters */
1676
+	if (f == fixup_var_str_12 ||
1677
+		f == fixup_var_int_12 ||
1678
+		f == fixup_int_12 ||
1679
+		f == fixup_str_12 ||
1680
+		f == fixup_regex_12)
1681
+		return fixup_free_fparam_all;
1682
+	
1683
+	/* "pure" fparam, 1st parameter */
1684
+	if (f == fixup_var_str_1 ||
1685
+		f == fixup_var_int_1 ||
1686
+		f == fixup_int_1 ||
1687
+		f == fixup_str_1 ||
1688
+		f == fixup_regex_1)
1689
+		return fixup_free_fparam_1;
1690
+	
1691
+	/* "pure" fparam, 2nd parameters */
1692
+	if (f == fixup_var_str_2 ||
1693
+		f == fixup_var_int_2 ||
1694
+		f == fixup_int_2 ||
1695
+		f == fixup_str_2 ||
1696
+		f == fixup_regex_2)
1697
+		return fixup_free_fparam_2;
1698
+	
1699
+	/* mod_fix.h kamailio style fixups */
1700
+	if ((ret = mod_fix_get_fixup_free(f)) != 0)
1701
+		return ret;
1702
+	
1703
+	/* unknown */
1704
+	return 0;
1705
+}
... ...
@@ -600,4 +600,7 @@ void fparam_free_restore(void** param);
600 600
 int fixup_free_fparam_all(void** param, int param_no);
601 601
 int fixup_free_fparam_1(void** param, int param_no);
602 602
 int fixup_free_fparam_2(void** param, int param_no);
603
+
604
+free_fixup_function get_fixup_free(fixup_function f);
605
+
603 606
 #endif /* sr_module_h */