Exemple #1
0
void HttpParams::restore() {
	if(!len)
		return;
	if(k != len) {
		if(params[v]) {
			params[v-1]='=';
			reencode(params+v,n-v-1);
			v--;
		}
		params[v+strlen(value())]='&';
		reencode(params+k,v-k);
	}
	params[len]='\0';
}
Exemple #2
0
struct commitinfo *cgit_parse_commit(struct commit *commit)
{
	struct commitinfo *ret;
	char *p = commit->buffer, *t = commit->buffer;

	ret = xmalloc(sizeof(*ret));
	ret->commit = commit;
	ret->author = NULL;
	ret->author_email = NULL;
	ret->committer = NULL;
	ret->committer_email = NULL;
	ret->subject = NULL;
	ret->msg = NULL;
	ret->msg_encoding = NULL;

	if (p == NULL)
		return ret;

	if (strncmp(p, "tree ", 5))
		die("Bad commit: %s", sha1_to_hex(commit->object.sha1));
	else
		p += 46; // "tree " + hex[40] + "\n"

	while (!strncmp(p, "parent ", 7))
		p += 48; // "parent " + hex[40] + "\n"

	if (p && !strncmp(p, "author ", 7)) {
		p = parse_user(p + 7, &ret->author, &ret->author_email,
			&ret->author_date);
	}

	if (p && !strncmp(p, "committer ", 9)) {
		p = parse_user(p + 9, &ret->committer, &ret->committer_email,
			&ret->committer_date);
	}

	if (p && !strncmp(p, "encoding ", 9)) {
		p += 9;
		t = strchr(p, '\n');
		if (t) {
			ret->msg_encoding = substr(p, t + 1);
			p = t + 1;
		}
	}

	// skip unknown header fields
	while (p && *p && (*p != '\n')) {
		p = strchr(p, '\n');
		if (p)
			p++;
	}

	// skip empty lines between headers and message
	while (p && *p == '\n')
		p++;

	if (!p)
		return ret;

	t = strchr(p, '\n');
	if (t) {
		ret->subject = substr(p, t);
		p = t + 1;

		while (p && *p == '\n') {
			p = strchr(p, '\n');
			if (p)
				p++;
		}
		if (p)
			ret->msg = xstrdup(p);
	} else
		ret->subject = xstrdup(p);

	if (ret->msg_encoding) {
		reencode(&ret->subject, PAGE_ENCODING, ret->msg_encoding);
		reencode(&ret->msg, PAGE_ENCODING, ret->msg_encoding);
	}

	return ret;
}
Exemple #3
0
struct commitinfo *cgit_parse_commit(struct commit *commit)
{
	struct commitinfo *ret;
	const char *p = get_cached_commit_buffer(commit, NULL);
	const char *t;

	ret = xmalloc(sizeof(*ret));
	ret->commit = commit;
	ret->author = NULL;
	ret->author_email = NULL;
	ret->committer = NULL;
	ret->committer_email = NULL;
	ret->subject = NULL;
	ret->msg = NULL;
	ret->msg_encoding = NULL;

	if (p == NULL)
		return ret;

	if (!starts_with(p, "tree "))
		die("Bad commit: %s", sha1_to_hex(commit->object.sha1));
	else
		p += 46; // "tree " + hex[40] + "\n"

	while (starts_with(p, "parent "))
		p += 48; // "parent " + hex[40] + "\n"

	if (p && starts_with(p, "author ")) {
		p = parse_user(p + 7, &ret->author, &ret->author_email,
			&ret->author_date);
	}

	if (p && starts_with(p, "committer ")) {
		p = parse_user(p + 10, &ret->committer, &ret->committer_email,
			&ret->committer_date);
	}

	if (p && starts_with(p, "encoding ")) {
		p += 9;
		t = strchr(p, '\n');
		if (t) {
			ret->msg_encoding = substr(p, t + 1);
			p = t + 1;
		}
	}

	/* if no special encoding is found, assume UTF-8 */
	if (!ret->msg_encoding)
		ret->msg_encoding = xstrdup("UTF-8");

	// skip unknown header fields
	while (p && *p && (*p != '\n')) {
		p = strchr(p, '\n');
		if (p)
			p++;
	}

	// skip empty lines between headers and message
	while (p && *p == '\n')
		p++;

	if (!p)
		return ret;

	t = strchr(p, '\n');
	if (t) {
		ret->subject = substr(p, t);
		p = t + 1;

		while (p && *p == '\n') {
			p = strchr(p, '\n');
			if (p)
				p++;
		}
		if (p)
			ret->msg = xstrdup(p);
	} else
		ret->subject = xstrdup(p);

	reencode(&ret->author, ret->msg_encoding, PAGE_ENCODING);
	reencode(&ret->author_email, ret->msg_encoding, PAGE_ENCODING);
	reencode(&ret->committer, ret->msg_encoding, PAGE_ENCODING);
	reencode(&ret->committer_email, ret->msg_encoding, PAGE_ENCODING);
	reencode(&ret->subject, ret->msg_encoding, PAGE_ENCODING);
	reencode(&ret->msg, ret->msg_encoding, PAGE_ENCODING);

	return ret;
}
Exemple #4
0
struct commitinfo *cgit_parse_commit(struct commit *commit)
{
	const int sha1hex_len = 40;
	struct commitinfo *ret;
	const char *p = get_cached_commit_buffer(commit, NULL);
	const char *t;

	ret = xcalloc(1, sizeof(struct commitinfo));
	ret->commit = commit;

	if (!p)
		return ret;

	if (!skip_prefix(p, "tree ", &p))
		die("Bad commit: %s", oid_to_hex(&commit->object.oid));
	p += sha1hex_len + 1;

	while (skip_prefix(p, "parent ", &p))
		p += sha1hex_len + 1;

	if (p && skip_prefix(p, "author ", &p)) {
		parse_user(p, &ret->author, &ret->author_email,
			&ret->author_date, &ret->author_tz);
		p = next_header_line(p);
	}

	if (p && skip_prefix(p, "committer ", &p)) {
		parse_user(p, &ret->committer, &ret->committer_email,
			&ret->committer_date, &ret->committer_tz);
		p = next_header_line(p);
	}

	if (p && skip_prefix(p, "encoding ", &p)) {
		t = strchr(p, '\n');
		if (t) {
			ret->msg_encoding = substr(p, t + 1);
			p = t + 1;
		}
	}

	if (!ret->msg_encoding)
		ret->msg_encoding = xstrdup("UTF-8");

	while (!end_of_header(p))
		p = next_header_line(p);
	while (p && *p == '\n')
		p++;
	if (!p)
		return ret;

	t = strchrnul(p, '\n');
	ret->subject = substr(p, t);
	while (*t == '\n')
		t++;
	ret->msg = xstrdup(t);

	reencode(&ret->author, ret->msg_encoding, PAGE_ENCODING);
	reencode(&ret->author_email, ret->msg_encoding, PAGE_ENCODING);
	reencode(&ret->committer, ret->msg_encoding, PAGE_ENCODING);
	reencode(&ret->committer_email, ret->msg_encoding, PAGE_ENCODING);
	reencode(&ret->subject, ret->msg_encoding, PAGE_ENCODING);
	reencode(&ret->msg, ret->msg_encoding, PAGE_ENCODING);

	return ret;
}