Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

TCP_ContentLine Class Reference

#include <TCP_Contents.h>

Inheritance diagram for TCP_ContentLine:

Inheritance graph
[legend]
Collaboration diagram for TCP_ContentLine:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 TCP_ContentLine (TCP_Endpoint *endp, int is_NUL_sensitive, int skip_partial, int CRLF_as_EOL=(CR_as_EOL|LF_as_EOL))
 ~TCP_ContentLine ()
int HasPartialLine () const

Protected Member Functions

 TCP_ContentLine ()
void Init (int size)
void Deliver (double t, int seq, int len, u_char *data)
virtual void DoDeliver (double t, int seq, int len, u_char *data)
virtual int DoDeliverOnce (int len, u_char *data)
virtual void ExcessiveLine (const u_char *data, int len)
u_char * NextNewLine (int len, u_char *data, int &offset)
void CheckNUL ()
 DECLARE_SERIAL (TCP_ContentLine)

Protected Attributes

char * buf
int offset
int buf_len
unsigned int last_char
unsigned int flag_NULs:1
unsigned int punt_on_partial:1
unsigned int line_limit:1
unsigned int CR_LF_as_EOL:2

Constructor & Destructor Documentation

TCP_ContentLine::TCP_ContentLine TCP_Endpoint endp,
int  is_NUL_sensitive,
int  skip_partial,
int  CRLF_as_EOL = (CR_as_EOL|LF_as_EOL)
 

Definition at line 409 of file TCP_Contents.cc.

References CR_LF_as_EOL, flag_NULs, Init(), line_limit, and punt_on_partial.

00412 : TCP_Contents(arg_endp)
00413         {
00414         flag_NULs = is_NUL_sensitive;
00415         punt_on_partial = skip_partial;
00416         CR_LF_as_EOL = arg_CRLF_as_EOL;
00417         line_limit = 1024;
00418         buf = 0;
00419         Init(0);
00420         }

TCP_ContentLine::~TCP_ContentLine  ) 
 

Definition at line 445 of file TCP_Contents.cc.

00446         {
00447         delete [] buf;
00448         }

TCP_ContentLine::TCP_ContentLine  )  [inline, protected]
 

Definition at line 126 of file TCP_Contents.h.

00126 { }


Member Function Documentation

void TCP_ContentLine::CheckNUL  )  [protected]
 

Definition at line 591 of file TCP_Contents.cc.

References TCP_Contents::Conn(), flag_NULs, Connection::FlagEvent(), TCP_Endpoint::LastSeq(), NUL_IN_LINE, TCP_Endpoint::StartSeq(), TCP_Endpoint::state, TCP_PARTIAL, and Connection::Weird().

Referenced by TCP_NVT::DoDeliver(), and DoDeliverOnce().

00592         {
00593         // If this is the first byte seen on this connection,
00594         // and if the connection's state is PARTIAL, then we've
00595         // intercepted a keep-alive, and shouldn't complain
00596         // about it.  Note that for PARTIAL connections, the
00597         // starting sequence number is adjusted as though there
00598         // had been an initial SYN, so we check for whether
00599         // the connection has at most two bytes so far.
00600         if ( endp->state == TCP_PARTIAL &&
00601              endp->LastSeq() - endp->StartSeq() <= 2 )
00602                 ; // Ignore it.
00603         else
00604                 {
00605                 if ( Conn()->FlagEvent(NUL_IN_LINE) )
00606                         Conn()->Weird("NUL_in_line");
00607                 flag_NULs = 0;
00608                 }
00609         }

TCP_ContentLine::DECLARE_SERIAL TCP_ContentLine   )  [protected]
 

void TCP_ContentLine::Deliver double  t,
int  seq,
int  len,
u_char *  data
[protected, virtual]
 

Reimplemented from TCP_Contents.

Definition at line 450 of file TCP_Contents.cc.

References TCP_Contents::Conn(), DoDeliver(), internal_error(), TCP_Endpoint::peer, punt_on_partial, Connection::SetRecordPackets(), Connection::SetSkip(), TCP_Endpoint::state, and TCP_PARTIAL.

Referenced by TCP_NVT::ScanOption().

