#include <stdlib.h>
#endif
-#define READ_BUF_SIZE 10240
-#define WRITE_BUF_SIZE 10240
-#define LINE_BUF_SIZE 2048
+#define READ_BUF_SIZE 128*1024
+#define WRITE_BUF_SIZE 128*1024
+#define LINE_BUF_SIZE 128*1024
static apr_file_t *errfile;
static const char *shortname = "logresolve";
"Options:" NL
" -s Record statistics to STATFILE when finished." NL
NL
- " -c Perform double lookups when resolving IP addresses." NL,
+ " -c Perform double lookups when resolving IP addresses." NL,
shortname, shortname);
exit(1);
}
apr_status_t status;
const char * arg;
char * stats = NULL;
-#if APR_MAJOR_VERSION > 1 || (APR_MAJOR_VERSION == 1 && APR_MINOR_VERSION >= 3)
char * inbuffer;
char * outbuffer;
-#endif
- char line[LINE_BUF_SIZE];
+ char * line;
int doublelookups = 0;
if (apr_app_initialize(&argc, &argv, NULL) != APR_SUCCESS) {
apr_file_open_stdout(&outfile, pool);
apr_file_open_stdin(&infile, pool);
-#if APR_MAJOR_VERSION > 1 || (APR_MAJOR_VERSION == 1 && APR_MINOR_VERSION >= 3)
/* Allocate two new 10k file buffers */
- if ((outbuffer = apr_palloc(pool, WRITE_BUF_SIZE)) == NULL ||
- (inbuffer = apr_palloc(pool, READ_BUF_SIZE)) == NULL) {
+ if ( (outbuffer = apr_palloc(pool, WRITE_BUF_SIZE)) == NULL
+ || (inbuffer = apr_palloc(pool, READ_BUF_SIZE)) == NULL
+ || (line = apr_palloc(pool, LINE_BUF_SIZE)) == NULL) {
return 1;
}
/* Set the buffers */
apr_file_buffer_set(infile, inbuffer, READ_BUF_SIZE);
apr_file_buffer_set(outfile, outbuffer, WRITE_BUF_SIZE);
-#endif
cache = apr_hash_make(pool);
- if(apr_pool_create(&pline, NULL) != APR_SUCCESS){
+ if (apr_pool_create(&pline, pool) != APR_SUCCESS) {
return 1;
}
- while (apr_file_gets(line, sizeof(line), infile) == APR_SUCCESS) {
+ while (apr_file_gets(line, LINE_BUF_SIZE, infile) == APR_SUCCESS) {
char *hostname;
char *space;
apr_sockaddr_t *ip;
/* Check if this could even be an IP address */
if (!apr_isxdigit(line[0]) && line[0] != ':') {
- withname++;
+ withname++;
apr_file_puts(line, outfile);
continue;
}
resolves++;
/* From here on our we cache each result, even if it was not
- * succesful
+ * successful
*/
cachesize++;
/* Add to cache */
*space = '\0';
apr_hash_set(cache, line, APR_HASH_KEY_STRING,
- apr_pstrdup(pool, line));
+ apr_pstrdup(apr_hash_pool_get(cache), line));
continue;
}
/* Add to cache */
*space = '\0';
apr_hash_set(cache, line, APR_HASH_KEY_STRING,
- apr_pstrdup(pool, line));
+ apr_pstrdup(apr_hash_pool_get(cache), line));
continue;
}
}
/* Store it in the cache */
apr_hash_set(cache, line, APR_HASH_KEY_STRING,
- apr_pstrdup(pool, hostname));
+ apr_pstrdup(apr_hash_pool_get(cache), hostname));
apr_pool_clear(pline);
}
if (stats) {
apr_file_t *statsfile;
if (apr_file_open(&statsfile, stats,
- APR_FOPEN_WRITE | APR_FOPEN_CREATE | APR_FOPEN_TRUNCATE,
+ APR_FOPEN_WRITE | APR_FOPEN_CREATE | APR_FOPEN_TRUNCATE,
APR_OS_DEFAULT, pool) != APR_SUCCESS) {
apr_file_printf(errfile, "%s: Could not open %s for writing.",
shortname, stats);