Author: czeidler Date: 2011-03-10 07:25:57 +0100 (Thu, 10 Mar 2011) New Revision: 40895 Changeset: http://dev.haiku-os.org/changeset/40895 Ticket: http://dev.haiku-os.org/ticket/7266 Modified: haiku/trunk/src/preferences/mail/AutoConfigWindow.cpp haiku/trunk/src/preferences/mail/ConfigWindow.cpp haiku/trunk/src/preferences/mail/DNSQuery.cpp haiku/trunk/src/preferences/mail/DNSQuery.h haiku/trunk/src/preferences/mail/main.cpp Log: Fix reading of compressed strings. This fixes #7266. Some clean up. Modified: haiku/trunk/src/preferences/mail/AutoConfigWindow.cpp =================================================================== --- haiku/trunk/src/preferences/mail/AutoConfigWindow.cpp 2011-03-10 01:31:33 UTC (rev 40894) +++ haiku/trunk/src/preferences/mail/AutoConfigWindow.cpp 2011-03-10 06:25:57 UTC (rev 40895) @@ -42,7 +42,7 @@ B_FOLLOW_ALL_SIDES, B_NAVIGABLE); fRootView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); AddChild(fRootView); - + int32 buttonHeight = 25; int32 buttonWidth = 50; BRect buttonRect = Bounds(); @@ -51,27 +51,26 @@ buttonRect.left = buttonRect.right - 2 * buttonWidth - 5; buttonRect.right = buttonRect.left + buttonWidth; fBackButton = new BButton(buttonRect, "back", B_TRANSLATE("Back"), - new BMessage(kBackMsg)); + new BMessage(kBackMsg)); fBackButton->SetEnabled(false); fRootView->AddChild(fBackButton); - + buttonRect.left+= 5 + buttonWidth; buttonRect.right = buttonRect.left + buttonWidth; fNextButton = new BButton(buttonRect, "ok", B_TRANSLATE("OK"), new BMessage(kOkMsg)); fNextButton->MakeDefault(true); fRootView->AddChild(fNextButton); - + fBoxRect = Bounds(); fBoxRect.InsetBy(5,5); fBoxRect.bottom-= buttonHeight + 5; - + fMainView = new AutoConfigView(fBoxRect, fAutoConfig); fMainView->SetLabel(B_TRANSLATE("Account settings")); fRootView->AddChild(fMainView); - + // Add a shortcut to close the window using Command-W AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED)); - } Modified: haiku/trunk/src/preferences/mail/ConfigWindow.cpp =================================================================== --- haiku/trunk/src/preferences/mail/ConfigWindow.cpp 2011-03-10 01:31:33 UTC (rev 40894) +++ haiku/trunk/src/preferences/mail/ConfigWindow.cpp 2011-03-10 06:25:57 UTC (rev 40895) @@ -245,7 +245,8 @@ SetFontAndColor(0,23,&font,B_FONT_SIZE); // center the view vertically - rect = TextRect(); rect.OffsetTo(0,(Bounds().Height() - TextHeight(0,42)) / 2); + rect = TextRect(); + rect.OffsetTo(0,(Bounds().Height() - TextHeight(0,42)) / 2); SetTextRect(rect); // set the link regions @@ -270,11 +271,14 @@ BTextView::Draw(updateRect); BRect rect(fMail.Frame()); - StrokeLine(BPoint(rect.left,rect.bottom-2),BPoint(rect.right,rect.bottom-2)); + StrokeLine(BPoint(rect.left,rect.bottom-2), + BPoint(rect.right,rect.bottom-2)); rect = fBugsite.Frame(); - StrokeLine(BPoint(rect.left,rect.bottom-2),BPoint(rect.right,rect.bottom-2)); + StrokeLine(BPoint(rect.left,rect.bottom-2), + BPoint(rect.right,rect.bottom-2)); rect = fWebsite.Frame(); - StrokeLine(BPoint(rect.left,rect.bottom-2),BPoint(rect.right,rect.bottom-2)); + StrokeLine(BPoint(rect.left,rect.bottom-2), + BPoint(rect.right,rect.bottom-2)); } virtual void MouseDown(BPoint point) @@ -308,7 +312,6 @@ fSaveSettings(false) { // create controls - BRect rect(Bounds()); BView *top = new BView(rect, NULL, B_FOLLOW_ALL, 0); top->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); Modified: haiku/trunk/src/preferences/mail/DNSQuery.cpp =================================================================== --- haiku/trunk/src/preferences/mail/DNSQuery.cpp 2011-03-10 01:31:33 UTC (rev 40894) +++ haiku/trunk/src/preferences/mail/DNSQuery.cpp 2011-03-10 06:25:57 UTC (rev 40895) @@ -94,29 +94,11 @@ status_t BRawNetBuffer::ReadString(BString& string) { - if (fReadPosition >= fBuffer.BufferLength()) + string = ""; + size_t readed = _ReadStringAt(string, fReadPosition); + if (readed < 0) return B_ERROR; - - char* buffer = (char*)fBuffer.Buffer(); - buffer = &buffer[fReadPosition]; - - // if the string is compressed we have to follow the links to the - // sub strings - while (fReadPosition < fBuffer.BufferLength() && *buffer != 0) { - if (uint8(*buffer) == 192) { - // found a pointer mark - buffer++; - // pointer takes 2 byte - fReadPosition = fReadPosition + 1; - off_t pos = uint8(*buffer); - _ReadSubString(string, pos); - break; - } - string.Append(buffer, 1); - buffer++; - fReadPosition++; - } - fReadPosition++; + fReadPosition += readed; return B_OK; } @@ -140,13 +122,32 @@ } -void -BRawNetBuffer::_ReadSubString(BString& string, off_t pos) +size_t +BRawNetBuffer::_ReadStringAt(BString& string, off_t pos) { - // sub strings have no links to other substrings so we can read it in one - // piece + if (pos >= fBuffer.BufferLength()) + return -1; + + size_t readed = 0; char* buffer = (char*)fBuffer.Buffer(); - string.Append(&buffer[pos]); + buffer = &buffer[pos]; + // if the string is compressed we have to follow the links to the + // sub strings + while (pos < fBuffer.BufferLength() && *buffer != 0) { + if (uint8(*buffer) == 192) { + // found a pointer mark + buffer++; + readed++; + off_t subPos = uint8(*buffer); + _ReadStringAt(string, subPos); + break; + } + string.Append(buffer, 1); + buffer++; + readed++; + } + readed++; + return readed; } Modified: haiku/trunk/src/preferences/mail/DNSQuery.h =================================================================== --- haiku/trunk/src/preferences/mail/DNSQuery.h 2011-03-10 01:31:33 UTC (rev 40894) +++ haiku/trunk/src/preferences/mail/DNSQuery.h 2011-03-10 06:25:57 UTC (rev 40895) @@ -42,7 +42,8 @@ private: void _Init(const void* buf, size_t size); - void _ReadSubString(BString& string, off_t pos); + size_t _ReadStringAt(BString& string, off_t pos); + off_t fWritePosition; off_t fReadPosition; BMallocIO fBuffer; Modified: haiku/trunk/src/preferences/mail/main.cpp =================================================================== --- haiku/trunk/src/preferences/mail/main.cpp 2011-03-10 01:31:33 UTC (rev 40894) +++ haiku/trunk/src/preferences/mail/main.cpp 2011-03-10 06:25:57 UTC (rev 40895) @@ -1,46 +1,23 @@ -/* main - the application and startup code -** -** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved. -*/ +/* + * Copyright 2011, Haiku, Inc. All rights reserved. + * Copyright 2011, Clemens Zeidler <haiku@xxxxxxxxxxxxxxxxxx> + * Distributed under the terms of the MIT License. + */ -#include "ConfigWindow.h" - #include <Application.h> -#include <Catalog.h> -#include <Locale.h> +#include "ConfigWindow.h" -class BCatalog; -class MailConfigApp : public BApplication { - public: - MailConfigApp(); - ~MailConfigApp(); -}; - - -MailConfigApp::MailConfigApp() - : BApplication("application/x-vnd.Haiku-Mail") -{ - (new ConfigWindow())->Show(); -} - - -MailConfigApp::~MailConfigApp() -{ -} - - -// #pragma mark - - - int -main(int argc,char **argv) +main(int argc, char** argv) { - (new MailConfigApp())->Run(); - delete be_app; + BApplication app("application/x-vnd.Haiku-Mail"); + BWindow* window = new ConfigWindow; + window->Show(); + + app.Run(); return 0; } -