Index: /trunk/BNC/src/upload/bncuploadcaster.cpp
===================================================================
--- /trunk/BNC/src/upload/bncuploadcaster.cpp	(revision 9706)
+++ /trunk/BNC/src/upload/bncuploadcaster.cpp	(revision 9707)
@@ -20,4 +20,5 @@
 #include "bnccore.h"
 #include "bnctableitem.h"
+#include "bncsettings.h"
 
 using namespace std;
@@ -32,7 +33,9 @@
                                  int rate) {
   _mountpoint    = mountpoint;
-  _outHost       = outHost;
-  _outPort       = outPort;
+  _casterOutHost = outHost;
+  _casterOutPort = outPort;
   _ntripVersion  = ntripVersion;
+  (_ntripVersion == "2s") ?  _secure = true : _secure = false;
+  _postExtension = "";
   _userName      = userName;
   _password      = password;
@@ -41,4 +44,5 @@
   _iRow          = iRow;
   _rate          = rate;
+
   if      (_rate < 0) {
     _rate = 0;
@@ -48,4 +52,23 @@
   }
   _isToBeDeleted = false;
+
+  if (!QSslSocket::supportsSsl()) {
+    BNC_CORE->slotMessage("No SSL support, install OpenSSL run-time libraries", true);
+    deleteSafely();
+  }
+
+  if (_ntripVersion != "1") {
+    bncSettings settings;
+    _proxyHost = settings.value("proxyHost").toString();
+    _proxyPort = settings.value("proxyPort").toInt();
+    _sslIgnoreErrors = (Qt::CheckState(settings.value("sslIgnoreErrors").toInt()) == Qt::Checked);
+    if (_secure) {
+      _casterOutPort = 443;
+      _postExtension = QString("https://%1:%2").arg(_casterOutHost).arg(_casterOutPort);
+    }
+    else {
+      _postExtension = QString("http://%1:%2").arg(_casterOutHost).arg(_casterOutPort);
+    }
+  }
 
   connect(this, SIGNAL(newMessage(QByteArray,bool)),
@@ -80,7 +103,51 @@
   }
   if (_outSocket) {
+    disconnect(_outSocket, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)),
+               this, SLOT(slotProxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)));
     delete _outSocket;
   }
 }
+
+//
+////////////////////////////////////////////////////////////////////////////
+void bncUploadCaster::slotProxyAuthenticationRequired(const QNetworkProxy&,
+                                                    QAuthenticator*) {
+  emit newMessage("slotProxyAuthenticationRequired", true);
+}
+
+
+/* TSL/SSL
+////////////////////////////////////////////////////////////////////////////
+void bncUploadCaster::slotSslErrors(QList<QSslError> errors) {
+
+  QString msg = "SSL Error\n";
+  QSslCertificate cert = _outSocket->sslConfiguration().peerCertificate();
+  if (!cert.isNull()) {
+    msg += QString("Server Certificate Issued by:\n"
+                   "%1\n%2\nCannot be verified\n")
+#if QT_VERSION >= 0x050000
+           .arg(cert.issuerInfo(QSslCertificate::OrganizationalUnitName).at(0))
+           .arg(cert.issuerInfo(QSslCertificate::Organization).at(0));
+#else
+           .arg(cert.issuerInfo(QSslCertificate::OrganizationalUnitName))
+           .arg(cert.issuerInfo(QSslCertificate::Organization));
+#endif
+  }
+  QListIterator<QSslError> it(errors);
+  while (it.hasNext()) {
+    const QSslError& err = it.next();
+    msg += "\n" + err.errorString();
+  }
+
+  BNC_CORE->slotMessage(msg.toLatin1(), true);
+
+  if (_sslIgnoreErrors) {
+    _outSocket->ignoreSslErrors();
+  }
+  else {
+    deleteSafely();
+  }
+}
+*/
 
 // Endless Loop
@@ -97,6 +164,14 @@
       QMutexLocker locker(&_mutex);
       if (_outBuffer.size() > 0) {
-        _outSocket->write(_outBuffer);
-        _outSocket->flush();
+        if (_ntripVersion == "1") {
+          _outSocket->write(_outBuffer);
+          _outSocket->flush();
+        }
+        else {
+          QString chunkSize = QString("%1").arg(_outBuffer.size(),0,16,QLatin1Char('0'));
+          QByteArray chunkedData = chunkSize.toLatin1() + "\r\n" + _outBuffer + "\r\n";
+          _outSocket->write(chunkedData);
+          _outSocket->flush();
+        }
         emit newBytes(_mountpoint.toLatin1(), _outBuffer.size());
       }
@@ -127,5 +202,5 @@
     return;
   }
-
+  
   delete _outSocket; _outSocket = 0;
 
@@ -142,12 +217,38 @@
   }
 
