Changeset 469 in ntrip


Ignore:
Timestamp:
Jun 6, 2007, 4:56:59 PM (17 years ago)
Author:
stoecker
Message:

cleanup and tests

Location:
trunk/ntripserver
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/ntripserver/NtripLinuxServer.c

    r467 r469  
    11/*
    2  * $Id: NtripLinuxServer.c,v 1.28 2007/06/06 09:44:27 stoecker Exp $
     2 * $Id: NtripLinuxServer.c,v 1.29 2007/06/06 12:16:08 stoecker Exp $
    33 *
    44 * Copyright (c) 2003...2007
     
    3737
    3838/* CVS revision and version */
    39 static char revisionstr[] = "$Revision: 1.28 $";
    40 static char datestr[]     = "$Date: 2007/06/06 09:44:27 $";
     39static char revisionstr[] = "$Revision: 1.29 $";
     40static char datestr[]     = "$Date: 2007/06/06 12:16:08 $";
    4141
    4242#include <ctype.h>
     
    7171CASTER = 6, LAST };
    7272
    73 enum OUTMODE { NTRIPV1, HTTP, RTSP, END };
     73enum OUTMODE { HTTP = 1, RTSP = 2, NTRIPV1 = 3, END };
    7474
    7575#define AGENTSTRING     "NTRIP NtripServerLinux"
     
    180180
    181181  /*** OUTPUT ***/
    182   const char *       casterouthost = 0;
    183   unsigned int       casteroutport = 0;
     182  const char *       casterouthost = NTRIP_CASTER;
     183  unsigned int       casteroutport = NTRIP_PORT;
    184184  const char *       outhost = 0;
    185185  unsigned int       outport = 0;
     
    352352      proxyport = atoi(optarg);
    353353      break;
    354     case 'O': /* OutputMode - default: Ntrip-Version 2.0 TCP/IP */
    355       if     (!strcmp(optarg,"f")) outputmode = NTRIPV1;
    356       else if(!strcmp(optarg,"r")) outputmode = RTSP;
     354    case 'O': /* OutputMode */
     355      outputmode = 0;
     356      if (!strcmp(optarg,"n") || !strcmp(optarg,"ntrip1"))
     357        outputmode = NTRIPV1;
     358      else if(!strcmp(optarg,"h") || !strcmp(optarg,"http"))
     359        outputmode = HTTP;
     360      else if(!strcmp(optarg,"r") || !strcmp(optarg,"rtsp"))
     361        outputmode = RTSP;
     362      else outputmode = atoi(optarg);
     363      if((outputmode == 0) || (outputmode >= END))
     364      {
     365        fprintf(stderr, "ERROR: can't convert <%s> to a valid OutputMode\n",
     366        optarg);
     367        usage(-1, argv[0]);
     368      }
    357369      break;
    358370    case 'n': /* Destination caster user ID for stream upload to mountpoint */
     
    504516      {
    505517        if(!inport) inport = SERV_TCP_PORT;
    506         if(!inhost) inhost = "127.0.0.1";
     518        if(!inhost) inhost = SERV_HOST_ADDR;
    507519      }
    508520
     
    765777
    766778    /* connect to Destination caster or Proxy server*/
    767     fprintf(stderr, "caster output: host = %s, port = %d, mountpoint = %s\n",
    768     inet_ntoa(caster.sin_addr), outport, mountpoint);
     779    fprintf(stderr, "caster output: host = %s, port = %d, mountpoint = %s"
     780    ", mode = %s\n", inet_ntoa(caster.sin_addr), outport, mountpoint,
     781    outputmode == NTRIPV1 ? "ntrip1" : outputmode == HTTP ? "http" : "rtsp");
    769782
    770783    if(connect(socket_tcp, (struct sockaddr *) &caster, sizeof(caster)) < 0)
     
    810823          break;
    811824        }
     825#ifndef NDEBUG
    812826        else
    813827        {
     
    816830          szSendBuffer);
    817831        }
     832#endif
    818833        send_receive_loop(socket_tcp, gpsfd, outputmode, NULL, 0);
    819834        break;
     
    823838          "Host: %s\r\n"
    824839          "Ntrip-Version: Ntrip/2.0\r\n"
    825           "User-Agent: NTRIP %s\r\n"
     840          "User-Agent: %s/%s\r\n"
    826841          "Authorization: Basic %s\r\n"
    827842          "Ntrip-STR: %s\r\n"
    828843          "Transfer-Encoding: chunked\r\n\r\n",
    829844          post_extension, mountpoint, casterouthost, AGENTSTRING,
    830           authorization, ntrip_str);
     845          revisionstr, authorization, ntrip_str);
    831846        if((nBufferBytes > (int)sizeof(szSendBuffer)) || (nBufferBytes < 0))
    832847        {
     
    847862          char *a;
    848863          fprintf(stderr,
    849           "ERROR: Destination caster's or Proxy's reply is not OK: ");
     864          "ERROR: Destination caster's%s reply is not OK: ",
     865          *proxyhost ? " or Proxy's" : "");
    850866          for(a = szSendBuffer; *a && *a != '\n' && *a != '\r'; ++a)
    851867          {
     
    857873          {
    858874            fprintf(stderr,
    859             " - Ntrip Version 2.0 not implemented at Destination caster"
    860             " <%s> or Proxy <%s> or\n"
    861             " - HTTP/1.1 not implemented at Proxy or\n"
    862             " - RTSP/1.0 not implemented at Destination caster or Proxy\n\n"
    863             "caster fallback: Fallback to Ntrip Version 1.0\n\n",
    864             casterouthost, proxyhost);
     875            " Ntrip Version 2.0 not implemented at Destination caster"
     876            " <%s>%s%s%s\n%s\n"
     877            "caster fallback: Fallback to Ntrip Version 1.0\n",
     878            casterouthost,
     879            *proxyhost ? " or Proxy <" : "", proxyhost, *proxyhost ? ">" : "",
     880            *proxyhost ? " or HTTP/1.1 not implemented at Proxy\n" : "");
    865881            outputmode = NTRIPV1;
    866882            break;
     
    910926          "Ntrip-Version: Ntrip/2.0\r\n"
    911927          "Ntrip-Component: Ntripserver\r\n"
    912           "User-Agent: NTRIP %s \r\n"
     928          "User-Agent: %s/%s\r\n"
    913929          "Transport: RTP/GNSS;unicast;client_port=%u\r\n"
    914930          "Authorization: Basic %s\r\n"
    915931          "Ntrip-STR: %s\r\n\r\n",
    916           casterouthost, rtsp_extension, mountpoint, AGENTSTRING, client_port,
    917           authorization, ntrip_str);
     932          casterouthost, rtsp_extension, mountpoint, AGENTSTRING, revisionstr,
     933          client_port, authorization, ntrip_str);
    918934        if((nBufferBytes > (int)sizeof(szSendBuffer)) || (nBufferBytes < 0))
    919935        {
     
    936952            char *a;
    937953            fprintf(stderr,
    938             "ERROR: Destination caster's or Proxy's reply is not OK: ");
     954            "ERROR: Destination caster's%s reply is not OK: ",
     955            *proxyhost ? " or Proxy's" : "");
    939956            for(a = szSendBuffer; *a && *a != '\n' && *a != '\r'; ++a)
    940957            {
     
    948965              {
    949966                fprintf(stderr,
    950                 " - RTSP not implemented at Destination caster <%s> or"
    951                 " Proxy <%s>\n\n"
     967                " - RTSP not implemented at Destination caster <%s>%s%s%s\n\n"
    952968                "caster fallback: Fallback to Ntrip Version 2.0 in TCP/IP"
    953                 " mode\n\n", casterouthost, proxyhost);
     969                " mode\n\n", casterouthost,
     970                *proxyhost ? " or Proxy <" :"", proxyhost, *proxyhost ? ">":"");
    954971                outputmode = HTTP;
    955972                break;
     
    958975              {
    959976                fprintf(stderr,
    960                 " - Ntrip-Version 2.0 not implemented at Destination caster"
    961                 "<%s> or Proxy <%s> or\n"
    962                 " - HTTP/1.1 not implemented at Proxy or\n"
    963                 " - RTSP/1.0 not implemented at Destination caster or Proxy\n\n"
    964                 "caster fallback: Fallback to Ntrip Version 1.0\n\n",
    965                 casterouthost, proxyhost);
     977                " Ntrip-Version 2.0 not implemented at Destination caster"
     978                "<%s>%s%s%s\n%s"
     979                " or RTSP/1.0 not implemented at Destination caster%s\n\n"
     980                "caster fallback: Fallback to Ntrip Version 1.0\n",
     981                casterouthost, *proxyhost ? " or Proxy <" :"", proxyhost,
     982                *proxyhost ? ">":"",
     983                *proxyhost ? " or HTTP/1.1 not implemented at Proxy\n" : "",
     984                *proxyhost ? " or Proxy" :"");
    966985                outputmode = NTRIPV1;
    967986                break;
     
    974993            }
    975994          }
     995#ifndef NDEBUG
    976996          else
    977997          {
    978998            fprintf(stderr, "Destination caster response:\n%s\n",szSendBuffer);
    979999          }
     1000#endif
    9801001          if((strstr(szSendBuffer,"RTSP/1.0 200 OK\r\n"))
    9811002          && (strstr(szSendBuffer,"CSeq: 1\r\n")))
     
    11751196      if(signal_was_caught())
    11761197      {
    1177         fprintf(stderr, "NtripLinuxServer exits send-receive mode \n");
     1198        fprintf(stderr, "NtripLinuxServer exits send-receive mode\n");
    11781199        break;
    11791200      }
     
    14401461  fprintf(stderr, "       -W <SourcePass>   Source caster password for input stream access, mandatory\n");
    14411462  fprintf(stderr, "                         for protected streams if <InputMode> = 6\n\n");
    1442   fprintf(stderr, "    -O <OutputMode> Sets the output mode for communatation with the destination\n");
    1443   fprintf(stderr, "       caster (r = NTRIP Version 2.0 Caster in RTSP/RTP mode, t = Ntrip Version 2.0\n");
    1444   fprintf(stderr, "       Caster in TCP/IP mode, f = NTRIP Version 1.0 Caster)\n\n");
     1463  fprintf(stderr, "    -O <OutputMode> Sets output mode for communatation with destination caster\n");
     1464  fprintf(stderr, "       0 = h = http: Ntrip Version 2.0 Caster in TCP/IP mode\n");
     1465  fprintf(stderr, "       1 = r = rtsp: NTRIP Version 2.0 Caster in RTSP/RTP mode\n");
     1466  fprintf(stderr, "       2 = n = ntrip1: NTRIP Version 1.0 Caster\n\n");
    14451467  fprintf(stderr, "       Defaults to NTRIP1.0, but wil change to 2.0 in future versions\n");
    14461468  fprintf(stderr, "       Note that the program automatically falls back from mode r to mode t and\n");
     
    14921514  fflush(stdout);
    14931515  if(sigint_received)
    1494     fprintf(stderr, "\nSIGINT received: ");
     1516    fprintf(stderr, "SIGINT received: ");
    14951517
    14961518  return (sigint_received);
     
    15561578static int send_to_caster(char *input, int socket, int input_size)
    15571579{
    1558 int send_error = 1;
     1580 int send_error = 1;
    15591581
    15601582  if((send(socket, input, (size_t)input_size, 0)) != input_size)
     
    15621584    fprintf(stderr, "ERROR: could not send full header to Destination caster\n");
    15631585    send_error = 0;
    1564   }else{
     1586  }
     1587#ifndef NDEBUG
     1588  else
     1589  {
    15651590    fprintf(stderr, "\nDestination caster request:\n");
    15661591    fprintf(stderr, "%s", input);
    15671592  }
     1593#endif
    15681594  return send_error;
    15691595}/* send_to_caster */
     
    15871613      exit(0);
    15881614    }
     1615#ifndef NDEBUG
    15891616    else
    15901617    {
    15911618      fprintf(stderr, "\nclose input device: successful\n");
    15921619    }
     1620#endif
    15931621  }
    15941622
     
    16111639      size_send_buf = recv(sock_tcp, send_buf, sizeof(send_buf), 0);
    16121640      send_buf[size_send_buf] = '\0';
     1641#ifndef NDEBUG
    16131642      fprintf(stderr, "Destination caster response:\n%s", send_buf);
     1643#endif
    16141644    }
    16151645    if(close(sock_udp)==-1)
     
    16181648      exit(0);
    16191649    }
     1650#ifndef NDEBUG
    16201651    else
    16211652    {
    16221653      fprintf(stderr, "close udp socket:   successful\n");
    16231654    }
     1655#endif
    16241656  }
    16251657
     
    16291661    exit(0);
    16301662  }
     1663#ifndef NDEBUG
    16311664  else
    16321665  {
    16331666    fprintf(stderr, "close tcp socket:   successful\n\n");
    16341667  }
     1668#endif
    16351669} /* close_session */
  • trunk/ntripserver/makefile

    r468 r469  
    22
    33NtripServerLinux: NtripLinuxServer.c
    4         $(CC) -Wall -W -O3 $? -o $@
     4        $(CC) -Wall -W -O3 $? -DNDEBUG -o $@
     5
     6debug: NtripLinuxServer.c
     7        $(CC) -Wall -W -O3 $? -o NtripServerLinux
    58
    69clean:
Note: See TracChangeset for help on using the changeset viewer.