summaryrefslogtreecommitdiffstats
path: root/utils/url_extracter.c
blob: 97bf72c47b882aba7227f25c9b0b33e34ae60af6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <sys/types.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <sys/param.h>

#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <syslog.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>

#include <gmime/gmime.h>

#include "../src/config.h"
#if !defined(HAVE_OWN_QUEUE_H) && defined(HAVE_SYS_QUEUE_H)
#include <sys/queue.h>
#endif
#ifdef HAVE_OWN_QUEUE_H
#include "../src/queue.h"
#endif

#include "../src/main.h"
#include "../src/cfg_file.h"
#include "../src/url.h"
#include "../src/util.h"
#include "../src/message.h"

rspamd_hash_t *counters = NULL;

int
main (int argc, char **argv)
{
	struct worker_task task;
	struct uri *url;
	char *buf = NULL;
	size_t pos = 0, size = 65535;
	GList *cur;
	
	g_mem_set_vtable(glib_mem_profiler_table);
	g_mime_init (0);
	bzero (&task, sizeof (struct worker_task));
	task.task_pool = memory_pool_new (memory_pool_get_size ());
	
	/* Preallocate buffer */
	buf = g_malloc (size);

	while (!feof (stdin)) {
		*(buf + pos) = getchar ();
		pos ++;
		if (pos == size) {
			size *= 2;
			buf = g_realloc (buf, size);
		}
	}
	
	task.cfg = memory_pool_alloc0 (task.task_pool, sizeof (struct config_file));
	task.cfg->log_level = G_LOG_LEVEL_CRITICAL;
	task.cfg->log_fd = STDERR_FILENO;
	g_log_set_default_handler (file_log_function, task.cfg);

	task.msg = memory_pool_alloc (task.task_pool, sizeof (f_str_t));
	task.msg->begin = buf;
	task.msg->len = pos;
	process_message (&task);
	
	cur = task.urls;
	while (cur) {
		url = cur->data;
		printf ("%s\n", struri (url));
		cur = g_list_next (cur);
	}
	
	return 0;
}