Index: trunk/ntripserver/ntripserver.c
===================================================================
--- trunk/ntripserver/ntripserver.c	(revision 9404)
+++ trunk/ntripserver/ntripserver.c	(revision 9448)
@@ -104,5 +104,5 @@
   NTRIP1 = 3,
   UDP = 4,
-  TDC = 5,
+  TCPIP = 5,
   END
 };
@@ -230,7 +230,4 @@
   const char *ntrip_str = "";
 
-  const char *dabplus_provider = 0;
-  char dabplus_provider_str[17] = "";
-
   const char *user = "";
   const char *password = "";
@@ -296,5 +293,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:T: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:n:B")) != EOF) {
     switch (c) {
       case 'M': /*** InputMode ***/
@@ -422,6 +419,6 @@
         else if (!strcmp(optarg, "u") || !strcmp(optarg, "udp"))
           outputmode = UDP;
-        else if (!strcmp(optarg, "t") || !strcmp(optarg, "tdc"))
-          outputmode = TDC;
+        else if (!strcmp(optarg, "t") || !strcmp(optarg, "tcpip"))
+          outputmode = TCPIP;
         else
           outputmode = atoi(optarg);
@@ -438,7 +435,4 @@
         ntrip_str = optarg;
         break;
-      case 'T':
-        dabplus_provider = optarg;
-        break;
       case 'h': /* print help screen */
       case '?':
@@ -471,29 +465,14 @@
   }
 
-  if (!mountpoint && outputmode != TDC) {
+  if (!mountpoint && outputmode != TCPIP) {
     fprintf(stderr, "ERROR: Missing mountpoint argument for stream upload\n");
     exit(1);
   }
-
-  if (outputmode == TDC) {
-    fprintf(stderr, "ERROR: DABPLUS server upload implementation is so far not completed\n\n");
-    exit(0);
-
+  if (outputmode == TCPIP) {
     mountpoint = NULL;
-    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);
-    }
   }
 
   if (!password[0]) {
-    if (outputmode != TDC)
+    if (outputmode != TCPIP)
       fprintf(stderr,
           "WARNING: Missing password argument for stream upload - are you really sure?\n");
@@ -515,27 +494,6 @@
   /*** proxy server handling ***/
   if (*proxyhost) {
-    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)) {
-      fprintf(stderr,
-          "ERROR: Destination caster name/port to long - length = %d (max: %d)\n",
-          i, SZ);
-      exit(0);
-    } else {
-      strncpy(post_extension, szSendBuffer, (size_t) i);
-      strcpy(szSendBuffer, "");
-      i = snprintf(szSendBuffer, sizeof(szSendBuffer), ":%d", casteroutport);
-      strncpy(rtsp_extension, szSendBuffer, SZ);
-      strcpy(szSendBuffer, ""); i = 0;
-    }
+    inhost = proxyhost;
+    inport = proxyport;
     i = snprintf(szSendBuffer, sizeof(szSendBuffer), "http://%s:%d", casterinhost, casterinport);
     if ((i > SZ) || (i < 0)) {
@@ -549,4 +507,27 @@
       i = 0;
     }
+    if (strstr(casterouthost, "127.0.0.1") ||
+        strstr(casterouthost, "localhost")) {
+      outhost = casterouthost;
+      outport = casteroutport;
+    }
+    else {
+      outhost = proxyhost;
+      outport = proxyport;
+      i = snprintf(szSendBuffer, sizeof(szSendBuffer), "http://%s:%d", casterouthost, casteroutport);
+      if ((i > SZ) || (i < 0)) {
+        fprintf(stderr,
+            "ERROR: Destination caster name/port to long - length = %d (max: %d)\n",
+            i, SZ);
+        exit(0);
+      } else {
+        strncpy(post_extension, szSendBuffer, (size_t) i);
+        strcpy(szSendBuffer, "");
+        i = snprintf(szSendBuffer, sizeof(szSendBuffer), ":%d", casteroutport);
+        strncpy(rtsp_extension, szSendBuffer, SZ);
+        strcpy(szSendBuffer, ""); i = 0;
+      }
+    }
+
   } else {
     outhost = casterouthost;
@@ -682,6 +663,5 @@
           }
         } /* connect to input-caster or proxy server*/
