Changeset 9448 in ntrip for trunk/ntripserver/ntripserver.c


Ignore:
Timestamp:
May 28, 2021, 12:23:36 PM (15 months ago)
Author:
stuerze
Message:

data upload to localhost added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ntripserver/ntripserver.c

    r9404 r9448  
    104104  NTRIP1 = 3,
    105105  UDP = 4,
    106   TDC = 5,
     106  TCPIP = 5,
    107107  END
    108108};
     
    230230  const char *ntrip_str = "";
    231231
    232   const char *dabplus_provider = 0;
    233   char dabplus_provider_str[17] = "";
    234 
    235232  const char *user = "";
    236233  const char *password = "";
     
    296293  }
    297294  while ((c = getopt(argc, argv,
    298       "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) {
     295      "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) {
    299296    switch (c) {
    300297      case 'M': /*** InputMode ***/
     
    422419        else if (!strcmp(optarg, "u") || !strcmp(optarg, "udp"))
    423420          outputmode = UDP;
    424         else if (!strcmp(optarg, "t") || !strcmp(optarg, "tdc"))
    425           outputmode = TDC;
     421        else if (!strcmp(optarg, "t") || !strcmp(optarg, "tcpip"))
     422          outputmode = TCPIP;
    426423        else
    427424          outputmode = atoi(optarg);
     
    438435        ntrip_str = optarg;
    439436        break;
    440       case 'T':
    441         dabplus_provider = optarg;
    442         break;
    443437      case 'h': /* print help screen */
    444438      case '?':
     
    471465  }
    472466
    473   if (!mountpoint && outputmode != TDC) {
     467  if (!mountpoint && outputmode != TCPIP) {
    474468    fprintf(stderr, "ERROR: Missing mountpoint argument for stream upload\n");
    475469    exit(1);
    476470  }
    477 
    478   if (outputmode == TDC) {
    479     fprintf(stderr, "ERROR: DABPLUS server upload implementation is so far not completed\n\n");
    480     exit(0);
    481 
     471  if (outputmode == TCPIP) {
    482472    mountpoint = NULL;
    483     if (dabplus_provider) {
    484       i = snprintf(dabplus_provider_str, 17, "%16s", dabplus_provider);
    485       if ((i > 16) || (i < 0)) {
    486         fprintf(stderr, "ERROR: DABPLUS provider name to long - length = %d (max: %d)\n", i, 16);
    487         exit(0);
    488       }
    489     }
    490     else {
    491       fprintf(stderr, "ERROR: DABPLUS provider name required\n");
    492       exit(0);
    493     }
    494473  }
    495474
    496475  if (!password[0]) {
    497     if (outputmode != TDC)
     476    if (outputmode != TCPIP)
    498477      fprintf(stderr,
    499478          "WARNING: Missing password argument for stream upload - are you really sure?\n");
     
    515494  /*** proxy server handling ***/
    516495  if (*proxyhost) {
    517     if (outputmode == TDC) {
    518       fprintf(stderr, "\nWARNING: TDC is not able to support proxy servers, try direct connection\n\n");
    519       inhost = proxyhost;
    520       inport = proxyport;
    521       outhost = casterouthost;
    522       outport = casteroutport;
    523     } else {
    524       outhost = inhost = proxyhost;
    525       outport = inport = proxyport;
    526     }
    527     i = snprintf(szSendBuffer, sizeof(szSendBuffer), "http://%s:%d", casterouthost, casteroutport);
    528     if ((i > SZ) || (i < 0)) {
    529       fprintf(stderr,
    530           "ERROR: Destination caster name/port to long - length = %d (max: %d)\n",
    531           i, SZ);
    532       exit(0);
    533     } else {
    534       strncpy(post_extension, szSendBuffer, (size_t) i);
    535       strcpy(szSendBuffer, "");
    536       i = snprintf(szSendBuffer, sizeof(szSendBuffer), ":%d", casteroutport);
    537       strncpy(rtsp_extension, szSendBuffer, SZ);
    538       strcpy(szSendBuffer, ""); i = 0;
    539     }
     496    inhost = proxyhost;
     497    inport = proxyport;
    540498    i = snprintf(szSendBuffer, sizeof(szSendBuffer), "http://%s:%d", casterinhost, casterinport);
    541499    if ((i > SZ) || (i < 0)) {
     
    549507      i = 0;
    550508    }
     509    if (strstr(casterouthost, "127.0.0.1") ||
     510        strstr(casterouthost, "localhost")) {
     511      outhost = casterouthost;
     512      outport = casteroutport;
     513    }
     514    else {
     515      outhost = proxyhost;
     516      outport = proxyport;
     517      i = snprintf(szSendBuffer, sizeof(szSendBuffer), "http://%s:%d", casterouthost, casteroutport);
     518      if ((i > SZ) || (i < 0)) {
     519        fprintf(stderr,
     520            "ERROR: Destination caster name/port to long - length = %d (max: %d)\n",
     521            i, SZ);
     522        exit(0);
     523      } else {
     524        strncpy(post_extension, szSendBuffer, (size_t) i);
     525        strcpy(szSendBuffer, "");
     526        i = snprintf(szSendBuffer, sizeof(szSendBuffer), ":%d", casteroutport);
     527        strncpy(rtsp_extension, szSendBuffer, SZ);
     528        strcpy(szSendBuffer, ""); i = 0;
     529      }
     530    }
     531
    551532  } else {
    552533    outhost = casterouthost;
     
    682663          }
    683664        } /* connect to input-caster or proxy server*/
    684         else if (connect(gps_socket, (struct sockaddr*) &caster, sizeof(caster))
    685             < 0) {
     665        else if (connect(gps_socket, (struct sockaddr*) &caster, sizeof(caster)) < 0) {
    686666          fprintf(stderr, "WARNING: can't connect input to %s at port %d\n",
    687667              inet_ntoa(caster.sin_addr), inport);
     
    728708        szSendBuffer[nBufferBytes++] = '\r';
    729709        szSendBuffer[nBufferBytes++] = '\n';
    730         // fprintf(stdout, "%s\n", szSendBuffer);
     710        fprintf(stdout, "%s\n", szSendBuffer);
    731711        if ((send(gps_socket, szSendBuffer, (size_t) nBufferBytes, 0)) != nBufferBytes) {
    732712          fprintf(stderr, "WARNING: could not send Source caster request\n");
     
    917897        break;
    918898      }
    919 
    920899      memset((char*) &caster, 0x00, sizeof(caster));
    921900      memcpy(&caster.sin_addr, he->h_addr, (size_t)he->h_length);
     
    929908          outputmode == HTTP   ? "http"   :
    930909          outputmode == UDP    ? "udp"    :
    931           outputmode == RTSP   ? "rtsp"   : "tdc");
     910          outputmode == RTSP   ? "rtsp"   : "tcpip");
    932911
    933912      if (connect(socket_tcp, (struct sockaddr*) &caster, sizeof(caster)) < 0) {
     
    11901169            break;
    11911170          }
    1192           if ((getsockname(socket_udp, (struct sockaddr*) &local, &len))
    1193               != -1) {
     1171          if ((getsockname(socket_udp, (struct sockaddr*) &local, &len)) != -1) {
    11941172            client_port = (unsigned int) ntohs(local.sin_port);
    11951173          } else {
     
    13271305          input_init = output_init = 0;
    13281306          break;
    1329         case TDC:
     1307        case TCPIP:
    13301308          fallback = 0;
    1331           szSendBuffer[0] = 0x28;
    1332           szSendBuffer[1] = 0x11;
    1333           szSendBuffer[2] = 0x19;
    1334           szSendBuffer[3] = 0x69;
    1335           strncpy(szSendBuffer + 4, dabplus_provider_str, 16);
    1336           szSendBuffer[20] = 0; // mot
    1337           nBufferBytes =  strlen(szSendBuffer);
    1338           if ((nBufferBytes > 20) || (nBufferBytes < 0)) {
    1339             fprintf(stderr, "ERROR: Destination server request to long\n");
    1340             reconnect_sec_max = 0;
    1341             output_init = 0;
    1342             break;
    1343           }
    1344           if (!send_to_caster(szSendBuffer, socket_tcp, nBufferBytes)) {
    1345             output_init = 0;
    1346             break;
    1347           }
    1348           /* check Destination server's response
    1349           in case of a unidirectional connection muxd will close the connection
    1350           if an error occurs without transmitting any status information
    1351           */
    13521309          send_receive_loop(socket_tcp, outputmode, NULL, 0, 0, chunkymode);
    13531310          input_init = output_init = 0;
     
    15801537    /*  send data    */
    15811538    /*****************/
    1582     if ((nBufferBytes) && (outmode == NTRIP1)) {
     1539    if ((nBufferBytes) && (outmode == NTRIP1 || outmode == TCPIP)) {
    15831540      int i;
    15841541      if ((i = send(sock, buffer, (size_t) nBufferBytes, MSG_DONTWAIT)) != nBufferBytes) {
     
    17501707      }
    17511708    }
    1752     else if ((nBufferBytes) && (outmode == TDC)) {
    1753 
     1709    else if ((nBufferBytes) && (outmode == TCPIP)) {
     1710      int i;
     1711      if ((i = send(sock, buffer, (size_t) nBufferBytes, MSG_DONTWAIT)) != nBufferBytes) {
     1712        if (i < 0) {
     1713          if (errno != EAGAIN) {
     1714            perror("WARNING: could not send data to IP server and port");
     1715            return;
     1716          }
     1717        } else if (i) {
     1718          memmove(buffer, buffer + i, (size_t) (nBufferBytes - i));
     1719          nBufferBytes -= i;
     1720        }
     1721      } else {
     1722        nBufferBytes = 0;
     1723      }
    17541724    }
    17551725    if (send_recv_success == 3)
     
    19391909  fprintf(stderr,
    19401910      "   and forward that incoming stream (Output, Destination) to either\n\n");
    1941   fprintf(stderr, "     - an NTRIP Version 1.0 Caster, or\n");
    1942   fprintf(stderr, "     - an NTRIP Version 2.0 Caster via TCP/IP or RTSP/RTP, or \n");
    1943   fprintf(stderr, "     - an DABPLUS Content Server via TCP/IP and TDC \n\n\n");
     1911  fprintf(stderr, "     1. an NTRIP Version 2.0 Caster via TCP/IP (Output, Destination), or\n");
     1912  fprintf(stderr, "     2. an NTRIP Version 2.0 Caster via RTSP/RTP (Output, Destination), or\n");
     1913  fprintf(stderr, "     3. an NTRIP Version 2.0 Caster via plain UDP (Output, Destination), or\n");
     1914  fprintf(stderr, "     4. an NTRIP Version 1.0 Caster, or\n");
     1915  fprintf(stderr, "     5. an IP server via TCP/IP\n\n\n");
    19441916  fprintf(stderr, "OPTIONS\n");
    19451917  fprintf(stderr, "   -h|? print this help screen\n\n");
     
    19531925  fprintf(stderr, "                         optional\n\n");
    19541926  fprintf(stderr, "    -M <InputMode> Sets the input mode (1 = Serial Port, 2 = IP server,\n");
    1955   fprintf(stderr, "       3 = File, 4 = SISNeT Data Server, 5 = UDP server, 6 = NTRIP1 Caster, 7 = NTRIP2 Caster in HTTP mode),\n");
     1927  fprintf(stderr, "       3 = File, 4 = SISNeT Data Server, 5 = UDP server, 6 = NTRIP1 Caster,\n");
     1928  fprintf(stderr, "       7 = NTRIP2 Caster in HTTP mode),\n");
    19561929  fprintf(stderr, "       mandatory\n\n");
    19571930  fprintf(stderr, "       <InputMode> = 1 (Serial Port):\n");
     
    19951968  fprintf(stderr, "                         for protected streams if <InputMode> = 6|7\n\n");
    19961969  fprintf(stderr, "    -O <OutputMode> Sets output mode for communication with destination caster / server\n");
    1997   fprintf(stderr, "       1 = http NTRIP Version 2.0 Caster in TCP/IP mode\n");
    1998   fprintf(stderr, "       2 = rtsp NTRIP Version 2.0 Caster in RTSP/RTP mode\n");
     1970  fprintf(stderr, "       1 = http  : NTRIP Version 2.0 Caster in TCP/IP mode\n");
     1971  fprintf(stderr, "       2 = rtsp  : NTRIP Version 2.0 Caster in RTSP/RTP mode\n");
    19991972  fprintf(stderr, "       3 = ntrip1: NTRIP Version 1.0 Caster\n");
    2000   fprintf(stderr, "       4 = udp:    NTRIP Version 2.0 Caster in Plain UDP mode\n");
    2001   fprintf(stderr, "       5 = tdc:    DABPLUS Content Server in TDC mode\n\n\n");
     1973  fprintf(stderr, "       4 = udp   : NTRIP Version 2.0 Caster in Plain UDP mode\n");
     1974  fprintf(stderr, "       5 = tcpip : IP server in TCP/IP mode\n\n\n");
    20021975  fprintf(stderr, "       Defaults to NTRIP1.0, but will change to 2.0 in future versions\n");
    20031976  fprintf(stderr, "       Note that the program automatically falls back from mode rtsp to mode http and\n");
    20041977  fprintf(stderr, "       further to mode ntrip1 if necessary.\n\n");
    2005   fprintf(stderr, "       -a <DestHost>     Destination caster name or address, default: 127.0.0.1,\n");
     1978  fprintf(stderr, "       -a <DestHost>     Destination caster/server name or address, default: 127.0.0.1,\n");
    20061979  fprintf(stderr, "                         mandatory\n");
    2007   fprintf(stderr, "       -p <DestPort>     Destination caster port, default: 2101,\n");
     1980  fprintf(stderr, "       -p <DestPort>     Destination caster/server port, default: 2101,\n");
    20081981  fprintf(stderr, "                         mandatory\n");
    20091982  fprintf(stderr, "       -m <DestMount>    Destination caster mountpoint for stream upload,\n");
     
    20151988  fprintf(stderr, "       -N <STR-record>   Sourcetable STR-record\n");
    20161989  fprintf(stderr, "                         optional for NTRIP Version 2.0 in RTSP/RTP and TCP/IP mode\n\n");
    2017   fprintf(stderr, "       -T <DAB+provider> DAB+ provider name, not longer than 16 char, mandatory for \n");
    2018   fprintf(stderr, "                         upload to DABPLUS Content Server in TDC mode\n");
    20191990  exit(rc);
    20201991} /* usage */
Note: See TracChangeset for help on using the changeset viewer.