/**
 * initialize primarily functions to initialize static global variables
 * that will not be changed frequently. These variables are currently
 * _hostName.
 *
 */
void ComputerSystem::initialize()
{
    char    hostName[PEGASUS_MAXHOSTNAMELEN + 1];
    struct  hostent *hostEntry;

    if (gethostname(hostName, sizeof(hostName)) != 0)
    {
        _hostName.assign("Not initialized");
    }
    hostName[sizeof(hostName)-1] = 0;

    // Now get the official hostname.  If this call fails then return
    // the value from gethostname().

    char hostEntryBuffer[8192];
    struct hostent hostEntryStruct;
    int hostEntryErrno;

    gethostbyname_r(
        hostName,
        &hostEntryStruct,
        hostEntryBuffer,
        sizeof(hostEntryBuffer),
        &hostEntry,
        &hostEntryErrno);

    if (hostEntry)
    {
        _hostName.assign(hostEntry->h_name);
    }
    else
    {
        _hostName.assign(hostName);
    }
}
Example #2
0
//------------------------------------------------------------------------------
// FUNCTION: getUtilGetHostName
//
// REMARKS:
//
// PARAMETERS:  [OUT] systemName -> string that will contain the host name
//
// RETURN: TRUE if successful, FALSE otherwise
//------------------------------------------------------------------------------
static Boolean getUtilGetHostName(String& systemName)
{
  char    hostName[PEGASUS_MAXHOSTNAMELEN + 1];
  struct  hostent *he;

  if (gethostname(hostName, sizeof(hostName)) != 0)
  {
     return false;
  }
  hostName[sizeof(hostName)-1] = 0;

  // Now get the official hostname.  If this call fails then return
  // the value from gethostname().

  if ((he = gethostbyname(hostName)) != 0)
  {
      systemName.assign(he->h_name);
  }
  else
  {
      systemName.assign(hostName);
  }

  return true;
}
Example #3
0
String String::substr(size_type index, size_type num) const {
	String tmp;
	if(num == npos)
		tmp.assign(data() + index, length() - index);
	else
		tmp.assign(data() + index, num);
	return tmp;
}
Example #4
0
//----------------------------------------------------------------------------//
void FalagardEditbox::setupVisualString(String& visual) const
{
    Editbox* w = static_cast<Editbox*>(d_window);

    if (w->isTextMasked())
        visual.assign(w->getText().length(), w->getMaskCodePoint());
    else
        visual.assign(w->getTextVisual());
}
Example #5
0
void CheatFeedback(int16_t whichCheat, bool activate, Handle<Admiral> whichPlayer) {
    String admiral_name(GetAdmiralName(whichPlayer));
    String feedback;
    if (activate) {
        feedback.assign(StringList(kCheatFeedbackOnID).at(whichCheat - 1));
    } else {
        feedback.assign(StringList(kCheatFeedbackOffID).at(whichCheat - 1));
    }
    Messages::add(format("{0}{1}", admiral_name, feedback));
}
Example #6
0
	void LibConfigProgram::expandModuleNames()
	{
		String item;

		// Lowercase
		const String::List::iterator end = pOptModules.end();
		for (String::List::iterator i = pOptModules.begin(); i != end; ++i)
		{
			item = *i;
			*i = item.toLower();
		}

		bool mustContinue;
		do
		{
			mustContinue = false;
			const String::List::iterator end = pOptModules.end();
			for (String::List::iterator i = pOptModules.begin(); i != end; ++i)
			{
				if (i->empty())
				{
					// We have no interest in empty strings
					pOptModules.erase(i);
					mustContinue = true;
					break;
				}
				if (String::npos != i->find_first_of(YUNI_LIBYUNI_CONFIG_SEPARATORS))
				{
					// This item seems to be actually a list of several requested modules
					// We will split the string to get the real list
					item = *i;
					pOptModules.erase(i);
					item.split(pOptModules, YUNI_LIBYUNI_CONFIG_SEPARATORS, false, false, true);
					mustContinue = true;
					break;
				}
				if (i->first() == '+')
				{
					// The symbol `+` enables a module, but this is already a default behavior
					item.assign(*i, 1, i->size() - 1);
					*i = item;
					continue;
				}
				if (i->first() == '-')
				{
					// The symbol `-` disables a module, so we have to remove all existing entries
					mustContinue = true;
					item.assign(*i, 1, i->size() - 1);
					pOptModules.erase(i);
					pOptModules.remove(item);
					break;
				}
			}
		} while (mustContinue);
	}
