Skip to content

Commit

Permalink
textops: clang-format for coherent indentation and coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxmaniac committed May 18, 2023
1 parent 76482e4 commit 507d424
Show file tree
Hide file tree
Showing 6 changed files with 1,678 additions and 1,804 deletions.
113 changes: 59 additions & 54 deletions src/modules/textops/api.c
Expand Up @@ -37,16 +37,18 @@
* User friendly wrapper around add_hf_helper, to be called from
* other modules.
*/
int append_hf_api(struct sip_msg *msg, str* str_hf){
int append_hf_api(struct sip_msg *msg, str *str_hf)
{
return add_hf_helper(msg, str_hf, NULL, NULL, 0, NULL);
}

/*
* User friendly wrapper around remove_hf_f, to be called from
* other modules.
*/
int remove_hf_api(struct sip_msg *msg, str* str_hf){
return remove_hf_f(msg, (char*)str_hf,NULL);
int remove_hf_api(struct sip_msg *msg, str *str_hf)
{
return remove_hf_f(msg, (char *)str_hf, NULL);
}


Expand All @@ -55,62 +57,63 @@ int remove_hf_api(struct sip_msg *msg, str* str_hf){
* modules
*/

int search_append_api(struct sip_msg *msg, str *regex, str *data_str){
int search_append_api(struct sip_msg *msg, str *regex, str *data_str)
{
int retval;
char *data;
void **param;
data=pkg_malloc(data_str->len+1);
memcpy(data,data_str->s,data_str->len);
memset(data+data_str->len,0,1);
param=pkg_malloc(sizeof(void*));
*param=pkg_malloc(regex->len+1);
memcpy(*param,regex->s,regex->len);
memset(*param+regex->len,0,1);
fixup_regexp_none(param,1);
retval=search_append_f(msg, *param, data);
fixup_free_regexp_none(param,1);

data = pkg_malloc(data_str->len + 1);
memcpy(data, data_str->s, data_str->len);
memset(data + data_str->len, 0, 1);

param = pkg_malloc(sizeof(void *));
*param = pkg_malloc(regex->len + 1);
memcpy(*param, regex->s, regex->len);
memset(*param + regex->len, 0, 1);

fixup_regexp_none(param, 1);

retval = search_append_f(msg, *param, data);

fixup_free_regexp_none(param, 1);

pkg_free(param);
pkg_free(data);

return retval;

}

/*
* User friendly wrapper to call search from other modules.
*/
int search_api(struct sip_msg *msg, str *regex){
int search_api(struct sip_msg *msg, str *regex)
{
int retval;

void **param=pkg_malloc(sizeof(void*));
*param=pkg_malloc(regex->len+1);
memcpy(*param,regex->s,regex->len);
memset(*param+regex->len,0,1);
fixup_regexp_none(param,1);
retval=search_f(msg, *param, NULL);
fixup_free_regexp_none(param,1);
void **param = pkg_malloc(sizeof(void *));

*param = pkg_malloc(regex->len + 1);
memcpy(*param, regex->s, regex->len);
memset(*param + regex->len, 0, 1);

fixup_regexp_none(param, 1);

retval = search_f(msg, *param, NULL);

fixup_free_regexp_none(param, 1);
pkg_free(param);

return retval;

}

int is_privacy_api(struct sip_msg *msg, str* privacy_type){
int is_privacy_api(struct sip_msg *msg, str *privacy_type)
{
int retval;
void **param=pkg_malloc(sizeof(void*));
*param=pkg_malloc(privacy_type->len+1);
memcpy(*param,privacy_type->s,privacy_type->len);
memset(*param+privacy_type->len,0,1);
void **param = pkg_malloc(sizeof(void *));
*param = pkg_malloc(privacy_type->len + 1);
memcpy(*param, privacy_type->s, privacy_type->len);
memset(*param + privacy_type->len, 0, 1);

fixup_privacy(param, 1);
retval = is_privacy_f(msg, *param, NULL);
Expand All @@ -122,34 +125,36 @@ int is_privacy_api(struct sip_msg *msg, str* privacy_type){

int set_body_api(struct sip_msg *msg, str *body, str *content_type)
{
return set_body(msg, body, content_type);
return set_body(msg, body, content_type);
}

int set_body_multipart_api(struct sip_msg *msg)
{
return set_body_multipart(msg);
return set_body_multipart(msg);
}

int append_body_part_api(struct sip_msg *msg, str *body, str *content_type, str *content_disposition)
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);
return append_body_part(msg, body, content_type, content_disposition);
}

/*
* Function to load the textops api.
*/
int bind_textops(textops_api_t *tob){
if(tob==NULL){
int bind_textops(textops_api_t *tob)
{
if(tob == NULL) {
LM_WARN("textops_binds: Cannot load textops API into a NULL pointer\n");
return -1;
}
tob->append_hf=append_hf_api;
tob->remove_hf=remove_hf_api;
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;
tob->append_hf = append_hf_api;
tob->remove_hf = remove_hf_api;
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;
}
42 changes: 23 additions & 19 deletions src/modules/textops/api.h
Expand Up @@ -26,50 +26,54 @@
*/



#ifndef TEXTOPS_API_H_
#define TEXTOPS_API_H_
#include "../../core/str.h"
#include "../../core/sr_module.h"


typedef int (*append_hf_t)(struct sip_msg*, str*);
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*);
typedef int (*append_hf_t)(struct sip_msg *, str *);
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.
*/
typedef struct textops_binds {
append_hf_t append_hf; // Append a header to the message.
remove_hf_t remove_hf; // Remove a header with the specified name from the message.
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;
typedef struct textops_binds
{
append_hf_t append_hf; // Append a header to the message.
remove_hf_t
remove_hf; // Remove a header with the specified name from the message.
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*);
typedef int (*bind_textops_f)(textops_api_t *);

/*
* function exported by module - it will load the other functions
*/
int bind_textops(textops_api_t*);
int bind_textops(textops_api_t *);

/*
* Function to be called direclty from other modules to load
* the textops API.
*/
inline static int load_textops_api(textops_api_t *tob){
inline static int load_textops_api(textops_api_t *tob)
{
bind_textops_f bind_textops_exports;
if(!(bind_textops_exports=(bind_textops_f)find_export("bind_textops",0,0))){
if(!(bind_textops_exports =
(bind_textops_f)find_export("bind_textops", 0, 0))) {
LM_ERR("Failed to import bind_textops\n");
return -1;
}
Expand Down

0 comments on commit 507d424

Please sign in to comment.