00451         {
00452         if ( len <= 0 || skip_deliveries )
00453                 return;
00454 
00455         if ( punt_on_partial &&
00456              (endp->state == TCP_PARTIAL || endp->peer->state == TCP_PARTIAL) )
00457                 {
00458                 Conn()->SetSkip(1);
00459                 Conn()->SetRecordPackets(0);    // ###
00460                 return;
00461                 }
00462 
00463         if ( buf && len + offset >= buf_len )
00464                 { // Make sure we have enough room to accommodate the new stuff.
00465                 int old_buf_len = buf_len;
00466                 buf_len = ((offset + len) * 3) / 2 + 1;
00467 
00468                 char* tmp = new char[buf_len];
00469                 for ( int i = 0; i < old_buf_len; ++i )
00470                         tmp[i] = buf[i];
00471 
00472                 delete [] buf;
00473                 buf = tmp; 
00474 
00475                 if ( ! buf )
00476                         internal_error("out of memory delivering endpoint line");
00477                 }
00478 
00479         DoDeliver(t, seq, len, data);
00480         }

void TCP_ContentLine::DoDeliver double  t,
int  seq,
int  len,
u_char *  data
[protected, virtual]
 

Reimplemented in TCP_NVT, and RloginEndpoint.

Definition at line 497 of file TCP_Contents.cc.

References CR_as_EOL, CR_LF_as_EOL, DoDeliverOnce(), and last_char.

Referenced by Deliver().

00498         {
00499         while ( len > 0 )
00500                 {
00501                 if ( (CR_LF_as_EOL & CR_as_EOL) &&
00502                      last_char == '\r' && *data == '\n' )
00503                         {
00504                         // CR is already considered as EOL.
00505                         // Compress CRLF to just one line termination.
00506                         last_char = *data;
00507                         --len; ++data;
00508                         }
00509 
00510                 int n = DoDeliverOnce(len, data);
00511                 len -= n;
00512                 data += n;
00513                 }
00514         }

int TCP_ContentLine::DoDeliverOnce int  len,
u_char *  data
[protected, virtual]
 

Reimplemented in HTTP_Endpoint.

Definition at line 516 of file TCP_Contents.cc.

References CheckNUL(), TCP_Contents::Conn(), CR_as_EOL, CR_LF_as_EOL, EMIT_LINE, flag_NULs, Connection::FlagEvent(), Init(), last_char, LF_as_EOL, SINGULAR_CR, SINGULAR_LF, and Connection::Weird().

Referenced by DoDeliver(), and HTTP_Endpoint::DoDeliverOnce().

00517         {
00518         const u_char* data_start = data;
00519 
00520         // ### Note, excessive_line checking no longer done.
00521 
00522         // ### This code should be correspondingly updated in TCP_NVT
00523         // ### and Rlogin.
00524         //        fprintf(stderr, "Data delivered (len): '%.*s' (%d)\n", len, data, len);
00525 
00526         if ( len <= 0 )
00527                 return 0;
00528 
00529         for ( ; len > 0; --len, ++data )
00530                 {
00531                 if ( offset >= buf_len )
00532                         Init(buf_len * 2);
00533 
00534                 int c = data[0];
00535 
00536 #define EMIT_LINE \
00537         { \
00538         buf[offset] = '\0'; \
00539         Conn()->NewLine(this, offset, buf); \
00540         offset = 0; \
00541         last_char = c; \
00542         return data + 1 - data_start; \
00543         }
00544 
00545                 switch ( c ) {
00546                 case '\r':
00547                         if ( CR_LF_as_EOL & CR_as_EOL )
00548                                 EMIT_LINE
00549                         else
00550                                 buf[offset++] = c;
00551                         break;
00552 
00553                 case '\n':
00554                         if ( last_char == '\r' )
00555                                 {
00556                                 --offset; // remove '\r'
00557                                 EMIT_LINE
00558                                 }
00559                         else if ( CR_LF_as_EOL & LF_as_EOL )
00560                                 EMIT_LINE
00561                         else
00562                                 {
00563                                 if ( Conn()->FlagEvent(SINGULAR_LF) )
00564                                         Conn()->Weird("line_terminated_with_single_LF");
00565                                 buf[offset++] = c;
00566                                 }
00567                         break;
00568 
00569                 case '\0':
00570                         if ( flag_NULs )
00571                                 CheckNUL();
00572                         else
00573                                 buf[offset++] = c;
00574                         break;
00575 
00576                 default:
00577                         buf[offset++] = c;
00578                         break;
00579                 }
00580 
00581                 if ( last_char == '\r' )
00582                         if ( Conn()->FlagEvent(SINGULAR_CR) )
00583                                 Conn()->Weird("line_terminated_with_single_CR");
00584 
00585                 last_char = c;
00586                 }
00587 
00588         return data - data_start;
00589         }

