示例#1
0
文件: iri.c 项目: BIllli/mget
char *mget_iri_get_filename(const mget_iri_t *iri, mget_buffer_t *buf, const char *encoding)
{
	if (iri->path) {
		char *fname;

		if (mget_strcasecmp_ascii(encoding, "utf-8")) {
			if ((fname = strrchr(iri->path, '/')))
				fname = mget_utf8_to_str(fname + 1, encoding);
			else
				fname = mget_utf8_to_str(iri->path, encoding);

			if (fname) {
				mget_buffer_strcat(buf, fname);
				xfree(fname);
			}
		} else {
			if ((fname = strrchr(iri->path, '/')))
				mget_buffer_strcat(buf, fname + 1);
			else
				mget_buffer_strcat(buf, iri->path);
		}
	}

	if ((buf->length == 0 || buf->data[buf->length - 1] == '/') && default_page)
		mget_buffer_memcat(buf, default_page, default_page_length);

	return mget_iri_get_query_as_filename(iri, buf, encoding);
}
示例#2
0
文件: iri.c 项目: rockdaboot/mget
char *mget_iri_get_filename(const mget_iri_t *iri, mget_buffer_t *buf, const char *encoding)
{
	if (iri->path) {
		char *fname, *p;

		if (mget_strcasecmp_ascii(encoding, "utf-8")) {
			if ((p = strrchr(iri->path, '/'))) {
				if (!(fname = mget_utf8_to_str(p + 1, encoding)))
					mget_buffer_strcat(buf, p + 1); // conversion failed, keep original string
			} else {
				if (!(fname = mget_utf8_to_str(iri->path, encoding)))
					mget_buffer_strcat(buf, iri->path); // conversion failed, keep original string
			}

			if (fname) {
				// conversion succeeded
				mget_buffer_strcat(buf, fname);
				xfree(fname);
			}
		} else {
			if ((fname = strrchr(iri->path, '/')))
				mget_buffer_strcat(buf, fname + 1);
			else
				mget_buffer_strcat(buf, iri->path);
		}
	}

	if ((buf->length == 0 || buf->data[buf->length - 1] == '/') && default_page)
		mget_buffer_memcat(buf, default_page, default_page_length);

	return mget_iri_get_query_as_filename(iri, buf, encoding);
}