Jelajahi Sumber

Merge branch 'master' of ssh://git.sip-router.org/sip-router

* 'master' of ssh://git.sip-router.org/sip-router:
  dialog(k): table version in DB is 7
  htable(k): Implement "delete" mi/rpc function.
  tm: reset T if t_continue() resumes a canceled transaction
Peter Dunkley 13 tahun lalu
induk
melakukan
030273ffbc

+ 2 - 0
modules/tm/t_suspend.c

@@ -133,6 +133,8 @@ int t_continue(unsigned int hash_index, unsigned int label,
 		/* The transaction has already been canceled,
 		 * needless to continue */
 		UNREF(t); /* t_unref would kill the transaction */
+		/* reset T as we have no working T anymore */
+		set_t(T_UNDEFINED, T_BR_UNDEFINED);
 		return 1;
 	}
 

+ 1 - 1
modules_k/dialog/dlg_db_handler.h

@@ -56,7 +56,7 @@
 #define REQ_URI_COL				"req_uri"
 #define XDATA_COL				"xdata"
 #define DIALOG_TABLE_NAME		"dialog"
-#define DLG_TABLE_VERSION		6
+#define DLG_TABLE_VERSION		7
 
 #define DIALOG_TABLE_COL_NO 		23
 

+ 35 - 2
modules_k/htable/doc/htable_admin.xml

@@ -620,7 +620,7 @@ sht_rm_value_re("ha=>.*");
 		_empty_line_
 		</programlisting>
     </section>
-	<section>
+    <section>
 		<title>
 		<function moreinfo="none">sht_dump</function>
 		</title>
@@ -635,12 +635,45 @@ sht_rm_value_re("ha=>.*");
  		<para>
 		MI FIFO Command Format:
 		</para>
-        <programlisting  format="linespecific">
+		<programlisting  format="linespecific">
 		:sht_dump:_reply_fifo_file_
 		_hash_table_name_
 		_empty_line_
 		</programlisting>
     </section>
+    <section>
+		<title>
+		<function moreinfo="none">sht_delete</function>
+		</title>
+		<para>
+		Delete a key from a hash table via MI.
+		</para>
+		<para>
+		Name: <emphasis>sht_delete</emphasis>
+		</para>
+		<para>Parameters:</para>
+		<itemizedlist>
+			<listitem><para><emphasis>_hash_table_name: </emphasis>The table name to delete the key from</para></listitem>
+			<listitem><para><emphasis>_key_name: </emphasis>The key to delete from the htable</para></listitem>
+		</itemizedlist>
+
+ 		<para>
+		MI FIFO Command Format:
+		</para>
+		<programlisting  format="linespecific">
+		:sht_delete:_reply_fifo_file_
+		_hash_table_name_
+		_key_name_
+		_empty_line_
+		</programlisting>
+
+ 		<para>
+		Example (note the quoting when executing it via FIFO):
+		</para>
+		<programlisting  format="linespecific">
+		kamctl fifo sht_delete auth '"[email protected]::last_auth"'
+		</programlisting>
+    </section>
     </section>
 	<section>
 	<title>Event routes</title>

+ 57 - 0
modules_k/htable/htable.c

@@ -66,6 +66,7 @@ int ht_param(modparam_t type, void* val);
 
 static struct mi_root* ht_mi_reload(struct mi_root* cmd_tree, void* param);
 static struct mi_root* ht_mi_dump(struct mi_root* cmd_tree, void* param);
+static struct mi_root* ht_mi_delete(struct mi_root* cmd_tree, void* param);
 
 static pv_export_t mod_pvs[] = {
 	{ {"sht", sizeof("sht")-1}, PVT_OTHER, pv_get_ht_cell, pv_set_ht_cell,
@@ -87,6 +88,7 @@ static pv_export_t mod_pvs[] = {
 static mi_export_t mi_cmds[] = {
 	{ "sht_reload",     ht_mi_reload,  0,  0,  0},
 	{ "sht_dump",       ht_mi_dump,    0,  0,  0},
+	{ "sht_delete",     ht_mi_delete,  0,  0,  0},
 	{ 0, 0, 0, 0, 0}
 };
 
@@ -414,6 +416,39 @@ static struct mi_root* ht_mi_reload(struct mi_root* cmd_tree, void* param)
 	return init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
 }
 
+static struct mi_root* ht_mi_delete(struct mi_root* cmd_tree, void* param) {
+	struct mi_node *node;
+	str *htname, *key;
+	ht_t *ht;
+
+	node = cmd_tree->node.kids;
+	if (!node)
+		goto param_err;
+
+	htname = &node->value;
+	if (!htname->len)
+		goto param_err;
+
+	node = node->next;
+	if (!node)
+		goto param_err;
+
+	key = &node->value;
+	if (!key->len)
+		goto param_err;
+
+	ht = ht_get_table(htname);
+	if (!ht)
+		return init_mi_tree(404, MI_BAD_PARM_S, MI_BAD_PARM_LEN);
+
+	ht_del_cell(ht, key);
+
+	return init_mi_tree(200, MI_OK_S, MI_OK_LEN);
+
+param_err:
+	return init_mi_tree(400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN);
+}
+
 static struct mi_root* ht_mi_dump(struct mi_root* cmd_tree, void* param)
 {
 	struct mi_node* node;
@@ -487,6 +522,27 @@ static const char* htable_dump_doc[2] = {
 	"Dump the contents of hash table.",
 	0
 };
+static const char* htable_delete_doc[2] = {
+	"Delete one key from a hash table.",
+	0
+};
+
+static void htable_rpc_delete(rpc_t* rpc, void* c) {
+	str htname, keyname;
+	ht_t *ht;
+
+	if (rpc->scan(c, "SS", &htname, &keyname) < 2) {
+		rpc->fault(c, 500, "Not enough parameters (htable name & key name");
+		return;
+	}
+	ht = ht_get_table(&htname);
+	if (!ht) {
+		rpc->fault(c, 500, "No such htable");
+		return;
+	}
+
+	ht_del_cell(ht, &keyname);
+}
 
 static void  htable_rpc_dump(rpc_t* rpc, void* c)
 {
@@ -568,6 +624,7 @@ error:
 
 rpc_export_t htable_rpc[] = {
 	{"htable.dump", htable_rpc_dump, htable_dump_doc, 0},
+	{"htable.delete", htable_rpc_delete, htable_delete_doc, 0},
 	{0, 0, 0, 0}
 };