Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Add the "redirect:" option to CGI, to scan multiple repositories and redirect to the one that contains the requested artifact ID. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
ef6e364866d76ce9114fc4281d464f02 |
User & Date: | drh 2011-03-23 13:30:04.874 |
Context
2011-03-23
| ||
15:13 | Do a better response in the redirector if no matching artifact is found. ... (check-in: dbc2098a user: drh tags: trunk) | |
13:30 | Add the "redirect:" option to CGI, to scan multiple repositories and redirect to the one that contains the requested artifact ID. ... (check-in: ef6e3648 user: drh tags: trunk) | |
12:32 | If the "info" webpage references an ambiguous artifact ID, show all of the possible results. ... (check-in: 2c8ea5ff user: drh tags: trunk) | |
Changes
Changes to src/main.c.
︙ | ︙ | |||
1022 1023 1024 1025 1026 1027 1028 | ** The second line defines the name of the repository. After locating ** the repository, fossil will generate a webpage on stdout based on ** the values of standard CGI environment variables. */ void cmd_cgi(void){ const char *zFile; const char *zNotFound = 0; | > > | | 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 | ** The second line defines the name of the repository. After locating ** the repository, fossil will generate a webpage on stdout based on ** the values of standard CGI environment variables. */ void cmd_cgi(void){ const char *zFile; const char *zNotFound = 0; char **azRedirect = 0; /* List of repositories to redirect to */ int nRedirect = 0; /* Number of entries in azRedirect */ Blob config, line, key, value, value2; if( g.argc==3 && fossil_strcmp(g.argv[1],"cgi")==0 ){ zFile = g.argv[2]; }else{ zFile = g.argv[1]; } g.httpOut = stdout; g.httpIn = stdin; |
︙ | ︙ | |||
1076 1077 1078 1079 1080 1081 1082 | blob_reset(&value); continue; } if( blob_eq(&key, "localauth") ){ g.useLocalauth = 1; continue; } | > > > > > > > > > | > | > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 | blob_reset(&value); continue; } if( blob_eq(&key, "localauth") ){ g.useLocalauth = 1; continue; } if( blob_eq(&key, "redirect:") && blob_token(&line, &value) && blob_token(&line, &value2) ){ nRedirect++; azRedirect = fossil_realloc(azRedirect, 2*nRedirect*sizeof(char*)); azRedirect[nRedirect*2-2] = mprintf("%s", blob_str(&value)); azRedirect[nRedirect*2-1] = mprintf("%s", blob_str(&value2)); blob_reset(&value); blob_reset(&value2); continue; } } blob_reset(&config); if( g.db==0 && g.zRepositoryName==0 && nRedirect==0 ){ cgi_panic("Unable to find or open the project repository"); } cgi_init(); if( nRedirect ){ redirect_web_page(nRedirect, azRedirect); }else{ process_one_web_page(zNotFound); } } /* If the CGI program contains one or more lines of the form ** ** redirect: repository-filename http://hostname/path/%s ** ** then control jumps here. Search each repository for an artifact ID ** that matches the "name" CGI parameter and for the first match, ** redirect to the corresponding URL with the "name" CGI parameter ** inserted. Paint an error page if no match is found. ** ** If there is a line of the form: ** ** redirect: * URL ** ** Then a redirect is made to URL if no match is found. Otherwise a ** very primative error message is returned. */ void redirect_web_page(int nRedirect, char **azRedirect){ int i; /* Loop counter */ const char *zNotFound = 0; /* Not found URL */ const char *zName = P("name"); if( zName && validate16(zName, strlen(zName)) ){ for(i=0; i<nRedirect; i++){ if( strcmp(azRedirect[i*2],"*")==0 ){ zNotFound = azRedirect[i*2+1]; continue; } db_open_repository(azRedirect[i*2]); if( db_exists("SELECT 1 FROM blob WHERE uuid GLOB '%s*'", zName) ){ cgi_redirectf(azRedirect[i*2+1], zName); return; } db_close(1); } } if( zNotFound ){ cgi_redirectf(zNotFound, zName); }else{ printf( "Status: 200 Ok\r\n\r\n" "<p>No such object: %s</p>\n", zName ); } } /* ** If g.argv[2] exists then it is either the name of a repository ** that will be used by a server, or else it is a directory that ** contains multiple repositories that can be served. If g.argv[2] ** is a directory, the repositories it contains must be named |
︙ | ︙ |