static int assert_uri_to_filename (const char *uri, const char *reference_filename) { char *filename; filename=raptor_uri_uri_string_to_filename((const unsigned char*)uri); if(filename && !reference_filename) { fprintf(stderr, "%s: raptor_uri_uri_string_to_filename(%s) FAILED giving filename %s != NULL\n", program, uri, filename); if(filename) RAPTOR_FREE(cstring, filename); return 1; } else if (filename && strcmp(filename, reference_filename)) { fprintf(stderr, "%s: raptor_uri_uri_string_to_filename(%s) FAILED gaving filename %s != %s\n", program, uri, filename, reference_filename); if(filename) RAPTOR_FREE(cstring, filename); return 1; } RAPTOR_FREE(cstring, filename); return 0; }
/** * librdf_uri_to_filename: * @uri: #librdf_uri object * * Return pointer to filename of URI. * * Returns a pointer to a newly allocated buffer that * the caller must free. This will fail if the URI * is not a file: URI. This can be checked with #librdf_uri_is_file_uri * * Return value: pointer to filename or NULL on failure **/ const char* librdf_uri_to_filename(librdf_uri* uri) { LIBRDF_ASSERT_OBJECT_POINTER_RETURN_VALUE(uri, librdf_uri, NULL); return raptor_uri_uri_string_to_filename(librdf_uri_as_string(uri)); }
static int raptor_www_file_fetch(raptor_www* www) { char *filename; FILE *fh; unsigned char *uri_string = raptor_uri_as_string(www->uri); #if defined(HAVE_UNISTD_H) && defined(HAVE_SYS_STAT_H) struct stat buf; #endif www->status_code = 200; filename = raptor_uri_uri_string_to_filename(uri_string); if(!filename) { raptor_www_error(www, "Not a file: URI"); return 1; } #if defined(HAVE_UNISTD_H) && defined(HAVE_SYS_STAT_H) if(!stat(filename, &buf) && S_ISDIR(buf.st_mode)) { raptor_www_error(www, "Cannot read from a directory '%s'", filename); RAPTOR_FREE(cstring, filename); www->status_code = 404; return 1; } #endif fh = fopen(filename, "rb"); if(!fh) { raptor_www_error(www, "file '%s' open failed - %s", filename, strerror(errno)); RAPTOR_FREE(cstring, filename); www->status_code = (errno == EACCES) ? 403: 404; www->failed = 1; return www->failed; } raptor_www_file_handle_fetch(www, fh); fclose(fh); RAPTOR_FREE(cstring, filename); return www->failed; }
static int assert_uri_to_filename (const char *uri, const char *reference_filename) { char *filename; filename=raptor_uri_uri_string_to_filename((const unsigned char*)uri); if (!filename || strcmp(filename, reference_filename)) { fprintf(stderr, "FAIL raptor_uri_uri_string_to_filename URI %s gave filename %s != %s\n", uri, filename, reference_filename); if(filename) RAPTOR_FREE(cstring, filename); return 1; } RAPTOR_FREE(cstring, filename); return 0; }