コード例 #1
0
ファイル: Commands.cpp プロジェクト: BearWare/TeamTalk5
    bool GetProperty(const mstrings_t& properties, 
        const ACE_TString& prop, std::vector<int>& vec)
    {
        ACE_TString value;
        mstrings_t::const_iterator ite = properties.find(prop);
        if( ite != properties.end() )
        {
            value = (*ite).second;
            ACE_TString token;
            size_t offset = 0;
            size_t i = value.find(',', offset);//Tokenize(ACE_TEXT(","),offset);
            while(i != ACE_TString::npos)
            {
                token = value.substr(offset, i-offset);
                offset = i+1;
                vec.push_back(int(string2i(token)));
                i = value.find(',', offset);

            }
            if( value.length() && (value.length() - 1) >= offset )
            {
                token = value.substr(offset, value.length()-offset);
                offset = i+1;
                vec.push_back(int(string2i(token)));
            }
            return true;
        }
        return false;
    }
コード例 #2
0
ファイル: Commands.cpp プロジェクト: BearWare/TeamTalk5
 ACE_TString stripEOL(const ACE_TString& input)
 {
     size_t len = ACE_OS::strlen(EOL);
     if(input.length()<len)
         return input;
     if(input.substr(input.length()-len,len) == EOL)
         return input.substr(0,input.length()-len);
     else if(input.substr(input.length()-1,1) == ACE_TEXT("\n"))
         return input.substr(0,input.length()-1);
     return input;
 }
コード例 #3
0
ファイル: SubDriver.cpp プロジェクト: AndroidDev77/OpenDDS
int
SubDriver::parse_sub_arg(const ACE_TString& arg)
{
  DBG_ENTRY("SubDriver","parse_sub_arg");

  size_t pos;

  // Find the first ':' character, and make sure it is in a legal spot.
  if ((pos = std::find(arg.c_str(), arg.c_str() + arg.length(), ACE_TEXT(':')) - arg.c_str()) == arg.length()) {
    ACE_ERROR((LM_ERROR,
               "(%P|%t) Bad -p command-line value (%s). Missing ':' char.\n",
               arg.c_str()));
    return -1;
  }

  if (pos == 0) {
    ACE_ERROR((LM_ERROR,
               "(%P|%t) Bad -p command-line value (%s). "
               "':' char cannot be first char.\n",
               arg.c_str()));
    return -1;
  }

  if (pos == (arg.length() - 1)) {
    ACE_ERROR((LM_ERROR,
               "(%P|%t) Bad -p command-line value  (%s) - "
               "':' char cannot be last char.\n",
               arg.c_str()));
    return -1;
  }

  // Parse the sub_id from left of ':' char, and remainder to right of ':'.
  ACE_TString sub_id_str(arg.c_str(), pos);
  this->sub_addr_str_ = arg.c_str() + pos + 1;

  // RepoIds are conventionally created and managed by the DCPSInfoRepo. Those
  // generated here are for the sole purpose of verifying internal behavior.
  OpenDDS::DCPS::RepoIdBuilder builder(sub_id_);

  builder.participantId(1);
  builder.entityKey(ACE_OS::atoi(sub_id_str.c_str()));
  builder.entityKind(OpenDDS::DCPS::ENTITYKIND_USER_WRITER_WITH_KEY);

  // Use the remainder as the "stringified" ACE_INET_Addr.
  this->sub_addr_ = ACE_INET_Addr(this->sub_addr_str_.c_str());

  return 0;
}
コード例 #4
0
ファイル: SelectNSDialog.cpp プロジェクト: asdlei00/ACE
BOOL CSelectNSDialog::OnInitDialog()
{
  CDialog::OnInitDialog();

  // TODO: Add extra initialization here
  HKEY hKey = ACE_Configuration_Win32Registry::resolve_key(HKEY_LOCAL_MACHINE, ACE_TEXT("Software\\TAO\\NamingViewer\\Servers"));
  m_pConfig = new ACE_Configuration_Win32Registry(hKey);
  ACE_Configuration_Section_Key Section = m_pConfig->root_section();;
  int index = 0;
  ACE_TString name;
  ACE_Configuration::VALUETYPE type;
  while(m_pConfig->enumerate_values(Section, index, name, type) == 0)
  {
    ACE_TString value;
    if(m_pConfig->get_string_value(Section, name.c_str(), value) == 0)
    {
      int pos = m_Servers.AddString(name.c_str());
      ACE_TCHAR* pIOR = new ACE_TCHAR[value.length() + 1];
      ACE_OS::strcpy(pIOR, value.c_str());
      m_Servers.SetItemData(pos, (DWORD)pIOR);
    }
    ++index;
  }

  return TRUE;  // return TRUE unless you set the focus to a control
  // EXCEPTION: OCX Property Pages should return FALSE
}
コード例 #5
0
ファイル: LameMP3.cpp プロジェクト: BearWare/TeamTalk5
void LameMP3::Close()
{
    if(!m_hMp3Stream)
        return;

    DWORD outLen = 0;
    int err = deinitStream(m_hMp3Stream, &m_out_mp3data[0], &outLen);
    assert(err == 0);
    if(outLen)
        m_outfile.send((const char*)&m_out_mp3data[0], outLen);

    ACE_TString filename = GetFileName();
    
    closeStream(m_hMp3Stream);
    
    m_outfile.close();
    
    if(filename.length())
    {
#if defined(UNICODE)
        //LAME doesn't support Unicode, so we just convert to locale
        //and hope for the best
        ACE_CString ascii = UnicodeToLocal(filename.c_str());
        err = writeInfoTag(m_hMp3Stream, ascii.c_str());
#else
        err = writeInfoTag(m_hMp3Stream, filename.c_str());
#endif
    }
    m_out_mp3data.resize(0);
    m_hMp3Stream = 0;
}
コード例 #6
0
ファイル: ConfigTreeCtrl.cpp プロジェクト: CCJY/ACE
void ConfigTreeCtrl::ResolveKey(wxTreeItemId Item, ACE_Configuration_Section_Key& Key)
{
  wxTreeItemId OriginalItem = Item;
  ACE_TString Path("");
  ACE_TString Temp;
  while(Item != GetRootItem())
  {
    wxString Text = GetItemText(Item);
    Temp = Path;
    Path = Text.c_str();
    if(Temp.length())
    {
      Path += "\\";
      Path += Temp;
    }
    Item = GetParent(Item);
  }
  if(Path.length())
  {
    m_pConfig->expand_path(m_pConfig->root_section(), Path, Key, 0);
  }
  else
  {
    Key = m_pConfig->root_section();
  }
}
コード例 #7
0
ファイル: Commands.cpp プロジェクト: BearWare/TeamTalk5
 size_t pastBlanks(size_t offset, const ACE_TString& input)
 {
     while(offset<input.length() && 
         (input[offset] == ' ' ||
         input[offset] == '\r' ||
         input[offset] == '\n')) offset ++;
     return offset;
 }
