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
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
00047
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
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
00078
00079
00080
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
00092 tmcb_types =
00093
00094
00095 TMCB_ON_FAILURE |
00096
00097
00098 TMCB_RESPONSE_OUT |
00099
00100 TMCB_E2EACK_IN |
00101
00102 TMCB_ON_FAILURE_RO |
00103
00104
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
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
00122
00123
00124
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 }