/*
**
**      Copyright (c) 2000-2005 ChoiceStream, Inc.  All Rights Reserved
**
**      ChoiceStream
**      210 Broadway
**      Cambridge, MA 02139
**
**  $Id: httpconnection.h,v 1.5 2005/03/18 22:34:42 mmastroianni Exp $
**
**/

#ifndef CSM_httpconnection_h_included_
#define CSM_httpconnection_h_included_

#include <vector>
#include <string>

#include "csmlogger.h"
#include "httprequest.h"
#include "httpresponse.h"

struct curl_httppost;

namespace csm {

    typedef void CURL;

    class HttpConnection: public LoggerSingleton<HttpConnection>
    {
      public:
        HttpConnection(long maxtransactions = 60*1000,
                       const std::string & dns1 = "",
                       const std::string & dns2 = "");
        virtual ~HttpConnection();

        void sendRequest(const HttpRequest& request, HttpResponse& response);
      
      protected:
        void recreateHandle();
        void init();

        bool initializeRequest(const csm::HttpRequest& request);
        void cleanup();
        void addFormInfo(const csm::HttpFormList & forms);
        void sendPostRequest(const csm::HttpRequest& request, csm::HttpResponse& response);
        void sendGetRequest(const csm::HttpRequest& request, csm::HttpResponse& response);
        void sendSinglePartPost(const csm::HttpRequest& request, csm::HttpResponse& response);

        curl_httppost *postBody_;
        CURL *curlHandle_;
        long maxTime_;
        long handleTime_;
        //These two are for when we want to use other dns than the default on the machine
        //we are running on
        std::string dns1_;
        std::string dns2_;
        friend class LoggerSingleton<HttpConnection>;
        static const char *logger_name() {return "csm.HttpConnection";}
    };
}

#endif