コード例 #8
0
ファイル: FileSystemStorage.cpp プロジェクト: binary42/OCI
Directory::Ptr Directory::make_new_subdir(const ACE_TString& t_name)
{
  if (files_.find(t_name) != files_.end()) {
    throw std::runtime_error("Can't create a directory with the same "
                             "name as an existing file.");
  }

  ACE_TString logical(t_name.c_str(),
                      (std::min)(FSS_MAX_FILE_NAME, t_name.length()));
  ACE_TString phys_prefix = add_entry();
  ACE_TString phys_base = b32h_encode(logical.c_str());

  if (t_name.length() >= FSS_MAX_FILE_NAME) {
    unsigned int& counter = long_names_[phys_prefix + phys_base];

    if (counter == 99999) {
      throw std::runtime_error("Long directory name out of range");
    }

    phys_base += ACE_TEXT(".     X"); // snprintf will clobber the X with a 0
    ACE_TCHAR* buf = &phys_base[0] + phys_base.length() - 6;
    ACE_OS::snprintf(buf, 6, ACE_TEXT("%05u"), counter++);
    phys_base = phys_base.substr(0, phys_base.length() - 1); // trim the 0
  }

  ACE_TString phys = phys_prefix + phys_base;
  dirs_[t_name] = phys;
  {
    CwdGuard cg(physical_dirname_);

    if (dds_mkdir(phys.c_str()) == -1) {
      throw std::runtime_error("Can't create directory");
    }

    if ((phys_prefix.length() > 0 && dds_chdir(phys_prefix.c_str()) == -1)
        || dds_chdir(phys_base.c_str()) == -1) {
      dds_rmdir(phys.c_str());
      throw std::runtime_error("Can't change to newly created directory");
    }

    std::ofstream fn("_fullname");
    fn << t_name << '\n';
  }
  return new Directory(physical_dirname_ + phys, t_name, this);
}
コード例 #9
0
ファイル: be_init.cpp プロジェクト: CCJY/ATCD
int
BE_save_orb_args (int &argc, ACE_TCHAR *argv[])
{
  int i = 1;
  ACE_TString holder;

  while (i < argc)
    {
      if (ACE_OS::strncmp (argv[i], ACE_TEXT("-ORB"), 4) == 0)
        {
          holder += ACE_TString (argv[i]);
          holder += ACE_TEXT(" ");

          // Could be another -ORBxxx arg or an IDL compiler arg.
          if (*argv[i + 1] == '-')
            {
              ++i;
              continue;
            }

          // No-copy constructor.
          ACE_TString tmp (argv[i + 1],
                           0,
                           false);

          // If the arg ends with either .idl or .pidl, we're done.

          size_t len = tmp.length ();
          ssize_t pos = tmp.find (ACE_TEXT(".idl"));

          if (len - pos == 4)
            {
              return 0;
            }

          pos = tmp.find (ACE_TEXT(".pidl"));

          if (len - pos == 5)
            {
              return 0;
            }

          // If we're here, the next arg goes with the preceding -ORBxxx.
          holder += tmp;
          holder += ACE_TEXT(" ");
          i += 2;
        }
      else
        {
          ++i;
        }
    }

  be_global->orb_args (ACE_TEXT_ALWAYS_CHAR(holder.c_str()));

  return 0;
}
コード例 #10
0
ファイル: SubDriver.cpp プロジェクト: svn2github/OpenDDS
int
SubDriver::parse_pub_arg(const ACE_TString& arg)
{
  size_t pos;

  // Find the first ':' character, and make sure it is in a legal spot.
  if ((pos = std::find(arg.c_str(), arg.c_str() + arg.length(), ACE_TEXT(':')) - arg.c_str()) == arg.length()) {
    ACE_ERROR((LM_ERROR,
               "(%P|%t) Bad -p command-line value (%s). Missing ':' char.\n",
               arg.c_str()));
    return -1;
  }

  if (pos == 0) {
    ACE_ERROR((LM_ERROR,
               "(%P|%t) Bad -p command-line value (%s). "
               "':' char cannot be first char.\n",
               arg.c_str()));
    return -1;
  }

  if (pos == (arg.length() - 1)) {
    ACE_ERROR((LM_ERROR,
               "(%P|%t) Bad -p command-line value  (%s) - "
               "':' char cannot be last char.\n",
               arg.c_str()));
    return -1;
  }

  // Parse the pub_id from left of ':' char, and remainder to right of ':'.
  ACE_TString pub_id_str(arg.c_str(), pos);
  this->pub_addr_str_ = arg.c_str() + pos + 1;

  this->pub_id_fname_ = pub_id_str.c_str();
  this->pub_addr_ = ACE_INET_Addr(this->pub_addr_str_.c_str());

  return 0;
}
コード例 #11
0
ファイル: TestClient.cpp プロジェクト: OspreyHub/ATCD
// Read in the stringified object references into an array
// Warning: The file may contain many separate IORs separated by linefeeds.
void TestClient::buildIORList()
{
  FILE* iorFile = ACE_OS::fopen (iorFile_, "r");
  if ( iorFile == 0 )
    ACE_ERROR ((LM_ERROR, "Fail to open %s\n", iorFile_));

  ACE_TString ior;
  while (getline(iorFile, ior) != EOF )
  {
    if (ior.length() > 0)
      iors_.push_back(ior);
    else
      break;
  }
}
コード例 #12
0
ファイル: Commands.cpp プロジェクト: BearWare/TeamTalk5
    ACE_TString PrepareString(const ACE_TString& str)
    {
        ACE_TString newstr;
        if(str.length()>MAX_STRING_LENGTH)
            newstr = str.substr(0, MAX_STRING_LENGTH);
        else
            newstr = str;

        replace_all(newstr, ACE_TEXT("\\"), ACE_TEXT("\\\\"));
        replace_all(newstr, ACE_TEXT("\""), ACE_TEXT("\\\""));
        replace_all(newstr, ACE_TEXT("\r"), ACE_TEXT("\\r"));
        replace_all(newstr, ACE_TEXT("\n"), ACE_TEXT("\\n"));

        return newstr;
    }
