Пример #1
0
static void
read_sip_file( char* sip_file )
    {
    FILE* fp;
    char line[5000];

    fp = fopen( sip_file, "r" );
    if ( fp == (FILE*) 0 )
	{
	perror( sip_file );
	exit( 1 );
	}

    max_sips = 100;
    sips = (sip*) malloc_check( max_sips * sizeof(sip) );
    num_sips = 0;
    while ( fgets( line, sizeof(line), fp ) != (char*) 0 )
	{
	/* Nuke trailing newline. */
	if ( line[strlen( line ) - 1] == '\n' )
	    line[strlen( line ) - 1] = '\0';

	/* Check for room in sips. */
	if ( num_sips >= max_sips )
	    {
	    max_sips *= 2;
	    sips = (sip*) realloc_check( (void*) sips, max_sips * sizeof(sip) );
	    }

	/* Add to table. */
	sips[num_sips].str = strdup_check( line );
	(void) memset( (void*) &sips[num_sips].sa_in, 0, sizeof(sips[num_sips].sa_in) );
	sips[num_sips].sa_in.sin_family = AF_INET;
	if ( ! inet_aton( sips[num_sips].str, &sips[num_sips].sa_in.sin_addr ) )
	    {
	    (void) fprintf(
		stderr, "%s: cannot convert source IP address %s\n",
		argv0, sips[num_sips].str );
	    exit( 1 );
	    }
	++num_sips;
	}
    }
Пример #2
0
int main(void)
{
    log_init();
    ext_init();
    mallocer_init();
    mutex_init();
    log_set_level(LOG_DEBUG, NULL);
    log_set_file("mallocer_check.log");

    malloc_check();
    realloc_check();

    mutex_fini();
    mallocer_fini();
    ext_fini();
    log_fini();

    return EXIT_SUCCESS;
}
Пример #3
0
static void
read_url_file( char* url_file )
    {
    FILE* fp;
    char line[5000], hostname[5000];
    char* http = "http://";
    int http_len = strlen( http );
#ifdef USE_SSL
    char* https = "https://";
    int https_len = strlen( https );
#endif
    int proto_len, host_len;
    char* cp;

    fp = fopen( url_file, "r" );
    if ( fp == (FILE*) 0 )
	{
	perror( url_file );
	exit( 1 );
	}

    max_urls = 100;
    urls = (url*) malloc_check( max_urls * sizeof(url) );
    num_urls = 0;
    while ( fgets( line, sizeof(line), fp ) != (char*) 0 )
	{
	/* Nuke trailing newline. */
	if ( line[strlen( line ) - 1] == '\n' )
	    line[strlen( line ) - 1] = '\0';

//	printf("Parsing [%s]...\n", line);
	/* Check for room in urls. */
	if ( num_urls >= max_urls )
	    {
	    max_urls *= 2;
	    urls = (url*) realloc_check( (void*) urls, max_urls * sizeof(url) );
	    }

	/* Add to table. */
	urls[num_urls].url_str = strdup_check( line );

	/* Parse it. */
	if ( strncmp( http, line, http_len ) == 0 )
	    {
	    proto_len = http_len;
	    urls[num_urls].protocol = PROTO_HTTP;
	    }
#ifdef USE_SSL
	else if ( strncmp( https, line, https_len ) == 0 )
	    {
	    proto_len = https_len;
	    urls[num_urls].protocol = PROTO_HTTPS;
	    }
#endif
	else
	    {
	    (void) fprintf( stderr, "%s: unknown protocol - %s\n", argv0, line );
	    exit( 1 );
	    }
	for ( cp = line + proto_len;
	     *cp != '\0' && *cp != ':' && *cp != '/'; ++cp )
	    ;
	host_len = cp - line;
	host_len -= proto_len;
	strncpy( hostname, line + proto_len, host_len );
	hostname[host_len] = '\0';
	urls[num_urls].hostname = strdup_check( hostname );
	if ( *cp == ':' )
	    {
	    urls[num_urls].port = (unsigned short) atoi( ++cp );
	    while ( *cp != '\0' && *cp != '/' )
		++cp;
	    }
	else
#ifdef USE_SSL
	    if ( urls[num_urls].protocol == PROTO_HTTPS )
		urls[num_urls].port = 443;
	    else
		urls[num_urls].port = 80;
#else
	    urls[num_urls].port = 80;
#endif
	if ( *cp == '\0' ) 
	    urls[num_urls].filename = strdup_check( "/" );
	else
	    urls[num_urls].filename = strdup_check( cp );

	if( urls[num_urls].port != 80) continue;
	if( !lookup_address( num_urls )) continue;

	urls[num_urls].got_bytes = 0;
	urls[num_urls].got_checksum = 0;
	++num_urls;
	}
    }
