Esempio n. 1
0
int
ACE::clr_flags (ACE_HANDLE handle, int flags)
{
  ACE_TRACE ("ACE::clr_flags");

#if defined (ACE_LACKS_FCNTL)
  switch (flags)
    {
    case ACE_NONBLOCK:
      // nonblocking argument (1)
      // blocking:            (0)
      {
        int nonblock = 0;
        return ACE_OS::ioctl (handle, FIONBIO, &nonblock);
      }
    default:
      ACE_NOTSUP_RETURN (-1);
    }
#else
  int val = ACE_OS::fcntl (handle, F_GETFL, 0);

  if (val == -1)
    return -1;

  // Turn flags off.
  ACE_CLR_BITS (val, flags);

  if (ACE_OS::fcntl (handle, F_SETFL, val) == -1)
    return -1;
  else
    return 0;
#endif /* ACE_LACKS_FCNTL */
}
Esempio n. 2
0
int
ACE_SPIPE_Connector::connect (ACE_SPIPE_Stream &new_io,
			      const ACE_SPIPE_Addr &remote_sap,
			      ACE_Time_Value *timeout,
			      const ACE_Addr & /* local_sap */,
			      int /* reuse_addr */,
			      int flags,
			      int perms)
{
  ACE_TRACE ("ACE_SPIPE_Connector::connect");

  // Make darn sure that the O_CREAT flag is not set!
#if ! defined (ACE_PSOS_DIAB_MIPS)
  ACE_CLR_BITS (flags, O_CREAT);
# endif /* !ACE_PSOS_DIAB_MIPS */
  ACE_HANDLE handle = ACE_Handle_Ops::handle_timed_open (timeout,
                                                         remote_sap.get_path_name (),
                                                         flags, perms);
  new_io.set_handle (handle);
  new_io.remote_addr_ = remote_sap; // class copy.

#if defined (ACE_WIN32) && !defined (ACE_HAS_PHARLAP)
  DWORD pipe_mode = PIPE_READMODE_MESSAGE | PIPE_WAIT;

  // Set named pipe mode and buffering characteristics.
  if (handle != ACE_INVALID_HANDLE)
    return ::SetNamedPipeHandleState (handle,
				      &pipe_mode,
				      NULL,
				      NULL);
#endif
  return handle == ACE_INVALID_HANDLE ? -1 : 0;
}
Esempio n. 3
0
/*the recipt is in below format
^^pqr||step2$$
 */
