From: <svn...@op...> - 2009-09-18 12:09:51
|
Author: bricks Date: Fri Sep 18 14:09:31 2009 New Revision: 5806 URL: http://www.opensync.org/changeset/5806 Log: added some error checks for tomboy-note osync_xmlfield_set_key_value doesn't create a xml tag if value is "" Modified: format-plugins/tomboy-note/src/tomboy_note.c format-plugins/tomboy-note/src/tomboy_note_internal.h format-plugins/tomboy-note/tests/parser_test.c Modified: format-plugins/tomboy-note/src/tomboy_note.c ============================================================================== --- format-plugins/tomboy-note/src/tomboy_note.c Fri Sep 18 10:44:28 2009 (r5805) +++ format-plugins/tomboy-note/src/tomboy_note.c Fri Sep 18 14:09:31 2009 (r5806) @@ -223,7 +223,7 @@ } } -void tomboynote_parse_content(xmlDocPtr doc, GString * output) { +void tomboynote_parse_content(xmlDocPtr doc, GString * output, OSyncError **error) { osync_trace(TRACE_ENTRY, "%s (%p,%p)", __func__, doc, output); osync_assert(doc); @@ -237,13 +237,12 @@ xpathCtx = xmlXPathNewContext(doc); if (xpathCtx == NULL) { - osync_trace(TRACE_EXIT, "%s", __func__); - return; + osync_error_set(error, OSYNC_ERROR_GENERIC, "could not initialize xml xpath context for tomboy-format"); + goto error; } if( xmlXPathRegisterNs(xpathCtx, BAD_CAST "tomboy", BAD_CAST "http://beatniksoftware.com/tomboy") != 0 ) { - xmlXPathFreeContext(xpathCtx); - osync_trace(TRACE_EXIT, "%s", __func__); - return; + osync_error_set(error, OSYNC_ERROR_GENERIC, "could not register xml namespace for tomboy-format"); + goto error_free_xpath; } xpathObj = xmlXPathEvalExpression(BAD_CAST "/tomboy:note/tomboy:text/tomboy:note-content/node()", xpathCtx); if ( xpathObj != NULL ) { @@ -255,8 +254,20 @@ tomboynote_parse_content_node(cur, output); } } + else { + osync_error_set(error, OSYNC_ERROR_GENERIC, "could not apply xml xpath for tomboy-format. couldn't find note-content tag."); + goto error_free_xpath; + } + xmlXPathFreeContext(xpathCtx); osync_trace(TRACE_EXIT, "%s", __func__); + return; + +error_free_xpath: + xmlXPathFreeContext(xpathCtx); +error: + osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); + return; } // converter functions @@ -277,7 +288,9 @@ if (!data) { return FALSE; } - + + osync_trace(TRACE_SENSITIVE, "... Input tomboy-note is: \n%s", data); + ctxt = xmlNewParserCtxt(); if ( ctxt == NULL ) { osync_trace(TRACE_EXIT, "%s", __func__); @@ -311,9 +324,17 @@ } // parse content as description - tomboynote_parse_content(doc, str); + tomboynote_parse_content(doc, str, error); + char * content = str->str; + /* sanity check + /* if content is null or strlen is 0 then osync_xmlfield_set_key_value + * doesn't create an new xml tag + */ + if (!content || strlen(content) == 0 ) { + content = " "; + } xmlfield = osync_xmlfield_new(xmlformat, "Description", error); - osync_xmlfield_set_key_value(xmlfield, "Content", str->str, error); + osync_xmlfield_set_key_value(xmlfield, "Content", content, error); //parse last-change-date as lastmodified node_data = tomboynote_parse_node(doc, "last-change-date"); @@ -395,8 +416,8 @@ unsigned int size; char *str; osync_xmlformat_assemble(xmlformat, &str, &size, error); - osync_trace(TRACE_INTERNAL, "Input XMLFormat is:\n%s", str); -// osync_trace(TRACE_SENSITIVE, "Input XMLFormat is:\n%s", str); +// osync_trace(TRACE_INTERNAL, "Input XMLFormat is:\n%s", str); + osync_trace(TRACE_SENSITIVE, "Input XMLFormat is:\n%s", str); g_free(str); //TODO: always free old content_text @@ -480,6 +501,8 @@ goto error; } + osync_trace(TRACE_SENSITIVE, "... Output tomboy-note is:\n%s", *output); + osync_trace(TRACE_EXIT, "%s", __func__); return TRUE; error: Modified: format-plugins/tomboy-note/src/tomboy_note_internal.h ============================================================================== --- format-plugins/tomboy-note/src/tomboy_note_internal.h Fri Sep 18 10:44:28 2009 (r5805) +++ format-plugins/tomboy-note/src/tomboy_note_internal.h Fri Sep 18 14:09:31 2009 (r5806) @@ -34,7 +34,7 @@ }; void tomboynote_parse_content_node(xmlNodePtr node, GString * output); -void tomboynote_parse_content(xmlDocPtr doc, GString * output); +void tomboynote_parse_content(xmlDocPtr doc, GString * output, OSyncError **error); const char * tomboynote_parse_node(xmlDocPtr doc, const char * nodename); GList * tomboynote_parse_tags(xmlDocPtr doc); Modified: format-plugins/tomboy-note/tests/parser_test.c ============================================================================== --- format-plugins/tomboy-note/tests/parser_test.c Fri Sep 18 10:44:28 2009 (r5805) +++ format-plugins/tomboy-note/tests/parser_test.c Fri Sep 18 14:09:31 2009 (r5806) @@ -86,9 +86,10 @@ START_TEST (tomboynote_test_parse_content) { GString *str; + OSyncError *error = NULL; str = g_string_new(""); - tomboynote_parse_content(good_doc, str); + tomboynote_parse_content(good_doc, str, &error); //printf("Good: len %d %s\n", str->len, str->str ); g_string_free(str,TRUE); |