Changeset 915 in ntrip


Ignore:
Timestamp:
May 16, 2008, 9:33:31 AM (14 years ago)
Author:
stoecker
Message:

fixes for NTRIPV2 pre standard

Location:
trunk/ntripserver
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/ntripserver

    • Property svn:ignore
      •  

        old new  
        1 NtripServerLinux
        2 NtripServerLinux.zip
         1ntripserver
         2ntripserver.tgz
  • trunk/ntripserver/.cvsignore

    r470 r915  
    1 NtripServerLinux
    2 NtripServerLinux.zip
     1ntripserver
     2ntripserver.tgz
  • trunk/ntripserver/ntripserver.c

    r768 r915  
    11/*
    2  * $Id: ntripserver.c,v 1.39 2008/04/04 10:03:11 stoecker Exp $
     2 * $Id: ntripserver.c,v 1.40 2008/04/04 13:07:31 stuerze Exp $
    33 *
    44 * Copyright (c) 2003...2007
     
    3737
    3838/* CVS revision and version */
    39 static char revisionstr[] = "$Revision: 1.39 $";
    40 static char datestr[]     = "$Date: 2008/04/04 10:03:11 $";
     39static char revisionstr[] = "$Revision: 1.40 $";
     40static char datestr[]     = "$Date: 2008/04/04 13:07:31 $";
    4141
    4242#include <ctype.h>
     
    128128static int sigint_received     = 0;
    129129static int reconnect_sec       = 1;
    130 
     130static const char * casterouthost = NTRIP_CASTER;
     131static char rtsp_extension[SZ] = "";
     132static const char * mountpoint = NULL;
     133static int udp_cseq            = 1;
    131134
    132135/* Forward references */
     
    136139static int  encode(char *buf, int size, const char *user, const char *pwd);
    137140static int  send_to_caster(char *input, sockettype socket, int input_size);
    138 static void close_session(const char *caster_addr, const char *mountpoint, 
    139   int cseq, int session, char *rtsp_ext, int fallback);
     141static void close_session(const char *caster_addr, const char *mountpoint,
     142  int session, char *rtsp_ext, int fallback);
    140143static int  reconnect(int rec_sec, int rec_sec_max);
    141144static void handle_sigint(int sig);
     
    184187
    185188  struct hostent *   he;
    186   const char *       mountpoint = NULL;
    187189
    188190  const char *       sisnetpassword = "";
     
    201203
    202204  /*** OUTPUT ***/
    203   const char *       casterouthost = NTRIP_CASTER;
    204205  unsigned int       casteroutport = NTRIP_PORT;
    205206  const char *       outhost = 0;
    206207  unsigned int       outport = 0;
    207208  char               post_extension[SZ] = "";
    208   char               rtsp_extension[SZ] = "";
    209 
    210   const char *       ntrip_str = "";
     209
     210  const char *       ntrip_str = 0;
    211211
    212212  const char *       user = "";
     
    220220  int                server_port = 0;
    221221  int                session = 0;
    222   int                cseq = 0;
    223222  socklen_t          len = 0;
    224223  int                i = 0;
     
    443442  }
    444443
    445   if(*ntrip_str && (outputmode == NTRIP1))
     444  if(ntrip_str && (outputmode == NTRIP1))
    446445  {
    447446     fprintf(stderr, "WARNING: OutputMode is Ntrip version 1.0"
     
    849848        fprintf(stderr, "ERROR: Destination caster or proxy host <%s> unknown\n",
    850849        outhost);
    851         close_session(casterouthost, mountpoint, cseq, session, rtsp_extension, 0);
     850        close_session(casterouthost, mountpoint, session, rtsp_extension, 0);
    852851        usage(-2, argv[0]);
    853852      }
     
    933932            "Ntrip-Version: Ntrip/2.0\r\n"
    934933            "User-Agent: %s/%s\r\n"
    935             "Authorization: Basic %s\r\n"
    936             "Ntrip-STR: %s\r\n"
     934            "Authorization: Basic %s%s%s\r\n"
    937935            "Connection: close\r\n"
    938936            "Transfer-Encoding: chunked\r\n\r\n",
    939937            post_extension, mountpoint, casterouthost, AGENTSTRING,
    940             revisionstr, authorization, ntrip_str);
     938            revisionstr, authorization, ntrip_str ? "\r\nNtrip-STR: " : "",
     939            ntrip_str);
    941940          if((nBufferBytes > (int)sizeof(szSendBuffer)) || (nBufferBytes < 0))
    942941          {
     
    975974              *proxyhost ? " or Proxy <" : "", proxyhost, *proxyhost ? ">" : "",
    976975              *proxyhost ? "       or HTTP/1.1 not implemented at Proxy\n" : "");
    977               close_session(casterouthost, mountpoint, cseq, session, rtsp_extension, 1);
     976              close_session(casterouthost, mountpoint, session, rtsp_extension, 1);
    978977              outputmode = NTRIP1;
    979978              break;
     
    10291028          nBufferBytes = snprintf(szSendBuffer, sizeof(szSendBuffer),
    10301029            "SETUP rtsp://%s%s/%s RTSP/1.0\r\n"
    1031             "CSeq: 1\r\n"
     1030            "CSeq: %d\r\n"
    10321031            "Ntrip-Version: Ntrip/2.0\r\n"
    10331032            "Ntrip-Component: Ntripserver\r\n"
    10341033            "User-Agent: %s/%s\r\n"
    10351034            "Transport: RTP/GNSS;unicast;client_port=%u\r\n"
    1036             "Authorization: Basic %s\r\n"
    1037             "Ntrip-STR: %s\r\n\r\n",
    1038             casterouthost, rtsp_extension, mountpoint, AGENTSTRING, revisionstr,
    1039             client_port, authorization, ntrip_str);
     1035            "Authorization: Basic %s%s%s\r\n\r\n",
     1036            casterouthost, rtsp_extension, mountpoint, udp_cseq++, AGENTSTRING,
     1037            revisionstr, client_port, authorization, ntrip_str
     1038            ? "\r\nNtrip-STR: " : "", ntrip_str);
    10401039          if((nBufferBytes > (int)sizeof(szSendBuffer)) || (nBufferBytes < 0))
    10411040          {
     
    10761075                  " mode\n\n", casterouthost,
    10771076                  *proxyhost ? " or Proxy <" :"", proxyhost, *proxyhost ? ">":"");
    1078                   close_session(casterouthost, mountpoint, cseq, session, rtsp_extension, 1);
     1077                  close_session(casterouthost, mountpoint, session, rtsp_extension, 1);
    10791078                  outputmode = HTTP;
    10801079                  break;
     
    10911090                  *proxyhost ? " or HTTP/1.1 not implemented at Proxy\n" : "",
    10921091                  *proxyhost ? " or Proxy" :"");
    1093                   close_session(casterouthost, mountpoint, cseq, session, rtsp_extension, 1);
     1092                  close_session(casterouthost, mountpoint, session, rtsp_extension, 1);
    10941093                  outputmode = NTRIP1;
    10951094                  break;
     
    11221121              nBufferBytes = snprintf(szSendBuffer, sizeof(szSendBuffer),
    11231122                "RECORD rtsp://%s%s/%s RTSP/1.0\r\n"
    1124                 "CSeq: 2\r\n"
     1123                "CSeq: %d\r\n"
    11251124                "Session: %d\r\n"
    11261125                "\r\n",
    1127                 casterouthost, rtsp_extension,  mountpoint,  session);
     1126                casterouthost, rtsp_extension,  mountpoint,  udp_cseq++,
     1127                session);
    11281128              if((nBufferBytes >= (int)sizeof(szSendBuffer))
    11291129              || (nBufferBytes < 0))
     
    11591159                he->h_addr_list[0], (size_t)he->h_length);
    11601160              }
    1161               cseq = 2;
    11621161              len = (socklen_t)sizeof(casterRTP);
    11631162              send_receive_loop(socket_udp, outputmode, (struct sockaddr *)&casterRTP,
     
    11711170      }
    11721171    }
    1173     close_session(casterouthost, mountpoint, cseq, session, rtsp_extension, 0);
     1172    close_session(casterouthost, mountpoint, session, rtsp_extension, 0);
    11741173    if((reconnect_sec_max)  && (!sigint_received))
    11751174      reconnect_sec = reconnect(reconnect_sec, reconnect_sec_max);
     
    11951194  int      rtpseq = 0;
    11961195  int      rtptime = 0;
     1196  time_t   laststate = time(0);
     1197
     1198  if(outmode == RTSP)
     1199  {
     1200#ifdef WINDOWSVERSION
     1201    u_long blockmode = 1;
     1202    if(ioctlsocket(socket_tcp, FIONBIO, &blockmode))
     1203#else /* WINDOWSVERSION */
     1204    if(fcntl(socket_tcp, F_SETFL, O_NONBLOCK) < 0)
     1205#endif /* WINDOWSVERSION */
     1206    {
     1207      fprintf(stderr, "Could not set nonblocking mode\n");
     1208      return;
     1209    }
     1210  }
    11971211
    11981212  /* data transmission */
     
    13551369    else if((nBufferBytes)  && (outmode == RTSP))
    13561370    {
     1371      time_t ct;
     1372      int r;
    13571373      char rtpbuffer[BUFSZ+12];
    13581374      int i, j;
     
    14091425      {
    14101426        nBufferBytes = 0;
     1427      }
     1428      ct = time(0);
     1429      if(ct-laststate > 15)
     1430      {
     1431        i = snprintf(buffer, sizeof(buffer),
     1432        "GET_PARAMETER rtsp://%s%s/%s RTSP/1.0\r\n"
     1433        "CSeq: %d\r\n"
     1434        "Session: %d\r\n"
     1435        "\r\n",
     1436        casterouthost, rtsp_extension,  mountpoint,  udp_cseq++, rtpseq);
     1437        if(i > (int)sizeof(buffer) || i < 0)
     1438        {
     1439          fprintf(stderr, "Requested data too long\n");
     1440          return;
     1441        }
     1442        else if(send(socket_tcp, buffer, (size_t)i, 0) != i)
     1443        {
     1444          perror("send");
     1445          return;
     1446        }
     1447        laststate = ct;
     1448      }
     1449      /* ignore RTSP server replies */
     1450      if((r=recv(socket_tcp, buffer, sizeof(buffer), 0)) < 0)
     1451      {
     1452#ifdef WINDOWSVERSION
     1453        if(WSAGetLastError() != WSAEWOULDBLOCK)
     1454#else /* WINDOWSVERSION */
     1455        if(errno != EAGAIN)
     1456#endif /* WINDOWSVERSION */
     1457        {
     1458          fprintf(stderr, "Control connection closed\n");
     1459          return;
     1460        }
     1461      }
     1462      else if(!r)
     1463      {
     1464        fprintf(stderr, "Control connection read error\n");
     1465        return;
    14111466      }
    14121467    }
     
    18911946*********************************************************************/
    18921947static void close_session(const char *caster_addr, const char *mountpoint,
    1893 int cseq, int session, char *rtsp_ext, int fallback)
     1948int session, char *rtsp_ext, int fallback)
    18941949{
    18951950  int  size_send_buf;
     
    19552010  }
    19562011
    1957   if(socket_udp  != INVALID_SOCKET)
    1958   {
    1959     if(cseq == 2)
     2012  if(socket_udp != INVALID_SOCKET)
     2013  {
     2014    if(udp_cseq > 2)
    19602015    {
    19612016      size_send_buf = snprintf(send_buf, sizeof(send_buf),
    19622017        "TEARDOWN rtsp://%s%s/%s RTSP/1.0\r\n"
    1963         "CSeq: 2\r\n"
     2018        "CSeq: %d\r\n"
    19642019        "Session: %d\r\n"
    19652020        "\r\n",
    1966         caster_addr, rtsp_ext, mountpoint, session);
     2021        caster_addr, rtsp_ext, mountpoint, udp_cseq++, session);
    19672022      if((size_send_buf >= (int)sizeof(send_buf)) || (size_send_buf < 0))
    19682023      {
Note: See TracChangeset for help on using the changeset viewer.