diff --git a/daemon/load.h b/daemon/load.h
index bb93b880..0722ac8a 100644
--- a/daemon/load.h
+++ b/daemon/load.h
@@ -51,6 +51,8 @@
#define PARSE_CONTEXT_ROOMS 15
#define PARSE_CONTEXT_ROOM 16
#define PARSE_CONTEXT_PROJECT 17
+#define PARSE_CONTEXT_DESCRIPTION 18
+#define PARSE_CONTEXT_NOTES 19
#define MAX_STACK_DEPTH 10
#define MAX_DATA_SIZE 10240
diff --git a/daemon/room_load.c b/daemon/room_load.c
index 5de8ea4d..787a0347 100644
--- a/daemon/room_load.c
+++ b/daemon/room_load.c
@@ -51,7 +51,9 @@ static void callback_chrdata(void * data, const XML_Char * s, int len)
if (context_ptr->element[context_ptr->depth] == PARSE_CONTEXT_PARAMETER ||
context_ptr->element[context_ptr->depth] == PARSE_CONTEXT_KEY ||
- context_ptr->element[context_ptr->depth] == PARSE_CONTEXT_APPLICATION)
+ context_ptr->element[context_ptr->depth] == PARSE_CONTEXT_APPLICATION ||
+ context_ptr->element[context_ptr->depth] == PARSE_CONTEXT_DESCRIPTION ||
+ context_ptr->element[context_ptr->depth] == PARSE_CONTEXT_NOTES)
{
if (context_ptr->data_used + len >= sizeof(context_ptr->data))
{
@@ -119,6 +121,38 @@ static void callback_elstart(void * data, const char * el, const char ** attr)
return;
}
+ if (strcmp(el, "description") == 0)
+ {
+ //log_info("");
+
+ if (room_ptr->project_description != NULL)
+ {
+ log_error("project description is already set");
+ context_ptr->error = XML_TRUE;
+ return;
+ }
+
+ context_ptr->element[++context_ptr->depth] = PARSE_CONTEXT_DESCRIPTION;
+ context_ptr->data_used = 0;
+ return;
+ }
+
+ if (strcmp(el, "notes") == 0)
+ {
+ //log_info("");
+
+ if (room_ptr->project_notes != NULL)
+ {
+ log_error("project notes are already set");
+ context_ptr->error = XML_TRUE;
+ return;
+ }
+
+ context_ptr->element[++context_ptr->depth] = PARSE_CONTEXT_NOTES;
+ context_ptr->data_used = 0;
+ return;
+ }
+
if (strcmp(el, "jack") == 0)
{
//log_info("");
@@ -631,6 +665,32 @@ static void callback_elend(void * data, const char * el)
context_ptr->error = XML_TRUE;
}
}
+ else if (context_ptr->element[context_ptr->depth] == PARSE_CONTEXT_DESCRIPTION)
+ {
+ context_ptr->data[unescape(context_ptr->data, context_ptr->data_used, context_ptr->data)] = 0;
+ //log_info("");
+ //log_info("[%s]", context_ptr->data);
+
+ ASSERT(room_ptr->project_description == NULL);
+ room_ptr->project_description = strdup(context_ptr->data);
+ if (room_ptr->project_description == NULL)
+ {
+ ladish_notify_simple(LADISH_NOTIFY_URGENCY_HIGH, "Project description failed to load", LADISH_CHECK_LOG_TEXT);
+ }
+ }
+ else if (context_ptr->element[context_ptr->depth] == PARSE_CONTEXT_NOTES)
+ {
+ context_ptr->data[unescape(context_ptr->data, context_ptr->data_used, context_ptr->data)] = 0;
+ //log_info("");
+ //log_info("[%s]", context_ptr->data);
+
+ ASSERT(room_ptr->project_notes == NULL);
+ room_ptr->project_notes = strdup(context_ptr->data);
+ if (room_ptr->project_notes == NULL)
+ {
+ ladish_notify_simple(LADISH_NOTIFY_URGENCY_HIGH, "Project notes failed to load", LADISH_CHECK_LOG_TEXT);
+ }
+ }
context_ptr->depth--;
diff --git a/daemon/room_save.c b/daemon/room_save.c
index 2d1d3e4f..151fbc25 100644
--- a/daemon/room_save.c
+++ b/daemon/room_save.c
@@ -49,7 +49,6 @@ static bool ladish_room_save_project_do(struct ladish_room * room_ptr)
char uuid_str[37];
char * filename;
char * bak_filename;
- char * escaped_project_name;
int fd;
log_info("Saving project '%s' in room '%s' to '%s'", room_ptr->project_name, room_ptr->name, room_ptr->project_dir);
@@ -68,22 +67,13 @@ static bool ladish_room_save_project_do(struct ladish_room * room_ptr)
uuid_generate(room_ptr->project_uuid); /* TODO: the uuid should be changed on "save as" but not on "rename" */
uuid_unparse(room_ptr->project_uuid, uuid_str);
- escaped_project_name = malloc(max_escaped_length(strlen(room_ptr->project_name)) + 1);
- if (escaped_project_name == NULL)
- {
- log_error("malloc() failed to allocate buffer for storing escaped project name");
- goto exit;
- }
-
filename = catdup(room_ptr->project_dir, LADISH_PROJECT_FILENAME);
if (filename == NULL)
{
log_error("catdup() failed to compose project xml filename");
- goto free_escaped_project_name;
+ goto exit;
}
- escape_simple(room_ptr->project_name, escaped_project_name);
-
bak_filename = catdup(filename, ".bak");
if (bak_filename == NULL)
{
@@ -138,7 +128,7 @@ static bool ladish_room_save_project_do(struct ladish_room * room_ptr)
goto close;
}
- if (!ladish_write_string(fd, escaped_project_name))
+ if (!ladish_write_string_escape(fd, room_ptr->project_name))
{
return false;
}
@@ -158,6 +148,42 @@ static bool ladish_room_save_project_do(struct ladish_room * room_ptr)
goto close;
}
+ if (room_ptr->project_description != NULL)
+ {
+ if (!ladish_write_indented_string(fd, 1, ""))
+ {
+ goto close;
+ }
+
+ if (!ladish_write_string_escape(fd, room_ptr->project_description))
+ {
+ goto close;
+ }
+
+ if (!ladish_write_string(fd, "\n"))
+ {
+ goto close;
+ }
+ }
+
+ if (room_ptr->project_notes != NULL)
+ {
+ if (!ladish_write_indented_string(fd, 1, ""))
+ {
+ goto close;
+ }
+
+ if (!ladish_write_string_escape(fd, room_ptr->project_notes))
+ {
+ goto close;
+ }
+
+ if (!ladish_write_string(fd, "\n"))
+ {
+ goto close;
+ }
+ }
+
if (!ladish_write_indented_string(fd, 1, "\n"))
{
goto close;
@@ -218,8 +244,6 @@ free_bak_filename:
free(bak_filename);
free_filename:
free(filename);
-free_escaped_project_name:
- free(escaped_project_name);
exit:
return ret;
}
diff --git a/daemon/save.c b/daemon/save.c
index 16a1d53d..db00f90b 100644
--- a/daemon/save.c
+++ b/daemon/save.c
@@ -71,6 +71,27 @@ bool ladish_write_indented_string(int fd, int indent, const char * string)
return true;
}
+bool ladish_write_string_escape(int fd, const char * string)
+{
+ bool ret;
+ char * escaped_buffer;
+
+ escaped_buffer = malloc(max_escaped_length(strlen(string)));
+ if (escaped_buffer == NULL)
+ {
+ log_error("malloc() failed to allocate buffer for escaped string");
+ return false;
+ }
+
+ escape_simple(string, escaped_buffer);
+
+ ret = ladish_write_string(fd, escaped_buffer);
+
+ free(escaped_buffer);
+
+ return ret;
+}
+
#define fd (((struct ladish_write_context *)context)->fd)
#define indent (((struct ladish_write_context *)context)->indent)
diff --git a/daemon/save.h b/daemon/save.h
index e4ace455..77c9acae 100644
--- a/daemon/save.h
+++ b/daemon/save.h
@@ -43,6 +43,7 @@ struct ladish_write_context
bool ladish_write_string(int fd, const char * string);
bool ladish_write_indented_string(int fd, int indent, const char * string);
+bool ladish_write_string_escape(int fd, const char * string);
bool ladish_write_dict(int fd, int indent, ladish_dict_handle dict);
bool ladish_write_vgraph(int fd, int indent, ladish_graph_handle vgraph, ladish_app_supervisor_handle app_supervisor);
bool ladish_write_room_link_ports(int fd, int indent, ladish_room_handle room);