VTY: Introduce common code to add 'description' to objects like BTS

There is now an option to add a human-readable description to objects
that are configured in the VTY.
diff --git a/openbsc/src/vty_interface_cmds.c b/openbsc/src/vty_interface_cmds.c
index 8c78caa..4e5dc29 100644
--- a/openbsc/src/vty_interface_cmds.c
+++ b/openbsc/src/vty_interface_cmds.c
@@ -41,6 +41,23 @@
 		vty_out(vty, "\r");
 }
 
+struct buffer *vty_argv_to_buffer(int argc, const char *argv[], int base)
+{
+	struct buffer *b = buffer_new(NULL, 1024);
+	int i;
+
+	if (!b)
+		return NULL;
+
+	for (i = base; i < argc; i++) {
+		buffer_putstr(b, argv[i]);
+		buffer_putc(b, ' ');
+	}
+	buffer_putc(b, '\0');
+
+	return b;
+}
+
 struct log_target *log_target_create_vty(struct vty *vty)
 {
 	struct log_target *target;
@@ -307,6 +324,52 @@
 	return CMD_SUCCESS;
 }
 
+gDEFUN(cfg_description, cfg_description_cmd,
+	"description .TEXT",
+	"Save human-readable decription of the object\n")
+{
+	char **dptr = vty->index_sub;
+	struct buffer *b;
+
+	if (!dptr) {
+		vty_out(vty, "vty->index_sub == NULL%s", VTY_NEWLINE);
+		return CMD_WARNING;
+	}
+
+	b = vty_argv_to_buffer(argc, argv, 0);
+	if (!b)
+		return CMD_WARNING;
+
+	if (*dptr)
+		talloc_free(*dptr);
+
+	*dptr = talloc_strdup(NULL, buffer_getstr(b));
+
+	buffer_free(b);
+
+	return CMD_SUCCESS;
+}
+
+gDEFUN(cfg_no_description, cfg_no_description_cmd,
+	"no description",
+	NO_STR
+	"Remove description of the object\n")
+{
+	char **dptr = vty->index_sub;
+
+	if (!dptr) {
+		vty_out(vty, "vty->index_sub == NULL%s", VTY_NEWLINE);
+		return CMD_WARNING;
+	}
+
+	if (*dptr) {
+		talloc_free(*dptr);
+		*dptr = NULL;
+	}
+
+	return CMD_SUCCESS;
+}
+
 void openbsc_vty_print_statistics(struct vty *vty, struct gsm_network *net)
 {
 	vty_out(vty, "Channel Requests        : %lu total, %lu no channel%s",