Index: funcs/func_realtime.c
===================================================================
--- funcs/func_realtime.c	(revision 102238)
+++ funcs/func_realtime.c	(working copy)
@@ -124,6 +124,105 @@
 	return 0;
 }
 
+static int function_realtime_store(struct ast_channel *chan, const char *cmd, char *data, const char *value)
+{
+	int res = 0;
+	char storeid[32];
+	AST_DECLARE_APP_ARGS(args,
+		AST_APP_ARG(family);
+		AST_APP_ARG(field);
+	);
+
+	if (ast_strlen_zero(data)) {
+		ast_log(LOG_WARNING, "Syntax: REALTIME_STORE(family,field) - missing argument!\n");
+		return -1;
+	}
+
+	if (chan)
+		ast_autoservice_start(chan);
+
+	AST_STANDARD_APP_ARGS(args, data);
+
+	res = ast_store_realtime(args.family, args.field, (char *)value, NULL);
+
+	if (res < 0) {
+		ast_log(LOG_WARNING, "Failed to store. Check the debug log for possible data repository related entries.\n");
+	} else {
+		snprintf(storeid, sizeof(storeid), "%d", res);
+		pbx_builtin_setvar_helper(chan, "RTSTOREID", storeid);
+	}
+
+	/* 
+		XXX:
+		If RT engine generates Unique ID for inserted records, it's value is returned in res.
+		It would be nice if we could return it to dialplan, something like this
+		exten => 111,1,Set(ID=${REALTIME_STORE(sip,name)=123})
+	*/
+
+	if (chan)
+		ast_autoservice_stop(chan);
+
+	return 0;
+}
+
+static int function_realtime_readdestroy(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) 
+{
+	struct ast_variable *var, *head;
+	struct ast_str *out;
+	size_t resultslen;
+	int n;
+	AST_DECLARE_APP_ARGS(args,
+		AST_APP_ARG(family);
+		AST_APP_ARG(fieldmatch);
+		AST_APP_ARG(value);
+		AST_APP_ARG(delim1);
+		AST_APP_ARG(delim2);
+	);
+
+	if (ast_strlen_zero(data)) {
+		ast_log(LOG_WARNING, "Syntax: REALTIME_DESTROY(family,fieldmatch[,value[,delim1[,delim2]]]) - missing argument!\n");
+		return -1;
+	}
+
+	AST_STANDARD_APP_ARGS(args, data);
+
+	if (!args.delim1)
+		args.delim1 = ",";
+	if (!args.delim2)
+		args.delim2 = "=";
+
+	if (chan)
+		ast_autoservice_start(chan);
+
+	head = ast_load_realtime_all(args.family, args.fieldmatch, args.value, NULL);
+
+	if (!head) {
+		if (chan)
+			ast_autoservice_stop(chan);
+		return -1;
+	}
+
+	resultslen = 0;
+	n = 0;
+	for (var = head; var; n++, var = var->next)
+		resultslen += strlen(var->name) + strlen(var->value);
+	/* add space for delimiters and final '\0' */
+	resultslen += n * (strlen(args.delim1) + strlen(args.delim2)) + 1;
+
+	out = ast_str_alloca(resultslen);
+	for (var = head; var; var = var->next) {
+		ast_str_append(&out, 0, "%s%s%s%s", var->name, args.delim2, var->value, args.delim1);
+	}
+	ast_copy_string(buf, out->str, len);
+
+	ast_destroy_realtime(args.family, args.fieldmatch, args.value, NULL);
+
+	if (chan)
+		ast_autoservice_stop(chan);
+
+	return 0;
+}
+
 struct ast_custom_function realtime_function = {
 	.name = "REALTIME",
 	.synopsis = "RealTime Read/Write Functions",
@@ -142,14 +241,41 @@
 	.write = function_realtime_write,
 };
 
+struct ast_custom_function realtime_store_function = {
+	.name = "REALTIME_STORE",
+	.synopsis = "RealTime Store Function",
+	.syntax = "REALTIME_STORE(family,field) = value",
+	.desc = "This function will insert a new set of values into the RealTime repository.\n"
+		"If RT engine provides an unique ID of the stored record, REALTIME_STORE(...)=..\n"
+		"creates channel variable named RTSTOREID, which contains value of unique ID.\n",
+	.write = function_realtime_store,
+};
+
+struct ast_custom_function realtime_destroy_function = {
+	.name = "REALTIME_DESTROY",
+	.synopsis = "RealTime Destroy Function",
+	.syntax = "REALTIME_DESTROY(family,fieldmatch[,value[,delim1[,delim2]]])\n",
+	.desc = "This function acts in the same way as REALTIME(....) does, except that\n"
+		"it destroys matched record in RT engine.\n",
+	.read = function_realtime_readdestroy,
+};
+
 static int unload_module(void)
 {
-	return ast_custom_function_unregister(&realtime_function);
+	int res = 0;
+	res |= ast_custom_function_unregister(&realtime_function);
+	res |= ast_custom_function_unregister(&realtime_store_function);
+	res |= ast_custom_function_unregister(&realtime_destroy_function);
+	return res;
 }
 
 static int load_module(void)
 {
-	return ast_custom_function_register(&realtime_function);
+	int res = 0;
+	res |= ast_custom_function_register(&realtime_function);
+	res |= ast_custom_function_register(&realtime_store_function);
+	res |= ast_custom_function_register(&realtime_destroy_function);
+	return res;
 }
 
-AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Read/Write values from a RealTime repository");
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Read/Write/Store/Destroy values from a RealTime repository");