-        else if (connect(gps_socket, (struct sockaddr*) &caster, sizeof(caster))
-            < 0) {
+        else if (connect(gps_socket, (struct sockaddr*) &caster, sizeof(caster)) < 0) {
           fprintf(stderr, "WARNING: can't connect input to %s at port %d\n",
               inet_ntoa(caster.sin_addr), inport);
@@ -728,5 +708,5 @@
         szSendBuffer[nBufferBytes++] = '\r';
         szSendBuffer[nBufferBytes++] = '\n';
-        // fprintf(stdout, "%s\n", 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");
@@ -917,5 +897,4 @@
         break;
       }
-
       memset((char*) &caster, 0x00, sizeof(caster));
       memcpy(&caster.sin_addr, he->h_addr, (size_t)he->h_length);
@@ -929,5 +908,5 @@
           outputmode == HTTP   ? "http"   :
           outputmode == UDP    ? "udp"    :
-          outputmode == RTSP   ? "rtsp"   : "tdc");
+          outputmode == RTSP   ? "rtsp"   : "tcpip");
 
       if (connect(socket_tcp, (struct sockaddr*) &caster, sizeof(caster)) < 0) {
@@ -1190,6 +1169,5 @@
             break;
           }
-          if ((getsockname(socket_udp, (struct sockaddr*) &local, &len))
-              != -1) {
+          if ((getsockname(socket_udp, (struct sockaddr*) &local, &len)) != -1) {
             client_port = (unsigned int) ntohs(local.sin_port);
           } else {
@@ -1327,27 +1305,6 @@
           input_init = output_init = 0;
           break;
-        case TDC:
+        case TCPIP:
           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;
@@ -1580,5 +1537,5 @@
     /*  send data    */
     /*****************/
-    if ((nBufferBytes) && (outmode == NTRIP1)) {
+    if ((nBufferBytes) && (outmode == NTRIP1 || outmode == TCPIP)) {
       int i;
       if ((i = send(sock, buffer, (size_t) nBufferBytes, MSG_DONTWAIT)) != nBufferBytes) {
@@ -1750,6 +1707,19 @@
       }
     }
-    else if ((nBufferBytes) && (outmode == TDC)) {
-
+    else if ((nBufferBytes) && (outmode == TCPIP)) {
+      int i;
+      if ((i = send(sock, buffer, (size_t) nBufferBytes, MSG_DONTWAIT)) != nBufferBytes) {
+        if (i < 0) {
+          if (errno != EAGAIN) {
+            perror("WARNING: could not send data to IP server and port");
+            return;
+          }
+        } else if (i) {
+          memmove(buffer, buffer + i, (size_t) (nBufferBytes - i));
+          nBufferBytes -= i;
+        }
+      } else {
+        nBufferBytes = 0;
+      }
     }
     if (send_recv_success == 3)
@@ -1939,7 +1909,9 @@
   fprintf(stderr,
       "   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 DABPLUS Content Server via TCP/IP and TDC \n\n\n");
+  fprintf(stderr, "     1. an NTRIP Version 2.0 Caster via TCP/IP (Output, Destination), or\n");
+  fprintf(stderr, "     2. an NTRIP Version 2.0 Caster via RTSP/RTP (Output, Destination), or\n");
+  fprintf(stderr, "     3. an NTRIP Version 2.0 Caster via plain UDP (Output, Destination), or\n");
+  fprintf(stderr, "     4. an NTRIP Version 1.0 Caster, or\n");
+  fprintf(stderr, "     5. an IP server via TCP/IP\n\n\n");
   fprintf(stderr, "OPTIONS\n");
   fprintf(stderr, "   -h|? print this help screen\n\n");
@@ -1953,5 +1925,6 @@
   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, "       3 = File, 4 = SISNeT Data Server, 5 = UDP server, 6 = NTRIP1 Caster,\n");
+  fprintf(stderr, "       7 = NTRIP2 Caster in HTTP mode),\n");
   fprintf(stderr, "       mandatory\n\n");
   fprintf(stderr, "       <InputMode> = 1 (Serial Port):\n");
@@ -1995,15 +1968,15 @@
   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, "       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, "       4 = udp   : NTRIP Version 2.0 Caster in Plain UDP mode\n");
+  fprintf(stderr, "       5 = tcpip : IP server in TCP/IP 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/server 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/server port, default: 2101,\n");
   fprintf(stderr, "                         mandatory\n");
   fprintf(stderr, "       -m <DestMount>    Destination caster mountpoint for stream upload,\n");
@@ -2015,6 +1988,4 @@
   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, "       -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 */
