Beispiel #1
0
static const ULONG ami_file_asl_mime_hook(struct Hook *mh,
		struct FileRequester *fr, struct AnchorPathOld *ap)
{
	char fname[1024];
	BOOL ret = FALSE;
	char *mt = NULL;
	lwc_string *lwc_mt = NULL;
	lwc_error lerror;
	content_type ct;

	if(ap->ap_Info.fib_DirEntryType > 0) return(TRUE);

	strcpy(fname,fr->fr_Drawer);
	AddPart(fname,ap->ap_Info.fib_FileName,1024);

  	mt = strdup(fetch_filetype(fname));
	lerror = lwc_intern_string(mt, strlen(mt), &lwc_mt);
	if (lerror != lwc_error_ok)
		return FALSE;

	ct = content_factory_type_from_mime_type(lwc_mt);
	lwc_string_unref(lwc_mt);

	if(ct != CONTENT_NONE) ret = TRUE;

	free(mt);
	return ret;
}
Beispiel #2
0
int main(int argc, char *argv[])
{
	unsigned int c1, *c2;
	const char *key;

	gtk_fetch_filetype_init("./mime.types");

	c1 = 0; c2 = 0;

	while ( (key = hash_iterate(mime_hash, &c1, &c2)) != NULL) {
		printf("%s ", key);
	}

	printf("\n");

	if (argc > 1) {
		printf("%s maps to %s\n", argv[1], fetch_filetype(argv[1]));
	}

	gtk_fetch_filetype_fin();
}
Beispiel #3
0
static bool fetch_rsrc_process(struct fetch_rsrc_context *c)
{
	fetch_msg msg;
	char *params;
	char *at = NULL;
	char *slash;
	char *comma = NULL;
	char *unescaped;
	uint32 type = 'data'; // default for embeded files
	int32 id = 0;
	
	/* format of a rsrc: URL is:
	 *   rsrc://[TYPE][@NUM]/name[,mime]
	 */
	
	LOG(("*** Processing %s", c->url));
	
	if (strlen(c->url) < 7) {
		/* 7 is the minimum possible length (rsrc://) */
		msg.type = FETCH_ERROR;
		msg.data.error = "Malformed rsrc: URL";
		fetch_rsrc_send_callback(&msg, c);
		return false;
	}
	
	/* skip the rsrc: part */
	params = c->url + sizeof("rsrc://") - 1;
	
	/* find the slash */
	if ( (slash = strchr(params, '/')) == NULL) {
		msg.type = FETCH_ERROR;
		msg.data.error = "Malformed rsrc: URL";
		fetch_rsrc_send_callback(&msg, c);
		return false;
	}

	// doesn't exist in the filesystem but we should hit the internal types.
	c->mimetype = strdup(fetch_filetype(slash));
	c->name = strdup(slash + 1);
	
	if (c->mimetype == NULL) {
		msg.type = FETCH_ERROR;
		msg.data.error =
			"Unable to allocate memory for mimetype in rsrc: URL";
		fetch_rsrc_send_callback(&msg, c);
		return false;
	}

	if (params[0] != '/') {
		uint8 c1, c2, c3, c4;
		if (sscanf(params, "%c%c%c%c", &c1, &c2, &c3, &c4) > 3) {
			type = c1 << 24 | c2 << 16 | c3 << 8 | c4;
			LOG(("fetch_rsrc: type:%4.4s\n", &type));
		}
	}

	LOG(("fetch_rsrc: 0x%08lx, %ld, '%s'\n", type, id, c->name));

	bool found;
	if (id)
		found = gAppResources->HasResource(type, id);
	else
		found = gAppResources->HasResource(type, c->name);
	if (!found) {
		BString error("Cannot locate resource: ");
		if (id)
			error << id;
		else
			error << c->name;
		msg.type = FETCH_ERROR;
		msg.data.error = error.String();
		fetch_rsrc_send_callback(&msg, c);
		return false;
	}

	size_t len;
	const void *data;
	if (id)
		data = gAppResources->LoadResource(type, id, &len);
	else
		data = gAppResources->LoadResource(type, c->name, &len);

	if (!data) {
		msg.type = FETCH_ERROR;
		msg.data.error = "Cannot load rsrc: URL";
		fetch_rsrc_send_callback(&msg, c);
		return false;
	}

	c->datalen = len;
	c->data = (char *)malloc(c->datalen);
	if (c->data == NULL) {
		msg.type = FETCH_ERROR;
		msg.data.error = "Unable to allocate memory for rsrc: URL";
		fetch_rsrc_send_callback(&msg, c);
		return false;
	}
	memcpy(c->data, data, c->datalen);

	return true;
}
Beispiel #4
0
char *fetch_mimetype(const char *ro_path)
{
	return strdup(fetch_filetype(ro_path));
}