-int cgit_parse_snapshots_mask(const char *str)
-{
- static const char *delim = " \t,:/|;";
- int f, tl, rv = 0;
- /* favor legacy setting */
- if(atoi(str)) return 1;
- for(;;) {
- str += strspn(str,delim);
- tl = strcspn(str,delim);
- if(!tl)
- break;
- for(f=0;f<(sizeof(snapshot_archives)/sizeof(*snapshot_archives));++f) {
- const struct snapshot_archive_t* sat = &snapshot_archives[f];
- if(! ( strncmp(sat->suffix,str,tl) && strncmp(sat->suffix+1,str,tl-1) ) ) {
- rv |= sat->bit;
- break;
- }
+void cgit_print_snapshot(const char *head, const char *hex,
+ const char *filename, int dwim)
+{
+ const struct cgit_snapshot_format* f;
+ const char *sig_filename = NULL;
+ char *adj_filename = NULL;
+ char *prefix = NULL;
+
+ if (!filename) {
+ cgit_print_error_page(400, "Bad request",
+ "No snapshot name specified");
+ return;
+ }
+
+ if (ends_with(filename, ".asc")) {
+ sig_filename = filename;
+
+ /* Strip ".asc" from filename for common format processing */
+ adj_filename = xstrdup(filename);
+ adj_filename[strlen(adj_filename) - 4] = '\0';
+ filename = adj_filename;
+ }
+
+ f = get_format(filename);
+ if (!f || (!sig_filename && !(ctx.repo->snapshots & cgit_snapshot_format_bit(f)))) {
+ cgit_print_error_page(400, "Bad request",
+ "Unsupported snapshot format: %s", filename);
+ return;
+ }
+
+ if (!hex && dwim) {
+ hex = get_ref_from_filename(ctx.repo, filename, f);
+ if (hex == NULL) {
+ cgit_print_error_page(404, "Not found", "Not found");
+ return;