summaryrefslogtreecommitdiff
path: root/examples/Web_Crawler/Command_Processor.cpp
blob: 95b78b77a3356cb376f5d4485d07b3904745a260 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// $Id$

#include "URL.h"
#include "HTTP_URL.h"
#include "Options.h"
#include "Command_Processor.h"
#include "URL_Visitor.h"

ACE_RCSID(Web_Crawler, Command_Processor, "$Id$")

Command::~Command (void)
{
}

URL_Command::URL_Command (URL *url)
  : url_ (url)
{
}

int
URL_Command::execute (void)
{

  ACE_CString check_string (this->url_->url_addr ().get_path_name ());
  if (check_string.find ("news:") >= 0)
    return 0;

  if (check_string.find (".cgi") >= 0)
     return 0;

  if (check_string.find ("mailto") >= 0)
    return 0;

  if (check_string.find (".gif") >= 0)
    return 0;

  if (check_string.find (".pdf") >= 0)
    return 0;

  if (check_string.find (".map") >= 0)
    return 0;

  if (check_string.find (".bmp") >= 0)
    return 0;

  if (check_string.find (".jpg") >= 0)
    return 0;

  if (this->url_->accept (OPTIONS::instance ()->visitor ()) !=0)
    {
      ACE_DEBUG ((LM_DEBUG,
                "Coudnt accept url\n"));
      return -1;
    }
  return 0;
}

int
URL_Command::destroy (void)
{
  delete this;
  return 0;
}
Command_Processor::Command_Processor (void)
{
}

Command_Processor::~Command_Processor (void)
{
}

int
Command_Processor::destroy (void)
{
  delete this;
  return 0;
return 0;
}

int
Command_Processor::execute (void)
{
  Command *command;
  while (this->url_queue_.is_empty () != 1)
    {
      if (this->url_queue_.dequeue_head (command) != 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "%p\n", "dequeue_head"),
                          -1);
      URL_Command *url_command = ACE_dynamic_cast (URL_Command *,
                                                   command);
      Auto_Destroyer<URL_Command> url_command_ptr (url_command);
      if (url_command_ptr->execute () != 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "%p\n", "Couldnt execute command"),
                          -1);
    }
  return 0;
}

int
Command_Processor::insert (Command *command)
{
  // According to the order specified the commands are removed from the queue.
  if (this->url_queue_.is_full() != 1)
    {
      if (ACE_OS::strcmp (OPTIONS::instance ()->order (),"FIFO") == 0)
        {
          if (this->url_queue_.enqueue_tail (command) !=0)
            ACE_ERROR_RETURN ((LM_ERROR,
                               "%p\n", "enqueue_tail"),
                              - 1);
        }
      if (ACE_OS::strcmp (OPTIONS::instance ()->order (),"LIFO") == 0)
        {
          if (this->url_queue_.enqueue_head (command) !=0)
            ACE_ERROR_RETURN ((LM_ERROR,
                               "%p\n", "enqueue_head"),
                              - 1);
        }
    }
  return 0;
}

#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class ACE_Singleton<Options, ACE_Null_Mutex>;
template class ACE_Node<Command *>;
template class ACE_Unbounded_Queue_Iterator<Command *>;
template class ACE_Unbounded_Queue<Command *>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#pragma instantiate ACE_Singleton<Options, ACE_Null_Mutex>
#pragma instantiate ACE_Node<Command *>
#pragma instantiate ACE_Unbounded_Queue_Iterator<Command *>
#pragma instantiate ACE_Unbounded_Queue<Command *>
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */