Example #1
0
BString
DNSTools::ConvertToDNSName(const BString& string)
{
	BString outString = string;
	int32 dot, lastDot, diff;

	dot = string.FindFirst(".");
	if (dot != B_ERROR) {
		outString.Prepend((char*)&dot, 1);
		// because we prepend a char add 1 more
		lastDot = dot + 1;

		while (true) {
			dot = outString.FindFirst(".", lastDot + 1);
			if (dot == B_ERROR)
				break;

			// set a counts to the dot
			diff =  dot - 1 - lastDot;
			outString[lastDot] = (char)diff;
			lastDot = dot;
		}
	} else
		lastDot = 0;

	diff = outString.CountChars() - 1 - lastDot;
	outString[lastDot] = (char)diff;

	return outString;
}
Example #2
0
/*!
	\brief Get the FontStyle object for the name given
	\param style Name of the style to be obtained
	\return The FontStyle object or NULL if none was found.

	The object returned belongs to the family and must not be deleted.
*/
FontStyle*
FontFamily::GetStyle(const char *name) const
{
    if (name == NULL || !name[0])
        return NULL;

    FontStyle* style = _FindStyle(name);
    if (style != NULL)
        return style;

    // try alternative names

    if (!strcmp(name, "Roman") || !strcmp(name, "Regular")
            || !strcmp(name, "Book")) {
        style = _FindStyle("Roman");
        if (style == NULL) {
            style = _FindStyle("Regular");
            if (style == NULL)
                style = _FindStyle("Book");
        }
        return style;
    }

    BString alternative = name;
    if (alternative.FindFirst("Italic") >= 0) {
        alternative.ReplaceFirst("Italic", "Oblique");
        return _FindStyle(alternative.String());
    }
    if (alternative.FindFirst("Oblique") >= 0) {
        alternative.ReplaceFirst("Oblique", "Italic");
        return _FindStyle(alternative.String());
    }

    return NULL;
}
Example #3
0
bool
SftpClient::PutFile(const string& local, const string& remote, ftp_mode mode)
{
	bool rc = false;
	int len;
	//XXX: handle mode ?
	BString cmd("put");
	cmd << " " << local.c_str() << " " << remote.c_str() << "\n";
	SendCommand(cmd.String());
	BString reply;

	if ((len = ReadReply(&reply)) < 0) {
		fprintf(stderr, _GetReadText(), len);
		return false;
	}
	fprintf(stderr, _GetReplyText(), reply.String());
	if (reply.FindFirst("Uploading") < 0)
		return false;

	if ((len = ReadReply(&reply)) < 0) {
		fprintf(stderr, _GetReadText(), len);
		return false;
	}
	fprintf(stderr, _GetReplyText(), reply.String());
	if (reply.FindFirst("sftp>") < 0)
		return false;

	rc = true;
	return rc;
}
Example #4
0
bool
SftpClient::Chmod(const string& path, const string& mod)
{
	bool rc = false;
	int len;
	//XXX: handle mode ?
	BString cmd("chmod");
	cmd << " " << mod.c_str() << " " << path.c_str() << "\n";
	SendCommand(cmd.String());
	BString reply;

	if ((len = ReadReply(&reply)) < 0) {
		fprintf(stderr, _GetReadText(), len);
		return false;
	}
	fprintf(stderr, _GetReplyText(), reply.String());
	if (reply.FindFirst("Changing") < 0)
		return false;

	if ((len = ReadReply(&reply)) < 0) {
		fprintf(stderr, _GetReadText(), len);
		return false;
	}
	fprintf(stderr, _GetReplyText(), reply.String());
	if (reply.FindFirst("sftp>") < 0)
		return false;

	rc = true;
	return rc;
}
Example #5
0
void
BHttpForm::_ExtractNameValuePair(const BString& formString, int32* index)
{
	// Look for a name=value pair
	int16 firstAmpersand = formString.FindFirst("&", *index);
	int16 firstEqual = formString.FindFirst("=", *index);

	BString name;
	BString value;

	if (firstAmpersand == -1) {
		if (firstEqual != -1) {
			formString.CopyInto(name, *index, firstEqual - *index);
			formString.CopyInto(value, firstEqual + 1,
				formString.Length() - firstEqual - 1);
		} else
			formString.CopyInto(value, *index,
				formString.Length() - *index);

		*index = formString.Length() + 1;
	} else {
		if (firstEqual != -1 && firstEqual < firstAmpersand) {
			formString.CopyInto(name, *index, firstEqual - *index);
			formString.CopyInto(value, firstEqual + 1,
				firstAmpersand - firstEqual - 1);
		} else
			formString.CopyInto(value, *index, firstAmpersand - *index);

		*index = firstAmpersand + 1;
	}

	AddString(name, value);
}
Example #6
0
platform_t
DetectPlatform(void)
{
	platform_t type = PLATFORM_R5;
	
	// While, yes, there is a uname() function in sys/utsname.h, we use spawn a shell
	// so that we can easily avoid the build mess of BONE vs netserver.
	// Use ShellHelper class to avoid problems with popen() causing hangs. :/
	ShellHelper shell;
	BString osname;
	
	shell << "uname" << "-o";
	shell.RunInPipe(osname, false);
	
	if (osname.FindFirst("Haiku\n") == 0)
	{
		BPath libpath;
		find_directory(B_BEOS_LIB_DIRECTORY,&libpath);
		libpath.Append("libsupc++.so");
		type =  BEntry(libpath.Path()).Exists() ? PLATFORM_HAIKU_GCC4 : PLATFORM_HAIKU;
	}
	else if (osname.FindFirst("Zeta\n") == 0)
		type = PLATFORM_ZETA;
	else
		printf("Detected platform from uname: %s\n", osname.String());
	
	return type;
}
Example #7
0
bool
SftpClient::Connect(const string& server, const string& login, 
	const string& passwd)
{
	bool rc = false;
	BString cmd("sftp ");
	BString host(server.c_str());
	BString port;
	if (host.FindFirst(':'))
		host.MoveInto(port, host.FindFirst(':'), host.Length());
	port.RemoveAll(":");
	if (port.Length())
		cmd << "-oPort=" << port << " ";
	cmd << login.c_str();
	cmd << "@" << host.String();
	printf("COMMAND: '%s'\n", cmd.String());
	SetCommandLine(cmd.String());
	rc = SpawningUploadClient::Connect(server, login, passwd);
	BString reply;
	ssize_t len;
	
	if ((len = ReadReply(&reply)) < 0) {
		fprintf(stderr, _GetLongReadText(), len);
		return false;
	}
	fprintf(stderr, _GetReplyText(), reply.String());
	if (reply.FindFirst("Connecting to ") != 0)
		return false;
	
	if ((len = ReadReply(&reply)) < 0) {
		fprintf(stderr, _GetLongReadText(), len);
		return false;
	}
	fprintf(stderr, _GetReplyText(), reply.String());
	if (reply.FindFirst(/*[pP]*/"assword:") < 0)
		return false;
	
	write(OutputPipe(), passwd.c_str(), strlen(passwd.c_str()));
	write(OutputPipe(), "\n", 1);
	
	if ((len = ReadReply(&reply)) < 0) {
		fprintf(stderr, _GetLongReadText(), len);
		return false;
	}
	fprintf(stderr, _GetReplyText(), reply.String());
	if (reply != "\n")
		return false;
	
	if ((len = ReadReply(&reply)) < 0) {
		fprintf(stderr, _GetLongReadText(), len);
		return false;
	}
	fprintf(stderr, _GetReplyText(), reply.String());
	if (reply.FindFirst("sftp>") < 0)
		return false;
	return rc;
}
Example #8
0
// --------------------------------------------------------------------------------------------- rgetcomment -
BString rgetcomment(BString str)
{
 BString tmp;
 if (str.FindFirst('#')>=0)
 {
  str.CopyInto(tmp,0,str.FindFirst('#'));
 } else tmp=str;
 return tmp;
}
status_t FortuneAccess::GetFortune(BString *target)
{
	if(!target)
		return B_BAD_VALUE;
	
	if(fRefList.CountItems()<1)
		return B_ERROR;
	
	int32 index = int32(float(rand()) / RAND_MAX * fRefList.CountItems());
	
	entry_ref *ref = (entry_ref*)fRefList.ItemAt(index);
	
	BFile file(ref,B_READ_ONLY);
	if(file.InitCheck()!=B_OK)
		return file.InitCheck();
	
	fLastFile = ref->name;
	
	off_t size;
	file.GetSize(&size);
	
	if(size<1)
		return B_ERROR;
	
	BString data;
	
	char *buffer = data.LockBuffer(size + 10);
	file.Read(buffer,size);
	data.UnlockBuffer();
	buffer = NULL;
	
	// We can't depend on a .dat file, so calculate the number of entries manually
	int32 entrycount = 0;
	int32 entrystart = 0;
	
	do
	{
		entrystart = data.FindFirst("%\n",entrystart + 1);
		entrycount++;
	} while(entrystart>0);
	
	int32 entry = int32(float(rand()) / RAND_MAX * (entrycount-1));

	entrystart = 0;
	for(int32 i=0; i<entry; i++)
		entrystart = data.FindFirst("%\n",entrystart + 1);
		
	BString entrydata;
	entrydata = data.String() + entrystart + 2;
	int32 entrylength = entrydata.FindFirst("%\n");
	if(entrylength>0)
		entrydata.Truncate(entrylength);
	
	*target = entrydata;
	return B_OK;
}
Example #10
0
bool
StringCompare(const BString &from, const BString &to, const char *mode,
			const bool &match_case)
{
	if (!mode)
	{
		debugger("NULL mode in StringCompare");
		return false;
	}
	
	if (strcmp(mode,"is") == 0)
		if (match_case)
			return from.Compare(to) == 0;
		else
			return from.ICompare(to) == 0;
	else if (strcmp(mode,"is not") == 0)
		if (match_case)
			return from.Compare(to) != 0;
		else
			return from.ICompare(to) != 0;
	else if (strcmp(mode,"contains") == 0)
		if (match_case)
			return to.FindFirst(from) >= 0;
		else
			return to.IFindFirst(from) >= 0;
	else if (strcmp(mode,"does not contain") == 0)
		if (match_case)
			return to.FindFirst(from) < 0;
		else
			return to.IFindFirst(from) < 0;
	else if (strcmp(mode,"starts with") == 0)
		if (match_case)
			return to.FindFirst(from) == 0;
		else
			return to.IFindFirst(from) == 0;
	else if (strcmp(mode,"ends with") == 0)
	{
		int32 pos;
		if (match_case)
			pos = to.FindLast(from);
		else
			pos = to.IFindLast(from);
		
		return (to.CountChars() - from.CountChars() == pos);
	}	
	
	return false;
}
Example #11
0
/**
 *	@brief	Reads items array in menu design resource.
 *	@return	trigger character
 */
