static void backend_repo_manager_thread(PkBackendJob *job, GVariant *params, gpointer user_data) { // list PkBitfield filters; // enable const gchar *repo_id; gboolean enabled; bool found = false; // generic PkRoleEnum role; const char *const salt = "$1$/iSaq7rB$EoUw5jJPPvAPECNaaWzMK/"; AptIntf *apt = static_cast<AptIntf*>(pk_backend_job_get_user_data(job)); role = pk_backend_job_get_role(job); if (role == PK_ROLE_ENUM_GET_REPO_LIST) { pk_backend_job_set_status(job, PK_STATUS_ENUM_QUERY); g_variant_get(params, "(t)", &filters); } else { pk_backend_job_set_status(job, PK_STATUS_ENUM_REQUEST); g_variant_get (params, "(&sb)", &repo_id, &enabled); } SourcesList _lst; if (_lst.ReadSources() == false) { _error-> Warning("Ignoring invalid record(s) in sources.list file!"); //return false; } if (_lst.ReadVendors() == false) { _error->Error("Cannot read vendors.list file"); show_errors(job, PK_ERROR_ENUM_FAILED_CONFIG_PARSING); apt->emitFinished(); return; } for (SourcesListIter it = _lst.SourceRecords.begin(); it != _lst.SourceRecords.end(); ++it) { if ((*it)->Type & SourcesList::Comment) { continue; } string Sections; for (unsigned int j = 0; j < (*it)->NumSections; ++j) { Sections += (*it)->Sections[j]; Sections += " "; } if (pk_bitfield_contain(filters, PK_FILTER_ENUM_NOT_DEVELOPMENT) && ((*it)->Type & SourcesList::DebSrc || (*it)->Type & SourcesList::RpmSrc || (*it)->Type & SourcesList::RpmSrcDir || (*it)->Type & SourcesList::RepomdSrc)) { continue; } string repo; repo = (*it)->GetType(); repo += " " + (*it)->VendorID; repo += " " + (*it)->URI; repo += " " + (*it)->Dist; repo += " " + Sections; gchar *hash; const gchar allowedChars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; hash = crypt(repo.c_str(), salt); g_strcanon(hash, allowedChars, 'D'); string repoId(hash); if (role == PK_ROLE_ENUM_GET_REPO_LIST) { pk_backend_job_repo_detail(job, repoId.c_str(), repo.c_str(), !((*it)->Type & SourcesList::Disabled)); } else { if (repoId.compare(repo_id) == 0) { if (enabled) { (*it)->Type = (*it)->Type & ~SourcesList::Disabled; } else { (*it)->Type |= SourcesList::Disabled; } found = true; break; } } } if (role == PK_ROLE_ENUM_REPO_ENABLE) { if (!found) { _error->Error("Could not found the repositorie"); show_errors(job, PK_ERROR_ENUM_REPO_NOT_AVAILABLE); } else if (!_lst.UpdateSources()) { _error->Error("Could not update sources file"); show_errors(job, PK_ERROR_ENUM_CANNOT_WRITE_REPO_CONFIG); } } apt->emitFinished(); }
static gboolean backend_repo_manager_thread (PkBackend *backend) { // list PkBitfield filters; bool notDevelopment; // enable const gchar *repo_id; bool enabled; bool found = false; // generic const char *const salt = "$1$/iSaq7rB$EoUw5jJPPvAPECNaaWzMK/"; bool list = pk_backend_get_bool(backend, "list"); if (list) { pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY); filters = (PkBitfield) pk_backend_get_uint(backend, "filters"); notDevelopment = pk_bitfield_contain(filters, PK_FILTER_ENUM_NOT_DEVELOPMENT); } else { pk_backend_set_status (backend, PK_STATUS_ENUM_REQUEST); repo_id = pk_backend_get_string(backend, "repo_id"); enabled = pk_backend_get_bool(backend, "enabled"); } SourcesList _lst; if (_lst.ReadSources() == false) { _error-> Warning("Ignoring invalid record(s) in sources.list file!"); //return false; } if (_lst.ReadVendors() == false) { _error->Error("Cannot read vendors.list file"); show_errors(backend, PK_ERROR_ENUM_FAILED_CONFIG_PARSING); pk_backend_finished (backend); return false; } for (SourcesListIter it = _lst.SourceRecords.begin(); it != _lst.SourceRecords.end(); it++) { if ((*it)->Type & SourcesList::Comment) { continue; } string Sections; for (unsigned int J = 0; J < (*it)->NumSections; J++) { Sections += (*it)->Sections[J]; Sections += " "; } if (notDevelopment && ((*it)->Type & SourcesList::DebSrc || (*it)->Type & SourcesList::RpmSrc || (*it)->Type & SourcesList::RpmSrcDir || (*it)->Type & SourcesList::RepomdSrc)) { continue; } string repo; repo = (*it)->GetType(); repo += " " + (*it)->VendorID; repo += " " + (*it)->URI; repo += " " + (*it)->Dist; repo += " " + Sections; gchar *hash; const gchar allowedChars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; hash = crypt(repo.c_str(), salt); g_strcanon(hash, allowedChars, 'D'); string repoId(hash); if (list) { pk_backend_repo_detail(backend, repoId.c_str(), repo.c_str(), !((*it)->Type & SourcesList::Disabled)); } else { if (repoId.compare(repo_id) == 0) { if (enabled) { (*it)->Type = (*it)->Type & ~SourcesList::Disabled; } else { (*it)->Type |= SourcesList::Disabled; } found = true; break; } } } if (!list) { if (!found) { _error->Error("Could not found the repositorie"); show_errors(backend, PK_ERROR_ENUM_REPO_NOT_AVAILABLE); } else if (!_lst.UpdateSources()) { _error->Error("Could not update sources file"); show_errors(backend, PK_ERROR_ENUM_CANNOT_WRITE_REPO_CONFIG); } } pk_backend_finished (backend); return true; }