summaryrefslogtreecommitdiff
path: root/src/visited.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/visited.c')
-rw-r--r--src/visited.c39
1 files changed, 36 insertions, 3 deletions
diff --git a/src/visited.c b/src/visited.c
index e9f691c6..466add5b 100644
--- a/src/visited.c
+++ b/src/visited.c
@@ -109,11 +109,13 @@ void load_Visited(iVisited *d, const char *dirPath) {
109 const char *urlStart = skipSpace_CStr(endp); 109 const char *urlStart = skipSpace_CStr(endp);
110 iVisitedUrl item; 110 iVisitedUrl item;
111 item.when.ts = (struct timespec){ .tv_sec = ts }; 111 item.when.ts = (struct timespec){ .tv_sec = ts };
112 if (secondsSince_Time(&now, &item.when) > maxAge_Visited) { 112 if (~flags & kept_VisitedUrlFlag &&
113 secondsSince_Time(&now, &item.when) > maxAge_Visited) {
113 continue; /* Too old. */ 114 continue; /* Too old. */
114 } 115 }
115 item.flags = flags; 116 item.flags = flags;
116 initRange_String(&item.url, (iRangecc){ urlStart, line.end }); 117 initRange_String(&item.url, (iRangecc){ urlStart, line.end });
118 set_String(&item.url, &item.url);
117 insert_SortedArray(&d->visited, &item); 119 insert_SortedArray(&d->visited, &item);
118 } 120 }
119 unlock_Mutex(d->mtx); 121 unlock_Mutex(d->mtx);
@@ -153,6 +155,9 @@ void visitUrl_Visited(iVisited *d, const iString *url, uint16_t visitFlags) {
153 lock_Mutex(d->mtx); 155 lock_Mutex(d->mtx);
154 if (locate_SortedArray(&d->visited, &visit, &pos)) { 156 if (locate_SortedArray(&d->visited, &visit, &pos)) {
155 iVisitedUrl *old = at_SortedArray(&d->visited, pos); 157 iVisitedUrl *old = at_SortedArray(&d->visited, pos);
158 if (old->flags & kept_VisitedUrlFlag) {
159 visitFlags |= kept_VisitedUrlFlag; /* must continue to be kept */
160 }
156 if (cmpNewer_VisitedUrl_(&visit, old)) { 161 if (cmpNewer_VisitedUrl_(&visit, old)) {
157 old->when = visit.when; 162 old->when = visit.when;
158 old->flags = visitFlags; 163 old->flags = visitFlags;
@@ -165,6 +170,21 @@ void visitUrl_Visited(iVisited *d, const iString *url, uint16_t visitFlags) {
165 unlock_Mutex(d->mtx); 170 unlock_Mutex(d->mtx);
166} 171}
167 172
173void setUrlKept_Visited(iVisited *d, const iString *url, iBool isKept) {
174 if (isEmpty_String(url)) return;
175 iVisitedUrl visit;
176 init_VisitedUrl(&visit);
177 set_String(&visit.url, canonicalUrl_String(url));
178 size_t pos;
179 lock_Mutex(d->mtx);
180 if (locate_SortedArray(&d->visited, &visit, &pos)) {
181 iVisitedUrl *vis = at_SortedArray(&d->visited, pos);
182 iChangeFlags(vis->flags, kept_VisitedUrlFlag, isKept);
183 }
184 unlock_Mutex(d->mtx);
185 deinit_VisitedUrl(&visit);
186}
187
168void removeUrl_Visited(iVisited *d, const iString *url) { 188void removeUrl_Visited(iVisited *d, const iString *url) {
169 url = canonicalUrl_String(url); 189 url = canonicalUrl_String(url);
170 iGuardMutex(d->mtx, { 190 iGuardMutex(d->mtx, {
@@ -183,7 +203,7 @@ iTime urlVisitTime_Visited(const iVisited *d, const iString *url) {
183 iVisitedUrl item; 203 iVisitedUrl item;
184 size_t pos; 204 size_t pos;
185 iZap(item); 205 iZap(item);
186 initCopy_String(&item.url, url); 206 initCopy_String(&item.url, canonicalUrl_String(url));
187 lock_Mutex(d->mtx); 207 lock_Mutex(d->mtx);
188 if (locate_SortedArray(&d->visited, &item, &pos)) { 208 if (locate_SortedArray(&d->visited, &item, &pos)) {
189 item.when = ((const iVisitedUrl *) constAt_SortedArray(&d->visited, pos))->when; 209 item.when = ((const iVisitedUrl *) constAt_SortedArray(&d->visited, pos))->when;
@@ -203,7 +223,7 @@ static int cmpWhenDescending_VisitedUrlPtr_(const void *a, const void *b) {
203 return -cmp_Time(&s->when, &t->when); 223 return -cmp_Time(&s->when, &t->when);
204} 224}
205 225
206const iArray *list_Visited(const iVisited *d, size_t count) { 226const iPtrArray *list_Visited(const iVisited *d, size_t count) {
207 iPtrArray *urls = collectNew_PtrArray(); 227 iPtrArray *urls = collectNew_PtrArray();
208 iGuardMutex(d->mtx, { 228 iGuardMutex(d->mtx, {
209 iConstForEach(Array, i, &d->visited.values) { 229 iConstForEach(Array, i, &d->visited.values) {
@@ -219,3 +239,16 @@ const iArray *list_Visited(const iVisited *d, size_t count) {
219 } 239 }
220 return urls; 240 return urls;
221} 241}
242
243const iPtrArray *listKept_Visited(const iVisited *d) {
244 iPtrArray *urls = collectNew_PtrArray();
245 iGuardMutex(d->mtx, {
246 iConstForEach(Array, i, &d->visited.values) {
247 const iVisitedUrl *vis = i.value;
248 if (vis->flags & kept_VisitedUrlFlag) {
249 pushBack_PtrArray(urls, vis);
250 }
251 }
252 });
253 return urls;
254}