char BeSkinView::parseMenuItemTrigger(
	const char* sourceLabel,	///< source label string
	BString& outLabel			///< OUTPUT. label string without '&' prefix character.
)
{
	char trigger = 0;
	outLabel = sourceLabel;
	int32 find = 0;
	
	while (true)
	{
		find = outLabel.FindFirst('~', find);
		if (B_ERROR == find)
		{
			break;
		}
		outLabel.Remove(find, 1);
		if (outLabel[find] != '~')
		{
			if (0 == trigger)
			{
				trigger = tolower(outLabel[find]);
			}
		}
		else
		{
			find++;
		}
	}
	
	return trigger;
}
Example #12
0
RuleFilter::RuleFilter(MailProtocol& protocol, AddonSettings* addonSettings)
	:
	MailFilter(protocol, addonSettings)
{
	const BMessage* settings = &addonSettings->Settings();
	// attribute is adapted to our "capitalize-each-word-in-the-header" policy
	settings->FindString("attribute", &fAttribute);
	fAttribute.CapitalizeEachWord();

	BString regex;
	settings->FindString("regex", &regex);
	
	int32 index = regex.FindFirst("REGEX:");
	if (index == B_ERROR || index > 0)
		EscapeRegexTokens(regex);
	else
		regex.RemoveFirst("REGEX:");
		
	fMatcher.SetPattern(regex, false);
	
	settings->FindString("argument",&fArg);
	settings->FindInt32("do_what",(long *)&fDoWhat);
	if (fDoWhat == Z_SET_REPLY)
		settings->FindInt32("argument", &fReplyAccount);
}
Example #13
0
void
BUrl::_ExtractRequestAndFragment(const BString& urlString, int16* origin)
{
	// Extract request field from URL
	if (urlString.ByteAt(*origin) == '?') {
		(*origin)++;
		int16 requestEnd = urlString.FindFirst('#', *origin);

		fHasRequest = true;

		if (requestEnd == -1) {
			urlString.CopyInto(fRequest, *origin, urlString.Length() - *origin);
			return;
		} else {
			urlString.CopyInto(fRequest, *origin, requestEnd - *origin);
			*origin = requestEnd;
		}
	}

	// Extract fragment field if needed
	if (urlString.ByteAt(*origin) == '#') {
		(*origin)++;
		urlString.CopyInto(fFragment, *origin, urlString.Length() - *origin);

		fHasFragment = true;
	}
}
Example #14
0
bool
ThemeManager::ThemeIsReadOnly(int32 id)
{
	FENTRY;
	status_t err;
	BString s;
	BMessage *theme;
	
	if (id < 0)
		return true;
	
	theme = (BMessage *)fThemeList.ItemAt(id);
	if (!theme)
		return true;
	// imported themes are always RO for now
	if (theme->FindString(Z_THEME_IMPORTER, &s) >= B_OK)
		return true;
	
	err = ThemeLocation(id, s);
	if (err)
		return true;
	if (s.FindFirst("/boot/beos") >= 0)
		return true;
	return false;
}
Example #15
0
void
KeyboardLayout::_Trim(BString& string, bool stripComments)
{
	// Strip leading spaces
	int32 i = 0;
	while (isspace(string[i])) {
		i++;
	}
	if (i > 0)
		string.Remove(0, i);

	// Remove comments
	if (stripComments) {
		i = string.FindFirst('#');
		if (i >= 0)
			string.Truncate(i);
	}

	// Strip trailing spaces
	i = string.Length() - 1;
	while (i > 0 && isspace(string[i])) {
		i--;
	}
	string.Truncate(i + 1);
}
Example #16
0
void
MainWindow::_DisplayPartitionError(BString _message,
	const BPartition* partition, status_t error) const
{
	char message[1024];

	if (partition && _message.FindFirst("%s") >= 0) {
		BString name;
		name << "\"" << partition->ContentName() << "\"";
		snprintf(message, sizeof(message), _message.String(), name.String());
	} else {
		_message.ReplaceAll("%s", "");
		snprintf(message, sizeof(message), _message.String());
	}

	if (error < B_OK) {
		BString helper = message;
		const char* errorString
			= B_TRANSLATE_COMMENT("Error: ", "in any error alert");
		snprintf(message, sizeof(message), "%s\n\n%s%s", helper.String(),
			errorString, strerror(error));
	}

	BAlert* alert = new BAlert("error", message, B_TRANSLATE("OK"), NULL, NULL,
		B_WIDTH_FROM_WIDEST, error < B_OK ? B_STOP_ALERT : B_INFO_ALERT);
	alert->Go(NULL);
}
Example #17
0
bool DataFile::LoadDataFile(BString filename)
////////////////////////////////////////////////////////////////////////
{
	BString line;
	int	sign;		// itt van az '=' jel
	int len;
	BString key;
	BString value;

	if (Read(filename))
	{
		while (GetLine(line))
		{
			RemoveComment(line);
			sign = line.FindFirst('=');
			if (sign >= 1)
			{
				len = line.Length();
				line.CopyInto(key, 0, sign);
				line.CopyInto(value, sign+1, len-sign-1);
				Trim(key);
				Trim(value);
				AddEntry(key, value);
			}				
		}
	}
	else
		return false;
		
	return true;
}
Example #18
0
void MainWindow::OpenTorrentDownloadFolder()
{
	
	entry_ref ref;
	
	
	if( const DownloadItem* item = fDownloadView->ItemSelected() )
	{
		//
		// Get the torrent object.
		//	
		const TorrentObject* torrent = item->GetTorrentObject();

	
		//
		// Build the download path.
		//
		BString DownloadPath = torrent->DownloadFolder();
		
		//
		//
		//
		if( torrent->IsFolder() )
		{
			BString FolderName = torrent->Info()->files[ 0 ].name;
			
			FolderName.Truncate(FolderName.FindFirst('/'));
			
			DownloadPath << "/" << FolderName;
		}
	
		status_t status = get_ref_for_path(DownloadPath.String(), &ref);
		if (status == B_OK)
			status = be_roster->Launch(&ref);
	}

/*const char* kTrackerSignature = "application/x-vnd.Be-TRAK";

	if( const DownloadItem* item = fDownloadView->ItemSelected() )
	{
		const TorrentObject* torrent = item->GetTorrentObject();

			
		entry_ref ref;
		status_t status = get_ref_for_path(torrent->GetDownloadDir(), &ref);
		

		
		if( status == B_OK )
		{
			BMessage message(B_REFS_RECEIVED);
			message.AddRef("refs", &ref);

			BMessenger messenger(kTrackerSignature);
			messenger.SendMessage(&message);
	
		}
	}
*/
}
Example #19
0
bool
CommandLineUserInterface::_RegisterCommand(const BString& name,
	CliCommand* command)
{
	BReference<CliCommand> commandReference(command, true);
	if (name.IsEmpty() || command == NULL)
		return false;

	BString nextName;
	int32 startIndex = 0;
	int32 spaceIndex;
	do {
		spaceIndex = name.FindFirst(' ', startIndex);
		if (spaceIndex == B_ERROR)
			spaceIndex = name.Length();
		name.CopyInto(nextName, startIndex, spaceIndex - startIndex);

		CommandEntry* entry = new(std::nothrow) CommandEntry(nextName,
			command);
		if (entry == NULL || !fCommands.AddItem(entry)) {
			delete entry;
			return false;
		}
		startIndex = spaceIndex + 1;
	} while (startIndex < name.Length());

	return true;
}
Example #20
0
bool
AutoConfigView::GetBasicAccountInfo(account_info &info)
{
	status_t status = B_OK;

	BString inboundProtocolName = "";
	BMenuItem* item = fInProtocolsField->Menu()->FindMarked();
	if (item) {
		inboundProtocolName = item->Label();
		item->Message()->FindRef("protocol", &(info.inboundProtocol));
	}
	else
		status = B_ERROR;

	if (inboundProtocolName.FindFirst("IMAP") >= 0)
		info.inboundType = IMAP;
	else
		info.inboundType = POP;

	info.outboundProtocol = fSMTPAddOnRef;
	info.name = fNameView->Text();
	info.accountName = fAccountNameView->Text();
	info.email = fEmailView->Text();
	info.loginName = fLoginNameView->Text();
	info.password = fPasswordView->Text();

	return status;
}
void TranslateEntities(BString &str)
{
	// pointeur vers un caractère '&'
	int l_Pointer=-1;
	
	while ((l_Pointer = str.FindFirst('&',l_Pointer+1)) >= 0)
	{
		// recherche du ';' de fin
		unsigned int l_Pointer2;
		
		l_Pointer2 = str.FindFirst(';',l_Pointer);
		
		if (l_Pointer2 < 0)
			return;
			// s'il n'y a plus de ';' dans la chaîne, on peut arréter de chercher des '&', c'est fini
		
		BString l_Entity(str.String()+l_Pointer+1,l_Pointer2-l_Pointer-1);
		
		// recherche de l'entité dans la liste déclarée ci-dessus
		// on procède par dichotomie pour trouver la chaîne
		unsigned int l_Start = 0;
		unsigned int l_End = c_NumEntities;
		unsigned int l_StringIndex;

		while(l_Start != l_End)
		{
			// on regarde ce qu'il y a au milieu
			l_StringIndex = (l_End+l_Start)/2;
			
			int l_Comp = l_Entity.Compare(s_EntityNames[l_StringIndex]);
		
			if (l_Comp == 0)
			{
				l_Entity.Prepend("&");
				l_Entity.Append(";");
				str.Replace(l_Entity.String(),s_EntityCharacters[l_StringIndex],1,l_Pointer);
				break;	
			}			
			if (l_Comp>0)
				// la chaîne à chercher est après
				l_Start = ++l_StringIndex;
			else
				// la chaîne à chercher est avant
				l_End = l_StringIndex;
		}		
	}
}
Example #22
0
void Parser::UpdateStatementType(Statement* statement)
{
	if (statement->GetType() != Statement::kUnknown) return;
	
	BString* keyword = statement->GetKeyword();
	Statement::Type type;
	if (keyword->FindFirst("Default") == 0) {
		type = Statement::kDefault;
		keyword->RemoveFirst("Default");
	} else if (keyword->FindFirst("Param") == 0) {
		type = Statement::kParam;
		keyword->RemoveFirst("Param");
	} else {
		type = Statement::kValue;
	}
	statement->SetType(type);
}
Example #23
0
void
BF_GUI_Text::Find(char *pc_Sample, uint32 i_StartLine, uint32 i_StartCol)
{
	uint32	iColumn = i_StartCol;
	BString *poString;
	char cSample[256];
	bool bFound = false;
	BF_GUI_MessageBox *po_Message;

	ClearMatch();
	if (pc_Sample == NULL) 
	{
		FromUtf8(poMatch->String(),cSample);
	}
	else
	{
		FromUtf8(pc_Sample,cSample);
	}

	for(int32 i = i_StartLine; i < ploString->CountItems();i++)
	{
		poString = (BString *) ploString->ItemAt(i);
		if (poString->FindFirst(cSample,iColumn) != B_ERROR)
		{
			iMatchLine = i;
			bFound = true;
			break;
		};
		iColumn = 0;
	};
	if (bFound)
	{
		if (pc_Sample != NULL)
		{
			if (poMatch != NULL) delete(poMatch);
			poMatch = new BString(pc_Sample);
		};
		bDrawSel = true;
		BRect oRect = Bounds();
		float y = iMatchLine * poSysSetup->oFontNode.fHeight;
		ScrollTo(oRect.left,y);
		iStartSel = iColumn;
		DrawPage();
	}
	else
	{
		bDrawSel = false;
		if (i_StartLine)
		{
			po_Message = new BF_GUI_MessageBox(BRect(30,30,300,150),"Error","Not more samles found!",Parent(),"Ok");
		}
		else
		{
			po_Message = new BF_GUI_MessageBox(BRect(30,30,300,150),"Error","The sample is not found in this file!",Parent(),"Ok");
		}
		Parent()->AddChild(po_Message);
	};
};
Example #24
0
_EXPORT void
extract_address(BString &address)
{
	const char *string = address.String();
	int32 first;

	// first, remove all quoted text
	
	if ((first = address.FindFirst('"')) >= 0) {
		int32 last = first + 1;
		while (string[last] && string[last] != '"')
			last++;

		if (string[last] == '"')
			address.Remove(first, last + 1 - first);
	}

	// try to extract the address now

	if ((first = address.FindFirst('<')) >= 0) {
		// the world likes us and we can just get the address the easy way...
		int32 last = address.FindFirst('>');
		if (last >= 0) {
			address.Truncate(last);
			address.Remove(0, first + 1);

			return;
		}
	}

	// then, see if there is anything in parenthesis to throw away

	if ((first = address.FindFirst('(')) >= 0) {
		int32 last = first + 1;
		while (string[last] && string[last] != ')')
			last++;

		if (string[last] == ')')
			address.Remove(first, last + 1 - first);
	}

	// now, there shouldn't be much else left

	trim_white_space(address);
}
Example #25
0
void DataFile::RemoveComment(BString &result)
////////////////////////////////////////////////////////////////////////
{
	int len = result.Length();
	int x = result.FindFirst('#');

	if (x>=0)
		result.Remove(x, len-x);
}
Example #26
0
// Note: this only works for local remote moves, cross filesystem moves
// will not work
bool
SftpClient::MoveFile(const string& oldPath, const string& newPath)
{
	bool rc = false;
	int len;
	
	// sftpd can't rename to an existing file...
	BString cmd("rm");
	cmd << " " << newPath.c_str() << "\n";
	fprintf(stderr, "CMD: '%s'\n", cmd.String());
	SendCommand(cmd.String());
	BString reply;

	if ((len = ReadReply(&reply)) < 0) {
		fprintf(stderr, _GetReadText(), len);
		return false;
	}
	fprintf(stderr, _GetReplyText(), reply.String());
	// we don't care if it worked or not.
	//if (reply.FindFirst("Removing") != 0 && reply.FindFirst("Couldn't") )
	//	return false;

	if ((len = ReadReply(&reply)) < 0) {
		fprintf(stderr, _GetReadText(), len);
		return false;
	}
	fprintf(stderr, _GetReplyText(), reply.String());
	if (reply.FindFirst("sftp>") < 0)
		return false;

	cmd = "rename";
	cmd << " " << oldPath.c_str() << " " << newPath.c_str() << "\n";
	SendCommand(cmd.String());
	if ((len = ReadReply(&reply)) < 0) {
		fprintf(stderr, _GetReadText(), len);
		return false;
	}
	fprintf(stderr, _GetReplyText(), reply.String());
	if (reply.FindFirst("sftp>") < 0)
		return false;
	rc = true;
	return rc;
}
Example #27
0
status_t
ThemeManager::SaveTheme(int32 id, bool excl)
{
	FENTRY;
	status_t err;
	BString name, fname;
	BPath path;
	BDirectory dir;
	BDirectory tdir;
	BFile tfile;
	BMessage names;
	BString location;
	BMessage *theme;
	theme = ThemeAt(id);
	if (!theme)
		return EINVAL;
	err = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
	if (err)	return err;
	path.Append(Z_THEMES_FOLDER_NAME);
	err = dir.SetTo(path.Path());
	if (err)	return err;
	err = ThemeName(id, name);
	if (err)	return err;
	fname = name;
	NormalizeThemeFolderName(fname);

	err = ThemeLocation(id, location);
	if (!err) {
		if (location.FindFirst("/boot/beos") >= 0) {
			PRINT(("trying to save theme '%s' to system dir!\n", name.String()));
			return B_PERMISSION_DENIED;
		}
	}
	path.Append(fname.String());
	err = theme->ReplaceString(Z_THEME_LOCATION, path.Path());
	if (err)
		err = theme->AddString(Z_THEME_LOCATION, path.Path());
	
	if (dir.CreateDirectory(fname.String(), NULL) < B_OK) {
		if (excl)
			return B_FILE_EXISTS;
	}
	err = tdir.SetTo(&dir, fname.String());
	if (err)	return err;
	err = tdir.CreateFile(Z_THEME_FILE_NAME, &tfile);
	if (err)	return err;
	
	BMessage tosave(*theme);
	err = tosave.RemoveName(Z_THEME_LOCATION);
	err = GetNames(names);
	
	err = DumpMessageToStream(&tosave, tfile, 0, &names);
	if (err)	return err;
	return B_OK;
}
Example #28
0
	virtual status_t HandleEntry(BPackageEntry* entry)
	{
		BString path = MakePath(entry);
		if (path.FindFirst("data/deskbar/menu") == 0
			&& entry->SymlinkPath() != NULL) {
			printf("found deskbar entry: %s -> %s\n", path.String(),
				entry->SymlinkPath());
			fDeskbarLinks.Add(DeskbarLink(path, entry->SymlinkPath()));
		}
		return B_OK;
	}