-  _outSocket = new QTcpSocket();
-  _outSocket->setProxy(QNetworkProxy::NoProxy); // Ntrip1: to prevent the usage of system entries
-  _outSocket->connectToHost(_outHost, _outPort);
+  _outSocket = new QSslSocket();
+  if (_sslIgnoreErrors) {
+    _outSocket->ignoreSslErrors();
+  }
+  _outSocket->setProxy(QNetworkProxy::NoProxy); // to prevent the usage of system entries
+  if (_ntripVersion == "1") {
+    _outHost = _casterOutHost;
+    _outPort = _casterOutPort;
+  }
+  else {
+    if (!_proxyHost.isEmpty()) {
+      _outHost = _proxyHost;
+      _outPort = _proxyPort;
+      connect(_outSocket, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)),
+              this, SLOT(slotProxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)));
+    }
+  }
+
+  if (!_secure) {
+    _outSocket->connectToHost(_outHost, _outPort);
+  }
+  else {
+    _outSocket->connectToHostEncrypted(_outHost, _outPort);/*
+    if (!_outSocket->waitForEncrypted()) {
+        cout << "waitForEncrypted: " << _outSocket->errorString().toStdString().c_str() << endl;;
+        return;
+    }*/
+  }
 
   const int timeOut = 5000;  // 5 seconds
   if (!_outSocket->waitForConnected(timeOut)) {
     emit(newMessage("Broadcaster: Connect timeout for " + _mountpoint.toLatin1()
-         + "(" + _outHost.toLatin1() + "), " + _outSocket->errorString().toLatin1(), true));
+         + " (" + _outHost.toLatin1()+ ":" + QString("%1) ").arg(_outPort).toLatin1()
+         + _outSocket->errorString().toLatin1(), true));
     delete _outSocket;
     _outSocket = 0;
@@ -155,18 +256,29 @@
   }
 
-  QByteArray msg = "SOURCE " + _password.toLatin1() + " /" +
-                   _mountpoint.toLatin1() + "\r\n" +
-                   "Source-Agent: NTRIP BNC/" BNCVERSION "\r\n\r\n";
-
+  QByteArray msg;
+  if (_ntripVersion == "1") {
+    msg = "SOURCE " + _password.toLatin1() + " /" + _mountpoint.toLatin1() + "\r\n" +
+          "Source-Agent: NTRIP BNC/" BNCVERSION "\r\n\r\n";
+  }
+  else {
+    msg = "POST " + _postExtension.toLatin1() + "/" + _mountpoint.toLatin1() + " HTTP/1.1\r\n" +
+          "Host: " + _casterOutHost.toLatin1() + "\r\n" +
+          "Ntrip-Version: Ntrip/2.0\r\n" +
+          "Authorization: Basic " + (_userName + ":" + _password).toLatin1().toBase64() + "\r\n" +
+          "User-Agent: NTRIP BNC/" BNCVERSION " (" + BNC_OS + ")\r\n" +
+          "Connection: close\r\n" +
+          "Transfer-Encoding: chunked\r\n\r\n";
+  }
+  cout << msg.toStdString().c_str();
   _outSocket->write(msg);
   _outSocket->waitForBytesWritten();
 
   _outSocket->waitForReadyRead();
-  QByteArray ans = _outSocket->readLine();
+  QByteArray ans = _outSocket->readLine();cout << ans.toStdString().c_str() << endl;
 
   if (ans.indexOf("OK") == -1) {
     delete _outSocket;
     _outSocket = 0;
-    emit(newMessage("Broadcaster: Connection broken for " + _mountpoint.toLatin1(), true));
+    emit(newMessage("Broadcaster: Connection broken for " + _mountpoint.toLatin1() + ": " + ans.left(ans.length()-2), true));
   }
   else {
Index: /trunk/BNC/src/upload/bncuploadcaster.h
===================================================================
--- /trunk/BNC/src/upload/bncuploadcaster.h	(revision 9706)
+++ /trunk/BNC/src/upload/bncuploadcaster.h	(revision 9707)
@@ -4,7 +4,10 @@
 #include <QDateTime>
 #include <QMutex>
-#include <QTcpSocket>
+#include <QSslSocket>
 #include <QNetworkProxy>
 #include <QThread>
+#include <QSslError>
+#include <iostream>
+
 
 class bncUploadCaster : public QThread {
@@ -31,4 +34,8 @@
   void newBytes(QByteArray staID, double nbyte);
 
+ private slots:
+  void slotProxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*);
+  //void slotSslErrors(QList<QSslError>);
+
  private:
   void         open();
@@ -38,9 +45,15 @@
   QString     _outHost;
   int         _outPort;
+  QString     _casterOutHost;
+  int         _casterOutPort;
+  QString     _proxyHost;
+  int         _proxyPort;
   QString     _userName;
   QString     _password;
   QString     _ntripVersion;
+  QString     _postExtension;
   bool        _secure;
-  QTcpSocket* _outSocket;
+  bool        _sslIgnoreErrors;
+  QSslSocket* _outSocket;
   int         _sOpenTrial;
   QDateTime   _outSocketOpenTime;
