Changeset 1830 in ntrip
- Timestamp:
- May 6, 2009, 4:52:52 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ntripclient/ntripclient.c
r1811 r1830 1 1 /* 2 2 NTRIP client for POSIX. 3 $Id: ntripclient.c,v 1.4 7 2009/02/10 12:18:23stoecker Exp $3 $Id: ntripclient.c,v 1.48 2009/04/27 09:49:54 stoecker Exp $ 4 4 Copyright (C) 2003-2008 by Dirk Stöcker <soft@dstoecker.de> 5 5 … … 65 65 66 66 /* CVS revision and version */ 67 static char revisionstr[] = "$Revision: 1.4 7$";68 static char datestr[] = "$Date: 2009/0 2/10 12:18:23$";67 static char revisionstr[] = "$Revision: 1.48 $"; 68 static char datestr[] = "$Date: 2009/04/27 09:49:54 $"; 69 69 70 70 enum MODE { HTTP = 1, RTSP = 2, NTRIP1 = 3, AUTO = 4, UDP = 5, END }; … … 808 808 const char *sessioncheck = "session: "; 809 809 const char *datacheck = "Content-Type: gnss/data\r\n"; 810 const char *sourcetablecheck = "Content-Type: gnss/sourcetable\r\n"; 811 const char *contentlengthcheck = "Content-Length: "; 812 const char *httpresponseend = "\r\n\r\n"; 813 int contentlength = 0, httpresponselength = 0; 814 /* datacheck */ 810 815 int l = strlen(datacheck)-1; 811 816 int j=0; … … 815 820 ; 816 821 } 817 if(i == numbytes-l) 818 { 819 fprintf(stderr, "No 'Content-Type: gnss/data' found\n"); 820 error = 1; 821 } 822 /* check for Session */ 823 l = strlen(sessioncheck)-1; 824 j=0; 825 for(i = 12; j != l && i < numbytes-l; ++i) 826 { 827 for(j = 0; j < l && tolower(rtpbuf[i+j]) == sessioncheck[j]; ++j) 828 ; 829 } 830 if(i != numbytes-l) /* found a session number */ 831 { 832 i+=l; 833 session = 0; 834 while(i < numbytes && rtpbuf[i] >= '0' && rtpbuf[i] <= '9') 835 session = session * 10 + rtpbuf[i++]-'0'; 836 if(rtpbuf[i] != '\r') 822 if(i != numbytes-l) 823 { 824 /* check for Session */ 825 l = strlen(sessioncheck)-1; 826 j=0; 827 for(i = 12; j != l && i < numbytes-l; ++i) 837 828 { 838 fprintf(stderr, "Could not extract session number\n"); 839 stop = 1; 829 for(j = 0; j < l && tolower(rtpbuf[i+j]) == sessioncheck[j]; ++j) 830 ; 831 } 832 if(i != numbytes-l) /* found a session number */ 833 { 834 i+=l; 835 session = 0; 836 while(i < numbytes && rtpbuf[i] >= '0' && rtpbuf[i] <= '9') 837 session = session * 10 + rtpbuf[i++]-'0'; 838 if(rtpbuf[i] != '\r') 839 { 840 fprintf(stderr, "Could not extract session number\n"); 841 stop = 1; 842 } 843 } 844 } 845 else 846 { 847 /* sourcetablecheck */ 848 l = strlen(sourcetablecheck)-1; 849 j=0; 850 for(i = 12; j != l && i < numbytes-l; ++i) 851 { 852 for(j = 0; j < l && rtpbuf[i+j] == sourcetablecheck[j]; ++j) 853 ; 854 } 855 if(i == numbytes-l) 856 { 857 fprintf(stderr, "No 'Content-Type: gnss/data' or" 858 " 'Content-Type: gnss/sourcetable' found\n"); 859 error = 1; 860 } 861 else 862 { 863 /* check for http response end */ 864 l = strlen(httpresponseend)-1; 865 j=0; 866 for(i = 12; j != l && i < numbytes-l; ++i) 867 { 868 for(j = 0; j < l && rtpbuf[i+j] == httpresponseend[j]; ++j) 869 ; 870 } 871 if(i != numbytes-l) /* found http response end */ 872 { 873 httpresponselength = i+3-12; 874 } 875 /* check for content length */ 876 l = strlen(contentlengthcheck)-1; 877 j=0; 878 for(i = 12; j != l && i < numbytes-l; ++i) 879 { 880 for(j = 0; j < l && rtpbuf[i+j] == contentlengthcheck[j]; ++j) 881 ; 882 } 883 if(i != numbytes-l) /* found content length */ 884 { 885 i+=l; 886 contentlength = 0; 887 while(i < numbytes && rtpbuf[i] >= '0' && rtpbuf[i] <= '9') 888 contentlength = contentlength * 10 + rtpbuf[i++]-'0'; 889 if(rtpbuf[i] == '\r') 890 { 891 contentlength += httpresponselength; 892 do 893 { 894 fwrite(rtpbuf+12, (size_t)numbytes-12, 1, stdout); 895 if((contentlength -= (numbytes-12)) == 0) 896 { 897 stop = 1; 898 } 899 else 900 { 901 numbytes = recv(sockfd, rtpbuf, sizeof(rtpbuf), 0); 902 } 903 }while((numbytes >12) && (!stop)); 904 } 905 else 906 { 907 fprintf(stderr, "Could not extract content length\n"); 908 stop = 1; 909 } 910 } 840 911 } 841 912 } … … 872 943 alarm(ALARMTIME); 873 944 #endif 874 if(i >= 12 +1&& (unsigned char)rtpbuf[0] == (2 << 6)945 if(i >= 12 && (unsigned char)rtpbuf[0] == (2 << 6) 875 946 && rtpbuf[1] >= 96 && rtpbuf[1] <= 98) 876 947 { … … 899 970 continue; 900 971 } 901 else if( rtpbuf[1] == 96)972 else if((rtpbuf[1] == 96) && (i>12)) 902 973 { 903 974 fwrite(rtpbuf+12, (size_t)i-12, 1, stdout);
Note:
See TracChangeset
for help on using the changeset viewer.