ladishd: save/load project description and notes
This commit is contained in:
parent
18e317ff4b
commit
dba04d196e
|
@ -51,6 +51,8 @@
|
||||||
#define PARSE_CONTEXT_ROOMS 15
|
#define PARSE_CONTEXT_ROOMS 15
|
||||||
#define PARSE_CONTEXT_ROOM 16
|
#define PARSE_CONTEXT_ROOM 16
|
||||||
#define PARSE_CONTEXT_PROJECT 17
|
#define PARSE_CONTEXT_PROJECT 17
|
||||||
|
#define PARSE_CONTEXT_DESCRIPTION 18
|
||||||
|
#define PARSE_CONTEXT_NOTES 19
|
||||||
|
|
||||||
#define MAX_STACK_DEPTH 10
|
#define MAX_STACK_DEPTH 10
|
||||||
#define MAX_DATA_SIZE 10240
|
#define MAX_DATA_SIZE 10240
|
||||||
|
|
|
@ -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 ||
|
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_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))
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (strcmp(el, "description") == 0)
|
||||||
|
{
|
||||||
|
//log_info("<description>");
|
||||||
|
|
||||||
|
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("<notes>");
|
||||||
|
|
||||||
|
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)
|
if (strcmp(el, "jack") == 0)
|
||||||
{
|
{
|
||||||
//log_info("<jack>");
|
//log_info("<jack>");
|
||||||
|
@ -631,6 +665,32 @@ static void callback_elend(void * data, const char * el)
|
||||||
context_ptr->error = XML_TRUE;
|
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("</description>");
|
||||||
|
//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("</notes>");
|
||||||
|
//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--;
|
context_ptr->depth--;
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,6 @@ static bool ladish_room_save_project_do(struct ladish_room * room_ptr)
|
||||||
char uuid_str[37];
|
char uuid_str[37];
|
||||||
char * filename;
|
char * filename;
|
||||||
char * bak_filename;
|
char * bak_filename;
|
||||||
char * escaped_project_name;
|
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
log_info("Saving project '%s' in room '%s' to '%s'", room_ptr->project_name, room_ptr->name, room_ptr->project_dir);
|
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_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);
|
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);
|
filename = catdup(room_ptr->project_dir, LADISH_PROJECT_FILENAME);
|
||||||
if (filename == NULL)
|
if (filename == NULL)
|
||||||
{
|
{
|
||||||
log_error("catdup() failed to compose project xml filename");
|
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");
|
bak_filename = catdup(filename, ".bak");
|
||||||
if (bak_filename == NULL)
|
if (bak_filename == NULL)
|
||||||
{
|
{
|
||||||
|
@ -138,7 +128,7 @@ static bool ladish_room_save_project_do(struct ladish_room * room_ptr)
|
||||||
goto close;
|
goto close;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ladish_write_string(fd, escaped_project_name))
|
if (!ladish_write_string_escape(fd, room_ptr->project_name))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -158,6 +148,42 @@ static bool ladish_room_save_project_do(struct ladish_room * room_ptr)
|
||||||
goto close;
|
goto close;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (room_ptr->project_description != NULL)
|
||||||
|
{
|
||||||
|
if (!ladish_write_indented_string(fd, 1, "<description>"))
|
||||||
|
{
|
||||||
|
goto close;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ladish_write_string_escape(fd, room_ptr->project_description))
|
||||||
|
{
|
||||||
|
goto close;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ladish_write_string(fd, "</description>\n"))
|
||||||
|
{
|
||||||
|
goto close;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (room_ptr->project_notes != NULL)
|
||||||
|
{
|
||||||
|
if (!ladish_write_indented_string(fd, 1, "<notes>"))
|
||||||
|
{
|
||||||
|
goto close;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ladish_write_string_escape(fd, room_ptr->project_notes))
|
||||||
|
{
|
||||||
|
goto close;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ladish_write_string(fd, "</notes>\n"))
|
||||||
|
{
|
||||||
|
goto close;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!ladish_write_indented_string(fd, 1, "<room>\n"))
|
if (!ladish_write_indented_string(fd, 1, "<room>\n"))
|
||||||
{
|
{
|
||||||
goto close;
|
goto close;
|
||||||
|
@ -218,8 +244,6 @@ free_bak_filename:
|
||||||
free(bak_filename);
|
free(bak_filename);
|
||||||
free_filename:
|
free_filename:
|
||||||
free(filename);
|
free(filename);
|
||||||
free_escaped_project_name:
|
|
||||||
free(escaped_project_name);
|
|
||||||
exit:
|
exit:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,27 @@ bool ladish_write_indented_string(int fd, int indent, const char * string)
|
||||||
return true;
|
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 fd (((struct ladish_write_context *)context)->fd)
|
||||||
#define indent (((struct ladish_write_context *)context)->indent)
|
#define indent (((struct ladish_write_context *)context)->indent)
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@ struct ladish_write_context
|
||||||
|
|
||||||
bool ladish_write_string(int fd, const char * string);
|
bool ladish_write_string(int fd, const char * string);
|
||||||
bool ladish_write_indented_string(int fd, int indent, 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_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_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);
|
bool ladish_write_room_link_ports(int fd, int indent, ladish_room_handle room);
|
||||||
|
|
Loading…
Reference in New Issue