[sr-dev] git:master:3f3fb6ad: textopsx: added hf_iterator_append(iname, htext) function
Daniel-Constantin Mierla
miconda at gmail.com
Mon Jul 26 17:16:44 CEST 2021
Module: kamailio
Branch: master
Commit: 3f3fb6ad94805407b316eb0ec4883631ac1df604
URL: https://github.com/kamailio/kamailio/commit/3f3fb6ad94805407b316eb0ec4883631ac1df604
Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2021-07-26T17:02:01+02:00
textopsx: added hf_iterator_append(iname, htext) function
---
Modified: src/modules/textopsx/textopsx.c
---
Diff: https://github.com/kamailio/kamailio/commit/3f3fb6ad94805407b316eb0ec4883631ac1df604.diff
Patch: https://github.com/kamailio/kamailio/commit/3f3fb6ad94805407b316eb0ec4883631ac1df604.patch
---
diff --git a/src/modules/textopsx/textopsx.c b/src/modules/textopsx/textopsx.c
index ec3e1afb75..297ff1098e 100644
--- a/src/modules/textopsx/textopsx.c
+++ b/src/modules/textopsx/textopsx.c
@@ -77,6 +77,7 @@ static int w_hf_iterator_start(sip_msg_t *msg, char *piname, char *p2);
static int w_hf_iterator_next(sip_msg_t *msg, char *piname, char *p2);
static int w_hf_iterator_end(sip_msg_t *msg, char *piname, char *p2);
static int w_hf_iterator_rm(sip_msg_t *msg, char *piname, char *p2);
+static int w_hf_iterator_append(sip_msg_t *msg, char *piname, char *phtext);
static int bind_textopsx(textopsx_api_t *tob);
@@ -139,6 +140,8 @@ static cmd_export_t cmds[] = {
fixup_free_spve_null, ANY_ROUTE},
{"hf_iterator_rm", w_hf_iterator_rm, 1, fixup_spve_null,
fixup_free_spve_null, ANY_ROUTE},
+ {"hf_iterator_append", w_hf_iterator_append, 2, fixup_spve_spve,
+ fixup_free_spve_spve, ANY_ROUTE},
{"bind_textopsx", (cmd_function)bind_textopsx, 1, 0, 0, ANY_ROUTE},
@@ -2057,6 +2060,63 @@ static int w_hf_iterator_rm(sip_msg_t *msg, char *piname, char *p2)
return ki_hf_iterator_rm(msg, &iname);
}
+/**
+ *
+ */
+static int ki_hf_iterator_append(sip_msg_t *msg, str *iname, str *htext)
+{
+ int k;
+ sr_lump_t *anchor;
+ str sval = STR_NULL;
+
+ k = ki_hf_iterator_index(msg, iname);
+ if(k<0 || _hf_iterators[k].it==NULL) {
+ return -1;
+ }
+ anchor = anchor_lump(msg, _hf_iterators[k].it->name.s
+ + _hf_iterators[k].it->len - msg->buf, 0, 0);
+ if (anchor==0) {
+ LM_ERR("cannot append hdr after %.*s\n", _hf_iterators[k].it->name.len,
+ _hf_iterators[k].it->name.s);
+ return -1;
+ }
+ sval.s = (char*)pkg_malloc(htext->len + 1);
+ if(sval.s==NULL) {
+ LM_ERR("failed append hdr after %.*s\n", _hf_iterators[k].it->name.len,
+ _hf_iterators[k].it->name.s);
+ return -1;
+ }
+ memcpy(sval.s, htext->s, htext->len);
+ sval.len = htext->len;
+ sval.s[sval.len] = '\0';
+
+ if (insert_new_lump_before(anchor, sval.s, sval.len, 0) == 0) {
+ LM_ERR("cannot insert lump\n");
+ pkg_free(sval.s);
+ return -1;
+ }
+ return 1;
+}
+
+/**
+ *
+ */
+static int w_hf_iterator_append(sip_msg_t *msg, char *piname, char *phtext)
+{
+ str iname = STR_NULL;
+ str htext = STR_NULL;
+ if(fixup_get_svalue(msg, (gparam_t*)piname, &iname)<0) {
+ LM_ERR("failed to get iterator name\n");
+ return -1;
+ }
+ if(fixup_get_svalue(msg, (gparam_t*)phtext, &htext)<0) {
+ LM_ERR("failed to get header text\n");
+ return -1;
+ }
+
+ return ki_hf_iterator_append(msg, &iname, &htext);
+}
+
/**
*
*/
More information about the sr-dev
mailing list