浏览代码

Merge pull request #2586 from danielmartinezruiz/textops_add_body_functions_to_api

textops: added functions to manipulate the body in the exported api
Daniel-Constantin Mierla 4 年之前
父节点
当前提交
67f741395d
共有 4 个文件被更改,包括 46 次插入0 次删除
  1. 18 0
      src/modules/textops/api.c
  2. 6 0
      src/modules/textops/api.h
  3. 19 0
      src/modules/textops/textops.c
  4. 3 0
      src/modules/textops/textops.h

+ 18 - 0
src/modules/textops/api.c

@@ -120,6 +120,21 @@ int is_privacy_api(struct sip_msg *msg, str* privacy_type){
 	return retval;
 }
 
+int set_body_api(struct sip_msg *msg, str *body, str *content_type)
+{
+    return set_body(msg, body, content_type);
+}
+
+int set_body_multipart_api(struct sip_msg *msg)
+{
+    return set_body_multipart(msg);
+}
+
+int append_body_part_api(struct sip_msg *msg, str *body, str *content_type, str *content_disposition)
+{
+    return append_body_part(msg, body, content_type, content_disposition);
+}
+
 /*
  * Function to load the textops api.
  */
@@ -133,5 +148,8 @@ int bind_textops(textops_api_t *tob){
 	tob->search_append=search_append_api;
 	tob->search=search_api;
 	tob->is_privacy=is_privacy_api;
+	tob->set_body=set_body_api;
+	tob->set_body_multipart=set_body_multipart_api;
+	tob->append_body_part=append_body_part_api;
 	return 0;
 }

+ 6 - 0
src/modules/textops/api.h

@@ -38,6 +38,9 @@ typedef int (*remove_hf_t)(struct sip_msg*, str*);
 typedef int (*search_append_t)(struct sip_msg*, str*, str*);
 typedef int (*search_t)(struct sip_msg*, str*);
 typedef int (*is_privacy_t)(struct sip_msg*, str*);
+typedef int (*set_body_t)(struct sip_msg*, str*, str*);
+typedef int (*set_body_multipart_t)(struct sip_msg*);
+typedef int (*append_body_part_t)(struct sip_msg*, str*, str*, str*);
 
 /*
  * Struct with the textops api.
@@ -48,6 +51,9 @@ typedef struct textops_binds {
 	search_append_t search_append; // Append a str after a match of the specified regex.
 	search_t search; // Check if the regex matches a part of the message.
 	is_privacy_t	is_privacy;
+	set_body_t set_body;
+	set_body_multipart_t set_body_multipart;
+	append_body_part_t append_body_part;
 } textops_api_t;
 
 typedef int (*bind_textops_f)(textops_api_t*);

+ 19 - 0
src/modules/textops/textops.c

@@ -2307,6 +2307,11 @@ static int ki_set_body(sip_msg_t* msg, str* nb, str* nc)
 	return 1;
 }
 
+int set_body(struct sip_msg* msg, str *body, str *content_type)
+{
+    return ki_set_body(msg, body, content_type);
+}
+
 static int set_body_f(struct sip_msg* msg, char* p1, char* p2)
 {
 	str nb = {0,0};
@@ -2775,6 +2780,15 @@ int set_multibody_helper(struct sip_msg* msg, char* p1, char* p2, char* p3)
 	return ki_set_multibody(msg, &nbody, &ctype, &boundary);
 }
 
+int set_body_multipart(struct sip_msg* msg)
+{
+	str nbody = STR_NULL;
+	str ctype = STR_NULL;
+	str boundary = STR_NULL;
+
+	return ki_set_multibody(msg, &nbody, &ctype, &boundary);
+}
+
 static int set_multibody_0(struct sip_msg* msg, char* p1, char* p2, char* p3)
 {
 	return set_multibody_helper(msg, NULL, NULL, NULL);
@@ -2981,6 +2995,11 @@ static int append_multibody_helper(sip_msg_t *msg, char *p1, char *p2, char *p3,
 	}
 }
 
+int append_body_part(struct sip_msg* msg, str *body, str *content_type, str *content_disposition)
+{
+	return ki_append_multibody_cd(msg, body, content_type, content_disposition);
+}
+
 static int append_multibody_2(struct sip_msg* msg, char* p1, char* p2)
 {
 	return append_multibody_helper(msg, p1, p2, NULL, 0);

+ 3 - 0
src/modules/textops/textops.h

@@ -36,6 +36,9 @@ int search_append_f(struct sip_msg*, char*, char*);
 int remove_hf_f(struct sip_msg* msg, char* str_hf, char* foo);
 int add_hf_helper(struct sip_msg* msg, str *str1, str *str2, gparam_p hfval, int mode, gparam_p hfanc);
 int is_privacy_f(struct sip_msg *msg, char *privacy, char *str2 );
+int set_body(struct sip_msg *msg, str *body, str *content_type);
+int set_body_multipart(struct sip_msg *msg);
+int append_body_part(struct sip_msg *msg, str *body, str *content_type, str *content_disposition);
 
 int fixup_regexp_none(void** param, int param_no);
 int fixup_free_regexp_none(void** param, int param_no);