1 #include "ace/Truncate.h"
5 URL_Iterator::~URL_Iterator ()
10 URL_Iterator::destroy ()
17 HTML_Body_Iterator::HTML_Body_Iterator (URL
&url
)
23 HTML_Body_Iterator::next (ACE_CString
&url
)
30 for (buf
= this->url_
.stream ().recv (len
);
32 buf
= this->url_
.stream ().recv (len
))
34 buffer
.set (buf
, BUFSIZ
, 1);
36 href_index
= ACE_Utils::truncate_cast
<int> (buffer
.find ("HREF"));
39 href_index
= ACE_Utils::truncate_cast
<int> (buffer
.find ("href"));
41 // Grep fpr " and grab the string until end-"
44 // Get back to buffer start location.
45 this->url_
.stream ().seek (-1 * static_cast<ACE_OFF_T
> (len
),
49 ACE_Utils::truncate_cast
<int> (
50 buffer
.find ('\"', href_index
));
55 start_index
+= href_index
;
58 ACE_Utils::truncate_cast
<int> (
59 buffer
.find ('\"', start_index
+ 1));
64 end_index
+= start_index
+ 1;
66 ssize_t url_len
= end_index
- (start_index
+ 1);
68 ACE_CString temp
= buffer
.substring (start_index
+ 1,
70 url
.set (temp
.c_str (), len
, 1);
72 this->url_
.stream ().seek (end_index
+ 1);
80 HTTP_Header_Iterator::HTTP_Header_Iterator (URL
&url
)
87 HTTP_Header_Iterator::next (ACE_CString
&line
)
89 if (this->end_of_header_
)
94 (c
= this->url_
.stream ().get_char ()) != (char)EOF
;
97 // Check to see if we're at the end of the header line.
98 if (c
== '\r' && this->url_
.stream ().peek_char (0) == '\n')
100 line
.set (this->url_
.stream ().recv (),
101 this->url_
.stream ().recv_len () - 1,
104 // Check to see if we're at the end of the header.
105 if (this->url_
.stream ().peek_char (1) == '\r'
106 && this->url_
.stream ().peek_char (2) == '\n')
108 this->end_of_header_
= 1;
109 // We're at the end of the header section.
110 this->url_
.stream ().seek (3);
113 // We're at the end of the line.
114 this->url_
.stream ().seek (1);
118 // Handle broken Web servers that use '\n' instead of
122 line
.set (this->url_
.stream ().recv (),
123 (this->url_
.stream ().recv_len ()),
126 // Check to see if we're at the end of the header.
127 if (this->url_
.stream ().peek_char (0) == '\n')
129 // We're at the end of the header section.
130 this->url_
.stream ().seek (1);
131 this->end_of_header_
= 1;
142 URL_Download_Iterator::URL_Download_Iterator (URL
&url
)
148 URL_Download_Iterator::next (ACE_CString
&buffer
)
152 const char *buf
= this->url_
.stream ().recv (len
);
159 buffer
.set (buf
, len
, 1);