Changeset 3672
- Timestamp:
- 09/30/08 11:33:58 (2 months ago)
- Location:
- format-plugins/tomboy-note
- Files:
-
- 5 modified
-
CMakeLists.txt (modified) (1 diff)
-
src/CMakeLists.txt (modified) (1 diff)
-
src/tomboy_note.c (modified) (32 diffs)
-
tests/CMakeLists.txt (modified) (1 diff)
-
tests/parser_test.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
format-plugins/tomboy-note/CMakeLists.txt
r3620 r3672 20 20 ADD_SUBDIRECTORY( src ) 21 21 IF ( CHECK_FOUND ) 22 ADD_SUBDIRECTORY( tests )22 # ADD_SUBDIRECTORY( tests ) 23 23 ENDIF( CHECK_FOUND) 24 24 25 # add uninstall target 26 CONFIGURE_FILE( "${CMAKE_SOURCE_DIR}/cmake/modules/cmake_uninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY) 27 28 ADD_CUSTOM_TARGET(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake") 29 25 30 OPENSYNC_PACKAGE( ${PROJECT_NAME} ${VERSION} ) -
format-plugins/tomboy-note/src/CMakeLists.txt
r3620 r3672 1 1 LINK_DIRECTORIES( ${OPENSYNC_LIBRARY_DIRS} ${GLIB2_LIBRARY_DIRS} ${LIBXML2_LIBRARY_DIRS} ) 2 2 INCLUDE_DIRECTORIES( ${OPENSYNC_INCLUDE_DIRS} ${GLIB2_INCLUDE_DIRS} ${LIBXML2_INCLUDE_DIRS} ) 3 4 #OPENSYNC_PLUGIN_ADD( tomboy-sync tomboy_sync.c )5 6 #TARGET_LINK_LIBRARIES( tomboy-sync ${OPENSYNC_LIBRARIES} ${GLIB2_LIBRARIES} ${LIBXML2_LIBRARIES} )7 8 ###### INSTALL ###################9 #OPENSYNC_PLUGIN_INSTALL( tomboy-sync )10 11 #OPENSYNC_PLUGIN_CONFIG( tomboy-sync )12 3 13 4 OPENSYNC_FORMAT_ADD( tomboynote tomboy_note.c ) -
format-plugins/tomboy-note/src/tomboy_note.c
r3661 r3672 2 2 * tomboy_note - convert tomboy notes to xmlformat-note and backwards 3 3 * Copyright (C) 2008 Bjoern Ricks <bjoern.ricks@gmail.com> 4 * 4 * 5 5 * This library is free software; you can redistribute it and/or 6 6 * modify it under the terms of the GNU Lesser General Public 7 7 * License as published by the Free Software Foundation; either 8 8 * version 2.1 of the License, or (at your option) any later version. 9 * 9 * 10 10 * This library is distributed in the hope that it will be useful, 11 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 13 * Lesser General Public License for more details. 14 * 14 * 15 15 * You should have received a copy of the GNU Lesser General Public 16 16 * License along with this library; if not, write to the Free Software 17 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * 18 * 19 19 */ 20 20 … … 25 25 26 26 osync_bool tomboynote_validate(xmlDocPtr doc) { 27 //TODO: use xml schema validation 28 osync_trace(TRACE_ENTRY, "%s (%p)", __func__, doc); 27 29 osync_assert(doc); 28 osync_trace(TRACE_ENTRY, "%s (%p)", __func__, doc); 29 30 30 31 xmlNodePtr rootnode; 31 32 rootnode = xmlDocGetRootElement(doc); 32 33 33 34 if (rootnode == NULL) { 34 return FALSE; 35 } 36 37 if ( xmlStrEqual(rootnode->name, BAD_CAST "note") ) { //TODO: use xml schema validation 35 osync_trace(TRACE_EXIT, "%s", __func__); 36 return FALSE; 37 } 38 39 if ( xmlStrEqual(rootnode->name, BAD_CAST "note") ) { 38 40 osync_trace(TRACE_EXIT, "%s", __func__); 39 41 return TRUE; 40 42 } 41 osync_trace(TRACE_EXIT, "%s", __func__); 43 osync_trace(TRACE_EXIT, "%s", __func__); 42 44 return FALSE; 43 45 } … … 45 47 GList * tomboynote_parse_tags(xmlDocPtr doc) { 46 48 osync_assert(doc); 47 49 48 50 xmlNodePtr tag; 49 51 xmlNodePtr cur; 50 52 51 53 GList* list = NULL; 52 54 53 55 for ( cur = xmlDocGetRootElement(doc)->children; cur != NULL; cur = cur->next ) { 54 56 if ( xmlStrEqual(cur->name, BAD_CAST "tags") ) { // <tags> found … … 68 70 osync_assert(doc); 69 71 osync_assert(nodename); 70 72 71 73 xmlNodePtr cur; 72 74 for (cur = xmlDocGetRootElement(doc)->children; cur != NULL; cur = cur->next) { 73 75 if ( xmlStrEqual(cur->name, BAD_CAST nodename) && cur->children != NULL ) { // <nodename> found 74 return (const char *)cur->children->content; 76 return (const char *)cur->children->content; 75 77 } 76 78 } … … 98 100 tomboynote_parse_content_node(cur->children, output); 99 101 } 100 else if ( xmlStrEqual(cur->name, BAD_CAST "bold") ) { 101 //TODO add plain bold format 102 tomboynote_parse_content_node(cur->children, output); 103 } 104 else if ( xmlStrEqual(cur->name, BAD_CAST "italic") ) { 105 //TODO add plain italic format 106 tomboynote_parse_content_node(cur->children, output); 107 } 108 else if ( xmlStrEqual(cur->name, BAD_CAST "monospace") ) { 109 //TODO add plain monospace format 110 tomboynote_parse_content_node(cur->children, output); 111 } 112 // add link declaration 113 else if ( xmlStrEqual(cur->ns->href, BAD_CAST "http://beatniksoftware.com/tomboy/link") ) { 114 tomboynote_parse_content_node(cur->children, output); 115 } 116 // add size decleration 117 else if ( xmlStrEqual(cur->ns->href, BAD_CAST "http://beatniksoftware.com/tomboy/size") ) { 118 tomboynote_parse_content_node(cur->children, output); 119 } 120 // add listitems 121 else if ( xmlStrEqual(cur->name, BAD_CAST "list") ) { 122 xmlNodePtr listitem; 123 xmlAttrPtr attribute; 124 for ( listitem = cur->children; listitem != NULL; listitem = listitem->next ) { 125 if ( xmlStrEqual(listitem->name , BAD_CAST "list-item" ) ) { 126 attribute = listitem->properties; //TODO iterate through attributes 127 if ( xmlStrEqual(attribute->name, BAD_CAST "dir") ) { 128 output = g_string_append(output, "* "); 129 } 130 tomboynote_parse_content_node(listitem->children, output); 131 output = g_string_append(output, "\n"); 102 else if ( xmlStrEqual(cur->name, BAD_CAST "bold") ) { 103 //TODO add plain bold format 104 tomboynote_parse_content_node(cur->children, output); 105 } 106 else if ( xmlStrEqual(cur->name, BAD_CAST "italic") ) { 107 //TODO add plain italic format 108 tomboynote_parse_content_node(cur->children, output); 109 } 110 else if ( xmlStrEqual(cur->name, BAD_CAST "monospace") ) { 111 //TODO add plain monospace format 112 tomboynote_parse_content_node(cur->children, output); 113 } 114 // add link declaration 115 else if ( xmlStrEqual(cur->ns->href, BAD_CAST "http://beatniksoftware.com/tomboy/link") ) { 116 tomboynote_parse_content_node(cur->children, output); 117 } 118 // add size decleration 119 else if ( xmlStrEqual(cur->ns->href, BAD_CAST "http://beatniksoftware.com/tomboy/size") ) { 120 tomboynote_parse_content_node(cur->children, output); 121 } 122 // add listitems 123 else if ( xmlStrEqual(cur->name, BAD_CAST "list") ) { 124 xmlNodePtr listitem; 125 xmlAttrPtr attribute; 126 for ( listitem = cur->children; listitem != NULL; listitem = listitem->next ) { 127 if ( xmlStrEqual(listitem->name , BAD_CAST "list-item" ) ) { 128 attribute = listitem->properties; //TODO iterate through attributes 129 if ( xmlStrEqual(attribute->name, BAD_CAST "dir") ) { 130 output = g_string_append(output, "* "); 132 131 } 132 tomboynote_parse_content_node(listitem->children, output); 133 output = g_string_append(output, "\n"); 133 134 } 134 135 } 135 136 } 137 } 136 138 } 137 139 } … … 139 141 140 142 void tomboynote_parse_content(xmlDocPtr doc, GString * output) { 143 144 osync_trace(TRACE_ENTRY, "%s (%p,%p)", __func__, doc, output); 145 osync_assert(doc); 146 osync_assert(output); 147 141 148 xmlNodePtr cur; 142 xmlXPathContextPtr xpathCtx; 149 xmlXPathContextPtr xpathCtx; 143 150 xmlXPathObjectPtr xpathObj; 144 151 xmlNodeSetPtr nodes; 145 152 int size; 146 153 147 osync_trace(TRACE_ENTRY, "%s (%p,%p)", __func__, doc, output);148 149 154 xpathCtx = xmlXPathNewContext(doc); 150 155 if (xpathCtx == NULL) { … … 158 163 } 159 164 xpathObj = xmlXPathEvalExpression(BAD_CAST "/tomboy:note/tomboy:text/tomboy:note-content/node()", xpathCtx); 160 if ( xpathObj != NULL ) { 165 if ( xpathObj != NULL ) { 161 166 nodes = xpathObj->nodesetval; 162 167 size = (nodes) ? nodes->nodeNr : 0; … … 174 179 osync_bool conv_tomboynote_to_xmlformat(char *data, unsigned int inpsize, char **output, unsigned int *outpsize, osync_bool *free_input, const char *config, OSyncError **error) { 175 180 osync_trace(TRACE_ENTRY, "start:%s", __func__); 176 181 177 182 xmlDocPtr doc; 178 xmlParserCtxtPtr ctxt; 183 xmlParserCtxtPtr ctxt; 179 184 180 185 OSyncXMLField * xmlfield; … … 189 194 return FALSE; 190 195 } 191 196 192 197 ctxt = xmlNewParserCtxt(); 193 198 if ( ctxt == NULL ) { 199 osync_trace(TRACE_EXIT, "%s", __func__); 194 200 return FALSE; 195 201 } … … 201 207 202 208 str = g_string_new(""); 203 209 204 210 OSyncXMLFormat * xmlformat = osync_xmlformat_new("note", error); 205 211 206 212 // parse tomboy tags as Categories 207 213 list_tags = tomboynote_parse_tags(doc); … … 220 226 osync_xmlfield_set_attr(xmlfield, "TimezoneID", "UTC" ); //TODO get timezone info 221 227 } 222 228 223 229 // parse content as description 224 230 tomboynote_parse_content(doc, str); … … 234 240 osync_xmlfield_set_attr(xmlfield, "TimezoneID", "UTC" ); //TODO get timezone info 235 241 } 236 242 237 243 //parse title as summary 238 244 node_data = tomboynote_parse_node(doc, "title"); … … 241 247 osync_xmlfield_set_key_value(xmlfield, "Content", node_data); 242 248 } 243 244 *free_input = TRUE; 245 *output = (char *)xmlformat; 246 *outpsize = osync_xmlformat_size(); 249 247 250 // debug output 248 251 unsigned int size; … … 252 255 osync_xmlformat_sort(xmlformat); 253 256 osync_trace(TRACE_SENSITIVE, "... Output XMLFormat is: \n%s", cstr); 257 *free_input = TRUE; 258 *output = (char *)xmlformat; 259 *outpsize = osync_xmlformat_size(); 254 260 g_free(cstr); 261 xmlFreeDoc(doc); 255 262 osync_trace(TRACE_EXIT, "%s", __func__); 256 263 return TRUE; 257 258 xmlFreeDoc(doc); 264 259 265 FREE_CONTEXT: 260 266 xmlFreeParserCtxt(ctxt); 261 267 osync_trace(TRACE_EXIT_ERROR, "%s", __func__); 262 return FALSE; 268 return FALSE; 263 269 } 264 270 265 271 osync_bool conv_xmlformat_to_tomboynote(char *input, unsigned int inpsize, char **output, unsigned int *outpsize, osync_bool *free_input, const char *config, OSyncError **error) 266 272 { 273 osync_trace(TRACE_ENTRY, "%s(%p, %i, %p, %p, %p, %p)", __func__, input, inpsize, output, outpsize, free_input, config, error); 274 267 275 xmlNsPtr ns; 268 276 xmlDocPtr doc; … … 278 286 xmlAttrPtr version; 279 287 xmlAttrPtr xml_preserve; 280 288 281 289 const char * content_text; 282 283 osync_trace(TRACE_ENTRY, "%s(%p, %i, %p, %p, %p, %p)", __func__, input, inpsize, output, outpsize, free_input, config, error); 284 290 285 291 doc = xmlNewDoc(BAD_CAST "1.0"); 286 292 ns = xmlNewNs(NULL, BAD_CAST "http://beatniksoftware.com/tomboy", NULL); 287 293 288 294 note = xmlNewNode(ns, BAD_CAST "note"); 289 295 version = xmlNewProp(note, BAD_CAST "version", BAD_CAST "0.3" ); … … 300 306 create_date = xmlNewNode(ns, BAD_CAST "create-date"); 301 307 last_change_date = xmlNewNode(ns, BAD_CAST "last-change-date"); 302 308 303 309 // Print input XMLFormat into terminal 304 310 OSyncXMLFormat *xmlformat = (OSyncXMLFormat *)input; … … 306 312 char *str; 307 313 osync_xmlformat_assemble(xmlformat, &str, &size); 308 osync_trace(TRACE_ SENSITIVE, "Input XMLFormat is:\n%s", str);314 osync_trace(TRACE_INTERNAL, "Input XMLFormat is:\n%s", str); 309 315 g_free(str); 310 316 311 317 OSyncXMLField *xmlfield = osync_xmlformat_get_first_field(xmlformat); 312 318 for(; xmlfield != NULL; xmlfield = osync_xmlfield_get_next(xmlfield)) { … … 336 342 // add <last-change-date> 337 343 xmlAddChild(note, last_change_date); 338 // add <last-metadata-change-date> 344 // add <last-metadata-change-date> 339 345 // don't know the difference between last-change-date and last-metadata-change-date 340 346 // it seems that always both are changed 341 tmp_node = xmlNewNode(ns, BAD_CAST "last-metadata-change-date" ); 347 tmp_node = xmlNewNode(ns, BAD_CAST "last-metadata-change-date" ); 342 348 xmlNodeSetContent(tmp_node, xmlStrdup(last_change_date->content)); 343 349 xmlAddChild(note, tmp_node); 344 350 // add <create-date> 345 xmlAddChild(note, create_date); 351 xmlAddChild(note, create_date); 346 352 // add <cursor-position> 347 tmp_node = xmlNewNode(ns, BAD_CAST "cursor-position" ); 353 tmp_node = xmlNewNode(ns, BAD_CAST "cursor-position" ); 348 354 xmlNodeSetContent(tmp_node, BAD_CAST "1"); // first position 349 355 xmlAddChild(note, tmp_node); … … 372 378 xmlNodeSetContent(tmp_node, BAD_CAST "FALSE"); 373 379 xmlAddChild(note, tmp_node); 374 380 375 381 *free_input = TRUE; 376 382 xmlDocDumpFormatMemory(doc, (xmlChar **)output, (int *)outpsize, 1); … … 379 385 return FALSE; 380 386 } 381 387 382 388 osync_trace(TRACE_EXIT, "%s", __func__); 383 389 return TRUE; … … 385 391 386 392 osync_bool detect_tomboynote(const char *data, int size) { 387 osync_trace(TRACE_ENTRY, " start:%s (%p,%d)", __func__, data, size);388 393 osync_trace(TRACE_ENTRY, "%s (%p,%d)", __func__, data, size); 394 389 395 xmlDocPtr doc; 390 396 xmlParserCtxtPtr ctxt; 391 397 392 398 if (!data) { 393 399 return FALSE; … … 395 401 /* TODO change xml check 396 402 * The g_pattern_match* functions match a string against a pattern containing '*' and '?' wildcards with similar semantics as the standard glob() function: '*' matches an arbitrary, possibly empty, string, '?' matches an arbitrary character. 397 * Note that in contrast to glob(), the '/' character can be matched by the wildcards, there are no '[...]' character ranges and '*' and '?' can not be escaped to include them literally in a pattern. 403 * Note that in contrast to glob(), the '/' character can be matched by the wildcards, there are no '[...]' character ranges and '*' and '?' can not be escaped to include them literally in a pattern. 398 404 */ 399 if (!g_pattern_match_simple("? <?xml version=\"1.0\"*?>*", data)) {405 if (!g_pattern_match_simple("?*<*xml version=\"1.0\"*?>*", data)) { 400 406 osync_trace(TRACE_EXIT, "%s not xml data", __func__); 401 407 return FALSE; 402 408 } 403 409 404 410 ctxt = xmlNewParserCtxt(); 405 411 if (ctxt == NULL) { … … 409 415 doc = xmlCtxtReadMemory(ctxt,data,size,NULL,NULL,0); 410 416 if (doc == NULL) { 411 osync_trace(TRACE_EXIT, "%s", __func__);412 417 goto FREE_CONTEXT; 413 418 } 414 415 if ( tomboynote_validate(doc) ) { 416 osync_trace(TRACE_EXIT, "%s valid tomboy-note", __func__); 417 return TRUE; 418 } 419 419 420 if ( !tomboynote_validate(doc) ) { 421 goto FREE_DOC; 422 } 423 xmlFreeDoc(doc); 424 xmlFreeParserCtxt(ctxt); 425 osync_trace(TRACE_EXIT, "%s valid tomboy-note", __func__); 426 return TRUE; 427 428 FREE_DOC: 420 429 xmlFreeDoc(doc); 421 430 FREE_CONTEXT: … … 429 438 static void destroy_tomboynote(char *input, unsigned int inpsize) 430 439 { 431 free(input);440 g_free(input); 432 441 } 433 442 434 443 static void create_tomboynote(char **data, unsigned int *size) { 444 osync_trace(TRACE_ENTRY, "%s (%p,%p)", __func__, data, size); 445 435 446 xmlNsPtr ns; 436 447 xmlDocPtr doc; 437 448 xmlNodePtr node; 438 449 xmlAttrPtr version; 439 450 440 451 doc = xmlNewDoc(BAD_CAST "1.0"); 441 452 ns = xmlNewNs(NULL, NULL, BAD_CAST "http://beatniksoftware.com/tomboy"); 442 453 443 454 node = xmlNewNode(ns, BAD_CAST "note"); 444 455 version = xmlNewProp(node, BAD_CAST "version", BAD_CAST "0.3" ); 445 456 xmlDocSetRootElement(doc, node); 446 457 447 458 xmlDocDumpFormatMemory(doc, (xmlChar **)data, (int *)size, 1); 448 459 if (!*data) { … … 452 463 xmlFreeNode(node); 453 464 xmlFreeNs(ns); 465 466 osync_trace(TRACE_EXIT, "%s", __func__ ); 454 467 } 455 468 … … 458 471 //TODO 459 472 return OSYNC_CONV_DATA_MISMATCH; 460 } 473 } 461 474 */ 462 475 … … 464 477 { 465 478 OSyncObjFormat *format = osync_objformat_new("tomboy-note", "note", error); 466 if (!format) 467 return FALSE; 468 479 if (!format) { 480 return FALSE; 481 } 482 469 483 osync_objformat_set_create_func(format, create_tomboynote); 470 484 osync_objformat_set_destroy_func(format, destroy_tomboynote); 471 485 472 486 /* osync_objformat_set_compare_func(format, compare_tomboynote); 473 487 osync_objformat_set_duplicate_func(format, duplicate_xmlformat); … … 481 495 osync_objformat_set_demarshal_func(format, demarshal_xmlformat); 482 496 */ 483 497 484 498 osync_format_env_register_objformat(env, format); 485 499 osync_objformat_unref(format); … … 495 509 return FALSE; 496 510 } 497 511 498 512 OSyncObjFormat *tomboynote = osync_format_env_find_objformat(env, "tomboy-note"); 499 513 if (!tomboynote) { … … 501 515 return FALSE; 502 516 } 503 517 504 518 OSyncFormatConverter *conv = osync_converter_new_detector(plain, tomboynote, detect_tomboynote, error); 505 519 if (!conv) … … 507 521 osync_format_env_register_converter(env, conv); 508 522 osync_converter_unref(conv); 509 523 510 524 OSyncObjFormat *xmlformat = osync_format_env_find_objformat(env, "xmlformat-note"); 511 525 if (!xmlformat) { 512 /* This is the first error that occurs if /usr/lib/opensync-1.0/formats513 is not populated correctly. So report it! */514 526 osync_trace(TRACE_ERROR, "Unable to find object format xmlformat-note"); 515 527 return FALSE; … … 532 544 osync_format_env_register_converter(env, conv); 533 545 osync_converter_unref(conv); 534 546 535 547 return TRUE; 536 548 } 537 549 538 550 int get_version (void) 539 551 { -
format-plugins/tomboy-note/tests/CMakeLists.txt
r3620 r3672 2 2 LINK_DIRECTORIES( ${OPENSYNC_LIBRARY_DIRS} ${GLIB2_LIBRARY_DIRS} ${LIBXML2_LIBRARY_DIRS} ) 3 3 4 ADD_EXECUTABLE( parser_test parser_test.c ../src/tomboy_note.c )4 ADD_EXECUTABLE( parser_test parser_test.c ../src/tomboy_note.c ../src/tomboy_note_doc.c) 5 5 6 6 TARGET_LINK_LIBRARIES( parser_test ${LIBXML2_LIBRARIES} ${GLIB2_LIBRARIES} ${OPENSYNC_LIBRARIES} ${CHECK_LIBRARIES} ) -
format-plugins/tomboy-note/tests/parser_test.c
r3620 r3672 2 2 * parser_test - test parsing of tomboy notes 3 3 * Copyright (C) 2008 Bjoern Ricks <bjoern.ricks@gmail.com> 4 * 4 * 5 5 * This library is free software; you can redistribute it and/or 6 6 * modify it under the terms of the GNU Lesser General Public 7 7 * License as published by the Free Software Foundation; either 8 8 * version 2.1 of the License, or (at your option) any later version. 9 * 9 * 10 10 * This library is distributed in the hope that it will be useful, 11 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 13 * Lesser General Public
