NetSurf
urlhistory.c
Go to the documentation of this file.
1/*
2 * Copyright 2009 Rene W. Olsen <ac@rebels.com>
3 * Copyright 2009 Stephen Fellner <sf.amiga@gmail.com>
4 * Copyright 2009 Chris Young <chris@unsatisfactorysoftware.co.uk>
5 *
6 * This file is part of NetSurf, http://www.netsurf-browser.org/
7 *
8 * NetSurf is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * NetSurf is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifdef __amigaos4__
22#include <stdio.h>
23#include <ctype.h>
24#include <string.h>
25
26#include <proto/exec.h>
27
28#include "amiga/os3support.h"
29
30#include "utils/nsoption.h"
31#include "utils/nsurl.h"
32#include "netsurf/url_db.h"
33
34#include "urlhistory.h"
35
36static struct List PageList;
37
38#ifdef __amigaos4__
39#define ALLOCVEC_SHARED(N) AllocVecTags((N), AVT_Type, MEMF_SHARED, TAG_DONE);
40#else
41#define ALLOCVEC_SHARED(N) AllocVec((N), MEMF_SHARED);
42#endif
43
44void URLHistory_Init( void )
45{
46 // Initialise page list
47 NewList( &PageList );
48}
49
50
51void URLHistory_Free( void )
52{
53 struct Node *node;
54
55 while(( node = RemHead( &PageList )))
56 {
57 if( node->ln_Name) FreeVec( node->ln_Name );
58 FreeVec( node );
59 }
60}
61
62
63void URLHistory_ClearList( void )
64{
65 struct Node *node;
66
67 while(( node = RemHead( &PageList )))
68 {
69 if( node->ln_Name) FreeVec( node->ln_Name );
70 FreeVec( node );
71 }
72}
73
74
75struct List * URLHistory_GetList( void )
76{
77 return &PageList;
78}
79
80static bool URLHistoryFound(nsurl *url, const struct url_data *data)
81{
82 struct Node *node;
83
84 /* skip non-visited pages - disabled for testing
85 if(data->visits <= 0) return true;
86 */
87
88 /* skip this URL if it is already in the list */
89 if(URLHistory_FindPage(nsurl_access(url))) return true;
90
91 node = ALLOCVEC_SHARED(sizeof(struct Node));
92
93 if ( node )
94 {
95 STRPTR urladd = (STRPTR) ALLOCVEC_SHARED( strlen ( nsurl_access(url) ) + 1);
96
97 if ( urladd )
98 {
99 strcpy(urladd, nsurl_access(url));
100 node->ln_Name = urladd;
101 AddTail( &PageList, node );
102 }
103 else
104 {
105 FreeVec(node);
106 }
107 }
108 return true;
109}
110
111struct Node * URLHistory_FindPage( const char *urlString )
112{
113 return FindName(&PageList,urlString);
114}
115
116
117void URLHistory_AddPage( const char * urlString )
118{
119 if(!nsoption_bool(url_suggestion)) return;
120
121 // Only search if length > 0
122 if( strlen( urlString ) > 0 )
123 {
124 urldb_iterate_partial(urlString, URLHistoryFound);
125 }
126}
127#endif //__amigaos4__
128
NetSurf URL handling (interface).
const char * nsurl_access(const nsurl *url)
Access a NetSurf URL object as a string.
struct nsurl nsurl
NetSurf URL object.
Definition: nsurl.h:31
Minimal compatibility header for AmigaOS 3.
Interface to utility string handling.
Unified URL information database public interface.
void urldb_iterate_partial(const char *prefix, bool(*callback)(struct nsurl *url, const struct url_data *data))
Iterate over entries in the database which match the given prefix.
void URLHistory_Free(void)
struct List * URLHistory_GetList(void)
struct Node * URLHistory_FindPage(const char *urlString)
void URLHistory_ClearList(void)
void URLHistory_Init(void)
void URLHistory_AddPage(const char *urlString)
Option reading and saving interface.
#define nsoption_bool(OPTION)
Get the value of a boolean option.
Definition: nsoption.h:270