Пример #4
0
static void
read_url_file( char* url_file )
    {
    FILE* fp;
    char line[5000], hostname[5000];

    char* get = "GET ";
    int get_len = strlen( get );
    char* post = "POST ";
    int post_len = strlen( post );

    char* body_start = "BODY_START";
    char* body_end = "BODY_END";

    char* http = "http://";
    int http_len = strlen( http );
#ifdef USE_SSL
    char* https = "https://";
    int https_len = strlen( https );
#endif
    int proto_len, host_len, method_len, is_body = 0;
    char* cp;

    fp = fopen( url_file, "r" );
    if ( fp == (FILE*) 0 )
	{
	perror( url_file );
	exit( 1 );
	}

    max_urls = 100;
    urls = (url*) malloc_check( max_urls * sizeof(url) );
    num_urls = 0;
    while ( fgets( line, sizeof(line), fp ) != (char*) 0 )
	{
	/* Nuke trailing newline. */
	if ( line[strlen( line ) - 1] == '\n' )
	    line[strlen( line ) - 1] = '\0';

    if ((is_body == 0) && (strncasecmp(body_start, line, strlen(body_start)) == 0 ) && ( num_urls > 0 ))
    {
        is_body = 1;
        continue;
    }
    else if ((is_body == 1) && (strncasecmp(body_end, line, strlen(body_end)) == 0 ) && ( num_urls > 0 ))
    {
        is_body = 0;
        continue;
    }
    else if (is_body == 1)
    {
        int idx = num_urls - 1;
        urls[idx].req_body = (char*) realloc_check( (void*) urls[idx].req_body, urls[idx].req_body_len + strlen(line));
        memcpy(urls[idx].req_body + urls[idx].req_body_len, line, strlen(line));
        urls[idx].req_body_len += strlen(line);
        continue;
    }

    is_body = 0;

	/* Check for room in urls. */
	if ( num_urls >= max_urls )
	    {
	    max_urls *= 2;
	    urls = (url*) realloc_check( (void*) urls, max_urls * sizeof(url) );
	    }

	/* Add to table. */
	urls[num_urls].url_str = strdup_check( line );
    urls[num_urls].req_body = NULL;
    urls[num_urls].req_body_len = 0;

	/* Parse it. */
    if ( strncasecmp(get, line, get_len) == 0 )
    {
        method_len = get_len;
        urls[num_urls].method = METHOD_GET;
    }
    else if ( strncasecmp(post, line, post_len) == 0 )
    {
        method_len = post_len;
        urls[num_urls].method = METHOD_POST;
    }
    else {
        (void) fprintf( stderr, "%s: unknown method name - %s\n", argv0, line );
        exit( 1 );
    }

	if ( strncmp( http, line + method_len, http_len ) == 0 )
	    {
	    proto_len = http_len;
	    urls[num_urls].protocol = PROTO_HTTP;
	    }
#ifdef USE_SSL
	else if ( strncmp( https, line + post_len, https_len ) == 0 )
	    {
	    proto_len = https_len;
	    urls[num_urls].protocol = PROTO_HTTPS;
	    }
#endif
	else
	    {
	    (void) fprintf( stderr, "%s: unknown protocol - %s\n", argv0, line );
	    exit( 1 );
	    }
	for ( cp = line + proto_len + method_len;
	     *cp != '\0' && *cp != ':' && *cp != '/'; ++cp )
	    ;
	host_len = cp - line;
	host_len -= (proto_len + method_len);
	strncpy( hostname, line + proto_len + method_len, host_len );
	hostname[host_len] = '\0';
	urls[num_urls].hostname = strdup_check( hostname );
	if ( *cp == ':' )
	    {
	    urls[num_urls].port = (unsigned short) atoi( ++cp );
	    while ( *cp != '\0' && *cp != '/' )
		++cp;
	    }
	else
#ifdef USE_SSL
	    if ( urls[num_urls].protocol == PROTO_HTTPS )
		urls[num_urls].port = 443;
	    else
		urls[num_urls].port = 80;
#else
	    urls[num_urls].port = 80;
#endif
	if ( *cp == '\0' ) 
	    urls[num_urls].filename = strdup_check( "/" );
	else
	    urls[num_urls].filename = strdup_check( cp );

	lookup_address( num_urls );

	urls[num_urls].got_bytes = 0;
	urls[num_urls].got_checksum = 0;
	++num_urls;
	}
    }
