HttpInitiateConnectionCommand.cc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* <!-- copyright */
  2. /*
  3. * aria2 - a simple utility for downloading files faster
  4. *
  5. * Copyright (C) 2006 Tatsuhiro Tsujikawa
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. /* copyright --> */
  22. #include "HttpInitiateConnectionCommand.h"
  23. #include "HttpRequestCommand.h"
  24. #include "HttpProxyRequestCommand.h"
  25. #include "Util.h"
  26. #include "DlAbortEx.h"
  27. #include "message.h"
  28. #include "prefs.h"
  29. HttpInitiateConnectionCommand::HttpInitiateConnectionCommand(int cuid, Request* req, DownloadEngine* e):AbstractCommand(cuid, req, e) {}
  30. HttpInitiateConnectionCommand::~HttpInitiateConnectionCommand() {}
  31. bool HttpInitiateConnectionCommand::executeInternal(Segment segment) {
  32. socket = new Socket();
  33. // socket->establishConnection(...);
  34. Command* command;
  35. if(useProxy()) {
  36. logger->info(MSG_CONNECTING_TO_SERVER, cuid,
  37. e->option->get(PREF_HTTP_PROXY_HOST).c_str(),
  38. e->option->getAsInt(PREF_HTTP_PROXY_PORT));
  39. socket->establishConnection(e->option->get(PREF_HTTP_PROXY_HOST),
  40. e->option->getAsInt(PREF_HTTP_PROXY_PORT));
  41. if(useProxyTunnel()) {
  42. command = new HttpProxyRequestCommand(cuid, req, e, socket);
  43. } else if(useProxyGet()) {
  44. command = new HttpRequestCommand(cuid, req, e, socket);
  45. } else {
  46. // TODO
  47. throw new DlAbortEx("ERROR");
  48. }
  49. } else {
  50. logger->info(MSG_CONNECTING_TO_SERVER, cuid, req->getHost().c_str(),
  51. req->getPort());
  52. socket->establishConnection(req->getHost(), req->getPort());
  53. command = new HttpRequestCommand(cuid, req, e, socket);
  54. }
  55. e->commands.push(command);
  56. return true;
  57. }
  58. bool HttpInitiateConnectionCommand::useProxy() {
  59. return e->option->get(PREF_HTTP_PROXY_ENABLED) == V_TRUE;
  60. }
  61. bool HttpInitiateConnectionCommand::useProxyGet() {
  62. return e->option->get(PREF_HTTP_PROXY_METHOD) == V_GET;
  63. }
  64. bool HttpInitiateConnectionCommand::useProxyTunnel() {
  65. return e->option->get(PREF_HTTP_PROXY_METHOD) == V_TUNNEL;
  66. }