Ejemplo n.º 1
0
// generate content takes the request rec and a file_t pointing to the
// already opened file from the request
// it adds the html information surrounding the body then loops
// over the names in the file and prints their coordinates
static int generate_content(request_rec *r, apr_file_t *fd) {
	// initialization
	char buf[MAX_BUF_LENGTH];
	apr_status_t rv;
	apr_file_t *name_data;
	const char * cookies;
	char * user = NULL;
	char * groups = NULL;
	moon_svr_cfg* cfg = ap_get_module_config(r->server->module_config, &moon_module);

	// get the cookies string from the request, retrieve the data
	// about a user and set the user and groups strings
	cookies = get_cookies_from_request(r);
	if(cookies != NULL) {
		rv = get_user_info(r, cookies, &user, &groups);
		if(rv != OK) {
			return rv;
		}
	}
	
	// set the reponse content type
	ap_set_content_type(r, "text/html;charset=ascii");

	// send initial html data
	ap_rputs(DOCTYPE, r);
	ap_rputs(OPEN_HTML_AND_HEAD, r);
	ap_rputs(TITLE, r);
	
	add_user_css(r, cfg, user);
	add_group_css(r, cfg, groups);

	ap_rputs(CLOSE_HEAD_OPEN_BODY, r);
	// check headers and return cookie, if NULL then no cookie set
	if(cookies != NULL && user != NULL) {
		add_user_info(r, user, groups);
	}
	else {
		add_anonymous_info(r);
	}

	// loop over file, get the next place
	// and print information about that place
	while(1) {
		rv = get_next_place(r, fd, buf);
		if(rv != OK) {
			if(rv==DONE) {
				break;
			} else {
				return rv;
			}
		}
		rv = get_place_coordinates(r, buf);
		ap_rprintf(r, "\n\t\t<p>\n\t\tCoordinates: %s\t\t</p>", buf);
		if(rv != OK) {
			return rv;
		}
	}	

	// cleanup and return 
	ap_rputs(CLOSE_HTML, r);
	return OK;
}
Ejemplo n.º 2
0
unsigned long pretty_print_commit(enum cmit_fmt fmt, const char *msg, unsigned long len, char *buf, unsigned long space)
{
	int hdr = 1, body = 0;
	unsigned long offset = 0;
	int parents = 0;
	int indent = (fmt == CMIT_FMT_ONELINE) ? 0 : 4;

	for (;;) {
		const char *line = msg;
		int linelen = get_one_line(msg, len);

		if (!linelen)
			break;

		/*
		 * We want some slop for indentation and a possible
		 * final "...". Thus the "+ 20".
		 */
		if (offset + linelen + 20 > space) {
			memcpy(buf + offset, "    ...\n", 8);
			offset += 8;
			break;
		}

		msg += linelen;
		len -= linelen;
		if (hdr) {
			if (linelen == 1) {
				hdr = 0;
				if (fmt != CMIT_FMT_ONELINE)
					buf[offset++] = '\n';
				continue;
			}
			if (fmt == CMIT_FMT_RAW) {
				memcpy(buf + offset, line, linelen);
				offset += linelen;
				continue;
			}
			if (!memcmp(line, "parent ", 7)) {
				if (linelen != 48)
					die("bad parent line in commit");
				offset += add_parent_info(fmt, buf + offset, line, ++parents);
			}

			/*
			 * MEDIUM == DEFAULT shows only author with dates.
			 * FULL shows both authors but not dates.
			 * FULLER shows both authors and dates.
			 */
			if (!memcmp(line, "author ", 7))
				offset += add_user_info("Author", fmt,
							buf + offset,
							line + 7);
			if (!memcmp(line, "committer ", 10) &&
			    (fmt == CMIT_FMT_FULL || fmt == CMIT_FMT_FULLER))
				offset += add_user_info("Commit", fmt,
							buf + offset,
							line + 10);
			continue;
		}

		if (is_empty_line(line, linelen)) {
			if (!body)
				continue;
			if (fmt == CMIT_FMT_SHORT)
				break;
		} else {
			body = 1;
		}

		memset(buf + offset, ' ', indent);
		memcpy(buf + offset + indent, line, linelen);
		offset += linelen + indent;
		if (fmt == CMIT_FMT_ONELINE)
			break;
	}
	if (fmt == CMIT_FMT_ONELINE) {
		/* We do not want the terminating newline */
		if (buf[offset - 1] == '\n')
			offset--;
	}
	else {
		/* Make sure there is an EOLN */
		if (buf[offset - 1] != '\n')
			buf[offset++] = '\n';
	}
	buf[offset] = '\0';
	return offset;
}