The unified diff between revisions [a81fe555..] and [879bb490..] is displayed below. It can also be downloaded as a raw diff.

#
# old_revision [a81fe5550c21fa983b4e344e07c29b9cecdf75ea]
# new_revision [879bb490162f7bfef0afc9c96666267f54996591]
#
# patch "src/lsi/abi.h"
#  from [0553ade9748fed1e6808e874fa67020a6dd52a22]
#    to [22ae6181e13640fa9e5388e7e9862a5b98d98d28]
# 
# patch "src/lsi/abispec"
#  from [14bb48cc77b6f36777d424e8a354f629082b14e8]
#    to [258eb50ffcd6396b358fec612b301d4cd65f1884]
# 
# patch "src/lsi/vm.c"
#  from [c29bc86ce0d4170f8a0229735384ea9eea76763f]
#    to [7fbddce92f86fd74d95ad28871274cf4653d9d55]
#
============================================================
--- src/lsi/abi.h	0553ade9748fed1e6808e874fa67020a6dd52a22
+++ src/lsi/abi.h	22ae6181e13640fa9e5388e7e9862a5b98d98d28
@@ -51,3 +51,5 @@ int vm_intfn_sql_query_1s(void);
 int vm_intfn_cmdsocket_prefix(void);
 int vm_intfn_sql_query(void);
 int vm_intfn_sql_query_1s(void);
+int vm_intfn_sql_getvar(void);
+int vm_intfn_sql_setvar(void);
============================================================
--- src/lsi/abispec	14bb48cc77b6f36777d424e8a354f629082b14e8
+++ src/lsi/abispec	258eb50ffcd6396b358fec612b301d4cd65f1884
@@ -41,6 +41,8 @@ function sql_query_1s
 /* NOT_YET function_v sql_query */
 function sql_query
 function sql_query_1s
+function sql_getvar
+function sql_setvar
 
 /*
  * The ABI should be identified by a SHA1 hash of this file
============================================================
--- src/lsi/vm.c	c29bc86ce0d4170f8a0229735384ea9eea76763f
+++ src/lsi/vm.c	7fbddce92f86fd74d95ad28871274cf4653d9d55
@@ -596,6 +596,55 @@ int vm_intfn_sql_query_1s(void)
 	stack_poke(vm_current, 0, result); /* return value */
 	return 1;
 }
+
+int vm_intfn_sql_getvar(void)
+{
+	int len;
+	char buf[VM_STRING_MAX];
+	char query[VM_STRING_MAX];
+	int result;
+
+	len = stack_get(vm_current, 1);
+
+	if (len >= VM_STRING_MAX) {
+		printf("Excessive string length - can't perform query\n");
+		return 1;
+	}
+
+	snprintf(buf, len+1, stack_getstr(vm_current, len, 1));
+	snprintf(query, VM_STRING_MAX, "SELECT value FROM vars WHERE name=\"%s\"", buf);
+
+	sql_query(query, strlen(query), &result);
+
+	/* XXX what to do with an error here? */
+	stack_poke(vm_current, 0, result); /* return value */
+	return 1;
+}
+
+int vm_intfn_sql_setvar(void)
+{
+	int len, val;
+	char buf[VM_STRING_MAX];
+	char query[VM_STRING_MAX];
+	int result;
+
+	val = stack_get(vm_current, 1);
+	len = stack_get(vm_current, 2);
+
+	if (len >= VM_STRING_MAX) {
+		printf("Excessive string length - can't perform query\n");
+		return 1;
+	}
+
+	snprintf(buf, len+1, stack_getstr(vm_current, len, 2));
+	snprintf(query, VM_STRING_MAX, "INSERT OR REPLACE INTO vars VALUES(\"%s\", %d)", buf, val);
+
+	sql_query(query, strlen(query), &result);
+
+	/* XXX what to do with an error here? */
+	stack_poke(vm_current, 0, result); /* return value */
+	return 1;
+}
 #endif
 
 int vm_intfn_beatdetect_read(void)