acc_api.h

Go to the documentation of this file.
00001 /*
00002  * $Id$
00003  *
00004  * Copyright (C) 2001-2003 FhG Fokus
00005  *
00006  * This file is part of Kamailio, a free SIP server.
00007  *
00008  * Kamailio is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version
00012  *
00013  * Kamailio is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License 
00019  * along with this program; if not, write to the Free Software 
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  * History:
00023  * --------
00024  */
00025 
00034 #ifndef _ACC_API_H_
00035 #define _ACC_API_H_
00036 
00037 #include <stdio.h>
00038 #include <string.h>
00039 
00040 #include "../../str.h"
00041 #include "../../dprint.h"
00042 #include "../../sr_module.h"
00043 #include "../../mem/mem.h"
00044 
00045 /* param trasnporter */
00046 typedef struct acc_param {
00047         int code;
00048         str code_s;
00049         str reason;
00050 } acc_param_t;
00051 
00052 /* various acc variables */
00053 typedef struct acc_enviroment {
00054         unsigned int code;
00055         str code_s;
00056         str reason;
00057         struct hdr_field *to;
00058         str text;
00059         time_t ts;
00060 } acc_enviroment_t;
00061 
00062 /* acc extra parameter */
00063 typedef struct acc_extra {
00064         str        name;       
00065         pv_spec_t  spec;       
00066         struct acc_extra *next;
00067 } acc_extra_t;
00068 
00069 typedef int (*core2strar_f)( struct sip_msg *req, str *c_vals,
00070                               int *i_vals, char *t_vals);
00071 typedef int (*extra2strar_f)(struct acc_extra *extra, struct sip_msg *rq, str *val_arr,
00072                 int *int_arr, char *type_arr);
00073 typedef int (*legs2strar_f)( struct acc_extra *legs, struct sip_msg *rq, str *val_arr,
00074                 int *int_arr, char *type_arr, int start);
00075 typedef acc_extra_t* (*leg_info_f)(void);
00076 
00077 /* acc event data structures */
00078 typedef struct acc_info {
00079         acc_enviroment_t *env;
00080         str *varr;
00081         int *iarr;
00082         char *tarr;
00083         acc_extra_t *leg_info;
00084 } acc_info_t;
00085 
00086 /* acc engine initialization data structures */
00087 typedef struct acc_init_info {
00088         acc_extra_t   *leg_info;
00089 } acc_init_info_t;
00090 
00091 typedef int (*acc_init_f)(acc_init_info_t *inf);
00092 typedef int (*acc_req_f)(struct sip_msg *req, acc_info_t *data);
00093 
00094 /* acc engine structure */
00095 typedef struct acc_engine {
00096         char name[16];
00097         int flags;
00098         int acc_flag;
00099         int missed_flag;
00100         acc_init_f acc_init;
00101         acc_req_f  acc_req;
00102         struct acc_engine *next;
00103 } acc_engine_t;
00104 
00105 #define MAX_ACC_EXTRA 64
00106 #define MAX_ACC_LEG   16
00107 #define ACC_CORE_LEN 6
00108 
00109 
00110 enum {TYPE_NULL = 0, TYPE_INT, TYPE_STR};
00111 
00112 
00113 typedef int (*register_engine_f)(acc_engine_t *eng);
00114 typedef int (*acc_api_exec_f)(struct sip_msg *rq, acc_engine_t *eng,
00115                 acc_param_t* comment);
00116 typedef acc_extra_t* (*parse_extra_f)(char *extra_str);
00117 
00118 /* the acc API */
00119 typedef struct acc_api {
00120         leg_info_f    get_leg_info;
00121         core2strar_f  get_core_attrs;
00122         extra2strar_f get_extra_attrs;
00123         legs2strar_f  get_leg_attrs;
00124         parse_extra_f parse_extra;
00125         register_engine_f register_engine;
00126         acc_api_exec_f    exec;
00127 } acc_api_t;
00128 
00129 typedef int (*bind_acc_f)(acc_api_t* api);
00130 
00131 int acc_run_engines(struct sip_msg *msg, int type, int *reset);
00132 acc_engine_t *acc_api_get_engines(void);
00133 void acc_api_set_arrays(acc_info_t *inf);
00134 
00135 
00139 static inline int acc_load_api(acc_api_t *accb)
00140 {
00141         bind_acc_f bindacc;
00142 
00143         bindacc = (bind_acc_f)find_export("bind_acc", 0, 0);
00144         if (bindacc == 0) {
00145                 LM_ERR("cannot find bind_acc\n");
00146                 return -1;
00147         }
00148         if (bindacc(accb)==-1)
00149         {
00150                 LM_ERR("cannot bind acc api\n");
00151                 return -1;
00152         }
00153         return 0;
00154 }
00155 
00156 
00157 #endif