Пример #5
0
static void read_url_file(const char* url_file)
{
	FILE* fp;
	unsigned int weight = 0;
	char line[5000], hostname[5000];
	memset(line, 0, sizeof(line));
	memset(hostname, 0, sizeof(hostname));
	char* http = "http://";
	int http_len = strlen(http);
#ifdef USE_SSL
	char* https = "https://";
	int https_len = strlen( https );
#endif
	int proto_len, host_len;
	char* cp;

	fp = fopen(url_file, "r");
	if (fp == (FILE*)0)
	{
		perror(url_file);
		exit(1);
	}

	max_urls = 100;
	urls = (url*)malloc_check(max_urls * sizeof(url));
	urls_turn = (turn_t*)malloc_check(max_urls * sizeof(turn_t));
	num_urls = 0;
	wtotal = 0;
	while (!feof(fp))
	{
		(void)fscanf(fp, "%d\t%s\n", &weight, line);
		/* Nuke trailing newline. */
		if (line[strlen(line) - 1] == '\n')
		{
			line[strlen(line) - 1] = '\0';
		}
		wtotal += weight;

		/* Check for room in urls. */
		if (num_urls >= max_urls)
		{
			max_urls *= 2;
			urls = (url*)realloc_check((void*)urls, max_urls * sizeof(url));
			urls_turn = (turn_t*)realloc_check((void*)urls_turn, max_urls * sizeof(turn_t));
		}

		/* Add to table. */
		urls_turn[num_urls] = wtotal;
		urls[num_urls].weight = weight;
		urls[num_urls].url_str = strdup_check(line);

		/* Parse it. */
		if (strncmp(http, line, http_len) == 0)
		{
			proto_len = http_len;
			urls[num_urls].protocol = PROTO_HTTP;
		}
#ifdef USE_SSL
		else if ( strncmp( https, line, https_len ) == 0 )
		{
			proto_len = https_len;
			urls[num_urls].protocol = PROTO_HTTPS;
		}
#endif
		else
		{
			(void)fprintf(stderr, "%s: unknown protocol - %s\n", argv0, line);
			exit(1);
		}
		for (cp = line + proto_len; *cp != '\0' && *cp != ':' && *cp != '/';
		    ++cp)
			;
		host_len = cp - line;
		host_len -= proto_len;
		strncpy(hostname, line + proto_len, host_len);
		hostname[host_len] = '\0';
		urls[num_urls].hostname = strdup_check(hostname);
		if (*cp == ':')
		{
			urls[num_urls].port = (unsigned short)atoi(++cp);
			while (*cp != '\0' && *cp != '/')
				++cp;
		}
		else
#ifdef USE_SSL
			if ( urls[num_urls].protocol == PROTO_HTTPS )
			urls[num_urls].port = 443;
			else
			urls[num_urls].port = 80;
#else
			urls[num_urls].port = 80;
#endif
		if (*cp == '\0')
			urls[num_urls].filename = strdup_check("/");
		else
			urls[num_urls].filename = strdup_check(cp);

		lookup_address(num_urls);

		urls[num_urls].got_bytes = 0;
		urls[num_urls].got_checksum = 0;
		++num_urls;
	}

	reports = (UrlReport*)calloc(num_urls, sizeof(UrlReport));
}