Fossil SCM
When the "name" parameter for the /artifact webpage (and similar pages) is ambiguous, bring up a page that allows the user to choose between the various options. Ticket [901936cf06df1b9b9a].
Commit
d02115bbf0a001d3123c5838215d222acd9253ad
Parent
d4125d551e6669f…
2 files changed
+11
-10
+75
-3
+11
-10
| --- src/info.c | ||
| +++ src/info.c | ||
| @@ -269,12 +269,12 @@ | ||
| 269 | 269 | int showDiff; |
| 270 | 270 | const char *zName; |
| 271 | 271 | |
| 272 | 272 | login_check_credentials(); |
| 273 | 273 | if( !g.okRead ){ login_needed(); return; } |
| 274 | - zName = PD("name","0"); | |
| 275 | - rid = name_to_rid(zName); | |
| 274 | + zName = P("name"); | |
| 275 | + rid = name_to_rid_www("name"); | |
| 276 | 276 | if( rid==0 ){ |
| 277 | 277 | style_header("Check-in Information Error"); |
| 278 | 278 | @ No such object: %h(g.argv[2]) |
| 279 | 279 | style_footer(); |
| 280 | 280 | return; |
| @@ -456,11 +456,11 @@ | ||
| 456 | 456 | Stmt q; |
| 457 | 457 | int rid; |
| 458 | 458 | |
| 459 | 459 | login_check_credentials(); |
| 460 | 460 | if( !g.okRdWiki ){ login_needed(); return; } |
| 461 | - rid = name_to_rid(PD("name","0")); | |
| 461 | + rid = name_to_rid_www("name"); | |
| 462 | 462 | if( rid==0 ){ |
| 463 | 463 | style_header("Wiki Page Information Error"); |
| 464 | 464 | @ No such object: %h(g.argv[2]) |
| 465 | 465 | style_footer(); |
| 466 | 466 | return; |
| @@ -542,11 +542,11 @@ | ||
| 542 | 542 | |
| 543 | 543 | login_check_credentials(); |
| 544 | 544 | if( !g.okRead ){ login_needed(); return; } |
| 545 | 545 | login_anonymous_available(); |
| 546 | 546 | |
| 547 | - rid = name_to_rid(PD("name","")); | |
| 547 | + rid = name_to_rid_www("name"); | |
| 548 | 548 | if( rid==0 ){ |
| 549 | 549 | fossil_redirect_home(); |
| 550 | 550 | } |
| 551 | 551 | zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid); |
| 552 | 552 | style_header("Check-in [%.10s]", zUuid); |
| @@ -610,11 +610,11 @@ | ||
| 610 | 610 | ** |
| 611 | 611 | ** * It's artifact ID |
| 612 | 612 | ** * date of check-in |
| 613 | 613 | ** * Comment & user |
| 614 | 614 | */ |
| 615 | -static void object_description( | |
| 615 | +void object_description( | |
| 616 | 616 | int rid, /* The artifact ID */ |
| 617 | 617 | int linkToView, /* Add viewer link if true */ |
| 618 | 618 | Blob *pDownloadName /* Fill with an appropriate download name */ |
| 619 | 619 | ){ |
| 620 | 620 | Stmt q; |
| @@ -735,11 +735,11 @@ | ||
| 735 | 735 | } |
| 736 | 736 | db_prepare(&q, |
| 737 | 737 | "SELECT target, filename, datetime(mtime), user, src" |
| 738 | 738 | " FROM attachment" |
| 739 | 739 | " WHERE src=(SELECT uuid FROM blob WHERE rid=%d)" |
| 740 | - " ORDER BY mtime DESC", | |
| 740 | + " ORDER BY mtime DESC /*sort*/", | |
| 741 | 741 | rid |
| 742 | 742 | ); |
| 743 | 743 | while( db_step(&q)==SQLITE_ROW ){ |
| 744 | 744 | const char *zTarget = db_column_text(&q, 0); |
| 745 | 745 | const char *zFilename = db_column_text(&q, 1); |
| @@ -797,10 +797,11 @@ | ||
| 797 | 797 | int v2 = name_to_rid(P("v2")); |
| 798 | 798 | Blob c1, c2, diff; |
| 799 | 799 | |
| 800 | 800 | login_check_credentials(); |
| 801 | 801 | if( !g.okRead ){ login_needed(); return; } |
| 802 | + if( v1==0 || v2==0 ) fossil_redirect_home(); | |
| 802 | 803 | style_header("Diff"); |
| 803 | 804 | @ <h2>Differences From:</h2> |
| 804 | 805 | @ <blockquote> |
| 805 | 806 | object_description(v1, 1, 0); |
| 806 | 807 | @ </blockquote> |
| @@ -832,11 +833,11 @@ | ||
| 832 | 833 | void rawartifact_page(void){ |
| 833 | 834 | int rid; |
| 834 | 835 | const char *zMime; |
| 835 | 836 | Blob content; |
| 836 | 837 | |
| 837 | - rid = name_to_rid(PD("name","0")); | |
| 838 | + rid = name_to_rid_www("name"); | |
| 838 | 839 | zMime = PD("m","application/x-fossil-artifact"); |
| 839 | 840 | login_check_credentials(); |
| 840 | 841 | if( !g.okRead ){ login_needed(); return; } |
| 841 | 842 | if( rid==0 ) fossil_redirect_home(); |
| 842 | 843 | content_get(rid, &content); |
| @@ -906,11 +907,11 @@ | ||
| 906 | 907 | int rid; |
| 907 | 908 | Blob content; |
| 908 | 909 | Blob downloadName; |
| 909 | 910 | char *zUuid; |
| 910 | 911 | |
| 911 | - rid = name_to_rid(PD("name","0")); | |
| 912 | + rid = name_to_rid_www("name"); | |
| 912 | 913 | login_check_credentials(); |
| 913 | 914 | if( !g.okRead ){ login_needed(); return; } |
| 914 | 915 | if( rid==0 ) fossil_redirect_home(); |
| 915 | 916 | if( g.okAdmin ){ |
| 916 | 917 | const char *zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid); |
| @@ -953,11 +954,11 @@ | ||
| 953 | 954 | Blob downloadName; |
| 954 | 955 | int renderAsWiki = 0; |
| 955 | 956 | int renderAsHtml = 0; |
| 956 | 957 | const char *zUuid; |
| 957 | 958 | |
| 958 | - rid = name_to_rid(PD("name","0")); | |
| 959 | + rid = name_to_rid_www("name"); | |
| 959 | 960 | login_check_credentials(); |
| 960 | 961 | if( !g.okRead ){ login_needed(); return; } |
| 961 | 962 | if( rid==0 ) fossil_redirect_home(); |
| 962 | 963 | if( g.okAdmin ){ |
| 963 | 964 | const char *zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid); |
| @@ -1043,11 +1044,11 @@ | ||
| 1043 | 1044 | char zTktName[20]; |
| 1044 | 1045 | Manifest m; |
| 1045 | 1046 | |
| 1046 | 1047 | login_check_credentials(); |
| 1047 | 1048 | if( !g.okRdTkt ){ login_needed(); return; } |
| 1048 | - rid = name_to_rid(PD("name","0")); | |
| 1049 | + rid = name_to_rid_www("name"); | |
| 1049 | 1050 | if( rid==0 ){ fossil_redirect_home(); } |
| 1050 | 1051 | zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid); |
| 1051 | 1052 | if( g.okAdmin ){ |
| 1052 | 1053 | if( db_exists("SELECT 1 FROM shun WHERE uuid='%s'", zUuid) ){ |
| 1053 | 1054 | style_submenu_element("Unshun","Unshun", "%s/shun?uuid=%s&sub=1", |
| 1054 | 1055 |
| --- src/info.c | |
| +++ src/info.c | |
| @@ -269,12 +269,12 @@ | |
| 269 | int showDiff; |
| 270 | const char *zName; |
| 271 | |
| 272 | login_check_credentials(); |
| 273 | if( !g.okRead ){ login_needed(); return; } |
| 274 | zName = PD("name","0"); |
| 275 | rid = name_to_rid(zName); |
| 276 | if( rid==0 ){ |
| 277 | style_header("Check-in Information Error"); |
| 278 | @ No such object: %h(g.argv[2]) |
| 279 | style_footer(); |
| 280 | return; |
| @@ -456,11 +456,11 @@ | |
| 456 | Stmt q; |
| 457 | int rid; |
| 458 | |
| 459 | login_check_credentials(); |
| 460 | if( !g.okRdWiki ){ login_needed(); return; } |
| 461 | rid = name_to_rid(PD("name","0")); |
| 462 | if( rid==0 ){ |
| 463 | style_header("Wiki Page Information Error"); |
| 464 | @ No such object: %h(g.argv[2]) |
| 465 | style_footer(); |
| 466 | return; |
| @@ -542,11 +542,11 @@ | |
| 542 | |
| 543 | login_check_credentials(); |
| 544 | if( !g.okRead ){ login_needed(); return; } |
| 545 | login_anonymous_available(); |
| 546 | |
| 547 | rid = name_to_rid(PD("name","")); |
| 548 | if( rid==0 ){ |
| 549 | fossil_redirect_home(); |
| 550 | } |
| 551 | zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid); |
| 552 | style_header("Check-in [%.10s]", zUuid); |
| @@ -610,11 +610,11 @@ | |
| 610 | ** |
| 611 | ** * It's artifact ID |
| 612 | ** * date of check-in |
| 613 | ** * Comment & user |
| 614 | */ |
| 615 | static void object_description( |
| 616 | int rid, /* The artifact ID */ |
| 617 | int linkToView, /* Add viewer link if true */ |
| 618 | Blob *pDownloadName /* Fill with an appropriate download name */ |
| 619 | ){ |
| 620 | Stmt q; |
| @@ -735,11 +735,11 @@ | |
| 735 | } |
| 736 | db_prepare(&q, |
| 737 | "SELECT target, filename, datetime(mtime), user, src" |
| 738 | " FROM attachment" |
| 739 | " WHERE src=(SELECT uuid FROM blob WHERE rid=%d)" |
| 740 | " ORDER BY mtime DESC", |
| 741 | rid |
| 742 | ); |
| 743 | while( db_step(&q)==SQLITE_ROW ){ |
| 744 | const char *zTarget = db_column_text(&q, 0); |
| 745 | const char *zFilename = db_column_text(&q, 1); |
| @@ -797,10 +797,11 @@ | |
| 797 | int v2 = name_to_rid(P("v2")); |
| 798 | Blob c1, c2, diff; |
| 799 | |
| 800 | login_check_credentials(); |
| 801 | if( !g.okRead ){ login_needed(); return; } |
| 802 | style_header("Diff"); |
| 803 | @ <h2>Differences From:</h2> |
| 804 | @ <blockquote> |
| 805 | object_description(v1, 1, 0); |
| 806 | @ </blockquote> |
| @@ -832,11 +833,11 @@ | |
| 832 | void rawartifact_page(void){ |
| 833 | int rid; |
| 834 | const char *zMime; |
| 835 | Blob content; |
| 836 | |
| 837 | rid = name_to_rid(PD("name","0")); |
| 838 | zMime = PD("m","application/x-fossil-artifact"); |
| 839 | login_check_credentials(); |
| 840 | if( !g.okRead ){ login_needed(); return; } |
| 841 | if( rid==0 ) fossil_redirect_home(); |
| 842 | content_get(rid, &content); |
| @@ -906,11 +907,11 @@ | |
| 906 | int rid; |
| 907 | Blob content; |
| 908 | Blob downloadName; |
| 909 | char *zUuid; |
| 910 | |
| 911 | rid = name_to_rid(PD("name","0")); |
| 912 | login_check_credentials(); |
| 913 | if( !g.okRead ){ login_needed(); return; } |
| 914 | if( rid==0 ) fossil_redirect_home(); |
| 915 | if( g.okAdmin ){ |
| 916 | const char *zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid); |
| @@ -953,11 +954,11 @@ | |
| 953 | Blob downloadName; |
| 954 | int renderAsWiki = 0; |
| 955 | int renderAsHtml = 0; |
| 956 | const char *zUuid; |
| 957 | |
| 958 | rid = name_to_rid(PD("name","0")); |
| 959 | login_check_credentials(); |
| 960 | if( !g.okRead ){ login_needed(); return; } |
| 961 | if( rid==0 ) fossil_redirect_home(); |
| 962 | if( g.okAdmin ){ |
| 963 | const char *zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid); |
| @@ -1043,11 +1044,11 @@ | |
| 1043 | char zTktName[20]; |
| 1044 | Manifest m; |
| 1045 | |
| 1046 | login_check_credentials(); |
| 1047 | if( !g.okRdTkt ){ login_needed(); return; } |
| 1048 | rid = name_to_rid(PD("name","0")); |
| 1049 | if( rid==0 ){ fossil_redirect_home(); } |
| 1050 | zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid); |
| 1051 | if( g.okAdmin ){ |
| 1052 | if( db_exists("SELECT 1 FROM shun WHERE uuid='%s'", zUuid) ){ |
| 1053 | style_submenu_element("Unshun","Unshun", "%s/shun?uuid=%s&sub=1", |
| 1054 |
| --- src/info.c | |
| +++ src/info.c | |
| @@ -269,12 +269,12 @@ | |
| 269 | int showDiff; |
| 270 | const char *zName; |
| 271 | |
| 272 | login_check_credentials(); |
| 273 | if( !g.okRead ){ login_needed(); return; } |
| 274 | zName = P("name"); |
| 275 | rid = name_to_rid_www("name"); |
| 276 | if( rid==0 ){ |
| 277 | style_header("Check-in Information Error"); |
| 278 | @ No such object: %h(g.argv[2]) |
| 279 | style_footer(); |
| 280 | return; |
| @@ -456,11 +456,11 @@ | |
| 456 | Stmt q; |
| 457 | int rid; |
| 458 | |
| 459 | login_check_credentials(); |
| 460 | if( !g.okRdWiki ){ login_needed(); return; } |
| 461 | rid = name_to_rid_www("name"); |
| 462 | if( rid==0 ){ |
| 463 | style_header("Wiki Page Information Error"); |
| 464 | @ No such object: %h(g.argv[2]) |
| 465 | style_footer(); |
| 466 | return; |
| @@ -542,11 +542,11 @@ | |
| 542 | |
| 543 | login_check_credentials(); |
| 544 | if( !g.okRead ){ login_needed(); return; } |
| 545 | login_anonymous_available(); |
| 546 | |
| 547 | rid = name_to_rid_www("name"); |
| 548 | if( rid==0 ){ |
| 549 | fossil_redirect_home(); |
| 550 | } |
| 551 | zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid); |
| 552 | style_header("Check-in [%.10s]", zUuid); |
| @@ -610,11 +610,11 @@ | |
| 610 | ** |
| 611 | ** * It's artifact ID |
| 612 | ** * date of check-in |
| 613 | ** * Comment & user |
| 614 | */ |
| 615 | void object_description( |
| 616 | int rid, /* The artifact ID */ |
| 617 | int linkToView, /* Add viewer link if true */ |
| 618 | Blob *pDownloadName /* Fill with an appropriate download name */ |
| 619 | ){ |
| 620 | Stmt q; |
| @@ -735,11 +735,11 @@ | |
| 735 | } |
| 736 | db_prepare(&q, |
| 737 | "SELECT target, filename, datetime(mtime), user, src" |
| 738 | " FROM attachment" |
| 739 | " WHERE src=(SELECT uuid FROM blob WHERE rid=%d)" |
| 740 | " ORDER BY mtime DESC /*sort*/", |
| 741 | rid |
| 742 | ); |
| 743 | while( db_step(&q)==SQLITE_ROW ){ |
| 744 | const char *zTarget = db_column_text(&q, 0); |
| 745 | const char *zFilename = db_column_text(&q, 1); |
| @@ -797,10 +797,11 @@ | |
| 797 | int v2 = name_to_rid(P("v2")); |
| 798 | Blob c1, c2, diff; |
| 799 | |
| 800 | login_check_credentials(); |
| 801 | if( !g.okRead ){ login_needed(); return; } |
| 802 | if( v1==0 || v2==0 ) fossil_redirect_home(); |
| 803 | style_header("Diff"); |
| 804 | @ <h2>Differences From:</h2> |
| 805 | @ <blockquote> |
| 806 | object_description(v1, 1, 0); |
| 807 | @ </blockquote> |
| @@ -832,11 +833,11 @@ | |
| 833 | void rawartifact_page(void){ |
| 834 | int rid; |
| 835 | const char *zMime; |
| 836 | Blob content; |
| 837 | |
| 838 | rid = name_to_rid_www("name"); |
| 839 | zMime = PD("m","application/x-fossil-artifact"); |
| 840 | login_check_credentials(); |
| 841 | if( !g.okRead ){ login_needed(); return; } |
| 842 | if( rid==0 ) fossil_redirect_home(); |
| 843 | content_get(rid, &content); |
| @@ -906,11 +907,11 @@ | |
| 907 | int rid; |
| 908 | Blob content; |
| 909 | Blob downloadName; |
| 910 | char *zUuid; |
| 911 | |
| 912 | rid = name_to_rid_www("name"); |
| 913 | login_check_credentials(); |
| 914 | if( !g.okRead ){ login_needed(); return; } |
| 915 | if( rid==0 ) fossil_redirect_home(); |
| 916 | if( g.okAdmin ){ |
| 917 | const char *zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid); |
| @@ -953,11 +954,11 @@ | |
| 954 | Blob downloadName; |
| 955 | int renderAsWiki = 0; |
| 956 | int renderAsHtml = 0; |
| 957 | const char *zUuid; |
| 958 | |
| 959 | rid = name_to_rid_www("name"); |
| 960 | login_check_credentials(); |
| 961 | if( !g.okRead ){ login_needed(); return; } |
| 962 | if( rid==0 ) fossil_redirect_home(); |
| 963 | if( g.okAdmin ){ |
| 964 | const char *zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid); |
| @@ -1043,11 +1044,11 @@ | |
| 1044 | char zTktName[20]; |
| 1045 | Manifest m; |
| 1046 | |
| 1047 | login_check_credentials(); |
| 1048 | if( !g.okRdTkt ){ login_needed(); return; } |
| 1049 | rid = name_to_rid_www("name"); |
| 1050 | if( rid==0 ){ fossil_redirect_home(); } |
| 1051 | zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid); |
| 1052 | if( g.okAdmin ){ |
| 1053 | if( db_exists("SELECT 1 FROM shun WHERE uuid='%s'", zUuid) ){ |
| 1054 | style_submenu_element("Unshun","Unshun", "%s/shun?uuid=%s&sub=1", |
| 1055 |
+75
-3
| --- src/name.c | ||
| +++ src/name.c | ||
| @@ -43,11 +43,12 @@ | ||
| 43 | 43 | ** If the input is not a tag, then try to match it as an ISO-8601 date |
| 44 | 44 | ** string YYYY-MM-DD HH:MM:SS and pick the nearest check-in to that date. |
| 45 | 45 | ** If the input is of the form "date:*" or "localtime:*" or "utc:*" then |
| 46 | 46 | ** always resolve the name as a date. |
| 47 | 47 | ** |
| 48 | -** Return the number of errors. | |
| 48 | +** Return 0 on success. Return 1 if the name cannot be resolved. | |
| 49 | +** Return 2 name is ambiguous. | |
| 49 | 50 | */ |
| 50 | 51 | int name_to_uuid(Blob *pName, int iErrPriority){ |
| 51 | 52 | int rc; |
| 52 | 53 | int sz; |
| 53 | 54 | sz = blob_size(pName); |
| @@ -102,11 +103,11 @@ | ||
| 102 | 103 | fossil_error(iErrPriority, |
| 103 | 104 | "multiple artifacts match" |
| 104 | 105 | ); |
| 105 | 106 | blob_reset(pName); |
| 106 | 107 | db_finalize(&q); |
| 107 | - return 1; | |
| 108 | + return 2; | |
| 108 | 109 | } |
| 109 | 110 | db_finalize(&q); |
| 110 | 111 | rc = 0; |
| 111 | 112 | }else{ |
| 112 | 113 | rc = 0; |
| @@ -273,11 +274,11 @@ | ||
| 273 | 274 | ** Convert a name to a rid. If the name is a small integer value then |
| 274 | 275 | ** just use atoi() to do the conversion. If the name contains alphabetic |
| 275 | 276 | ** characters or is not an existing rid, then use name_to_uuid then |
| 276 | 277 | ** convert the uuid to a rid. |
| 277 | 278 | ** |
| 278 | -** This routine is used in test routines to resolve command-line inputs | |
| 279 | +** This routine is used by command-line routines to resolve command-line inputs | |
| 279 | 280 | ** into a rid. |
| 280 | 281 | */ |
| 281 | 282 | int name_to_rid(const char *zName){ |
| 282 | 283 | int i; |
| 283 | 284 | int rid; |
| @@ -300,5 +301,76 @@ | ||
| 300 | 301 | rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%B", &name); |
| 301 | 302 | blob_reset(&name); |
| 302 | 303 | } |
| 303 | 304 | return rid; |
| 304 | 305 | } |
| 306 | + | |
| 307 | +/* | |
| 308 | +** WEBPAGE: ambiguous | |
| 309 | +** URL: /ambiguous?name=UUID&src=WEBPAGE | |
| 310 | +** | |
| 311 | +** The UUID given by the name paramager is ambiguous. Display a page | |
| 312 | +** that shows all possible choices and let the user select between them. | |
| 313 | +*/ | |
| 314 | +void ambiguous_page(void){ | |
| 315 | + Stmt q; | |
| 316 | + const char *zName = P("name"); | |
| 317 | + const char *zSrc = P("src"); | |
| 318 | + char *z; | |
| 319 | + | |
| 320 | + if( zName==0 || zName[0]==0 || zSrc==0 || zSrc[0]==0 ){ | |
| 321 | + fossil_redirect_home(); | |
| 322 | + } | |
| 323 | + style_header("Ambiguous Artifact ID"); | |
| 324 | + @ <p>The artifact id <b>%h(zName)</b> is ambiguous and might | |
| 325 | + @ mean any of the following: | |
| 326 | + @ <ol> | |
| 327 | + z = mprintf("%s", zName); | |
| 328 | + canonical16(z, strlen(z)); | |
| 329 | + db_prepare(&q, "SELECT uuid, rid FROM blob WHERE uuid GLOB '%q*'", z); | |
| 330 | + while( db_step(&q)==SQLITE_ROW ){ | |
| 331 | + const char *zUuid = db_column_text(&q, 0); | |
| 332 | + int rid = db_column_int(&q, 1); | |
| 333 | + @ <li><p><a href="%s(g.zBaseURL)/%T(zSrc)/%S(zUuid)"> | |
| 334 | + @ %S(zUuid)</a> - | |
| 335 | + object_description(rid, 0, 0); | |
| 336 | + @ </p></li> | |
| 337 | + } | |
| 338 | + @ </ol> | |
| 339 | + style_footer(); | |
| 340 | +} | |
| 341 | + | |
| 342 | +/* | |
| 343 | +** Convert the name in CGI parameter zParamName into a rid and return that | |
| 344 | +** rid. If the CGI parameter is missing or is not a valid artifact tag, | |
| 345 | +** return 0. If the CGI parameter is ambiguous, redirect to a page that | |
| 346 | +** shows all possibilities and do not return. | |
| 347 | +*/ | |
| 348 | +int name_to_rid_www(const char *zParamName){ | |
| 349 | + int i, rc; | |
| 350 | + int rid; | |
| 351 | + const char *zName = P(zParamName); | |
| 352 | + Blob name; | |
| 353 | + | |
| 354 | + if( zName==0 || zName[0]==0 ) return 0; | |
| 355 | + blob_init(&name, zName, -1); | |
| 356 | + rc = name_to_uuid(&name, -1); | |
| 357 | + if( rc==1 ){ | |
| 358 | + blob_reset(&name); | |
| 359 | + for(i=0; zName[i] && isdigit(zName[i]); i++){} | |
| 360 | + if( zName[i]==0 ){ | |
| 361 | + rid = atoi(zName); | |
| 362 | + if( db_exists("SELECT 1 FROM blob WHERE rid=%d", rid) ){ | |
| 363 | + return rid; | |
| 364 | + } | |
| 365 | + } | |
| 366 | + return 0; | |
| 367 | + }else if( rc==2 ){ | |
| 368 | + cgi_redirectf("%s/ambiguous/%T?src=%t", g.zTop, zName, g.zPath); | |
| 369 | + return 0; | |
| 370 | + }else{ | |
| 371 | + rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%B", &name); | |
| 372 | + blob_reset(&name); | |
| 373 | + } | |
| 374 | + return rid; | |
| 375 | +} | |
| 376 | + | |
| 305 | 377 |
| --- src/name.c | |
| +++ src/name.c | |
| @@ -43,11 +43,12 @@ | |
| 43 | ** If the input is not a tag, then try to match it as an ISO-8601 date |
| 44 | ** string YYYY-MM-DD HH:MM:SS and pick the nearest check-in to that date. |
| 45 | ** If the input is of the form "date:*" or "localtime:*" or "utc:*" then |
| 46 | ** always resolve the name as a date. |
| 47 | ** |
| 48 | ** Return the number of errors. |
| 49 | */ |
| 50 | int name_to_uuid(Blob *pName, int iErrPriority){ |
| 51 | int rc; |
| 52 | int sz; |
| 53 | sz = blob_size(pName); |
| @@ -102,11 +103,11 @@ | |
| 102 | fossil_error(iErrPriority, |
| 103 | "multiple artifacts match" |
| 104 | ); |
| 105 | blob_reset(pName); |
| 106 | db_finalize(&q); |
| 107 | return 1; |
| 108 | } |
| 109 | db_finalize(&q); |
| 110 | rc = 0; |
| 111 | }else{ |
| 112 | rc = 0; |
| @@ -273,11 +274,11 @@ | |
| 273 | ** Convert a name to a rid. If the name is a small integer value then |
| 274 | ** just use atoi() to do the conversion. If the name contains alphabetic |
| 275 | ** characters or is not an existing rid, then use name_to_uuid then |
| 276 | ** convert the uuid to a rid. |
| 277 | ** |
| 278 | ** This routine is used in test routines to resolve command-line inputs |
| 279 | ** into a rid. |
| 280 | */ |
| 281 | int name_to_rid(const char *zName){ |
| 282 | int i; |
| 283 | int rid; |
| @@ -300,5 +301,76 @@ | |
| 300 | rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%B", &name); |
| 301 | blob_reset(&name); |
| 302 | } |
| 303 | return rid; |
| 304 | } |
| 305 |
| --- src/name.c | |
| +++ src/name.c | |
| @@ -43,11 +43,12 @@ | |
| 43 | ** If the input is not a tag, then try to match it as an ISO-8601 date |
| 44 | ** string YYYY-MM-DD HH:MM:SS and pick the nearest check-in to that date. |
| 45 | ** If the input is of the form "date:*" or "localtime:*" or "utc:*" then |
| 46 | ** always resolve the name as a date. |
| 47 | ** |
| 48 | ** Return 0 on success. Return 1 if the name cannot be resolved. |
| 49 | ** Return 2 name is ambiguous. |
| 50 | */ |
| 51 | int name_to_uuid(Blob *pName, int iErrPriority){ |
| 52 | int rc; |
| 53 | int sz; |
| 54 | sz = blob_size(pName); |
| @@ -102,11 +103,11 @@ | |
| 103 | fossil_error(iErrPriority, |
| 104 | "multiple artifacts match" |
| 105 | ); |
| 106 | blob_reset(pName); |
| 107 | db_finalize(&q); |
| 108 | return 2; |
| 109 | } |
| 110 | db_finalize(&q); |
| 111 | rc = 0; |
| 112 | }else{ |
| 113 | rc = 0; |
| @@ -273,11 +274,11 @@ | |
| 274 | ** Convert a name to a rid. If the name is a small integer value then |
| 275 | ** just use atoi() to do the conversion. If the name contains alphabetic |
| 276 | ** characters or is not an existing rid, then use name_to_uuid then |
| 277 | ** convert the uuid to a rid. |
| 278 | ** |
| 279 | ** This routine is used by command-line routines to resolve command-line inputs |
| 280 | ** into a rid. |
| 281 | */ |
| 282 | int name_to_rid(const char *zName){ |
| 283 | int i; |
| 284 | int rid; |
| @@ -300,5 +301,76 @@ | |
| 301 | rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%B", &name); |
| 302 | blob_reset(&name); |
| 303 | } |
| 304 | return rid; |
| 305 | } |
| 306 | |
| 307 | /* |
| 308 | ** WEBPAGE: ambiguous |
| 309 | ** URL: /ambiguous?name=UUID&src=WEBPAGE |
| 310 | ** |
| 311 | ** The UUID given by the name paramager is ambiguous. Display a page |
| 312 | ** that shows all possible choices and let the user select between them. |
| 313 | */ |
| 314 | void ambiguous_page(void){ |
| 315 | Stmt q; |
| 316 | const char *zName = P("name"); |
| 317 | const char *zSrc = P("src"); |
| 318 | char *z; |
| 319 | |
| 320 | if( zName==0 || zName[0]==0 || zSrc==0 || zSrc[0]==0 ){ |
| 321 | fossil_redirect_home(); |
| 322 | } |
| 323 | style_header("Ambiguous Artifact ID"); |
| 324 | @ <p>The artifact id <b>%h(zName)</b> is ambiguous and might |
| 325 | @ mean any of the following: |
| 326 | @ <ol> |
| 327 | z = mprintf("%s", zName); |
| 328 | canonical16(z, strlen(z)); |
| 329 | db_prepare(&q, "SELECT uuid, rid FROM blob WHERE uuid GLOB '%q*'", z); |
| 330 | while( db_step(&q)==SQLITE_ROW ){ |
| 331 | const char *zUuid = db_column_text(&q, 0); |
| 332 | int rid = db_column_int(&q, 1); |
| 333 | @ <li><p><a href="%s(g.zBaseURL)/%T(zSrc)/%S(zUuid)"> |
| 334 | @ %S(zUuid)</a> - |
| 335 | object_description(rid, 0, 0); |
| 336 | @ </p></li> |
| 337 | } |
| 338 | @ </ol> |
| 339 | style_footer(); |
| 340 | } |
| 341 | |
| 342 | /* |
| 343 | ** Convert the name in CGI parameter zParamName into a rid and return that |
| 344 | ** rid. If the CGI parameter is missing or is not a valid artifact tag, |
| 345 | ** return 0. If the CGI parameter is ambiguous, redirect to a page that |
| 346 | ** shows all possibilities and do not return. |
| 347 | */ |
| 348 | int name_to_rid_www(const char *zParamName){ |
| 349 | int i, rc; |
| 350 | int rid; |
| 351 | const char *zName = P(zParamName); |
| 352 | Blob name; |
| 353 | |
| 354 | if( zName==0 || zName[0]==0 ) return 0; |
| 355 | blob_init(&name, zName, -1); |
| 356 | rc = name_to_uuid(&name, -1); |
| 357 | if( rc==1 ){ |
| 358 | blob_reset(&name); |
| 359 | for(i=0; zName[i] && isdigit(zName[i]); i++){} |
| 360 | if( zName[i]==0 ){ |
| 361 | rid = atoi(zName); |
| 362 | if( db_exists("SELECT 1 FROM blob WHERE rid=%d", rid) ){ |
| 363 | return rid; |
| 364 | } |
| 365 | } |
| 366 | return 0; |
| 367 | }else if( rc==2 ){ |
| 368 | cgi_redirectf("%s/ambiguous/%T?src=%t", g.zTop, zName, g.zPath); |
| 369 | return 0; |
| 370 | }else{ |
| 371 | rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%B", &name); |
| 372 | blob_reset(&name); |
| 373 | } |
| 374 | return rid; |
| 375 | } |
| 376 | |
| 377 |