Example #7
0
bool Exec::FindProgram(String &dest, String name)
{
    String path;
    String exts;
    StringVector ppath;
    StringVector pext;

    int lpatherror = Environment::GetVariable(path, _T("PATH"), defpath);
    int lexterror = Environment::GetVariable(exts, _T("PATHEXT"), defexts);

    Str::SplitLine(ppath, path, _T(';'));
    Str::SplitLine(pext, exts, _T(';'));

    if (Path::FileHasExtension(name) || (pext.size() == 0))
    {
        for (auto pit : ppath)
        {
            String cpath(pit);
            if ((cpath.at(cpath.size() - 1) != _T('/')) && (cpath.at(cpath.size() - 1) != _T('\\')))
                cpath.append(1, _T('/'));
            cpath.append(name);

            if (Path::FileExists(cpath))
            {
                dest.assign(cpath);
                return true;
            }
        }
    }
    else
    {
        for (auto pit : ppath)
        {
            for (auto eit : pext)
            {
                String cpath(pit);
                String cext(eit);

                if ((cpath.at(cpath.size() - 1) != _T('/')) && (cpath.at(cpath.size() - 1) != _T('\\')))
                    cpath.append(1, _T('/'));

                cpath.append(name);
                cpath.append(cext);

                if (Path::FileExists(cpath))
                {
                    dest.assign(cpath);
                    return true;
                }
            }
        }
    }

    return false;
}
Example #8
0
Boolean OperatingSystem::getCaption(String& caption)
{

   caption.assign("The current Operating System");

   return true;
}
/**
   getCaption method for Solaris implementation of OS Provider

   Uses uname system call and extracts information for the Caption.
  */
