int slack_convert(const string& filename, string& xml_output) { mDebug("Preparing to convert " + filename); PACKAGE package; package.set_filename(filename); // Resolving name, version, arch and build string tmp; string tmp_xml = get_tmp_file(); extractFromTgz(filename, "install/data.xml", tmp_xml); if (FileNotEmpty(tmp_xml)) { WriteFile(xml_output, ReadFile(tmp_xml)); delete_tmp_files(); return 0; } string ptrstr; // Guessing type string pkgType = getExtension(filename); if (pkgType!="tgz" && pkgType!="txz" && pkgType!="tlz" && pkgType!="tbz") { mError(_("Unknown package type ") + pkgType); return 1; } // Name-ver-arch-build parsing string name_tmp=filename.substr(0,filename.find("." + pkgType)); name_tmp = name_tmp.substr(name_tmp.find_last_of("/")+1); ptrstr = name_tmp.substr(name_tmp.find_last_of("-")+1); package.set_build(ptrstr); name_tmp = name_tmp.substr(0,name_tmp.find_last_of("-")); ptrstr = name_tmp.substr(name_tmp.find_last_of("-")+1); package.set_arch(ptrstr); name_tmp = name_tmp.substr(0,name_tmp.find_last_of("-")); ptrstr=name_tmp.substr(name_tmp.find_last_of("-")+1); package.set_version(ptrstr); name_tmp = name_tmp.substr(0,name_tmp.find_last_of("-")); package.set_name(name_tmp); name_tmp.clear(); #define DESCRIPTION_PROCESS #ifdef DESCRIPTION_PROCESS //DESCRIPTION mDebug("Processing description"); string desc_file= filename.substr(0,filename.length()-3)+"txt"; bool can_read=false; #ifdef GET_TXT_DESC if (access(desc_file.c_str(), R_OK)==0) { mDebug("Retrieving from txt"); can_read=true; } else { #endif desc_file=get_tmp_file(); string desc="tar xf "+filename+" install/slack-desc --to-stdout > "+desc_file; if (system(desc.c_str())==0) { mDebug("Retrieving from slack-desc"); can_read=true; } else mDebug("Cannot find any description"); #ifdef GET_TXT_DESC } #endif if (can_read) { string description=ReadFile(desc_file); delete_tmp_files(); // Step 1. Skip comments unsigned int dpos=0; //unsigned int strLen=0; string comment; string head; string short_description; //bool str1=true; if (!description.empty()) { // Cleaning out comments for (unsigned int i=0; i<description.length(); i++) { if (description[i]=='#') { while (description[i]!='\n') i++; } if (i<description.length()) tmp+=description[i]; } description=tmp; tmp.clear(); string pHead=package.get_name()+":"; int spos=description.find(pHead,0); // Removing package: headers for (unsigned int i=spos; i<description.length(); i++) { //head+=description[i]; if (i==0 || description[i-1]=='\n') { i=i+package.get_name().length()+1; //if (description[i-1]=='\n') i=i+package.get_name().length()+2; //head.clear(); } if (i<description.length()) tmp+=description[i]; } description=tmp; tmp.clear(); // Splitting short and long descriptions for (unsigned int i=0; i<description.length() && description[i]!='\n'; i++) { tmp+=description[i]; dpos=i+1; } short_description=tmp; tmp.clear(); for (unsigned int i=dpos; i<description.length(); i++) { if (i==dpos && description[i]=='\n') { while (description[i]=='\n' || description[i]==' ') i++; if (i>=description.length()) break; } if (i<description.length()) tmp+=description[i]; } description=tmp; tmp.clear(); package.set_short_description(short_description); package.set_description(description); mDebug("Description: " + description); } } #endif XMLNode pkg=XMLNode::createXMLTopNode("package"); pkg.addChild("name"); pkg.getChildNode("name").addText(package.get_name().c_str()); pkg.addChild("version"); pkg.getChildNode("version").addText(package.get_version().c_str()); pkg.addChild("arch"); pkg.getChildNode("arch").addText(package.get_arch().c_str()); pkg.addChild("build"); pkg.getChildNode("build").addText(package.get_build().c_str()); #ifdef DESCRIPTION_PROCESS mDebug("Adding description to XML node"); pkg.addChild("short_description"); pkg.getChildNode("short_description").addText(package.get_short_description().c_str()); pkg.addChild("description"); pkg.getChildNode("description").addText(package.get_description().c_str()); #endif #ifdef TAG_CONVERTED pkg.addChild("tags"); pkg.getChildNode("tags").addChild("tag"); pkg.getChildNode("tags").getChildNode("tag").addText("slackware"); #endif // Get maintainer name and email string mName = mConfig.getValue("maintainer_name"); string mEmail = mConfig.getValue("maintainer_email"); if (mName.empty()) mName = "Converted by anonymous maintainer"; if (mEmail.empty()) mEmail = "No email specified"; pkg.addChild("maintainer"); pkg.getChildNode("maintainer").addChild("name"); pkg.getChildNode("maintainer").getChildNode("name").addText(mName.c_str()); pkg.getChildNode("maintainer").addChild("email"); pkg.getChildNode("maintainer").getChildNode("email").addText(mEmail.c_str()); pkg.writeToFile(xml_output.c_str(), "utf-8"); return 0; }
//XMLNode _rootFList; int slackpackages2list (string *packageslist, string *md5list, PACKAGE_LIST *pkglist, string server_url) { if (actionBus._abortActions) { actionBus._abortComplete=true; actionBus.setActionState(ACTIONID_DBUPDATE, ITEMSTATE_ABORTED); say("aborted\n"); return MPKGERROR_ABORTED; } if (packageslist->length()<20) { say("aborted\n"); return -1; // It's impossible if it has less size... } // Parsing slackware PACKAGES.TXT file // Keywords (in [] braces to show spaces: // [PACKAGE NAME: ] going first or after \n\n symbols. Until \n, contains package filename (that contains name, version, arch and build information) // [PACKAGE LOCATION: ] location of package (from repository root). Going after \n // [PACKAGE SIZE (compressed): ] // [PACKAGE SIZE (uncompressed): ] // [PACKAGE REQUIRED: ] // [PACKAGE SUGGESTS: ] // [PACKAGE DESCRIPTION:\n] Package description (max 11 lines starting with [package_name:]) PACKAGE *pkg = new PACKAGE; LOCATION *tmplocation = new LOCATION; #ifdef ENABLE_INTERNATIONAL DESCRIPTION *tmpDesc = new DESCRIPTION; tmpDesc->set_language("en"); #endif string *tmpDescStr = new string; string *tmpstr = packageslist; int tmpSize; int lines = 0; int name_start = 0; bool endReached = false; string slackPackageName; string slackPackageLocation; string slackCompressedSize; string slackUncompressedSize; string slackRequired; string slackSuggests; string slackDescription; string filename; string tmp; string md5tmp; string pkgNameKeyword = "PACKAGE NAME: "; string pkgLocationKeyword = "PACKAGE LOCATION: "; string pkgCompressedKeyword = "PACKAGE SIZE (compressed): "; string pkgUncompressedKeyword = "PACKAGE SIZE (uncompressed): "; string pkgRequiredKeyword = "PACKAGE REQUIRED: "; string pkgSuggestsKeyword = "PACKAGE SUGGESTS: "; string pkgDescriptionKeyword = "PACKAGE DESCRIPTION:"; unsigned int pos; unsigned int num=0; //tmpstr = packageslist; // Visualization actionBus.setActionProgress(ACTIONID_DBUPDATE, 0); unsigned int tmp_max = tmpstr->length(); actionBus.setActionProgressMaximum(ACTIONID_DBUPDATE, (double) tmpstr->length()); //progressEnabled = true; while (!endReached) { if (actionBus._abortActions) { actionBus._abortComplete=true; actionBus.setActionState(ACTIONID_DBUPDATE, ITEMSTATE_ABORTED); say("aborted\n"); return MPKGERROR_ABORTED; } actionBus.setActionProgress (ACTIONID_DBUPDATE, (double) tmp_max - tmpstr->length()); mDebug("Parsing "+IntToStr(num)+" package"); // Stage 1: retrieving dirty info pos = tmpstr->find(pkgNameKeyword); *tmpstr=tmpstr->substr(pos+pkgNameKeyword.length()); // Cuts off a header and keyword pos = tmpstr->find("\n"); // Searching end of line slackPackageName = tmpstr->substr(0,pos); // Filling package name (in full form) mDebug("slackPackageName = "+slackPackageName); pos = tmpstr->find(pkgLocationKeyword); *tmpstr = tmpstr->substr(pkgLocationKeyword.length()+pos); pos = tmpstr->find("\n"); slackPackageLocation = tmpstr->substr(0,pos); mDebug("slackPackageLocation = "+ slackPackageLocation); pos = tmpstr->find(pkgCompressedKeyword); *tmpstr = tmpstr->substr(pos + pkgCompressedKeyword.length()); pos = tmpstr->find("\n"); slackCompressedSize = tmpstr->substr(0,pos); mDebug("slackCompressedSize = " + slackCompressedSize); pos = tmpstr->find(pkgUncompressedKeyword); *tmpstr = tmpstr->substr(pos + pkgUncompressedKeyword.length()); pos = tmpstr->find("\n"); slackUncompressedSize = tmpstr->substr(0,pos); mDebug("slackUncompressedSize = " + slackUncompressedSize); pos = tmpstr->find(pkgRequiredKeyword); if (pos < tmpstr->find(pkgNameKeyword)) { mDebug("required list present!"); *tmpstr = tmpstr->substr(pos + pkgRequiredKeyword.length()); pos = tmpstr->find("\n"); slackRequired = tmpstr->substr(0,pos); mDebug("slackRequired = " + slackRequired); } else { mDebug("no required list"); slackRequired.clear(); } pos = tmpstr->find(pkgSuggestsKeyword); if (pos < tmpstr->find(pkgNameKeyword)) { mDebug("suggest list present!"); *tmpstr = tmpstr->substr(pos + pkgSuggestsKeyword.length()); pos = tmpstr->find("\n"); slackSuggests = tmpstr->substr(0,pos); mDebug("slackSuggests = " + slackSuggests); } else { slackSuggests.clear(); mDebug("no suggest list"); } pos = tmpstr->find(pkgDescriptionKeyword); *tmpstr = tmpstr->substr(pos + pkgSuggestsKeyword.length()+1); // +1 because there are newline pos = tmpstr->find(pkgNameKeyword); mDebug("searched end"); if (pos == std::string::npos) { mDebug("description end reached"); slackDescription = *tmpstr; mDebug("slackDescription = " + slackDescription); endReached = true; } else { slackDescription = tmpstr->substr(0,pos-1); mDebug("slackDescription = "+ slackDescription); } // Stage 2: info cleanup // Filename pkg->set_filename(&slackPackageName); if (md5list->find(slackPackageName) == std::string::npos) { mError("MD5 checksum not found for package " + slackPackageName +", skipping"); } else { mDebug("md5 found"); md5tmp = md5list->substr(0,md5list->find(slackPackageName)); } md5tmp = md5tmp.substr(0, md5tmp.find_last_of(" \t")); md5tmp = md5tmp.substr(md5tmp.rfind("\n")+1); md5tmp = cutSpaces(md5tmp); pkg->set_md5(&md5tmp); mDebug("MD5 = " + md5tmp); filename = slackPackageName; // Name, version, arch, build pos = slackDescription.find(":"); mDebug("pos = "+IntToStr(pos)); tmp.clear(); if (true) { name_start=0; for (int i=filename.length()-1; filename[i]!='/' && i>=0; i--) { name_start=i; } for (unsigned int i=name_start; i<filename.length()-1; i++) { if (filename[i]=='-') { if (filename[i+1]=='0' || \ filename[i+1] == '1' || \ filename[i+1] == '2' || \ filename[i+1] == '3' || \ filename[i+1] == '4' || \ filename[i+1] == '5' || \ filename[i+1] == '6' || \ filename[i+1] == '7' || \ filename[i+1] == '8' || \ filename[i+1] == '9') { pkg->set_name(&tmp); pos=i+2; break; } } tmp+=filename[i]; } tmp.clear(); //VERSION for (unsigned int i=pos-1; i< filename.length(); i++) { if (filename[i]=='-') { pkg->set_version(&tmp); pos=i+2; break; } tmp+=filename[i]; } tmp.clear(); //ARCH for (unsigned int i=pos-1; i< filename.length(); i++) { if (filename[i]=='-') { pkg->set_arch(&tmp); pos=i+2; break; } tmp+=filename[i]; } tmp.clear(); //BUILD for (unsigned int i=pos-1; i<filename.length()-4; i++) { tmp+=filename[i]; } pkg->set_build(&tmp); tmp.clear(); } mDebug("package name: "+ *pkg->get_name()); mDebug("package version: "+ *pkg->get_version()); mDebug("package arch: "+ *pkg->get_arch()); mDebug("package build: "+ *pkg->get_build()); // Location if (slackPackageLocation.find("./") == 0) { mDebug("DOTCUT:"); slackPackageLocation = slackPackageLocation.substr(2); } tmplocation->set_path(&slackPackageLocation); tmplocation->set_server_url(&server_url); pkg->get_locations()->push_back(*tmplocation); //mDebug("LOC_SET: "+*pkg->get_locations()->at(0)->get_path()); // Size tmpSize = atoi(slackCompressedSize.substr(0, slackCompressedSize.length()-2).c_str()); *pkg->get_compressed_size()=IntToStr(tmpSize*1024); mDebug("package size (compressed): "+ *pkg->get_compressed_size()); tmpSize = atoi(slackUncompressedSize.substr(0, slackUncompressedSize.length()-2).c_str()); *pkg->get_installed_size()=IntToStr(tmpSize*1024); mDebug("package size (uncompressed): "+ *pkg->get_installed_size()); mDebug("reached description"); // Description tmpDescStr->clear(); if (slackDescription.length()>0) { slackDescription = slackDescription.substr(1); if (slackDescription.length() >= slackDescription.find(*pkg->get_name()+": ") + pkg->get_name()->length()+2) { slackDescription = slackDescription.substr(slackDescription.find(*pkg->get_name()+": ")+pkg->get_name()->length()+2); //tmpDesc->set_shorttext(slackDescription.substr(0, slackDescription.find_first_of("\n"))); *pkg->get_short_description()=slackDescription.substr(0, slackDescription.find_first_of("\n")); //mDebug("short description: "+slackDescription.substr(0, slackDescription.find_first_of("\n"))); } pos = slackDescription.find("\n"); lines = 0; while (pos != std::string::npos && lines < 11) { pos = slackDescription.find(*pkg->get_name()+": "); if (pos == std::string::npos) { mDebug("Description end"); } else { slackDescription = slackDescription.substr(pos+pkg->get_name()->length()+2); *tmpDescStr = *tmpDescStr + slackDescription.substr(0,slackDescription.find("\n"))+"\n"; lines++; } } mDebug("Description: "+ *tmpDescStr); //tmpDesc->set_text(*tmpDescStr); pkg->set_description(tmpDescStr); #ifdef ENABLE_INTERNATIONAL pkg->get_descriptions()->add(tmpDesc); #endif } pkglist->add(pkg); pkg->clear(); num++; mDebug("done"); } delete pkg; delete tmplocation; //delete tmpDesc; delete tmpDescStr; //delete tmpstr; return 0; } // End slackpackages2list()