author | Lars Hjemli <hjemli@gmail.com> | 2007-05-14 22:48:31 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-05-14 22:48:31 (UTC) |
commit | ea2831f1c826d92c0158474c2d07837ec2f9fd6c (patch) (unidiff) | |
tree | e8d6a89bf0f50835f9c86dd642e7906e1d050df7 /cgit.c | |
parent | 6fb7d09fea94b3dd6932469283358cb24f1e7e29 (diff) | |
download | cgit-ea2831f1c826d92c0158474c2d07837ec2f9fd6c.zip cgit-ea2831f1c826d92c0158474c2d07837ec2f9fd6c.tar.gz cgit-ea2831f1c826d92c0158474c2d07837ec2f9fd6c.tar.bz2 |
Don't hardcode urls when SCRIPT_NAME is available
Also, let the makefile define the name of the installed cgi and
use that definition as a default value for cgit_script_name variable.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | cgit.c | 2 |
1 files changed, 2 insertions, 0 deletions
@@ -183,78 +183,80 @@ static void cgit_check_cache(struct cacheitem *item) | |||
183 | } | 183 | } |
184 | } | 184 | } |
185 | } | 185 | } |
186 | 186 | ||
187 | static void cgit_print_cache(struct cacheitem *item) | 187 | static void cgit_print_cache(struct cacheitem *item) |
188 | { | 188 | { |
189 | static char buf[4096]; | 189 | static char buf[4096]; |
190 | ssize_t i; | 190 | ssize_t i; |
191 | 191 | ||
192 | int fd = open(item->name, O_RDONLY); | 192 | int fd = open(item->name, O_RDONLY); |
193 | if (fd<0) | 193 | if (fd<0) |
194 | die("Unable to open cached file %s", item->name); | 194 | die("Unable to open cached file %s", item->name); |
195 | 195 | ||
196 | while((i=read(fd, buf, sizeof(buf))) > 0) | 196 | while((i=read(fd, buf, sizeof(buf))) > 0) |
197 | write(STDOUT_FILENO, buf, i); | 197 | write(STDOUT_FILENO, buf, i); |
198 | 198 | ||
199 | close(fd); | 199 | close(fd); |
200 | } | 200 | } |
201 | 201 | ||
202 | static void cgit_parse_args(int argc, const char **argv) | 202 | static void cgit_parse_args(int argc, const char **argv) |
203 | { | 203 | { |
204 | int i; | 204 | int i; |
205 | 205 | ||
206 | for (i = 1; i < argc; i++) { | 206 | for (i = 1; i < argc; i++) { |
207 | if (!strncmp(argv[i], "--cache=", 8)) { | 207 | if (!strncmp(argv[i], "--cache=", 8)) { |
208 | cgit_cache_root = xstrdup(argv[i]+8); | 208 | cgit_cache_root = xstrdup(argv[i]+8); |
209 | } | 209 | } |
210 | if (!strcmp(argv[i], "--nocache")) { | 210 | if (!strcmp(argv[i], "--nocache")) { |
211 | cgit_nocache = 1; | 211 | cgit_nocache = 1; |
212 | } | 212 | } |
213 | if (!strncmp(argv[i], "--query=", 8)) { | 213 | if (!strncmp(argv[i], "--query=", 8)) { |
214 | cgit_querystring = xstrdup(argv[i]+8); | 214 | cgit_querystring = xstrdup(argv[i]+8); |
215 | } | 215 | } |
216 | if (!strncmp(argv[i], "--repo=", 7)) { | 216 | if (!strncmp(argv[i], "--repo=", 7)) { |
217 | cgit_query_repo = xstrdup(argv[i]+7); | 217 | cgit_query_repo = xstrdup(argv[i]+7); |
218 | } | 218 | } |
219 | if (!strncmp(argv[i], "--page=", 7)) { | 219 | if (!strncmp(argv[i], "--page=", 7)) { |
220 | cgit_query_page = xstrdup(argv[i]+7); | 220 | cgit_query_page = xstrdup(argv[i]+7); |
221 | } | 221 | } |
222 | if (!strncmp(argv[i], "--head=", 7)) { | 222 | if (!strncmp(argv[i], "--head=", 7)) { |
223 | cgit_query_head = xstrdup(argv[i]+7); | 223 | cgit_query_head = xstrdup(argv[i]+7); |
224 | cgit_query_has_symref = 1; | 224 | cgit_query_has_symref = 1; |
225 | } | 225 | } |
226 | if (!strncmp(argv[i], "--sha1=", 7)) { | 226 | if (!strncmp(argv[i], "--sha1=", 7)) { |
227 | cgit_query_sha1 = xstrdup(argv[i]+7); | 227 | cgit_query_sha1 = xstrdup(argv[i]+7); |
228 | cgit_query_has_sha1 = 1; | 228 | cgit_query_has_sha1 = 1; |
229 | } | 229 | } |
230 | if (!strncmp(argv[i], "--ofs=", 6)) { | 230 | if (!strncmp(argv[i], "--ofs=", 6)) { |
231 | cgit_query_ofs = atoi(argv[i]+6); | 231 | cgit_query_ofs = atoi(argv[i]+6); |
232 | } | 232 | } |
233 | } | 233 | } |
234 | } | 234 | } |
235 | 235 | ||
236 | int main(int argc, const char **argv) | 236 | int main(int argc, const char **argv) |
237 | { | 237 | { |
238 | struct cacheitem item; | 238 | struct cacheitem item; |
239 | 239 | ||
240 | htmlfd = STDOUT_FILENO; | 240 | htmlfd = STDOUT_FILENO; |
241 | item.st.st_mtime = time(NULL); | 241 | item.st.st_mtime = time(NULL); |
242 | cgit_repolist.length = 0; | 242 | cgit_repolist.length = 0; |
243 | cgit_repolist.count = 0; | 243 | cgit_repolist.count = 0; |
244 | cgit_repolist.repos = NULL; | 244 | cgit_repolist.repos = NULL; |
245 | 245 | ||
246 | cgit_read_config(CGIT_CONFIG, cgit_global_config_cb); | 246 | cgit_read_config(CGIT_CONFIG, cgit_global_config_cb); |
247 | if (getenv("SCRIPT_NAME")) | ||
248 | cgit_script_name = xstrdup(getenv("SCRIPT_NAME")); | ||
247 | if (getenv("QUERY_STRING")) | 249 | if (getenv("QUERY_STRING")) |
248 | cgit_querystring = xstrdup(getenv("QUERY_STRING")); | 250 | cgit_querystring = xstrdup(getenv("QUERY_STRING")); |
249 | cgit_parse_args(argc, argv); | 251 | cgit_parse_args(argc, argv); |
250 | cgit_parse_query(cgit_querystring, cgit_querystring_cb); | 252 | cgit_parse_query(cgit_querystring, cgit_querystring_cb); |
251 | if (!cgit_prepare_cache(&item)) | 253 | if (!cgit_prepare_cache(&item)) |
252 | return 0; | 254 | return 0; |
253 | if (cgit_nocache) { | 255 | if (cgit_nocache) { |
254 | cgit_fill_cache(&item, 0); | 256 | cgit_fill_cache(&item, 0); |
255 | } else { | 257 | } else { |
256 | cgit_check_cache(&item); | 258 | cgit_check_cache(&item); |
257 | cgit_print_cache(&item); | 259 | cgit_print_cache(&item); |
258 | } | 260 | } |
259 | return 0; | 261 | return 0; |
260 | } | 262 | } |