Boolean OperatingSystem::getCaption(String& caption)
{

   struct utsname     unameInfo;

   // Call uname and check for any errors.
   if (uname(&unameInfo) < 0)
   {
       return false;
   }

   // append in caption the information available from uname system call.
   //     system name, release, version, machine and nodename.
   caption.assign(unameInfo.sysname);
   caption.append(" ");
   caption.append(unameInfo.release);
   // caption.append(" ");
   // caption.append(unameInfo.version);
   // caption.append(" ");
   // caption.append(unameInfo.machine);
   // caption.append(" ");
   // caption.append(unameInfo.nodename);

   return true;
}
Example #10
0
Substrinfo 
Regex::match(const char *target, Subex &subex, String &the_substr) const {
	Substrinfo m = match(target, subex);
	if (m)
		the_substr.assign(target + m.i, m.len);
	return m;
}
Boolean ComputerSystem::getOtherIdentifyingInfo(CIMProperty& p)
{
  // return model for this property

   int status;
   Array<String> s;
   char hwname[32];
   typedef struct {
        unsigned short wlength;
        unsigned short wcode;
        void *pbuffer;
        void *pretlen; } item_list;
   item_list itmlst3[2];

   itmlst3[0].wlength = sizeof(hwname);
   itmlst3[0].wcode = SYI$_HW_NAME;
   itmlst3[0].pbuffer = hwname;
   itmlst3[0].pretlen = NULL;
   itmlst3[1].wlength = 0;
   itmlst3[1].wcode = 0;
   itmlst3[1].pbuffer = NULL;
   itmlst3[1].pretlen = NULL;

   status = sys$getsyiw (0, 0, 0, itmlst3, 0, 0, 0);
   if ($VMS_STATUS_SUCCESS(status))
   {
	_otherInfo.assign(hwname);
	s.append(_otherInfo);
	p = CIMProperty(PROPERTY_OTHER_IDENTIFYING_INFO,s);
        return true;
   }
   else
        return false;
}
Example #12
0
String System::getHostIP(const String &hostName)
{
    struct hostent * phostent;
    struct in_addr   inaddr;
    String ipAddress = String::EMPTY;
    CString csName = hostName.getCString();
    const char * ccName = csName;
#ifndef PEGASUS_OS_OS400
    if ((phostent = ::gethostbyname(ccName)) != NULL)
#else
    char ebcdicHost[PEGASUS_MAXHOSTNAMELEN];
    if (strlen(ccName) < PEGASUS_MAXHOSTNAMELEN)
        strcpy(ebcdicHost, ccName);
    else
        return ipAddress;
    AtoE(ebcdicHost);
    if ((phostent = ::gethostbyname(ebcdicHost)) != NULL)
#endif
    {
        ::memcpy( &inaddr, phostent->h_addr,4);
#ifdef PEGASUS_PLATFORM_ZOS_ZSERIES_IBM
        char * gottenIPAdress = NULL;
        gottenIPAdress = ::inet_ntoa( inaddr );
        __etoa(gottenIPAdress);
        if (gottenIPAdress != NULL)
        {
            ipAddress.assign(gottenIPAdress);
        }
#else
        ipAddress = ::inet_ntoa( inaddr );
#endif
    }
    return ipAddress;
}
Example #13
0
/**
Get Xsl file path (imagecheck.xsl).

@internalComponent
@released

@param aExePath - Reference to Xsl file Path.
@return - 'true' for success.
*/
bool XmlWriter::GetXslSourcePath(String& aExePath)
{
#ifdef __LINUX__
	aExePath.assign("/");
	return true;
#else

	char* size = new char[KXmlGenBuffer];
	if (!size)
	{
		throw ExceptionReporter(NOMEMORY, __FILE__, __LINE__);
	}
	if(!(GetModuleFileName(NULL, size, KXmlGenBuffer)))
	{
		delete [] size;
		return false;
	}
	String path(size);
	delete [] size;
	size_t last = path.rfind('\\');
	if(last != String::npos)
	{
		aExePath = path.substr(0, last+1);
		return true;
	}
#endif
	return true ; // to avoid warning
}
Example #14
0
	void
	set_word(
		String const& word
	) {
		m_word.assign(word);
		refresh_counts();
	}
Example #15
0
bool OOBase::Environment::get_current(env_table_t& tabEnv)
{
	for (const char** env = (const char**)environ;*env != NULL;++env)
	{
		String str;
		if (!str.assign(*env))
			return false;

		size_t eq = str.find('=');
		if (eq == String::npos)
		{
			if (tabEnv.exists(str))
				continue;

			if (!tabEnv.insert(String(),str))
				return false;
		}
		else
		{
			String strK,strV;
			if (!strK.assign(str.c_str(),eq))
				return false;

			if (tabEnv.exists(strK))
				continue;

			if (!strV.assign(str.c_str()+eq+1) || !tabEnv.insert(strK,strV))
				return false;
		}
	}

	return true;
}
Example #16
0
//------------------------------------------------------------------------------
// FUNCTION:  DNSFileOk
//
// REMARKS:
//
// PARAMETERS:
//
// RETURN: true if file exists with appropriate contents, otherwise false.
//------------------------------------------------------------------------------
Boolean DNSFileOk()
{
    FILE *fp;
    char buffer[512];
    String strBuffer;
    int count = 0;
    Boolean ok = false;

    if ((fp = fopen(DNS_FILE_CONFIG.getCString(), "r")) == NULL)
        return ok;

    while(!feof(fp))
    {
        memset(buffer, 0, sizeof(buffer));
        fscanf(fp, "%s", buffer);
        strBuffer.assign(buffer);

        // Verify if keys exist
        if (String::equalNoCase(strBuffer, DNS_ROLE_DOMAIN) ||
            String::equalNoCase(strBuffer, DNS_ROLE_SEARCH) ||
            String::equalNoCase(strBuffer, DNS_ROLE_NAMESERVER))
            count++;

        if (count >= 2)
        {
            ok = true;
            break;
        }
    }
    fclose(fp);
    return ok;
}
Example #17
0
	XMLNode* XMLDecoderUTF8::parseComment()
	{
		size_t n = 0;
		size_t len;
		const uint8_t* ptr;
		String comment;

		/* discard "<!--" */
		advance(4);

		ptr = _stream;
		len = _rlen;
		while( *ptr != 0 && len ) {
			if( *ptr == '-' ) {
				if( match( ( const char* ) ptr, "-->") ) {
					comment.assign( ( const char* )  _stream, n );
					advance( n + 3 );
					return new XMLComment( comment );
				}
			}
			len--;
			n++;
			ptr++;
		}
		throw CVTException("Invalid comment");
	}
