k/osp/tm.c

00001 /*
00002  * openser osp module. 
00003  *
00004  * This module enables openser to communicate with an Open Settlement 
00005  * Protocol (OSP) server.  The Open Settlement Protocol is an ETSI 
00006  * defined standard for Inter-Domain VoIP pricing, authorization
00007  * and usage exchange.  The technical specifications for OSP 
00008  * (ETSI TS 101 321 V4.1.1) are available at www.etsi.org.
00009  *
00010  * Uli Abend was the original contributor to this module.
00011  * 
00012  * Copyright (C) 2001-2005 Fhg Fokus
00013  *
00014  * This file is part of Kamailio, a free SIP server.
00015  *
00016  * Kamailio is free software; you can redistribute it and/or modify
00017  * it under the terms of the GNU General Public License as published by
00018  * the Free Software Foundation; either version 2 of the License, or
00019  * (at your option) any later version
00020  *
00021  * Kamailio is distributed in the hope that it will be useful,
00022  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024  * GNU General Public License for more details.
00025  *
00026  * You should have received a copy of the GNU General Public License
00027  * along with this program; if not, write to the Free Software
00028  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00029  *
00030  * History:
00031  * ---------
00032  *  2006-03-13  TM functions are loaded via API function (bogdan)
00033  */
00034 
00035 #include "../../modules/tm/tm_load.h"
00036 #include "tm.h"
00037 #include "destination.h"
00038 
00039 struct tm_binds osp_tmb;
00040 
00041 static void ospOnReq(struct cell* t, int type, struct tmcb_params* ps);
00042 static void ospTmcbFunc(struct cell* t, int type, struct tmcb_params* ps);
00043 
00044 /*
00045  * Load TM API
00046  * return 0 success, -1 failure
00047  */
00048 int ospInitTm(void)
00049 {
00050     if (load_tm_api(&osp_tmb) != 0) {
00051        LM_ERR("failed to load TM API\n");
00052        LM_ERR("TM is required for reporting call setup usage\n");
00053         return -1;
00054     }
00055 
00056     /* Register callbacks, listen for all incoming requests  */
00057     if (osp_tmb.register_tmcb(0, 0, TMCB_REQUEST_IN, ospOnReq, 0, 0) <= 0) {
00058        LM_ERR("failed to register TMCB_REQUEST_IN callback\n");
00059        LM_ERR("TM callbacks are required for reporting call set up usage\n");
00060         return -1;
00061     }
00062 
00063     return 0;
00064 }
00065 
00066 /*
00067  * Register OSP callback function
00068  * param t
00069  * param type
00070  * param ps
00071  */
00072 static void ospOnReq(
00073     struct cell* t, 
00074     int type, 
00075     struct tmcb_params* ps)
00076 {
00077     int tmcb_types;
00078 
00079     /* install addaitional handlers */
00080     tmcb_types =
00081 //        TMCB_REQUEST_FWDED |
00082 //        TMCB_RESPONSE_FWDED |
00083         TMCB_ON_FAILURE | 
00084 //        TMCB_LOCAL_COMPLETED |
00085         /* report on completed transactions */
00086         TMCB_RESPONSE_OUT |
00087         /* account e2e acks if configured to do so */
00088         TMCB_E2EACK_IN |
00089         /* report on missed calls */
00090         TMCB_ON_FAILURE_RO |
00091         /* get incoming replies ready for processing */
00092 //        TMCB_RESPONSE_IN |
00093         0;
00094 
00095     if (osp_tmb.register_tmcb(0, t, tmcb_types, ospTmcbFunc, 0, 0) <= 0) {
00096        LM_ERR("failed to register TM callbacks\n");
00097        LM_ERR("TM callbacks are required for reporting call setup usage\n");
00098         return;
00099     }
00100 }
00101 
00102 /*
00103  * OSP callback function
00104  * param t
00105  * param type
00106  * param ps
00107  */
00108 static void ospTmcbFunc(
00109     struct cell* t, 
00110     int type, 
00111     struct tmcb_params* ps)
00112 {
00113     if (type & TMCB_RESPONSE_OUT) {
00114         LM_DBG("RESPONSE_OUT\n");
00115     } else if (type & TMCB_E2EACK_IN) {
00116         LM_DBG("E2EACK_IN\n");
00117     } else if (type & TMCB_ON_FAILURE_RO) {
00118         LM_DBG("FAILURE_RO\n");
00119     } else if (type & TMCB_RESPONSE_IN) {
00120         LM_DBG("RESPONSE_IN\n");
00121     } else if (type & TMCB_REQUEST_FWDED) {
00122         LM_DBG("REQUEST_FWDED\n");
00123     } else if (type & TMCB_RESPONSE_FWDED) {
00124         LM_DBG("RESPONSE_FWDED\n");
00125     } else if (type & TMCB_ON_FAILURE) {
00126         LM_DBG("FAILURE\n");
00127     } else if (type & TMCB_LOCAL_COMPLETED) {
00128         LM_DBG("COMPLETED\n");
00129     } else {
00130         LM_DBG("something else '%d'\n", type);
00131     }
00132 
00133     if (t) {
00134         ospRecordEvent(t->uac[t->nr_of_outgoings - 1].last_received,
00135                                            t->uas.status);
00136     } else {
00137         LM_DBG("cell is empty\n");
00138     }
00139 }