s/osp/tm.c

00001 /*
00002  * ser osp module. 
00003  *
00004  * This module enables ser 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 ser, a free SIP server.
00015  *
00016  * ser 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  * For a license to use the ser software under conditions
00022  * other than those described here, or to purchase support for this
00023  * software, please contact iptel.org by e-mail at the following addresses:
00024  *    info@iptel.org
00025  *
00026  * ser is distributed in the hope that it will be useful,
00027  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00028  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00029  * GNU General Public License for more details.
00030  *
00031  * You should have received a copy of the GNU General Public License
00032  * along with this program; if not, write to the Free Software
00033  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00034  */
00035 
00036 #include "../../modules/tm/tm_load.h"
00037 #include "tm.h"
00038 #include "destination.h"
00039 
00040 struct tm_binds osp_tmb;
00041 
00042 static void ospOnReq(struct cell* t, int type, struct tmcb_params* ps);
00043 static void ospTmcbFunc(struct cell* t, int type, struct tmcb_params* ps);
00044 
00045 /*
00046  * Load TM API
00047  * return 0 success, -1 failure
00048  */
00049 int ospInitTm(void)
00050 {
00051     load_tm_f load_tm;
00052 
00053     LOG(L_DBG, "osp: ospInitTm\n");
00054 
00055     if ((load_tm = (load_tm_f)find_export("load_tm", NO_SCRIPT, 0)) == 0) {
00056         LOG(L_ERR, "osp: ERROR: failed to import load_tm\n");
00057         return -1;
00058     }
00059 
00060     if (load_tm(&osp_tmb) == -1) {
00061         LOG(L_ERR, "osp: ERROR: failed to load TM API\n");
00062         LOG(L_ERR, "osp: ERROR: TM is required for reporting call setup usage\n");
00063         return -1;
00064     }
00065 
00066     /* Register callbacks, listen for all incoming requests  */
00067     if (osp_tmb.register_tmcb(0, 0, TMCB_REQUEST_IN, ospOnReq, 0, 0) <= 0) {
00068         LOG(L_ERR, "osp: ERROR: failed to register TMCB_REQUEST_IN callback\n");
00069         LOG(L_ERR, "osp: ERROR: TM callbacks are required for reporting call set up usage\n");
00070         return -1;
00071     }
00072 
00073     return 0;
00074 }
00075 
00076 /*
00077  * Register OSP callback function
00078  * param t
00079  * param type
00080  * param ps
00081  */
00082 static void ospOnReq(
00083     struct cell* t, 
00084     int type, 
00085     struct tmcb_params* ps)
00086 {
00087     int tmcb_types;
00088 
00089     LOG(L_DBG, "osp: ospOnReq\n");
00090 
00091     /* install addaitional handlers */
00092     tmcb_types =
00093 //        TMCB_REQUEST_FWDED |
00094 //        TMCB_RESPONSE_FWDED |
00095         TMCB_ON_FAILURE | 
00096 //        TMCB_LOCAL_COMPLETED |
00097         /* report on completed transactions */
00098         TMCB_RESPONSE_OUT |
00099         /* account e2e acks if configured to do so */
00100         TMCB_E2EACK_IN |
00101         /* report on missed calls */
00102         TMCB_ON_FAILURE_RO |
00103         /* get incoming replies ready for processing */
00104 //        TMCB_RESPONSE_IN |
00105         0;
00106 
00107     if (osp_tmb.register_tmcb(0, t, tmcb_types, ospTmcbFunc, 0, 0) <= 0) {
00108         LOG(L_ERR, "osp: ERROR: failed to register TM callbacks\n");
00109         LOG(L_ERR, "osp: ERROR: TM callbacks are required for reporting call setup usage\n");
00110         return;
00111     }
00112 
00113     /* Also, if that is INVITE, disallow silent t-drop */
00114     if (ps->req->REQ_METHOD == METHOD_INVITE) {
00115         LOG(L_DBG, "osp: noisy_timer set for accounting\n");
00116         t->flags |= T_NOISY_CTIMER_FLAG;
00117     }
00118 }
00119 
00120 /*
00121  * OSP callback function
00122  * param t
00123  * param type
00124  * param ps
00125  */
00126 static void ospTmcbFunc(
00127     struct cell* t, 
00128     int type, 
00129     struct tmcb_params* ps)
00130 {
00131     LOG(L_DBG, "osp: ospTmcbFunc\n");
00132 
00133     if (type & TMCB_RESPONSE_OUT) {
00134         LOG(L_DBG, "osp: RESPONSE_OUT\n");
00135     } else if (type & TMCB_E2EACK_IN) {
00136         LOG(L_DBG, "osp: E2EACK_IN\n");
00137     } else if (type & TMCB_ON_FAILURE_RO) {
00138         LOG(L_DBG, "osp: FAILURE_RO\n");
00139     } else if (type & TMCB_RESPONSE_IN) {
00140         LOG(L_DBG, "osp: RESPONSE_IN\n");
00141     } else if (type & TMCB_REQUEST_FWDED) {
00142         LOG(L_DBG, "osp: REQUEST_FWDED\n");
00143     } else if (type & TMCB_RESPONSE_FWDED) {
00144         LOG(L_DBG, "osp: RESPONSE_FWDED\n");
00145     } else if (type & TMCB_ON_FAILURE) {
00146         LOG(L_DBG, "osp: FAILURE\n");
00147     } else if (type & TMCB_LOCAL_COMPLETED) {
00148         LOG(L_DBG, "osp: COMPLETED\n");
00149     } else {
00150         LOG(L_DBG, "osp: something else '%d'\n", type);
00151     }
00152 
00153     if (t) {
00154         ospRecordEvent(t->uac[t->nr_of_outgoings - 1].last_received, t->uas.status);
00155     } else {
00156         LOG(L_DBG, "osp: cell is empty\n");
00157     }
00158 }