michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "mozilla/AppData.h" michael@0: #include "nsXULAppAPI.h" michael@0: #include "nsINIParser.h" michael@0: #include "nsIFile.h" michael@0: #include "nsCRTGlue.h" michael@0: #include "nsAutoPtr.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: void michael@0: SetAllocatedString(const char *&str, const char *newvalue) michael@0: { michael@0: NS_Free(const_cast(str)); michael@0: if (newvalue) { michael@0: str = NS_strdup(newvalue); michael@0: } michael@0: else { michael@0: str = nullptr; michael@0: } michael@0: } michael@0: michael@0: void michael@0: SetAllocatedString(const char *&str, const nsACString &newvalue) michael@0: { michael@0: NS_Free(const_cast(str)); michael@0: if (newvalue.IsEmpty()) { michael@0: str = nullptr; michael@0: } michael@0: else { michael@0: str = ToNewCString(newvalue); michael@0: } michael@0: } michael@0: michael@0: ScopedAppData::ScopedAppData(const nsXREAppData* aAppData) michael@0: { michael@0: Zero(); michael@0: michael@0: this->size = aAppData->size; michael@0: michael@0: SetAllocatedString(this->vendor, aAppData->vendor); michael@0: SetAllocatedString(this->name, aAppData->name); michael@0: SetAllocatedString(this->version, aAppData->version); michael@0: SetAllocatedString(this->buildID, aAppData->buildID); michael@0: SetAllocatedString(this->ID, aAppData->ID); michael@0: SetAllocatedString(this->copyright, aAppData->copyright); michael@0: SetAllocatedString(this->profile, aAppData->profile); michael@0: SetStrongPtr(this->directory, aAppData->directory); michael@0: this->flags = aAppData->flags; michael@0: michael@0: if (aAppData->size > offsetof(nsXREAppData, xreDirectory)) { michael@0: SetStrongPtr(this->xreDirectory, aAppData->xreDirectory); michael@0: SetAllocatedString(this->minVersion, aAppData->minVersion); michael@0: SetAllocatedString(this->maxVersion, aAppData->maxVersion); michael@0: } michael@0: michael@0: if (aAppData->size > offsetof(nsXREAppData, crashReporterURL)) { michael@0: SetAllocatedString(this->crashReporterURL, aAppData->crashReporterURL); michael@0: } michael@0: michael@0: if (aAppData->size > offsetof(nsXREAppData, UAName)) { michael@0: SetAllocatedString(this->UAName, aAppData->UAName); michael@0: } michael@0: } michael@0: michael@0: ScopedAppData::~ScopedAppData() michael@0: { michael@0: SetAllocatedString(this->vendor, nullptr); michael@0: SetAllocatedString(this->name, nullptr); michael@0: SetAllocatedString(this->version, nullptr); michael@0: SetAllocatedString(this->buildID, nullptr); michael@0: SetAllocatedString(this->ID, nullptr); michael@0: SetAllocatedString(this->copyright, nullptr); michael@0: SetAllocatedString(this->profile, nullptr); michael@0: michael@0: NS_IF_RELEASE(this->directory); michael@0: michael@0: SetStrongPtr(this->xreDirectory, (nsIFile*) nullptr); michael@0: SetAllocatedString(this->minVersion, nullptr); michael@0: SetAllocatedString(this->maxVersion, nullptr); michael@0: michael@0: SetAllocatedString(this->crashReporterURL, nullptr); michael@0: SetAllocatedString(this->UAName, nullptr); michael@0: } michael@0: michael@0: } // namespace mozilla