void TCP_ContentLine::ExcessiveLine const u_char *  data,
int  len
[protected, virtual]
 

Definition at line 611 of file TCP_Contents.cc.

References TCP_Contents::Conn(), Connection::Event(), and line_limit.

00612         {
00613         Conn()->Event(excessive_line);
00614         line_limit = 0;
00615         }

int TCP_ContentLine::HasPartialLine  )  const [inline]
 

Definition at line 123 of file TCP_Contents.h.

Referenced by IdentConn::Done(), FTP_Conn::Done(), and FingerConn::Done().

00123 { return buf && offset > 0; }

void TCP_ContentLine::Init int  size  )  [protected]
 

Definition at line 422 of file TCP_Contents.cc.

References last_char.

Referenced by RloginEndpoint::DoDeliver(), TCP_NVT::DoDeliver(), DoDeliverOnce(), and TCP_ContentLine().

00423         {
00424         if ( size < 128 )
00425                 size = 128;
00426 
00427         char* b = new char[size];
00428 
00429         if ( buf )
00430                 {
00431                 if ( offset > 0 )
00432                         memcpy(b, buf, offset);
00433                 delete [] buf;
00434                 }
00435         else
00436                 {
00437                 offset = 0;
00438                 last_char = 0;
00439                 }
00440 
00441         buf = b;
00442         buf_len = size;
00443         }

u_char * TCP_ContentLine::NextNewLine int  len,
u_char *  data,
int &  offset
[protected]
 

Definition at line 482 of file TCP_Contents.cc.

References last_char.

00483         {
00484         u_char* end_of_data = data + len;
00485         for ( u_char* p = data; p < end_of_data; ++p )
00486                 if ( *p == '\n' || *p == '\r' )
00487                         {
00488                         next_pos = p + 1 - data;        // where next line begins
00489                         last_char = *p;
00490                         return p;
00491                         }
00492         next_pos = 0;
00493         return 0;
00494         }


Member Data Documentation

char* TCP_ContentLine::buf [protected]
 

Definition at line 138 of file TCP_Contents.h.

int TCP_ContentLine::buf_len [protected]
 

Definition at line 140 of file TCP_Contents.h.

unsigned int TCP_ContentLine::CR_LF_as_EOL [protected]
 

Definition at line 153 of file TCP_Contents.h.

Referenced by DoDeliver(), DoDeliverOnce(), and TCP_ContentLine().

unsigned int TCP_ContentLine::flag_NULs [protected]
 

Definition at line 144 of file TCP_Contents.h.

Referenced by CheckNUL(), DoDeliverOnce(), and TCP_ContentLine().

unsigned int TCP_ContentLine::last_char [protected]
 

Definition at line 141 of file TCP_Contents.h.

Referenced by DoDeliver(), DoDeliverOnce(), Init(), and NextNewLine().

unsigned int TCP_ContentLine::line_limit [protected]
 

Definition at line 150 of file TCP_Contents.h.

Referenced by ExcessiveLine(), and TCP_ContentLine().

int TCP_ContentLine::offset [protected]
 

Definition at line 139 of file TCP_Contents.h.

unsigned int TCP_ContentLine::punt_on_partial [protected]
 

Definition at line 147 of file TCP_Contents.h.

Referenced by Deliver(), and TCP_ContentLine().


The documentation for this class was generated from the following files:
Generated on Sat May 1 15:32:41 2004 for bro_docs.8a82 by doxygen 1.3.6