コード例 #13
0
ファイル: Commands.cpp プロジェクト: BearWare/TeamTalk5
 bool GetProperty(const mstrings_t& properties, 
     const ACE_TString& prop, 
     ACE_TString& value)
 {
     mstrings_t::const_iterator ite = properties.find(prop);
     if( ite != properties.end() )
     {
         value = (*ite).second;
         if(value.length()>MAX_STRING_LENGTH)
             value.resize(MAX_STRING_LENGTH);
         return true;
     }
     else
         return false;
 }
コード例 #14
0
ファイル: Capabilities.cpp プロジェクト: Sanzzes/wopc-core
int
ACE_Capabilities::getline (FILE *fp, ACE_TString &line)
{
  int ch;

  line.set (0, 0);

  while ((ch = ACE_OS::fgetc (fp)) != EOF && ch != ACE_TEXT ('\n'))
    line += (ACE_TCHAR) ch;

  if (ch == EOF && line.length () == 0)
    return -1;
  else
    return 0;
}
コード例 #15
0
ファイル: SelectNSDialog.cpp プロジェクト: asdlei00/ACE
void CSelectNSDialog::OnAdd()
{
  // TODO: Add your control notification handler code here
  CAddNameServerDlg Dialog;
  if(Dialog.DoModal() != IDOK)
  {
    return;
  }
  ACE_Configuration_Section_Key Section = m_pConfig->root_section();
  ACE_TString Value = Dialog.m_IOR;
  m_pConfig->set_string_value(Section, Dialog.m_Name, Value);
  int pos = m_Servers.AddString(Dialog.m_Name);
  ACE_TCHAR* pIOR = new ACE_TCHAR[Value.length() + 1];
  ACE_OS::strcpy(pIOR, Value.c_str());
  m_Servers.SetItemData(pos, (DWORD)pIOR);

}
コード例 #16
0
int
ACE_Ini_ImpExp::export_section (const ACE_Configuration_Section_Key& section,
                                const ACE_TString& path,
                                FILE* out)
{
  // don't export the root
  if (path.length ())
    {
      // Write out the section header
      ACE_TString header = ACE_TEXT ("[");
      header += path;
      header += ACE_TEXT ("]\n");
      if (ACE_OS::fputs (header.fast_rep (), out) < 0)
        return -1;
      // Write out each value
      int index = 0;
      ACE_TString name;
      ACE_Configuration::VALUETYPE type;
      ACE_TString line;
      ACE_TCHAR int_value[32];
      ACE_TCHAR bin_value[3];
      void* binary_data;
      size_t binary_length;
      ACE_TString string_value;
      while (!config_.enumerate_values (section, index, name, type))
        {
          line = name + ACE_TEXT ("=");
          switch (type)
            {
            case ACE_Configuration::INTEGER:
              {
                u_int value;
                if (config_.get_integer_value (section, name.fast_rep (), value))
                  return -2;
                ACE_OS::sprintf (int_value, ACE_TEXT ("%08x"), value);
                line += int_value;
                break;
              }
            case ACE_Configuration::STRING:
              {
                if (config_.get_string_value (section,
                                              name.fast_rep (),
                                              string_value))
                  return -2;
                line += string_value;
                break;
              }
#ifdef _WIN32
            case ACE_Configuration::INVALID:
              break;  // JDO added break.  Otherwise INVALID is processed
              // like BINARY. If that's correct, please remove the
              // break and these comments
#endif
            case ACE_Configuration::BINARY:
              {
                // not supported yet - maybe use BASE64 codeing?
                if (config_.get_binary_value (section,
                                              name.fast_rep (),
                                              binary_data,
                                              binary_length))
                  return -2;
                line += ACE_TEXT ("\"");
                unsigned char* ptr = (unsigned char*)binary_data;
                while (binary_length)
                  {
                    if (ptr != binary_data)
                      {
                        line += ACE_TEXT (",");
                      }
                    ACE_OS::sprintf (bin_value, ACE_TEXT ("%02x"), *ptr);
                    line += bin_value;
                    --binary_length;
                    ++ptr;
                  }
                line += ACE_TEXT ("\"");
                delete [] (char *) binary_data;
                break;
              }
            default:
              return -3;

            }// end switch on type

          line += ACE_TEXT ("\n");
          if (ACE_OS::fputs (line.fast_rep (), out) < 0)
            return -4;
          ++index;
        }// end while enumerating values
    }
  // Export all sub sections
  int index = 0;
  ACE_TString name;
  ACE_Configuration_Section_Key sub_key;
  ACE_TString sub_section;
  while (!config_.enumerate_sections (section, index, name))
    {
      ACE_TString sub_section (path);
      if (path.length ())
        sub_section += ACE_TEXT ("\\");
      sub_section += name;
      if (config_.open_section (section, name.fast_rep (), 0, sub_key))
        return -5;
      if (export_section (sub_key, sub_section.fast_rep (), out))
        return -6;
      ++index;
    }
  return 0;

}
コード例 #17
0
ファイル: Commands.cpp プロジェクト: BearWare/TeamTalk5
    int ExtractProperties(const ACE_TString& input, mstrings_t& properties)
    {
        TTASSERT(input.find('\n') == input.rfind('\n'));

        bool bSyntaxError = false;
        if( input.length() == 0 )
            bSyntaxError = true;

        size_t offset = input.find(' ');//past command
        if(offset == ACE_TString::npos)
            return 0;

        while(offset < input.length() && !bSyntaxError)
        {
            //past any spaces
            offset = pastBlanks(offset, input);
            if(offset == input.length())
            {
                break;
            }

            size_t propBegin = offset;
            ACE_TString prop;
            ACE_TString value;
            while(offset < input.length()) //extract property name
            {
                if( input[offset] != ' ' && input[offset] != '=') offset ++;
                else break;
            }
            if(offset == input.length())
            {
                bSyntaxError = true; //no properties in ACE_TString
                break;
            }

            prop = input.substr(propBegin, offset-propBegin); //set propertyname
            TTASSERT(properties.find(prop) == properties.end());
            offset = pastBlanks(offset, input); //past spaces
            if(offset == input.length())
            {
                bSyntaxError = true;
                break;
            }
            if(input[offset] != '=')
            {
                bSyntaxError = true;
                break;
            }
            else offset ++; //past =

            offset = pastBlanks(offset, input); //past spaces
            if(offset == input.length())
            {
                bSyntaxError = true;
                break;
            }

            //determine whether it's a string or an integer
            if(input[offset] == '"') //a ACE_TString
            {
                bool found = false;
                size_t strBegin = ++offset; //past "
                while(!found && offset<input.length())
                {
                    /*
                    if(input[offset]==ACE_TEXT('\"') && input[offset-1] != ACE_TEXT('\\')) found = true;
                    offset++;
                    */
                    if(input[offset] == '\\')
                        offset += 2;
                    else if(input[offset] == '"')
                    {
                        found = true;
                        offset++;
                    }
                    else
                        offset++;
                }

                if(!found)
                {
                    bSyntaxError = true;
                    break;
                }

                value = input.substr(strBegin, offset-strBegin-1);
                offset ++; //past \"

                properties[prop] = RebuildString(value);
                //properties.SetAt(prop, RebuildString(value));
            }
            else if(input[offset] == '[') // an int list
            {
                bool found = false;
                size_t listBegin = ++offset; //past "
                while(!found && offset<input.length())
                {
                    if(input[offset] == ']') found = true;
                    offset++;
                }

                if(!found)
                {
                    bSyntaxError = true;
                    break;
                }

                value = input.substr(listBegin, offset-listBegin-1);
                offset ++; //past ]

                properties[prop] = RebuildString(value);
                //properties.SetAt(prop, RebuildString(value));
            }
            else //eat what's left until space
            {
                size_t intBegin = offset;
                while(offset<input.length() && 
                    input[offset] != ' ' && 
                    input[offset] != '\r' &&
                    input[offset] != '\n') offset ++; //past spaces
                value = input.substr(intBegin, offset-intBegin);

                properties[prop] = RebuildString(value);
                //properties.SetAt(prop, RebuildString(value));
            }
        }

        return bSyntaxError? -1 : (int)properties.size();
    }
