CString
CMSWindowsClipboardAnyTextConverter::convertLinefeedToWin32(
				const CString& src) const
{
	// note -- we assume src is a valid UTF-8 string

	// count newlines in string
	UInt32 numNewlines = 0;
	UInt32 n = (UInt32)src.size();
	for (const char* scan = src.c_str(); n > 0; ++scan, --n) {
		if (*scan == '\n') {
			++numNewlines;
		}
	}
	if (numNewlines == 0) {
		return src;
	}

	// allocate new string
	CString dst;
	dst.reserve(src.size() + numNewlines);

	// copy string, converting newlines
	n = (UInt32)src.size();
	for (const char* scan = src.c_str(); n > 0; ++scan, --n) {
		if (scan[0] == '\n') {
			dst += '\r';
		}
		dst += scan[0];
	}

	return dst;
}
CString
CMSWindowsClipboardAnyTextConverter::convertLinefeedToUnix(
				const CString& src) const
{
	// count newlines in string
	UInt32 numNewlines = 0;
	UInt32 n = (UInt32)src.size();
	for (const char* scan = src.c_str(); n > 0; ++scan, --n) {
		if (scan[0] == '\r' && scan[1] == '\n') {
			++numNewlines;
		}
	}
	if (numNewlines == 0) {
		return src;
	}

	// allocate new string
	CString dst;
	dst.reserve(src.size());

	// copy string, converting newlines
	n = (UInt32)src.size();
	for (const char* scan = src.c_str(); n > 0; ++scan, --n) {
		if (scan[0] != '\r' || scan[1] != '\n') {
			dst += scan[0];
		}
	}

	return dst;
}
Example #3
0
bool
CKeyMap::parseKey(const CString& x, KeyID& key)
{
	// initialize tables
	initKeyNameMaps();

	// parse the key
	key = kKeyNone;
	if (s_nameToKeyMap->count(x) > 0) {
		key = s_nameToKeyMap->find(x)->second;
	}
	// XXX -- we're assuming ASCII encoding here
	else if (x.size() == 1) {
		if (!isgraph(x[0])) {
			// unknown key
			return false;
		}
		key = (KeyID)x[0];
	}
	else if (x.size() == 6 && x[0] == '\\' && x[1] == 'u') {
		// escaped unicode (\uXXXX where XXXX is a hex number)
		char* end;
		key = (KeyID)strtol(x.c_str() + 2, &end, 16);
		if (*end != '\0') {
			return false;
		}
	}
	else if (!x.empty()) {
		// unknown key
		return false;
	}

	return true;
}
Example #4
0
void CIRCSock::ParseISupport(const CMessage& Message) {
    const VCString vsParams = Message.GetParams();

    for (size_t i = 1; i < vsParams.size() - 1; ++i) {
        const CString& sParam = vsParams[i];
        CString sName = sParam.Token(0, false, "=");
        CString sValue = sParam.Token(1, true, "=");

        if (0 < sName.length() && ':' == sName[0]) {
            break;
        }

        m_mISupport[sName] = sValue;

        if (sName.Equals("PREFIX")) {
            CString sPrefixes = sValue.Token(1, false, ")");
            CString sPermModes = sValue.Token(0, false, ")");
            sPermModes.TrimLeft("(");

            if (!sPrefixes.empty() && sPermModes.size() == sPrefixes.size()) {
                m_sPerms = sPrefixes;
                m_sPermModes = sPermModes;
            }
        } else if (sName.Equals("CHANTYPES")) {
            m_pNetwork->SetChanPrefixes(sValue);
        } else if (sName.Equals("NICKLEN")) {
            unsigned int uMax = sValue.ToUInt();

            if (uMax) {
                m_uMaxNickLen = uMax;
            }
        } else if (sName.Equals("CHANMODES")) {
            if (!sValue.empty()) {
                m_mueChanModes.clear();

                for (unsigned int a = 0; a < 4; a++) {
                    CString sModes = sValue.Token(a, false, ",");

                    for (unsigned int b = 0; b < sModes.size(); b++) {
                        m_mueChanModes[sModes[b]] = (EChanModeArgs) a;
                    }
                }
            }
        } else if (sName.Equals("NAMESX")) {
            if (m_bNamesx)
                continue;
            m_bNamesx = true;
            PutIRC("PROTOCTL NAMESX");
        } else if (sName.Equals("UHNAMES")) {
            if (m_bUHNames)
                continue;
            m_bUHNames = true;
            PutIRC("PROTOCTL UHNAMES");
        }
    }
}
RageFileBasic *RageFileDriverDirect::Open( const CString &sPath_, int iMode, int &iError )
{
	CString sPath = sPath_;
	ASSERT( sPath.size() && sPath[0] == '/' );

	/* This partially resolves.  For example, if "abc/def" exists, and we're opening
	 * "ABC/DEF/GHI/jkl/mno", this will resolve it to "abc/def/GHI/jkl/mno"; we'll
	 * create the missing parts below. */
	FDB->ResolvePath( sPath );

	if( iMode & RageFile::WRITE )
	{
		const CString dir = Dirname(sPath);
		if( this->GetFileType(dir) != RageFileManager::TYPE_DIR )
			CreateDirectories( m_sRoot + dir );
	}

	RageFileObjDirect *ret = this->CreateInternal( m_sRoot + sPath );

	if( ret->OpenInternal( m_sRoot + sPath, iMode, iError) )
		return ret;

	SAFE_DELETE( ret );
	return NULL;
}
Example #6
0
void
CServerProxy::onClipboardChanged(ClipboardID id, const IClipboard* clipboard)
{
    CString data = IClipboard::marshall(clipboard);
    LOG((CLOG_DEBUG1 "sending clipboard %d seqnum=%d, size=%d", id, m_seqNum, data.size()));
    CProtocolUtil::writef(m_stream, kMsgDClipboard, id, m_seqNum, &data);
}
Example #7
0
CString
CKeyMap::formatKey(KeyID key, KeyModifierMask mask)
{
	// initialize tables
	initKeyNameMaps();

	CString x;
	for (SInt32 i = 0; i < kKeyModifierNumBits; ++i) {
		KeyModifierMask mod = (1u << i);
		if ((mask & mod) != 0 && s_modifierToNameMap->count(mod) > 0) {
			x += s_modifierToNameMap->find(mod)->second;
			x += "+";
		}
	}
	if (key != kKeyNone) {
		if (s_keyToNameMap->count(key) > 0) {
			x += s_keyToNameMap->find(key)->second;
		}
		// XXX -- we're assuming ASCII here
		else if (key >= 33 && key < 127) {
			x += (char)key;
		}
		else {
			x += CStringUtil::print("\\u%04x", key);
		}
	}
	else if (!x.empty()) {
		// remove trailing '+'
		x.erase(x.size() - 1);
	}
	return x;
}
Example #8
0
bool getline(CString &_str, CString &line){
  if(_str.size()==0)  return false;
  CString::size_type pLeft=0, pRight = _str.find('\n');
  line = _str.substr( pLeft, pRight );
  _str = _str.erase(0,pRight+1);
  return true;
};
// Variant value must be released with NPReleaseVariantValue()
void coerceValueToNPVariantStringType (KJS::ExecState *exec, const KJS::Value &value, NPVariant *result)
{
    UString ustring = value.toString(exec);
    CString cstring = ustring.UTF8String();
    NPString string = { (const NPUTF8 *)cstring.c_str(), cstring.size() };
    NPN_InitializeVariantWithStringCopy (result, &string);
}
Example #10
0
void TextBanner::LoadFromString( 
	CString sDisplayTitle, CString sTranslitTitle, 
	CString sDisplaySubTitle, CString sTranslitSubTitle, 
	CString sDisplayArtist, CString sTranslitArtist )
{
	Init();

	bool bTwoLines = sDisplaySubTitle.size() == 0;

	if( bTwoLines )
	{
		m_textTitle.Command( TWO_LINES_TITLE_COMMAND );
		m_textSubTitle.Command( TWO_LINES_SUBTITLE_COMMAND );
		m_textArtist.Command( TWO_LINES_ARTIST_COMMAND );
	}
	else
	{
		m_textTitle.Command( THREE_LINES_TITLE_COMMAND );
		m_textSubTitle.Command( THREE_LINES_SUBTITLE_COMMAND );
		m_textArtist.Command( THREE_LINES_ARTIST_COMMAND );
	}

	m_textTitle.SetText( sDisplayTitle, sTranslitTitle );
	m_textSubTitle.SetText( sDisplaySubTitle, sTranslitSubTitle );
	m_textArtist.SetText( sDisplayArtist, sTranslitArtist );
}
Example #11
0
bool
CConfig::isValidScreenName(const CString& name) const
{
	// name is valid if matches validname
	//  name      ::= [_A-Za-z0-9] | [_A-Za-z0-9][-_A-Za-z0-9]*[_A-Za-z0-9]
	//  domain    ::= . name
	//  validname ::= name domain*

	// check each dot separated part
	CString::size_type b = 0;
	for (;;) {
		// find end of part
		CString::size_type e = name.find('.', b);
		if (e == CString::npos) {
			e = name.size();
		}

		// part may not be empty
		if (e - b < 1) {
			return false;
		}

		// check first and last characters
		if (!(isalnum(name[b]) || name[b] == '_') ||
			!(isalnum(name[e - 1]) || name[e - 1] == '_')) {
			return false;
		}

		// check interior characters
		for (CString::size_type i = b; i < e; ++i) {
			if (!isalnum(name[i]) && name[i] != '_' && name[i] != '-') {
				return false;
			}
		}

		// next part
		if (e == name.size()) {
			// no more parts
			break;
		}
		b = e + 1;
	}

	return true;
}
// Variant value must be released with NPReleaseVariantValue()
void convertValueToNPVariant (KJS::ExecState *exec, const KJS::Value &value, NPVariant *result)
{
    Type type = value.type();

    if (type == StringType) {
        UString ustring = value.toString(exec);
        CString cstring = ustring.UTF8String();
        NPString string = { (const NPUTF8 *)cstring.c_str(), cstring.size() };
        NPN_InitializeVariantWithStringCopy (result, &string );
    }
    else if (type == NumberType) {
        NPN_InitializeVariantWithDouble (result, value.toNumber(exec));
    }
    else if (type == BooleanType) {
        NPN_InitializeVariantWithBool (result, value.toBoolean(exec));
    }
    else if (type == UnspecifiedType) {
        NPN_InitializeVariantAsUndefined(result);
    }
    else if (type == NullType) {
        NPN_InitializeVariantAsNull(result);
    }
    else if (type == ObjectType) {
        KJS::ObjectImp *objectImp = static_cast<KJS::ObjectImp*>(value.imp());
        if (objectImp->classInfo() == &KJS::RuntimeObjectImp::info) {
            KJS::RuntimeObjectImp *imp = static_cast<KJS::RuntimeObjectImp *>(value.imp());
            CInstance *instance = static_cast<CInstance*>(imp->getInternalInstance());
            NPN_InitializeVariantWithObject (result, instance->getObject());
        }
        else {

            KJS::Interpreter *originInterpreter = exec->interpreter();
            const Bindings::RootObject *originExecutionContext = rootForInterpreter(originInterpreter);

            KJS::Interpreter *interpreter = 0;
            if (originInterpreter->isGlobalObject(value)) {
                interpreter = originInterpreter->interpreterForGlobalObject (value.imp());
            }

            if (!interpreter)
                interpreter = originInterpreter;

            const Bindings::RootObject *executionContext = rootForInterpreter(interpreter);
            if (!executionContext) {
                Bindings::RootObject *newExecutionContext = new KJS::Bindings::RootObject(0);
                newExecutionContext->setInterpreter (interpreter);
                executionContext = newExecutionContext;
            }

            NPObject *obj = (NPObject *)exec->interpreter()->createLanguageInstanceForValue (exec, Instance::CLanguage, value.toObject(exec), originExecutionContext, executionContext);
            NPN_InitializeVariantWithObject (result, obj);
            _NPN_ReleaseObject (obj);
        }
    }
    else
        NPN_InitializeVariantAsUndefined(result);
}
Example #13
0
bool
CKeyMap::parseModifiers(CString& x, KeyModifierMask& mask)
{
	// initialize tables
	initKeyNameMaps();

	mask = 0;
	CString::size_type tb = x.find_first_not_of(" \t", 0);
	while (tb != CString::npos) {
		// get next component
		CString::size_type te = x.find_first_of(" \t+)", tb);
		if (te == CString::npos) {
			te = x.size();
		}
		CString c = x.substr(tb, te - tb);
		if (c.empty()) {
			// missing component
			return false;
		}

		if (s_nameToModifierMap->count(c) > 0) {
			KeyModifierMask mod = s_nameToModifierMap->find(c)->second;
			if ((mask & mod) != 0) {
				// modifier appears twice
				return false;
			}
			mask |= mod;
		}
		else {
			// unknown string
			x.erase(0, tb);
			CString::size_type tb = x.find_first_not_of(" \t");
			CString::size_type te = x.find_last_not_of(" \t");
			if (tb == CString::npos) {
				x = "";
			}
			else {
				x = x.substr(tb, te - tb + 1);
			}
			return true;
		}

		// check for '+' or end of string
		tb = x.find_first_not_of(" \t", te);
		if (tb != CString::npos) {
			if (x[tb] != '+') {
				// expected '+'
				return false;
			}
			tb = x.find_first_not_of(" \t", tb + 1);
		}
	}

	// parsed the whole thing
	x = "";
	return true;
}
Example #14
0
CString Font::GetFontName( CString sFileName )
{
	CString sOrig = sFileName;

	CString sDir, sFName, sExt;
	splitpath( sFileName, sDir, sFName, sExt );
	sFileName = sFName;

	/* If it ends in an extension, remove it. */
	static Regex drop_ext( "\\....$" );
	if( drop_ext.Compare(sFileName) )
		sFileName.erase( sFileName.size()-4 );

	/* If it ends in a resolution spec, remove it. */
	CStringArray asMatch;
	static Regex ResSpec( "( \\(res [0-9]+x[0-9]+\\))$" );
	if( ResSpec.Compare(sFileName, asMatch) )
		sFileName.erase(sFileName.size()-asMatch[0].size());

	/* If it ends in a dimension spec, remove it. */
	static Regex DimSpec( "( [0-9]+x[0-9]+)$" );
	if( DimSpec.Compare(sFileName, asMatch) )
		sFileName.erase( sFileName.size()-asMatch[0].size() );

	/* If it ends in texture hints, remove them. */
	static Regex Hints( "( \\([^\\)]+\\))$" );
	if( Hints.Compare(sFileName, asMatch) )
		sFileName.erase( sFileName.size()-asMatch[0].size() );

	/* If it ends in a page name, remove it. */
	static Regex PageName("( \\[.+\\])$");
	if( PageName.Compare( sFileName, asMatch ) )
		sFileName.erase( sFileName.size()-asMatch[0].size() );

	TrimRight( sFileName );

	if( sFileName.empty() )
		RageException::Throw( "Can't parse font filename \"%s\"", sOrig.c_str() );

	sFileName.MakeLower();
	return sFileName;
}
Example #15
0
static bool GetMessageNameFromCommandName( const CString &sCommandName, CString &sMessageNameOut )
{
	if( sCommandName.Right(7) == "Message" )
	{
		sMessageNameOut = sCommandName.Left(sCommandName.size()-7);
		return true;
	}
	else
	{
		return false;
	}
}
Example #16
0
File: Chan.cpp Project: BtbN/znc
map<char, unsigned int> CChan::GetPermCounts() const {
    map<char, unsigned int> mRet;

    for (const auto& it : m_msNicks) {
        CString sPerms = it.second.GetPermStr();

        for (unsigned int p = 0; p < sPerms.size(); p++) {
            mRet[sPerms[p]]++;
        }
    }

    return mRet;
}
Example #17
0
// Variant value must be released with NPReleaseVariantValue()
void convertValueToNPVariant(ExecState *exec, JSValue *value, NPVariant *result)
{
    JSLock lock;
    
    JSType type = value->type();
    
    VOID_TO_NPVARIANT(*result);

    if (type == StringType) {
        UString ustring = value->toString(exec);
        CString cstring = ustring.UTF8String();
        NPString string = { (const NPUTF8 *)cstring.c_str(), static_cast<uint32_t>(cstring.size()) };
        NPN_InitializeVariantWithStringCopy(result, &string);
    } else if (type == NumberType) {
        DOUBLE_TO_NPVARIANT(value->toNumber(exec), *result);
    } else if (type == BooleanType) {
        BOOLEAN_TO_NPVARIANT(value->toBoolean(exec), *result);
    } else if (type == UnspecifiedType) {
        VOID_TO_NPVARIANT(*result);
    } else if (type == NullType) {
        NULL_TO_NPVARIANT(*result);
    } else if (type == ObjectType) {
        JSObject* object = static_cast<JSObject*>(value);
        if (object->classInfo() == &RuntimeObjectImp::info) {
            RuntimeObjectImp* imp = static_cast<RuntimeObjectImp *>(value);
            CInstance* instance = static_cast<CInstance*>(imp->getInternalInstance());
            if (instance) {
                NPObject* obj = instance->getObject();
                _NPN_RetainObject(obj);
                OBJECT_TO_NPVARIANT(obj, *result);
            }
        } else {
            Interpreter* originInterpreter = exec->dynamicInterpreter();
            RootObject* originRootObject = findRootObject(originInterpreter);

            Interpreter* interpreter = 0;
            if (originInterpreter->isGlobalObject(value)) {
                interpreter = originInterpreter->interpreterForGlobalObject(value);
            }

            if (!interpreter)
                interpreter = originInterpreter;

            RootObject* rootObject = findRootObject(interpreter);
            if (rootObject) {
                NPObject* npObject = _NPN_CreateScriptObject(0, object, originRootObject, rootObject);
                OBJECT_TO_NPVARIANT(npObject, *result);
            }
        }
    }
}
Example #18
0
void 
NetworkTests::sendMockData(void* eventTarget)
{
	// send first message (file size)
	CString size = intToString(kMockDataSize);
	size_t sizeLength = size.size();
	CFileChunker::CFileChunk* sizeMessage = new CFileChunker::CFileChunk(sizeLength + 2);
	char* chunkData = sizeMessage->m_chunk;

	chunkData[0] = kFileStart;
	memcpy(&chunkData[1], size.c_str(), sizeLength);
	chunkData[sizeLength + 1] = '\0';
	m_events.addEvent(CEvent(m_events.forIScreen().fileChunkSending(), eventTarget, sizeMessage));

	// send chunk messages with incrementing chunk size
	size_t lastSize = 0;
	size_t sentLength = 0;
	while (true) {
		size_t chunkSize = lastSize + kMockDataChunkIncrement;

		// make sure we don't read too much from the mock data.
		if (sentLength + chunkSize > kMockDataSize) {
			chunkSize = kMockDataSize - sentLength;
		}

		// first byte is the chunk mark, last is \0
		CFileChunker::CFileChunk* fileChunk = new CFileChunker::CFileChunk(chunkSize + 2);
		char* chunkData = fileChunk->m_chunk;

		chunkData[0] = kFileChunk;
		memcpy(&chunkData[1], &m_mockData[sentLength], chunkSize);
		chunkData[chunkSize + 1] = '\0';
		m_events.addEvent(CEvent(m_events.forIScreen().fileChunkSending(), eventTarget, fileChunk));

		sentLength += chunkSize;
		lastSize = chunkSize;

		if (sentLength == kMockDataSize) {
			break;
		}

	}
	
	// send last message
	CFileChunker::CFileChunk* transferFinished = new CFileChunker::CFileChunk(2);
	chunkData = transferFinished->m_chunk;

	chunkData[0] = kFileEnd;
	chunkData[1] = '\0';
	m_events.addEvent(CEvent(m_events.forIScreen().fileChunkSending(), eventTarget, transferFinished));
}
Example #19
0
map<char, unsigned int> CChan::GetPermCounts() const {
	map<char, unsigned int> mRet;

	map<CString,CNick>::const_iterator it;
	for (it = m_msNicks.begin(); it != m_msNicks.end(); ++it) {
		CString sPerms = it->second.GetPermStr();

		for (unsigned int p = 0; p < sPerms.size(); p++) {
			mRet[sPerms[p]]++;
		}
	}

	return mRet;
}
Example #20
0
void Actor::LoadFromNode( const CString& sDir, const XNode* pNode )
{
	// Load Name, if any.
	pNode->GetAttrValue( "Name", m_sName );


	float f;
	if( pNode->GetAttrValue( "BaseRotationXDegrees", f ) )	SetBaseRotationX( f );
	if( pNode->GetAttrValue( "BaseRotationYDegrees", f ) )	SetBaseRotationY( f );
	if( pNode->GetAttrValue( "BaseRotationZDegrees", f ) )	SetBaseRotationZ( f );
	if( pNode->GetAttrValue( "BaseZoomX", f ) )			SetBaseZoomX( f );
	if( pNode->GetAttrValue( "BaseZoomY", f ) )			SetBaseZoomY( f );
	if( pNode->GetAttrValue( "BaseZoomZ", f ) )			SetBaseZoomZ( f );


	//
	// Load commands
	//
	FOREACH_CONST_Attr( pNode, a )
	{
		CString sKeyName = a->m_sName; /* "OnCommand" */

		if( sKeyName.Right(7).CompareNoCase("Command") != 0 )
			continue; /* not a command */

		CString sValue = a->m_sValue;
		THEME->EvaluateString( sValue );
		apActorCommands apac( new ActorCommands( sValue ) );

		CString sCmdName;
		/* Special case: "Command=foo" -> "OnCommand=foo" */
		if( sKeyName.size() == 7 )
			sCmdName="On";
		else
			sCmdName = sKeyName.Left( sKeyName.size()-7 );
		AddCommand( sCmdName, apac );
	}
Example #21
0
CTblReader::CTblReader(istream &Stream, const char *pSectionName):
    m_Stream(Stream), m_bSectionFound(false), m_iLine(0), m_nPos(0), m_nNamePos(0)
{
    if(!pSectionName)
        m_bSectionFound = true;
    else
        m_strSection = pSectionName;
    
    while(m_Stream.good() && !m_bSectionFound)
    {
        /* Get line from file */
        CString strLine;
        getline(m_Stream, strLine);
        ++m_iLine;
        
        /* Hack: remove \r from the end of line */
        if(strLine.size() > 0 && strLine[strLine.size() - 1] == '\r')
            strLine.resize(strLine.size() - 1);
        
        /* Check if we found the section */
        if(strLine.size() > 0 && strLine[0] == '#' && !strLine.comparei(pSectionName, 1))
            m_bSectionFound = true;
    }
}
Example #22
0
void CHTTPSock::PrintPage(const CString& sPage) {
#ifdef HAVE_ZLIB
    if (m_bAcceptGzip && !SentHeader()) {
        char szBuf[4096];
        z_stream zStrm;
        int zStatus, zFlush = Z_NO_FLUSH;

        if (InitZlibStream(&zStrm, sPage.c_str())) {
            DEBUG("- Sending gzip-compressed.");
            AddHeader("Content-Encoding", "gzip");
            PrintHeader(0);  // we do not know the compressed data's length

            zStrm.avail_in = sPage.size();
            do {
                if (zStrm.avail_in == 0) {
                    zFlush = Z_FINISH;
                }

                zStrm.next_out = (Bytef*)szBuf;
                zStrm.avail_out = sizeof(szBuf);

                zStatus = deflate(&zStrm, zFlush);

                if ((zStatus == Z_OK || zStatus == Z_STREAM_END) &&
                    zStrm.avail_out < sizeof(szBuf)) {
                    Write(szBuf, sizeof(szBuf) - zStrm.avail_out);
                }
            } while (zStatus == Z_OK);

            Close(Csock::CLT_AFTERWRITE);
            deflateEnd(&zStrm);
            return;
        }

    }  // else: fall through
#endif
    if (!SentHeader()) {
        PrintHeader(sPage.length());
    } else {
        DEBUG("PrintPage(): Header was already sent");
    }

    Write(sPage);
    Close(Csock::CLT_AFTERWRITE);
}
Example #23
0
File: Modules.cpp Project: md-5/znc
void CModule::HandleHelpCommand(const CString& sLine) {
	CString sFilter = sLine.Token(1).AsLower();
	CString::size_type  iFilterLength = sFilter.size();
	CTable Table;
	map<CString, CModCommand>::const_iterator it;

	CModCommand::InitHelp(Table);
	for (it = m_mCommands.begin(); it != m_mCommands.end(); ++it) {
		CString sCmd = it->second.GetCommand().AsLower();
		if (sFilter.empty() || (sCmd.Equals(sFilter, true, iFilterLength)) || sCmd.WildCmp(sFilter)) {
			it->second.AddHelp(Table);
		}
	}
	if (Table.empty()) {
		PutModule("No matches for '" + sFilter + "'");
	} else {
		PutModule(Table);
	}
}
Example #24
0
void
CServerProxy::setClipboard()
{
    // parse
    ClipboardID id;
    UInt32 seqNum;
    CString data;
    CProtocolUtil::readf(m_stream, kMsgDClipboard + 4, &id, &seqNum, &data);
    LOG((CLOG_DEBUG "recv clipboard %d size=%d", id, data.size()));

    // validate
    if (id >= kClipboardEnd) {
        return;
    }

    // forward
    CClipboard clipboard;
    clipboard.unmarshall(data, 0);
    m_client->setClipboard(id, &clipboard);
}
Example #25
0
// Variant value must be released with NPReleaseVariantValue()
void convertValueToNPVariant(ExecState* exec, JSValue* value, NPVariant* result)
{
    JSLock lock(false);

    VOID_TO_NPVARIANT(*result);

    if (value->isString()) {
        UString ustring = value->toString(exec);
        CString cstring = ustring.UTF8String();
        NPString string = { (const NPUTF8*)cstring.c_str(), static_cast<uint32_t>(cstring.size()) };
        NPN_InitializeVariantWithStringCopy(result, &string);
    } else if (value->isNumber()) {
        DOUBLE_TO_NPVARIANT(value->toNumber(exec), *result);
    } else if (value->isBoolean()) {
        BOOLEAN_TO_NPVARIANT(value->toBoolean(exec), *result);
    } else if (value->isNull()) {
        NULL_TO_NPVARIANT(*result);
    } else if (value->isObject()) {
        JSObject* object = static_cast<JSObject*>(value);
        if (object->classInfo() == &RuntimeObjectImp::s_info) {
            RuntimeObjectImp* imp = static_cast<RuntimeObjectImp*>(value);
            CInstance* instance = static_cast<CInstance*>(imp->getInternalInstance());
            if (instance) {
                NPObject* obj = instance->getObject();
                _NPN_RetainObject(obj);
                OBJECT_TO_NPVARIANT(obj, *result);
            }
        } else {
            JSGlobalObject* globalObject = exec->dynamicGlobalObject();

            RootObject* rootObject = findRootObject(globalObject);
            if (rootObject) {
                NPObject* npObject = _NPN_CreateScriptObject(0, object, rootObject);
                OBJECT_TO_NPVARIANT(npObject, *result);
            }
        }
    }
}
Example #26
0
bool CIRCSock::OnModeMessage(CModeMessage& Message) {
    const CNick& Nick = Message.GetNick();
    CString sTarget = Message.GetTarget();
    CString sModes = Message.GetModes();

    CChan* pChan = m_pNetwork->FindChan(sTarget);
    if (pChan) {
        pChan->ModeChange(sModes, &Nick);

        if (pChan->IsDetached()) {
            return true;
        }
    } else if (sTarget == m_Nick.GetNick()) {
        CString sModeArg = sModes.Token(0);
        bool bAdd = true;
        /* no module call defined (yet?)
        		MODULECALL(OnRawUserMode(*pOpNick, *this, sModeArg, sArgs), m_pNetwork->GetUser(), nullptr, );
        */
        for (unsigned int a = 0; a < sModeArg.size(); a++) {
            const unsigned char& uMode = sModeArg[a];

            if (uMode == '+') {
                bAdd = true;
            } else if (uMode == '-') {
                bAdd = false;
            } else {
                if (bAdd) {
                    m_scUserModes.insert(uMode);
                } else {
                    m_scUserModes.erase(uMode);
                }
            }
        }
    }
    return false;
}
HANDLE
CMSWindowsClipboardAnyTextConverter::fromIClipboard(const CString& data) const
{
	// convert linefeeds and then convert to desired encoding
	CString text = doFromIClipboard(convertLinefeedToWin32(data));
	UInt32 size  = (UInt32)text.size();

	// copy to memory handle
	HGLOBAL gData = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, size);
	if (gData != NULL) {
		// get a pointer to the allocated memory
		char* dst = (char*)GlobalLock(gData);
		if (dst != NULL) {
			memcpy(dst, text.data(), size);
			GlobalUnlock(gData);
		}
		else {
			GlobalFree(gData);
			gData = NULL;
		}
	}

	return gData;
}
Example #28
0
bool CClient::PutClient(const CMessage& Message) {
    if (!m_bAwayNotify && Message.GetType() == CMessage::Type::Away) {
        return false;
    } else if (!m_bAccountNotify &&
               Message.GetType() == CMessage::Type::Account) {
        return false;
    }

    CMessage Msg(Message);

    const CIRCSock* pIRCSock = GetIRCSock();
    if (pIRCSock) {
        if (Msg.GetType() == CMessage::Type::Numeric) {
            unsigned int uCode = Msg.As<CNumericMessage>().GetCode();

            if (uCode == 352) {  // RPL_WHOREPLY
                if (!m_bNamesx && pIRCSock->HasNamesx()) {
                    // The server has NAMESX, but the client doesn't, so we need
                    // to remove extra prefixes
                    CString sNick = Msg.GetParam(6);
                    if (sNick.size() > 1 && pIRCSock->IsPermChar(sNick[1])) {
                        CString sNewNick = sNick;
                        size_t pos =
                            sNick.find_first_not_of(pIRCSock->GetPerms());
                        if (pos >= 2 && pos != CString::npos) {
                            sNewNick = sNick[0] + sNick.substr(pos);
                        }
                        Msg.SetParam(6, sNewNick);
                    }
                }
            } else if (uCode == 353) {  // RPL_NAMES
                if ((!m_bNamesx && pIRCSock->HasNamesx()) ||
                    (!m_bUHNames && pIRCSock->HasUHNames())) {
                    // The server has either UHNAMES or NAMESX, but the client
                    // is missing either or both
                    CString sNicks = Msg.GetParam(3);
                    VCString vsNicks;
                    sNicks.Split(" ", vsNicks, false);

                    for (CString& sNick : vsNicks) {
                        if (sNick.empty()) break;

                        if (!m_bNamesx && pIRCSock->HasNamesx() &&
                            pIRCSock->IsPermChar(sNick[0])) {
                            // The server has NAMESX, but the client doesn't, so
                            // we just use the first perm char
                            size_t pos =
                                sNick.find_first_not_of(pIRCSock->GetPerms());
                            if (pos >= 2 && pos != CString::npos) {
                                sNick = sNick[0] + sNick.substr(pos);
                            }
                        }

                        if (!m_bUHNames && pIRCSock->HasUHNames()) {
                            // The server has UHNAMES, but the client doesn't,
                            // so we strip away ident and host
                            sNick = sNick.Token(0, false, "!");
                        }
                    }

                    Msg.SetParam(
                        3, CString(" ").Join(vsNicks.begin(), vsNicks.end()));
                }
            }
        } else if (Msg.GetType() == CMessage::Type::Join) {
            if (!m_bExtendedJoin && pIRCSock->HasExtendedJoin()) {
                Msg.SetParams({Msg.As<CJoinMessage>().GetTarget()});
            }
        }
    }

    CString sLine = Msg.ToString(CMessage::ExcludeTags);

    // TODO: introduce a module hook that gives control over the tags that are
    // sent
    MCString mssTags;

    if (HasServerTime()) {
        CString sServerTime = Msg.GetTag("time");
        if (!sServerTime.empty()) {
            mssTags["time"] = sServerTime;
        } else {
            mssTags["time"] = CUtils::FormatServerTime(Msg.GetTime());
        }
    }

    if (HasBatch()) {
        CString sBatch = Msg.GetTag("batch");
        if (!sBatch.empty()) {
            mssTags["batch"] = sBatch;
        }
    }

    if (!mssTags.empty()) {
        CUtils::SetMessageTags(sLine, mssTags);
    }

    PutClient(sLine);
    return true;
}
Example #29
0
ssize_t CFile::Write(const CString & sData) {
	return Write(sData.data(), sData.size());
}
Example #30
0
CString CChan::GetModeArg(CString& sArgs) const {
	CString sRet = sArgs.substr(0, sArgs.find(' '));
	sArgs = (sRet.size() < sArgs.size()) ? sArgs.substr(sRet.size() +1) : "";
	return sRet;
}