Boolean ComputerSystem::getSerialNumber(CIMProperty& p)
{
    long status = SS$_NORMAL, i;
    char lrSerNum[16]="",lSerNum[16]="";

    struct k1_arglist {                 // kernel call arguments
            long    lCount;             // number of arguments
            char *pSerNum;
        } getsernumkargs = {1};                // init 1 argument

    getsernumkargs.pSerNum = lrSerNum;

    status = sys$cmkrnl(GetSerNum,&getsernumkargs);
    if ($VMS_STATUS_SUCCESS(status))
    {
        for (i=0;i<strlen(lrSerNum);i++)
        {
           lSerNum[strlen(lrSerNum)-i-1] = lrSerNum[i];
        }
	_serialNumber.assign(lSerNum);
	p = CIMProperty(PROPERTY_SERIAL_NUMBER, _serialNumber);
        return true;
    }

    return false;
}
Example #19
0
static void * __render_load_text(Sdl_Graph *graph,void *string,void *font,int r, int g, int b, int a)
{
	allocator_t *allocator = ((Obj *)graph)->allocator;
	Sdl_Text *text;
	Sdl_Font *f = (Sdl_Font *)font;
	SDL_Surface* surface = NULL;
	SDL_Color textColor = {r, g, b, a };
	String *content;

	dbg_str(DBG_DETAIL,"Sdl_Text load text");
    text = OBJECT_NEW(allocator, Sdl_Text,"");
	content = ((Text *)text)->content;
	content->assign(content,string);

	surface = TTF_RenderText_Solid(f->ttf_font,
                                   ((Text *)text)->content->value,
                                   textColor ); 

	if(surface != NULL) {
		text->texture = SDL_CreateTextureFromSurface(graph->render, surface);
		text->width = surface->w;
		text->height = surface->h;
		dbg_str(DBG_DETAIL,"width =%d height=%d",text->width, text->height);
		SDL_FreeSurface(surface);
	}

	return text;
}
Example #20
0
int
scim_split_string_list (std::vector<String>& vec, const String& str, char delim)
{
    int count = 0;

    String temp;
    String::const_iterator bg, ed;

    vec.clear ();

    bg = str.begin ();
    ed = str.begin ();

    while (bg != str.end () && ed != str.end ()) {
        for (; ed != str.end (); ++ed) {
            if (*ed == delim)
                break;
        }
        temp.assign (bg, ed);
        vec.push_back (temp);
        ++count;

        if (ed != str.end ())
            bg = ++ ed;
    }
    return count;
}
Example #21
0
int Message::decode(const char* str, String& id)
{
    String s("%%>message:");
    if (!str || ::strncmp(str,s.c_str(),s.length()))
	return -1;
    // locate the SEP after id
    const char *sep = ::strchr(str+s.length(),':');
    if (!sep)
	return s.length();
    // locate the SEP after time
    const char *sep2 = ::strchr(sep+1,':');
    if (!sep2)
	return sep-str;
    id.assign(str+s.length(),(sep-str)-s.length());
    int err = -1;
    id = id.msgUnescape(&err);
    if (err >= 0)
	return err+s.length();
    String t(sep+1,sep2-sep-1);
    unsigned int tm = 0;
    t >> tm;
    if (!t.null())
	return sep-str;
    m_time=tm ? ((u_int64_t)1000000)*tm : Time::now();
    return commonDecode(str,sep2-str+1);
}
Example #22
0
/*
================================================================================
NAME              : getParentProcessID
DESCRIPTION       :
ASSUMPTIONS       :
PRE-CONDITIONS    :
POST-CONDITIONS   :
NOTES             :
================================================================================
*/
Boolean Process::getParentProcessID(String& s) const
{
  char buf[100];
  sprintf(buf,"%d",pInfo.pst_ppid);
  s.assign(buf);
  return true;
}
Example #23
0
bool StateBrush_Context::BrushConfig::read_word(const char **pos, String &out_value)
{
	out_value.clear();
	const char *p = *pos;
	while ((*p >= 'a' && *p <= 'z') || *p == '_') ++p;
	if (p > *pos) { out_value.assign(*pos, p); *pos = p; return true; }
	return false;
}
/**
   getStatus method for Windows implementation of OS provider

   Would like to be able to return and actual status vs. just
   always Unknown, but didn't know how to differentiate between
   OK and Degraded (assuming they are the only values that make
   sense, since the CIMOM is up and running), but one could see
   an argument for including Stopping if the Shutdown or Reboot
   methods have been invoked. For now, always return "Unknown".
   */