コード例 #18
0
int
SimpleDataWriter::run(SimplePublisher* publisher)
{
  DBG_ENTRY("SimpleDataWriter","run");

  VDBG((LM_DEBUG, "(%P|%t) DBG:   "
             "Build the DataSampleElementList to contain one element - "
             "our 'Hello World' string.\n"));

  // We just send one message.

  // This is what goes in the "Data Block".
  ACE_TString data = "Hello World!";

  // Now we can create the DataSampleHeader struct and set its fields.
  TAO::DCPS::DataSampleHeader header;

  // The +1 makes the null terminator ('/0') get placed into the block.
  header.message_length_ = data.length() + 1;
  header.message_id_ = 1;
  header.sequence_ = 0;
  // TMB - Compiler no longer likes the next line...  source_timestamp_ is gone.
  //header.source_timestamp_ = ACE_OS::gettimeofday().msec();
  header.publication_id_ = this->pub_id_;

  // The DataSampleHeader is what goes in the "Header Block".
  ACE_Message_Block* header_block = new ACE_Message_Block
                                                (header.max_marshaled_size());
  header_block << header;

  // The +1 makes the null terminator ('/0') get placed into the block.
  ACE_Message_Block* data_block = new ACE_Message_Block(data.length() + 1);
  data_block->copy(data.c_str());

  // Chain the "Data Block" to the "Header Block"
  header_block->cont(data_block);

  // Create the DataSampleListElement now.
  TAO::DCPS::DataSampleListElementAllocator allocator(3);
  TAO::DCPS::TransportSendElementAllocator trans_allocator(3, sizeof (TAO::DCPS::TransportSendElement));
  TAO::DCPS::DataSampleListElement* element;

  ACE_NEW_MALLOC_RETURN(element,
           static_cast<TAO::DCPS::DataSampleListElement*> (allocator.malloc(sizeof (TAO::DCPS::DataSampleListElement))),
           TAO::DCPS::DataSampleListElement(this->pub_id_, this, 0, &trans_allocator),
           1);

  // The Sample Element will hold on to the chain of blocks (header + data).
  element->sample_ = header_block;

  // Set up the DataSampleList
  TAO::DCPS::DataSampleList samples;

  samples.head_ = element;
  samples.tail_ = element;
  samples.size_ = 1;

  VDBG((LM_DEBUG, "(%P|%t) DBG:   "
             "Ask the publisher to send the DataSampleList (samples).\n"));

  publisher->send_samples(samples);

  VDBG((LM_DEBUG, "(%P|%t) DBG:   "
             "The Publisher has finished sending the samples.\n"));

  return 0;
}
コード例 #19
0
ファイル: DLL_Manager.cpp プロジェクト: yuanxu/liveshow_r2
int
ACE_DLL_Handle::open (const ACE_TCHAR *dll_name,
                      int open_mode,
                      ACE_SHLIB_HANDLE handle)
{
  ACE_TRACE ("ACE_DLL_Handle::open");
  ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, 0));

  if (this->dll_name_)
    {
      // Once dll_name_ has been set, it can't be changed..
      if (ACE_OS::strcmp (this->dll_name_, dll_name) != 0)
        {
          if (ACE::debug ())
            ACE_ERROR ((LM_ERROR,
                        ACE_TEXT ("(%P|%t) DLL_Handle::open: error, ")
                        ACE_TEXT ("tried to reopen %s with name %s\n"),
                        this->dll_name_,
                        dll_name));

          return -1;
        }
    }
  else
    this->dll_name_ = ACE::strnew (dll_name);

  if (!this->open_called_)
    this->open_called_ = 1;

  // If it hasn't been loaded yet, go ahead and do that now.
  if (this->handle_ == ACE_SHLIB_INVALID_HANDLE)
    {
      if (handle)
        this->handle_ = handle;
      else
        {
          /*
          ** Get the set of names to try loading. We need to do this to
          ** properly support the ability for a user to specify a simple,
          ** unadorned name (for example, "ACE") that will work across
          ** platforms. We apply platform specifics to get a name that will
          ** work (e.g. libACE, ACEd.dll, ACE.dll, etc.) We rely on the
          ** underlying dlopen() implementation to "Do The Right Thing" in
          ** terms of using relative paths, LD_LIBRARY_PATH, system security
          ** rules, etc. except when ACE_MUST_HELP_DLOPEN_SEARCH_PATH is set.
          ** If it is set, then ACE::ldfind() scans the configured path
          ** looking for a match on the name and prefix/suffix applications.
          ** NOTE: having ACE scan for a file and then pass a fully-qualified
          ** pathname to dlopen() is a potential security hole; therefore,
          ** do not use ACE_MUST_HELP_DLOPEN_SEARCH_PATH unless necessary
          ** and only after considering the risks.
          */
          ACE_Array<ACE_TString> dll_names;
          dll_names.max_size (10);    // Decent guess to avoid realloc later

#if defined (ACE_MUST_HELP_DLOPEN_SEARCH_PATH)
          // Find out where the library is
          ACE_TCHAR dll_pathname[MAXPATHLEN + 1];

          // Transform the pathname into the appropriate dynamic link library
          // by searching the ACE_LD_SEARCH_PATH.
          ACE::ldfind (dll_name,
                       dll_pathname,
                       (sizeof dll_pathname / sizeof (ACE_TCHAR)));
          ACE_TString dll_str (dll_pathname);
          dll_names.size (1);
          dll_names.set (dll_str, 0);
#else
          this->get_dll_names (dll_name, dll_names);
#endif

          ACE_Array_Iterator<ACE_TString> name_iter (dll_names);
          ACE_TString *name = 0;
          while (name_iter.next (name))
            {
              // The ACE_SHLIB_HANDLE object is obtained.
              this->handle_ = ACE_OS::dlopen (name->c_str (),
                                              open_mode);

              if (ACE::debug ())
                {
                  ACE_DEBUG ((LM_DEBUG,
                              ACE_TEXT ("ACE (%P|%t) DLL_Handle::open ")
                              ACE_TEXT ("(\"%s\", 0x%x) -> %s: %s\n"),
                              name->c_str (),
                              open_mode,
                              ((this->handle_ != ACE_SHLIB_INVALID_HANDLE)
                               ? ACE_TEXT ("succeeded")
                               : ACE_TEXT ("failed")),
                              this->error()->c_str()));
                }

              if (this->handle_ != ACE_SHLIB_INVALID_HANDLE)   // Good one?
                break;

              // If errno is ENOENT we just skip over this one,
              // anything else - like an undefined symbol, for
              // instance must be flagged here or the next error will
              // mask it.
              // @TODO: If we've found our DLL _and_ it's
              // broken, should we continue at all?
              if ((errno != 0) && (errno != ENOENT) && ACE::debug ())
                ACE_ERROR ((LM_ERROR,
                            ACE_TEXT ("ACE (%P|%t) DLL_Handle::open ")
                            ACE_TEXT ("(\'%s\') failed, errno=")
                            ACE_TEXT ("%d: %s\n"),
                            name->c_str (),
                            errno,
                            this->error ()->c_str ()));

#if defined (AIX)
              // AIX often puts the shared library file (most often named
              // shr.o) inside an archive library. If this is an archive
              // library name, then try appending [shr.o] and retry.
              if (ACE_TString::npos != name->strstr (ACE_TEXT (".a")))
                {
                  ACE_TCHAR aix_pathname[MAXPATHLEN + 1];
                  ACE_OS::strncpy (aix_pathname,
                                   name->c_str (),
                                   name->length ());
                  aix_pathname[name->length ()] = '\0';
                  ACE_OS::strcat (aix_pathname, ACE_TEXT ("(shr.o)"));
                  open_mode |= RTLD_MEMBER;

                  if (ACE::debug ())
                    {
                      ACE_DEBUG ((LM_DEBUG,
                                  ACE_TEXT ("ACE (%P|%t) DLL_Handle::open ")
                                  ACE_TEXT ("(\"%s\", 0x%x) -> %s: %s\n"),
                                  aix_pathname,
                                  open_mode,
                                  ACE_TEXT ((this->handle_ != ACE_SHLIB_INVALID_HANDLE)
                                                ? "succeeded"
                                                : "failed"),
                                  this->error()->c_str()));
                    }

                  this->handle_ = ACE_OS::dlopen (aix_pathname, open_mode);
                  if (this->handle_ != ACE_SHLIB_INVALID_HANDLE)
                    break;

                  // If errno is ENOENT we just skip over this one, anything
                  // else - like an undefined symbol, for instance
                  // must be flagged here or the next error will mask it.
                  //
                  // @TODO: If we've found our DLL _and_ it's broken,
                  // should we continue at all?
                  if (ACE::debug () && (errno != 0) && (errno != ENOENT))
                    ACE_ERROR ((LM_ERROR,
                                ACE_TEXT ("ACE (%P|%t) DLL_Handle::open ")
                                ACE_TEXT ("(\'%s\') failed, errno=")
                                ACE_TEXT ("%d: %s\n"),
                                name->c_str (),
                                errno,
                                this->error ()->c_str ()));

                }
#endif /* AIX */

              name_iter.advance ();
            }

          if (this->handle_ == ACE_SHLIB_INVALID_HANDLE)
            {
              if (ACE::debug ())
                ACE_ERROR ((LM_ERROR,
                            ACE_TEXT ("ACE (%P|%t) DLL_Handle::open (\"%s\"): ")
                            ACE_TEXT ("Invalid handle error: %s\n"),
                            this->dll_name_,
                            this->error ()->c_str ()));

              return -1;
            }
        }
    }

  ++this->refcount_;

  if (ACE::debug ())
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("ACE (%P|%t) DLL_Handle::open - %s (%d), refcount=%d\n"),
                this->dll_name_,
                this->handle_,
                this->refcount_));
  return 0;
}
コード例 #20
0
int
ACE_Registry_ImpExp::export_section (const ACE_Configuration_Section_Key& section,
                                     const ACE_TString& path,
                                     FILE* out)
{
  // don't export the root
  if (path.length ())
    {
      // Write out the section header
      ACE_TString header = ACE_TEXT ("[");
      header += path;
      header += ACE_TEXT ("]");
      header += ACE_TEXT ("\n");
      if (ACE_WRITE_STRING (header.fast_rep (), out) < 0)
        return -1;
      // Write out each value
      int index = 0;
      ACE_TString name;
      ACE_Configuration::VALUETYPE type;
      ACE_TString line;
      ACE_TCHAR int_value[32];
      ACE_TCHAR bin_value[3];
      void* binary_data;
      size_t binary_length;
      ACE_TString string_value;
      while (!config_.enumerate_values (section, index, name, type))
        {
          line = ACE_TEXT ("\"") + name + ACE_TEXT ("\"=");
          switch (type)
            {
            case ACE_Configuration::INTEGER:
              {
                u_int value;
                if (config_.get_integer_value (section, name.fast_rep (), value))
                  return -2;
                ACE_OS::snprintf (int_value, 32, ACE_TEXT ("%08x"), value);
                line += ACE_TEXT ("dword:");
                line += int_value;
                break;
              }
            case ACE_Configuration::STRING:
              {
                if (config_.get_string_value (section,
                                              name.fast_rep (),
                                              string_value))
                  return -2;
                line += ACE_TEXT ("\"");
                line += string_value + ACE_TEXT ("\"");
                break;
              }
#ifdef ACE_WIN32
            case ACE_Configuration::INVALID:
              break;
#endif
            case ACE_Configuration::BINARY:
              {
                // not supported yet - maybe use BASE64 codeing?
                if (config_.get_binary_value (section,
                                              name.fast_rep (),
                                              binary_data,
                                              binary_length))
                  return -2;
                line += ACE_TEXT ("hex:");
                unsigned char* ptr = (unsigned char*)binary_data;
                while (binary_length)
                  {
                    if (ptr != binary_data)
                      {
                        line += ACE_TEXT (",");
                      }
                    ACE_OS::snprintf (bin_value, 3, ACE_TEXT ("%02x"), *ptr);
                    line += bin_value;
                    --binary_length;
                    ++ptr;
                  }
#if defined (ACE_HAS_ALLOC_HOOKS)
                ACE_Allocator::instance()->free(binary_data);
#else
                delete [] (char*) binary_data;
#endif /* ACE_HAS_ALLOC_HOOKS */
                break;
              }
            default:
              return -3;
            }
          line += ACE_TEXT ("\n");
          if (ACE_WRITE_STRING (line.fast_rep (), out) < 0)
            return -4;
          ++index;
        }
    }
  // Export all sub sections
  int index = 0;
  ACE_TString name;
  ACE_Configuration_Section_Key sub_key;
  ACE_TString sub_section;
  while (!config_.enumerate_sections (section, index, name))
    {
      ACE_TString sub_section (path);
      if (path.length ())
        sub_section += ACE_TEXT ("\\");
      sub_section += name;
      if (config_.open_section (section, name.fast_rep (), 0, sub_key))
        return -5;
      if (export_section (sub_key, sub_section.fast_rep (), out))
        return -6;
      ++index;
    }
  return 0;
}