Index: /trunk/ntripserver/ntripserver.c
===================================================================
--- /trunk/ntripserver/ntripserver.c	(revision 9402)
+++ /trunk/ntripserver/ntripserver.c	(revision 9403)
@@ -120,7 +120,4 @@
 #define NTRIP_PORT      2101
 
-#define DABPLUS_SERVER  "62.225.182.198"
-#define DABPLUS_PORT    10000
-
 #define SISNET_SERVER   "131.176.49.142"
 #define SISNET_PORT     7777
@@ -233,4 +230,7 @@
   const char *ntrip_str = "";
 
+  const char *dabplus_provider = 0;
+  char dabplus_provider_str[17] = "";
+
   const char *user = "";
   const char *password = "";
@@ -296,5 +296,5 @@
   }
   while ((c = getopt(argc, argv,
-      "M:i:h:b:p:s:a:m:c:H:P:f:x:y:l:u:V:D:U:W:O:E:F:R:N:n:B")) != EOF) {
+      "M:i:h:b:p:s:a:m:c:H:P:f:x:y:l:u:V:D:U:W:O:E:F:R:N:T:n:B")) != EOF) {
     switch (c) {
       case 'M': /*** InputMode ***/
@@ -438,4 +438,7 @@
         ntrip_str = optarg;
         break;
+      case 'T':
+        dabplus_provider = optarg;
+        break;
       case 'h': /* print help screen */
       case '?':
@@ -474,10 +477,18 @@
 
   if (outputmode == TDC) {
+    fprintf(stderr, "ERROR: DABPLUS server upload implementation is so far not completed\n\n");
+    exit(0);
+
     mountpoint = NULL;
-    if (!strcmp(casterouthost, NTRIP_CASTER)) {
-      casterouthost = DABPLUS_SERVER;
-    }
-    if (casteroutport == NTRIP_PORT) {
-      casteroutport = DABPLUS_PORT;
+    if (dabplus_provider) {
+      i = snprintf(dabplus_provider_str, 17, "%16s", dabplus_provider);
+      if ((i > 16) || (i < 0)) {
+        fprintf(stderr, "ERROR: DABPLUS provider name to long - length = %d (max: %d)\n", i, 16);
+        exit(0);
+      }
+    }
+    else {
+      fprintf(stderr, "ERROR: DABPLUS provider name required\n");
+      exit(0);
     }
   }
@@ -499,12 +510,19 @@
 
   if (stream_name && stream_user && !stream_password) {
-    fprintf(stderr,
-        "WARNING: Missing password argument for stream download - are you really sure?\n");
+    fprintf(stderr, "WARNING: Missing password argument for stream download - are you really sure?\n");
   }
 
   /*** proxy server handling ***/
   if (*proxyhost) {
-    outhost = inhost = proxyhost;
-    outport = inport = proxyport;
+    if (outputmode == TDC) {
+      fprintf(stderr, "\nWARNING: TDC is not able to support proxy servers, try direct connection\n\n");
+      inhost = proxyhost;
+      inport = proxyport;
+      outhost = casterouthost;
+      outport = casteroutport;
+    } else {
+      outhost = inhost = proxyhost;
+      outport = inport = proxyport;
+    }
     i = snprintf(szSendBuffer, sizeof(szSendBuffer), "http://%s:%d", casterouthost, casteroutport);
     if ((i > SZ) || (i < 0)) {
@@ -530,5 +548,4 @@
       strcpy(szSendBuffer, "");
       i = 0;
-      fprintf(stdout, "%s",get_extension);
     }
   } else {
@@ -711,5 +728,5 @@
         szSendBuffer[nBufferBytes++] = '\r';
         szSendBuffer[nBufferBytes++] = '\n';
-fprintf(stdout, "%s", szSendBuffer);
+        // fprintf(stdout, "%s\n", szSendBuffer);
         if ((send(gps_socket, szSendBuffer, (size_t) nBufferBytes, 0)) != nBufferBytes) {
           fprintf(stderr, "WARNING: could not send Source caster request\n");
@@ -883,4 +900,5 @@
       if((sigalarm_received) || (sigint_received)) break;
 #endif
+
       if (!(he = gethostbyname(outhost))) {
         fprintf(stderr,
@@ -889,5 +907,7 @@
         close_session(casterouthost, mountpoint, session, rtsp_extension, 0);
         usage(-2, argv[0]);
-      }
+      }else {fprintf(stderr,
+          "Destination caster, server or proxy host <%s> \n",
+          outhost);}
 
       /* create socket */
@@ -904,8 +924,10 @@
 
       /* connect to Destination caster, server or proxy host */
-      fprintf(stderr, "caster output: host = %s, port = %d, mountpoint = %s"
+      fprintf(stderr, "caster|server output: host = %s, port = %d, mountpoint = %s"
           ", mode = %s\n\n", inet_ntoa(caster.sin_addr), outport, mountpoint,
-          outputmode == NTRIP1 ? "ntrip1" : outputmode == HTTP ? "http" :
-          outputmode == UDP ? "udp" : "rtsp");
+          outputmode == NTRIP1 ? "ntrip1" :
+          outputmode == HTTP   ? "http"   :
+          outputmode == UDP    ? "udp"    :
+          outputmode == RTSP   ? "rtsp"   : "tdc");
 
       if (connect(socket_tcp, (struct sockaddr*) &caster, sizeof(caster)) < 0) {
@@ -1065,6 +1087,5 @@
           }
           /* check Destination caster's response */
-          nBufferBytes = recv(socket_tcp, szSendBuffer, sizeof(szSendBuffer),
-              0);
+          nBufferBytes = recv(socket_tcp, szSendBuffer, sizeof(szSendBuffer), 0);
           szSendBuffer[nBufferBytes] = '\0';
           if (!strstr(szSendBuffer, "OK")) {
@@ -1307,4 +1328,28 @@
           break;
         case TDC:
+          fallback = 0;
+          szSendBuffer[0] = 0x28;
+          szSendBuffer[1] = 0x11;
+          szSendBuffer[2] = 0x19;
+          szSendBuffer[3] = 0x69;
+          strncpy(szSendBuffer + 4, dabplus_provider_str, 16);
+          szSendBuffer[20] = 0; // mot
+          nBufferBytes =  strlen(szSendBuffer);
+          if ((nBufferBytes > 20) || (nBufferBytes < 0)) {
+            fprintf(stderr, "ERROR: Destination server request to long\n");
+            reconnect_sec_max = 0;
+            output_init = 0;
+            break;
+          }
+          if (!send_to_caster(szSendBuffer, socket_tcp, nBufferBytes)) {
+            output_init = 0;
+            break;
+          }
+          /* check Destination server's response
+          in case of a unidirectional connection muxd will close the connection
+          if an error occurs without transmitting any status information
+          */
+          send_receive_loop(socket_tcp, outputmode, NULL, 0, 0, chunkymode);
+          input_init = output_init = 0;
           break;
       }
@@ -1409,7 +1454,13 @@
         }
       }
-      /*** receiving data ****/
+      /***********************/
+      /* receiving data      */
+      /***********************/
+
+      /* INFILE  */
       if (inputmode == INFILE)
         nBufferBytes = read(gps_file, buffer, sizeof(buffer));
+
+      /* SERIAL */
       else if (inputmode == SERIAL) {
 #ifndef WINDOWSVERSION
@@ -1425,4 +1476,6 @@
 #endif
       }
+
+      /* ALL OTHER MODES */
       else
 #ifdef WINDOWSVERSION
@@ -1523,7 +1576,9 @@
       }
     }
-    /**  send data ***/
-    if ((nBufferBytes) && (outmode == NTRIP1)) /*** Ntrip-Version 1.0 ***/
-    {
+
+    /*****************/
+    /*  send data    */
+    /*****************/
+    if ((nBufferBytes) && (outmode == NTRIP1)) {
       int i;
       if ((i = send(sock, buffer, (size_t) nBufferBytes, MSG_DONTWAIT)) != nBufferBytes) {
@@ -1694,4 +1749,7 @@
         return;
       }
+    }
+    else if ((nBufferBytes) && (outmode == TDC)) {
+
     }
     if (send_recv_success == 3)
@@ -1882,131 +1940,81 @@
       "   and forward that incoming stream (Output, Destination) to either\n\n");
   fprintf(stderr, "     - an NTRIP Version 1.0 Caster, or\n");
-  fprintf(stderr,
-      "     - an NTRIP Version 2.0 Caster via TCP/IP or RTSP/RTP, or \n");
+  fprintf(stderr, "     - an NTRIP Version 2.0 Caster via TCP/IP or RTSP/RTP, or \n");
   fprintf(stderr, "     - an DABPLUS Content Server via TCP/IP and TDC \n\n\n");
   fprintf(stderr, "OPTIONS\n");
   fprintf(stderr, "   -h|? print this help screen\n\n");
-  fprintf(stderr,
-      "    -E <ProxyHost>       Proxy server host name or address, required i.e. when\n");
-  fprintf(stderr,
-      "                         running the program in a proxy server protected LAN,\n");
+  fprintf(stderr, "    -E <ProxyHost>       Proxy server host name or address, required i.e. when\n");
+  fprintf(stderr, "                         running the program in a proxy server protected LAN,\n");
   fprintf(stderr, "                         optional\n");
-  fprintf(stderr,
-      "    -F <ProxyPort>       Proxy server IP port, required i.e. when running\n");
-  fprintf(stderr,
-      "                         the program in a proxy server protected LAN, optional\n");
-  fprintf(stderr,
-      "    -R <maxDelay>        Reconnect mechanism with maximum delay between reconnect\n");
-  fprintf(stderr,
-      "                         attemts in seconds, default: no reconnect activated,\n");
+  fprintf(stderr, "    -F <ProxyPort>       Proxy server IP port, required i.e. when running\n");
+  fprintf(stderr, "                         the program in a proxy server protected LAN, optional\n");
+  fprintf(stderr, "    -R <maxDelay>        Reconnect mechanism with maximum delay between reconnect\n");
+  fprintf(stderr, "                         attemts in seconds, default: no reconnect activated,\n");
   fprintf(stderr, "                         optional\n\n");
-  fprintf(stderr,
-      "    -M <InputMode> Sets the input mode (1 = Serial Port, 2 = IP server,\n");
-  fprintf(stderr,
-      "       3 = File, 4 = SISNeT Data Server, 5 = UDP server, 6 = NTRIP1 Caster, 7 = NTRIP2 Caster in HTTP mode),\n");
+  fprintf(stderr, "    -M <InputMode> Sets the input mode (1 = Serial Port, 2 = IP server,\n");
+  fprintf(stderr, "       3 = File, 4 = SISNeT Data Server, 5 = UDP server, 6 = NTRIP1 Caster, 7 = NTRIP2 Caster in HTTP mode),\n");
   fprintf(stderr, "       mandatory\n\n");
   fprintf(stderr, "       <InputMode> = 1 (Serial Port):\n");
-  fprintf(stderr,
-      "       -i <Device>       Serial input device, default: %s, mandatory if\n",
-      ttyport);
+  fprintf(stderr, "       -i <Device>       Serial input device, default: %s, mandatory if\n", ttyport);
   fprintf(stderr, "                         <InputMode>=1\n");
-  fprintf(stderr,
-      "       -b <BaudRate>     Serial input baud rate, default: 19200 bps, mandatory\n");
+  fprintf(stderr, "       -b <BaudRate>     Serial input baud rate, default: 19200 bps, mandatory\n");
   fprintf(stderr, "                         if <InputMode>=1\n");
-  fprintf(stderr,
-      "       -f <InitFile>     Name of initialization file to be send to input device,\n");
+  fprintf(stderr, "       -f <InitFile>     Name of initialization file to be send to input device,\n");
   fprintf(stderr, "                         optional\n\n");
   fprintf(stderr, "       <InputMode> = 2|5 (IP port | UDP port):\n");
-  fprintf(stderr,
-      "       -H <ServerHost>   Input host name or address, default: 127.0.0.1,\n");
+  fprintf(stderr, "       -H <ServerHost>   Input host name or address, default: 127.0.0.1,\n");
   fprintf(stderr, "                         mandatory if <InputMode> = 2|5\n");
-  fprintf(stderr,
-      "       -P <ServerPort>   Input port, default: 1025, mandatory if <InputMode>= 2|5\n");
-  fprintf(stderr,
-      "       -f <ServerFile>   Name of initialization file to be send to server,\n");
+  fprintf(stderr, "       -P <ServerPort>   Input port, default: 1025, mandatory if <InputMode>= 2|5\n");
+  fprintf(stderr, "       -f <ServerFile>   Name of initialization file to be send to server,\n");
   fprintf(stderr, "                         optional\n");
-  fprintf(stderr,
-      "       -x <ServerUser>   User ID to access incoming stream, optional\n");
-  fprintf(stderr,
-      "       -y <ServerPass>   Password, to access incoming stream, optional\n");
-  fprintf(stderr,
-      "       -B                Bind to incoming UDP stream, optional for <InputMode> = 5\n\n");
+  fprintf(stderr, "       -x <ServerUser>   User ID to access incoming stream, optional\n");
+  fprintf(stderr, "       -y <ServerPass>   Password, to access incoming stream, optional\n");
+  fprintf(stderr, "       -B                Bind to incoming UDP stream, optional for <InputMode> = 5\n\n");
   fprintf(stderr, "       <InputMode> = 3 (File):\n");
-  fprintf(stderr,
-      "       -s <File>         File name to simulate stream by reading data from (log)\n");
-  fprintf(stderr,
-      "                         file, default is %s, mandatory for <InputMode> = 3\n\n",
-      filepath);
+  fprintf(stderr, "       -s <File>         File name to simulate stream by reading data from (log)\n");
+  fprintf(stderr, "                         file, default is %s, mandatory for <InputMode> = 3\n\n",  filepath);
   fprintf(stderr, "       <InputMode> = 4 (SISNeT Data Server):\n");
-  fprintf(stderr,
-      "       -H <SisnetHost>   SISNeT Data Server name or address,\n");
-  fprintf(stderr,
-      "                         default: 131.176.49.142, mandatory if <InputMode> = 4\n");
-  fprintf(stderr,
-      "       -P <SisnetPort>   SISNeT Data Server port, default: 7777, mandatory if\n");
+  fprintf(stderr, "       -H <SisnetHost>   SISNeT Data Server name or address,\n");
+  fprintf(stderr, "                         default: 131.176.49.142, mandatory if <InputMode> = 4\n");
+  fprintf(stderr, "       -P <SisnetPort>   SISNeT Data Server port, default: 7777, mandatory if\n");
   fprintf(stderr, "                         <InputMode> = 4\n");
-  fprintf(stderr,
-      "       -u <SisnetUser>   SISNeT Data Server user ID, mandatory if <InputMode> = 4\n");
-  fprintf(stderr,
-      "       -l <SisnetPass>   SISNeT Data Server password, mandatory if <InputMode> = 4\n");
-  fprintf(stderr,
-      "       -V <SisnetVers>   SISNeT Data Server Version number, options are 2.1, 3.0\n");
-  fprintf(stderr,
-      "                         or 3.1, default: 3.1, mandatory if <InputMode> = 4\n\n");
-  fprintf(stderr, "       <InputMode> = 6 (NTRIP Version 1.0 Caster):\n");
-  fprintf(stderr,
-      "       -H <SourceHost>   Source caster name or address, default: 127.0.0.1,\n");
-  fprintf(stderr, "                         mandatory if <InputMode> = 6\n");
-  fprintf(stderr,
-      "       -P <SourcePort>   Source caster port, default: 2101, mandatory if\n");
-  fprintf(stderr, "                         <InputMode> = 6\n");
-  fprintf(stderr,
-      "       -D <SourceMount>  Source caster mountpoint for stream input, mandatory if\n");
+  fprintf(stderr, "       -u <SisnetUser>   SISNeT Data Server user ID, mandatory if <InputMode> = 4\n");
+  fprintf(stderr, "       -l <SisnetPass>   SISNeT Data Server password, mandatory if <InputMode> = 4\n");
+  fprintf(stderr, "       -V <SisnetVers>   SISNeT Data Server Version number, options are 2.1, 3.0\n");
+  fprintf(stderr, "                         or 3.1, default: 3.1, mandatory if <InputMode> = 4\n\n");
+  fprintf(stderr, "       <InputMode> = 6|7 (NTRIP Version 1.0|2.0 Caster):\n");
+  fprintf(stderr, "       -H <SourceHost>   Source caster name or address, default: 127.0.0.1,\n");
+  fprintf(stderr, "                         mandatory if <InputMode> = 6|7\n");
+  fprintf(stderr, "       -P <SourcePort>   Source caster port, default: 2101, mandatory if\n");
   fprintf(stderr, "                         <InputMode> = 6|7\n");
-  fprintf(stderr,
-      "       -U <SourceUser>   Source caster user Id for input stream access, mandatory\n");
-  fprintf(stderr,
-      "                         for protected streams if <InputMode> = 6|7\n");
-  fprintf(stderr,
-      "       -W <SourcePass>   Source caster password for input stream access, mandatory\n");
-  fprintf(stderr,
-      "                         for protected streams if <InputMode> = 6|7\n\n");
-  fprintf(stderr,
-      "    -O <OutputMode> Sets output mode for communication with destination caster / server\n");
-  fprintf(stderr,
-      "       1 = http:   NTRIP Version 2.0 Caster in TCP/IP mode\n");
-  fprintf(stderr,
-      "       2 = rtsp:   NTRIP Version 2.0 Caster in RTSP/RTP mode\n");
+  fprintf(stderr, "       -D <SourceMount>  Source caster mountpoint for stream input, mandatory if\n");
+  fprintf(stderr, "                         <InputMode> = 6|7\n");
+  fprintf(stderr, "       -U <SourceUser>   Source caster user Id for input stream access, mandatory\n");
+  fprintf(stderr, "                         for protected streams if <InputMode> = 6|7\n");
+  fprintf(stderr, "       -W <SourcePass>   Source caster password for input stream access, mandatory\n");
+  fprintf(stderr, "                         for protected streams if <InputMode> = 6|7\n\n");
+  fprintf(stderr, "    -O <OutputMode> Sets output mode for communication with destination caster / server\n");
+  fprintf(stderr, "       1 = http:   NTRIP Version 2.0 Caster in TCP/IP mode\n");
+  fprintf(stderr, "       2 = rtsp:   NTRIP Version 2.0 Caster in RTSP/RTP mode\n");
   fprintf(stderr, "       3 = ntrip1: NTRIP Version 1.0 Caster\n");
-  fprintf(stderr,
-      "       4 = udp:    NTRIP Version 2.0 Caster in Plain UDP mode\n");
-  fprintf(stderr,
-      "       5 = tdc:    DABPLUS Content Server in TDC mode\n\n\n");
-  fprintf(stderr,
-      "       Defaults to NTRIP1.0, but will change to 2.0 in future versions\n");
-  fprintf(stderr,
-      "       Note that the program automatically falls back from mode rtsp to mode http and\n");
+  fprintf(stderr, "       4 = udp:    NTRIP Version 2.0 Caster in Plain UDP mode\n");
+  fprintf(stderr, "       5 = tdc:    DABPLUS Content Server in TDC mode\n\n\n");
+  fprintf(stderr, "       Defaults to NTRIP1.0, but will change to 2.0 in future versions\n");
+  fprintf(stderr, "       Note that the program automatically falls back from mode rtsp to mode http and\n");
   fprintf(stderr, "       further to mode ntrip1 if necessary.\n\n");
-  fprintf(stderr,
-      "       -a <DestHost>     Destination caster name or address, default: 127.0.0.1,\n");
+  fprintf(stderr, "       -a <DestHost>     Destination caster name or address, default: 127.0.0.1,\n");
   fprintf(stderr, "                         mandatory\n");
-  fprintf(stderr,
-      "       -p <DestPort>     Destination caster port, default: 2101,\n");
+  fprintf(stderr, "       -p <DestPort>     Destination caster port, default: 2101,\n");
   fprintf(stderr, "                         mandatory\n");
-  fprintf(stderr,
-      "       -m <DestMount>    Destination caster mountpoint for stream upload,\n");
-  fprintf(stderr,
-      "                         only for NTRIP destination casters, mandatory\n");
-  fprintf(stderr,
-      "       -n <DestUser>     Destination caster user ID for stream upload to mountpoint,\n");
-  fprintf(stderr,
-      "                         only for NTRIP Version 2.0 destination casters, mandatory\n");
-  fprintf(stderr,
-      "       -c <DestPass>     Destination caster password for stream upload to mountpoint,\n");
-  fprintf(stderr,
-      "                         only for NTRIP destination casters, mandatory\n");
+  fprintf(stderr, "       -m <DestMount>    Destination caster mountpoint for stream upload,\n");
+  fprintf(stderr, "                         only for NTRIP destination casters, mandatory\n");
+  fprintf(stderr, "       -n <DestUser>     Destination caster user ID for stream upload to mountpoint,\n");
+  fprintf(stderr, "                         only for NTRIP Version 2.0 destination casters, mandatory\n");
+  fprintf(stderr, "       -c <DestPass>     Destination caster password for stream upload to mountpoint,\n");
+  fprintf(stderr, "                         only for NTRIP destination casters, mandatory\n");
   fprintf(stderr, "       -N <STR-record>   Sourcetable STR-record\n");
-  fprintf(stderr,
-      "                         optional for NTRIP Version 2.0 in RTSP/RTP and TCP/IP mode\n\n");
+  fprintf(stderr, "                         optional for NTRIP Version 2.0 in RTSP/RTP and TCP/IP mode\n\n");
+  fprintf(stderr, "       -T <DAB+provider> DAB+ provider name, not longer than 16 char, mandatory for \n");
+  fprintf(stderr, "                         upload to DABPLUS Content Server in TDC mode\n");
   exit(rc);
 } /* usage */
@@ -2130,5 +2138,5 @@
   else {
     fprintf(stderr, "\nDestination caster request:\n");
-    fprintf(stderr, "%s", input);
+    fprintf(stderr, "%s\n", input);
   }
 #endif
