| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package ZConf::Bookmarks; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
21338
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
30
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
29
|
|
|
5
|
1
|
|
|
1
|
|
1137
|
use ZConf; |
|
|
1
|
|
|
|
|
163372
|
|
|
|
1
|
|
|
|
|
3445
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
ZConf::Bookmarks - ZConf backed bookmark storage system. |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 VERSION |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Version 0.2.4 |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.2.4'; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
use ZConf::Bookmarks; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $zbm = ZConf::Bookmarks->new(); |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 METHODS |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head2 new |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
This initializes it. |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
One arguement is taken and that is a hash value. |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head3 hash values |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head4 autoinit |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
If this is set to true, it will automatically call |
|
39
|
|
|
|
|
|
|
init the set and config. If this is set to false or |
|
40
|
|
|
|
|
|
|
not defined, besure to check '$zbm->{init}' to see |
|
41
|
|
|
|
|
|
|
if the config/module has been initiated or not. |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
If it is not specified, it will default to true. |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head4 set |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
This is the set to load initially. |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head4 zconf |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
If this key is defined, this hash will be passed to ZConf->new(). |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my $zbm=ZConf::Bookmarks->new(); |
|
54
|
|
|
|
|
|
|
if($zbm->{error}){ |
|
55
|
|
|
|
|
|
|
print "Error!\n"; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub new{ |
|
61
|
0
|
|
|
0
|
1
|
|
my %args; |
|
62
|
0
|
0
|
|
|
|
|
if(defined($_[1])){ |
|
63
|
0
|
|
|
|
|
|
%args= %{$_[1]}; |
|
|
0
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $self={error=>undef, errorString=>undef}; |
|
67
|
0
|
|
|
|
|
|
bless $self; |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
#this sets the set to undef if it is not defined |
|
70
|
0
|
0
|
|
|
|
|
if (!defined($args{set})) { |
|
71
|
0
|
|
|
|
|
|
$self->{set}=undef; |
|
72
|
|
|
|
|
|
|
}else { |
|
73
|
0
|
|
|
|
|
|
$self->{set}=$args{set}; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
#this sets the set to 1 if it is not defined |
|
77
|
0
|
0
|
|
|
|
|
if (!defined($args{autoinit})) { |
|
78
|
0
|
|
|
|
|
|
$self->{autoinit}=1; |
|
79
|
|
|
|
|
|
|
}else { |
|
80
|
0
|
|
|
|
|
|
$self->{autoinit}=$args{set}; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
#this is done to keep from throwing an error when we try to pass it to ZConf->new |
|
84
|
0
|
0
|
|
|
|
|
if (!defined($args{zconf})) { |
|
85
|
0
|
|
|
|
|
|
$args{zconf}={}; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
#creates the ZConf object |
|
89
|
0
|
|
|
|
|
|
$self->{zconf}=ZConf->new(%{$args{zconf}}); |
|
|
0
|
|
|
|
|
|
|
|
90
|
0
|
0
|
|
|
|
|
if(defined($self->{zconf}->{error})){ |
|
91
|
0
|
|
|
|
|
|
warn("ZConf-Bookmarks new:1: Could not initiate ZConf. It failed with '" |
|
92
|
|
|
|
|
|
|
.$self->{zconf}->{error}."', '".$self->{zconf}->{errorString}."'"); |
|
93
|
0
|
|
|
|
|
|
$self->{error}=1; |
|
94
|
0
|
|
|
|
|
|
$self->{errorString}="Could not initiate ZConf. It failed with '" |
|
95
|
|
|
|
|
|
|
.$self->{zconf}->{error}."', '". |
|
96
|
|
|
|
|
|
|
$self->{zconf}->{errorString}."'"; |
|
97
|
0
|
|
|
|
|
|
return $self; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
#create the config if it does not exist |
|
102
|
|
|
|
|
|
|
#if it does exist, make sure the set we are using exists |
|
103
|
0
|
|
|
|
|
|
$self->{init} = $self->{zconf}->configExists("bookmarks"); |
|
104
|
0
|
0
|
|
|
|
|
if($self->{zconf}->{error}){ |
|
105
|
0
|
|
|
|
|
|
warn("ZConf-Bookmarks new:2: Could not check if the config 'bookmarks' exists.". |
|
106
|
|
|
|
|
|
|
" It failed with '".$self->{zconf}->{error}."', '" |
|
107
|
|
|
|
|
|
|
.$self->{zconf}->{errorString}."'"); |
|
108
|
0
|
|
|
|
|
|
$self->{error}=2; |
|
109
|
0
|
|
|
|
|
|
$self->{errorString}="Could not check if the config 'bookmarks' exists.". |
|
110
|
|
|
|
|
|
|
" It failed with '".$self->{zconf}->{error}."', '" |
|
111
|
|
|
|
|
|
|
.$self->{zconf}->{errorString}."'"; |
|
112
|
0
|
|
|
|
|
|
return $self; |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
#if it is not inited, check to see if it needs to do so |
|
116
|
0
|
0
|
0
|
|
|
|
if ((!$self->{init}) && $self->{autoinit}) { |
|
117
|
0
|
|
|
|
|
|
$self->init($self->{set}); |
|
118
|
0
|
0
|
|
|
|
|
if ($self->{error}) { |
|
119
|
0
|
|
|
|
|
|
warn('ZConf-Bookmarks new:4: Autoinit failed.'); |
|
120
|
|
|
|
|
|
|
}else { |
|
121
|
|
|
|
|
|
|
#if init works, it is now inited and thus we set it to one |
|
122
|
0
|
|
|
|
|
|
$self->{init}=1; |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
#we don't set any error stuff here even if the above action failed... |
|
125
|
|
|
|
|
|
|
#it will have been set any ways by init methode |
|
126
|
0
|
|
|
|
|
|
return $self; |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
#checks it is set to use the default set |
|
130
|
|
|
|
|
|
|
#use defined as '0' is a legit set name and is a perl boolean for false |
|
131
|
0
|
0
|
0
|
|
|
|
if ((!defined($self->{set})) && $self->{init}) { |
|
132
|
0
|
|
|
|
|
|
$self->{init}=$self->{zconf}->defaultSetExists('bookmarks'); |
|
133
|
0
|
0
|
|
|
|
|
if($self->{zconf}->{error}){ |
|
134
|
0
|
|
|
|
|
|
warn("ZConf-Bookmarks new:2: defaultSetExists failed for 'bookmarks'.". |
|
135
|
|
|
|
|
|
|
" It failed with '".$self->{zconf}->{error}."', '" |
|
136
|
|
|
|
|
|
|
.$self->{zconf}->{errorString}."'"); |
|
137
|
0
|
|
|
|
|
|
$self->{error}=2; |
|
138
|
0
|
|
|
|
|
|
$self->{errorString}="defaultSetExists failed for 'bookmarks'.". |
|
139
|
|
|
|
|
|
|
" It failed with '".$self->{zconf}->{error}."', '" |
|
140
|
|
|
|
|
|
|
.$self->{zconf}->{errorString}."'"; |
|
141
|
0
|
|
|
|
|
|
return $self; |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
#check it if it set to use a specific set |
|
146
|
|
|
|
|
|
|
#use defined as '0' is a legit set name and is a perl boolean for false |
|
147
|
0
|
0
|
|
|
|
|
if (defined($self->{set})) { |
|
148
|
0
|
|
|
|
|
|
$self->{init}=$self->{zconf}->setExists('bookmarks', $self->{set}); |
|
149
|
0
|
0
|
|
|
|
|
if($self->{zconf}->{error}){ |
|
150
|
0
|
|
|
|
|
|
warn("ZConf-Bookmarks new:2: defaultSetExists failed for 'bookmarks'.". |
|
151
|
|
|
|
|
|
|
" It failed with '".$self->{zconf}->{error}."', '" |
|
152
|
|
|
|
|
|
|
.$self->{zconf}->{errorString}."'"); |
|
153
|
0
|
|
|
|
|
|
$self->{error}=2; |
|
154
|
0
|
|
|
|
|
|
$self->{errorString}="defaultSetExists failed for 'bookmarks'.". |
|
155
|
|
|
|
|
|
|
" It failed with '".$self->{zconf}->{error}."', '" |
|
156
|
|
|
|
|
|
|
.$self->{zconf}->{errorString}."'"; |
|
157
|
0
|
|
|
|
|
|
return $self; |
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
#the first one does this if the config has not been done yet |
|
162
|
|
|
|
|
|
|
#this one does it if the set has not been done yet |
|
163
|
|
|
|
|
|
|
#if it is not inited, check to see if it needs to do so |
|
164
|
0
|
0
|
0
|
|
|
|
if (!$self->{init} && $self->{autoinit}) { |
|
165
|
0
|
|
|
|
|
|
$self->init($self->{set}); |
|
166
|
0
|
0
|
|
|
|
|
if ($self->{error}) { |
|
167
|
0
|
|
|
|
|
|
warn('ZConf-Bookmarks new:4: Autoinit failed.'); |
|
168
|
|
|
|
|
|
|
}else { |
|
169
|
|
|
|
|
|
|
#if init works, it is now inited and thus we set it to one |
|
170
|
0
|
|
|
|
|
|
$self->{init}=1; |
|
171
|
|
|
|
|
|
|
} |
|
172
|
|
|
|
|
|
|
#we don't set any error stuff here even if the above action failed... |
|
173
|
|
|
|
|
|
|
#it will have been set any ways by init methode |
|
174
|
0
|
|
|
|
|
|
return $self; |
|
175
|
|
|
|
|
|
|
} |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
#reads it if it does not need to be initiated |
|
178
|
0
|
0
|
|
|
|
|
if ($self->{init}) { |
|
179
|
0
|
|
|
|
|
|
$self->{zconf}->read({set=>$self->{set}, config=>'bookmarks'}); |
|
180
|
|
|
|
|
|
|
} |
|
181
|
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
|
return $self; |
|
183
|
|
|
|
|
|
|
} |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head2 addBookmark |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
This adds a bookmark for a specified scheme. |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Only one arguement is accepted and that is a hash. Please |
|
190
|
|
|
|
|
|
|
see the below for a list of keys. |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head3 hash args |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head4 name |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
This is name for a book mark. |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head4 description |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
This is a description for the bookmark. |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head4 link |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
This is the URI, minus scheme. Thus 'http://vvelox.net/' would become |
|
205
|
|
|
|
|
|
|
'vvelox.net'. |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head4 scheme |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
This is the scheme it should be added it. If it is not in lower case |
|
210
|
|
|
|
|
|
|
it will be converted to it. |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
my %newBM; |
|
213
|
|
|
|
|
|
|
$newBM{description}='VVelox.net'; |
|
214
|
|
|
|
|
|
|
$newBM{name}='VVelox.net'; |
|
215
|
|
|
|
|
|
|
$newBM{link}='vvelox.net'; |
|
216
|
|
|
|
|
|
|
$newBM{scheme}='http'; |
|
217
|
|
|
|
|
|
|
$zbm->modBookmark(%newBM); |
|
218
|
|
|
|
|
|
|
if($zbm->{error}){ |
|
219
|
|
|
|
|
|
|
print "Error!\n"; |
|
220
|
|
|
|
|
|
|
} |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=cut |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
sub addBookmark{ |
|
225
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
226
|
0
|
|
|
|
|
|
my %args; |
|
227
|
0
|
0
|
|
|
|
|
if(defined($_[1])){ |
|
228
|
0
|
|
|
|
|
|
%args= %{$_[1]}; |
|
|
0
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
} |
|
230
|
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
#blanks any previous errors |
|
232
|
0
|
|
|
|
|
|
$self->errorblank; |
|
233
|
|
|
|
|
|
|
|
|
234
|
0
|
0
|
|
|
|
|
if (!defined($args{scheme})) { |
|
235
|
0
|
|
|
|
|
|
warn("ZConf-Bookmarks addBookmark:3: No scheme type specified"); |
|
236
|
0
|
|
|
|
|
|
$self->{error}=3; |
|
237
|
0
|
|
|
|
|
|
$self->{errorString}="No scheme type specified"; |
|
238
|
0
|
|
|
|
|
|
return undef; |
|
239
|
|
|
|
|
|
|
} |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
#makes sure a name is specified |
|
242
|
0
|
0
|
|
|
|
|
if (!defined($args{name})) { |
|
243
|
0
|
|
|
|
|
|
warn('ZConf-Bookmarks addBookmark:3: No name, $args{name}, type specified'); |
|
244
|
0
|
|
|
|
|
|
$self->{error}=3; |
|
245
|
0
|
|
|
|
|
|
$self->{errorString}="No name, $args{name}, type specified'"; |
|
246
|
0
|
|
|
|
|
|
return undef; |
|
247
|
|
|
|
|
|
|
} |
|
248
|
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
#make sure the scheme is lower case |
|
250
|
0
|
|
|
|
|
|
$args{scheme}=lc($args{scheme}); |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
#makes sure a URI scheme type is specified |
|
253
|
0
|
0
|
|
|
|
|
if (!defined($args{scheme})) { |
|
254
|
0
|
|
|
|
|
|
warn('ZConf-Bookmarks addBookmark:3: No URI scheme, $args{name}, specified'); |
|
255
|
0
|
|
|
|
|
|
$self->{error}=3; |
|
256
|
0
|
|
|
|
|
|
$self->{errorString}="No URI scheme, $args{URI}, specified'"; |
|
257
|
0
|
|
|
|
|
|
return undef; |
|
258
|
|
|
|
|
|
|
} |
|
259
|
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
#makes sure a description is specified |
|
261
|
0
|
0
|
|
|
|
|
if (!defined($args{description})) { |
|
262
|
0
|
|
|
|
|
|
warn('ZConf-Bookmarks addBookmark:3: No description, $args{description}, specified'); |
|
263
|
0
|
|
|
|
|
|
$self->{error}=3; |
|
264
|
0
|
|
|
|
|
|
$self->{errorString}="No description, $args{description}, specified'"; |
|
265
|
0
|
|
|
|
|
|
return undef; |
|
266
|
|
|
|
|
|
|
} |
|
267
|
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
#makes sure a link is specified |
|
269
|
0
|
0
|
|
|
|
|
if (!defined($args{'link'})) { |
|
270
|
0
|
|
|
|
|
|
warn('ZConf-Bookmarks addBookmark:3: No link, $args{description}, specified'); |
|
271
|
0
|
|
|
|
|
|
$self->{error}=3; |
|
272
|
0
|
|
|
|
|
|
$self->{errorString}='No link, $args{"link"}, specified'; |
|
273
|
0
|
|
|
|
|
|
return undef; |
|
274
|
|
|
|
|
|
|
} |
|
275
|
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
#sets the ID |
|
277
|
0
|
|
|
|
|
|
my $hostname=`hostname`; |
|
278
|
0
|
|
|
|
|
|
chomp($hostname); |
|
279
|
0
|
|
|
|
|
|
$args{bmid}=$hostname.':'.time.':'.rand; |
|
280
|
|
|
|
|
|
|
|
|
281
|
0
|
|
|
|
|
|
my $bookmarkExists=undef; |
|
282
|
0
|
|
|
|
|
|
my $schemeExists=$self->schemeExists($args{scheme}); |
|
283
|
0
|
0
|
|
|
|
|
if ($self->{error}) { |
|
284
|
0
|
|
|
|
|
|
warn('ZConf-Bookmarks addBookmark: schemeExists errored'); |
|
285
|
0
|
|
|
|
|
|
return undef; |
|
286
|
|
|
|
|
|
|
} |
|
287
|
|
|
|
|
|
|
|
|
288
|
0
|
0
|
|
|
|
|
if ($schemeExists) { |
|
289
|
0
|
|
|
|
|
|
my $max=3; |
|
290
|
0
|
|
|
|
|
|
my $int=0; |
|
291
|
0
|
|
|
|
|
|
my $exists=1; |
|
292
|
|
|
|
|
|
|
#loop till it does not exists or has tried three times... |
|
293
|
|
|
|
|
|
|
#it is unlikely a hit will ever be found... this exists |
|
294
|
|
|
|
|
|
|
#just to prevent the very rare circumstance that one may |
|
295
|
|
|
|
|
|
|
#exist already |
|
296
|
0
|
|
0
|
|
|
|
while (($int <= $max) && $exists) { |
|
297
|
|
|
|
|
|
|
#check if it exists |
|
298
|
0
|
|
|
|
|
|
$exists=$self->bookmarkExists($args{scheme}, $args{bmid}); |
|
299
|
0
|
0
|
|
|
|
|
if ($self->{error}) { |
|
300
|
0
|
|
|
|
|
|
warn('ZConf-Bookmarks addBookmark: bookmarkExists errored'); |
|
301
|
0
|
|
|
|
|
|
return undef; |
|
302
|
|
|
|
|
|
|
} |
|
303
|
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
#if it exists regen the ID and try again |
|
305
|
0
|
0
|
|
|
|
|
if ($exists) { |
|
306
|
0
|
|
|
|
|
|
$args{bmid}=`hostname`.':'.time.':'.rand; |
|
307
|
|
|
|
|
|
|
} |
|
308
|
|
|
|
|
|
|
|
|
309
|
0
|
|
|
|
|
|
$int++; |
|
310
|
|
|
|
|
|
|
} |
|
311
|
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
#error if a new ID could not be found |
|
313
|
0
|
0
|
|
|
|
|
if ($exists) { |
|
314
|
0
|
|
|
|
|
|
warn('ZConf-Bookmarks addBookmark:4: Could not generate a new ID'); |
|
315
|
0
|
|
|
|
|
|
$self->{error}=4; |
|
316
|
0
|
|
|
|
|
|
$self->{errorString}='Could not generate a new ID.'; |
|
317
|
0
|
|
|
|
|
|
return undef; |
|
318
|
|
|
|
|
|
|
} |
|
319
|
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
} |
|
321
|
|
|
|
|
|
|
|
|
322
|
0
|
|
|
|
|
|
my $bmVar='schemes/'.$args{scheme}.'/'.$args{bmid}.'/'; |
|
323
|
|
|
|
|
|
|
|
|
324
|
0
|
|
|
|
|
|
$self->{zconf}->setVar('bookmarks', $bmVar.'name', $args{name}); |
|
325
|
|
|
|
|
|
|
#if for some uber unlikely this fails, error |
|
326
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->{error}) { |
|
327
|
0
|
|
|
|
|
|
warn('ZConf-Bookmarks addBookmark:5: setVar failed... var="'.$bmVar.'name"'. |
|
328
|
|
|
|
|
|
|
' value="'.$args{name}.'"'); |
|
329
|
0
|
|
|
|
|
|
$self->{error}=5; |
|
330
|
0
|
|
|
|
|
|
$self->{errorString}='setVar failed... var="'.$bmVar.'name"'. |
|
331
|
|
|
|
|
|
|
' value="'.$args{name}.'"'; |
|
332
|
0
|
|
|
|
|
|
return undef; |
|
333
|
|
|
|
|
|
|
} |
|
334
|
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
#this adds the rest |
|
336
|
0
|
|
|
|
|
|
$self->{zconf}->setVar('bookmarks', $bmVar.'link', $args{link}); |
|
337
|
0
|
|
|
|
|
|
$self->{zconf}->setVar('bookmarks', $bmVar.'description', $args{description}); |
|
338
|
0
|
|
|
|
|
|
$self->{zconf}->setVar('bookmarks', $bmVar.'created', time()); |
|
339
|
0
|
|
|
|
|
|
$self->{zconf}->setVar('bookmarks', $bmVar.'lastModified', time()); |
|
340
|
|
|
|
|
|
|
|
|
341
|
0
|
|
|
|
|
|
$self->{zconf}->writeSetFromLoadedConfig({config=>'bookmarks'}); |
|
342
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->{error}) { |
|
343
|
0
|
|
|
|
|
|
warn('ZConf-Bookmarks addBookmark:2: writeSetFromLoadedConfig failed. '. |
|
344
|
|
|
|
|
|
|
'error="'.$self->{zconf}->{error}.'" errorString="'. |
|
345
|
|
|
|
|
|
|
$self->{zconf}->{errorString}.'"'); |
|
346
|
0
|
|
|
|
|
|
$self->{error}=2; |
|
347
|
0
|
|
|
|
|
|
$self->{errorString}='writeSetFromLoadedConfig failed. '. |
|
348
|
|
|
|
|
|
|
'error="'.$self->{zconf}->{error}. |
|
349
|
|
|
|
|
|
|
'" errorString="'. |
|
350
|
|
|
|
|
|
|
$self->{zconf}->{errorString}.'"'; |
|
351
|
0
|
|
|
|
|
|
return undef; |
|
352
|
|
|
|
|
|
|
} |
|
353
|
|
|
|
|
|
|
|
|
354
|
0
|
|
|
|
|
|
return 1; |
|
355
|
|
|
|
|
|
|
} |
|
356
|
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
=head2 bookmarkExists |
|
358
|
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
This verifies a bookmark ID exists for a specified scheme. |
|
360
|
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
You do have to check the return value as it will contain if it |
|
362
|
|
|
|
|
|
|
exists or not. $zbm->{error} is only true if there is an error |
|
363
|
|
|
|
|
|
|
and for this the bookmark ID not existing is not considered an |
|
364
|
|
|
|
|
|
|
error. |
|
365
|
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
my $returned=$zbm->bookmarkExists($scheme, $bmid); |
|
367
|
|
|
|
|
|
|
if($zbm->{error}){ |
|
368
|
|
|
|
|
|
|
print "Error!\n"; |
|
369
|
|
|
|
|
|
|
}else{ |
|
370
|
|
|
|
|
|
|
if($returned){ |
|
371
|
|
|
|
|
|
|
print "It does exist.\n"; |
|
372
|
|
|
|
|
|
|
}else{ |
|
373
|
|
|
|
|
|
|
print "It does not exist.\n"; |
|
374
|
|
|
|
|
|
|
} |
|
375
|
|
|
|
|
|
|
} |
|
376
|
|
|
|
|
|
|
|
|
377
|
|
|
|
|
|
|
=cut |
|
378
|
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
sub bookmarkExists{ |
|
380
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
381
|
0
|
|
|
|
|
|
my $scheme=$_[1]; |
|
382
|
0
|
|
|
|
|
|
my $bmid=$_[2]; |
|
383
|
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
#blanks any previous errors |
|
385
|
0
|
|
|
|
|
|
$self->errorblank; |
|
386
|
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
#make s |
|
388
|
0
|
0
|
|
|
|
|
if (!defined($scheme)) { |
|
389
|
0
|
|
|
|
|
|
warn("ZConf-Bookmarks bookmarkExists:3: No scheme type specified"); |
|
390
|
0
|
|
|
|
|
|
$self->{error}=3; |
|
391
|
0
|
|
|
|
|
|
$self->{errorString}="No scheme type specified"; |
|
392
|
0
|
|
|
|
|
|
return undef; |
|
393
|
|
|
|
|
|
|
} |
|
394
|
0
|
|
|
|
|
|
$scheme=lc($scheme); |
|
395
|
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
#make sure a scheme is specified |
|
397
|
0
|
0
|
|
|
|
|
if (!defined($bmid)) { |
|
398
|
0
|
|
|
|
|
|
warn("ZConf-Bookmarks bookmarkExists:3: No bmid specified"); |
|
399
|
0
|
|
|
|
|
|
$self->{error}=3; |
|
400
|
0
|
|
|
|
|
|
$self->{errorString}="No bmid specified"; |
|
401
|
0
|
|
|
|
|
|
return undef; |
|
402
|
|
|
|
|
|
|
} |
|
403
|
|
|
|
|
|
|
|
|
404
|
0
|
|
|
|
|
|
my @bmids=$self->listBookmarks($scheme); |
|
405
|
|
|
|
|
|
|
|
|
406
|
|
|
|
|
|
|
#go through each one looking for a match |
|
407
|
0
|
|
|
|
|
|
my $int=0; |
|
408
|
0
|
|
|
|
|
|
while (defined($bmids[$int])) { |
|
409
|
0
|
0
|
|
|
|
|
if ($bmid eq $bmids[$int]) { |
|
410
|
0
|
|
|
|
|
|
return 1; |
|
411
|
|
|
|
|
|
|
} |
|
412
|
|
|
|
|
|
|
|
|
413
|
0
|
|
|
|
|
|
$int++; |
|
414
|
|
|
|
|
|
|
} |
|
415
|
|
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
#return undef if it is not found |
|
417
|
0
|
|
|
|
|
|
return undef; |
|
418
|
|
|
|
|
|
|
} |
|
419
|
|
|
|
|
|
|
|
|
420
|
|
|
|
|
|
|
=head2 delBookmark |
|
421
|
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
This removes a bookmark. |
|
423
|
|
|
|
|
|
|
|
|
424
|
|
|
|
|
|
|
Two arguements are required. The first is the |
|
425
|
|
|
|
|
|
|
scheme and the second is the bookmark. |
|
426
|
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
$zbm->delBookmark($scheme, $bmid); |
|
428
|
|
|
|
|
|
|
if($zbm->{error}){ |
|
429
|
|
|
|
|
|
|
print "Error\n"; |
|
430
|
|
|
|
|
|
|
} |
|
431
|
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
=cut |
|
433
|
|
|
|
|
|
|
|
|
434
|
|
|
|
|
|
|
sub delBookmark{ |
|
435
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
436
|
0
|
|
|
|
|
|
my $scheme=$_[1]; |
|
437
|
0
|
|
|
|
|
|
my $bmid=$_[2]; |
|
438
|
|
|
|
|
|
|
|
|
439
|
|
|
|
|
|
|
#blanks any previous errors |
|
440
|
0
|
|
|
|
|
|
$self->errorblank; |
|
441
|
|
|
|
|
|
|
|
|
442
|
|
|
|
|
|
|
#make s |
|
443
|
0
|
0
|
|
|
|
|
if (!defined($scheme)) { |
|
444
|
0
|
|
|
|
|
|
warn("ZConf-Bookmarks delBookmark:3: No scheme type specified"); |
|
445
|
0
|
|
|
|
|
|
$self->{error}=3; |
|
446
|
0
|
|
|
|
|
|
$self->{errorString}="No scheme type specified"; |
|
447
|
0
|
|
|
|
|
|
return undef; |
|
448
|
|
|
|
|
|
|
} |
|
449
|
|
|
|
|
|
|
#convert it to lowercase |
|
450
|
0
|
|
|
|
|
|
$scheme=lc($scheme); |
|
451
|
|
|
|
|
|
|
|
|
452
|
|
|
|
|
|
|
#make sure a scheme is specified |
|
453
|
0
|
0
|
|
|
|
|
if (!defined($bmid)) { |
|
454
|
0
|
|
|
|
|
|
warn("ZConf-Bookmarks delBookmark:3: No bmid specified"); |
|
455
|
0
|
|
|
|
|
|
$self->{error}=3; |
|
456
|
0
|
|
|
|
|
|
$self->{errorString}="No bmid specified"; |
|
457
|
0
|
|
|
|
|
|
return undef; |
|
458
|
|
|
|
|
|
|
} |
|
459
|
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
#the path that will be removed |
|
461
|
0
|
|
|
|
|
|
my $path='schemes/'.$scheme.'/'.$bmid.'/'; |
|
462
|
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
#delete them and check for any errors |
|
464
|
0
|
|
|
|
|
|
my @deleted=$self->{zconf}->regexVarDel('bookmarks', '^'.quotemeta($path)); |
|
465
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->{error}) { |
|
466
|
0
|
|
|
|
|
|
warn('ZConf-Bookmarks delBookmark:2: regexVarDel errored. '. |
|
467
|
|
|
|
|
|
|
'error="'.$self->{zconf}->{error}.'" errorString="'. |
|
468
|
|
|
|
|
|
|
$self->{zconf}->{errorString}.'"'); |
|
469
|
0
|
|
|
|
|
|
$self->{error}=2; |
|
470
|
0
|
|
|
|
|
|
$self->{errorString}='regexVarDel errored. '. |
|
471
|
|
|
|
|
|
|
'error="'.$self->{zconf}->{error}.'" errorString="'. |
|
472
|
|
|
|
|
|
|
$self->{zconf}->{errorString}.'"'; |
|
473
|
0
|
|
|
|
|
|
return undef; |
|
474
|
|
|
|
|
|
|
} |
|
475
|
|
|
|
|
|
|
|
|
476
|
|
|
|
|
|
|
#save it |
|
477
|
0
|
|
|
|
|
|
$self->{zconf}->writeSetFromLoadedConfig({config=>'bookmarks'}); |
|
478
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->{error}) { |
|
479
|
0
|
|
|
|
|
|
warn('ZConf-Bookmarks delBookmark:2: writeSetFromLoadedConfig failed. '. |
|
480
|
|
|
|
|
|
|
'error="'.$self->{zconf}->{error}.'" errorString="'. |
|
481
|
|
|
|
|
|
|
$self->{zconf}->{errorString}.'"'); |
|
482
|
0
|
|
|
|
|
|
$self->{error}=2; |
|
483
|
0
|
|
|
|
|
|
$self->{errorString}='writeSetFromLoadedConfig failed. '. |
|
484
|
|
|
|
|
|
|
'error="'.$self->{zconf}->{error}. |
|
485
|
|
|
|
|
|
|
'" errorString="'. |
|
486
|
|
|
|
|
|
|
$self->{zconf}->{errorString}.'"'; |
|
487
|
0
|
|
|
|
|
|
return undef; |
|
488
|
|
|
|
|
|
|
} |
|
489
|
|
|
|
|
|
|
|
|
490
|
0
|
|
|
|
|
|
return 1; |
|
491
|
|
|
|
|
|
|
} |
|
492
|
|
|
|
|
|
|
|
|
493
|
|
|
|
|
|
|
=head2 getBookmark |
|
494
|
|
|
|
|
|
|
|
|
495
|
|
|
|
|
|
|
This reads a returns a bookmark. |
|
496
|
|
|
|
|
|
|
|
|
497
|
|
|
|
|
|
|
Two arguements are accepted. The first is the scheme |
|
498
|
|
|
|
|
|
|
and the second is the bookmark ID. |
|
499
|
|
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
my %bookmark=$zbm->get($scheme, $bmID); |
|
501
|
|
|
|
|
|
|
if($zbm->{error}){ |
|
502
|
|
|
|
|
|
|
print "Error!\n"; |
|
503
|
|
|
|
|
|
|
} |
|
504
|
|
|
|
|
|
|
|
|
505
|
|
|
|
|
|
|
=cut |
|
506
|
|
|
|
|
|
|
|
|
507
|
|
|
|
|
|
|
sub getBookmark{ |
|
508
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
509
|
0
|
|
|
|
|
|
my $scheme=$_[1]; |
|
510
|
0
|
|
|
|
|
|
my $bmid=$_[2]; |
|
511
|
|
|
|
|
|
|
|
|
512
|
0
|
|
|
|
|
|
$self->errorblank; |
|
513
|
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
#make sure we have a scheme |
|
515
|
0
|
0
|
|
|
|
|
if (!defined($scheme)) { |
|
516
|
0
|
|
|
|
|
|
$self->{error}=3; |
|
517
|
0
|
|
|
|
|
|
$self->{errorString}="No scheme specified"; |
|
518
|
0
|
|
|
|
|
|
warn('ZConf-Bookmarks getBookmark:3: '.$self->{errorString}); |
|
519
|
0
|
|
|
|
|
|
return undef; |
|
520
|
|
|
|
|
|
|
} |
|
521
|
|
|
|
|
|
|
#convert it to lowercase |
|
522
|
0
|
|
|
|
|
|
$scheme=lc($scheme); |
|
523
|
|
|
|
|
|
|
|
|
524
|
|
|
|
|
|
|
#make sure we have a bookmark ID |
|
525
|
0
|
0
|
|
|
|
|
if (!defined($bmid)) { |
|
526
|
0
|
|
|
|
|
|
$self->{error}=3; |
|
527
|
0
|
|
|
|
|
|
$self->{errorString}="No bookmark ID specified"; |
|
528
|
0
|
|
|
|
|
|
warn('ZConf-Bookmarks getBookmark:3: '.$self->{errorString}); |
|
529
|
0
|
|
|
|
|
|
return undef; |
|
530
|
|
|
|
|
|
|
} |
|
531
|
|
|
|
|
|
|
|
|
532
|
|
|
|
|
|
|
#check if it exists or not |
|
533
|
0
|
|
|
|
|
|
my $exists=$self->bookmarkExists($scheme, $bmid); |
|
534
|
0
|
0
|
|
|
|
|
if ($self->{error}) { |
|
535
|
0
|
|
|
|
|
|
warn('ZConf-Bookmarks getBookmark: bookmarkExists errored'); |
|
536
|
0
|
|
|
|
|
|
return undef; |
|
537
|
|
|
|
|
|
|
} |
|
538
|
0
|
0
|
|
|
|
|
if (!$exists) { |
|
539
|
0
|
|
|
|
|
|
$self->{error}=6; |
|
540
|
0
|
|
|
|
|
|
$self->{errorString}='"'.$bmid.'" does not exist'; |
|
541
|
0
|
|
|
|
|
|
warn('ZConf-Bookmarks getBookmark:6: '.$self->{errorString}); |
|
542
|
0
|
|
|
|
|
|
return undef; |
|
543
|
|
|
|
|
|
|
} |
|
544
|
|
|
|
|
|
|
|
|
545
|
|
|
|
|
|
|
#this is what will be returned |
|
546
|
0
|
|
|
|
|
|
my %bookmark; |
|
547
|
|
|
|
|
|
|
|
|
548
|
|
|
|
|
|
|
#base bookmark variable name |
|
549
|
0
|
|
|
|
|
|
my $bmvar='schemes/'.$scheme.'/'.$bmid.'/'; |
|
550
|
|
|
|
|
|
|
|
|
551
|
0
|
|
|
|
|
|
my %found=$self->{zconf}->regexVarGet( |
|
552
|
|
|
|
|
|
|
'bookmarks', |
|
553
|
|
|
|
|
|
|
'^'.quotemeta($bmvar) |
|
554
|
|
|
|
|
|
|
); |
|
555
|
|
|
|
|
|
|
|
|
556
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->{error}) { |
|
557
|
0
|
|
|
|
|
|
$self->{error}=2; |
|
558
|
0
|
|
|
|
|
|
$self->{errorString}='ZConf errored when doing a regexVarSearch. error="'. |
|
559
|
|
|
|
|
|
|
$self->{zconf}->{error}.'" errorString="'. |
|
560
|
|
|
|
|
|
|
$self->{zconf}->{error}.'"'; |
|
561
|
0
|
|
|
|
|
|
warn('ZConf-Bookmarks getBookmark:2: '.$self->{errorString}); |
|
562
|
0
|
|
|
|
|
|
return undef; |
|
563
|
|
|
|
|
|
|
} |
|
564
|
|
|
|
|
|
|
|
|
565
|
0
|
|
|
|
|
|
$bookmark{name}=$found{$bmvar.'name'}; |
|
566
|
0
|
|
|
|
|
|
$bookmark{link}=$found{$bmvar.'link'}; |
|
567
|
0
|
|
|
|
|
|
$bookmark{description}=$found{$bmvar.'description'}; |
|
568
|
0
|
|
|
|
|
|
$bookmark{created}=$found{$bmvar.'created'}; |
|
569
|
0
|
|
|
|
|
|
$bookmark{lastModified}=$found{$bmvar.'lastModified'}; |
|
570
|
|
|
|
|
|
|
|
|
571
|
0
|
|
|
|
|
|
return %bookmark; |
|
572
|
|
|
|
|
|
|
} |
|
573
|
|
|
|
|
|
|
|
|
574
|
|
|
|
|
|
|
=head2 getSet |
|
575
|
|
|
|
|
|
|
|
|
576
|
|
|
|
|
|
|
This gets what the current set is. |
|
577
|
|
|
|
|
|
|
|
|
578
|
|
|
|
|
|
|
my $set=$zbm->getSet; |
|
579
|
|
|
|
|
|
|
if($zbm->{error}){ |
|
580
|
|
|
|
|
|
|
print "Error!\n"; |
|
581
|
|
|
|
|
|
|
} |
|
582
|
|
|
|
|
|
|
|
|
583
|
|
|
|
|
|
|
=cut |
|
584
|
|
|
|
|
|
|
|
|
585
|
|
|
|
|
|
|
sub getSet{ |
|
586
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
587
|
|
|
|
|
|
|
|
|
588
|
0
|
|
|
|
|
|
my $set=$self->{zconf}->getSet('bookmarks'); |
|
589
|
0
|
0
|
|
|
|
|
if($self->{zconf}->{error}){ |
|
590
|
0
|
|
|
|
|
|
warn('ZConf-Runner getSet:2: ZConf error getting the loaded set the config "bookmarks".'. |
|
591
|
|
|
|
|
|
|
' ZConf error="'.$self->{zconf}->{error}.'" '. |
|
592
|
|
|
|
|
|
|
'ZConf error string="'.$self->{zconf}->{errorString}.'"'); |
|
593
|
0
|
|
|
|
|
|
$self->{error}=2; |
|
594
|
0
|
|
|
|
|
|
$self->{errorString}='ZConf error getting the loaded set the config "bookmarks".'. |
|
595
|
|
|
|
|
|
|
' ZConf error="'.$self->{zconf}->{error}.'" '. |
|
596
|
|
|
|
|
|
|
'ZConf error string="'.$self->{zconf}->{errorString}.'"'; |
|
597
|
0
|
|
|
|
|
|
return undef; |
|
598
|
|
|
|
|
|
|
} |
|
599
|
|
|
|
|
|
|
|
|
600
|
0
|
|
|
|
|
|
return $set; |
|
601
|
|
|
|
|
|
|
} |
|
602
|
|
|
|
|
|
|
|
|
603
|
|
|
|
|
|
|
=head2 init |
|
604
|
|
|
|
|
|
|
|
|
605
|
|
|
|
|
|
|
This initializes it or a new set. |
|
606
|
|
|
|
|
|
|
|
|
607
|
|
|
|
|
|
|
If the specified set already exists, it will be reset. |
|
608
|
|
|
|
|
|
|
|
|
609
|
|
|
|
|
|
|
One arguement is required and it is the name of the set. If |
|
610
|
|
|
|
|
|
|
it is not defined, ZConf will use the default one. |
|
611
|
|
|
|
|
|
|
|
|
612
|
|
|
|
|
|
|
#creates a new set named foo |
|
613
|
|
|
|
|
|
|
$zbm->init('foo'); |
|
614
|
|
|
|
|
|
|
if($zbm->{error}){ |
|
615
|
|
|
|
|
|
|
print "Error!\n"; |
|
616
|
|
|
|
|
|
|
} |
|
617
|
|
|
|
|
|
|
|
|
618
|
|
|
|
|
|
|
#creates a new set with ZConf choosing it's name |
|
619
|
|
|
|
|
|
|
$zbg->init(); |
|
620
|
|
|
|
|
|
|
if($zbm->{error}){ |
|
621
|
|
|
|
|
|
|
print "Error!\n"; |
|
622
|
|
|
|
|
|
|
} |
|
623
|
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
=cut |
|
625
|
|
|
|
|
|
|
|
|
626
|
|
|
|
|
|
|
sub init{ |
|
627
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
628
|
0
|
|
|
|
|
|
my $set=$_[1]; |
|
629
|
|
|
|
|
|
|
|
|
630
|
|
|
|
|
|
|
#blanks any previous errors |
|
631
|
0
|
|
|
|
|
|
$self->errorblank; |
|
632
|
|
|
|
|
|
|
|
|
633
|
0
|
|
|
|
|
|
my $returned = $self->{zconf}->configExists("bookmarks"); |
|
634
|
0
|
0
|
|
|
|
|
if(defined($self->{zconf}->{error})){ |
|
635
|
0
|
|
|
|
|
|
warn("ZConf-Bookmarks init:2: Could not check if the config 'bookmarks' exists.". |
|
636
|
|
|
|
|
|
|
" It failed with '".$self->{zconf}->{error}."', '" |
|
637
|
|
|
|
|
|
|
.$self->{zconf}->{errorString}."'"); |
|
638
|
0
|
|
|
|
|
|
$self->{error}=2; |
|
639
|
0
|
|
|
|
|
|
$self->{errorString}="Could not check if the config 'bookmarks' exists.". |
|
640
|
|
|
|
|
|
|
" It failed with '".$self->{zconf}->{error}."', '" |
|
641
|
|
|
|
|
|
|
.$self->{zconf}->{errorString}."'"; |
|
642
|
0
|
|
|
|
|
|
return undef; |
|
643
|
|
|
|
|
|
|
} |
|
644
|
|
|
|
|
|
|
|
|
645
|
|
|
|
|
|
|
#create the config if it does not exist |
|
646
|
0
|
0
|
|
|
|
|
if (!$returned) { |
|
647
|
0
|
|
|
|
|
|
$self->{zconf}->createConfig("bookmarks"); |
|
648
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->{error}) { |
|
649
|
0
|
|
|
|
|
|
warn("ZConf-Bookmarks init:2: Could not create the ZConf config 'bookmarks'.". |
|
650
|
|
|
|
|
|
|
" It failed with '".$self->{zconf}->{error}."', '" |
|
651
|
|
|
|
|
|
|
.$self->{zconf}->{errorString}."'"); |
|
652
|
0
|
|
|
|
|
|
$self->{error}=2; |
|
653
|
0
|
|
|
|
|
|
$self->{errorString}="Could not create the ZConf config 'bookmarks'.". |
|
654
|
|
|
|
|
|
|
" It failed with '".$self->{zconf}->{error}."', '" |
|
655
|
|
|
|
|
|
|
.$self->{zconf}->{errorString}."'"; |
|
656
|
0
|
|
|
|
|
|
return undef; |
|
657
|
|
|
|
|
|
|
} |
|
658
|
|
|
|
|
|
|
} |
|
659
|
|
|
|
|
|
|
|
|
660
|
|
|
|
|
|
|
#create the new set |
|
661
|
0
|
|
|
|
|
|
$self->{zconf}->writeSetFromHash({config=>"bookmarks", set=>$set},{}); |
|
662
|
|
|
|
|
|
|
#error if the write failed |
|
663
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->{error}) { |
|
664
|
0
|
|
|
|
|
|
warn("ZConf-Bookmarks init:2: writeSetFromHash failed.". |
|
665
|
|
|
|
|
|
|
" It failed with '".$self->{zconf}->{error}."', '" |
|
666
|
|
|
|
|
|
|
.$self->{zconf}->{errorString}."'"); |
|
667
|
0
|
|
|
|
|
|
$self->{error}=2; |
|
668
|
0
|
|
|
|
|
|
$self->{errorString}="writeSetFromHash failed.". |
|
669
|
|
|
|
|
|
|
" It failed with '".$self->{zconf}->{error}."', '" |
|
670
|
|
|
|
|
|
|
.$self->{zconf}->{errorString}."'"; |
|
671
|
0
|
|
|
|
|
|
return undef; |
|
672
|
|
|
|
|
|
|
} |
|
673
|
|
|
|
|
|
|
|
|
674
|
0
|
|
|
|
|
|
return 1; |
|
675
|
|
|
|
|
|
|
} |
|
676
|
|
|
|
|
|
|
|
|
677
|
|
|
|
|
|
|
=head2 listBookmarks |
|
678
|
|
|
|
|
|
|
|
|
679
|
|
|
|
|
|
|
This lists the currently setup bookmark IDs for a scheme. |
|
680
|
|
|
|
|
|
|
|
|
681
|
|
|
|
|
|
|
Only one arguement is accepted and that is the scheme to look under. |
|
682
|
|
|
|
|
|
|
|
|
683
|
|
|
|
|
|
|
my @bookmarkIDs=$zbm->listBookmarks('http'); |
|
684
|
|
|
|
|
|
|
if($zbm->{error}){ |
|
685
|
|
|
|
|
|
|
print "Error!\n"; |
|
686
|
|
|
|
|
|
|
} |
|
687
|
|
|
|
|
|
|
|
|
688
|
|
|
|
|
|
|
=cut |
|
689
|
|
|
|
|
|
|
|
|
690
|
|
|
|
|
|
|
sub listBookmarks{ |
|
691
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
692
|
0
|
|
|
|
|
|
my $scheme=$_[1]; |
|
693
|
|
|
|
|
|
|
|
|
694
|
|
|
|
|
|
|
#blanks any previous errors |
|
695
|
0
|
|
|
|
|
|
$self->errorblank; |
|
696
|
|
|
|
|
|
|
|
|
697
|
0
|
0
|
|
|
|
|
if (!defined($scheme)) { |
|
698
|
0
|
|
|
|
|
|
warn("ZConf-Bookmarks listBookmarks:3: No scheme type specified"); |
|
699
|
0
|
|
|
|
|
|
$self->{error}=3; |
|
700
|
0
|
|
|
|
|
|
$self->{errorString}="No scheme type specified"; |
|
701
|
0
|
|
|
|
|
|
return undef; |
|
702
|
|
|
|
|
|
|
} |
|
703
|
|
|
|
|
|
|
#convert it to lowercase |
|
704
|
0
|
|
|
|
|
|
$scheme=lc($scheme); |
|
705
|
|
|
|
|
|
|
|
|
706
|
|
|
|
|
|
|
#check if it exists |
|
707
|
0
|
|
|
|
|
|
my $returned=$self->schemeExists($scheme); |
|
708
|
0
|
0
|
|
|
|
|
if ($self->{error}) { |
|
709
|
0
|
|
|
|
|
|
warn('ZConf-Bookmarks listBookmarks: schemeExists errored'); |
|
710
|
0
|
|
|
|
|
|
return undef; |
|
711
|
|
|
|
|
|
|
} |
|
712
|
|
|
|
|
|
|
|
|
713
|
|
|
|
|
|
|
#error if it does not exist |
|
714
|
0
|
0
|
|
|
|
|
if (!$returned) { |
|
715
|
0
|
|
|
|
|
|
warn('ZConf-Bookmarks listbookmarks:7: The scheme "'.$scheme.'" does not exist'); |
|
716
|
0
|
|
|
|
|
|
$self->{error}=7; |
|
717
|
0
|
|
|
|
|
|
$self->{errorString}='The scheme "'.$scheme.'" does not exist'; |
|
718
|
|
|
|
|
|
|
} |
|
719
|
|
|
|
|
|
|
|
|
720
|
0
|
|
|
|
|
|
my @bookmarks=$self->{zconf}->regexVarSearch('bookmarks', '^schemes\/'.$scheme); |
|
721
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->{error}) { |
|
722
|
0
|
|
|
|
|
|
$self->{error}=2; |
|
723
|
0
|
|
|
|
|
|
$self->{errorString}="regexVarSearch failed.". |
|
724
|
|
|
|
|
|
|
" It failed with '".$self->{zconf}->{error}."', '" |
|
725
|
|
|
|
|
|
|
.$self->{zconf}->{errorString}."'"; |
|
726
|
0
|
|
|
|
|
|
warn("ZConf-Bookmarks listBookmarks:2".$self->{errorString}); |
|
727
|
0
|
|
|
|
|
|
return undef; |
|
728
|
|
|
|
|
|
|
} |
|
729
|
|
|
|
|
|
|
|
|
730
|
0
|
|
|
|
|
|
my %newBookmarks; |
|
731
|
|
|
|
|
|
|
|
|
732
|
0
|
|
|
|
|
|
my $int=0; |
|
733
|
0
|
|
|
|
|
|
while (defined($bookmarks[$int])) { |
|
734
|
0
|
|
|
|
|
|
my @bookmark=split(/\//, $bookmarks[$int]); |
|
735
|
0
|
|
|
|
|
|
$newBookmarks{$bookmark[2]}=''; |
|
736
|
0
|
|
|
|
|
|
$int++; |
|
737
|
|
|
|
|
|
|
} |
|
738
|
|
|
|
|
|
|
|
|
739
|
0
|
|
|
|
|
|
return keys(%newBookmarks); |
|
740
|
|
|
|
|
|
|
} |
|
741
|
|
|
|
|
|
|
|
|
742
|
|
|
|
|
|
|
=head2 listSchemss |
|
743
|
|
|
|
|
|
|
|
|
744
|
|
|
|
|
|
|
This lists the current schemes available to choose from. |
|
745
|
|
|
|
|
|
|
|
|
746
|
|
|
|
|
|
|
my @schemes=$zbm->listSchemes(); |
|
747
|
|
|
|
|
|
|
if($zbm->{error}){ |
|
748
|
|
|
|
|
|
|
print "Error!\n"; |
|
749
|
|
|
|
|
|
|
} |
|
750
|
|
|
|
|
|
|
|
|
751
|
|
|
|
|
|
|
=cut |
|
752
|
|
|
|
|
|
|
|
|
753
|
|
|
|
|
|
|
sub listSchemes{ |
|
754
|
0
|
|
|
0
|
0
|
|
my $self=$_[0]; |
|
755
|
|
|
|
|
|
|
|
|
756
|
|
|
|
|
|
|
#blanks any previous errors |
|
757
|
0
|
|
|
|
|
|
$self->errorblank; |
|
758
|
|
|
|
|
|
|
|
|
759
|
0
|
|
|
|
|
|
my @schemes=$self->{zconf}->regexVarSearch('bookmarks', '^schemes/'); |
|
760
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->{error}) { |
|
761
|
0
|
|
|
|
|
|
$self->{error}=2; |
|
762
|
0
|
|
|
|
|
|
$self->{errorString}="regexVarSearch failed.". |
|
763
|
|
|
|
|
|
|
" It failed with '".$self->{zconf}->{error}."', '" |
|
764
|
|
|
|
|
|
|
.$self->{zconf}->{errorString}."'"; |
|
765
|
0
|
|
|
|
|
|
warn("ZConf-Bookmarks listSchemes:2:".$self->{errorString}); |
|
766
|
0
|
|
|
|
|
|
return undef; |
|
767
|
|
|
|
|
|
|
} |
|
768
|
|
|
|
|
|
|
|
|
769
|
0
|
|
|
|
|
|
my %newSchemes; |
|
770
|
|
|
|
|
|
|
|
|
771
|
0
|
|
|
|
|
|
my $int=0; |
|
772
|
0
|
|
|
|
|
|
while (defined($schemes[$int])) { |
|
773
|
0
|
|
|
|
|
|
my @scheme=split(/\//, $schemes[$int]); |
|
774
|
0
|
|
|
|
|
|
$newSchemes{$scheme[1]}=''; |
|
775
|
0
|
|
|
|
|
|
$int++; |
|
776
|
|
|
|
|
|
|
} |
|
777
|
|
|
|
|
|
|
|
|
778
|
0
|
|
|
|
|
|
return keys(%newSchemes); |
|
779
|
|
|
|
|
|
|
} |
|
780
|
|
|
|
|
|
|
|
|
781
|
|
|
|
|
|
|
=head2 listSets |
|
782
|
|
|
|
|
|
|
|
|
783
|
|
|
|
|
|
|
This lists the available sets. |
|
784
|
|
|
|
|
|
|
|
|
785
|
|
|
|
|
|
|
my @sets=$zbm->listSets; |
|
786
|
|
|
|
|
|
|
if($zbm->{error}){ |
|
787
|
|
|
|
|
|
|
print "Error!"; |
|
788
|
|
|
|
|
|
|
} |
|
789
|
|
|
|
|
|
|
|
|
790
|
|
|
|
|
|
|
=cut |
|
791
|
|
|
|
|
|
|
|
|
792
|
|
|
|
|
|
|
sub listSets{ |
|
793
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
794
|
|
|
|
|
|
|
|
|
795
|
|
|
|
|
|
|
#blanks any previous errors |
|
796
|
0
|
|
|
|
|
|
$self->errorBlank; |
|
797
|
|
|
|
|
|
|
|
|
798
|
0
|
|
|
|
|
|
my @sets=$self->{zconf}->getAvailableSets('bookmarks'); |
|
799
|
0
|
0
|
|
|
|
|
if($self->{zconf}->{error}){ |
|
800
|
0
|
|
|
|
|
|
warn('ZConf-Bookmarks listSets:2: ZConf error listing sets for the config "bookmarks".'. |
|
801
|
|
|
|
|
|
|
' ZConf error="'.$self->{zconf}->{error}.'" '. |
|
802
|
|
|
|
|
|
|
'ZConf error string="'.$self->{zconf}->{errorString}.'"'); |
|
803
|
0
|
|
|
|
|
|
$self->{error}=2; |
|
804
|
0
|
|
|
|
|
|
$self->{errorString}='ZConf error listing sets for the config "bookmarks".'. |
|
805
|
|
|
|
|
|
|
' ZConf error="'.$self->{zconf}->{error}.'" '. |
|
806
|
|
|
|
|
|
|
'ZConf error string="'.$self->{zconf}->{errorString}.'"'; |
|
807
|
0
|
|
|
|
|
|
return undef; |
|
808
|
|
|
|
|
|
|
} |
|
809
|
|
|
|
|
|
|
|
|
810
|
0
|
|
|
|
|
|
return @sets; |
|
811
|
|
|
|
|
|
|
} |
|
812
|
|
|
|
|
|
|
|
|
813
|
|
|
|
|
|
|
=head2 modBookmark |
|
814
|
|
|
|
|
|
|
|
|
815
|
|
|
|
|
|
|
Modify a bookmark. |
|
816
|
|
|
|
|
|
|
|
|
817
|
|
|
|
|
|
|
Only one arguement is accepted and it is a hash. Please see |
|
818
|
|
|
|
|
|
|
the hash information below for the required keys. |
|
819
|
|
|
|
|
|
|
|
|
820
|
|
|
|
|
|
|
=head3 hash args |
|
821
|
|
|
|
|
|
|
|
|
822
|
|
|
|
|
|
|
=head4 bmid |
|
823
|
|
|
|
|
|
|
|
|
824
|
|
|
|
|
|
|
The bookmark ID to be changed. |
|
825
|
|
|
|
|
|
|
|
|
826
|
|
|
|
|
|
|
=head4 name |
|
827
|
|
|
|
|
|
|
|
|
828
|
|
|
|
|
|
|
This is name for a book mark. |
|
829
|
|
|
|
|
|
|
|
|
830
|
|
|
|
|
|
|
=head4 description |
|
831
|
|
|
|
|
|
|
|
|
832
|
|
|
|
|
|
|
This is a description for the bookmark. |
|
833
|
|
|
|
|
|
|
|
|
834
|
|
|
|
|
|
|
=head4 link |
|
835
|
|
|
|
|
|
|
|
|
836
|
|
|
|
|
|
|
This is the URI, minus scheme. Thus 'http://vvelox.net/' would become |
|
837
|
|
|
|
|
|
|
'vvelox.net'. |
|
838
|
|
|
|
|
|
|
|
|
839
|
|
|
|
|
|
|
=head4 scheme |
|
840
|
|
|
|
|
|
|
|
|
841
|
|
|
|
|
|
|
This is the scheme it should be added it. |
|
842
|
|
|
|
|
|
|
|
|
843
|
|
|
|
|
|
|
my %newBM; |
|
844
|
|
|
|
|
|
|
$newBM{bmid}=$bmid; |
|
845
|
|
|
|
|
|
|
$newBM{description}='VVelox.net'; |
|
846
|
|
|
|
|
|
|
$newBM{name}='VVelox.net'; |
|
847
|
|
|
|
|
|
|
$newBM{link}='vvelox.net'; |
|
848
|
|
|
|
|
|
|
$newBM{scheme}='http'; |
|
849
|
|
|
|
|
|
|
$zbm->modBookmark(%newBM); |
|
850
|
|
|
|
|
|
|
if($zbm->{error}){ |
|
851
|
|
|
|
|
|
|
print "Error!\n"; |
|
852
|
|
|
|
|
|
|
} |
|
853
|
|
|
|
|
|
|
|
|
854
|
|
|
|
|
|
|
=cut |
|
855
|
|
|
|
|
|
|
|
|
856
|
|
|
|
|
|
|
sub modBookmark{ |
|
857
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
858
|
0
|
|
|
|
|
|
my %args; |
|
859
|
0
|
0
|
|
|
|
|
if(defined($_[1])){ |
|
860
|
0
|
|
|
|
|
|
%args= %{$_[1]}; |
|
|
0
|
|
|
|
|
|
|
|
861
|
|
|
|
|
|
|
} |
|
862
|
|
|
|
|
|
|
|
|
863
|
|
|
|
|
|
|
#blanks any previous errors |
|
864
|
0
|
|
|
|
|
|
$self->errorblank; |
|
865
|
|
|
|
|
|
|
|
|
866
|
0
|
0
|
|
|
|
|
if (!defined($args{scheme})) { |
|
867
|
0
|
|
|
|
|
|
warn("ZConf-Bookmarks modBookmark:3: No scheme type specified"); |
|
868
|
0
|
|
|
|
|
|
$self->{error}=3; |
|
869
|
0
|
|
|
|
|
|
$self->{errorString}="No scheme type specified"; |
|
870
|
0
|
|
|
|
|
|
return undef; |
|
871
|
|
|
|
|
|
|
} |
|
872
|
|
|
|
|
|
|
#convert it to lowercase |
|
873
|
0
|
|
|
|
|
|
$args{scheme}=lc($args{scheme}); |
|
874
|
|
|
|
|
|
|
|
|
875
|
|
|
|
|
|
|
|
|
876
|
|
|
|
|
|
|
#makes sure a name is specified |
|
877
|
0
|
0
|
|
|
|
|
if (!defined($args{name})) { |
|
878
|
0
|
|
|
|
|
|
warn('ZConf-Bookmarks modBookmark:3: No name, $args{name}, type specified'); |
|
879
|
0
|
|
|
|
|
|
$self->{error}=3; |
|
880
|
0
|
|
|
|
|
|
$self->{errorString}="No name, $args{name}, type specified'"; |
|
881
|
0
|
|
|
|
|
|
return undef; |
|
882
|
|
|
|
|
|
|
} |
|
883
|
|
|
|
|
|
|
|
|
884
|
|
|
|
|
|
|
#makes sure a URI scheme type is specified |
|
885
|
0
|
0
|
|
|
|
|
if (!defined($args{scheme})) { |
|
886
|
0
|
|
|
|
|
|
warn('ZConf-Bookmarks modBookmark:3: No URI scheme, $args{name}, specified'); |
|
887
|
0
|
|
|
|
|
|
$self->{error}=3; |
|
888
|
0
|
|
|
|
|
|
$self->{errorString}="No URI scheme, $args{URI}, specified'"; |
|
889
|
0
|
|
|
|
|
|
return undef; |
|
890
|
|
|
|
|
|
|
} |
|
891
|
|
|
|
|
|
|
|
|
892
|
|
|
|
|
|
|
#makes sure a description is specified |
|
893
|
0
|
0
|
|
|
|
|
if (!defined($args{description})) { |
|
894
|
0
|
|
|
|
|
|
warn('ZConf-Bookmarks modBookmark:3: No description, $args{description}, specified'); |
|
895
|
0
|
|
|
|
|
|
$self->{error}=3; |
|
896
|
0
|
|
|
|
|
|
$self->{errorString}="No description, $args{description}, specified'"; |
|
897
|
0
|
|
|
|
|
|
return undef; |
|
898
|
|
|
|
|
|
|
} |
|
899
|
|
|
|
|
|
|
|
|
900
|
|
|
|
|
|
|
#makes sure a link is specified |
|
901
|
0
|
0
|
|
|
|
|
if (!defined($args{'link'})) { |
|
902
|
0
|
|
|
|
|
|
warn('ZConf-Bookmarks modBookmark:3: No link, $args{description}, specified'); |
|
903
|
0
|
|
|
|
|
|
$self->{error}=3; |
|
904
|
0
|
|
|
|
|
|
$self->{errorString}='No link, $args{"link"}, specified'; |
|
905
|
0
|
|
|
|
|
|
return undef; |
|
906
|
|
|
|
|
|
|
} |
|
907
|
|
|
|
|
|
|
|
|
908
|
|
|
|
|
|
|
#makes sure a link is specified |
|
909
|
0
|
0
|
|
|
|
|
if (!defined($args{'bmid'})) { |
|
910
|
0
|
|
|
|
|
|
warn('ZConf-Bookmarks modBookmark:3: No bookmark ID, $args{bmid}, specified'); |
|
911
|
0
|
|
|
|
|
|
$self->{error}=3; |
|
912
|
0
|
|
|
|
|
|
$self->{errorString}='No bookmark ID, $args{"bmid"}, specified'; |
|
913
|
0
|
|
|
|
|
|
return undef; |
|
914
|
|
|
|
|
|
|
} |
|
915
|
|
|
|
|
|
|
|
|
916
|
|
|
|
|
|
|
|
|
917
|
0
|
|
|
|
|
|
my $bookmarkExists=undef; |
|
918
|
0
|
|
|
|
|
|
$bookmarkExists=$self->bookmarkExists($args{scheme}, $args{bmid}); |
|
919
|
0
|
0
|
|
|
|
|
if ($self->{error}) { |
|
920
|
0
|
|
|
|
|
|
warn('ZConf-Bookmarks addBookmark: bookmarkExists errored'); |
|
921
|
0
|
|
|
|
|
|
return undef; |
|
922
|
|
|
|
|
|
|
} |
|
923
|
|
|
|
|
|
|
|
|
924
|
0
|
0
|
|
|
|
|
if (!$bookmarkExists) { |
|
925
|
0
|
|
|
|
|
|
warn('ZConf-Bookmarks modBookark:6: The bookmark ID "'.$args{bmid}. |
|
926
|
|
|
|
|
|
|
'" does not exist'); |
|
927
|
0
|
|
|
|
|
|
$self->{error}=6; |
|
928
|
0
|
|
|
|
|
|
$self->{errorString}='The bookmark ID "'.$args{bmid}.'" does not exist'; |
|
929
|
0
|
|
|
|
|
|
return undef; |
|
930
|
|
|
|
|
|
|
} |
|
931
|
|
|
|
|
|
|
|
|
932
|
0
|
|
|
|
|
|
my $bmVar='schemes/'.$args{scheme}.'/'.$args{bmid}.'/'; |
|
933
|
|
|
|
|
|
|
|
|
934
|
0
|
|
|
|
|
|
$self->{zconf}->setVar('bookmarks', $bmVar.'name', $args{name}); |
|
935
|
|
|
|
|
|
|
#if for some uber unlikely this fails, error |
|
936
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->{error}) { |
|
937
|
0
|
|
|
|
|
|
warn('ZConf-Bookmarks addBookmark:5: setVar failed... var="'.$bmVar.'name"'. |
|
938
|
|
|
|
|
|
|
' value="'.$args{name}.'"'); |
|
939
|
0
|
|
|
|
|
|
$self->{error}=5; |
|
940
|
0
|
|
|
|
|
|
$self->{errorString}='setVar failed... var="'.$bmVar.'name"'. |
|
941
|
|
|
|
|
|
|
' value="'.$args{name}.'"'; |
|
942
|
0
|
|
|
|
|
|
return undef; |
|
943
|
|
|
|
|
|
|
} |
|
944
|
|
|
|
|
|
|
|
|
945
|
|
|
|
|
|
|
#this changes the rest |
|
946
|
0
|
|
|
|
|
|
$self->{zconf}->setVar('bookmarks', $bmVar.'link', $args{link}); |
|
947
|
0
|
|
|
|
|
|
$self->{zconf}->setVar('bookmarks', $bmVar.'description', $args{description}); |
|
948
|
0
|
|
|
|
|
|
$self->{zconf}->setVar('bookmarks', $bmVar.'lastModified', gmtime()); |
|
949
|
|
|
|
|
|
|
|
|
950
|
0
|
|
|
|
|
|
$self->{zconf}->writeSetFromLoadedConfig({config=>'bookmarks'}); |
|
951
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->{error}) { |
|
952
|
0
|
|
|
|
|
|
warn('ZConf-Bookmarks modBookmark:2: writeSetFromLoadedConfig failed. '. |
|
953
|
|
|
|
|
|
|
'error="'.$self->{zconf}->{error}.'" errorString="'. |
|
954
|
|
|
|
|
|
|
$self->{zconf}->{errorString}.'"'); |
|
955
|
0
|
|
|
|
|
|
$self->{error}=2; |
|
956
|
0
|
|
|
|
|
|
$self->{errorString}='writeSetFromLoadedConfig failed. '. |
|
957
|
|
|
|
|
|
|
'error="'.$self->{zconf}->{error}. |
|
958
|
|
|
|
|
|
|
'" errorString="'. |
|
959
|
|
|
|
|
|
|
$self->{zconf}->{errorString}.'"'; |
|
960
|
0
|
|
|
|
|
|
return undef; |
|
961
|
|
|
|
|
|
|
} |
|
962
|
|
|
|
|
|
|
|
|
963
|
0
|
|
|
|
|
|
return 1; |
|
964
|
|
|
|
|
|
|
} |
|
965
|
|
|
|
|
|
|
|
|
966
|
|
|
|
|
|
|
=head2 schemeExists |
|
967
|
|
|
|
|
|
|
|
|
968
|
|
|
|
|
|
|
This checks if a scheme has any thing setup or not. |
|
969
|
|
|
|
|
|
|
|
|
970
|
|
|
|
|
|
|
Only one option is accepted and that is the scheme to check for. |
|
971
|
|
|
|
|
|
|
|
|
972
|
|
|
|
|
|
|
You do have to check the return value as it will contain if it |
|
973
|
|
|
|
|
|
|
exists or not. $zbm->{error} is only true if there is an error |
|
974
|
|
|
|
|
|
|
and for this the scheme not existing is not considered an error. |
|
975
|
|
|
|
|
|
|
|
|
976
|
|
|
|
|
|
|
my $returned=$zbm->schemeExists('http'); |
|
977
|
|
|
|
|
|
|
if($zbm->{error}){ |
|
978
|
|
|
|
|
|
|
print "Error!\n"; |
|
979
|
|
|
|
|
|
|
}else{ |
|
980
|
|
|
|
|
|
|
if($returned){ |
|
981
|
|
|
|
|
|
|
print "It exists.\n"; |
|
982
|
|
|
|
|
|
|
}else{ |
|
983
|
|
|
|
|
|
|
print "It does not exists.\n"; |
|
984
|
|
|
|
|
|
|
} |
|
985
|
|
|
|
|
|
|
} |
|
986
|
|
|
|
|
|
|
|
|
987
|
|
|
|
|
|
|
=cut |
|
988
|
|
|
|
|
|
|
|
|
989
|
|
|
|
|
|
|
sub schemeExists{ |
|
990
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
991
|
0
|
|
|
|
|
|
my $scheme=$_[1]; |
|
992
|
|
|
|
|
|
|
|
|
993
|
|
|
|
|
|
|
#blanks any previous errors |
|
994
|
0
|
|
|
|
|
|
$self->errorblank; |
|
995
|
|
|
|
|
|
|
|
|
996
|
0
|
0
|
|
|
|
|
if (!defined($scheme)) { |
|
997
|
0
|
|
|
|
|
|
warn("ZConf-Bookmarks schemeExists:3: No scheme type specified"); |
|
998
|
0
|
|
|
|
|
|
$self->{error}=3; |
|
999
|
0
|
|
|
|
|
|
$self->{errorString}="No scheme type specified"; |
|
1000
|
0
|
|
|
|
|
|
return undef; |
|
1001
|
|
|
|
|
|
|
} |
|
1002
|
|
|
|
|
|
|
#convert it to lowercase |
|
1003
|
0
|
|
|
|
|
|
$scheme=lc($scheme); |
|
1004
|
|
|
|
|
|
|
|
|
1005
|
0
|
|
|
|
|
|
my @schemes=$self->listSchemes(); |
|
1006
|
0
|
0
|
|
|
|
|
if ($self->{error}) { |
|
1007
|
0
|
|
|
|
|
|
warn("ZConf-Bookmarks schemeExists:3: listSchemes errored"); |
|
1008
|
0
|
|
|
|
|
|
return undef; |
|
1009
|
|
|
|
|
|
|
} |
|
1010
|
|
|
|
|
|
|
|
|
1011
|
|
|
|
|
|
|
#go through each one looking for matches |
|
1012
|
0
|
|
|
|
|
|
my $int=0; |
|
1013
|
0
|
|
|
|
|
|
while (defined($schemes[$int])) { |
|
1014
|
0
|
0
|
|
|
|
|
if ($scheme eq $schemes[$int]) { |
|
1015
|
0
|
|
|
|
|
|
return 1; |
|
1016
|
|
|
|
|
|
|
} |
|
1017
|
|
|
|
|
|
|
|
|
1018
|
0
|
|
|
|
|
|
$int++; |
|
1019
|
|
|
|
|
|
|
} |
|
1020
|
|
|
|
|
|
|
|
|
1021
|
0
|
|
|
|
|
|
return undef; |
|
1022
|
|
|
|
|
|
|
} |
|
1023
|
|
|
|
|
|
|
|
|
1024
|
|
|
|
|
|
|
=head2 readSet |
|
1025
|
|
|
|
|
|
|
|
|
1026
|
|
|
|
|
|
|
This reads a specific set. If the set specified |
|
1027
|
|
|
|
|
|
|
is undef, the default set is read. |
|
1028
|
|
|
|
|
|
|
|
|
1029
|
|
|
|
|
|
|
#read the default set |
|
1030
|
|
|
|
|
|
|
$zcr->readSet(); |
|
1031
|
|
|
|
|
|
|
if($zcr->{error}){ |
|
1032
|
|
|
|
|
|
|
print "Error!\n"; |
|
1033
|
|
|
|
|
|
|
} |
|
1034
|
|
|
|
|
|
|
|
|
1035
|
|
|
|
|
|
|
#read the set 'someSet' |
|
1036
|
|
|
|
|
|
|
$zcr->readSet('someSet'); |
|
1037
|
|
|
|
|
|
|
if($zcr->{error}){ |
|
1038
|
|
|
|
|
|
|
print "Error!\n"; |
|
1039
|
|
|
|
|
|
|
} |
|
1040
|
|
|
|
|
|
|
|
|
1041
|
|
|
|
|
|
|
=cut |
|
1042
|
|
|
|
|
|
|
|
|
1043
|
|
|
|
|
|
|
sub readSet{ |
|
1044
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
1045
|
0
|
|
|
|
|
|
my $set=$_[1]; |
|
1046
|
|
|
|
|
|
|
|
|
1047
|
|
|
|
|
|
|
|
|
1048
|
|
|
|
|
|
|
#blanks any previous errors |
|
1049
|
0
|
|
|
|
|
|
$self->errorBlank; |
|
1050
|
|
|
|
|
|
|
|
|
1051
|
0
|
|
|
|
|
|
$self->{zconf}->read({config=>'bookmarks', set=>$set}); |
|
1052
|
0
|
0
|
|
|
|
|
if ($self->{zconf}->{error}) { |
|
1053
|
0
|
|
|
|
|
|
warn('ZConf-Bookmarks readSet:2: ZConf error reading the config "bookmarks".'. |
|
1054
|
|
|
|
|
|
|
' ZConf error="'.$self->{zconf}->{error}.'" '. |
|
1055
|
|
|
|
|
|
|
'ZConf error string="'.$self->{zconf}->{errorString}.'"'); |
|
1056
|
0
|
|
|
|
|
|
$self->{error}=2; |
|
1057
|
0
|
|
|
|
|
|
$self->{errorString}='ZConf error reading the config "bookmarks".'. |
|
1058
|
|
|
|
|
|
|
' ZConf error="'.$self->{zconf}->{error}.'" '. |
|
1059
|
|
|
|
|
|
|
'ZConf error string="'.$self->{zconf}->{errorString}.'"'; |
|
1060
|
0
|
|
|
|
|
|
return undef; |
|
1061
|
|
|
|
|
|
|
} |
|
1062
|
|
|
|
|
|
|
|
|
1063
|
0
|
|
|
|
|
|
return 1; |
|
1064
|
|
|
|
|
|
|
} |
|
1065
|
|
|
|
|
|
|
|
|
1066
|
|
|
|
|
|
|
=head2 errorblank |
|
1067
|
|
|
|
|
|
|
|
|
1068
|
|
|
|
|
|
|
This blanks the error storage and is only meant for internal usage. |
|
1069
|
|
|
|
|
|
|
|
|
1070
|
|
|
|
|
|
|
It does the following. |
|
1071
|
|
|
|
|
|
|
|
|
1072
|
|
|
|
|
|
|
$self->{error}=undef; |
|
1073
|
|
|
|
|
|
|
$self->{errorString}=""; |
|
1074
|
|
|
|
|
|
|
|
|
1075
|
|
|
|
|
|
|
=cut |
|
1076
|
|
|
|
|
|
|
|
|
1077
|
|
|
|
|
|
|
#blanks the error flags |
|
1078
|
|
|
|
|
|
|
sub errorblank{ |
|
1079
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
|
1080
|
|
|
|
|
|
|
|
|
1081
|
0
|
|
|
|
|
|
$self->{error}=undef; |
|
1082
|
0
|
|
|
|
|
|
$self->{errorString}=""; |
|
1083
|
|
|
|
|
|
|
|
|
1084
|
0
|
|
|
|
|
|
return 1; |
|
1085
|
|
|
|
|
|
|
} |
|
1086
|
|
|
|
|
|
|
|
|
1087
|
|
|
|
|
|
|
=head1 ERROR CODES |
|
1088
|
|
|
|
|
|
|
|
|
1089
|
|
|
|
|
|
|
=head2 1 |
|
1090
|
|
|
|
|
|
|
|
|
1091
|
|
|
|
|
|
|
Could not initialize ZConf. |
|
1092
|
|
|
|
|
|
|
|
|
1093
|
|
|
|
|
|
|
=head2 2 |
|
1094
|
|
|
|
|
|
|
|
|
1095
|
|
|
|
|
|
|
ZConf error. |
|
1096
|
|
|
|
|
|
|
|
|
1097
|
|
|
|
|
|
|
=head2 3 |
|
1098
|
|
|
|
|
|
|
|
|
1099
|
|
|
|
|
|
|
Missing a required arguement. |
|
1100
|
|
|
|
|
|
|
|
|
1101
|
|
|
|
|
|
|
=head2 4 |
|
1102
|
|
|
|
|
|
|
|
|
1103
|
|
|
|
|
|
|
The highly unlikely event that there a duplicate bookmark ID exists after three |
|
1104
|
|
|
|
|
|
|
attempts to generate one has happened. If this happens, it means your the local time |
|
1105
|
|
|
|
|
|
|
function, or your system clock, and rand number generator are fragged. |
|
1106
|
|
|
|
|
|
|
|
|
1107
|
|
|
|
|
|
|
=head2 5 |
|
1108
|
|
|
|
|
|
|
|
|
1109
|
|
|
|
|
|
|
For some uber add the use of setVar here failed. |
|
1110
|
|
|
|
|
|
|
|
|
1111
|
|
|
|
|
|
|
=head2 6 |
|
1112
|
|
|
|
|
|
|
|
|
1113
|
|
|
|
|
|
|
Bookmark does not exist. |
|
1114
|
|
|
|
|
|
|
|
|
1115
|
|
|
|
|
|
|
=head2 7 |
|
1116
|
|
|
|
|
|
|
|
|
1117
|
|
|
|
|
|
|
Scheme does not exist. |
|
1118
|
|
|
|
|
|
|
|
|
1119
|
|
|
|
|
|
|
=head1 AUTHOR |
|
1120
|
|
|
|
|
|
|
|
|
1121
|
|
|
|
|
|
|
Zane C. Bowers, C<< >> |
|
1122
|
|
|
|
|
|
|
|
|
1123
|
|
|
|
|
|
|
=head1 BUGS |
|
1124
|
|
|
|
|
|
|
|
|
1125
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
|
1126
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
|
1127
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
|
1128
|
|
|
|
|
|
|
|
|
1129
|
|
|
|
|
|
|
|
|
1130
|
|
|
|
|
|
|
|
|
1131
|
|
|
|
|
|
|
|
|
1132
|
|
|
|
|
|
|
=head1 SUPPORT |
|
1133
|
|
|
|
|
|
|
|
|
1134
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
|
1135
|
|
|
|
|
|
|
|
|
1136
|
|
|
|
|
|
|
perldoc ZConf::Bookmarks |
|
1137
|
|
|
|
|
|
|
|
|
1138
|
|
|
|
|
|
|
|
|
1139
|
|
|
|
|
|
|
You can also look for information at: |
|
1140
|
|
|
|
|
|
|
|
|
1141
|
|
|
|
|
|
|
=over 4 |
|
1142
|
|
|
|
|
|
|
|
|
1143
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
|
1144
|
|
|
|
|
|
|
|
|
1145
|
|
|
|
|
|
|
L |
|
1146
|
|
|
|
|
|
|
|
|
1147
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
1148
|
|
|
|
|
|
|
|
|
1149
|
|
|
|
|
|
|
L |
|
1150
|
|
|
|
|
|
|
|
|
1151
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
1152
|
|
|
|
|
|
|
|
|
1153
|
|
|
|
|
|
|
L |
|
1154
|
|
|
|
|
|
|
|
|
1155
|
|
|
|
|
|
|
=item * Search CPAN |
|
1156
|
|
|
|
|
|
|
|
|
1157
|
|
|
|
|
|
|
L |
|
1158
|
|
|
|
|
|
|
|
|
1159
|
|
|
|
|
|
|
=back |
|
1160
|
|
|
|
|
|
|
|
|
1161
|
|
|
|
|
|
|
|
|
1162
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
1163
|
|
|
|
|
|
|
|
|
1164
|
|
|
|
|
|
|
|
|
1165
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
|
1166
|
|
|
|
|
|
|
|
|
1167
|
|
|
|
|
|
|
Copyright 2009 Zane C. Bowers, all rights reserved. |
|
1168
|
|
|
|
|
|
|
|
|
1169
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
1170
|
|
|
|
|
|
|
under the same terms as Perl itself. |
|
1171
|
|
|
|
|
|
|
|
|
1172
|
|
|
|
|
|
|
|
|
1173
|
|
|
|
|
|
|
=cut |
|
1174
|
|
|
|
|
|
|
|
|
1175
|
|
|
|
|
|
|
1; # End of ZConf::Bookmarks |