textops/api.c

Go to the documentation of this file.
00001 /* Copyright (C) 2008 Telecats BV
00002  *
00003  * This file is part of openser, a free SIP server.
00004  *
00005  * openser is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * openser is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018  *
00019  *
00020  * History:
00021  * ---------
00022  *  2008-07-14 first version (Ardjan Zwartjes)
00023  */
00024 
00025 
00026 #include "api.h"
00027 #include "textops.h"
00028 #include "../../mod_fix.h"
00029 #include "../../mem/mem.h"
00030 
00031 
00032 /*
00033  * User friendly wrapper around add_hf_helper, to be called from 
00034  * other modules.
00035  */
00036 int append_hf_api(struct sip_msg *msg, str* str_hf){
00037    return add_hf_helper(msg, str_hf, NULL, NULL, 0, NULL);
00038 }
00039 
00040 /*
00041  * User friendly wrapper around remove_hf_f, to be called from 
00042  * other modules.
00043  */
00044 int remove_hf_api(struct sip_msg *msg, str* str_hf){
00045    return remove_hf_f(msg, (char*)str_hf,NULL);
00046 }
00047 
00048 
00049 /*
00050  * User friendly wrapper to call search_append from other
00051  * modules
00052  */
00053 
00054 int search_append_api(struct sip_msg *msg, str *regex, str *data_str){
00055    int retval;
00056    
00057    char *data=pkg_malloc(data_str->len+1);
00058    memcpy(data,data_str->s,data_str->len);
00059    memset(data+data_str->len,0,1);
00060    
00061    void **param=pkg_malloc(sizeof(void*));
00062    *param=pkg_malloc(regex->len+1);
00063    memcpy(*param,regex->s,regex->len);
00064    memset(*param+regex->len,0,1);
00065    
00066    fixup_regexp_none(param,1);
00067    
00068    retval=search_append_f(msg, *param, data);
00069    
00070    fixup_free_regexp_none(param,1);
00071 
00072    pkg_free(param);
00073    pkg_free(data);
00074    
00075    return retval;
00076    
00077 }
00078 
00079 /*
00080  * User friendly wrapper to call search from other modules.
00081  */
00082 int search_api(struct sip_msg *msg, str *regex){
00083    int retval;
00084 
00085    void **param=pkg_malloc(sizeof(void*));
00086    
00087    *param=pkg_malloc(regex->len+1);
00088    memcpy(*param,regex->s,regex->len);
00089    memset(*param+regex->len,0,1);
00090    
00091    fixup_regexp_none(param,1);
00092    
00093    retval=search_f(msg, *param, NULL);
00094    
00095    fixup_free_regexp_none(param,1);
00096    pkg_free(param);
00097    
00098    return retval;
00099    
00100 }
00101 /*
00102  * Function to load the textops api.
00103  */
00104 int load_textops(struct textops_binds *tob){
00105    if(tob==NULL){
00106       LM_WARN("textops_binds: Cannot load textops API into a NULL pointer\n");
00107       return -1;
00108    }
00109    tob->append_hf=append_hf_api;
00110    tob->remove_hf=remove_hf_api;
00111    tob->search_append=search_append_api;
00112    tob->search=search_api;
00113    return 0;
00114 }

Generated on Thu May 24 20:00:24 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6