int
ACE_TMAIN(int argc, ACE_TCHAR* argv[]){
 u_long priority_mask =
   ACE_LOG_MSG->priority_mask (ACE_Log_Msg::PROCESS);
 ACE_CLR_BITS (priority_mask,
	       LM_DEBUG|LM_TRACE);
 ACE_LOG_MSG->priority_mask (priority_mask,
			     ACE_Log_Msg::PROCESS);

  ACE_CString* pqr = new ACE_CString(argv[1]);
  ACE_CString* step2 = new ACE_CString(argv[2]);
  /*  ACE_DEBUG((LM_INFO,
	     "%s||%s\n", pqr->c_str(), step2->c_str()));
  */
  bn* _pqr = from_hex(pqr);
  bn* _step2 = from_hex(step2);
  bn* e = new bn(1);
  e->addat(0, 0x10001);
  bn* r = npmod(_step2, e, _pqr);
  ACE_CString* output = encode(r);
  ACE_DEBUG((LM_INFO,
	     "%s\n", output->c_str()));
  delete r;
  delete output;
  delete e;
  delete _pqr;
  delete _step2;
  delete pqr;
  delete step2;
  return 0;
}
Esempio n. 4
0
int
ACE_Data_Block::size (size_t length)
{
  ACE_TRACE ("ACE_Data_Block::size");

  if (length <= this->max_size_)
    this->cur_size_ = length;
  else
    {
      // We need to resize!
      char *buf = 0;
      ACE_ALLOCATOR_RETURN (buf,
                            (char *) this->allocator_strategy_->malloc (length),
                            -1);

      ACE_OS::memcpy (buf,
                      this->base_,
                      this->cur_size_);
      if (ACE_BIT_DISABLED (this->flags_,
                            ACE_Message_Block::DONT_DELETE))
        this->allocator_strategy_->free ((void *) this->base_);
      else
        // We now assume ownership.
        ACE_CLR_BITS (this->flags_,
                      ACE_Message_Block::DONT_DELETE);
      this->max_size_ = length;
      this->cur_size_ = length;
      this->base_ = buf;
    }
  return 0;
}
Esempio n. 5
0
bool
Options::operator != (enum Option_Type opt)
{
  // @@ Why is this inequality comparison operator clearing bits?
  ACE_CLR_BITS (option_word_, opt);

  return true;
}
Esempio n. 6
0
int
Sender::terminate_io (ACE_Reactor_Mask mask)
{
  if (ACE_BIT_DISABLED (flg_mask_, mask))
    return 0;

  if (ACE_Reactor::instance ()->cancel_wakeup (this, mask) == -1)
    return -1;

  ACE_CLR_BITS (flg_mask_, mask);
  return 0;
}
Esempio n. 7
0
template <ACE_SYNCH_DECL> int
ACE_Module<ACE_SYNCH_USE>::close_i (int which,
                                    int flags)
{
    ACE_TRACE ("ACE_Module<ACE_SYNCH_USE>::close_i");

    if (this->q_pair_[which] == 0)
        return 0;

    // Copy task pointer to prevent problems when ACE_Task::close
    // changes the task pointer
    ACE_Task<ACE_SYNCH_USE> *task = this->q_pair_[which];

    // Change so that close doesn't get called again from the task base.

    // Now close the task.
    int result = 0;

    if (task->module_closed () == -1)
        result = -1;

    task->flush ();
    task->next (0);

    // Should we also delete it ?
    if (flags != M_DELETE_NONE
            && ACE_BIT_ENABLED (flags_, which + 1))
    {
        // Only delete the Tasks if there aren't any more threads
        // running in them.
        task->wait ();

        // If this assert happens it is likely because the task was
        // activated with the THR_DETACHED flag, which means that we
        // can't join() with the thread.  Not using THR_DETACHED should
        // solve this problem.
        ACE_ASSERT (task->thr_count () == 0);

        delete task;
    }

    // Set the tasks pointer to 0 so that we don't try to close()
    // this object again if the destructor gets called.
    this->q_pair_[which] = 0;

    // Finally remove the delete bit.
    ACE_CLR_BITS (flags_, which + 1);

    return result;
}
Esempio n. 8
0
template <ACE_SYNCH_DECL> int
ACE_Stream_Head<ACE_SYNCH_USE>::canonical_flush (ACE_Message_Block *mb)
{
  ACE_TRACE ("ACE_Stream_Head<ACE_SYNCH_USE>::canonical_flush");
  char *cp = mb->rd_ptr ();

  if (ACE_BIT_ENABLED (*cp, ACE_Task_Flags::ACE_FLUSHR))
    {
      this->flush (ACE_Task_Flags::ACE_FLUSHALL);
      ACE_CLR_BITS (*cp, ACE_Task_Flags::ACE_FLUSHR);
    }

  if (ACE_BIT_ENABLED (*cp, ACE_Task_Flags::ACE_FLUSHW))
    return this->reply (mb);
  else
    mb->release ();
  return 0;
}
Esempio n. 9
0
template <ACE_SYNCH_DECL> void
ACE_Module<ACE_SYNCH_USE>::writer (ACE_Task<ACE_SYNCH_USE> *q,
                                   int flags /* = M_DELETE_WRITER */)
{
    ACE_TRACE ("ACE_Module<ACE_SYNCH_USE>::writer");

    // Close and maybe delete old writer
    this->close_i (1, flags);

    this->q_pair_[1] = q;

    if (q != 0)
    {
        ACE_CLR_BITS (q->flags_, ACE_Task_Flags::ACE_READER);
        // Set the q's module pointer to point to us.
        q->mod_ = this;
    }

    // Don't allow the caller to change the reader status.
    ACE_SET_BITS (flags_, (flags & M_DELETE_WRITER));
}
Esempio n. 10
0
template <ACE_SYNCH_DECL, class TIME_POLICY> int
ACE_Stream_Tail<ACE_SYNCH_USE, TIME_POLICY>::canonical_flush (ACE_Message_Block *mb)
{
  ACE_TRACE ("ACE_Stream_Tail<ACE_SYNCH_USE, TIME_POLICY>::canonical_flush");
  char *cp = mb->rd_ptr ();

  if (ACE_BIT_ENABLED (*cp, ACE_Task_Flags::ACE_FLUSHW))
    {
      this->flush (ACE_Task_Flags::ACE_FLUSHALL);
      ACE_CLR_BITS (*cp, ACE_Task_Flags::ACE_FLUSHW);
    }

  if (ACE_BIT_ENABLED (*cp, ACE_Task_Flags::ACE_FLUSHR))
    {
      this->sibling ()->flush (ACE_Task_Flags::ACE_FLUSHALL);
      return this->reply (mb);
    }
  else
    mb->release ();

  return 0;
}
Esempio n. 11
0
int
ACE_SPIPE_Connector::connect (ACE_SPIPE_Stream &new_io,
                              const ACE_SPIPE_Addr &remote_sap,
                              ACE_Time_Value *timeout,
                              const ACE_Addr & /* local_sap */,
                              int /* reuse_addr */,
                              int flags,
                              int perms,
                              LPSECURITY_ATTRIBUTES sa,
                              int pipe_mode)
{
  ACE_TRACE ("ACE_SPIPE_Connector::connect");
  // Make darn sure that the O_CREAT flag is not set!
  ACE_CLR_BITS (flags, O_CREAT);

  ACE_HANDLE handle;

  ACE_UNUSED_ARG (pipe_mode);
#if defined (ACE_WIN32) && \
   !defined (ACE_HAS_PHARLAP) && !defined (ACE_HAS_WINCE)
  // We need to allow for more than one attempt to connect,
  // calculate the absolute time at which we give up.
  ACE_Time_Value absolute_time;
  if (timeout != 0)
    absolute_time = ACE_OS::gettimeofday () + *timeout;

  // Loop until success or failure.
  for (;;)
    {
      handle = ACE_OS::open (remote_sap.get_path_name(), flags, perms, sa);
      if (handle != ACE_INVALID_HANDLE)
        // Success!
        break;

      // Check if we have a busy pipe condition.
      if (::GetLastError() != ERROR_PIPE_BUSY)
        // Nope, this is a failure condition.
        break;

      // This will hold the time out value used in the ::WaitNamedPipe
      // call.
      DWORD time_out_value;

      // Check if we are to block until we connect.
      if (timeout == 0)
        // Wait for as long as it takes.
        time_out_value = NMPWAIT_WAIT_FOREVER;
      else
        {
          // Calculate the amount of time left to wait.
          ACE_Time_Value relative_time (absolute_time - ACE_OS::gettimeofday ());
          // Check if we have run out of time.
          if (relative_time <= ACE_Time_Value::zero)
            {
              // Mimick the errno value returned by
              // ACE::handle_timed_open.
              if (*timeout == ACE_Time_Value::zero)
                errno = EWOULDBLOCK;
              else
                errno = ETIMEDOUT;
              // Exit the connect loop with the failure.
              break;
            }
          // Get the amount of time remaining for ::WaitNamedPipe.
          time_out_value = relative_time.msec ();

        }

      // Wait for the named pipe to become available.
      ACE_TEXT_WaitNamedPipe (remote_sap.get_path_name (),
                              time_out_value);

      // Regardless of the return value, we'll do one more attempt to
      // connect to see if it is now available and to return
      // consistent error values.
    }

  // Set named pipe mode if we have a valid handle.
  if (handle != ACE_INVALID_HANDLE)
    {
      // Check if we are changing the pipe mode from the default.
      if (pipe_mode != (PIPE_READMODE_BYTE | PIPE_WAIT))
        {
          DWORD dword_pipe_mode = pipe_mode;
          if (!::SetNamedPipeHandleState (handle,
                                          &dword_pipe_mode,
                                          0,
                                          0))
            {
              // We were not able to put the pipe into the requested
              // mode.
              ACE_OS::close (handle);
              handle = ACE_INVALID_HANDLE;
            }
        }
    }
#else /* ACE_WIN32 && !ACE_HAS_PHARLAP */
  handle = ACE::handle_timed_open (timeout,
                                              remote_sap.get_path_name (),
                                              flags, perms, sa);
#endif /* !ACE_WIN32 || ACE_HAS_PHARLAP || ACE_HAS_WINCE */

  new_io.set_handle (handle);
  new_io.remote_addr_ = remote_sap; // class copy.

  return handle == ACE_INVALID_HANDLE ? -1 : 0;
}
Esempio n. 12
0
int
ACE_TMAIN(int argc, ACE_TCHAR* argv[]){

   u_long priority_mask =
         ACE_LOG_MSG->priority_mask (ACE_Log_Msg::PROCESS);
   ACE_CLR_BITS (priority_mask,
		 LM_DEBUG|LM_TRACE);
   ACE_LOG_MSG->priority_mask (priority_mask,
			       ACE_Log_Msg::PROCESS);


   ACE_CString* e = new ACE_CString("1000100000000000");
   
   bn* _pq = new bn(0x10);/*
*/
   _pq->addat(0, 0x3021802f);
   _pq->addat(1, 0x4c5faba9);
   _pq->addat(2, 0x18f820dc);
   _pq->addat(3, 0xc8a28aab);
   _pq->addat(4, 0x02de8542);
   _pq->addat(5, 0x8e301566);
   _pq->addat(6, 0xce281be5);
   _pq->addat(7, 0x346b2199);
   _pq->addat(8, 0xd8335836);
   _pq->addat(9, 0x59cebc36);
   _pq->addat(10, 0x4b768f8d);
   _pq->addat(11, 0xda316c22);
   _pq->addat(12, 0xd6c0f9f4);
   _pq->addat(13, 0xc46b3a0e);
   _pq->addat(14, 0x045015c0);
   _pq->addat(15, 0xbf78c2f6);
   
   //   _pq->subat(0,0x1);
   bn* _e = from_hex(e);
   bn* _d = new bn(0x10);
   _d->addat(0, 0xf4e5789b);
   _d->addat(1, 0x27c688d4);
   _d->addat(2, 0x40cb88fd);
   _d->addat(3, 0xe8c4c59d);
   _d->addat(4, 0x6b611a0e);
   _d->addat(5, 0x4493cfe9);
   _d->addat(6, 0x6a4d2e51);
   _d->addat(7, 0x58e231d1);
   _d->addat(8, 0xafefffe3);
   _d->addat(9, 0xae1d348b);
   _d->addat(10, 0x8d147a03);
   _d->addat(11, 0xddd6a6c5);
   _d->addat(12, 0x95749cf1);
   _d->addat(13, 0x5790ba88);
   _d->addat(14, 0x327997a7);
   _d->addat(15, 0x8f07aed1);
   
   bn* _jg = new bn(0xa);
   _jg->addat(0, 0xa3e6f7bb);
   _jg->addat(1, 0xb4594256);
   _jg->addat(2, 0x059555cf);
   _jg->addat(3, 0x503806c8);
   _jg->addat(4, 0x1d775b9f);
   _jg->addat(5, 0x0667d89e);
   _jg->addat(6, 0x52ff1ca5);
   _jg->addat(7, 0x37cd8aa6);
   _jg->addat(8, 0xf92ec894);
   _jg->addat(9, 0x674e57d3);
   _jg->addat(10, 0x1e8516);
   
   bn* tmp = new bn(1);
   tmp->addat(0,0x12345678);
   bn* _ed = mul(_e, _d);
   bn* _fv = mul(_ed, _jg);
   
   //   bn* v = (tmp, _fv, _pq);
   

   ACE_CString* str = v->to_hex();
   ACE_DEBUG((LM_INFO,
	      "%s\n", str->c_str()));
   delete str;
   delete v;
   delete _ed;
   delete _pq;
   delete _e;
   delete _d;
   delete tmp;
   //   delete pq;
   delete e;
   //   delete d;
   delete _jg;
   delete _fv;
}
Esempio n. 13
0
void
ACE_Logging_Strategy::priorities (ACE_TCHAR *priority_string,
                                  ACE_Log_Msg::MASK_TYPE mask)
{
  u_long priority_mask = 0;

  // Choose priority mask to change.

  if (mask == ACE_Log_Msg::PROCESS)
    priority_mask = process_priority_mask_;
  else
    priority_mask = thread_priority_mask_;

  // Parse string and alternate priority mask.

  for (ACE_TCHAR *priority = ACE_OS::strtok (priority_string,
                                             ACE_LIB_TEXT ("|"));
       priority != 0;
       priority = ACE_OS::strtok (0, ACE_LIB_TEXT ("|")))
    {
      if (ACE_OS::strcmp (priority, ACE_LIB_TEXT ("TRACE")) == 0)
        ACE_SET_BITS (priority_mask, LM_TRACE);
      else if (ACE_OS::strcmp (priority, ACE_LIB_TEXT ("~TRACE")) == 0)
        ACE_CLR_BITS (priority_mask, LM_TRACE);
      else if (ACE_OS::strcmp (priority, ACE_LIB_TEXT ("DEBUG")) == 0)
        ACE_SET_BITS (priority_mask, LM_DEBUG);
      else if (ACE_OS::strcmp (priority, ACE_LIB_TEXT ("~DEBUG")) == 0)
        ACE_CLR_BITS (priority_mask, LM_DEBUG);
      else if (ACE_OS::strcmp (priority, ACE_LIB_TEXT ("INFO")) == 0)
        ACE_SET_BITS (priority_mask, LM_INFO);
      else if (ACE_OS::strcmp (priority, ACE_LIB_TEXT ("~INFO")) == 0)
        ACE_CLR_BITS (priority_mask, LM_INFO);
      else if (ACE_OS::strcmp (priority, ACE_LIB_TEXT ("NOTICE")) == 0)
        ACE_SET_BITS (priority_mask, LM_NOTICE);
      else if (ACE_OS::strcmp (priority, ACE_LIB_TEXT ("~NOTICE")) == 0)
        ACE_CLR_BITS (priority_mask, LM_NOTICE);
      else if (ACE_OS::strcmp (priority, ACE_LIB_TEXT ("WARNING")) == 0)
        ACE_SET_BITS (priority_mask, LM_WARNING);
      else if (ACE_OS::strcmp (priority, ACE_LIB_TEXT ("~WARNING")) == 0)
        ACE_CLR_BITS (priority_mask, LM_WARNING);
      else if (ACE_OS::strcmp (priority, ACE_LIB_TEXT ("ERROR")) == 0)
        ACE_SET_BITS (priority_mask, LM_ERROR);
      else if (ACE_OS::strcmp (priority, ACE_LIB_TEXT ("~ERROR")) == 0)
        ACE_CLR_BITS (priority_mask, LM_ERROR);
      else if (ACE_OS::strcmp (priority, ACE_LIB_TEXT ("CRITICAL")) == 0)
        ACE_SET_BITS (priority_mask, LM_CRITICAL);
      else if (ACE_OS::strcmp (priority, ACE_LIB_TEXT ("~CRITICAL")) == 0)
        ACE_CLR_BITS (priority_mask, LM_CRITICAL);
      else if (ACE_OS::strcmp (priority, ACE_LIB_TEXT ("ALERT")) == 0)
        ACE_SET_BITS (priority_mask, LM_ALERT);
      else if (ACE_OS::strcmp (priority, ACE_LIB_TEXT ("~ALERT")) == 0)
        ACE_CLR_BITS (priority_mask, LM_ALERT);
      else if (ACE_OS::strcmp (priority, ACE_LIB_TEXT ("EMERGENCY")) == 0)
        ACE_SET_BITS (priority_mask, LM_EMERGENCY);
      else if (ACE_OS::strcmp (priority, ACE_LIB_TEXT ("~EMERGENCY")) == 0)
        ACE_CLR_BITS (priority_mask, LM_EMERGENCY);
    }

  // Affect right priority mask.

  if (mask == ACE_Log_Msg::PROCESS)
    process_priority_mask_ = priority_mask;
  else
    thread_priority_mask_ = priority_mask;
}
Esempio n. 14
0
int
Options::parse_args (int argc, char *argv[])
{
  if (ACE_LOG_MSG->open (argv[0]) == -1)
    return -1;

  //FUZZ: disable check_for_lack_ACE_OS
  ACE_Get_Opt getopt (argc, argv, "abBcCdDe:Ef:F:gGhH:i:IJj:k:K:lL:mMnN:oOprs:S:tTvVZ:");
  //FUZZ: enable check_for_lack_ACE_OS

  int option_char;

  argc_ = argc;
  argv_ = argv;

  while ((option_char = getopt ()) != -1)
    {
      switch (option_char)
        {
          // Generated coded uses the ANSI prototype format.
        case 'a':
          {
            ACE_SET_BITS (option_word_, ANSI);
            break;
          }
          // Generate code for Linear Search.
        case 'b':
          {
            ACE_SET_BITS (option_word_, LINEARSEARCH);
            break;
          }
          // Generate code for Binary Search.
        case 'B':
          {
            ACE_SET_BITS (option_word_, BINARYSEARCH);
            break;
          }
          // Generate strncmp rather than strcmp.
        case 'c':
          {
            ACE_SET_BITS (option_word_, COMP);
            break;
          }
        // Make the generated tables readonly (const).
        case 'C':
          {
            ACE_SET_BITS (option_word_, CONSTANT);
            break;
          }
        // Enable debugging option.
        case 'd':
          {
            ACE_SET_BITS (option_word_, DEBUGGING);
            ACE_ERROR ((LM_ERROR,
                        "Starting program %n, version %s, with debugging on.\n",
                        version_string));
            break;
          }
        // Enable duplicate option.
        case 'D':
          {
            ACE_SET_BITS (option_word_, DUP);
            break;
          }
        // Allows user to provide keyword/attribute separator
        case 'e':
          {
            delimiters_ = getopt.opt_arg ();
            break;
          }
        case 'E':
          {
            ACE_SET_BITS (option_word_, ENUM);
            break;
          }
        // Generate the hash table ``fast.''
        case 'f':
          {
            ACE_SET_BITS (option_word_, FAST);
            iterations_ = ACE_OS::atoi (getopt.opt_arg ());
            if (iterations_ < 0)
              {
                ACE_ERROR ((LM_ERROR, "iterations value must not be negative, assuming 0\n"));
                iterations_ = 0;
              }
            break;
          }
        // Use the ``inline'' keyword for generated sub-routines.
        case 'g':
          {
            ACE_SET_BITS (option_word_, INLINE);
            break;
          }
        // Make the keyword table a global variable.
        case 'G':
          {
            ACE_SET_BITS (option_word_, GLOBAL);
            break;
          }
        // Displays a list of helpful Options to the user.
        case 'h':
          {
            ACE_OS::fprintf (stderr,
                             "-a\tGenerate ANSI standard C output code, i.e., function prototypes.\n"
                             "-b\tGenerate code for Linear Search.\n"
                             "-B\tGenerate code for Binary Search.\n"
                             "-c\tGenerate comparison code using strncmp rather than strcmp.\n"
                             "-C\tMake the contents of generated lookup tables constant, i.e., readonly.\n"
                             "-d\tEnables the debugging option (produces verbose output to the standard\n"
                             "\terror).\n"
                             "-D\tHandle keywords that hash to duplicate values.  This is useful\n"
                             "\tfor certain highly redundant keyword sets.\n"
                             "-e\tAllow user to provide a string containing delimiters used to separate\n"
                             "\tkeywords from their attributes.  Default is \",\\n\"\n"
                             "-E\tDefine constant values using an enum local to the lookup function\n"
                             "\trather than with defines\n"
                             "-f\tGenerate the gen-perf.hash function ``fast.''  This decreases GPERF's\n"
                             "\trunning time at the cost of minimizing generated table-size.\n"
                             "\tThe numeric argument represents the number of times to iterate when\n"
                             "\tresolving a collision.  `0' means ``iterate by the number of keywords.''\n"
                             "-F\tProvided expression will be used to assign default values in keyword\n"
                             "\ttable, i.e., the fill value.  Default is \"\".\n"
                             "-g\tMake generated routines use ``inline'' to remove function overhead.\n"
                             "-G\tGenerate the static table of keywords as a static global variable,\n"
                             "\trather than hiding it inside of the lookup function (which is the\n"
                             "\tdefault behavior).\n"
                             "-h\tPrints this message.\n"
                             "-H\tAllow user to specify name of generated hash function. Default\n"
                             "\tis `hash'.\n"
                             "-i\tProvide an initial value for the associate values array.  Default is 0.\n"
                             "-I\tGenerate comparison code using case insensitive string comparison, e.g.,\n"
                             "\tstrncasecmp or strcasecmp.\n"
                             "\tSetting this value larger helps inflate the size of the final table.\n"
                             "-j\tAffects the ``jump value,'' i.e., how far to advance the associated\n"
                             "\tcharacter value upon collisions.  Must be an odd number, default is %d.\n"
                             "-J\tSkips '#include \"ace/OS_NS_string.h\"' part in the output.\n"
                             "-k\tAllows selection of the key positions used in the hash function.\n"
                             "\tThe allowable choices range between 1-%d, inclusive.  The positions\n"
                             "\tare separated by commas, ranges may be used, and key positions may\n"
                             "\toccur in any order.  Also, the meta-character '*' causes the generated\n"
                             "\thash function to consider ALL key positions, and $ indicates the\n"
                             "\t``final character'' of a key, e.g., $,1,2,4,6-10.\n"
                             "-K\tAllow use to select name of the keyword component in the keyword\n"
                             "\tstructure.\n"
                             "-l\tCompare key lengths before trying a string comparison.  This helps\n"
                             "\tcut down on the number of string comparisons made during the lookup.\n"
                             "-L\tGenerates code in the language specified by the option's argument.\n"
                             "\tLanguages handled are currently C++ and C.  The default is C.\n"
                             "-m\tAvoids the warning about identical hash values. This is valid\n"
                             "\tonly if the -D option is enabled.\n"
                             "-M\tSkips class definition in the output. This is valid only in C++ mode.\n"
                             "-n\tDo not include the length of the keyword when computing the hash\n"
                             "\tfunction.\n"
                             "-N\tAllow user to specify name of generated lookup function.  Default\n"
                             "\tname is `in_word_set.'\n"
                             "-o\tReorders input keys by frequency of occurrence of the key sets.\n"
                             "\tThis should decrease the search time dramatically.\n"
                             "-O\tOptimize the generated lookup function by assuming that all input\n"
                             "\tkeywords are members of the keyset from the keyfile.\n"
                             "-p\tChanges the return value of the generated function ``in_word_set''\n"
                             "\tfrom its default boolean value (i.e., 0 or 1), to type ``pointer\n"
                             "\tto wordlist array''  This is most useful when the -t option, allowing\n"
                             "\tuser-defined structs, is used.\n"
                             "-r\tUtilizes randomness to initialize the associated values table.\n"
                             "-s\tAffects the size of the generated hash table.  The numeric argument\n"
                             "\tfor this option indicates ``how many times larger or smaller'' the\n"
                             "\tassociated value range should be, in relationship to the number of\n"
                             "\tkeys, e.g. a value of 3 means ``allow the maximum associated value\n"
                             "\tto be about 3 times larger than the number of input keys.''\n"
                             "\tConversely, a value of -3 means ``make the maximum associated\n"
                             "\tvalue about 3 times smaller than the number of input keys. A\n"
                             "\tlarger table should decrease the time required for an unsuccessful\n"
                             "\tsearch, at the expense of extra table space.  Default value is 1.\n"
                             "-S\tCauses the generated C code to use a switch statement scheme, rather\n"
                             "\tthan an array lookup table.  This can lead to a reduction in both\n"
                             "\ttime and space requirements for some keyfiles.  The argument to\n"
                             "\tthis option determines how many switch statements are generated.\n"
                             "\tA value of 1 generates 1 switch containing all the elements, a value\n"
                             "\tof 2 generates 2 tables with 1/2 the elements in each table, etc.\n"
                             "\tThis is useful since many C compilers cannot correctly generate code\n"
                             "\tfor large switch statements.\n"
                             "-t\tAllows the user to include a structured type declaration for \n"
                             "\tgenerated code. Any text before %%%% is consider part of the type\n"
                             "\tdeclaration.  Key words and additional fields may follow this, one\n"
                             "\tgroup of fields per line.\n"
                             "-T\tPrevents the transfer of the type declaration to the output file.\n"
                             "\tUse this option if the type is already defined elsewhere.\n"
                             "-v\tPrints out the current version number and exits with a value of 0\n"
                             "-V\tExits silently with a value of 0.\n"
                             "-Z\tAllow user to specify name of generated C++ class.  Default\n"
                             "\tname is `Perfect_Hash.'\n",
                             DEFAULT_JUMP_VALUE,
                             MAX_KEY_POS - 1);
            Options::usage ();
            return -1;
          }
        // Sets the name for the hash function.
        case 'H':
          {
            hash_name_ = getopt.opt_arg ();
            break;
          }
        // Sets the initial value for the associated values array.
        case 'i':
          {
            initial_asso_value_ = ACE_OS::atoi (getopt.opt_arg ());
            if (initial_asso_value_ < 0)
              ACE_ERROR ((LM_ERROR,
                          "Initial value %d should be non-zero, ignoring and continuing.\n",
                          initial_asso_value_));
            if (option[RANDOM])
              ACE_ERROR ((LM_ERROR,
                          "warning, -r option superceeds -i, ignoring -i option and continuing\n"));
            break;
          }
         case 'I':
           {
             ACE_SET_BITS (option_word_, STRCASECMP);
             break;
           }
         // Sets the jump value, must be odd for later algorithms.
        case 'j':
          {
            jump_ = ACE_OS::atoi (getopt.opt_arg ());
            if (jump_ < 0)
              ACE_ERROR_RETURN ((LM_ERROR,
                                 "Jump value %d must be a positive number.\n%r",
                                 jump_,
                                 &Options::usage),
                                 -1);
            else if (jump_ && ACE_EVEN (jump_))
              ACE_ERROR ((LM_ERROR,
                          "Jump value %d should be odd, adding 1 and continuing...\n",
                          jump_++));
            break;
          }
        // Skip including the header file ace/OS_NS_string.h.
        case 'J':
          {
            ACE_SET_BITS (option_word_, SKIPSTRINGH);
            break;
          }
        // Sets key positions used for hash function.
        case 'k':
          {
            const int BAD_VALUE = -1;
            int value;
            Iterator expand (getopt.opt_arg (),
                             1,
                             MAX_KEY_POS - 1,
                             WORD_END,
                             BAD_VALUE,
                             EOS);

            // Use all the characters for hashing!!!!
            if (*getopt.opt_arg () == '*')
              option_word_ = (option_word_ & ~DEFAULTCHARS) | ALLCHARS;
            else
              {
                char *l_key_pos;

                for (l_key_pos = key_positions_;
                     (value = expand ()) != EOS;
                     l_key_pos++)
                  if (value == BAD_VALUE)
                    ACE_ERROR_RETURN ((LM_ERROR,
                                       "Illegal key value or range, use 1,2,3-%d,'$' or '*'.\n%r",
                                       MAX_KEY_POS - 1,
                                       usage),
                                      -1);
                  else
                    *l_key_pos = static_cast<char> (value);

                *l_key_pos = EOS;

                total_keysig_size_ = (l_key_pos - key_positions_);
                if (total_keysig_size_ == 0)
                  ACE_ERROR_RETURN ((LM_ERROR,
                                     "No keys selected.\n%r",
                                     &Options::usage),
                                    -1);
                else if (key_sort (key_positions_, total_keysig_size_) == 0)
                  ACE_ERROR_RETURN ((LM_ERROR,
                                     "Duplicate keys selected\n%r",
                                     &Options::usage),
                                    -1);
                if (total_keysig_size_ != 2
                    || (key_positions_[0] != 1
                        || key_positions_[1] != WORD_END))
                  ACE_CLR_BITS (option_word_, DEFAULTCHARS);
              }
            break;
          }
        // Make this the keyname for the keyword component field.
        case 'K':
          {
            key_name_ = getopt.opt_arg ();
            break;
          }
        // Create length table to avoid extra string compares.
        case 'l':
          {
            ACE_SET_BITS (option_word_, LENTABLE);
            break;
          }
        // Deal with different generated languages.
        case 'L':
          {
            option_word_ &= ~C;
            if (!ACE_OS::strcmp (getopt.opt_arg (), "C++"))
              ACE_SET_BITS (option_word_, (CPLUSPLUS | ANSI));
            else if (!ACE_OS::strcmp (getopt.opt_arg (), "C"))
              ACE_SET_BITS (option_word_, C);
            else
              {
                ACE_ERROR ((LM_ERROR,
                            "unsupported language option %s, defaulting to C\n",
                            getopt.opt_arg ()));
                ACE_SET_BITS (option_word_, C);
              }
            break;
          }
        // Don't print the warnings.
        case 'm':
          {
            ACE_SET_BITS (option_word_, MUTE);
            break;
          }
        // Skip the class definition while in C++ mode.
        case 'M':
          {
            ACE_SET_BITS (option_word_, SKIPCLASS);
            break;
          }
        // Don't include the length when computing hash function.
        case 'n':
          {
            ACE_SET_BITS (option_word_, NOLENGTH);
            break;
          }
        // Make generated lookup function name be.opt_arg ()
        case 'N':
          {
            function_name_ = getopt.opt_arg ();
            break;
          }
        // Make fill_default be.opt_arg ()
        case 'F':
          {
            fill_default_ = getopt.opt_arg ();
            break;
          }
        // Order input by frequency of key set occurrence.
        case 'o':
          {
            ACE_SET_BITS (option_word_, ORDER);
            break;
          }
        case 'O':
          {
            ACE_SET_BITS (option_word_, OPTIMIZE);
            break;
          }
        // Generated lookup function now a pointer instead of int.
        case 'p':
          {
            ACE_SET_BITS (option_word_, POINTER);
            break;
          }
        // Utilize randomness to initialize the associated values
        // table.
        case 'r':
          {
            ACE_SET_BITS (option_word_, RANDOM);
            if (initial_asso_value_ != 0)
              ACE_ERROR ((LM_ERROR,
                          "warning, -r option superceeds -i, disabling -i option and continuing\n"));
            break;
          }
        // Range of associated values, determines size of final table.
        case 's':
          {
            size_ = ACE_OS::atoi (getopt.opt_arg ());
            if (abs (size_) > 50)
              ACE_ERROR ((LM_ERROR,
                          "%d is excessive, did you really mean this?! (type %n -h for help)\n",
                          size_));
            break;
          }
        // Generate switch statement output, rather than lookup table.
        case 'S':
          {
            ACE_SET_BITS (option_word_, SWITCH);
            total_switches_ = ACE_OS::atoi (getopt.opt_arg ());
            if (total_switches_ <= 0)
              ACE_ERROR_RETURN ((LM_ERROR,
                                 "number of switches %s must be a positive number\n%r",
                                 getopt.opt_arg (),
                                 &Options::usage),
                                -1);
            break;
          }
        // Enable the TYPE mode, allowing arbitrary user structures.
        case 't':
          {
            ACE_SET_BITS (option_word_, TYPE);
            break;
          }
        // Don't print structure definition.
        case 'T':
          {
            ACE_SET_BITS (option_word_, NOTYPE);
            break;
          }
        // Print out the version and quit.
        case 'v':
          ACE_ERROR ((LM_ERROR,
                      "%n: version %s\n%r\n",
                      version_string,
                      &Options::usage));
          ACE_OS::exit (0);
          /* NOTREACHED */
          break;
        // Exit with value of 0 (this is useful to check if gperf exists)
        case 'V':
          ACE_OS::exit (0);
          /* NOTREACHED */
          break;
        // Set the class name.
        case 'Z':
          {
            class_name_ = getopt.opt_arg ();
            break;
          }
        default:
          ACE_ERROR_RETURN ((LM_ERROR,
                             "%r",
                             &Options::usage),
                            -1);
        }

    }

  if (argv[getopt.opt_ind ()] &&
    ACE_OS::freopen (argv[getopt.opt_ind ()],
                     "r",
                     stdin) == 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "Cannot open keyword file %p\n%r",
                       argv[getopt.opt_ind ()],
                       &Options::usage),
                      -1);
  if (getopt.opt_ind () + 1 < argc)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "Extra trailing arguments to %n.\n%r",
                       usage),
                      -1);
  return 0;
}
Esempio n. 15
0
int
MCT_Config::open (int argc, ACE_TCHAR *argv[])
{
  int retval = 0;
  int help = 0;

  //FUZZ: disable check_for_lack_ACE_OS
  ACE_Get_Opt getopt (argc, argv, ACE_TEXT (":?"), 1, 1);
  //FUZZ: enable check_for_lack_ACE_OS

  if (getopt.long_option (ACE_TEXT ("GroupStart"),
                          'g',
                          ACE_Get_Opt::ARG_REQUIRED) != 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT (" Unable to add GroupStart option.\n")),
                      1);

  if (getopt.long_option (ACE_TEXT ("Groups"),
                          'n',
                          ACE_Get_Opt::ARG_REQUIRED) != 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT (" Unable to add Groups option.\n")), 1);

  if (getopt.long_option (ACE_TEXT ("Debug"),
                          'd',
                          ACE_Get_Opt::NO_ARG) != 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT (" Unable to add Debug option.\n")), 1);

  if (getopt.long_option (ACE_TEXT ("Role"),
                          'r',
                          ACE_Get_Opt::ARG_REQUIRED) != 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT (" Unable to add Role option.\n")), 1);

  if (getopt.long_option (ACE_TEXT ("SDM_options"),
                          'm',
                          ACE_Get_Opt::ARG_REQUIRED) != 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT (" Unable to add Multicast_Options option.\n")),
                      1);

  if (getopt.long_option (ACE_TEXT ("Iterations"),
                          'i',
                          ACE_Get_Opt::ARG_REQUIRED) != 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT (" Unable to add iterations option.\n")),
                      1);

  if (getopt.long_option (ACE_TEXT ("TTL"),
                          't',
                          ACE_Get_Opt::ARG_REQUIRED) != 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT (" Unable to add TTL option.\n")),
                      1);

  if (getopt.long_option (ACE_TEXT ("Wait"),
                          'w',
                          ACE_Get_Opt::ARG_REQUIRED) != 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT (" Unable to add wait option.\n")),
                      1);

  if (getopt.long_option (ACE_TEXT ("help"),
                          'h',
                          ACE_Get_Opt::NO_ARG) != 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT (" Unable to add help option.\n")),
                      1);

  //FUZZ: disable check_for_lack_ACE_OS
  // Now, let's parse it...
  int c = 0;
  while ((c = getopt ()) != EOF)
    {
      //FUZZ: enable check_for_lack_ACE_OS
      switch (c)
        {
        case 0:
          // Long Option. This should never happen.
          retval = -1;
           break;
        case 'g':
          {
            // @todo validate all these, i.e., must be within range
            // 224.255.0.0 to 238.255.255.255, but we only allow the
            // administrative "site local" range, 239.255.0.0 to
            // 239.255.255.255.
            ACE_TCHAR *group = getopt.opt_arg ();
            if (this->group_start_.set (group) != 0)
              {
                ACE_ERROR ((LM_ERROR, ACE_TEXT ("Bad group address:%s\n"),
                            group));
              }
          }
          break;
        case 'i':
          this->iterations_ = ACE_OS::atoi (getopt.opt_arg ());
          break;
        case 'n':
          {
            int n = ACE_OS::atoi (getopt.opt_arg ());
            // I'm assuming 0 means unlimited, so just use whatever the
            // user provides.  Seems to work okay on Solaris 5.8.
            if (IP_MAX_MEMBERSHIPS == 0)
              this->groups_ = n;
            else
              this->groups_ = ACE_MIN (ACE_MAX (n, MCT_MIN_GROUPS),
                                       IP_MAX_MEMBERSHIPS);
            break;
          }
        case 'd':
          this->debug_ = 1;
          break;
        case 'r':
          {
            ACE_TCHAR *c = getopt.opt_arg ();
            if (ACE_OS::strcasecmp (c, ACE_TEXT ("CONSUMER")) == 0)
              this->role_ = CONSUMER;
            else if (ACE_OS::strcasecmp (c, ACE_TEXT ("PRODUCER")) == 0)
              this->role_ = PRODUCER;
            else
              {
                help = 1;
                retval = -1;
              }
          }
          break;
        case 'm':
          {
            //@todo add back OPT_BINDADDR_NO...
            ACE_TCHAR *c = getopt.opt_arg ();
            if (ACE_OS::strcasecmp (c, ACE_TEXT ("OPT_BINDADDR_YES")) == 0)
              ACE_SET_BITS (this->sdm_opts_,
                            ACE_SOCK_Dgram_Mcast::OPT_BINDADDR_YES);
            else if (ACE_OS::strcasecmp (c, ACE_TEXT ("OPT_BINDADDR_NO")) == 0)
              ACE_CLR_BITS (this->sdm_opts_,
                            ACE_SOCK_Dgram_Mcast::OPT_BINDADDR_YES);
            else if (ACE_OS::strcasecmp (c, ACE_TEXT ("DEFOPT_BINDADDR")) == 0)
              {
                ACE_CLR_BITS (this->sdm_opts_,
                              ACE_SOCK_Dgram_Mcast::OPT_BINDADDR_YES);
                ACE_SET_BITS (this->sdm_opts_,
                              ACE_SOCK_Dgram_Mcast::DEFOPT_BINDADDR);
              }
            else if (ACE_OS::strcasecmp (c, ACE_TEXT ("OPT_NULLIFACE_ALL")) == 0)
              ACE_SET_BITS (this->sdm_opts_,
                            ACE_SOCK_Dgram_Mcast::OPT_NULLIFACE_ALL);
            else if (ACE_OS::strcasecmp (c, ACE_TEXT ("OPT_NULLIFACE_ONE")) == 0)
              ACE_CLR_BITS (this->sdm_opts_,
                            ACE_SOCK_Dgram_Mcast::OPT_NULLIFACE_ALL);
            else if (ACE_OS::strcasecmp (c, ACE_TEXT ("DEFOPT_NULLIFACE")) == 0)
              {
                ACE_CLR_BITS (this->sdm_opts_,
                              ACE_SOCK_Dgram_Mcast::OPT_NULLIFACE_ALL);
                ACE_SET_BITS (this->sdm_opts_,
                              ACE_SOCK_Dgram_Mcast::DEFOPT_NULLIFACE);
              }
            else if (ACE_OS::strcasecmp (c, ACE_TEXT ("DEFOPTS")) == 0)
              this->sdm_opts_ = ACE_SOCK_Dgram_Mcast::DEFOPTS;
            else
              {
                help = 1;
                retval = -1;
              }
          }
          break;
        case 't':
          this->ttl_ = ACE_OS::atoi (getopt.opt_arg ());
          break;
        case 'w':
          this->wait_ = ACE_OS::atoi (getopt.opt_arg ());
          break;
        case ':':
          // This means an option requiring an argument didn't have one.
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT (" Option '%c' requires an argument but ")
                      ACE_TEXT ("none was supplied\n"),
                      getopt.opt_opt ()));
          help = 1;
          retval = -1;
          break;
        case '?':
        case 'h':
        default:
          if (ACE_OS::strcmp (argv[getopt.opt_ind () - 1], ACE_TEXT ("-?")) != 0
              && getopt.opt_opt () != 'h')
            // Don't allow unknown options.
            ACE_ERROR ((LM_ERROR,
                        ACE_TEXT (" Found an unknown option (%c) ")
                        ACE_TEXT ("we couldn't handle.\n"),
                        getopt.opt_opt ()));
                        // getopt.last_option ())); //readd with "%s" when
                        // last_option() is available.
          help = 1;
          retval = -1;
          break;
        }
    }

  if (retval == -1)
    {
      if (help)
        // print usage here
        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("usage: %s [options]\n")
                    ACE_TEXT ("Options:\n")
                    ACE_TEXT ("  -g {STRING}  --GroupStart={STRING}  ")
                    ACE_TEXT ("starting multicast group address\n")
                    ACE_TEXT ("                                      ")
                    ACE_TEXT ("(default=239.255.0.1:16000)\n")
                    ACE_TEXT ("  -n {#}       --Groups={#}           ")
                    ACE_TEXT ("number of groups (default=5)\n")
                    ACE_TEXT ("  -d           --Debug                ")
                    ACE_TEXT ("debug flag (default=off)\n")
                    ACE_TEXT ("  -r {STRING}  --Role={STRING}        ")
                    ACE_TEXT ("role {PRODUCER|CONSUMER|BOTH}\n")
                    ACE_TEXT ("                                      ")
                    ACE_TEXT ("(default=BOTH)\n")
                    ACE_TEXT ("  -m {STRING}  --SDM_options={STRING} ")
                    ACE_TEXT ("ACE_SOCK_Dgram_Mcast ctor options\n")
                    ACE_TEXT ("                                      ")
                    ACE_TEXT ("(default=DEFOPTS)\n")
                    ACE_TEXT ("  -i {#}       --Iterations={#}       ")
                    ACE_TEXT ("number of iterations (default=100)\n")
                    ACE_TEXT ("  -t {#}       --TTL={#}              ")
                    ACE_TEXT ("time to live (default=1)\n")
                    ACE_TEXT ("  -w {#}       --Wait={#}             ")
                    ACE_TEXT ("number of seconds to wait on CONSUMER\n")
                    ACE_TEXT ("                                      ")
                    ACE_TEXT ("(default=2)\n")
                    ACE_TEXT ("  -h/?         --help                 ")
                    ACE_TEXT ("show this message\n"),
                    argv[0]));

      return -1;
    }

  return 0;
}
Esempio n. 16
0
int
ACE_TMAIN(int argc, ACE_TCHAR* argv[]){
  u_long priority_mask =
  ACE_LOG_MSG->priority_mask (ACE_Log_Msg::PROCESS);
  ACE_CLR_BITS (priority_mask,
		LM_DEBUG|LM_TRACE);
  ACE_LOG_MSG->priority_mask (priority_mask,
			      ACE_Log_Msg::PROCESS);


  ACE::set_handle_limit();
  ACE_Thread_Manager* mgr = ACE_Thread_Manager::instance();
  ACE_SOCK_Acceptor _987acceptor;
  ACE_INET_Addr _987addr(0x987);//2439
  
  if(_987acceptor.open(_987addr, 1) == -1){
    ACE_ERROR_RETURN((LM_ERROR,
		      "%p\n",
		      "open"),
		     1);
  }else if(_987acceptor.get_local_addr(_987addr) == -1){
    ACE_ERROR_RETURN ((LM_ERROR,
		       "%p\n",
		       "get_local_addr"),
		      1);
  }

  ACE_DEBUG((LM_INFO,
	     "(%P|%t) starting 987 server at port %d\n",
	     _987addr.get_port_number()));
  ACE_SOCK_Stream _str;

  ACE_Handle_Set _set;
  _set.set_bit(_987acceptor.get_handle());

  do{
    ACE_Time_Value timeout(ACE_DEFAULT_TIMEOUT);
    ACE_Handle_Set tmp = _set;
    int result = ACE_OS::select(ACE_Utils::truncate_cast<int> ((intptr_t) _987acceptor.get_handle()) +1,
				(fd_set *) tmp,
				0,
				0,
				NULL);
    if(result == -1)
      ACE_ERROR((LM_ERROR,
		 "(%P|%t) %p\n",
		 "select"));
    else if(result==0)
      ACE_DEBUG((LM_INFO,
		 "(%P|%t) select timed out\n"));
    else{
      if(tmp.is_set(_987acceptor.get_handle())){
	if(_987acceptor.accept(_str) == -1){
	  ACE_ERROR((LM_ERROR,
		     "%p\n",
		     "987 accept"));
	  continue;
	}else{
	  ACE_DEBUG((LM_INFO,
		     "(%P|%t: %l) spawning 987 server\n"));
	  if(mgr->spawn(process,
			reinterpret_cast<void*> (_str.get_handle()),
			THR_DETACHED) == -1){
	    ACE_ERROR((LM_ERROR,
		       "(%P|%t) %p\n",
		       "spawn"));
	  }
	}
      }
    }
  }while(true);

  return 0;
}
Esempio n. 17
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  int counter = 1;

  if (argc > 1) // Just give a dummy command-line argument to trigger this path.
    {
      if (ACE_LOG_MSG->open (argv[0],
                             ACE_Log_Msg::OSTREAM) == -1)
        ACE_ERROR ((LM_ERROR,
                    "cannot open logger!!!\n"));

      cause_error ();
      // Check to see what happened.
      if (ACE_LOG_MSG->op_status () == -1
          && ACE_LOG_MSG->errnum () == EWOULDBLOCK)
        ACE_DEBUG ((LM_DEBUG,
                    "op_status and errnum work!\n"));
      else
        ACE_ERROR ((LM_ERROR,
                    "op_status and errnum failed!\n"));
    }
  else   // The default behavior is to log to STDERR...
    {
      if (ACE_LOG_MSG->open (argv[0]) == -1)
        ACE_ERROR ((LM_ERROR,
                    "cannot open logger!!!\n"));

      cause_error ();

      // Check to see what happened.
      if (ACE_LOG_MSG->op_status () == -1
          && ACE_LOG_MSG->errnum () == EWOULDBLOCK)
        ACE_DEBUG ((LM_DEBUG,
                    "op_status and errnum work!\n"));
      else
        ACE_ERROR ((LM_ERROR,
                    "op_status and errnum failed!\n"));

      // Exercise many different combinations of STDERR and OSTREAM.

      double f = 3.1416 * counter++;
      int i = 10000;

      ACE_DEBUG ((LM_INFO,
                  "%10f, %*s%s = %d\n",
                  f,
                  8,
                  "",
                  "hello",
                  i));

#if !defined (ACE_LACKS_IOSTREAM_TOTALLY)

      ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM);
      ACE_LOG_MSG->msg_ostream (&cout);

      f = 3.1416 * counter;
      i = 10000 * counter++;

      // This message will print twice - once for OSTREAM and once for
      // STDERR.

      ACE_DEBUG ((LM_INFO,
                  "%10f, %*s%s = %d\n",
                  f,
                  8,
                  "",
                  "world",
                  i));

      ACE_LOG_MSG->clr_flags (ACE_Log_Msg::STDERR);

      f = 3.1416 * counter;
      i = 10000 * counter++;

      ACE_DEBUG ((LM_INFO,
                  "%10f, %*s%s = %d\n",
                  f,
                  8,
                  "",
                  "world",
                  i));

      ACE_LOG_MSG->msg_ostream (0);

      ACE_LOG_MSG->set_flags (ACE_Log_Msg::STDERR);

      f = 3.1416 * counter;
      i = 10000 * counter++;

      ACE_DEBUG ((LM_INFO,
                  "%10f, %*s%s = %d\n",
                  f,
                  8,
                  "",
                  "world",
                  i));

      ACE_LOG_MSG->clr_flags (ACE_Log_Msg::OSTREAM);
      ACE_LOG_MSG->msg_ostream (&cerr);

      f = 3.1416 * counter;
      i = 10000 * counter++;

      ACE_DEBUG ((LM_INFO,
                  "%10f, %*s%s = %d\n",
                  f,
                  8,
                  "",
                  "world",
                  i));

