1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
Description: xbel bookmarks:fix session positions save/restore
[bookmarks] xbel did not restore positions. Refs #415
[xbel] Replace ' ' by POSITION_CHAR on load of bookmarks. #415
[xbel] Added <info><metadata ...><elinks:saved-postion ...> #415
Origin: upstream,commit: 145693adf4b64b3a3f62aef5f733f2daf855cc55,
8c407bf688036d73e054ca1306f9de0b1b5cb7a8,
a56de8224c71dc7f27ef72c0d6d927c980646815
Bug: https://github.com/rkd77/elinks/issues/415
Index: elinks/src/bookmarks/backend/xbel.c
===================================================================
--- elinks.orig/src/bookmarks/backend/xbel.c 2026-01-16 02:03:26.191708204 +0100
+++ elinks/src/bookmarks/backend/xbel.c 2026-01-16 02:03:26.187708243 +0100
@@ -232,12 +232,29 @@
secure_fputs(ssi, "</folder>\n\n");
} else if (bm->box_item->type == BI_LEAF) {
-
+ char *pos = strchr(bm->url, POSITION_CHAR);
secure_fputs(ssi, "<bookmark href=\"");
+
+ if (pos) {
+ *pos = '\0';
+ }
print_xml_entities(ssi, bm->url);
secure_fputs(ssi, "\">\n");
-
indentation(ssi, n + 2);
+
+ if (pos) {
+ secure_fputs(ssi, "<info>\n");
+ indentation(ssi, n + 3);
+ secure_fputs(ssi, "<metadata owner=\"http://elinks.cz\">\n");
+ indentation(ssi, n + 4);
+ secure_fputs(ssi, "<elinks:saved-position value=\"");
+ print_xml_entities(ssi, pos + 1);
+ secure_fputs(ssi, "\"/>\n");
+ indentation(ssi, n + 3);
+ secure_fputs(ssi, "</metadata>\n");
+ indentation(ssi, n + 2);
+ secure_fputs(ssi, "</info>\n");
+ }
secure_fputs(ssi, "<title>");
print_xml_entities(ssi, bm->title);
secure_fputs(ssi, "</title>\n");
@@ -387,11 +404,50 @@
while (node) {
if (!strcmp(node->name, "bookmark")) {
+ char *href_with_pos = NULL;
char *href;
title = get_child(node, "title");
href = get_attribute_value(node, "href");
+ if (href) {
+ char *p = NULL;
+ char *next = href;
+
+ for (;;) {
+ char *end = strstr(next, " x=");
+
+ if (!end) {
+ break;
+ }
+ p = end;
+ next = end + 3;
+ }
+
+ if (p) {
+ *p = POSITION_CHAR;
+ } else {
+ struct tree_node *info = get_child(node, "info");
+ char *pos = NULL;
+
+ if (info) {
+ struct tree_node *metadata = get_child(info, "metadata");
+
+ if (metadata) {
+ struct tree_node *elinks_saved_pos = get_child(metadata, "elinks:saved-position");
+
+ if (elinks_saved_pos) {
+ pos = get_attribute_value(elinks_saved_pos, "value");
+ }
+ }
+ }
+
+ if (pos) {
+ href_with_pos = straconcat(href, POSITION_CHAR_S, pos, NULL);
+ href = href_with_pos;
+ }
+ }
+ }
intl_set_charset_by_index(preload->utf8_cp);
tmp = add_bookmark(current_parent, 0,
/* The <title> element is optional */
@@ -404,6 +460,8 @@
href ? href
: (char *) gettext("No URL"));
+ mem_free_if(href_with_pos);
+
/* Out of memory */
if (!tmp) return 0;
|