Browse code

dialog: execute pre script callback only when event route is set

Daniel-Constantin Mierla authored on 21/04/2017 17:59:38
Showing 2 changed files
... ...
@@ -18,15 +18,15 @@
18 18
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 19
  * GNU General Public License for more details.
20 20
  *
21
- * You should have received a copy of the GNU General Public License 
22
- * along with this program; if not, write to the Free Software 
21
+ * You should have received a copy of the GNU General Public License
22
+ * along with this program; if not, write to the Free Software
23 23
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
24 24
  *
25 25
  */
26 26
 
27 27
 /*!
28 28
  * \file
29
- * \brief Kamailio core :: Script callbacks 
29
+ * \brief Kamailio core :: Script callbacks
30 30
  *
31 31
  * Script callbacks adds the ability to register callback
32 32
  * functions which are always called when script for request
... ...
@@ -151,12 +151,11 @@ int exec_pre_script_cb( struct sip_msg *msg, enum script_cb_type type)
151 151
 	struct script_cb	*cb;
152 152
 	unsigned int	flags;
153 153
 
154
-#ifdef EXTRA_DEBUG
155 154
 	if (type > SCRIPT_CB_NUM) {
156
-		LOG(L_BUG, "Uknown callback type\n");
157
-		abort();
155
+		LOG(L_BUG, "Uknown callback type %d\n", type);
156
+		return 0;
158 157
 	}
159
-#endif
158
+
160 159
 	flags = PRE_SCRIPT_CB | (1<<(type-1));
161 160
 	for (cb=pre_script_cb[type-1]; cb ; cb=cb->next ) {
162 161
 		/* stop on error */
... ...
@@ -174,12 +173,11 @@ int exec_post_script_cb( struct sip_msg *msg, enum script_cb_type type)
174 174
 	struct script_cb	*cb;
175 175
 	unsigned int	flags;
176 176
 
177
-#ifdef EXTRA_DEBUG
178 177
 	if (type > SCRIPT_CB_NUM) {
179
-		LOG(L_BUG, "exec_pre_script_cb: Uknown callback type\n");
180
-		abort();
178
+		LOG(L_BUG, "Uknown callback type %d\n", type);
179
+		return 1;
181 180
 	}
182
-#endif
181
+
183 182
 	flags = POST_SCRIPT_CB | (1<<(type-1));
184 183
 	for (cb=post_script_cb[type-1]; cb ; cb=cb->next){
185 184
 		cb->cbf(msg, flags, cb->param);
... ...
@@ -61,7 +61,7 @@ static str       rr_param;		/*!< record-route parameter for matching */
61 61
 static int       dlg_flag_mask=0;	/*!< flag for dialog tracking */
62 62
 static pv_spec_t *timeout_avp;		/*!< AVP for timeout setting */
63 63
 static int       default_timeout;	/*!< default dialog timeout */
64
-static int       seq_match_mode;	/*!< dlg_match mode */ 
64
+static int       seq_match_mode;	/*!< dlg_match mode */
65 65
 static int       shutdown_done = 0;	/*!< 1 when destroy_dlg_handlers was called */
66 66
 extern int       detect_spirals;
67 67
 extern int       dlg_timeout_noreset;
... ...
@@ -171,7 +171,7 @@ static inline int add_dlg_rr_param(struct sip_msg *req, unsigned int entry,
171 171
 /*!
172 172
  * \brief Parse SIP message and populate leg informations
173 173
  *
174
- * Parse SIP message and populate leg informations. 
174
+ * Parse SIP message and populate leg informations.
175 175
  * \param dlg the dialog to add cseq, contact & record_route
176 176
  * \param msg sip message
177 177
  * \param t transaction
... ...
@@ -813,7 +813,7 @@ static void unref_new_dialog(void *iuid)
813 813
  * \param t transaction
814 814
  * \param run_initial_cbs if set zero, initial callbacks are not executed
815 815
  * \return 0 on success, -1 on failure
816
- */ 
816
+ */
817 817
 int dlg_new_dialog(sip_msg_t *req, struct cell *t, const int run_initial_cbs)
818 818
 {
819 819
 	dlg_cell_t *dlg;
... ...
@@ -1191,7 +1191,7 @@ dlg_cell_t *dlg_lookup_msg_dialog(sip_msg_t *msg, unsigned int *dir)
1191 1191
 		}
1192 1192
 		return dlg;
1193 1193
 	}
1194
-	
1194
+
1195 1195
 	if (pre_match_parse(msg, &callid, &ftag, &ttag, 0)<0)
1196 1196
 		return NULL;
1197 1197
 	vdir = DLG_DIR_NONE;
... ...
@@ -1723,16 +1723,15 @@ void dlg_run_event_route(dlg_cell_t *dlg, sip_msg_t *msg, int ostate, int nstate
1723 1723
 		}
1724 1724
 	}
1725 1725
 
1726
+	if(rt>=0 || dlg_event_callback.len>0) {
1727
+		if(msg==NULL)
1728
+			fmsg = faked_msg_next();
1729
+		else
1730
+			fmsg = msg;
1726 1731
 
1727
-	if(msg==NULL)
1728
-		fmsg = faked_msg_next();
1729
-	else
1730
-		fmsg = msg;
1731
-
1732
-	if (exec_pre_script_cb(fmsg, LOCAL_CB_TYPE)<=0)
1733
-		return;
1732
+		if (exec_pre_script_cb(fmsg, LOCAL_CB_TYPE)<=0)
1733
+			return;
1734 1734
 
1735
-	if(rt>=0 || dlg_event_callback.len>0) {
1736 1735
 		dlg_ref(dlg, 1);
1737 1736
 		dlg_set_ctx_iuid(dlg);
1738 1737
 		LM_DBG("executing event_route %d on state %d\n", rt, nstate);