~ubuntu-branches/ubuntu/oneiric/libktorrent/oneiric

« back to all changes in this revision

Viewing changes to src/torrent/torrent.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Modestas Vainius
  • Date: 2011-05-26 00:33:38 UTC
  • mfrom: (5.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110526003338-2r4zwyzn8bovsxay
Tags: 1.1.1-2
Release to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
{
40
40
        static QString SanityzeName(const QString & name)
41
41
        {
 
42
                QString ret = name;
42
43
#ifdef Q_WS_WIN
43
 
                QString ret = name;
44
44
                char invalid[] = {'<','>',':','"','/','\\','|','?','*'};
45
45
                for (int i = 0;i < 9;i++)
46
46
                {
47
47
                        if (ret.contains(invalid[i]))
48
48
                                ret = ret.replace(invalid[i],'_');
49
49
                }
50
 
                
51
 
                return ret;
52
50
#else
53
 
                if (name.endsWith("/"))
54
 
                        return name.left(name.length() - 1);
55
 
                return name;
 
51
                if (ret.endsWith("/"))
 
52
                        ret = ret.left(ret.length() - 1);
 
53
                if (ret.startsWith("/"))
 
54
                        ret = ret.mid(1);
56
55
#endif
 
56
                // Don't allow directory traversal things in names
 
57
                if (ret.contains("/") || ret.contains(".."))
 
58
                {
 
59
                        QStringList sl = ret.split(bt::DirSeparator());
 
60
                        sl.removeAll("..");
 
61
                        ret = sl.join("_");
 
62
                }
 
63
                
 
64
                return ret;
57
65
        }
58
66
 
59
67
        Torrent::Torrent() : chunk_size(0),total_size(0),priv_torrent(false),pos_cache_chunk(0),pos_cache_file(0),tmon(0)
154
162
        {
155
163
                QFile fptr(file);
156
164
                if (!fptr.open(QIODevice::ReadOnly))
157
 
                        throw Error(i18n(" Unable to open torrent file %1 : %2", file, fptr.errorString()));
 
165
                        throw Error(i18n("Unable to open torrent file %1: %2", file, fptr.errorString()));
158
166
                
159
167
                QByteArray data = fptr.readAll();
160
168
                load(data,verbose);
283
291
                for (Uint32 i = 0;i < ml->getNumChildren();i++)
284
292
                {
285
293
                        BListNode* url_list = ml->getList(i);
286
 
                        if (!url_list)
287
 
                                throw Error(i18n("Parse Error"));
288
 
                        
289
 
                        for (Uint32 j = 0;j < url_list->getNumChildren();j++)
 
294
                        if (url_list)
290
295
                        {
291
 
                                KUrl url(url_list->getString(j,0));
292
 
                                tier->urls.append(url);
 
296
                                for (Uint32 j = 0;j < url_list->getNumChildren();j++)
 
297
                                {
 
298
                                        KUrl url(url_list->getString(j,0));
 
299
                                        tier->urls.append(url);
 
300
                                }
 
301
                                tier->next = new TrackerTier();
 
302
                                tier = tier->next;
293
303
                        }
294
 
                        tier->next = new TrackerTier();
295
 
                        tier = tier->next;
296
304
                }
297
305
        }
298
306