Forráskód Böngészése

topos: group storage function in an api structure

Daniel-Constantin Mierla 8 éve
szülő
commit
d40635aa94
2 módosított fájl, 115 hozzáadás és 10 törlés
  1. 54 0
      src/modules/topos/api.h
  2. 61 10
      src/modules/topos/tps_storage.c

+ 54 - 0
src/modules/topos/api.h

@@ -0,0 +1,54 @@
+/**
+ * Copyright (C) 2017 Daniel-Constantin Mierla (asipto.com)
+ *
+ * This file is part of Kamailio, a free SIP server.
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ *
+ * This file is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+/*!
+ * \file
+ * \brief Kamailio topos ::
+ * \ingroup topos
+ * Module: \ref topos
+ */
+
+#ifndef _TOPOS_API_H_
+#define _TOPOS_API_H_
+
+#include "tps_storage.h"
+
+typedef int (*tps_insert_dialog_f)(tps_data_t *td);
+typedef int (*tps_clean_dialogs_f)(void);
+typedef int (*tps_insert_branch_f)(tps_data_t *td);
+typedef int (*tps_clean_branches_f)(void);
+typedef int (*tps_load_branch_f)(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd);
+typedef int (*tps_load_dialog_f)(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd);
+typedef int (*tps_update_dialog_f)(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd);
+typedef int (*tps_end_dialog_f)(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd);
+
+typedef struct tps_storage_api {
+	tps_insert_dialog_f insert_dialog;
+	tps_clean_dialogs_f clean_dialogs;
+	tps_insert_branch_f insert_branch;
+	tps_clean_branches_f clean_branches;
+	tps_load_branch_f load_branch;
+	tps_load_dialog_f load_dialog;
+	tps_update_dialog_f update_dialog;
+	tps_end_dialog_f end_dialog;
+} tps_storage_api_t;
+
+#endif

+ 61 - 10
src/modules/topos/tps_storage.c

@@ -46,6 +46,7 @@
 #include "../../lib/srutils/sruid.h"
 
 #include "tps_storage.h"
+#include "api.h"
 
 extern sruid_t _tps_sruid;
 
@@ -58,10 +59,28 @@ static gen_lock_set_t *_tps_storage_lock_set = NULL;
 int _tps_branch_expire = 180;
 int _tps_dialog_expire = 10800;
 
-int tps_db_insert_branch(tps_data_t *td);
-int tps_db_clean_branches(void);
 int tps_db_insert_dialog(tps_data_t *td);
 int tps_db_clean_dialogs(void);
+int tps_db_insert_branch(tps_data_t *td);
+int tps_db_clean_branches(void);
+int tps_db_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd);
+int tps_db_load_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd);
+int tps_db_update_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd);
+int tps_db_end_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd);
+
+/**
+ *
+ */
+static tps_storage_api_t _tps_storage_api = {
+	.insert_dialog = tps_db_insert_dialog,
+	.clean_dialogs = tps_db_clean_dialogs,
+	.insert_branch = tps_db_insert_branch,
+	.clean_branches = tps_db_clean_branches,
+	.load_branch = tps_db_load_branch,
+	.load_dialog = tps_db_load_dialog,
+	.update_dialog = tps_db_update_dialog,
+	.end_dialog = tps_db_end_dialog
+};
 
 /**
  *
@@ -345,10 +364,10 @@ int tps_storage_record(sip_msg_t *msg, tps_data_t *td, int dialog)
 	ret = tps_storage_link_msg(msg, td, TPS_DIR_DOWNSTREAM);
 	if(ret<0) goto error;
 	if(dialog==0) {
-		ret = tps_db_insert_dialog(td);
+		ret = _tps_storage_api.insert_dialog(td);
 		if(ret<0) goto error;
 	}
-	ret = tps_db_insert_branch(td);
+	ret = _tps_storage_api.insert_branch(td);
 	if(ret<0) goto error;
 
 	return 0;
@@ -767,7 +786,7 @@ int tps_db_clean_branches(void)
 /**
  *
  */
-int tps_storage_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
+int tps_db_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
 {
 	db_key_t db_keys[4];
 	db_op_t  db_ops[4];
@@ -856,7 +875,15 @@ error:
 /**
  *
  */
-int tps_storage_load_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
+int tps_storage_load_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
+{
+	return _tps_storage_api.load_branch(msg, md, sd);
+}
+
+/**
+ *
+ */
+int tps_db_load_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
 {
 	db_key_t db_keys[4];
 	db_op_t  db_ops[4];
@@ -982,6 +1009,14 @@ error:
 	return -1;
 }
 
+/**
+ *
+ */
+int tps_storage_load_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
+{
+	return _tps_storage_api.load_dialog(msg, md, sd);
+}
+
 /**
  *
  */
@@ -993,7 +1028,7 @@ int tps_storage_update_branch(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
 /**
  *
  */
-int tps_storage_update_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
+int tps_db_update_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
 {
 	db_key_t db_keys[4];
 	db_op_t  db_ops[4];
@@ -1085,7 +1120,15 @@ int tps_storage_update_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
 /**
  *
  */
-int tps_storage_end_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
+int tps_storage_update_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
+{
+	return _tps_storage_api.update_dialog(msg, md, sd);
+}
+
+/**
+ *
+ */
+int tps_db_end_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
 {
 	db_key_t db_keys[4];
 	db_op_t  db_ops[4];
@@ -1147,11 +1190,19 @@ int tps_storage_end_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
 	return 0;
 }
 
+/**
+ *
+ */
+int tps_storage_end_dialog(sip_msg_t *msg, tps_data_t *md, tps_data_t *sd)
+{
+	return _tps_storage_api.end_dialog(msg, md, sd);
+}
+
 /**
  *
  */
 void tps_storage_clean(unsigned int ticks, void* param)
 {
-	tps_db_clean_branches();
-	tps_db_clean_dialogs();
+	_tps_storage_api.clean_branches();
+	_tps_storage_api.clean_dialogs();
 }