コード例 #1
0
ファイル: log.c プロジェクト: BitchX/BitchX-SVN
/*
 * add_to_log: add the given line to the log file.  If no log file is open
 * this function does nothing. 
 */
void BX_add_to_log(FILE *fp, time_t t, const char *line, int mangler)
{
#ifndef PUBLIC_ACCESS
	if (fp && !inhibit_logging)
	{
		char *local_line;
		int len = strlen(line) * 2 + 1;
		local_line = alloca(len);
		strcpy(local_line, line);

		/* Do this first */
		if (mangler)
			mangle_line(local_line, mangler, len);
		else if (!get_int_var(MIRCS_VAR))
		{
			char *tmp = alloca(strlen(local_line) + 1);
			strip_control(local_line, tmp);
			strcpy(local_line, tmp);
		}

		
		fprintf(fp, "%s\n", local_line);
		fflush(fp);
	}
#endif
}
コード例 #2
0
ファイル: log.c プロジェクト: carriercomm/epic5-1
/*
 * add_to_log: add the given line to the log file.  If no log file is open
 * this function does nothing. 
 */
void 	add_to_log (FILE *fp, long winref, const unsigned char *line, int mangler, const char *rewriter)
{
	char	*local_line;
	size_t	size;
	int	must_free = 0;

	if (!fp || inhibit_logging)
		return;

	/*
	 * We need to make a local copy because 'mangle_line' 
	 * diddles around with the source, and so we can't subject
	 * line to that, it is 'const'.
	 *
	 * 'mangle_line' can expand the input string, so it is 
	 * neccesary to allocate more than we need.
	 */
	size = (strlen(line) + 1) * 11;
	local_line = alloca(size + 1);
	strlcpy(local_line, line, size + 1);

	/* Do this first */
	if (mangler == 0)
		mangler = logfile_line_mangler;
	if (mangler)
	   if (mangle_line(local_line, mangler, size) > size)
		(void)0; /* Whimper -- what to do, what to do? */

	if (get_int_var(NO_CONTROL_LOG_VAR))
	{
		char *tmp = alloca(strlen(local_line) + 1);
		strip_control(local_line, tmp);
		strlcpy(local_line, tmp, size);
	}

	if (rewriter == NULL)
		rewriter = get_string_var(LOG_REWRITE_VAR);
	if (rewriter)
	{
		char    *prepend_exp;
		char    argstuff[10240];
		int     args_flag;

		/* First, create the $* list for the expando */
		snprintf(argstuff, 10240, "%ld %s", winref, local_line);

		/* Now expand the expando with the above $* */
		prepend_exp = expand_alias(rewriter, argstuff,
					   &args_flag, NULL);

		local_line = prepend_exp;
		must_free = 1;
	}

	fprintf(fp, "%s\n", local_line);
	fflush(fp);

	if (must_free)
		new_free(&local_line);
}