Boolean OperatingSystem::getStatus(String& status)
{
// ATTN-SLC-P3-17-Apr-02: Get true Windows status (vs. Unknown) BZ#44

    status.assign("Unknown");

    return true;
}
      /////////////////////////////////////////////////////////////////////////////////////////
      // NameDecoder::NameDecoder
      //! Create decoder from string id
      //! 
      //! \param[in] id - Name/description resource id
      /////////////////////////////////////////////////////////////////////////////////////////
      NameDecoder(resource_t id)
      {
        auto text = StringResource(id).c_str<encoding>();
      
        // [NAME/DESCRIPTION] Extract name & description
        if (text.contains(LineFeed))
        {
          int32_t sep = text.find(LineFeed);

          // Assign description and truncate name
          Name.assign(text.begin(), text.begin()+(sep+1));
          Description.assign(text.begin()+(sep+1), text.end());
        }
        // [NAME] Leave description blank
        else
          Name = text;
      }
Boolean OperatingSystem::getDescription(String& description)
{
    description.assign("This instance reflects the Operating System"
                       " on which the CIMOM is executing (as distinguished from instances"
                       " of other installed operating systems that could be run).");

    return true;
}
Example #27
0
void PacketData::read(String& value)
{
  if (!std::memchr(m_data + m_offset, '\0', m_size - m_offset))
    panic("Missing null character in packet data");

  value.assign((char*) (m_data + m_offset));
  m_offset += value.length() + 1;
}
qboolean OnClientConnectPost( edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[ 128 ] )
{
    if( Initialized && sv_allowdownload->value > 0 )
    {
        if( cvar_enable_debug->value > 0 )
        {
            ModuleDebug.append( UTIL_VarArgs( "\n\"%s\" (index = %d, address = %s) is connecting.\n", pszName, ENTINDEX( pEntity ), pszAddress ) );
        }

        if( rm_enable_downloadfix.value <= 0 )
        {
            NotifyClientDisconnectHook->Restore();
            RETURN_META_VALUE( MRES_IGNORED, TRUE );
        }
        else
        {
            NotifyClientDisconnectHook->Patch();
        }

        char	ip[ 16 ];
        uint32	player				= ENTINDEX( pEntity );
        time_t	timeSystem			= getSysTime();
        time_t*	nextReconnectTime	= &PlayerNextReconnectTime[ player ];
        String*	currentPlayerIp		= &PlayerCurrentIp[ player ];

        // Retrieve server IP one time from there because
        // we need to let server.cfg be executed in case
        // a specific ip is provided and because I have not
        // found forward to use to put this call at this time.
        retrieveServerIp( &ServerInternetIp );

        // Retrieve the current client's IP without the port.
        retrieveClientIp( ip, pszAddress );

        // Sanity IP address check to make sure the index
        // is our expected player. If not, we consider it
        // as a new player and we reset variables to the default.
        if( currentPlayerIp->compare( ip ) )
        {
            *nextReconnectTime = 0;

            currentPlayerIp->clear();
            currentPlayerIp->assign( ip );
        }

        // We are allowed to reconnect the player.
        // We put a cool down of 3 seconds minimum to avoid possible
        // infinite loop since depending where it will download resources,
        // it can connect/disconnect several times.
        if( *nextReconnectTime < timeSystem )
        {
            *nextReconnectTime = timeSystem + 3;
            CLIENT_COMMAND( pEntity, "Connect %s %d\n", isLocalIp( ip ) ? ServerLocalIp.c_str() : ServerInternetIp.c_str(), RANDOM_LONG( 1, 9999 ) );
        }
    }

    RETURN_META_VALUE( MRES_IGNORED, TRUE );
}
//-----------------------------------------------------------------------------
void EventLogDataBrowserSource::dbDrawCell (CDrawContext* context, const CRect& size, int32_t row, int32_t column, int32_t flags, CDataBrowser* browser)
{
	CColor cellColor (kWhiteCColor);
	bool oddRow = row % 2 != 0;
	if (oddRow)
	{
		cellColor = kBlackCColor;
		cellColor.alpha /= 16;
	}
	String cellValue;
	
	LogEvent& logEvent = mLogEvents.at (row);
	if (logEvent.count > 0)
	{
		if (String (LOG_ERR) == logEventSeverity[logEvent.id])
			cellColor = kRedCColor;
		else if (String (LOG_WARN) == logEventSeverity[logEvent.id])
			cellColor = kYellowCColor;
		else if (String (LOG_INFO) == logEventSeverity[logEvent.id])
			cellColor = kBlueCColor;
		
		if (oddRow)
			cellColor.alpha /= 2;
		else
			cellColor.alpha /= 3.;
	}

	context->setFillColor (cellColor);
	context->drawRect (size, kDrawFilled);

	switch (column)
	{
		case kType:
		{
			if (logEvent.count > 0)
				cellValue.printf (logEventSeverity[logEvent.id]);

			break;
		}
		case kDescription:
		{
			cellValue.assign (logEventDescriptions[row]);
			break;
		}
		case kCount:
		{
			cellValue.printf ("%d", logEvent.count);

			break;
		}
	}

	CRect cellSize (size);
	cellSize.inset (5, 0);
	context->setFont (kNormalFontSmall);
	context->setFontColor (kBlackCColor);
	context->drawString (cellValue.text8 (), cellSize, kLeftText);
}
Example #30
0
EW_ENTER


bool CallableWrapT<Stream>::getline(String& val)
{
	size_t i=0;

	for(;;i++)
	{
		if(i==buffer.size())
		{
			char buf[1024];
			int rc=value.recv(buf,1024);
			if(rc>0)
			{
				buffer.append(buf,rc);
			}
			else if(rc<=0)
			{
				if(buffer.empty())
				{
					return false;
				}

				val=buffer;
				buffer.clear();
				return true;
			}
		}

		if(buffer[i]=='\n') break;
	}

	if(i>0&&buffer[i-1]=='\r')
	{
		val.assign(&buffer[0],&buffer[i-1]);
	}
	else
	{
		val.assign(&buffer[0],&buffer[i]);
	}

	buffer.erase(buffer.begin(),buffer.begin()+i+1);
	return true;
}