void JAWS_Asynch_Handler::open (ACE_HANDLE h, ACE_Message_Block &mb) { JAWS_TRACE ("JAWS_Asynch_Handler::open"); // This currently does nothing, but just in case. ACE_Service_Handler::open (h, mb); // ioh_ set from the ACT hopefully //this->dispatch_handler (); #if !defined (ACE_WIN32) // Assume at this point there is no data. mb.rd_ptr (mb.wr_ptr ()); mb.crunch (); #else // AcceptEx reads some initial data from the socket. this->handler ()->message_block ()->copy (mb.rd_ptr (), mb.length ()); #endif ACE_Asynch_Accept_Result_Impl *fake_result = ACE_Proactor::instance ()->create_asynch_accept_result (this->proxy (), JAWS_IO_Asynch_Acceptor_Singleton::instance ()->get_handle (), h, mb, JAWS_Data_Block::JAWS_DATA_BLOCK_SIZE, this->ioh_, ACE_INVALID_HANDLE, 0); this->handler ()->handler_ = this; fake_result->complete (0, 1, 0); }
void TAO_ConstantDef_i::value_i (const CORBA::Any &value) { CORBA::TypeCode_var my_tc = this->type_i (); CORBA::TypeCode_var val_tc = value.type (); CORBA::Boolean const equal_tc = my_tc.in ()->equal (val_tc.in ()); if (!equal_tc) { return; } ACE_Message_Block *mb = 0; TAO::Any_Impl *impl = value.impl (); if (impl->encoded ()) { TAO::Unknown_IDL_Type *unk = dynamic_cast<TAO::Unknown_IDL_Type *> (impl); mb = unk->_tao_get_cdr ().steal_contents (); } else { TAO_OutputCDR out; impl->marshal_value (out); TAO_InputCDR in (out); mb = in.steal_contents (); } ACE_Auto_Ptr<ACE_Message_Block> safe (mb); CORBA::TCKind kind = val_tc->kind (); switch (kind) { // The data for these types will be aligned to an 8-byte // boundary, while the rd_ptr may not. case CORBA::tk_double: case CORBA::tk_ulonglong: case CORBA::tk_longlong: case CORBA::tk_longdouble: mb->rd_ptr (ACE_ptr_align_binary (mb->rd_ptr (), ACE_CDR::MAX_ALIGNMENT)); break; default: break; } mb->crunch (); this->repo_->config ()->set_binary_value (this->section_key_, "value", mb->base (), mb->length ()); }
int JAWS_Parse_Headers::parse_header_name (JAWS_Header_Info *info, ACE_Message_Block &mb) { char *p = mb.rd_ptr (); char *q; q = this->skipset (":\n", p, mb.wr_ptr ()); if (q == mb.wr_ptr ()) { // no more progress can be made until we find a ':' return 1; } if (*q != '\n' && q == p) { // Ignore empty header type names info->finish_last_header_value (); info->create_next_header_value (0); info->end_of_line (0); mb.rd_ptr (q+1); return 0; } if (*q == '\n') { // ignore this line mb.rd_ptr (q+1); if (q == p || ((q-1) == p && q[-1] == '\r')) { // blank line means end of headers info->finish_last_header_value (); info->create_next_header_value (0); info->end_of_headers (1); if (mb.rd_ptr () == mb.wr_ptr ()) mb.crunch (); return 1; } // not a blank line, but no ':', so ignore it info->finish_last_header_value (); info->create_next_header_value (0); return 0; } // otherwise, we have a header type name! *q = '\0'; info->create_next_header_value (p); info->end_of_line (0); mb.rd_ptr (q+1); return 0; }
void JAWS_Config_File_Impl::parse_file (void) { ACE_FILE_Connector fconnector; ACE_FILE_IO fio; if (fconnector.connect ( fio , this->faddr_ , 0 , ACE_Addr::sap_any , 0 , O_RDONLY ) == -1) return; ACE_Message_Block buffer (8192); ACE_Message_Block line (4096); ssize_t count = 0; const ACE_TCHAR *sym_name; const ACE_TCHAR *sym_value; int last_line_was_read = 0; ACE_TCHAR *end_of_current_line = 0; ACE_TCHAR *p = 0; while (last_line_was_read || (count = fio.recv (buffer.wr_ptr (), buffer.space () - 2)) >= 0) { end_of_current_line = 0; // Make sure input is newline terminated if it is the last line, // and always null terminated. if (! last_line_was_read) { if (count > 0) { buffer.wr_ptr (count); // Scan forward for at least one newline character p = buffer.rd_ptr (); while (p != buffer.wr_ptr ()) { if (*p == '\n') break; p++; } if (p == buffer.wr_ptr ()) continue; end_of_current_line = p; } else { if (buffer.wr_ptr ()[-1] != '\n') { buffer.wr_ptr ()[0] = '\n'; buffer.wr_ptr (1); } last_line_was_read = 1; } buffer.wr_ptr ()[0] = '\0'; } if (end_of_current_line == 0) { end_of_current_line = buffer.rd_ptr (); while (*end_of_current_line != '\n') end_of_current_line++; } // If buffer is not pointing to a continuation line, or there is // no more input, then can commit the scanned configuration // line. if (line.length () != 0 && ((last_line_was_read && buffer.length () == 0) || (buffer.rd_ptr ()[0] != ' ' && buffer.rd_ptr ()[0] != '\t'))) { ACE_TCHAR *name = 0; ACE_TCHAR *value = 0; name = line.rd_ptr (); for (p = name; *p != '\0'; p++) { if (*p == '=') { line.rd_ptr (p+1); while (p != name && (p[-1] == ' ' || p[-1] == '\t')) p--; *p = '\0'; } } if (*name) { value = line.rd_ptr (); while (*value == ' ' || *value == '\t') value++; p = line.wr_ptr (); while (p != value && (p[-1] == ' ' || p[-1] == '\t')) p--; *p = '\0'; sym_name = this->strings_->duplicate (name); sym_value = this->strings_->duplicate (value); this->symbols_->rebind (sym_name, sym_value); } line.reset (); } // If we are done, we are done! if (last_line_was_read && buffer.length () == 0) break; // If the buffer is pointing at a comment line, ignore it. if (buffer.rd_ptr ()[0] == '#' || buffer.rd_ptr ()[0] == '\n' || (buffer.rd_ptr ()[0] == '\r' && buffer.rd_ptr ()[1] == '\n')) { buffer.rd_ptr (end_of_current_line + 1); buffer.crunch (); continue; } // Whatever is left is either the start of a name-value-pair or a // continuation of one. line.copy (buffer.rd_ptr (), end_of_current_line - buffer.rd_ptr ()); p = line.wr_ptr (); while (p != line.rd_ptr () && (p[-1] == ' ' || p[-1] == '\t')) p--; line.wr_ptr (p); line.wr_ptr ()[0] = '\0'; buffer.rd_ptr (end_of_current_line + 1); buffer.crunch (); } fio.close (); }
int JAWS_Parse_Headers::parse_headers (JAWS_Header_Info *info, ACE_Message_Block &mb) { for (;;) { if (mb.rd_ptr () == mb.wr_ptr ()) break; char *p = mb.rd_ptr (); if (info->end_of_line () && (*p != ' ' && *p != '\t')) { int r = this->parse_header_name (info, mb); if (r == 1) return info->end_of_headers (); continue; } else { int r = this->parse_header_value (info, mb); if (r == 1) { if (info->end_of_headers ()) return 1; break; } continue; } } // If we arrive here, it means either there is nothing more to read, // or parse_header_value ran into difficulties (like maybe the // header value was too long). if (mb.rd_ptr () != mb.base ()) { mb.crunch (); return 0; } else if (mb.length () < mb.size ()) { return 0; } else if (mb.length () == mb.size ()) { // This is one of those cases that should rarely ever happen. // If we get here, the header type name is over 8K long. We // flag this as a bad thing. // In HTTP/1.1, I have to remember that a bad request means the // connection needs to be closed and the client has to // reinitiate the connection. info->status (JAWS_Header_Info::STATUS_CODE_TOO_LONG); return 1; } else if (mb.length () > mb.size ()) { ACE_DEBUG ((LM_DEBUG, "JAWS_Parse_Headers: buffer overrun!!\n")); info->status (JAWS_Header_Info::STATUS_CODE_TOO_LONG); return 1; } ACE_DEBUG ((LM_DEBUG, "JAWS_Parse_Headers -- shouldn't be here!\n")); return 1; }
virtual int svc () { const size_t FileReadSize = 8 * 1024; ACE_Message_Block mblk (FileReadSize); for (;; mblk.crunch ()) { // Read as much as will fit in the message block. ssize_t bytes_read = logfile_.recv (mblk.wr_ptr (), mblk.space ()); if (bytes_read <= 0) break; mblk.wr_ptr (static_cast<size_t> (bytes_read)); // We have a bunch of data from the log file. The data is // arranged like so: // hostname\0 // CDR-encoded log record // So, first we scan for the end of the host name, then // initialize another ACE_Message_Block aligned for CDR // demarshaling and copy the remainder of the block into it. We // can't use duplicate() because we need to be sure the data // pointer is aligned properly for CDR demarshaling. If at any // point, there's not enough data left in the message block to // extract what's needed, crunch the block to move all remaining // data to the beginning and read more from the file. for (;;) { size_t name_len = ACE_OS::strnlen (mblk.rd_ptr (), mblk.length ()); if (name_len == mblk.length ()) break; char *name_p = mblk.rd_ptr (); ACE_Message_Block *rec, *head, *temp; ACE_NEW_RETURN (head, ACE_Message_Block (name_len, MB_CLIENT), 0); head->copy (name_p, name_len); mblk.rd_ptr (name_len + 1); // Skip nul also size_t need = mblk.length () + ACE_CDR::MAX_ALIGNMENT; ACE_NEW_RETURN (rec, ACE_Message_Block (need), 0); ACE_CDR::mb_align (rec); rec->copy (mblk.rd_ptr (), mblk.length ()); // Now rec contains the remaining data we've read so far from // the file. Create an ACE_InputCDR to start demarshaling the // log record, header first to find the length, then the data. // Since the ACE_InputCDR constructor increases the reference count // on rec, we release it upon return to prevent leaks. // The cdr 'read' methods return 0 on failure, 1 on success. ACE_InputCDR cdr (rec); rec->release (); ACE_CDR::Boolean byte_order; if (!cdr.read_boolean (byte_order)) { head->release (); rec->release (); break; } cdr.reset_byte_order (byte_order); // Now read the length of the record. From there, we'll know // if rec contains the complete record or not. ACE_CDR::ULong length; if (!cdr.read_ulong (length)) { head->release (); mblk.rd_ptr (name_p); break; } if (length > cdr.length ()) { head->release (); mblk.rd_ptr (name_p); break; } // The complete record is in rec... grab all the fields into // separate, chained message blocks. ACE_NEW_RETURN (temp, ACE_Message_Block (length, MB_TEXT), 0); ACE_NEW_RETURN (temp, ACE_Message_Block (2 * sizeof (ACE_CDR::Long), MB_TIME, temp), 0); ACE_NEW_RETURN (temp, ACE_Message_Block (sizeof (ACE_CDR::Long), MB_PID, temp), 0); ACE_NEW_RETURN (temp, ACE_Message_Block (sizeof (ACE_CDR::Long), MB_TYPE, temp), 0); head->cont (temp); // Extract the type ACE_CDR::Long *lp; lp = reinterpret_cast<ACE_CDR::Long*> (temp->wr_ptr ()); cdr >> *lp; temp->wr_ptr (sizeof (ACE_CDR::Long)); temp = temp->cont (); // Extract the pid lp = reinterpret_cast<ACE_CDR::Long*> (temp->wr_ptr ()); cdr >> *lp; temp->wr_ptr (sizeof (ACE_CDR::Long)); temp = temp->cont (); // Extract the timestamp (2 Longs) lp = reinterpret_cast<ACE_CDR::Long*> (temp->wr_ptr ()); cdr >> *lp; ++lp; cdr >> *lp; temp->wr_ptr (2 * sizeof (ACE_CDR::Long)); temp = temp->cont (); // Demarshal the length of the message text, then demarshal // the text into the block. ACE_CDR::ULong text_len; cdr >> text_len; cdr.read_char_array (temp->wr_ptr (), text_len); temp->wr_ptr (text_len); // Forward the whole lot to the next module. if (put_next (head) == -1) break; // Move the file-content block's read pointer up past whatever // was just processed. Although the mblk's rd_ptr has not been // moved, cdr's has. Therefore, use its length() to determine // how much is left. mblk.rd_ptr (mblk.length () - cdr.length ()); } } // Now that the file is done, send a block down the stream to tell // the other modules to stop. ACE_Message_Block *stop; ACE_NEW_RETURN (stop, ACE_Message_Block (0, ACE_Message_Block::MB_STOP), 0); put_next (stop); return 0; }