Module: kamailio
Branch: master
Commit: df3d1e5cb80b7a6ac6ce93b582352aaa8e6fd369
URL:
https://github.com/kamailio/kamailio/commit/df3d1e5cb80b7a6ac6ce93b582352aa…
Author: Xenofon Karamanos <xk(a)gilawa.com>
Committer: Henning Westerholt <hw(a)gilawa.com>
Date: 2024-02-01T19:41:22Z
file_out: use name instead of index for file_out function parameter
---
Modified: src/modules/file_out/doc/file_out_admin.xml
Modified: src/modules/file_out/file_out.c
---
Diff:
https://github.com/kamailio/kamailio/commit/df3d1e5cb80b7a6ac6ce93b582352aa…
Patch:
https://github.com/kamailio/kamailio/commit/df3d1e5cb80b7a6ac6ce93b582352aa…
---
diff --git a/src/modules/file_out/doc/file_out_admin.xml
b/src/modules/file_out/doc/file_out_admin.xml
index b59efdad79f..3054af61672 100644
--- a/src/modules/file_out/doc/file_out_admin.xml
+++ b/src/modules/file_out/doc/file_out_admin.xml
@@ -166,8 +166,8 @@ modparam("file_out", "base_filename",
"accounting")
modparam("file_out", "base_filename", "missed_calls")
request_route {
- file_out("0", "Writing to accounting.out file $rm from $fu");
- file_out("1", "Writing to missed_calls.out file $rm from $fu");
+ file_out("accounting", "Writing to accounting.out file $rm from
$fu");
+ file_out("missed_calls", "Writing to missed_calls.out file $rm from
$fu");
}
...
</programlisting>
diff --git a/src/modules/file_out/file_out.c b/src/modules/file_out/file_out.c
index 04cc041aa86..1b9bfba7bb0 100644
--- a/src/modules/file_out/file_out.c
+++ b/src/modules/file_out/file_out.c
@@ -51,6 +51,7 @@ static int fo_init_file(const int index);
static int fo_close_file(const int index);
static int fo_check_interval();
static int fo_fixup_int_pvar(void **param, int param_no);
+static int fo_fixup_str_index(void **param, int param_no);
static int fo_count_assigned_files();
static void fo_log_writer_process(int rank);
static int fo_add_filename(modparam_t type, void *val);
@@ -201,6 +202,37 @@ static void fo_log_writer_process(int rank)
}
}
+static int fo_fixup_str_index(void **param, int param_no)
+{
+
+ fparam_t *p;
+ int index = 0;
+
+ p = (fparam_t *)pkg_malloc(sizeof(fparam_t));
+ if(!p) {
+ PKG_MEM_ERROR;
+ return E_OUT_OF_MEM;
+ }
+ memset(p, 0, sizeof(fparam_t));
+ p->orig = *param;
+
+ /* Map string to index */
+ while(index < *fo_number_of_files) {
+ if(strcmp(fo_base_filename[index], (char *)*param) == 0) {
+ LM_DBG("Found index %d for %s\n", index, (char *)*param);
+ p->v.i = (int)index;
+ p->fixed = (void *)(long)index;
+ p->type = FPARAM_INT;
+ *param = (void *)p;
+ return 0;
+ }
+ index++;
+ }
+
+ LM_ERR("Couldn't find index for %s\n", (char *)*param);
+ pkg_free(p);
+ return -1;
+}
/*
* fixup function for two parameters
* 1st param: int
@@ -209,7 +241,7 @@ static void fo_log_writer_process(int rank)
static int fo_fixup_int_pvar(void **param, int param_no)
{
if(param_no == 1) {
- return fixup_igp_null(param, param_no);
+ return fo_fixup_str_index(param, param_no);
} else if(param_no == 2) {
return fixup_var_pve_str_12(param, param_no);
}