diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/AlphaNumberDecorator.h | 84 | ||||
| -rw-r--r-- | src/FixedWidthNumberDecorator.h | 60 | ||||
| -rw-r--r-- | src/Makefile.am | 12 | ||||
| -rw-r--r-- | src/Makefile.in | 29 | ||||
| -rw-r--r-- | src/NumberDecorator.h | 49 | ||||
| -rw-r--r-- | src/OptionHandlerFactory.cc | 1 | ||||
| -rw-r--r-- | src/PStringBuildVisitor.cc | 54 | ||||
| -rw-r--r-- | src/PStringBuildVisitor.h | 68 | ||||
| -rw-r--r-- | src/PStringDatum.h | 51 | ||||
| -rw-r--r-- | src/PStringNumLoop.h | 100 | ||||
| -rw-r--r-- | src/PStringSegment.cc | 49 | ||||
| -rw-r--r-- | src/PStringSegment.h | 89 | ||||
| -rw-r--r-- | src/PStringSelect.h | 76 | ||||
| -rw-r--r-- | src/PStringVisitor.h | 47 | ||||
| -rw-r--r-- | src/ParameterizedStringParser.cc | 145 | ||||
| -rw-r--r-- | src/ParameterizedStringParser.h | 56 | ||||
| -rw-r--r-- | src/RequestInfo.h | 1 | ||||
| -rw-r--r-- | src/Util.cc | 59 | ||||
| -rw-r--r-- | src/Util.h | 8 | ||||
| -rw-r--r-- | src/main.cc | 66 | ||||
| -rw-r--r-- | src/prefs.h | 2 |
21 files changed, 1092 insertions, 14 deletions
diff --git a/src/AlphaNumberDecorator.h b/src/AlphaNumberDecorator.h new file mode 100644 index 00000000..03f9dc7a --- /dev/null +++ b/src/AlphaNumberDecorator.h @@ -0,0 +1,84 @@ +/* <!-- copyright */ +/* + * aria2 - The high speed download utility + * + * Copyright (C) 2006 Tatsuhiro Tsujikawa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations + * including the two. + * You must obey the GNU General Public License in all respects + * for all of the code used other than OpenSSL. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you + * do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source + * files in the program, then also delete it here. + */ +/* copyright --> */ +#ifndef _D_ALPHA_NUMBER_DECORATOR_H_ +#define _D_ALPHA_NUMBER_DECORATOR_H_ + +#include "NumberDecorator.h" +#include "FatalException.h" + +class AlphaNumberDecorator : public NumberDecorator +{ +private: + + int32_t _width; + + string _zero; + + string widen(const string& s, int32_t width) + { + string t = s; + while(t.size() < (size_t)width) { + t.insert(0, _zero); + } + return t; + } + +public: + AlphaNumberDecorator(int32_t width, bool uppercase = false): + _width(width), _zero(uppercase?"A":"a") {} + + virtual ~AlphaNumberDecorator() {} + + virtual string decorate(int32_t number) + { + if(number < 0) { + throw new FatalException("The number must be greater than 0."); + } + if(number == 0) { + return widen(_zero, _width); + } + int32_t base = 26; + string x; + while(number > 0) { + int32_t r = number%base; + char alpha = _zero[0]+r; + x.insert(0, string(1, alpha)); + number /= base; + } + return widen(x, _width); + } +}; + +#endif // _D_ALPHA_NUMBER_DECORATOR_H_ diff --git a/src/FixedWidthNumberDecorator.h b/src/FixedWidthNumberDecorator.h new file mode 100644 index 00000000..6ee8160d --- /dev/null +++ b/src/FixedWidthNumberDecorator.h @@ -0,0 +1,60 @@ +/* <!-- copyright */ +/* + * aria2 - The high speed download utility + * + * Copyright (C) 2006 Tatsuhiro Tsujikawa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations + * including the two. + * You must obey the GNU General Public License in all respects + * for all of the code used other than OpenSSL. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you + * do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source + * files in the program, then also delete it here. + */ +/* copyright --> */ +#ifndef _D_FIXED_WIDTH_NUMBER_DECORATOR_H_ +#define _D_FIXED_WIDTH_NUMBER_DECORATOR_H_ + +#include "NumberDecorator.h" +#include "Util.h" + +class FixedWidthNumberDecorator : public NumberDecorator +{ +private: + int32_t _width; +public: + FixedWidthNumberDecorator(int32_t width):_width(width) {} + + virtual ~FixedWidthNumberDecorator() {} + + virtual string decorate(int32_t number) + { + string s = Util::itos(number); + while(s.size() < (size_t)_width) { + s.insert(0, "0"); + } + return s; + } +}; + +#endif // _D_FIXED_WIDTH_NUMBER_DECORATOR_H_ diff --git a/src/Makefile.am b/src/Makefile.am index 0fa8004d..697b4af4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -98,7 +98,17 @@ SRCS = Socket.h\ CookieBoxFactory.cc CookieBoxFactory.h\ HttpHeaderProcessor.cc HttpHeaderProcessor.h\ FileEntry.cc FileEntry.h\ - Platform.cc Platform.h + Platform.cc Platform.h\ + PStringDatum.h\ + PStringSegment.cc PStringSegment.h\ + PStringNumLoop.h\ + PStringSelect.h\ + PStringVisitor.h\ + PStringBuildVisitor.cc PStringBuildVisitor.h\ + ParameterizedStringParser.cc ParameterizedStringParser.h\ + FixedWidthNumberDecorator.h\ + NumberDecorator.h\ + AlphaNumberDecorator.h # debug_new.cpp if ENABLE_MESSAGE_DIGEST diff --git a/src/Makefile.in b/src/Makefile.in index 6e00d78e..cba6ff5d 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -256,8 +256,13 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \ CookieParser.cc CookieParser.h CookieBoxFactory.cc \ CookieBoxFactory.h HttpHeaderProcessor.cc \ HttpHeaderProcessor.h FileEntry.cc FileEntry.h Platform.cc \ - Platform.h ChunkChecksumValidator.cc ChunkChecksumValidator.h \ - IteratableChunkChecksumValidator.cc \ + Platform.h PStringDatum.h PStringSegment.cc PStringSegment.h \ + PStringNumLoop.h PStringSelect.h PStringVisitor.h \ + PStringBuildVisitor.cc PStringBuildVisitor.h \ + ParameterizedStringParser.cc ParameterizedStringParser.h \ + FixedWidthNumberDecorator.h NumberDecorator.h \ + AlphaNumberDecorator.h ChunkChecksumValidator.cc \ + ChunkChecksumValidator.h IteratableChunkChecksumValidator.cc \ IteratableChunkChecksumValidator.h \ IteratableChecksumValidator.cc IteratableChecksumValidator.h \ ChecksumCommand.cc ChecksumCommand.h CheckIntegrityCommand.cc \ @@ -464,7 +469,9 @@ am__objects_12 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \ RealtimeCommand.$(OBJEXT) RequestGroupEntry.$(OBJEXT) \ Cookie.$(OBJEXT) CookieParser.$(OBJEXT) \ CookieBoxFactory.$(OBJEXT) HttpHeaderProcessor.$(OBJEXT) \ - FileEntry.$(OBJEXT) Platform.$(OBJEXT) $(am__objects_1) \ + FileEntry.$(OBJEXT) Platform.$(OBJEXT) \ + PStringSegment.$(OBJEXT) PStringBuildVisitor.$(OBJEXT) \ + ParameterizedStringParser.$(OBJEXT) $(am__objects_1) \ $(am__objects_2) $(am__objects_3) $(am__objects_4) \ $(am__objects_5) $(am__objects_6) $(am__objects_7) \ $(am__objects_8) $(am__objects_9) $(am__objects_10) \ @@ -721,10 +728,15 @@ SRCS = Socket.h SocketCore.cc SocketCore.h Command.cc Command.h \ CookieParser.cc CookieParser.h CookieBoxFactory.cc \ CookieBoxFactory.h HttpHeaderProcessor.cc \ HttpHeaderProcessor.h FileEntry.cc FileEntry.h Platform.cc \ - Platform.h $(am__append_1) $(am__append_2) $(am__append_3) \ - $(am__append_4) $(am__append_5) $(am__append_6) \ - $(am__append_7) $(am__append_8) $(am__append_9) \ - $(am__append_10) $(am__append_11) + Platform.h PStringDatum.h PStringSegment.cc PStringSegment.h \ + PStringNumLoop.h PStringSelect.h PStringVisitor.h \ + PStringBuildVisitor.cc PStringBuildVisitor.h \ + ParameterizedStringParser.cc ParameterizedStringParser.h \ + FixedWidthNumberDecorator.h NumberDecorator.h \ + AlphaNumberDecorator.h $(am__append_1) $(am__append_2) \ + $(am__append_3) $(am__append_4) $(am__append_5) \ + $(am__append_6) $(am__append_7) $(am__append_8) \ + $(am__append_9) $(am__append_10) $(am__append_11) noinst_LIBRARIES = libaria2c.a libaria2c_a_SOURCES = $(SRCS) aria2c_LDADD = libaria2c.a @LIBINTL@ @ALLOCA@ @LIBGNUTLS_LIBS@\ @@ -927,6 +939,9 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Option.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/OptionHandlerFactory.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/OptionParser.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PStringBuildVisitor.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PStringSegment.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ParameterizedStringParser.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Peer.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PeerAbstractCommand.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/PeerChokeCommand.Po@am__quote@ diff --git a/src/NumberDecorator.h b/src/NumberDecorator.h new file mode 100644 index 00000000..0f0f2733 --- /dev/null +++ b/src/NumberDecorator.h @@ -0,0 +1,49 @@ +/* <!-- copyright */ +/* + * aria2 - The high speed download utility + * + * Copyright (C) 2006 Tatsuhiro Tsujikawa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations + * including the two. + * You must obey the GNU General Public License in all respects + * for all of the code used other than OpenSSL. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you + * do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source + * files in the program, then also delete it here. + */ +/* copyright --> */ +#ifndef _D_NUMBER_DECORATOR_H_ +#define _D_NUMBER_DECORATOR_H_ + +#include "common.h" + +class NumberDecorator { +public: + virtual ~NumberDecorator() {} + + virtual string decorate(int32_t number) = 0; +}; + +typedef SharedHandle<NumberDecorator> NumberDecoratorHandle; + +#endif // _D_NUMBER_DECORATOR_H_ diff --git a/src/OptionHandlerFactory.cc b/src/OptionHandlerFactory.cc index 14718731..c3d466d5 100644 --- a/src/OptionHandlerFactory.cc +++ b/src/OptionHandlerFactory.cc @@ -94,6 +94,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers() handlers.push_back(new NumberOptionHandler(PREF_MAX_CONCURRENT_DOWNLOADS, 1, 45)); handlers.push_back(new DefaultOptionHandler(PREF_LOAD_COOKIES)); handlers.push_back(new DefaultOptionHandler(PREF_PEER_ID_PREFIX)); + handlers.push_back(new BooleanOptionHandler(PREF_FORCE_SEQUENTIAL)); return handlers; } diff --git a/src/PStringBuildVisitor.cc b/src/PStringBuildVisitor.cc new file mode 100644 index 00000000..7487b45b --- /dev/null +++ b/src/PStringBuildVisitor.cc @@ -0,0 +1,54 @@ +/* <!-- copyright */ +/* + * aria2 - The high speed download utility + * + * Copyright (C) 2006 Tatsuhiro Tsujikawa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations + * including the two. + * You must obey the GNU General Public License in all respects + * for all of the code used other than OpenSSL. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you + * do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source + * files in the program, then also delete it here. + */ +/* copyright --> */ +#include "PStringBuildVisitor.h" + +void PStringBuildVisitor::hello(PStringSegment* segment) +{ + string uri; + if(_buildQueue.empty()) { + uri += segment->getValue(); + } else { + uri = _buildQueue.front()+segment->getValue(); + } + _buildQueue.push_front(uri); + if(!segment->hasNext()) { + _uris.push_back(uri); + } +} + +void PStringBuildVisitor::goodbye(PStringSegment* segment) +{ + _buildQueue.pop_front(); +} diff --git a/src/PStringBuildVisitor.h b/src/PStringBuildVisitor.h new file mode 100644 index 00000000..4bb01d07 --- /dev/null +++ b/src/PStringBuildVisitor.h @@ -0,0 +1,68 @@ +/* <!-- copyright */ +/* + * aria2 - The high speed download utility + * + * Copyright (C) 2006 Tatsuhiro Tsujikawa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations + * including the two. + * You must obey the GNU General Public License in all respects + * for all of the code used other than OpenSSL. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you + * do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source + * files in the program, then also delete it here. + */ +/* copyright --> */ +#ifndef _D_P_STRING_BUILD_VISITOR_H_ +#define _D_P_STRING_BUILD_VISITOR_H_ + +#include "PStringSegment.h" + +class PStringBuildVisitor : public PStringVisitor, public PStringSegmentVisitor +{ +private: + + Strings _buildQueue; + + Strings _uris; + +public: + + virtual void hello(PStringSegment* segment); + + virtual void goodbye(PStringSegment* segment); + + const Strings& getURIs() const + { + return _uris; + } + + void reset() + { + _buildQueue.clear(); + _uris.clear(); + } +}; + +typedef SharedHandle<PStringBuildVisitor> PStringBuildVisitorHandle; + +#endif // _D_P_STRING_BUILD_VISITOR_H_ diff --git a/src/PStringDatum.h b/src/PStringDatum.h new file mode 100644 index 00000000..7a000ce2 --- /dev/null +++ b/src/PStringDatum.h @@ -0,0 +1,51 @@ +/* <!-- copyright */ +/* + * aria2 - The high speed download utility + * + * Copyright (C) 2006 Tatsuhiro Tsujikawa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations + * including the two. + * You must obey the GNU General Public License in all respects + * for all of the code used other than OpenSSL. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you + * do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source + * files in the program, then also delete it here. + */ +/* copyright --> */ +#ifndef _D_P_STRING_DATUM_H_ +#define _D_P_STRING_DATUM_H_ + +#include "common.h" +#include "PStringVisitor.h" + +class PStringDatum { +public: + virtual ~PStringDatum() {} + + virtual void accept(const PStringVisitorHandle& visitor) = 0; +}; + +typedef SharedHandle<PStringDatum> PStringDatumHandle; +typedef deque<PStringDatumHandle> PStringData; + +#endif // _D_P_STRING_DATUM_H_ diff --git a/src/PStringNumLoop.h b/src/PStringNumLoop.h new file mode 100644 index 00000000..1717d236 --- /dev/null +++ b/src/PStringNumLoop.h @@ -0,0 +1,100 @@ +/* <!-- copyright */ +/* + * aria2 - The high speed download utility + * + * Copyright (C) 2006 Tatsuhiro Tsujikawa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations + * including the two. + * You must obey the GNU General Public License in all respects + * for all of the code used other than OpenSSL. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you + * do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source + * files in the program, then also delete it here. + */ +/* copyright --> */ +#ifndef _D_P_STRING_NUM_LOOP_H_ +#define _D_P_STRING_NUM_LOOP_H_ + +#include "PStringDatum.h" +#include "Util.h" +#include "PStringSegment.h" +#include "NumberDecorator.h" + +class PStringNumLoop : public PStringDatum +{ +private: + + int32_t _startValue; + + int32_t _endValue; + + int32_t _step; + + NumberDecoratorHandle _numberDecorator; + + PStringDatumHandle _next; + +public: + PStringNumLoop(int32_t startValue, int32_t endValue, int32_t step, + const NumberDecoratorHandle& nd, + const PStringDatumHandle& next = 0): + _startValue(startValue), + _endValue(endValue), + _step(step), + _numberDecorator(nd), + _next(next) {} + + virtual ~PStringNumLoop() {} + + virtual void accept(const PStringVisitorHandle& visitor) + { + for(int32_t i = _startValue; i <= _endValue; i += _step) { + PStringSegment(_numberDecorator->decorate(i), _next).accept(visitor); + } + } + + PStringDatumHandle getNext() const + { + return _next; + } + + int32_t getStartValue() const + { + return _startValue; + } + + int32_t getEndValue() const + { + return _endValue; + } + + int32_t getStep() const + { + return _step; + } + +}; + +typedef SharedHandle<PStringNumLoop> PStringNumLoopHandle; + +#endif // _D_P_STRING_NUM_LOOP_H_ diff --git a/src/PStringSegment.cc b/src/PStringSegment.cc new file mode 100644 index 00000000..28d9796b --- /dev/null +++ b/src/PStringSegment.cc @@ -0,0 +1,49 @@ +/* <!-- copyright */ +/* + * aria2 - The high speed download utility + * + * Copyright (C) 2006 Tatsuhiro Tsujikawa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations + * including the two. + * You must obey the GNU General Public License in all respects + * for all of the code used other than OpenSSL. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you + * do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source + * files in the program, then also delete it here. + */ +/* copyright --> */ +#include "PStringSegment.h" +#include "FatalException.h" + +void PStringSegment::accept(const PStringVisitorHandle& visitor) +{ + PStringSegmentVisitorHandle v = visitor; + if(v.isNull()) { + throw new FatalException("Class cast exception"); + } + v->hello(this); + if(!_next.isNull()) { + _next->accept(visitor); + } + v->goodbye(this); +} diff --git a/src/PStringSegment.h b/src/PStringSegment.h new file mode 100644 index 00000000..ac35bb81 --- /dev/null +++ b/src/PStringSegment.h @@ -0,0 +1,89 @@ +/* <!-- copyright */ +/* + * aria2 - The high speed download utility + * + * Copyright (C) 2006 Tatsuhiro Tsujikawa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations + * including the two. + * You must obey the GNU General Public License in all respects + * for all of the code used other than OpenSSL. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you + * do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source + * files in the program, then also delete it here. + */ +/* copyright --> */ +#ifndef _D_P_STRING_SEGMENT_H_ +#define _D_P_STRING_SEGMENT_H_ + +#include "PStringDatum.h" + +class PStringSegmentVisitor; + +typedef SharedHandle<PStringSegmentVisitor> PStringSegmentVisitorHandle; + +class PStringSegment : public PStringDatum +{ +private: + + string _value; + + PStringDatumHandle _next; + +public: + PStringSegment(const string& value, const PStringDatumHandle& next = 0): + _value(value), _next(next) {} + + virtual ~PStringSegment() {} + + virtual void accept(const PStringVisitorHandle& visitor); + + const string& getValue() const + { + return _value; + } + + bool hasNext() const + { + return !_next.isNull(); + } + + PStringDatumHandle getNext() const + { + return _next; + } +}; + +typedef SharedHandle<PStringSegment> PStringSegmentHandle; + +class PStringSegmentVisitor { +public: + virtual ~PStringSegmentVisitor() {} + + virtual void hello(PStringSegment* s) = 0; + + virtual void goodbye(PStringSegment* s) = 0; +}; + +typedef SharedHandle<PStringSegmentVisitor> PStringSegmentVisitorHandle; + +#endif // _D_P_STRING_SEGMENT_H_ diff --git a/src/PStringSelect.h b/src/PStringSelect.h new file mode 100644 index 00000000..305ef9d9 --- /dev/null +++ b/src/PStringSelect.h @@ -0,0 +1,76 @@ +/* <!-- copyright */ +/* + * aria2 - The high speed download utility + * + * Copyright (C) 2006 Tatsuhiro Tsujikawa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations + * including the two. + * You must obey the GNU General Public License in all respects + * for all of the code used other than OpenSSL. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you + * do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source + * files in the program, then also delete it here. + */ +/* copyright --> */ +#ifndef _D_P_STRING_SELECT_H_ +#define _D_P_STRING_SELECT_H_ + +#include "PStringDatum.h" +#include "PStringSegment.h" + +class PStringSelect : public PStringDatum +{ +private: + + Strings _values; + + PStringDatumHandle _next; + +public: + PStringSelect(const Strings& values, const PStringDatumHandle& next = 0): + _values(values), + _next(next) {} + + virtual ~PStringSelect() {} + + virtual void accept(const PStringVisitorHandle& visitor) + { + for(Strings::iterator itr = _values.begin(); itr != _values.end(); ++itr) { + PStringSegment(*itr, _next).accept(visitor); + } + } + + const Strings& getValues() const + { + return _values; + } + + PStringDatumHandle getNext() const + { + return _next; + } +}; + +typedef SharedHandle<PStringSelect> PStringSelectHandle; + +#endif // _D_P_STRING_SELECT_H_ diff --git a/src/PStringVisitor.h b/src/PStringVisitor.h new file mode 100644 index 00000000..8c8c9807 --- /dev/null +++ b/src/PStringVisitor.h @@ -0,0 +1,47 @@ +/* <!-- copyright */ +/* + * aria2 - The high speed download utility + * + * Copyright (C) 2006 Tatsuhiro Tsujikawa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations + * including the two. + * You must obey the GNU General Public License in all respects + * for all of the code used other than OpenSSL. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you + * do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source + * files in the program, then also delete it here. + */ +/* copyright --> */ +#ifndef _D_P_STRING_VISITOR_H_ +#define _D_P_STRING_VISITOR_H_ + +#include "common.h" + +class PStringVisitor { +public: + virtual ~PStringVisitor() {} +}; + +typedef SharedHandle<PStringVisitor> PStringVisitorHandle; + +#endif // _D_P_STRING_VISITOR_H_ diff --git a/src/ParameterizedStringParser.cc b/src/ParameterizedStringParser.cc new file mode 100644 index 00000000..4eef3574 --- /dev/null +++ b/src/ParameterizedStringParser.cc @@ -0,0 +1,145 @@ +/* <!-- copyright */ +/* + * aria2 - The high speed download utility + * + * Copyright (C) 2006 Tatsuhiro Tsujikawa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations + * including the two. + * You must obey the GNU General Public License in all respects + * for all of the code used other than OpenSSL. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you + * do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source + * files in the program, then also delete it here. + */ +/* copyright --> */ +#include "ParameterizedStringParser.h" +#include "FatalException.h" +#include "Util.h" +#include "PStringSegment.h" +#include "PStringSelect.h" +#include "PStringNumLoop.h" +#include "NumberDecorator.h" +#include "FixedWidthNumberDecorator.h" +#include "AlphaNumberDecorator.h" + +PStringDatumHandle ParameterizedStringParser::parse(const string& src) +{ + int32_t offset = 0; + return diggPString(src, offset); +} + +PStringDatumHandle ParameterizedStringParser::diggPString(const string& src, + int32_t& offset) +{ + if(src.size() == (size_t)offset) { + return 0; + } + switch(src[offset]) { + case '[': + return createLoop(src, offset); + case '{': + return createSelect(src, offset); + default: + return createSegment(src, offset); + } +} + +PStringDatumHandle ParameterizedStringParser::createSegment(const string& src, + int32_t& offset) +{ + string::size_type nextDelimiterIndex = src.find_first_of("[{", offset); + if(nextDelimiterIndex == string::npos) { + nextDelimiterIndex = src.size(); + } + string value = src.substr(offset, nextDelimiterIndex-offset); + offset = nextDelimiterIndex; + PStringDatumHandle next = diggPString(src, offset); + return new PStringSegment(value, next); +} + +PStringDatumHandle ParameterizedStringParser::createSelect(const string& src, + int32_t& offset) +{ + ++offset; + string::size_type rightParenIndex = src.find("}", offset); + if(rightParenIndex == string::npos) { + throw new FatalException("Missing '}' in the parameterized string."); + } + Strings values; + Util::slice(values, src.substr(offset, rightParenIndex-offset), ',', true); + if(values.empty()) { + throw new FatalException("Empty {} is not allowed."); + } + offset = rightParenIndex+1; + PStringDatumHandle next = diggPString(src, offset); + return new PStringSelect(values, next); +} + +PStringDatumHandle ParameterizedStringParser::createLoop(const string& src, + int32_t& offset) +{ + ++offset; + string::size_type rightParenIndex = src.find("]", offset); + if(rightParenIndex == string::npos) { + throw new FatalException("Missing ']' in the parameterized string."); + } + string loopStr = src.substr(offset, rightParenIndex-offset); + offset = rightParenIndex+1; + + int32_t step = 1; + string::size_type colonIndex = loopStr.find(":"); + if(colonIndex != string::npos) { + string stepStr = loopStr.substr(colonIndex+1); + if(Util::isNumber(stepStr)) { + step = strtol(stepStr.c_str(), 0, 10); + } else { + throw new FatalException("A step count must be a number."); + } + loopStr.erase(colonIndex); + } + pair<string, string> range = Util::split(loopStr, "-"); + if(range.first == "" || range.second == "") { + throw new FatalException("Loop range missing."); + } + NumberDecoratorHandle nd = 0; + int32_t start; + int32_t end; + if(Util::isNumber(range.first) && Util::isNumber(range.second)) { + nd = new FixedWidthNumberDecorator(range.first.size()); + start = strtol(range.first.c_str(), 0, 10); + end = strtol(range.second.c_str(), 0, 10); + } else if(Util::isLowercase(range.first) && Util::isLowercase(range.second)) { + nd = new AlphaNumberDecorator(range.first.size()); + start = Util::alphaToNum(range.first); + end = Util::alphaToNum(range.second); + } else if(Util::isUppercase(range.first) && Util::isUppercase(range.second)) { + nd = new AlphaNumberDecorator(range.first.size(), true); + start = Util::alphaToNum(range.first); + end = Util::alphaToNum(range.second); + } else { + throw new FatalException("Invalid loop range."); + } + + PStringDatumHandle next = diggPString(src, offset); + return new PStringNumLoop(start, end, step, nd, next); +} diff --git a/src/ParameterizedStringParser.h b/src/ParameterizedStringParser.h new file mode 100644 index 00000000..10077a7a --- /dev/null +++ b/src/ParameterizedStringParser.h @@ -0,0 +1,56 @@ +/* <!-- copyright */ +/* + * aria2 - The high speed download utility + * + * Copyright (C) 2006 Tatsuhiro Tsujikawa + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of portions of this program with the + * OpenSSL library under certain conditions as described in each + * individual source file, and distribute linked combinations + * including the two. + * You must obey the GNU General Public License in all respects + * for all of the code used other than OpenSSL. If you modify + * file(s) with this exception, you may extend this exception to your + * version of the file(s), but you are not obligated to do so. If you + * do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source + * files in the program, then also delete it here. + */ +/* copyright --> */ +#ifndef _D_PARAMETERIZED_STRING_PARSER_H_ +#define _D_PARAMETERIZED_STRING_PARSER_H_ + +#include "common.h" +#include "PStringDatum.h" + +class ParameterizedStringParser { +private: + PStringDatumHandle diggPString(const string& src, int32_t& offset); + + PStringDatumHandle createSegment(const string& src, int32_t& offset); + + PStringDatumHandle createLoop(const string& src, int32_t& offset); + + PStringDatumHandle createSelect(const string& src, int32_t& offset); + + +public: + PStringDatumHandle parse(const string& parameterizedUri); +}; + +#endif // _D_PARAMETERIZED_STRING_PARSER_H_ diff --git a/src/RequestInfo.h b/src/RequestInfo.h index 69365963..99f35633 100644 --- a/src/RequestInfo.h +++ b/src/RequestInfo.h @@ -62,6 +62,7 @@ protected: printf(_("\nSome downloads were not complete because of errors." " Check the log.\n" "aria2 will resume download if the transfer is restarted.")); + printf("\n"); } public: RequestInfo(Option* op): diff --git a/src/Util.cc b/src/Util.cc index e5805bb3..bbd31465 100644 --- a/src/Util.cc +++ b/src/Util.cc @@ -694,3 +694,62 @@ void Util::usleep(long microseconds) { #error no usleep function is available (nanosleep?) #endif } + +bool Util::isNumber(const string& what) +{ + if(what.empty()) { + return false; + } + for(uint32_t i = 0; i < what.size(); ++i) { + if(!isdigit(what[i])) { + return false; + } + } + return true; +} + +bool Util::isLowercase(const string& what) +{ + if(what.empty()) { + return false; + } + for(uint32_t i = 0; i < what.size(); ++i) { + if(!('a' <= what[i] && what[i] <= 'z')) { + return false; + } + } + return true; +} + +bool Util::isUppercase(const string& what) +{ + if(what.empty()) { + return false; + } + for(uint32_t i = 0; i < what.size(); ++i) { + if(!('A' <= what[i] && what[i] <= 'Z')) { + return false; + } + } + return true; +} + +int32_t Util::alphaToNum(const string& alphabets) +{ + if(alphabets.empty()) { + return 0; + } + char base; + if(islower(alphabets[0])) { + base = 'a'; + } else { + base = 'A'; + } + int32_t num = 0; + for(uint32_t i = 0; i < alphabets.size(); ++i) { + int32_t v = alphabets[i]-base; + num = num*26+v; + } + return num; +} + @@ -135,6 +135,14 @@ public: static void sleep(long seconds); static void usleep(long microseconds); + + static bool isNumber(const string& what); + + static bool isLowercase(const string& what); + + static bool isUppercase(const string& what); + + static int32_t alphaToNum(const string& alphabets); }; #endif // _D_UTIL_H_ diff --git a/src/main.cc b/src/main.cc index e8ce8aba..4b79ce2c 100644 --- a/src/main.cc +++ b/src/main.cc @@ -57,6 +57,8 @@ #include "a2time.h" #include "Platform.h" #include "prefs.h" +#include "ParameterizedStringParser.h" +#include "PStringBuildVisitor.h" #include <deque> #include <algorithm> #include <signal.h> @@ -194,6 +196,10 @@ void showUsage() { " already exists but the corresponding .aria2 file\n" " doesn't exist.\n" " Default: false") << endl; + cout << _(" -Z, --force-sequential Fetch URIs in the command-line sequentially and\n" + " download each URI in a separate session, like\n" + " the usual command-line download utilities.") << endl; + #ifdef ENABLE_MESSAGE_DIGEST cout << _(" --check-integrity=true|false Check file integrity by validating piece hash.\n" " This option only affects in BitTorrent downloads\n" @@ -303,6 +309,10 @@ void showUsage() { cout << " aria2c http://AAA.BBB.CCC/file.zip http://DDD.EEE.FFF/GGG/file.zip" << endl; cout << _(" You can mix up different protocols:") << endl; cout << " aria2c http://AAA.BBB.CCC/file.zip ftp://DDD.EEE.FFF/GGG/file.zip" << endl; + cout << _(" Parameterized URI:") << endl; + cout << " aria2c http://{server1,server2,server3}/file.iso" << endl; + cout << _(" Parameterized URI. -Z option must be specified:") << endl; + cout << " aria2c -Z http://host/file[001-100].img" << endl; #ifdef ENABLE_BITTORRENT cout << endl; cout << _(" Download a torrent:") << endl; @@ -334,6 +344,20 @@ void showUsage() { cout << endl; } +Strings unfoldURI(const Strings& args) +{ + Strings nargs; + ParameterizedStringParser p; + PStringBuildVisitorHandle v = new PStringBuildVisitor(); + for(Strings::const_iterator itr = args.begin(); itr != args.end(); + ++itr) { + v->reset(); + p.parse(*itr)->accept(v); + nargs.insert(nargs.end(), v->getURIs().begin(), v->getURIs().end()); + } + return nargs; +} + int main(int argc, char* argv[]) { #ifdef HAVE_WINSOCK2_H Platform platform; @@ -400,6 +424,7 @@ int main(int argc, char* argv[]) { op->put(PREF_NO_NETRC, V_FALSE); op->put(PREF_MAX_CONCURRENT_DOWNLOADS, "5"); op->put(PREF_DIRECT_DOWNLOAD_TIMEOUT, "15"); + op->put(PREF_FORCE_SEQUENTIAL, V_FALSE); while(1) { int optIndex = 0; int lopt; @@ -432,6 +457,7 @@ int main(int argc, char* argv[]) { { "max-download-limit", required_argument, &lopt, 201 }, { "file-allocation", required_argument, 0, 'a' }, { "allow-overwrite", required_argument, &lopt, 202 }, + { "force-sequential", no_argument, 0, 'Z' }, #ifdef ENABLE_MESSAGE_DIGEST { "check-integrity", required_argument, &lopt, 203 }, { "realtime-chunk-checksum", required_argument, &lopt, 204 }, @@ -472,7 +498,7 @@ int main(int argc, char* argv[]) { { "help", no_argument, NULL, 'h' }, { 0, 0, 0, 0 } }; - c = getopt_long(argc, argv, "Dd:o:l:s:pt:m:vhST:M:C:a:cU:ni:j:", longOpts, &optIndex); + c = getopt_long(argc, argv, "Dd:o:l:s:pt:m:vhST:M:C:a:cU:ni:j:Z", longOpts, &optIndex); if(c == -1) { break; } @@ -639,6 +665,9 @@ int main(int argc, char* argv[]) { case 'j': cmdstream << PREF_MAX_CONCURRENT_DOWNLOADS << "=" << optarg << "\n"; break; + case 'Z': + cmdstream << PREF_FORCE_SEQUENTIAL << "=" << V_TRUE << "\n"; + break; case 'v': showVersion(); exit(EXIT_SUCCESS); @@ -800,7 +829,17 @@ int main(int argc, char* argv[]) { RequestGroups groups; while(flparser->hasNext()) { Strings uris = flparser->next(); - if(!uris.empty()) { + if(uris.size() == 1) { + Strings unfoldedURIs = unfoldURI(uris); + for(Strings::const_iterator itr = unfoldedURIs.begin(); + itr != unfoldedURIs.end(); ++itr) { + Strings xuris; + ncopy(itr, itr+1, op->getAsInt(PREF_SPLIT), + back_inserter(xuris)); + RequestGroupHandle rg = new RequestGroup(xuris, op); + groups.push_back(rg); + } + } else if(uris.size() > 1) { Strings xuris; ncopy(uris.begin(), uris.end(), op->getAsInt(PREF_SPLIT), back_inserter(xuris)); @@ -812,10 +851,25 @@ int main(int argc, char* argv[]) { } else { - Strings xargs; - ncopy(args.begin(), args.end(), op->getAsInt(PREF_SPLIT), - back_inserter(xargs)); - firstReqInfo = new MultiUrlRequestInfo(xargs, op); + + Strings nargs = unfoldURI(args); + if(op->get(PREF_FORCE_SEQUENTIAL) == V_TRUE) { + RequestGroups groups; + for(Strings::const_iterator itr = nargs.begin(); + itr != nargs.end(); ++itr) { + Strings xuris; + ncopy(itr, itr+1, op->getAsInt(PREF_SPLIT), + back_inserter(xuris)); + RequestGroupHandle rg = new RequestGroup(xuris, op); + groups.push_back(rg); + } + firstReqInfo = new MultiUrlRequestInfo(groups, op); + } else { + Strings xargs; + ncopy(nargs.begin(), nargs.end(), op->getAsInt(PREF_SPLIT), + back_inserter(xargs)); + firstReqInfo = new MultiUrlRequestInfo(xargs, op); + } } RequestInfos reqInfos; diff --git a/src/prefs.h b/src/prefs.h index 4f688c20..4ad48643 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -107,6 +107,8 @@ #define PREF_MAX_CONCURRENT_DOWNLOADS "max-concurrent-downloads" // value: 1*digit #define PREF_DIRECT_DOWNLOAD_TIMEOUT "direct-download-timeout" +// value: +#define PREF_FORCE_SEQUENTIAL "force-sequential" /** * FTP related preferences |
