Example #1
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 #2
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 #3
0
void
BHttpRequest::_ParseStatus()
{
	// Status line should be formatted like: HTTP/M.m SSS ...
	// With:   M = Major version of the protocol
	//         m = Minor version of the protocol
	//       SSS = three-digit status code of the response
	//       ... = additional text info
	BString statusLine;
	if (_GetLine(statusLine) == B_ERROR)
		return;

	if (statusLine.CountChars() < 12)
		return;

	fRequestStatus = kRequestStatusReceived;

	BString statusCodeStr;
	BString statusText;
	statusLine.CopyInto(statusCodeStr, 9, 3);
	_SetResultStatusCode(atoi(statusCodeStr.String()));

	statusLine.CopyInto(_ResultStatusText(), 13, statusLine.Length() - 13);

	_EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT, "Status line received: Code %d (%s)",
		atoi(statusCodeStr.String()), _ResultStatusText().String());
}
Example #4
0
void AddTorrentWindow::UpdateFileList()
{	
	//
	//
	int 	 fileCount = fTorrent->Info()->fileCount;
	tr_file* fileList  = fTorrent->Info()->files;
	
	for( int i = 0; i < fileCount; i++ )
	{
		char FormatBuffer[128] = { 0 };
		BRow* row = new BRow(FILE_COLUMN_HEIGHT);
		
		const char* name = fTorrent->IsFolder() ? (strchr(fileList[i].name, '/') + 1) : fileList[i].name;
		
		//
		//
		//
		BString FileExtension = B_EMPTY_STRING;
		BString FilePath = fileList[i].name;
		FilePath.CopyInto(FileExtension, FilePath.FindLast('.') + 1, FilePath.CountChars());
		
		
		const char* info = tr_formatter_mem_B(FormatBuffer, fileList[i].length, sizeof(FormatBuffer));;
		const BBitmap* icon = GetIconFromExtension(FileExtension);
		
		row->SetField(new FileField(icon, name, info), COLUMN_FILE_NAME);
		row->SetField(new CheckBoxField(true), COLUMN_FILE_DOWNLOAD);
		////row->SetField(new BIntegerField(PeerStatus[i].progress * 100.0), COLUMN_PEER_PROGRESS);
		
		fFileList->AddRow(row, i);

	} 	
}
Example #5
0
status_t ExtractXMLNode(const BString &xml, const BString &element, const BString &attr,
	const BString &attrValue, BString &value) {
	
	status_t result = B_ERROR;
	BString temp = "<";
	temp << element;
	if ((attr.Length() > 0) && (attrValue.Length() > 0)) {
		temp << " " << attr << "=\""  << attrValue << "\"";
	};
	temp << ">";

	int32 open = xml.IFindFirst(temp);
	if (open != B_ERROR) {
		int start = open + temp.Length();
		temp = "";
		temp << "</" << element << ">";
		int32 end = xml.IFindFirst(temp, start);
		if (end != B_ERROR) {
			xml.CopyInto(value, start, end - start);
			result = B_OK;
		};
	};
	
	return result;
};
Example #6
0
status_t ExtractXMLChunk(const BString &xml, const BString &element, const BString &childElement,
	const BString &childElementValue, BString &value) {
	
	status_t result = B_ERROR;
	int32 start = B_ERROR;
	int32 offset = 0;
	BString startElement = "<";
	BString endElement = "</";
	BString child = "<";
	
	startElement << element << ">";
	endElement << element << ">";
	child << childElement << ">" << childElementValue << "</" << childElement << ">";

	while ((start = xml.IFindFirst(startElement, offset)) != B_ERROR) {
		int32 end = xml.IFindFirst(endElement, start);
		value = "";
		
		if (end != B_ERROR) {		
			xml.CopyInto(value, start, end - start);
			
			if (value.IFindFirst(child) != B_ERROR) {
				result = B_OK;
				return result;
			}
		};
		
		offset = start + startElement.Length();
	};
	
	return result;
};
Example #7
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 #8
0
void
BUrl::_ExplodeUrlString(const BString& url)
{
	// The regexp is provided in RFC3986 (URI generic syntax), Appendix B
	static RegExp urlMatcher(
		"^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?");

	_ResetFields();

	RegExp::MatchResult match = urlMatcher.Match(url.String());

	if (!match.HasMatched())
		return; // TODO error reporting

	// Scheme/Protocol
	url.CopyInto(fProtocol, match.GroupStartOffsetAt(1),
		match.GroupEndOffsetAt(1) - match.GroupStartOffsetAt(1));
	if (!_IsProtocolValid()) {
		fHasProtocol = false;
		fProtocol.Truncate(0);
	} else
		fHasProtocol = true;

	// Authority (including user credentials, host, and port
	url.CopyInto(fAuthority, match.GroupStartOffsetAt(3),
		match.GroupEndOffsetAt(3) - match.GroupStartOffsetAt(3));
	SetAuthority(fAuthority);

	// Path
	url.CopyInto(fPath, match.GroupStartOffsetAt(4),
		match.GroupEndOffsetAt(4) - match.GroupStartOffsetAt(4));
	if (!fPath.IsEmpty())
		fHasPath = true;

	// Query
	url.CopyInto(fRequest, match.GroupStartOffsetAt(6),
		match.GroupEndOffsetAt(6) - match.GroupStartOffsetAt(6));
	if (!fRequest.IsEmpty())
		fHasRequest = true;

	// Fragment
	url.CopyInto(fFragment, match.GroupStartOffsetAt(8),
		match.GroupEndOffsetAt(8) - match.GroupStartOffsetAt(8));
	if (!fFragment.IsEmpty())
		fHasFragment = true;
}
void BMailRemoteStorageProtocol::SyncMailbox(const char *mailbox) {
	BPath path(runner->Chain()->MetaData()->FindString("path"));
	path.Append(mailbox);
	
	BDirectory folder(path.Path());
	
	BEntry entry;
	BFile snoodle;
	BString string;
	uint32 chain;
	bool append;
	
	while (folder.GetNextEntry(&entry) == B_OK) {
		if (!entry.IsFile())
			continue;
		while (snoodle.SetTo(&entry,B_READ_WRITE) == B_BUSY) snooze(100);
		append = false;
		
		while (snoodle.Lock() != B_OK) snooze(100);
		snoodle.Unlock();
		
		if (snoodle.ReadAttr("MAIL:chain",B_INT32_TYPE,0,&chain,sizeof(chain)) < B_OK)
			append = true;
		if (chain != runner->Chain()->ID())
			append = true;
		if (snoodle.ReadAttrString("MAIL:unique_id",&string) < B_OK)
			append = true;

		BString folder(string), id("");
		int32 j = string.FindLast('/');
		if ((!append) && (j >= 0)) {
			folder.Truncate(j);
			string.CopyInto(id,j + 1,string.Length());
			if (folder == mailbox)
				continue;
		} else {
			append = true;
		}
		
		if (append)
			AddMessage(mailbox,&snoodle,&id); //---We should check for partial messages here
		else
			CopyMessage(folder.String(),mailbox,&id);
			
		string = mailbox;
		string << '/' << id;
		/*snoodle.RemoveAttr("MAIL:unique_id");
		snoodle.RemoveAttr("MAIL:chain");*/
		chain = runner->Chain()->ID();
		snoodle.WriteAttr("MAIL:chain",B_INT32_TYPE,0,&chain,sizeof(chain));
		snoodle.WriteAttrString("MAIL:unique_id",&string);
		(*manifest) += string.String();
		(*unique_ids) += string.String();
		string = runner->Chain()->Name();
		snoodle.WriteAttrString("MAIL:account",&string);
	}
}
Example #10
0
void
truncate_string(BString &name, int32 length)
{
	if (name.Length() <= length)
		return;
	if (length < 6)
		length = 6;
	
	int32 beginLength = length / 3 - 1;
	int32 endLength = length - 3 - beginLength;

	BString begin, end;
	name.CopyInto(begin, 0, beginLength); 
	name.CopyInto(end, name.Length() - endLength, endLength);

	name = begin;
	name.Append("...").Append(end);
}
Example #11
0
// --------------------------------------------------------------------------------------------- rgetcomment -
BString rgetcomment(BString str)
{
 BString tmp;
 if (str.FindFirst('#')>=0)
 {
  str.CopyInto(tmp,0,str.FindFirst('#'));
 } else tmp=str;
 return tmp;
}
Example #12
0
void
Emoticor::_findTokens(RunView *fTextView,BString text,int tokenstart, int16 cols ,int16 font ,int16 cols2 ,int16 font2)
{
	//******************************************
	// "Iteration is human, recursion is divine"
	//******************************************
	
	
	int32 		newindex = 0;
	BString cur;
	int i=tokenstart;
	
	while(config->FindString("face",i,&cur)==B_OK)
	//for(int i=tokenstart;i<config->numfaces;i++)
	{
		i++;	
		//if(config->FindString("face",i,&cur)!=B_OK) return;
		
		newindex=0;
		
		while(true)
		{
	 	 newindex=text.IFindFirst(cur.String(),0);
	 	 //printf("Try %d %s  -- match %d\n",i,cur->original.String(),newindex);
	 	 		
		if(newindex!=B_ERROR)
		{
			//take a walk on the left side ;)
			
			//printf("Found at %ld \n",newindex);
					
			if(newindex-1>=0)
			{
				BString left;
				text.CopyInto(left,0,newindex);
				//printf("ready to recourse! [%s]\n",left.String());
				_findTokens(fTextView,left,tokenstart+1,cols,font,cols2,font2);
			}
			
				
			text.Remove(0,newindex+cur.Length());
			
			//printf("remaning [%s] printed  [%s]\n",text.String(),cur->original.String());
					
			fTextView->Append(cur.String(),cols2,cols2,font2);
			
			if(text.Length()==0) return; //useless stack
		}
		else
		 break;
				
		}
	}
	
	fTextView->Append(text.String(),cols,cols,font);
	
}
Example #13
0
status_t BVolume::GetName(char *name, size_t nameSize) const
{
	BString str;

	status_t status = GetName(&str);
	if (status == B_OK) str.CopyInto(name, nameSize, 0, -1);

	return status;
}
Example #14
0
void
BaseJob::_ParseExportVariable(BStringList& environment, const BString& line)
{
	if (!line.StartsWith("export "))
		return;

	int separator = line.FindFirst("=\"");
	if (separator < 0)
		return;

	BString variable;
	line.CopyInto(variable, 7, separator - 7);

	BString value;
	line.CopyInto(value, separator + 2, line.Length() - separator - 3);

	variable << "=" << value;
	environment.Add(variable);
}
Example #15
0
BString
FormatResultString(const BString& resultPath)
{
	BString result;

	int32 end = resultPath.FindFirst("CodeName") - 2;
	int32 start = resultPath.FindLast('/', end) + 1;

	if (end - start > 1) {
		resultPath.CopyInto(result, start, end - start + 1);
		result += "::";
		result += &resultPath.String()[resultPath.FindLast('/',
					resultPath.Length()) + 1];
	} else {
		int32 secbegin = resultPath.FindLast('/', resultPath.Length()) + 1;
		resultPath.CopyInto(result, secbegin, resultPath.Length() - secbegin);
	}

	return result;
}
Example #16
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 #17
0
bool
AutoConfigView::IsValidMailAddress(BString email)
{
	int32 atPos = email.FindFirst("@");
	if (atPos < 0)
		return false;
	BString provider;
	email.CopyInto(provider, atPos + 1, email.Length() - atPos);
	if (provider.FindLast(".") < 0)
		return false;
	return true;
}
Example #18
0
static const char*
UptimeToString(char string[], size_t size)
{
	BTimeFormat formatter;
	BString str;

	formatter.Format(system_time() / 1000000, &str);
	str.CopyInto(string,0,size);
	string[str.Length()] = '\0';

	return string;
}
Example #19
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 #20
0
// Format the message into HTML, and return it
char* HTMLView::GetFormattedMessage() {

	BString theText = Text();
	
	// replace all linebreaks with <br>'s
	theText.ReplaceAll( "\n", "<br>" );

	message = (char*)malloc( theText.Length() + 1 );
	theText.CopyInto( message, 0, theText.Length() );
	message[theText.Length()] = '\0';
	
	return message;
}
Example #21
0
bool
BJson::_ParseConstant(BString& JSON, int32& pos, const char* constant)
{
	BString value;
	JSON.CopyInto(value, pos, strlen(constant));
	if (value == constant) {
		// Increase pos by the remainder of the constant, pos will be
		// increased for the first letter in the main parse loop.
		pos += strlen(constant) - 1;
		return true;
	} else
		return false;
}
Example #22
0
static const char*
UptimeToString(char string[], size_t size)
{
	BDurationFormat formatter;
	BString str;

	bigtime_t uptime = system_time();
	bigtime_t now = (bigtime_t)time(NULL) * 1000000;
	formatter.Format(now - uptime, now, &str);
	str.CopyInto(string, 0, size);
	string[std::min((size_t)str.Length(), size)] = '\0';

	return string;
}
Example #23
0
_EXPORT status_t
extract_from_header(const BString& header, const BString& field,
	BString& target)
{
	int32 headerLength = header.Length();
	int32 fieldEndPos = 0;
	while (true) {
		int32 pos = header.IFindFirst(field, fieldEndPos);
		if (pos < 0)
			return B_BAD_VALUE;
		fieldEndPos = pos + field.Length();
		
		if (pos != 0 && header.ByteAt(pos - 1) != '\n')
			continue;
		if (header.ByteAt(fieldEndPos) == ':')
			break;
	}
	fieldEndPos++;

	int32 crPos = fieldEndPos;
	while (true) {
		fieldEndPos = crPos;
		crPos = header.FindFirst('\n', crPos);
		if (crPos < 0)
			crPos = headerLength;
		BString temp;
		header.CopyInto(temp, fieldEndPos, crPos - fieldEndPos);
		if (header.ByteAt(crPos - 1) == '\r') {
			temp.Truncate(temp.Length() - 1);
			temp += " ";
		}
		target += temp;
		crPos++;
		if (crPos >= headerLength)
			break;
		char nextByte = header.ByteAt(crPos);
		if (nextByte != ' ' && nextByte != '\t')
			break;
		crPos++;
	}

	size_t bufferSize = target.Length();
	char* buffer = target.LockBuffer(bufferSize);
	size_t length = rfc2047_to_utf8(&buffer, &bufferSize, bufferSize);
	target.UnlockBuffer(length);

	return B_OK;
}
Example #24
0
void
BUrl::_ExtractPath(const BString& urlString, int16* origin)
{
	// Extract path from URL
	if (urlString.ByteAt(*origin) == '/' || !HasAuthority()) {
		int16 pathEnd = *origin;

		while (pathEnd < urlString.Length()
				&& !_IsPathTerminator(urlString.ByteAt(pathEnd))) {
				pathEnd++;
		}

		urlString.CopyInto(fPath, *origin, pathEnd - *origin);

		*origin = pathEnd;
		fHasPath = true;
	}
}
Example #25
0
void
BUrl::_ExtractProtocol(const BString& urlString, int16* origin)
{
	int16 firstColon = urlString.FindFirst(':', *origin);

	// If no colon is found, assume the protocol
	// is not present
	if (firstColon == -1) 
		return;
	else {
		urlString.CopyInto(fProtocol, *origin, firstColon - *origin);
		*origin = firstColon + 1;
	}

	if (!_IsProtocolValid()) {
		fHasProtocol = false;
		fProtocol.Truncate(0);
	} else
		fHasProtocol = true;
}
static bool
strip_port(BString& host, BString& port)
{
	int32 first = host.FindFirst(':');
	int32 separator = host.FindLast(':');
	if (separator != first
			&& (separator == 0 || host.ByteAt(separator - 1) != ']')) {
		return false;
	}

	if (separator != -1) {
		// looks like there is a port
		host.CopyInto(port, separator + 1, -1);
		host.Truncate(separator);

		return true;
	}

	return false;
}
Example #27
0
char* CRegex::ReplaceString(const char* subject, int32 len, const char* repl)
{
	if (!subject || fInitCheck != B_OK || fMatchInfos.empty())
		return NULL;
	
	BString replStr;

	char c;
	int rl = strlen(repl);
	for(int i=0; i<rl; ++i)
	{
		c = repl[i];
		if (c == '\\' || c == '$')
		{
			c = repl[++i];
			if (c >= '1' && c <= '9')
				replStr << MatchStr(subject, c-'0');
			else if (c == '\\') 
			{	// de-escape newline, carriage-return, tab and backslash:
				if (c == 'n')
					replStr << '\n';
				else if (c == 'r')
					replStr << '\r';
				else if (c == 't')
					replStr << '\t';
				else if (c == '\\')
					replStr << '\\';
			}
		}
		else
			replStr << c;
	}
	char* resBuf = (char*)malloc(replStr.Length()+1);
	if (resBuf)
	{
		replStr.CopyInto(resBuf, 0, replStr.Length());
		resBuf[replStr.Length()] = '\0';
	}
	return resBuf;
}
/*	isCue
*	checks if selected file is a cue file (checks by file extension)
*	if yes, returns true
*/
bool
ProjectTypeSelector::isCue()
{
	BString *SelectedFile = (BString*)FileList->FirstItem();
	BString SelectedFileTMP;
	BString FileExtension;
	BString tmp;
	
	//get file extension
	SelectedFile->CopyInto(SelectedFileTMP, 0, (int)SelectedFile->Length());
	SelectedFileTMP.RemoveAll("/");
	for(int i = 3; i > 0; i--) {
		tmp.SetTo(SelectedFileTMP.ByteAt((SelectedFileTMP.Length() - i)), 1);
		FileExtension.Insert(tmp.String(), FileExtension.Length());
	}
	
	FileExtension.ToUpper();
	if(FileExtension.Compare("CUE") == 0)
		return true;
	
	return false;
}
/*	isVolume
*	checks if selected file is a volume
*	if yes, returns true
*/	
bool
ProjectTypeSelector::isVolume()
{
	BString *SelectedFile = (BString*)FileList->FirstItem();
	BString SelectedFileTMP;
	BVolumeRoster objVolumeRoster;
	objVolumeRoster.Rewind();
	BVolume objVolume;
	char chVolumeName[B_FILE_NAME_LENGTH];
	
	SelectedFile->CopyInto(SelectedFileTMP, 0, (int)SelectedFile->Length());	
	SelectedFileTMP.RemoveAll("/");
	while(objVolumeRoster.GetNextVolume(&objVolume) != B_BAD_VALUE) {
		objVolume.GetName(chVolumeName);
		
		if(SelectedFileTMP.Compare(chVolumeName) == 0 && objVolume.IsReadOnly()) {
			fSizeOfFiles = objVolume.Capacity();
			return true;
		}
	}
	
	return false;
}
BString
HaikuMailFormatFilter::_ExtractName(const BString& from)
{
	// extract name from something like "name" <*****@*****.**>
	// if name is empty return the mail address without "<>"

	BString name;
	int32 emailStart = from.FindFirst("<");
	if (emailStart < 0) {
		name = from;
		return name.Trim();
	}

	from.CopyInto(name, 0, emailStart);
	name.Trim();
	if (name.Length() >= 2) {
		if (name[name.Length() - 1] == '\"')
			name.Truncate(name.Length() - 1, true);
		if (name[0] == '\"')
			name.Remove(0, 1);
		name.Trim();
	}
	if (name != "")
		return name;

	// empty name extract email address
	name = from;
	name.Remove(0, emailStart + 1);
	name.Trim();
	if (name.Length() < 1)
		return from;
	if (name[name.Length() - 1] == '>')
		name.Truncate(name.Length() - 1, true);
	name.Trim();
	return name;
}