#include "Sources.hpp" #include #include #include #include #include #include #include #include #include using namespace std; using namespace net::lliurex::apt; string SourceLine::ToString() { stringstream ss; ss.str(""); ss<< ((source_type==SourceType::Deb) ? "deb" : "deb-src"); ss<<" "; switch(uri_type) { case UriType::Http: ss<<"http://"; break; case UriType::Https: ss<<"https://"; break; case UriType::Ftp: ss<<"ftp://"; break; case UriType::File: ss<<"file://"; break; case UriType::Cdrom: ss<<"cdrom:"; break; } ss< regex_line = Glib::Regex::create(Sources::str_line); Glib::RefPtr regex_option = Glib::Regex::create(Sources::str_option); ifstream file(filename); optional=false; name["C"]="noname"; while(!file.eof()) { string line; getline(file,line);//read a single line from the file Glib::MatchInfo info; //have we got a match? if(regex_line->match(line,info)) { string type; string uri_type; string uri; string dist; string components; vector vcmp; //fetch matching groups type = info.fetch_named("deb_type"); uri_type=info.fetch_named("uri_type"); uri=info.fetch_named("uri"); dist = info.fetch_named("dist"); components=info.fetch_named("components"); //split components string buf; stringstream ss(components.substr(1)); while(ss >> buf) vcmp.push_back(buf); //fill SourceLine object SourceLine sl; if(type=="deb")sl.source_type=SourceType::Deb; if(type=="deb-src")sl.source_type=SourceType::Source; if(uri_type=="http://")sl.uri_type=UriType::Http; if(uri_type=="https://")sl.uri_type=UriType::Https; if(uri_type=="file://")sl.uri_type=UriType::File; if(uri_type=="ftp://")sl.uri_type=UriType::Ftp; if(uri_type=="cdrom:")sl.uri_type=UriType::Cdrom; //remove all ending slashs while(uri[uri.length()-1]=='/') { uri=uri.substr(0,uri.length()-1); } sl.uri=uri; sl.dist=dist; sl.components = vcmp; //and Push it up Push(sl); } else { if(regex_option->match(line,info)) { string key=info.fetch_named("key"); string value=info.fetch_named("value"); string locale=info.fetch_named("locale"); if(key=="optional") { optional=(value=="true"); } if(key=="name") { locale=(locale=="") ? "C" : locale; name[locale]=value; } } } } file.close(); } void Sources::Add(string line) { Glib::RefPtr regex_line = Glib::Regex::create(Sources::str_line); Glib::MatchInfo info; if(regex_line->match(line,info)) { string type; string uri_type; string uri; string dist; string components; vector vcmp; //fetch matching groups type = info.fetch_named("deb_type"); uri_type=info.fetch_named("uri_type"); uri=info.fetch_named("uri"); dist = info.fetch_named("dist"); components=info.fetch_named("components"); //split components string buf; stringstream ss(components.substr(1)); while(ss >> buf) vcmp.push_back(buf); //fill SourceLine object SourceLine sl; if(type=="deb")sl.source_type=SourceType::Deb; if(type=="deb-src")sl.source_type=SourceType::Source; if(uri_type=="http://")sl.uri_type=UriType::Http; if(uri_type=="https://")sl.uri_type=UriType::Https; if(uri_type=="file://")sl.uri_type=UriType::File; if(uri_type=="ftp://")sl.uri_type=UriType::Ftp; if(uri_type=="cdrom:")sl.uri_type=UriType::Cdrom; sl.uri=uri; sl.dist=dist; sl.components = vcmp; //and Push it up Push(sl); } else { throw runtime_error("Failed to parse source line"); } } void Sources::Push(SourceLine line) { bool found = false; for(int n = 0;n0) { ret=FindLineStatus::Found; } else { if(p>0) { ret=FindLineStatus::Partial; } else { ret=FindLineStatus::NotFound; } } return ret; } Sources net::lliurex::apt::operator+(Sources & A,Sources & B) { Sources R; R.lines = A.lines; for(SourceLine line : B.lines) { R.Push(line); } return R; } void Sources::Print() { for(int n=0;n