sl_cb.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "../../mem/mem.h"
00035 #include "sl_cb.h"
00036
00037
00038 struct sl_callback* slcb_hl = 0;
00039
00040
00041
00042 void destroy_slcb_lists(void)
00043 {
00044 struct sl_callback *cbp, *cbp_tmp;
00045
00046 for( cbp=slcb_hl; cbp ; ) {
00047 cbp_tmp = cbp;
00048 cbp = cbp->next;
00049 pkg_free( cbp_tmp );
00050 }
00051 }
00052
00053
00054
00055 int register_slcb(unsigned int types, sl_cb_t f, void *param )
00056 {
00057 struct sl_callback *cbp;
00058
00059
00060 if (!(cbp=pkg_malloc( sizeof( struct sl_callback)))) {
00061 LM_ERR("out of pkg. mem\n");
00062 return -1;
00063 }
00064
00065
00066 cbp->types = types;
00067 cbp->callback = f;
00068 cbp->param = param;
00069
00070 cbp->next = slcb_hl;
00071 slcb_hl = cbp;
00072
00073 if (cbp->next)
00074 cbp->id = cbp->next->id+1;
00075 else
00076 cbp->id = 0;
00077
00078 return 0;
00079 }
00080
00081
00082
00083 void run_sl_callbacks( unsigned int types, struct sip_msg *req, str *buffer,
00084 int code, str *reason, union sockaddr_union *to )
00085 {
00086 static struct sl_cb_param cb_params;
00087 struct sl_callback *cbp;
00088
00089 cb_params.buffer = buffer;
00090 cb_params.code = code;
00091 cb_params.reason = reason;
00092 cb_params.dst = to;
00093
00094 for ( cbp=slcb_hl ; cbp ; cbp=cbp->next ) {
00095 if (types&cbp->types) {
00096 cb_params.param = cbp->param;
00097 LM_DBG("callback id %d entered\n", cbp->id );
00098 cbp->callback( types&cbp->types, req, &cb_params);
00099 }
00100 }
00101 }