my $cur_metric;
my @lines = split (/^/, $in);
- foreach my $line (@lines) {
- if ($line =~ m!Metric: (\S+); (\S+); (\S+) / (\S+)!) {
- $metrics{$1} = {
- isspam => $2,
- score => $3 + 0,
- threshold => $4 + 0,
- symbols => [],
- urls => [],
- messages => [],
- };
- $cur_metric = $1;
- }
- elsif ($line =~ /^Symbol: (\S+);\s*(.+)${EOL}$/ && $cur_metric) {
- # Line with parameters
- my $symref = $metrics{$cur_metric}->{'symbols'};
- push(@$symref, "$1($2)");
- }
- elsif ($line =~ /^Symbol: (\S+)/ && $cur_metric) {
- my $symref = $metrics{$cur_metric}->{'symbols'};
- push(@$symref, $1);
- }
- elsif ($line =~ /^Urls: (.+)$/ && $cur_metric) {
- @{ $metrics{$cur_metric}->{'urls'} } = split /,\s+/, $1;
- }
- elsif ($line =~ /^Message: (.+)/ && $cur_metric) {
- my $symref = $metrics{$cur_metric}->{'messages'};
- push(@$symref, $1);
+ if (lc $self->{'command'} eq 'urls') {
+ $metrics{'default'} = {
+ isspam => 'false',
+ score => 0,
+ threshold => 0,
+ symbols => [],
+ urls => [],
+ messages => [],
+ };
+ foreach my $line (@lines) {
+ if ($line =~ /^Urls: (.+)$/) {
+ @{ $metrics{'default'}->{'urls'} } = split /,\s+/, $1;
+ }
}
- elsif ($line =~ /^${EOL}$/) {
- last;
+ }
+ else {
+ foreach my $line (@lines) {
+ if ($line =~ m!Metric: (\S+); (\S+); (\S+) / (\S+)!) {
+ $metrics{$1} = {
+ isspam => $2,
+ score => $3 + 0,
+ threshold => $4 + 0,
+ symbols => [],
+ urls => [],
+ messages => [],
+ };
+ $cur_metric = $1;
+ }
+ elsif ($line =~ /^Symbol: (\S+);\s*(.+)${EOL}$/ && $cur_metric) {
+ # Line with parameters
+ my $symref = $metrics{$cur_metric}->{'symbols'};
+ push(@$symref, "$1($2)");
+ }
+ elsif ($line =~ /^Symbol: (\S+)/ && $cur_metric) {
+ my $symref = $metrics{$cur_metric}->{'symbols'};
+ push(@$symref, $1);
+ }
+ elsif ($line =~ /^Urls: (.+)$/ && $cur_metric) {
+ @{ $metrics{$cur_metric}->{'urls'} } = split /,\s+/, $1;
+ }
+ elsif ($line =~ /^Message: (.+)/ && $cur_metric) {
+ my $symref = $metrics{$cur_metric}->{'messages'};
+ push(@$symref, $1);
+ }
+ elsif ($line =~ /^${EOL}$/) {
+ last;
+ }
}
}
return 0;
}
-static int
+static gboolean
urls_command_handler (struct worker_task *task)
{
GList *cur;
cur = g_list_next (cur);
}
- buflen += sizeof (RSPAMD_REPLY_BANNER " 0 OK" CRLF CRLF "URLs: ");
+ buflen += sizeof (RSPAMD_REPLY_BANNER " 0 OK" CRLF CRLF "Urls: ");
outbuf = memory_pool_alloc (task->task_pool, buflen * sizeof (char));
r = rspamd_snprintf (outbuf, buflen, "%s 0 %s" CRLF, (task->proto == SPAMC_PROTO) ? SPAMD_REPLY_BANNER : RSPAMD_REPLY_BANNER, "OK");
- r += rspamd_snprintf (outbuf + r, buflen - r - 2, "URLs: ");
+ r += rspamd_snprintf (outbuf + r, buflen - r - 2, "Urls: ");
cur = g_list_first (task->urls);
g_tree_destroy (url_tree);
if (! rspamd_dispatcher_write (task->dispatcher, outbuf, r, FALSE, TRUE)) {
- return -1;
+ return FALSE;
}
msg_info ("msg ok, id: <%s>, %d urls extracted", task->message_id, num);
+ task->state = STATE_REPLY;
- return 0;
+ return TRUE;
}