Example #29
0
File: MSN.cpp Project: ModeenF/Caya
BString
MSNP::FindSHA1D(string msnobject)
{
	BString str = BString(msnobject.c_str());
	BString ret;
	int32 index = str.FindFirst("SHA1D=");
	index += 7;
	str.CopyInto(ret, index, (int32) 27);
	ret.RemoveAll("/");
	return ret.String();
}
Example #30
0
void
THeaderView::InitEmailCompletion()
{
	// get boot volume
	BVolume volume;
	BVolumeRoster().GetBootVolume(&volume);

	BQuery query;
	query.SetVolume(&volume);
	query.SetPredicate("META:email=**");
		// Due to R5 BFS bugs, you need two stars, META:email=** for the query.
		// META:email="*" will just return one entry and stop, same with
		// META:email=* and a few other variations.  Grumble.
	query.Fetch();
	entry_ref ref;

	while (query.GetNextRef (&ref) == B_OK) {
		BNode file;
		if (file.SetTo(&ref) == B_OK) {
			// Add the e-mail address as an auto-complete string.
			BString email;
			if (file.ReadAttrString("META:email", &email) >= B_OK)
				fEmailList.AddChoice(email.String());

			// Also add the quoted full name as an auto-complete string.  Can't
			// do unquoted since auto-complete isn't that smart, so the user
			// will have to type a quote mark if he wants to select someone by
			// name.
			BString fullName;
			if (file.ReadAttrString("META:name", &fullName) >= B_OK) {
				if (email.FindFirst('<') < 0) {
					email.ReplaceAll('>', '_');
					email.Prepend("<");
					email.Append(">");
				}
				fullName.ReplaceAll('\"', '_');
				fullName.Prepend("\"");
				fullName << "\" " << email;
				fEmailList.AddChoice(fullName.String());
			}

			// support for 3rd-party People apps.  Looks like a job for
			// multiple keyword (so you can have several e-mail addresses in
			// one attribute, perhaps comma separated) indices!  Which aren't
			// yet in BFS.
			for (int16 i = 2; i < 6; i++) {
				char attr[16];
				sprintf(attr, "META:email%d", i);
				if (file.ReadAttrString(attr, &email) >= B_OK)
					fEmailList.AddChoice(email.String());
			}
		}
	}
}