1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
|
#include "stdafx.h" <----N'était pas présent avant
using namespace std;
class descripteur
{
private :
string name[100]; //Permet de stocker les noms des fichiers contenu dans le fichier metalink
string hash[100]; //Permet de stocker les "Hashing algorithms" (algorithmes de brouillage)
string hash2[100]; //Stock la valeur retournée par cette algorithme
string http[10000]; //Stock les adresses http
string ftp[10000]; //Stock les adresses ftp
string torrent[1000]; //Stock les adresses torrent
int cptHash; //Permet de connaitre le nombre de "Hash" dans le tableau "hash"
int cptHTTP; //Permet de connaitre le nombre d'adresses http contenues le tableau
int cptFTP; //Permet de connaitre le nombre d'adresses ftp contenues dans le tableau
int cptTorrent; //Permet de connaitre le nombre d'adresses torrent contenues dans le tableau
int cptName; //Permet de connaitre le nombres de fichiers contenu dans le tableau
int total;
public :
descripteur()
{
cptHash=0;
cptHTTP=0;
cptFTP=0;
cptTorrent=0;
cptName=0;
total=0;
}
bool raffraichi(string mot)
{
bool OK = false;
int i = 0;
int j = 0;
while(!OK)
{
string s = mot.substr(0,3);
if(strcmp(s.c_str(),"typ")==0)
{
i=0;
while(mot.c_str()[i]!='"')
i++;
s = mot.substr(i+1);
j = 0;
while(s.c_str()[j]!='"')
j++;
s = s.substr(j+1);
//Maintenant on test pour savoir si l'adresse du fichier se trouve
//à la suite du champ "type"
if(s=="")
{
//Donc l'adresse ne se trouve pas à la suite du champ "type", car
//un espace sépare le champ "type" de l'adresse
return false;
}
else
{
return true;
}
}
s = mot.substr(0,3);
if(strcmp(s.c_str(),"pre")==0)
{
//données concernant les préférences
i=0;
while(mot.c_str()[i]!='"')
i++;
s = mot.substr(i+1);
j = 0;
while(s.c_str()[j]!='"')
j++;
s = s.substr(j+1);
//Maintenant on test pour savoir si l'adresse du fichier se trouve
//à la suite du champ "preference"
if(s=="")
{
//Donc l'adresse ne se trouve pas à la suite du champ "préférence", car
//un espace sépare le champ "preference" de l'adresse
return false;
}
else
{
//l'adresse se trouve à la suite du champ "preference", car il est
//suivi du caractère '>'
return true;
}
}
s = mot.substr(0,3);
if(strcmp(s.c_str(),"loc")==0)
{
//données concernant le pays de téléchargement
i=0;
while(mot.c_str()[i]!='"')
i++;
s = mot.substr(i+1);
j = 0;
while(s.c_str()[j]!='"')
j++;
s = s.substr(j+1);
//Maintenant on test pour savoir si l'adresse du fichier se trouve
//à la suite du champ "location"
if(s=="")
{
//Donc l'adresse ne se trouve pas à la suite du champ "location", car
//un espace sépare le champ "location" de l'adresse
return false;
}
else
{
//l'adresse se trouve à la suite du champ "location", car il est
//suivi du caractère '>'
return true;
}
}
}
return false;
}
void lire(HWND hwnd, char* source)
{
wstring texte=L"OK PASSE";//L"OK Metalink";
wstring caption=loadstring(/*IDS_EXCEPTION*/123);
wstring s=texte.substr(texte.length()-9);
MessageBox(hwnd, texte.c_str(), caption.c_str(), MB_ICONERROR|MB_OK);
std::ifstream f (source);
if (!f)
{
wstring texte=L"Impossible d'ouvrir le fichier";//L"OK Metalink";
wstring caption=loadstring(/*IDS_EXCEPTION*/123);
wstring s=texte.substr(texte.length()-9);
MessageBox(hwnd, texte.c_str(), caption.c_str(), MB_ICONERROR|MB_OK);
exit(0);
}
else
{
std::string mot="";
f >> mot;
if(strcmp(mot.c_str(),"<?xml")==0)
{
f>>mot;
f>>mot;
f>>mot;
}
if(strcmp(mot.c_str(),"<metalink")==0)
{
//Donc le type de fichier est valide
while(strcmp(mot.c_str(),"</metalink>")!=0 && !f.eof())
{
getline(f,mot);
while(!strcmp(mot.c_str(),"<files>")==0)
f>>mot;
if(strcmp(mot.c_str(),"<files>")==0)
{
f>>mot;
while(strcmp(mot.c_str(),"</files>")!=0 && !f.eof())
{
if(strcmp(mot.c_str(),"<file")==0)
{
f>>mot;
int i=0;
while(mot.c_str()[i]!='"')
i++;
string s = mot.substr(i+1);
int j=0;
while(s.c_str()[j]!='"')
j++;
name[cptName] = s.substr(0,j);
cptName++;
f>>mot;
}
bool passe=false;
if(strcmp(mot.c_str(),"<resources>")==0)
passe=true;
while(!passe)
{
if(strcmp(mot.c_str(),"<verification>")==0)
{
f>>mot;
while(strcmp(mot.c_str(),"</verification>")!=0)
{
if(strcmp(mot.c_str(),"<hash "))
{
f>>mot;
int i=0;
while(mot.c_str()[i]!='"')
i++;
string s=mot.substr(i+1);
int j=0;
while(s.c_str()[j]!='"')
j++;
s=s.substr(0,j);
string id=s;
mot=mot.substr(i+j+3);
i=0;
while(mot.c_str()[i]!='<')
i++;
s=mot.substr(0,i);
hash[cptHash]=id;
hash2[cptHash]=s;
cptHash++;
f>>mot;
passe=true;
}
else
{
cout<<"Problème Hash"<<endl;
exit(0);
}
}//while(strcmp(mot.c_str(),"</verification>")!=0)
}
else
{
passe=true;
}
}
//Toute la boucle de vérification a donc été lue
//Maintenant, on passe aux ressources
if(!strcmp(mot.c_str(),"<resources>")==0)
f>>mot;
if(strcmp(mot.c_str(),"<resources>")==0)
{
//Nous regardons bien les ressources
while(!(strcmp(mot.c_str(),"</resources>")==0))
{
f>>mot;
if(strcmp(mot.c_str(),"<url")==0)
{
f>>mot;
string s = mot.substr(0,3);
int i=0;
int j=0;
if(strcmp(s.c_str(),"typ")==0)
{
//On ne fait rien pour le moment, afin de récupérer le type
}
else
{
s = mot.substr(0,3);
if(strcmp(s.c_str(),"pre")==0)
{
//données concernant les préférences
i=0;
while(mot.c_str()[i]!='"')
i++;
s = mot.substr(i+1);
j = 0;
while(s.c_str()[j]!='"')
j++;
s = s.substr(j+1);
//Maintenant on test pour savoir si l'adresse du fichier se trouve
//à la suite du champ "preference"
if(s=="")
{
//Donc l'adresse ne se trouve pas à la suite du champ "preference", car
//un espace sépare le champ "preference" de l'adresse
f>>mot;
}
else
{
//l'adresse se trouve à la suite du champ "preference", car il est
//suivi du caractère '>'
s=s.substr(1);
mot=s;
}
}
s = mot.substr(0,3);
if(strcmp(s.c_str(),"loc")==0)
{
//données concernant le pays de téléchargement
i=0;
while(mot.c_str()[i]!='"')
i++;
s = mot.substr(i+1);
j = 0;
while(s.c_str()[j]!='"')
j++;
s = s.substr(j+1);
//Maintenant on test pour savoir si l'adresse du fichier se trouve
//à la suite du champ "location"
if(s=="")
{
//Donc l'adresse ne se trouve pas à la suite du champ "location", car
//un espace sépare le champ "location" de l'adresse
f>>mot;
}
else
{
//l'adresse se trouve à la suite du champ "location", car il est
//suivi du caractère '>'
mot=s;
}
}
}
i=0;
while(mot.c_str()[i]!='"')
i++;
s=mot.substr(i+1);
j=0;
while(s.c_str()[j]!='"')
j++;
string id=s.substr(0,j);
//id contient soit ftp, soit http, soit bittorrent
bool test=false;
while(!test)
{
test=raffraichi(mot);
if(!test)
f>>mot;
}
if(strcmp(id.c_str(),"ftp")==0 || strcmp(id.c_str(),"http")==0 || strcmp(id.c_str(),"bittorrent")==0)
{
bool OK = false;
while(!OK)
{
OK = raffraichi(mot);
if(!OK)
f>>mot;
}
//A ce moment, nous récupérons un string de type :
//..."...">adresse</url>
//Donc il faut enlever la balise ...> et </url>
i=0;
while(mot.c_str()[i]!='"')
i++;
s = mot.substr(i+1);
j=0;
while(s.c_str()[j]!='"')
j++;
mot = s.substr(j+2);
//Il reste :
//adresse</url>
i=0;
while(mot.substr()[i]!='<')
i++;
s=mot.substr(0,i);
//Donc s contient uniquement l'adresse
//Maintenant que les informations ont été récupérées,
//il faut savoir où les stocker
if(strcmp(id.c_str(),"ftp")==0)
{
//Stocke dans le tableau contenant toutes les adresses ftp
total++;
ftp[cptFTP]=s;
cptFTP++;
}
else
{
if(strcmp(id.c_str(),"http")==0)
{
//Stocke dans le tableau contenant toutes les adresses http
//Pour le téléchargement direct
total++;
http[cptHTTP]=s;
cptHTTP++;
}
else
{
if(strcmp(id.c_str(),"bittorrent")==0)
{
//Stocke dans le tableau contenant toutes les adresses torrent
//Afin de télécharger via un client bittorrent
total++;
torrent[cptTorrent]=s;
cptTorrent++;
}
}
}
}//if(strcmp(id,"ftp")...);
}//if(strcmp(mot.c_str(),"<url")==0)
}//while(strcmp(mot.c_str(),"</ressources>")!=0)
f>>mot;
}//if(strcmp(mot.c_str(),"<resources>")==0)
if(strcmp(mot.c_str(),"</file>")==0)
f>>mot;
}//while(strcmp(mot.c_str(),"</files>")!=0 && !f.eof())
}//if(strcmp(mot.c_str(),"<files>")==0)
f>>mot;
}//while(strcmp(mot.c_str(),"<\metalink")==0)
}//if(strcmp(mot.c_str(),"<metalink")==0)
}//else if(!f)
f.close ();
}
}; |
Partager