annotate src/history.c @ 162:7a0dad1cffe0

- Fixed a SEGFAULT bug in http.c (handling of web->url). - Fixed handling of #anchors with repush, and other operations.
author jcid
date Fri, 04 Apr 2008 00:23:21 +0200
parents 9bd7bf398a0c
children d513abcd4949
rev   line source
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
1 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
2 * File: history.c
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
3 *
35
d9e7b35430de Updated copyright lines
jcid
parents: 11
diff changeset
4 * Copyright (C) 2001-2007 Jorge Arellano Cid <jcid@dillo.org>
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
5 *
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
8 * the Free Software Foundation; either version 3 of the License, or
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
9 * (at your option) any later version.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
10 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
11
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
12 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
13 * Linear history (it also provides indexes for the navigation stack)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
14 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
15
162
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
16 #include "msg.h"
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
17 #include "list.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
18 #include "history.h"
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
19
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
20
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
21 typedef struct {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
22 DilloUrl *url;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
23 char *title;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
24 } H_Item;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
25
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
26
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
27 /* Global history list */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
28 static H_Item *history = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
29 static int history_size = 0; /* [1 based] */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
30 static int history_size_max = 16;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
31
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
32
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
33 /*
162
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
34 * Debug procedure.
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
35 */
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
36 void History_show()
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
37 {
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
38 int i;
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
39
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
40 MSG(" {");
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
41 for (i = 0; i < history_size; ++i)
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
42 MSG(" %s", URL_STR(history[i].url));
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
43 MSG(" }\n");
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
44 }
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
45
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
46 /*
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
47 * Add a new H_Item at the end of the history list
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
48 * (taking care of not making a duplicate entry)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
49 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
50 int a_History_add_url(DilloUrl *url)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
51 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
52 int i, idx;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
53
162
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
54 _MSG("a_History_add_url: '%s' ", URL_STR(url));
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
55 for (i = 0; i < history_size; ++i)
59
9bd7bf398a0c - Switched dillo to push a URL with fragment (anchor) into the stack.
jcid
parents: 50
diff changeset
56 if (!a_Url_cmp(history[i].url, url) &&
9bd7bf398a0c - Switched dillo to push a URL with fragment (anchor) into the stack.
jcid
parents: 50
diff changeset
57 !strcmp(URL_FRAGMENT(history[i].url), URL_FRAGMENT(url)))
162
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
58 break;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
59
162
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
60 if (i < history_size) {
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
61 idx = i;
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
62 _MSG("FOUND at idx=%d\n", idx);
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
63 } else {
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
64 idx = history_size;
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
65 a_List_add(history, history_size, history_size_max);
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
66 history[idx].url = a_Url_dup(url);
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
67 history[idx].title = NULL;
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
68 ++history_size;
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
69 _MSG("ADDED at idx=%d\n", idx);
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
70 }
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
71
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
72 /* History_show(); */
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
73
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
74 return idx;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
75 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
76
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
77 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
78 * Set the page-title for a given URL (by idx)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
79 * (this is known when the first chunks of HTML data arrive)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
80 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
81 int a_History_set_title(int idx, const char *title)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
82 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
83 dReturn_val_if_fail(idx >= 0 && idx < history_size, 0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
84
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
85 dFree(history[idx].title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
86 history[idx].title = dStrdup(title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
87 return 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
88 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
89
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
90 /*
50
22a3dedcb1a0 - s/camp/field/ s/CAMP/FIELD/
jcid
parents: 35
diff changeset
91 * Return the DilloUrl field (by index)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
92 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
93 DilloUrl *a_History_get_url(int idx)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
94 {
162
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
95 _MSG("a_History_get_url: ");
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
96 /* History_show(); */
7a0dad1cffe0 - Fixed a SEGFAULT bug in http.c (handling of web->url).
jcid
parents: 59
diff changeset
97
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
98 dReturn_val_if_fail(idx >= 0 && idx < history_size, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
99
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
100 return history[idx].url;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
101 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
102
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
103 /*
50
22a3dedcb1a0 - s/camp/field/ s/CAMP/FIELD/
jcid
parents: 35
diff changeset
104 * Return the title field (by index)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
105 * ('force' returns URL_STR when there's no title)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
106 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
107 const char *a_History_get_title(int idx, int force)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
108 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
109 dReturn_val_if_fail(idx >= 0 && idx < history_size, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
110
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
111 if (history[idx].title)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
112 return history[idx].title;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
113 else if (force)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
114 return URL_STR(history[idx].url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
115 else
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
116 return NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
117 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
118
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
119 /*
50
22a3dedcb1a0 - s/camp/field/ s/CAMP/FIELD/
jcid
parents: 35
diff changeset
120 * Return the title field (by url)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
121 * ('force' returns URL_STR when there's no title)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
122 */
11
4a5942beffdf Added some "const" qualifiers.
jcid
parents: 0
diff changeset
123 const char *a_History_get_title_by_url(const DilloUrl *url, int force)
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
124 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
125 int i;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
126
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
127 dReturn_val_if_fail(url != NULL, NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
128
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
129 for (i = 0; i < history_size; ++i)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
130 if (a_Url_cmp(url, history[i].url) == 0)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
131 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
132
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
133 if (i < history_size && history[i].title)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
134 return history[i].title;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
135 else if (force)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
136 return URL_STR_(url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
137 return NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
138 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
139
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
140
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
141 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
142 * Free all the memory used by this module
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
143 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
144 void a_History_free()
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
145 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
146 int i;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
147
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
148 for (i = 0; i < history_size; ++i) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
149 a_Url_free(history[i].url);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
150 dFree(history[i].title);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
151 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
152 dFree(history);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
153 }