- l = (int)strlen(entries[i].prefix);
- if (!strncmp(uri, entries[i].prefix, l))
- break;
+ len = (int)strlen(entries[i].prefix);
+ if (!strncmp(uri, entries[i].prefix, len))
+ goto end; /* found */
+ }
+
+ /* not a prefix of uri */
+ len = 0;
+
+ /* search default scheme if given and valid */
+ if (scheme && *scheme) {
+ deflen = (int)strlen(scheme);
+ deflen += (scheme[deflen - 1] != ':'); /* add virtual trailing colon */
+ i = (int)(sizeof entries / sizeof * entries);
+ while (i) {
+ i--;
+ if (deflen == (int)strlen(entries[i].prefix)
+ && !strncmp(scheme, entries[i].prefix, deflen - 1))
+ goto end; /* found */
+ }