~ubuntu-branches/ubuntu/quantal/aria2/quantal

« back to all changes in this revision

Viewing changes to src/ProtocolDetector.cc

  • Committer: Package Import Robot
  • Author(s): Kartik Mistry
  • Date: 2011-11-08 20:25:08 UTC
  • mfrom: (2.5.7 sid)
  • Revision ID: package-import@ubuntu.com-20111108202508-scfph8rj6tz0cckk
Tags: 1.13.0-1
* New upstream version:
  + Depends on libgcrypt11 (>= 1.5.0-3) (Closes: #642989)

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
#include "ProtocolDetector.h"
36
36
 
37
37
#include <cstring>
38
 
#include <fstream>
39
38
#include <iomanip>
40
39
 
41
40
#include "Request.h"
43
42
#include "util.h"
44
43
#include "RecoverableException.h"
45
44
#include "uri.h"
 
45
#include "BufferedFile.h"
46
46
#ifdef ENABLE_BITTORRENT
47
47
# include "bittorrent_helper.h"
48
48
#endif // ENABLE_BITTORRENT
61
61
 
62
62
bool ProtocolDetector::guessTorrentFile(const std::string& uri) const
63
63
{
64
 
  if(!File(uri).isFile()) {
65
 
    return false;
66
 
  }
67
 
  std::ifstream in(uri.c_str(), std::ios::binary);
68
 
  if(in) {
69
 
    char head;
70
 
    in >> head;
71
 
    return head == 'd';
 
64
  BufferedFile fp(uri, BufferedFile::READ);
 
65
  if(fp) {
 
66
    char head[1];
 
67
    if(fp.read(head, sizeof(head)) == sizeof(head)) {
 
68
      return head[0] == 'd';
 
69
    } else {
 
70
      return false;
 
71
    }
72
72
  } else {
73
73
    return false;
74
74
  }
90
90
 
91
91
bool ProtocolDetector::guessMetalinkFile(const std::string& uri) const
92
92
{
93
 
  if(!File(uri).isFile()) {
94
 
    return false;
95
 
  }
96
 
  std::ifstream in(uri.c_str(), std::ios::binary);
97
 
  if(in) {
98
 
    char head[6];
99
 
    in >> std::setw(6) >> head;
100
 
    return strcmp(head, "<?xml") == 0;
 
93
  BufferedFile fp(uri, BufferedFile::READ);
 
94
  if(fp) {
 
95
    char head[5];
 
96
    if(fp.read(head, sizeof(head)) == sizeof(head)) {
 
97
      return memcmp(head, "<?xml", 5) == 0;
 
98
    } else {
 
99
      return false;
 
100
    }
101
101
  } else {
102
102
    return false;
103
103
  }