Fossil SCM
Create a new interface for checking to see if a tag exists in the robot-restrict setting.
Commit
8784c600ceaaf1e39d5b18f550fb45b651b0321baa8ee4b5f52c26c058a645fd
Parent
3d32a109301d1ca…
1 file changed
+19
-11
+19
-11
| --- src/robot.c | ||
| +++ src/robot.c | ||
| @@ -270,10 +270,27 @@ | ||
| 270 | 270 | ** Return the default restriction GLOB |
| 271 | 271 | */ |
| 272 | 272 | const char *robot_restrict_default(void){ |
| 273 | 273 | return "timelineX,diff,annotate,zip,fileage,file"; |
| 274 | 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 | + | |
| 275 | 292 | /* |
| 276 | 293 | ** Check to see if the page named in the argument is on the |
| 277 | 294 | ** robot-restrict list. If it is on the list and if the user |
| 278 | 295 | ** is "nobody" then bring up a captcha to test to make sure that |
| 279 | 296 | ** client is not a robot. |
| @@ -280,22 +297,13 @@ | ||
| 280 | 297 | ** |
| 281 | 298 | ** This routine returns true if a captcha was rendered and if subsequent |
| 282 | 299 | ** page generation should be aborted. It returns false if the page |
| 283 | 300 | ** should not be restricted and should be rendered normally. |
| 284 | 301 | */ |
| 285 | -int robot_restrict(const char *zPage){ | |
| 286 | - const char *zGlob; | |
| 287 | - static int bKnownPass = 0; | |
| 288 | - | |
| 302 | +int robot_restrict(const char *zTag){ | |
| 289 | 303 | 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; | |
| 297 | 305 | if( !client_might_be_a_robot() ) return 0; |
| 298 | 306 | |
| 299 | 307 | /* Generate the proof-of-work captcha */ |
| 300 | 308 | ask_for_proof_that_client_is_not_robot(); |
| 301 | 309 | return 1; |
| 302 | 310 |
| --- 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 |