Fossil SCM

Create a new interface for checking to see if a tag exists in the robot-restrict setting.

drh 2025-08-19 16:57 trunk
Commit 8784c600ceaaf1e39d5b18f550fb45b651b0321baa8ee4b5f52c26c058a645fd
1 file changed +19 -11
+19 -11
--- src/robot.c
+++ src/robot.c
@@ -270,10 +270,27 @@
270270
** Return the default restriction GLOB
271271
*/
272272
const char *robot_restrict_default(void){
273273
return "timelineX,diff,annotate,zip,fileage,file";
274274
}
275
+
276
+/*
277
+** Return true if zTag matches one of the tags in the robot-restrict
278
+** setting.
279
+*/
280
+int robot_restrict_has_tag(const char *zTag){
281
+ static const char *zGlob = 0;
282
+ if( zGlob==0 ){
283
+ zGlob = db_get("robot-restrict",robot_restrict_default());
284
+ if( zGlob==0 ) zGlob = "";
285
+ }
286
+ if( zGlob[0]==0 || fossil_strcmp(zGlob, "off")==0 ){
287
+ return 0;
288
+ }
289
+ return glob_multi_match(zGlob,zTag);
290
+}
291
+
275292
/*
276293
** Check to see if the page named in the argument is on the
277294
** robot-restrict list. If it is on the list and if the user
278295
** is "nobody" then bring up a captcha to test to make sure that
279296
** client is not a robot.
@@ -280,22 +297,13 @@
280297
**
281298
** This routine returns true if a captcha was rendered and if subsequent
282299
** page generation should be aborted. It returns false if the page
283300
** should not be restricted and should be rendered normally.
284301
*/
285
-int robot_restrict(const char *zPage){
286
- const char *zGlob;
287
- static int bKnownPass = 0;
288
-
302
+int robot_restrict(const char *zTag){
289303
if( robot.resultCache==KNOWN_NOT_ROBOT ) return 0;
290
- if( bKnownPass ) return 0;
291
- zGlob = db_get("robot-restrict",robot_restrict_default());
292
- if( zGlob==0 || zGlob[0]==0 || fossil_strcmp(zGlob, "off")==0 ){
293
- bKnownPass = 1;
294
- return 0; /* Robot restriction is turned off */
295
- }
296
- if( !glob_multi_match(zGlob, zPage) ) return 0;
304
+ if( !robot_restrict_has_tag(zTag) ) return 0;
297305
if( !client_might_be_a_robot() ) return 0;
298306
299307
/* Generate the proof-of-work captcha */
300308
ask_for_proof_that_client_is_not_robot();
301309
return 1;
302310
--- src/robot.c
+++ src/robot.c
@@ -270,10 +270,27 @@
270 ** Return the default restriction GLOB
271 */
272 const char *robot_restrict_default(void){
273 return "timelineX,diff,annotate,zip,fileage,file";
274 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
275 /*
276 ** Check to see if the page named in the argument is on the
277 ** robot-restrict list. If it is on the list and if the user
278 ** is "nobody" then bring up a captcha to test to make sure that
279 ** client is not a robot.
@@ -280,22 +297,13 @@
280 **
281 ** This routine returns true if a captcha was rendered and if subsequent
282 ** page generation should be aborted. It returns false if the page
283 ** should not be restricted and should be rendered normally.
284 */
285 int robot_restrict(const char *zPage){
286 const char *zGlob;
287 static int bKnownPass = 0;
288
289 if( robot.resultCache==KNOWN_NOT_ROBOT ) return 0;
290 if( bKnownPass ) return 0;
291 zGlob = db_get("robot-restrict",robot_restrict_default());
292 if( zGlob==0 || zGlob[0]==0 || fossil_strcmp(zGlob, "off")==0 ){
293 bKnownPass = 1;
294 return 0; /* Robot restriction is turned off */
295 }
296 if( !glob_multi_match(zGlob, zPage) ) return 0;
297 if( !client_might_be_a_robot() ) return 0;
298
299 /* Generate the proof-of-work captcha */
300 ask_for_proof_that_client_is_not_robot();
301 return 1;
302
--- src/robot.c
+++ src/robot.c
@@ -270,10 +270,27 @@
270 ** Return the default restriction GLOB
271 */
272 const char *robot_restrict_default(void){
273 return "timelineX,diff,annotate,zip,fileage,file";
274 }
275
276 /*
277 ** Return true if zTag matches one of the tags in the robot-restrict
278 ** setting.
279 */
280 int robot_restrict_has_tag(const char *zTag){
281 static const char *zGlob = 0;
282 if( zGlob==0 ){
283 zGlob = db_get("robot-restrict",robot_restrict_default());
284 if( zGlob==0 ) zGlob = "";
285 }
286 if( zGlob[0]==0 || fossil_strcmp(zGlob, "off")==0 ){
287 return 0;
288 }
289 return glob_multi_match(zGlob,zTag);
290 }
291
292 /*
293 ** Check to see if the page named in the argument is on the
294 ** robot-restrict list. If it is on the list and if the user
295 ** is "nobody" then bring up a captcha to test to make sure that
296 ** client is not a robot.
@@ -280,22 +297,13 @@
297 **
298 ** This routine returns true if a captcha was rendered and if subsequent
299 ** page generation should be aborted. It returns false if the page
300 ** should not be restricted and should be rendered normally.
301 */
302 int robot_restrict(const char *zTag){
 
 
 
303 if( robot.resultCache==KNOWN_NOT_ROBOT ) return 0;
304 if( !robot_restrict_has_tag(zTag) ) return 0;
 
 
 
 
 
 
305 if( !client_might_be_a_robot() ) return 0;
306
307 /* Generate the proof-of-work captcha */
308 ask_for_proof_that_client_is_not_robot();
309 return 1;
310

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button