#endif /* !defined (ACE_LACKS_IOSTREAM_TOTALLY) */

      static int array[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048};

      // Print out the binary bytes of the array in hex form.
      ACE_LOG_MSG->log_hexdump (LM_DEBUG,
                                (char *) array,
                                sizeof array);

      // Disable the LM_DEBUG and LM_INFO messages at the process level.
      u_long priority_mask =
        ACE_LOG_MSG->priority_mask (ACE_Log_Msg::PROCESS);
      ACE_CLR_BITS (priority_mask,
                    LM_DEBUG | LM_INFO);
      ACE_LOG_MSG->priority_mask (priority_mask,
                                  ACE_Log_Msg::PROCESS);

      ACE_DEBUG ((LM_INFO,
                  "This LM_INFO message should not print!\n"));
      ACE_DEBUG ((LM_DEBUG,
                  "This LM_DEBUG message should not print!\n"));

      ACE_SET_BITS (priority_mask,
                    LM_INFO);
      ACE_LOG_MSG->priority_mask (priority_mask,
                                  ACE_Log_Msg::PROCESS);

      ACE_DEBUG ((LM_INFO,
                  "This LM_INFO message should print!\n"));
      ACE_DEBUG ((LM_DEBUG,
                  "This LM_DEBUG message should not print!\n"));

      ACE_CLR_BITS (priority_mask, LM_INFO);
      ACE_LOG_MSG->priority_mask (priority_mask,
                                  ACE_Log_Msg::PROCESS);

      ACE_DEBUG ((LM_INFO,
                  "This LM_INFO message should not print!\n"));
      ACE_DEBUG ((LM_DEBUG,
                  "This LM_DEBUG message should not print!\n"));

      char badname[] = "badname";

      char *l_argv[2];
      l_argv[0] = badname;
      l_argv[1] = 0;

      if (ACE_OS::execv (badname,
                         l_argv) == -1)
        {
          ACE_ERROR ((LM_ERROR,
                      "%n: (%x), %p%r\n",
                      10000,
                      badname,
                      cleanup));
          ACE_OS::_exit ();
        }
    }
  return 0;
}
Esempio n. 18
0
int
ACE_TMAIN(int argc, ACE_TCHAR* argv[]){
  u_long priority_mask =
    ACE_LOG_MSG->priority_mask (ACE_Log_Msg::PROCESS);

  ACE_CLR_BITS (priority_mask,
		LM_DEBUG|LM_TRACE);
  ACE_LOG_MSG->priority_mask (priority_mask,
			      ACE_Log_Msg::PROCESS);
  bn* pq = new bn(0x20);
  pq->addat(0, 0xeb8987339891e925);
  pq->addat(1, 0x0f053cd4371a7ceb);
  pq->addat(2, 0xf5dfaf22b1028231);
  pq->addat(3, 0x8e4ca43151c07e73);
  pq->addat(4, 0xc8e199c73a9b94ef);
  pq->addat(5, 0xb9028fee20d6ffba);
  pq->addat(6, 0xf253be6e1a689b05);
  pq->addat(7, 0x529d3e9ba016f15f);
  pq->addat(8, 0xd3b0f2ddfb2e52e8);
  pq->addat(9, 0x35a15f3ddebb6f2c);
  pq->addat(10, 0xe332c0bd18ee189a);
  pq->addat(11, 0xa884e035012b84d7);
  pq->addat(12, 0x288a009cfd58ac3e);
  pq->addat(13, 0xb60c0a39e34c9677);
  pq->addat(14, 0x07c82ab0f8e73236);
  pq->addat(15, 0x03f1c3664b965493);
  pq->addat(16, 0xfa3e247aff0f7f44);
  pq->addat(17, 0x68b1c0741dc06920);
  pq->addat(18, 0x0eea079974544a29);
  pq->addat(19, 0xd0e2b26ea75b019f);
  pq->addat(20, 0x037c24400193aa86);
  pq->addat(21, 0x24387de58a887d55);
  pq->addat(22, 0x9c9f78d60c314c84);
  pq->addat(23, 0x93b8e510d3c1a15b);
  pq->addat(24, 0xcc363a8d45682e10);
  pq->addat(25, 0x2ede6575a0f90bd6);
  pq->addat(26, 0x81e986a9bb403591);
  pq->addat(27, 0x530704f375f3f5a2);
  pq->addat(28, 0xe6c8694c51971e6f);
  pq->addat(29, 0xfa4fa3ccee1ba6a8);
  pq->addat(30, 0xb576464706e43aa9);
  pq->addat(31, 0xb24566314b2ee5b2);

  bn* d = new bn(0x20);
  d->addat(0, 0xa87d97cd4c5ccc89);
  d->addat(1, 0xc960703f7aff8cf6);
  d->addat(2, 0x1aa6c26f7a466188);
  d->addat(3, 0x1821039c4e78edd0);
  d->addat(4, 0xe946efbb9455c393);
  d->addat(5, 0x012b9bf4920d72c6);
  d->addat(6, 0x8147f6db3b86bedb);
  d->addat(7, 0x31ae2b9c9e7bf83e);
  d->addat(8, 0x2f50842080ce7f0c);
  d->addat(9, 0x4183fa699c52d222);
  d->addat(10, 0xab13d671bdfa4399);
  d->addat(11, 0x6476a75626902b90);
  d->addat(12, 0xbe8dc3bf9bbaca29);
  d->addat(13, 0x2f141a9eb2bcff82);
  d->addat(14, 0x0c82fa9414d367bc);
  d->addat(15, 0x31a74d56b005b3e4);
  d->addat(16, 0x7d0378a23f69462e);
  d->addat(17, 0x0f8f36d212ada850);
  d->addat(18, 0xdd6a28403a20256b);
  d->addat(19, 0xff39a9c6d2aa0393);
  d->addat(20, 0xcfc17163873c9d63);
  d->addat(21, 0xbb2b37c666a75b93);
  d->addat(22, 0xea9e8fc58061e09d);
  d->addat(23, 0x09498933cfbf304a);
  d->addat(24, 0x9de8880ef05d7700);
  d->addat(25, 0x46d8c7ec1564378b);
  d->addat(26, 0x10b0dbbf0ab4fafb);
  d->addat(27, 0xaae685c033d6c229);
  d->addat(28, 0xf984e6d83c33ab53);
  d->addat(29, 0x1435e7d2f2438d3b);
  d->addat(30, 0x08a30cae3ca9d37f);
  d->addat(31, 0xa21ee6ee1b5ce3d3);

  bn* e = new bn(1);
  e->addat(0, 0x10001);
  bn* jg = new bn(0x11);
  jg->addat(0, 0xa869393342acec39);
  jg->addat(1, 0xc2b321891985991d);
  jg->addat(2, 0x359df6ddd3b25387);
  jg->addat(3, 0x3b8c348f0752dbd9);
  jg->addat(4, 0x949ce5fc6f1d6358);
  jg->addat(5, 0x1190c6ae9c6d2d48);
  jg->addat(6, 0x4f46e06f47593ae2);
  jg->addat(7, 0xd9e7f79edfeb323a);
  jg->addat(8, 0x5f9f1c37437983eb);
  jg->addat(9, 0xd1fe797af8fd3e74);
  jg->addat(10, 0x796c8c320b4102a0);
  jg->addat(11, 0xa88f4abf82704f2d);
  jg->addat(12, 0x6b3be9e6c6a58823);
  jg->addat(13, 0x475bc8654836a3d4);
  jg->addat(14, 0x37b60fd13fcc0ba1);
  jg->addat(15, 0xcac8224683f549ea);
  jg->addat(16, 0xf294);

  bn* tmp = new bn(1);
  tmp->addat(0, 0x123456789abcdef0);
  bn* v1 = npmod(tmp,e, pq);
  bn* v2 = npmod(v1, d, pq);
  bn* v3 = npmod(v2, jg, pq);
  v3->print();

  delete v3;
  delete v2;
  delete v1;
  delete tmp;
  
  delete e;
  delete d;
  delete pq;
  delete jg;
  return 0;
}
Esempio n. 19
0
void My_ACE_Logging_Strategy::set_priority_mask(ACE_TCHAR* priority, u_long& priority_mask)
{
    if (ACE_OS::strcmp(priority, ACE_TEXT("SHUTDOWN")) == 0)
    {
        ACE_SET_BITS(priority_mask, LM_SHUTDOWN);
    }
    else if (ACE_OS::strcmp(priority, ACE_TEXT("~SHUTDOWN")) == 0)
    {
        ACE_CLR_BITS(priority_mask, LM_SHUTDOWN);
    }
    else if (ACE_OS::strcmp(priority, ACE_TEXT("TRACE")) == 0)
    {
        ACE_SET_BITS(priority_mask, LM_TRACE);
    }
    else if (ACE_OS::strcmp(priority, ACE_TEXT("~TRACE")) == 0)
    {
        ACE_CLR_BITS(priority_mask, LM_TRACE);
    }
    else if (ACE_OS::strcmp(priority, ACE_TEXT("DEBUG")) == 0)
    {
        ACE_SET_BITS(priority_mask, LM_DEBUG);
    }
    else if (ACE_OS::strcmp(priority, ACE_TEXT("~DEBUG")) == 0)
    {
        ACE_CLR_BITS(priority_mask, LM_DEBUG);
    }
    else if (ACE_OS::strcmp(priority, ACE_TEXT("INFO")) == 0)
    {
        ACE_SET_BITS(priority_mask, LM_INFO);
    }
    else if (ACE_OS::strcmp(priority, ACE_TEXT("~INFO")) == 0)
    {
        ACE_CLR_BITS(priority_mask, LM_INFO);
    }
    else if (ACE_OS::strcmp(priority, ACE_TEXT("NOTICE")) == 0)
    {
        ACE_SET_BITS(priority_mask, LM_NOTICE);
    }
    else if (ACE_OS::strcmp(priority, ACE_TEXT("~NOTICE")) == 0)
    {
        ACE_CLR_BITS(priority_mask, LM_NOTICE);
    }
    else if (ACE_OS::strcmp(priority, ACE_TEXT("WARNING")) == 0)
    {
        ACE_SET_BITS(priority_mask, LM_WARNING);
    }
    else if (ACE_OS::strcmp(priority, ACE_TEXT("~WARNING")) == 0)
    {
        ACE_CLR_BITS(priority_mask, LM_WARNING);
    }
    else if (ACE_OS::strcmp(priority, ACE_TEXT("STARTUP")) == 0)
    {
        ACE_SET_BITS(priority_mask, LM_STARTUP);
    }
    else if (ACE_OS::strcmp(priority, ACE_TEXT("~STARTUP")) == 0)
    {
        ACE_CLR_BITS(priority_mask, LM_STARTUP);
    }
    else if (ACE_OS::strcmp(priority, ACE_TEXT("ERROR")) == 0)
    {
        ACE_SET_BITS(priority_mask, LM_ERROR);
    }
    else if (ACE_OS::strcmp(priority, ACE_TEXT("~ERROR")) == 0)
    {
        ACE_CLR_BITS(priority_mask, LM_ERROR);
    }
    else if (ACE_OS::strcmp(priority, ACE_TEXT("CRITICAL")) == 0)
    {
        ACE_SET_BITS(priority_mask, LM_CRITICAL);
    }
    else if (ACE_OS::strcmp(priority, ACE_TEXT("~CRITICAL")) == 0)
    {
        ACE_CLR_BITS(priority_mask, LM_CRITICAL);
    }
    else if (ACE_OS::strcmp(priority, ACE_TEXT("ALERT")) == 0)
    {
        ACE_SET_BITS(priority_mask, LM_ALERT);
    }
    else if (ACE_OS::strcmp(priority, ACE_TEXT("~ALERT")) == 0)
    {
        ACE_CLR_BITS(priority_mask, LM_ALERT);
    }
    else if (ACE_OS::strcmp(priority, ACE_TEXT("EMERGENCY")) == 0)
    {
        ACE_SET_BITS(priority_mask, LM_EMERGENCY);
    }
    else if (ACE_OS::strcmp(priority, ACE_TEXT("~EMERGENCY")) == 0)
    {
        ACE_CLR_BITS(priority_mask, LM_EMERGENCY);
    }
}
static void
test_log_msg_features (const ACE_TCHAR *program)
{
  // Note that the default behavior is to log to STDERR...

  int counter = 1 ;

  if (ACE_LOG_MSG->open (program) == -1)
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("cannot open logger!!!\n")));

  cause_error ();

  // Check to see what happened.
  if (ACE_LOG_MSG->op_status () == -1
      && ACE_LOG_MSG->errnum () == EWOULDBLOCK)
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("op_status and errnum work!\n")));
  else
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("op_status and errnum failed!\n")));

  const char *badname = "badname";

  // We use the DEBUG messages instead of error messages. This is to
  // help the scripts. If we print out error messages the scripts
  // start catching them as errors.
  if (ACE_OS::open (badname,
                    O_RDONLY) == ACE_INVALID_HANDLE)
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("%n: (%x), can't open %s%r\n"),
                10000,
                badname,
                cleanup));

  // Try a log operation that would overflow the logging buffer if not
  // properly guarded.
  ACE_TCHAR big[ACE_Log_Record::MAXLOGMSGLEN + 1];
  size_t i = 0;
  const ACE_TCHAR alphabet[] = ACE_TEXT ("abcdefghijklmnopqrstuvwxyz");
  size_t j = ACE_OS::strlen (alphabet);
  while (i < ACE_Log_Record::MAXLOGMSGLEN)
    big[i++] = alphabet[i % j];
  ACE_DEBUG ((LM_INFO, ACE_TEXT ("This is too big: %s\n"), big));

  // Exercise many different combinations of OSTREAM.

  ACE_DEBUG ((LM_INFO,
              ACE_TEXT ("%10f, %*s%s = %d\n"),
              3.1416 * counter++,
              8,
              ACE_TEXT (""),
              ACE_TEXT ("hello"),
              10000));

  ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM);
  ACE_LOG_MSG->msg_ostream (ace_file_stream::instance ()->output_file ());

  ACE_DEBUG ((LM_INFO,
              ACE_TEXT ("%10f, %*s%s = %d\n"),
              3.1416 * counter,
              8,
              ACE_TEXT (""),
              ACE_TEXT ("world"),
              10000 * counter++));

  ACE_LOG_MSG->clr_flags (ACE_Log_Msg::OSTREAM);

  // The next two messages shouldn't print.
  ACE_DEBUG ((LM_INFO,
              ACE_TEXT ("%10f, %*s%s = %d\n"),
              3.1416 * counter,
              8,
              ACE_TEXT (""),
              ACE_TEXT ("world"),
              10000 * counter++));

  ACE_DEBUG ((LM_INFO,
              ACE_TEXT ("%10f, %*s%s = %d\n"),
              3.1416 * counter,
              8,
              ACE_TEXT (""),
              ACE_TEXT ("world"),
              10000 * counter++));

  ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM);
  ACE_DEBUG ((LM_INFO,
              ACE_TEXT ("%10f, %*s%s = %d\n"),
              3.1416 * counter,
              8,
              ACE_TEXT (""),
              ACE_TEXT ("world"),
              10000 * counter++));

  static int array[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048};

  // Print out the binary bytes of the array in hex form.
  ACE_LOG_MSG->log_hexdump (LM_DEBUG,
                            (char *) array,
                            sizeof array);

  // Disable the LM_DEBUG and LM_INFO messages.
  u_long priority_mask =
    ACE_LOG_MSG->priority_mask (ACE_Log_Msg::PROCESS);
  ACE_CLR_BITS (priority_mask,
                LM_DEBUG | LM_INFO);
  ACE_LOG_MSG->priority_mask (priority_mask,
                              ACE_Log_Msg::PROCESS);

  ACE_DEBUG ((LM_INFO,
              ACE_TEXT ("This LM_INFO message should not print!\n")));
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("This LM_DEBUG message should not print!\n")));

  ACE_SET_BITS (priority_mask,
                LM_INFO);
  ACE_LOG_MSG->priority_mask (priority_mask,
                              ACE_Log_Msg::PROCESS);

  ACE_DEBUG ((LM_INFO,
              ACE_TEXT ("This LM_INFO message should print!\n")));
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("This LM_DEBUG message should not print!\n")));

  ACE_CLR_BITS (priority_mask, LM_INFO);
  ACE_LOG_MSG->priority_mask (priority_mask,
                              ACE_Log_Msg::PROCESS);

  ACE_DEBUG ((LM_INFO,
              ACE_TEXT ("This LM_INFO message should not print!\n")));
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("This LM_DEBUG message should not print!\n")));
}
Esempio n. 21
0
ACE_BEGIN_VERSIONED_NAMESPACE_DECL

