⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mdatat~1.c

📁 100 病毒源碼,原始碼,無毒 ......
💻 C
📖 第 1 页 / 共 2 页
字号:
/*** Modular Logfile Analyzer** Copyright 2000 Jan Kneschke <jan@kneschke.de>**** Homepage: http://www.kneschke.de/projekte/modlogan**    This program is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation; either version 2 of the License, or    (at your option) any later version, and provided that the above    copyright and permission notice is included with all distributed    copies of this or derived software.    This program is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    You should have received a copy of the GNU General Public License    along with this program; if not, write to the Free Software    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA**** $Id: mdatatypes.c,v 1.23 2001/01/11 22:23:28 jk Exp $*/#include <stdio.h>#include <stdlib.h>#include <string.h>#include "config.h"#ifdef HAVE_LIBZ#include <zlib.h>#else #include "zlibwrapper.h"#endif#include "mdatatypes.h"#include "mstate.h"int destroy2Str(void *d) {	data_2Str *data = d;		free(data->string);	free(data->string2);	free(data);		return 0;}data_2Str *create2Str(char *string, char *string2) {	data_2Str *data = malloc(sizeof(data_2Str));		data->string = malloc(strlen(string)+1);	strcpy(data->string, string);			data->string2 = malloc(strlen(string2)+1);	strcpy(data->string2, string2);		data->destructor = destroy2Str;	data->write = NULL;		return data;}char * _getline (gzFile *f) {	char *buffer;	int buf_len = 256;	int buf_inc = 128;		buffer = malloc(buf_len * sizeof(char));		*buffer = '\0';	if (!gzgets(f, buffer, buf_len-1)) {		return buffer;	}	while (buffer[strlen(buffer)-1] != '\n') {		buffer = realloc(buffer, (buf_len+buf_inc) * sizeof(char));				if (!gzgets(f, buffer+strlen(buffer), buf_inc-1)) {			break;		}				buf_len += buf_inc;	}		return buffer;}/* begin of Str2Int */int Str2Int_write(gzFile *f, void *d) {	data_StrInt *data = d;	gzwrite(f, data->string, strlen(data->string));	gzprintf(f, "\n%d,%d\n", 		data->count,		data->type);	return 0;}int Str2Int_destroy(void *d) {	data_StrInt *data = d;	if (data->string != NULL) free(data->string);	if (data != NULL) free(data);		return 0;}int Str2Int_setdata(data_StrInt *data, const char *str, int count, int type) {	data->string	= malloc(strlen(str)+1);	strcpy(data->string, str);	data->count	= count;	data->type	= type;		return 0;}int Str2Int_read(void *data, gzFile *f) {	char *_s = NULL, *_c = NULL;	int c, type;		pcre *match;	const char *errptr;	int erroffset = 0;#define N 20 + 1	int ovector[3 * N], n;	const char **list;		if ((_s = _getline(f)) == NULL) return -1;		if (*_s == '\0') {		free(_s);		return -1;	}	if (mstate_is_section_end(_s)) {		free(_s);		return 0;	}		if ((_c = _getline(f)) == NULL) return -1;		if (*_c == '\0') {		free(_s);		free(_c);		return -1;	}		/* remove the newline */	_s[strlen(_s)-1] = '\0';		if ((match = pcre_compile(		"^([0-9]+),([0-9]+)$", 		0, &errptr, &erroffset, NULL)) == NULL) {				fprintf(stderr, "%s.%d: rexexp compilation error at %s\n", __FILE__, __LINE__, errptr);						return -1;	} 		if ((n = pcre_exec(match, NULL, _c, strlen(_c), 0, 0, ovector, 3 * N)) < 0) {		if (n == PCRE_ERROR_NOMATCH) {			fprintf(stderr, "%s.%d: string doesn't match: %s\n", __FILE__, __LINE__, _c);		} else {			fprintf(stderr, "%s.%d: execution error while matching: %d\n", __FILE__, __LINE__, n);		}		return -1;	}#undef N			pcre_get_substring_list(_c, ovector, n, &list);		c = strtol(list[1], NULL, 10);	type = strtol(list[2], NULL, 10);		Str2Int_setdata(data, _s, c, type);		free(_s);	free(_c);	free(list);	free(match);		return 0;}void *Str2Int_copy(void *d) {	data_StrInt *_data = d;		data_StrInt *data = Str2Int_init();		Str2Int_setdata(data, _data->string, _data->count, _data->type);		return data;}int Str2Int_append(void *d, void *s) {	data_StrInt *data = d;	data_StrInt *src = s;		data->count += src->count;		return 0;}data_StrInt *Str2Int_init() {	data_StrInt *data = malloc(sizeof(data_StrInt));		/* functions */	data->destructor	= Str2Int_destroy;	data->write		= Str2Int_write;	data->copy		= Str2Int_copy;	data->append		= Str2Int_append;	data->read		= Str2Int_read;		data->string	= NULL;	data->count	= 0;	data->type	= 0;		return data;}data_StrInt *createStr2Int(char *str, int count, int type) {	data_StrInt *data = Str2Int_init();		Str2Int_setdata(data, str, count, type);		return data;}/* end of Str2Int *//* begin of StrInt */int StrInt_setdata(data_StrInt *data, const char *str, int count) {	data->string	= malloc(strlen(str)+1);	strcpy(data->string, str);	data->count	= count;	data->type	= 0;		return 0;}data_StrInt *StrInt_init() {	data_StrInt *data = malloc(sizeof(data_StrInt));		/* functions */	data->destructor	= Str2Int_destroy;	data->write		= Str2Int_write;	data->copy		= Str2Int_copy;	data->append		= Str2Int_append;	data->read		= Str2Int_read;		data->string	= NULL;	data->count	= 0;	data->type	= 0;		return data;}data_StrInt *createStrInt(char *str, int count) {	data_StrInt *data = StrInt_init();		StrInt_setdata(data, str, count);		return data;}/* end of StrInt *//* begin of Str3Int */int Str3Int_write(gzFile *f, void *d) {	data_Str3Int *data = d;		gzwrite(f, data->string, strlen(data->string));	gzprintf(f, "\n%d,%d,%d\n", 		data->count,		data->vcount,		data->type);		return 0;}int Str3Int_destroy(void *d) {	data_Str3Int *data = d;//printf("freed  : %s (%p)\n", data->string, data->string);	if (data->string != NULL) free(data->string);	if (data != NULL) free(data);		return 0;}int Str3Int_setdata(data_Str3Int *data, const char *str, int count, int type, int vcount) {	data->string	= malloc(strlen(str)+1);	strcpy(data->string, str);//printf("alloced: %s (%p)\n", data->string, data->string);	data->count	= count;	data->type	= type;	data->vcount	= vcount;		return 0;}int Str3Int_read(void *data, gzFile *f) {	char *_s = NULL, *_c = NULL;	int c, type, vcount;		pcre *match;	const char *errptr;	int erroffset = 0;#define N 20 + 1	int ovector[3 * N], n;	const char **list;		if ((_s = _getline(f)) == NULL) return -1;		if (*_s == '\0') {		free(_s);		return -1;	}	if (mstate_is_section_end(_s)) {		free(_s);		return 0;	}		if ((_c = _getline(f)) == NULL) return -1;		if (*_c == '\0') {		free(_s);		free(_c);		return -1;	}		/* remove the newline */	_s[strlen(_s)-1] = '\0';		if ((match = pcre_compile(		"^([0-9]+),([0-9]+),([0-9]+)$", 		0, &errptr, &erroffset, NULL)) == NULL) {				fprintf(stderr, "%s.%d: rexexp compilation error at %s\n", __FILE__, __LINE__, errptr);						return -1;	} 		if ((n = pcre_exec(match, NULL, _c, strlen(_c), 0, 0, ovector, 3 * N)) < 0) {		if (n == PCRE_ERROR_NOMATCH) {			fprintf(stderr, "%s.%d: string doesn't match: %s\n", __FILE__, __LINE__, _c);		} else {			fprintf(stderr, "%s.%d: execution error while matching: %d\n", __FILE__, __LINE__, n);		}		return -1;	}#undef N			pcre_get_substring_list(_c, ovector, n, &list);		c = strtol(list[1], NULL, 10);	type = strtol(list[2], NULL, 10);	vcount = strtol(list[3], NULL, 10);		Str3Int_setdata(data, _s, c, type, vcount);		free(_s);	free(_c);	free(list);	free(match);		return 0;}void *Str3Int_copy(void *d) {	data_Str3Int *_data = d;		data_Str3Int *data = Str3Int_init();		Str3Int_setdata(data, _data->string, _data->count, _data->type, _data->vcount);		return data;}int Str3Int_append(void *d, void *s) {	data_Str3Int *data = d;	data_Str3Int *src = s;		data->count += src->count;	data->vcount += src->vcount;		return 0;}data_Str3Int *Str3Int_init() {	data_Str3Int *data = malloc(sizeof(data_Str3Int));		/* functions */	data->destructor	= Str3Int_destroy;	data->write		= Str3Int_write;	data->copy		= Str3Int_copy;	data->append		= Str3Int_append;	data->read		= Str3Int_read;		data->string	= NULL;	data->count	= 0;	data->type	= 0;	data->vcount	= 0;		return data;}data_Str3Int *createStr3Int(char *str, int count, int type, int vcount) {	data_Str3Int *data = Str3Int_init();		Str3Int_setdata(data, str, count, type, vcount);		return data;}/* end of Str3Int *//* begin of Visit */int Visit_write(gzFile *f, void *d) {	data_Visit *data = d;	gzwrite(f, data->string, strlen(data->string));	gzwrite(f, "\n", strlen("\n"));	gzwrite(f, data->lasturl, strlen(data->lasturl));	gzwrite(f, "\n", strlen("\n"));	gzwrite(f, data->useragent, strlen(data->useragent));		gzprintf(f, "\n%d,%d,%d,%d\n", 		data->count,		data->timediff,		data->timestamp,		data->type);	return 0;}int Visit_destroy(void *d) {	data_Visit *data = d;		if (data->string != NULL) free(data->string);	if (data->lasturl != NULL) free(data->lasturl);	if (data->useragent != NULL) free(data->useragent);	if (data != NULL) free(data);		return 0;}int Visit_setdata(data_Visit *data, char *str, char *lasturl, char *useragent, int count, long timediff, time_t timestamp, int type) {	data->string = malloc(strlen(str)+1);	strcpy(data->string, str);		data->lasturl = malloc(strlen(lasturl)+1);	strcpy(data->lasturl, lasturl);		if (useragent) {		data->useragent = malloc(strlen(useragent)+1);		strcpy(data->useragent, useragent);	} else {		data->useragent = malloc(strlen("-")+1);		strcpy(data->useragent, "-");	}		data->timediff	= timediff;	data->timestamp	= timestamp;	data->count	= count;	data->type	= type;		return 0;}int Visit_read(void *data, gzFile *f) {	char *_ls = NULL;	char *_s = NULL, *_c = NULL, *_ua = NULL;	int count, type, tdiff, tstamp;		pcre *match;	const char *errptr;	int erroffset = 0;#define N 20 + 1	int ovector[3 * N], n;	const char **list;		if ((_s = _getline(f)) == NULL) return -1;		if (*_s == '\0') {		free(_s);		return -1;	}	if (mstate_is_section_end(_s)) {		free(_s);		return 0;	}		if ((_ls = _getline(f)) == NULL) return -1;		if (*_ls == '\0') {		free(_s);		free(_ls);		return -1;	}		if ((_ua = _getline(f)) == NULL) return -1;		if (*_ua == '\0') {		free(_s);		free(_ls);		free(_ua);		return -1;	}		if ((_c = _getline(f)) == NULL) return -1;		if (*_c == '\0') {		free(_s);		free(_ls);		free(_ua);		free(_c);		return -1;	}				/* remove the newline */	_s[strlen(_s)-1] = '\0';	_ls[strlen(_ls)-1] = '\0';	_ua[strlen(_ua)-1] = '\0';		if ((match = pcre_compile(		"^([0-9]+),([0-9]+),([0-9]+),([0-9]+)$", 		0, &errptr, &erroffset, NULL)) == NULL) {				fprintf(stderr, "%s.%d: rexexp compilation error at %s\n", __FILE__, __LINE__, errptr);				return -1;	} 		if ((n = pcre_exec(match, NULL, _c, strlen(_c), 0, 0, ovector, 3 * N)) < 0) {		if (n == PCRE_ERROR_NOMATCH) {			fprintf(stderr, "%s.%d: string doesn't match: %s\n", __FILE__, __LINE__, _c);		} else {			fprintf(stderr, "%s.%d: execution error while matching: %d\n", __FILE__, __LINE__, n);		}		return -1;	}#undef N			pcre_get_substring_list(_c, ovector, n, &list);		count = strtol(list[1], NULL, 10);	tdiff = strtol(list[2], NULL, 10);	tstamp = strtol(list[3], NULL, 10);	type = strtol(list[4], NULL, 10);		Visit_setdata(data, _s, _ls, _ua, count, tdiff, tstamp, type);		free(_s);	free(_ls);	free(_c);	free(_ua);	free(list);	free(match);		return 0;}int Visit_append(void *d, void *s) {	data_Visit *data = d;	data_Visit *src = s;		if (!strcmp(src->string, data->string) && 		!strcmp(src->useragent, data->useragent)) {				if (data->timestamp > src->timestamp) {			data->timestamp = src->timestamp;					free(data->lasturl);			data->lasturl = malloc(strlen(src->lasturl)+1);			strcpy(data->lasturl, src->lasturl);		}				data->count += src->count;				return M_DATA_APPENDED;	} else {		fprintf(stderr, "%s.%d: append skipped: same host, but useragent was different\n", __FILE__, __LINE__);		return M_DATA_NOT_APPENDED;	}}data_Visit *Visit_init() {	data_Visit *data = malloc(sizeof(data_Visit));		/* functions */	data->destructor	= Visit_destroy;	data->write		= Visit_write;	data->copy		= NULL;	data->append		= Visit_append;	data->read		= Visit_read;		data->string	= NULL;	data->count	= 0;	data->type	= 0;	data->timediff	= 0;	data->timestamp	= 0;	data->lasturl	= NULL;	data->useragent = NULL;		return data;}data_Visit *createVisit(char *str, char *lasturl, char *useragent, int count, long timediff, time_t timestamp, int type) {	data_Visit *data = Visit_init();		Visit_setdata(data, str, lasturl, useragent, count, timediff, timestamp, type);		return data;}/* end of Visit */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -