static void LoadSettings()
{
  /*
   * NOTE! This code needs to stay in sync with the preference checking
   *       code in in nsExceptionHandler.cpp.
   */

  StringTable settings;
  if (ReadStringsFromFile(gSettingsPath + "/" + kIniFile, settings, true)) {
    if (settings.find("Email") != settings.end()) {
      gtk_entry_set_text(GTK_ENTRY(gEmailEntry), settings["Email"].c_str());
      gEmailFieldHint = false;
    }
    if (settings.find("EmailMe") != settings.end()) {
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gEmailMeCheck),
                                   settings["EmailMe"][0] != '0');
    }
    if (settings.find("IncludeURL") != settings.end() &&
        gIncludeURLCheck != 0) {
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gIncludeURLCheck),
                                   settings["IncludeURL"][0] != '0');
    }
    bool enabled;
    if (settings.find("SubmitReport") != settings.end())
      enabled = settings["SubmitReport"][0] != '0';
    else
      enabled = ShouldEnableSending();
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gSubmitReportCheck),
                                 enabled);
  }
}
示例#2
0
 GameString text(const GameStringKey& id) const {
     auto a = m_strings.find(id);
     if (a != m_strings.end()) {
         return a->second;
     }
     return GameStringUtil::fromString("MISSING: " + id);
 }
示例#3
0
    unsigned int PushString(unsigned int index, const std::string& content)
    {
        StringTable::iterator ot = _origin.find(index);
        if(ot != _origin.end())
            throw std::runtime_error( "String ID conflict." );

        StringTableRev::iterator otr = _origin_rev.find(content);
        if(otr != _origin_rev.end())
            return otr->second; // duplicated string

        // got unique string
        _origin[index] = content;
        _origin_rev[content] = index;

        if(_max_id < index)
            _max_id = index;

        return index;
    }
示例#4
0
//---------------------------------------------------------------------------
unsigned int StringID( const std::string& stringValue )
{
	std::string value( stringValue );
	ToLower( value );
	StringTable::iterator iter = s_theStringTable.find( value );
	if ( iter != s_theStringTable.end() )
	{
		return iter->second.m_id;
	}
	else
	{
		StringTableEntry newEntry;
		newEntry.m_id = s_nextStringID;
		newEntry.m_originalString = stringValue;
		s_theStringTable.insert( std::make_pair( value, newEntry ) );
		++ s_nextStringID;
		return newEntry.m_id;
	}
}
示例#5
0
int main(int argc, char** argv)
{
  gArgc = argc;
  gArgv = argv;

  if (!ReadConfig()) {
    UIError("Couldn't read configuration.");
    return 0;
  }

  if (!UIInit())
    return 0;

  if (argc > 1) {
    gReporterDumpFile = argv[1];
  }

  if (gReporterDumpFile.empty()) {
    // no dump file specified, run the default UI
    UIShowDefaultUI();
  } else {
    // Start by running minidump analyzer to gather stack traces.
    string reporterDumpFile = gReporterDumpFile;
    vector<string> args = { reporterDumpFile };
    UIRunProgram(GetProgramPath(UI_MINIDUMP_ANALYZER_FILENAME),
                 args, /* wait */ true);

    // go ahead with the crash reporter
    gExtraFile = GetAdditionalFilename(gReporterDumpFile, kExtraDataExtension);
    if (gExtraFile.empty()) {
      UIError(gStrings[ST_ERROR_BADARGUMENTS]);
      return 0;
    }

    if (!UIFileExists(gExtraFile)) {
      UIError(gStrings[ST_ERROR_EXTRAFILEEXISTS]);
      return 0;
    }

    gMemoryFile = GetAdditionalFilename(gReporterDumpFile,
                                        kMemoryReportExtension);
    if (!UIFileExists(gMemoryFile)) {
      gMemoryFile.erase();
    }

    StringTable queryParameters;
    if (!ReadStringsFromFile(gExtraFile, queryParameters, true)) {
      UIError(gStrings[ST_ERROR_EXTRAFILEREAD]);
      return 0;
    }

    if (queryParameters.find("ProductName") == queryParameters.end()) {
      UIError(gStrings[ST_ERROR_NOPRODUCTNAME]);
      return 0;
    }

    // There is enough information in the extra file to rewrite strings
    // to be product specific
    RewriteStrings(queryParameters);

    if (queryParameters.find("ServerURL") == queryParameters.end()) {
      UIError(gStrings[ST_ERROR_NOSERVERURL]);
      return 0;
    }

    // Hopefully the settings path exists in the environment. Try that before
    // asking the platform-specific code to guess.
    gSettingsPath = UIGetEnv("MOZ_CRASHREPORTER_DATA_DIRECTORY");
    if (gSettingsPath.empty()) {
      string product = queryParameters["ProductName"];
      string vendor = queryParameters["Vendor"];
      if (!UIGetSettingsPath(vendor, product, gSettingsPath)) {
        gSettingsPath.clear();
      }
    }

    if (gSettingsPath.empty() || !UIEnsurePathExists(gSettingsPath)) {
      UIError(gStrings[ST_ERROR_NOSETTINGSPATH]);
      return 0;
    }

    OpenLogFile();

    gEventsPath = UIGetEnv("MOZ_CRASHREPORTER_EVENTS_DIRECTORY");
    gPingPath = UIGetEnv("MOZ_CRASHREPORTER_PING_DIRECTORY");

    // Assemble and send the crash ping
    string hash;
    string pingUuid;

    hash = ComputeDumpHash();
    if (!hash.empty()) {
      AppendToEventFile("MinidumpSha256Hash", hash);
    }

    if (SendCrashPing(queryParameters, hash, pingUuid, gPingPath)) {
      AppendToEventFile("CrashPingUUID", pingUuid);
    }

    // Update the crash event with stacks if they are present
    auto stackTracesItr = queryParameters.find("StackTraces");
    if (stackTracesItr != queryParameters.end()) {
      AppendToEventFile(stackTracesItr->first, stackTracesItr->second);
    }

    if (!UIFileExists(gReporterDumpFile)) {
      UIError(gStrings[ST_ERROR_DUMPFILEEXISTS]);
      return 0;
    }

    string pendingDir = gSettingsPath + UI_DIR_SEPARATOR + "pending";
    if (!MoveCrashData(pendingDir, gReporterDumpFile, gExtraFile,
                       gMemoryFile)) {
      return 0;
    }

    string sendURL = queryParameters["ServerURL"];
    // we don't need to actually send this
    queryParameters.erase("ServerURL");

    queryParameters["Throttleable"] = "1";

    // re-set XUL_APP_FILE for xulrunner wrapped apps
    const char *appfile = getenv("MOZ_CRASHREPORTER_RESTART_XUL_APP_FILE");
    if (appfile && *appfile) {
      const char prefix[] = "XUL_APP_FILE=";
      char *env = (char*) malloc(strlen(appfile) + strlen(prefix) + 1);
      if (!env) {
        UIError("Out of memory");
        return 0;
      }
      strcpy(env, prefix);
      strcat(env, appfile);
      putenv(env);
      free(env);
    }

    vector<string> restartArgs;

    ostringstream paramName;
    int i = 0;
    paramName << "MOZ_CRASHREPORTER_RESTART_ARG_" << i++;
    const char *param = getenv(paramName.str().c_str());
    while (param && *param) {
      restartArgs.push_back(param);

      paramName.str("");
      paramName << "MOZ_CRASHREPORTER_RESTART_ARG_" << i++;
      param = getenv(paramName.str().c_str());
    }

    // allow override of the server url via environment variable
    //XXX: remove this in the far future when our robot
    // masters force everyone to use XULRunner
    char* urlEnv = getenv("MOZ_CRASHREPORTER_URL");
    if (urlEnv && *urlEnv) {
      sendURL = urlEnv;
    }

     // see if this version has been end-of-lifed
     if (queryParameters.find("Version") != queryParameters.end() &&
         CheckEndOfLifed(queryParameters["Version"])) {
       UIError(gStrings[ST_ERROR_ENDOFLIFE]);
       DeleteDump();
       return 0;
     }

    StringTable files;
    files["upload_file_minidump"] = gReporterDumpFile;
    if (!gMemoryFile.empty()) {
      files["memory_report"] = gMemoryFile;
    }

    if (!UIShowCrashUI(files, queryParameters, sendURL, restartArgs))
      DeleteDump();
  }

  UIShutdown();

  return 0;
}
示例#6
0
static bool AddSubmittedReport(const string& serverResponse)
{
  StringTable responseItems;
  istringstream in(serverResponse);
  ReadStrings(in, responseItems, false);

  if (responseItems.find("StopSendingReportsFor") != responseItems.end()) {
    // server wants to tell us to stop sending reports for a certain version
    string reportPath =
      gSettingsPath + UI_DIR_SEPARATOR + "EndOfLife" +
      responseItems["StopSendingReportsFor"];

    ofstream* reportFile = UIOpenWrite(reportPath);
    if (reportFile->is_open()) {
      // don't really care about the contents
      *reportFile << 1 << "\n";
      reportFile->close();
    }
    delete reportFile;
  }

  if (responseItems.find("Discarded") != responseItems.end()) {
    // server discarded this report... save it so the user can resubmit it
    // manually
    return false;
  }

  if (responseItems.find("CrashID") == responseItems.end())
    return false;

  string submittedDir =
    gSettingsPath + UI_DIR_SEPARATOR + "submitted";
  if (!UIEnsurePathExists(submittedDir)) {
    return false;
  }

  string path = submittedDir + UI_DIR_SEPARATOR +
    responseItems["CrashID"] + ".txt";

  ofstream* file = UIOpenWrite(path);
  if (!file->is_open()) {
    delete file;
    return false;
  }

  char buf[1024];
  UI_SNPRINTF(buf, 1024,
              gStrings["CrashID"].c_str(),
              responseItems["CrashID"].c_str());
  *file << buf << "\n";

  if (responseItems.find("ViewURL") != responseItems.end()) {
    UI_SNPRINTF(buf, 1024,
                gStrings["CrashDetailsURL"].c_str(),
                responseItems["ViewURL"].c_str());
    *file << buf << "\n";
  }

  file->close();
  delete file;

  WriteSubmissionEvent(Succeeded, responseItems["CrashID"]);
  return true;
}
示例#7
0
int main(int argc, char** argv)
{
    gArgc = argc;
    gArgv = argv;

    if (!ReadConfig()) {
        UIError("Couldn't read configuration.");
        return 0;
    }

    if (!UIInit())
        return 0;

    if (argc > 1) {
        gReporterDumpFile = argv[1];
    }

    if (gReporterDumpFile.empty()) {
        // no dump file specified, run the default UI
        UIShowDefaultUI();
    } else {
        gExtraFile = GetAdditionalFilename(gReporterDumpFile, kExtraDataExtension);
        if (gExtraFile.empty()) {
            UIError(gStrings[ST_ERROR_BADARGUMENTS]);
            return 0;
        }

        if (!UIFileExists(gExtraFile)) {
            UIError(gStrings[ST_ERROR_EXTRAFILEEXISTS]);
            return 0;
        }

        gMemoryFile = GetAdditionalFilename(gReporterDumpFile,
                                            kMemoryReportExtension);
        if (!UIFileExists(gMemoryFile)) {
            gMemoryFile.erase();
        }

        StringTable queryParameters;
        if (!ReadStringsFromFile(gExtraFile, queryParameters, true)) {
            UIError(gStrings[ST_ERROR_EXTRAFILEREAD]);
            return 0;
        }

        if (queryParameters.find("ProductName") == queryParameters.end()) {
            UIError(gStrings[ST_ERROR_NOPRODUCTNAME]);
            return 0;
        }

        // There is enough information in the extra file to rewrite strings
        // to be product specific
        RewriteStrings(queryParameters);

        if (queryParameters.find("ServerURL") == queryParameters.end()) {
            UIError(gStrings[ST_ERROR_NOSERVERURL]);
            return 0;
        }

        // Hopefully the settings path exists in the environment. Try that before
        // asking the platform-specific code to guess.
#ifdef XP_WIN32
        static const wchar_t kDataDirKey[] = L"MOZ_CRASHREPORTER_DATA_DIRECTORY";
        const wchar_t *settingsPath = _wgetenv(kDataDirKey);
        if (settingsPath && *settingsPath) {
            gSettingsPath = WideToUTF8(settingsPath);
        }
#else
        static const char kDataDirKey[] = "MOZ_CRASHREPORTER_DATA_DIRECTORY";
        const char *settingsPath = getenv(kDataDirKey);
        if (settingsPath && *settingsPath) {
            gSettingsPath = settingsPath;
        }
#endif
        else {
            string product = queryParameters["ProductName"];
            string vendor = queryParameters["Vendor"];
            if (!UIGetSettingsPath(vendor, product, gSettingsPath)) {
                gSettingsPath.clear();
            }
        }

        if (gSettingsPath.empty() || !UIEnsurePathExists(gSettingsPath)) {
            UIError(gStrings[ST_ERROR_NOSETTINGSPATH]);
            return 0;
        }

        OpenLogFile();

#ifdef XP_WIN32
        static const wchar_t kEventsDirKey[] = L"MOZ_CRASHREPORTER_EVENTS_DIRECTORY";
        const wchar_t *eventsPath = _wgetenv(kEventsDirKey);
        if (eventsPath && *eventsPath) {
            gEventsPath = WideToUTF8(eventsPath);
        }
#else
        static const char kEventsDirKey[] = "MOZ_CRASHREPORTER_EVENTS_DIRECTORY";
        const char *eventsPath = getenv(kEventsDirKey);
        if (eventsPath && *eventsPath) {
            gEventsPath = eventsPath;
        }
#endif
        else {
            gEventsPath.clear();
        }

        if (!UIFileExists(gReporterDumpFile)) {
            UIError(gStrings[ST_ERROR_DUMPFILEEXISTS]);
            return 0;
        }

        string pendingDir = gSettingsPath + UI_DIR_SEPARATOR + "pending";
        if (!MoveCrashData(pendingDir, gReporterDumpFile, gExtraFile,
                           gMemoryFile)) {
            return 0;
        }

        string sendURL = queryParameters["ServerURL"];
        // we don't need to actually send this
        queryParameters.erase("ServerURL");

        queryParameters["Throttleable"] = "1";

        // re-set XUL_APP_FILE for xulrunner wrapped apps
        const char *appfile = getenv("MOZ_CRASHREPORTER_RESTART_XUL_APP_FILE");
        if (appfile && *appfile) {
            const char prefix[] = "XUL_APP_FILE=";
            char *env = (char*) malloc(strlen(appfile) + strlen(prefix) + 1);
            if (!env) {
                UIError("Out of memory");
                return 0;
            }
            strcpy(env, prefix);
            strcat(env, appfile);
            putenv(env);
            free(env);
        }

        vector<string> restartArgs;

        ostringstream paramName;
        int i = 0;
        paramName << "MOZ_CRASHREPORTER_RESTART_ARG_" << i++;
        const char *param = getenv(paramName.str().c_str());
        while (param && *param) {
            restartArgs.push_back(param);

            paramName.str("");
            paramName << "MOZ_CRASHREPORTER_RESTART_ARG_" << i++;
            param = getenv(paramName.str().c_str());
        };

        // allow override of the server url via environment variable
        //XXX: remove this in the far future when our robot
        // masters force everyone to use XULRunner
        char* urlEnv = getenv("MOZ_CRASHREPORTER_URL");
        if (urlEnv && *urlEnv) {
            sendURL = urlEnv;
        }

        // see if this version has been end-of-lifed
        if (queryParameters.find("Version") != queryParameters.end() &&
                CheckEndOfLifed(queryParameters["Version"])) {
            UIError(gStrings[ST_ERROR_ENDOFLIFE]);
            DeleteDump();
            return 0;
        }

        StringTable files;
        files["upload_file_minidump"] = gReporterDumpFile;
        if (!gMemoryFile.empty()) {
            files["memory_report"] = gMemoryFile;
        }

        if (!UIShowCrashUI(files, queryParameters, sendURL, restartArgs))
            DeleteDump();
    }

    UIShutdown();

    return 0;
}