// Parse the string containing (thread) priorities and set them
// accordingly.

void
ACE_Logging_Strategy::priorities (ACE_TCHAR *priority_string,
                                  ACE_Log_Msg::MASK_TYPE mask)
{
  u_long priority_mask = 0;

  // Choose priority mask to change.

  if (mask == ACE_Log_Msg::PROCESS)
    priority_mask = process_priority_mask_;
  else
    priority_mask = thread_priority_mask_;

  ACE_TCHAR *strtokp = 0;

  // Parse string and alternate priority mask.

  for (ACE_TCHAR *priority = ACE_OS::strtok_r (priority_string,
                                               ACE_TEXT ("|"),
                                               &strtokp);
       priority != 0;
       priority = ACE_OS::strtok_r (0,
                                    ACE_TEXT ("|"),
                                    &strtokp))
    {
      if (ACE_OS::strcmp (priority, ACE_TEXT ("SHUTDOWN")) == 0)
        ACE_SET_BITS (priority_mask, LM_SHUTDOWN);
      else if (ACE_OS::strcmp (priority, ACE_TEXT ("~SHUTDOWN")) == 0)
        ACE_CLR_BITS (priority_mask, LM_SHUTDOWN);
      else if (ACE_OS::strcmp (priority, ACE_TEXT ("TRACE")) == 0)
        ACE_SET_BITS (priority_mask, LM_TRACE);
      else if (ACE_OS::strcmp (priority, ACE_TEXT ("~TRACE")) == 0)
        ACE_CLR_BITS (priority_mask, LM_TRACE);
      else if (ACE_OS::strcmp (priority, ACE_TEXT ("DEBUG")) == 0)
        ACE_SET_BITS (priority_mask, LM_DEBUG);
      else if (ACE_OS::strcmp (priority, ACE_TEXT ("~DEBUG")) == 0)
        ACE_CLR_BITS (priority_mask, LM_DEBUG);
      else if (ACE_OS::strcmp (priority, ACE_TEXT ("INFO")) == 0)
        ACE_SET_BITS (priority_mask, LM_INFO);
      else if (ACE_OS::strcmp (priority, ACE_TEXT ("~INFO")) == 0)
        ACE_CLR_BITS (priority_mask, LM_INFO);
      else if (ACE_OS::strcmp (priority, ACE_TEXT ("NOTICE")) == 0)
        ACE_SET_BITS (priority_mask, LM_NOTICE);
      else if (ACE_OS::strcmp (priority, ACE_TEXT ("~NOTICE")) == 0)
        ACE_CLR_BITS (priority_mask, LM_NOTICE);
      else if (ACE_OS::strcmp (priority, ACE_TEXT ("WARNING")) == 0)
        ACE_SET_BITS (priority_mask, LM_WARNING);
      else if (ACE_OS::strcmp (priority, ACE_TEXT ("~WARNING")) == 0)
        ACE_CLR_BITS (priority_mask, LM_WARNING);
      else if (ACE_OS::strcmp (priority, ACE_TEXT ("STARTUP")) == 0)
        ACE_SET_BITS (priority_mask, LM_STARTUP);
      else if (ACE_OS::strcmp (priority, ACE_TEXT ("~STARTUP")) == 0)
        ACE_CLR_BITS (priority_mask, LM_STARTUP);
      else if (ACE_OS::strcmp (priority, ACE_TEXT ("ERROR")) == 0)
        ACE_SET_BITS (priority_mask, LM_ERROR);
      else if (ACE_OS::strcmp (priority, ACE_TEXT ("~ERROR")) == 0)
        ACE_CLR_BITS (priority_mask, LM_ERROR);
      else if (ACE_OS::strcmp (priority, ACE_TEXT ("CRITICAL")) == 0)
        ACE_SET_BITS (priority_mask, LM_CRITICAL);
      else if (ACE_OS::strcmp (priority, ACE_TEXT ("~CRITICAL")) == 0)
        ACE_CLR_BITS (priority_mask, LM_CRITICAL);
      else if (ACE_OS::strcmp (priority, ACE_TEXT ("ALERT")) == 0)
        ACE_SET_BITS (priority_mask, LM_ALERT);
      else if (ACE_OS::strcmp (priority, ACE_TEXT ("~ALERT")) == 0)
        ACE_CLR_BITS (priority_mask, LM_ALERT);
      else if (ACE_OS::strcmp (priority, ACE_TEXT ("EMERGENCY")) == 0)
        ACE_SET_BITS (priority_mask, LM_EMERGENCY);
      else if (ACE_OS::strcmp (priority, ACE_TEXT ("~EMERGENCY")) == 0)
        ACE_CLR_BITS (priority_mask, LM_EMERGENCY);
    }

  // Affect right priority mask.

  if (mask == ACE_Log_Msg::PROCESS)
    process_priority_mask_ = priority_mask;
  else
    thread_priority_mask_ = priority_mask;
}
Esempio n. 22
0
int
TAO::SSLIOP::Protocol_Factory::init (int argc, ACE_TCHAR* argv[])
{
  char *certificate_path = 0;
  char *private_key_path = 0;
  char *dhparams_path = 0;
  char *ca_file = 0;
  CORBA::String_var ca_dir;
  ACE_TCHAR *rand_path = 0;

  int certificate_type = -1;
  int private_key_type = -1;
  int dhparams_type = -1;

  int prevdebug = -1;

  CSIIOP::AssociationOptions csiv2_target_supports =
    CSIIOP::Integrity | CSIIOP::Confidentiality;
  CSIIOP::AssociationOptions csiv2_target_requires =
    CSIIOP::Integrity | CSIIOP::Confidentiality;

  // Force the Singleton instance to be initialized/instantiated.
  // Some SSLIOP option combinations below will result in the
  // Singleton instance never being initialized.  In that case,
  // problems may occur later on due to lack of initialization of the
  // underlying SSL library (e.g. OpenSSL), which occurs when an
  // ACE_SSL_Context is instantiated.

  // This directive processing initializes ACE_SSL_Context as well
  // as registers ACE_SSL for correct cleanup.
  ACE_Service_Config::process_directive (
    ACE_STATIC_SERVICE_DIRECTIVE ("ACE_SSL_Initializer", ""));

  // The code is cleaner this way anyway.
  ACE_SSL_Context * ssl_ctx = ACE_SSL_Context::instance ();

  size_t session_id_len =
    (sizeof session_id_context_ >= SSL_MAX_SSL_SESSION_ID_LENGTH)
      ? SSL_MAX_SSL_SESSION_ID_LENGTH
      : sizeof session_id_context_;

  // Note that this function returns 1, if the operation succeded.
  // See SSL_CTX_set_session_id_context(3)
  if( 1 != ::SSL_CTX_set_session_id_context (ssl_ctx->context(),
                                             session_id_context_,
                                             session_id_len))
  {
    if (TAO_debug_level > 0)
      ORBSVCS_ERROR ((LM_ERROR,
                  ACE_TEXT ("TAO (%P|%t) Unable to set the session id ")
                  ACE_TEXT ("context to \'%C\'\n"), session_id_context_));

    return -1;
  }

  for (int curarg = 0; curarg != argc; ++curarg)
    {
      if ((ACE_OS::strcasecmp (argv[curarg],
                               ACE_TEXT("-verbose")) == 0)
          || (ACE_OS::strcasecmp (argv[curarg],
                                  ACE_TEXT("-v")) == 0))
        {
          if (TAO_debug_level == 0)
            {
              prevdebug = TAO_debug_level;
              TAO_debug_level = 1;
            }
        }

      else if (ACE_OS::strcasecmp (argv[curarg],
                                   ACE_TEXT("-SSLNoProtection")) == 0)
        {
          // Enable the eNULL cipher.  Note that enabling the "eNULL"
          // cipher only disables encryption.  However, certificate
          // exchanges will still occur.
          if (::SSL_CTX_set_cipher_list (ssl_ctx->context (),
                                         "ALL:eNULL") == 0)
            {
              ORBSVCS_DEBUG ((LM_ERROR,
                          ACE_TEXT ("TAO (%P|%t) Unable to set eNULL ")
                          ACE_TEXT ("SSL cipher in SSLIOP ")
                          ACE_TEXT ("factory.\n")));

              return -1;
            }

          // This does not disable secure invocations on the server
          // side.  It merely enables insecure ones.  On the client
          // side, secure invocations will be disabled unless
          // overridden by a SecurityLevel2::QOPPolicy in the object
          // reference.
          this->qop_ = ::Security::SecQOPNoProtection;

          ACE_SET_BITS (csiv2_target_supports,
                        CSIIOP::NoProtection);

          ACE_CLR_BITS (csiv2_target_requires,
                        CSIIOP::Confidentiality);
        }

      else if (ACE_OS::strcasecmp (argv[curarg],
                                   ACE_TEXT("-SSLCertificate")) == 0)
        {
          curarg++;
          if (curarg < argc)
            {
              certificate_type = parse_x509_file (ACE_TEXT_ALWAYS_CHAR(argv[curarg]), &certificate_path);
            }
        }

      else if (ACE_OS::strcasecmp (argv[curarg],
                                   ACE_TEXT("-SSLPrivateKey")) == 0)
        {
          curarg++;
          if (curarg < argc)
            {
              private_key_type = parse_x509_file (ACE_TEXT_ALWAYS_CHAR(argv[curarg]), &private_key_path);
            }
        }

      else if (ACE_OS::strcasecmp (argv[curarg],
                                   ACE_TEXT("-SSLAuthenticate")) == 0)
        {
          curarg++;
          if (curarg < argc)
            {
              int mode = SSL_VERIFY_NONE;
              if (ACE_OS::strcasecmp (argv[curarg], ACE_TEXT("NONE")) == 0)
                {
                  mode = SSL_VERIFY_NONE;
                }
              else if (ACE_OS::strcasecmp (argv[curarg], ACE_TEXT("SERVER")) == 0)
                {
                  mode = SSL_VERIFY_PEER;

                  ACE_SET_BITS (csiv2_target_supports,
                                CSIIOP::EstablishTrustInTarget
                                | CSIIOP::EstablishTrustInClient);
                }
              else if (ACE_OS::strcasecmp (argv[curarg], ACE_TEXT("CLIENT")) == 0
                       || ACE_OS::strcasecmp (argv[curarg],
                                              ACE_TEXT("SERVER_AND_CLIENT")) == 0)
                {
                  mode = SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT;

                  ACE_SET_BITS (csiv2_target_supports,
                                CSIIOP::EstablishTrustInTarget
                                | CSIIOP::EstablishTrustInClient);

                  ACE_SET_BITS (csiv2_target_requires,
                                CSIIOP::EstablishTrustInClient);
                }

              ssl_ctx->default_verify_mode (mode);
            }
        }

      else if (ACE_OS::strcasecmp (argv[curarg],
                                   ACE_TEXT("-SSLAcceptTimeout")) == 0)
        {
          curarg++;
          if (curarg < argc)
            {
              float timeout = 0;

              if (sscanf (ACE_TEXT_ALWAYS_CHAR(argv[curarg]), "%f", &timeout) != 1
                  || timeout < 0)
                ORBSVCS_ERROR_RETURN ((LM_ERROR,
                                   "ERROR: Invalid -SSLAcceptTimeout "
                                   "value: %s.\n",
                                   argv[curarg]),
                                  -1);
              else
                this->timeout_.set (timeout);
            }
        }

      else if (ACE_OS::strcasecmp (argv[curarg],
                                   ACE_TEXT("-SSLDHparams")) == 0)
        {
          curarg++;
          if (curarg < argc)
            {
              dhparams_type = parse_x509_file (ACE_TEXT_ALWAYS_CHAR(argv[curarg]), &dhparams_path);
            }
        }

      else if (ACE_OS::strcasecmp (argv[curarg],
                                   ACE_TEXT("-SSLCAfile")) == 0)
        {
          curarg++;
          if (curarg < argc)
            {
              (void) parse_x509_file (ACE_TEXT_ALWAYS_CHAR(argv[curarg]), &ca_file);
            }
        }

      else if (ACE_OS::strcasecmp (argv[curarg],
                                   ACE_TEXT("-SSLCApath")) == 0)
        {
          curarg++;
          if (curarg < argc)
            {
              ca_dir = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(argv[curarg]));
            }
        }

      else if (ACE_OS::strcasecmp (argv[curarg],
                                   ACE_TEXT("-SSLrand")) == 0)
        {
          curarg++;
          if (curarg < argc)
            {
              rand_path = argv[curarg];
            }
        }

#if !defined (__Lynx__)
      else if (ACE_OS::strcasecmp (argv[curarg],
                                   ACE_TEXT("-SSLServerCipherOrder")) == 0)
        {
          ::SSL_CTX_set_options (ssl_ctx->context (),
                                 SSL_OP_CIPHER_SERVER_PREFERENCE);
        }

      else if (ACE_OS::strcasecmp (argv[curarg],
                                   ACE_TEXT("-SSLCipherList")) == 0)
        {
          curarg++;
          if (curarg < argc)
            {
              if (::SSL_CTX_set_cipher_list (ssl_ctx->context (),
                                             ACE_TEXT_ALWAYS_CHAR(argv[curarg])) == 0)
                {
                  ORBSVCS_DEBUG ((LM_ERROR,
                              ACE_TEXT ("TAO (%P|%t) Unable to set cipher ")
                              ACE_TEXT ("list in SSLIOP ")
                              ACE_TEXT ("factory.\n")));

                  return -1;
                }
            }
        }
#endif

    }

  // Load some (more) entropy from the user specified sources
  // in addition to what's pointed to by ACE_SSL_RAND_FILE_ENV
  if (rand_path != 0)
  {
    short errors = 0;
    ACE_TCHAR *file_name = 0;
    const ACE_TCHAR *path = ACE_OS::strtok_r (rand_path,
                                              TAO_PATH_SEPARATOR_STRING,
                                              &file_name);
    while ( path != 0)
    {
      if( -1 == ssl_ctx->seed_file (ACE_TEXT_ALWAYS_CHAR(path), -1))
      {
        ++errors;
        ORBSVCS_ERROR ((LM_ERROR,
                    ACE_TEXT ("TAO (%P|%t) Failed to load ")
                    ACE_TEXT ("more entropy from <%s>: %m\n"), path));
      }
      else
      {
        if (TAO_debug_level > 0)
          ORBSVCS_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("TAO (%P|%t) Loaded ")
                      ACE_TEXT ("more entropy from <%s>\n"), path));
      }

      path = ACE_OS::strtok_r (0, TAO_PATH_SEPARATOR_STRING, &file_name);
    }

    if (errors > 0)
      return -1;
  }

  // Load any trusted certificates explicitely rather than relying on
  // previously set SSL_CERT_FILE and/or SSL_CERT_PATH environment variable
  if (ca_file != 0 || ca_dir.in () != 0)
    {
      if (ssl_ctx->load_trusted_ca (ca_file, ca_dir.in ()) != 0)
        {
          ORBSVCS_ERROR ((LM_ERROR,
                      ACE_TEXT ("TAO (%P|%t) Unable to load ")
                      ACE_TEXT ("CA certs from %C%C%C\n"),
                      ((ca_file != 0) ? ca_file : "a file pointed to by "
                                                  ACE_SSL_CERT_FILE_ENV
                                                  " env var (if any)"),
                      ACE_TEXT (" and "),
                      ((ca_dir.in () != 0) ?
                          ca_dir.in () : "a directory pointed to by "
                                         ACE_SSL_CERT_DIR_ENV
                                         " env var (if any)")));

          return -1;
        }
      else
        {
          if (TAO_debug_level > 0)
            ORBSVCS_DEBUG ((LM_INFO,
                        ACE_TEXT ("TAO (%P|%t) SSLIOP loaded ")
                        ACE_TEXT ("Trusted Certificates from %C%C%C\n"),
                        ((ca_file != 0) ? ca_file : "a file pointed to by "
                                                    ACE_SSL_CERT_FILE_ENV
                                                    " env var (if any)"),
                        ACE_TEXT (" and "),
                        ((ca_dir.in () != 0) ?
                            ca_dir.in () : "a directory pointed to by "
                                           ACE_SSL_CERT_DIR_ENV
                                           " env var (if any)")));
        }
    }

  // Load in the DH params.  If there was a file explicitly specified,
  // then we do that here, otherwise we load them in from the cert file.
  // Note that we only do this on the server side, I think so we might
  // need to defer this 'til later in the acceptor or something...
  if (dhparams_path == 0)
    {
      // If the user didn't explicitly specify a DH parameters file, we
      // also might find it concatenated in the certificate file.
      // So, we set the dhparams to that if it wasn't explicitly set.
      dhparams_path = certificate_path;
      dhparams_type = certificate_type;
    }

  if (dhparams_path != 0)
    {
      if (ssl_ctx->dh_params (dhparams_path,
                              dhparams_type) != 0)
        {
          if (dhparams_path != certificate_path)
            {
              // We only want to fail catastrophically if the user specified
              // a dh parameter file and we were unable to actually find it
              // and load from it.
              ORBSVCS_ERROR ((LM_ERROR,
                          ACE_TEXT ("(%P|%t) SSLIOP_Factory: ")
                          ACE_TEXT ("unable to set ")
                          ACE_TEXT ("DH parameters <%C>\n"),
                          dhparams_path));
              return -1;
            }
          else
            {
              if (TAO_debug_level > 0)
                ORBSVCS_DEBUG ((LM_INFO,
                            ACE_TEXT ("(%P|%t) SSLIOP_Factory: ")
                            ACE_TEXT ("No DH parameters found in ")
                            ACE_TEXT ("certificate <%C>; either none ")
                            ACE_TEXT ("are needed (RSA) or problems ")
                            ACE_TEXT ("will ensue later.\n"),
                            dhparams_path));
            }
        }
      else
        {
          if (TAO_debug_level > 0)
            ORBSVCS_DEBUG ((LM_INFO,
                        ACE_TEXT ("(%P|%t) SSLIOP loaded ")
                        ACE_TEXT ("Diffie-Hellman params ")
                        ACE_TEXT ("from %C\n"),
                        dhparams_path));
        }
    }

  // The certificate must be set before the private key since the
  // ACE_SSL_Context attempts to check the private key for
  // consistency.  That check requires the certificate to be available
  // in the underlying SSL_CTX.
  if (certificate_path != 0)
    {
      if (ssl_ctx->certificate (certificate_path,
                                certificate_type) != 0)
        {
          ORBSVCS_ERROR ((LM_ERROR,
                      ACE_TEXT ("TAO (%P|%t) Unable to set ")
                      ACE_TEXT ("SSL certificate <%C> ")
                      ACE_TEXT ("in SSLIOP factory.\n"),
                      certificate_path));

          return -1;
        }
      else
        {
          if (TAO_debug_level > 0)
            ORBSVCS_DEBUG ((LM_INFO,
                        ACE_TEXT ("TAO (%P|%t) SSLIOP loaded ")
                        ACE_TEXT ("SSL certificate ")
                        ACE_TEXT ("from %C\n"),
                        certificate_path));
        }
    }

  if (private_key_path != 0)
    {
      if (ssl_ctx->private_key (private_key_path, private_key_type) != 0)
        {

          ORBSVCS_ERROR ((LM_ERROR,
                      ACE_TEXT ("TAO (%P|%t) Unable to set ")
                      ACE_TEXT ("SSL private key ")
                      ACE_TEXT ("<%C> in SSLIOP factory.\n"),
                      private_key_path));

          return -1;
        }
      else
        {
          if (TAO_debug_level > 0)
            ORBSVCS_DEBUG ((LM_INFO,
                        ACE_TEXT ("TAO (%P|%t) SSLIOP loaded ")
                        ACE_TEXT ("Private Key ")
                        ACE_TEXT ("from <%C>\n"),
                        private_key_path));
        }
    }

  if (this->register_orb_initializer (csiv2_target_supports,
                                      csiv2_target_requires) != 0)
    return -1;

  if (prevdebug != -1)
    TAO_debug_level = prevdebug;

  return 0;
}
Esempio n. 23
0
int
main (int argc, char *argv[])
{
  // Note that the default behavior is to log to STDERR...

  int counter = 1 ;

  if (argc > 1)
    {
      if (ACE_LOG_MSG->open (argv[0],
                             ACE_Log_Msg::OSTREAM) == -1)
        ACE_ERROR ((LM_ERROR,
                    "cannot open logger!!!\n"));

      cause_error ();
      // Check to see what happened.
      if (ACE_LOG_MSG->op_status () == -1
          && ACE_LOG_MSG->errnum () == EWOULDBLOCK)
        ACE_DEBUG ((LM_DEBUG,
                    "op_status and errnum work!\n"));
      else
        ACE_ERROR ((LM_ERROR,
                    "op_status and errnum failed!\n"));
    }
  else
    {
      if (ACE_LOG_MSG->open (argv[0]) == -1)
        ACE_ERROR ((LM_ERROR,
                    "cannot open logger!!!\n"));

      cause_error ();

      // Check to see what happened.
      if (ACE_LOG_MSG->op_status () == -1
          && ACE_LOG_MSG->errnum () == EWOULDBLOCK)
        ACE_DEBUG ((LM_DEBUG,
                    "op_status and errnum work!\n"));
      else
        ACE_ERROR ((LM_ERROR,
                    "op_status and errnum failed!\n"));

      // Exercise many different combinations of STDERR and OSTREAM.

      ACE_DEBUG ((LM_INFO,
                  "%10f, %*s%s = %d\n",
                  3.1416 * counter++,
                  8,
                  "",
                  "hello",
                  10000));

      ACE_LOG_MSG->set_flags (ACE_Log_Msg::OSTREAM);
      ACE_LOG_MSG->msg_ostream (&cout);

      ACE_DEBUG ((LM_INFO,
                  "%10f, %*s%s = %d\n",
                  3.1416 * counter,
                  8,
                  "",
                  "world",
                  10000 * counter++));

      ACE_LOG_MSG->clr_flags (ACE_Log_Msg::STDERR);

      ACE_DEBUG ((LM_INFO,
                  "%10f, %*s%s = %d\n",
                  3.1416 * counter,
                  8,
                  "",
                  "world",
                  10000 * counter++));

      ACE_LOG_MSG->msg_ostream (0);

      ACE_LOG_MSG->set_flags (ACE_Log_Msg::STDERR);

      ACE_DEBUG ((LM_INFO,
                  "%10f, %*s%s = %d\n",
                  3.1416 * counter,
                  8,
                  "",
                  "world",
                  10000 * counter++));

      ACE_LOG_MSG->clr_flags (ACE_Log_Msg::OSTREAM);
      ACE_LOG_MSG->msg_ostream (&cerr);

      ACE_DEBUG ((LM_INFO,
                  "%10f, %*s%s = %d\n",
                  3.1416 * counter,
                  8,
                  "",
                  "world",
                  10000 * counter++));

      static int array[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048};

      // Print out the binary bytes of the array in hex form.
      ACE_LOG_MSG->log_hexdump (LM_DEBUG,
                                (char *) array,
                                sizeof array);

      // Disable the LM_DEBUG and LM_INFO messages at the process level.
      u_long priority_mask =
        ACE_LOG_MSG->priority_mask (ACE_Log_Msg::PROCESS);
      ACE_CLR_BITS (priority_mask,
                    LM_DEBUG | LM_INFO);
      ACE_LOG_MSG->priority_mask (priority_mask,
                                  ACE_Log_Msg::PROCESS);

      ACE_DEBUG ((LM_INFO,
                  "This LM_INFO message should not print!\n"));
      ACE_DEBUG ((LM_DEBUG,
                  "This LM_DEBUG message should not print!\n"));

      ACE_SET_BITS (priority_mask,
                    LM_INFO);
      ACE_LOG_MSG->priority_mask (priority_mask,
                                  ACE_Log_Msg::PROCESS);

      ACE_DEBUG ((LM_INFO,
                  "This LM_INFO message should print!\n"));
      ACE_DEBUG ((LM_DEBUG,
                  "This LM_DEBUG message should not print!\n"));

      ACE_CLR_BITS (priority_mask, LM_INFO);
      ACE_LOG_MSG->priority_mask (priority_mask,
                                  ACE_Log_Msg::PROCESS);
      
      ACE_DEBUG ((LM_INFO,
                  "This LM_INFO message should not print!\n"));
      ACE_DEBUG ((LM_DEBUG,
                  "This LM_DEBUG message should not print!\n"));

      char badname[] = "badname";

      char *l_argv[2];
      l_argv[0] = badname;
      l_argv[1] = 0;

      if (ACE_OS::execv (badname,
                         l_argv) == -1)
        {
          ACE_ERROR ((LM_ERROR,
                      "%n: (%x), %p%r\n",
                      10000,
                      badname,
                      cleanup));
          ACE_OS::_exit ();
        }
    }
  return 0;
}
Esempio n. 24
0
static int
test_acelib_category()
{
  int failed = 0;

  Log_Count  counter;

  ACE_LOG_MSG->msg_callback (&counter);

  // Disable the LM_DEBUG and LM_INFO messages.
  u_long priority_mask =
    ACE_LOG_MSG->priority_mask (ACE_Log_Msg::PROCESS);
  ACE_CLR_BITS (priority_mask,
                LM_DEBUG | LM_INFO);
  ACE_Log_Category::ace_lib().priority_mask (priority_mask);

  ACELIB_DEBUG ((LM_INFO,
              ACE_TEXT ("This LM_INFO message should not print!\n")));
  ACELIB_DEBUG ((LM_DEBUG,
              ACE_TEXT ("This LM_DEBUG message should not print!\n")));

  if (counter.count() != 0)
  {
    ++failed;
  }

  ACE_DEBUG ((LM_INFO,
              ACE_TEXT ("This LM_INFO message should print!\n")));
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("This LM_DEBUG message should print!\n")));

  if (counter.count() != 2)
  {
    ++failed;
  }

  ACE_SET_BITS (priority_mask,
                LM_INFO);
  ACE_Log_Category::ace_lib().priority_mask (priority_mask);

  ACELIB_DEBUG ((LM_INFO,
              ACE_TEXT ("This LM_INFO message should print!\n")));

  if (counter.count() != 3)
  {
    ++failed;
  }

  ACELIB_DEBUG ((LM_DEBUG,
              ACE_TEXT ("This LM_DEBUG message should not print!\n")));

  if (counter.count() != 3)
  {
    ++failed;
  }

  ACE_CLR_BITS (priority_mask, LM_INFO);
  ACE_Log_Category::ace_lib().priority_mask (priority_mask);

  ACELIB_DEBUG ((LM_INFO,
              ACE_TEXT ("This LM_INFO message should not print!\n")));
  ACELIB_DEBUG ((LM_DEBUG,
              ACE_TEXT ("This LM_DEBUG message should not print!\n")));

  if (counter.count() != 3)
  {
    ++failed;
  }


  if (failed == 0) {
    ACE_DEBUG((LM_DEBUG, "All ace lib category log passed\n"));
  }
  else {
    ACE_ERROR((LM_ERROR, "Some ace lib category log failed\n"));
  }
  ACE_LOG_MSG->msg_callback (0);
  return failed;
}