Exemple #1
0
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);
}
Exemple #2
0
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);
}
Exemple #3
0
char *mget_iri_get_path(const mget_iri_t *iri, mget_buffer_t *buf, const char *encoding)
{
	if (buf->length)
		mget_buffer_memcat(buf, "/", 1);

	if (iri->path) {
		if (mget_strcasecmp_ascii(encoding, "utf-8")) {
			char *fname;

			if ((fname = mget_utf8_to_str(iri->path, encoding))) {
				mget_buffer_strcat(buf, fname);
				xfree(fname);
			} else {
				// conversion failed, keep original string
				mget_buffer_strcat(buf, iri->path);
			}
		} 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 buf->data;
}
Exemple #4
0
char *mget_iri_get_query_as_filename(const mget_iri_t *iri, mget_buffer_t *buf, const char *encoding)
{
	if (iri->query) {
		const char *query;
		int allocated = 0;

		mget_buffer_memcat(buf, "?", 1);

		if (mget_strcasecmp_ascii(encoding, "utf-8")) {
			if ((query = mget_utf8_to_str(iri->query, encoding)))
				allocated = 1;
		} else {
			query = iri->query;
		}

		if (query) {
			int slashes = 0;
			const char *src = query;

			// count slashes in query string
			while ((src = strchr(src, '/'))) {
				slashes++;
				src++;
			}

			if (slashes) {
				// escape slashes to use query as part of a filename
				const char *begin;

				for (src = begin = query; *src; src++) {
					if (*src == '/') {
						if (begin != src)
							mget_buffer_memcat(buf, begin, src - begin);
						begin = src + 1;
						mget_buffer_memcat(buf, "%2F", 3);
					}
				}

				if (begin != src)
					mget_buffer_memcat(buf, begin, src - begin);
			} else {
				mget_buffer_strcat(buf, query);
			}
		}

		if (allocated)
			xfree(query);
	}

	return buf->data;
}