- Timestamp:
- Mar 4, 2022, 10:48:18 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ntripserver/ntripserver.c
r9468 r9643 672 672 673 673 /* input from NTRIP caster */ 674 int init = 0; 675 /* set socket buffer size */ 676 setsockopt(gps_socket, SOL_SOCKET, SO_SNDBUF, (const char*) &size, sizeof(const char*)); 677 /* input from Ntrip caster*/ 678 nBufferBytes=snprintf(szSendBuffer, sizeof(szSendBuffer) - 40,/* leave some space for login */ 679 "GET %s/%s HTTP/1.1\r\n" 680 "Host: %s\r\n" 681 "%s" 682 "User-Agent: %s/%s\r\n" 683 //"%s%s%s" // nmea 684 "Connection: close%s", 685 get_extension, 686 stream_name ? stream_name : "", 687 casterinhost, 688 inputmode == NTRIP1_IN ? "" : "Ntrip-Version: Ntrip/2.0\r\n", 689 AGENTSTRING, revisionstr, 690 //args.nmea ? "Ntrip-GGA: " : "", args.nmea ? args.nmea : "", args.nmea ? "\r\n" : "", // TODO: add argument 691 (*stream_user || *stream_password) ? "\r\nAuthorization: Basic " : ""); 692 /* second check for old glibc */ 693 if (nBufferBytes > (int) sizeof(szSendBuffer) - 40 || nBufferBytes < 0) { 694 fprintf(stderr, "ERROR: Source caster request too long\n"); 695 input_init = 0; 696 reconnect_sec_max = 0; 697 break; 698 } 699 nBufferBytes += encode(szSendBuffer + nBufferBytes, sizeof(szSendBuffer) - nBufferBytes - 4, 700 stream_user, stream_password); 701 if (nBufferBytes > (int) sizeof(szSendBuffer) - 4) { 702 fprintf(stderr, "ERROR: Source caster user ID and/or password too long\n"); 703 input_init = 0; 704 reconnect_sec_max = 0; 705 break; 706 } 707 szSendBuffer[nBufferBytes++] = '\r'; 708 szSendBuffer[nBufferBytes++] = '\n'; 709 szSendBuffer[nBufferBytes++] = '\r'; 710 szSendBuffer[nBufferBytes++] = '\n'; 711 #ifndef NDEBUG 712 fprintf(stdout, "%s\n", szSendBuffer); 713 #endif 714 if ((send(gps_socket, szSendBuffer, (size_t) nBufferBytes, 0)) != nBufferBytes) { 715 fprintf(stderr, "WARNING: could not send Source caster request\n"); 716 input_init = 0; 717 break; 718 } 719 nBufferBytes = 0; 720 /* check Source caster's response */ 721 while (!init && nBufferBytes < (int) sizeof(szSendBuffer) && 722 (nBufferBytes += recv(gps_socket, szSendBuffer, sizeof(szSendBuffer) - nBufferBytes, 0)) > 0) { 723 if( nBufferBytes > 17 && !strstr(szSendBuffer, "ICY 200 OK") && /* case 'proxy & ntrip 1.0 caster' */ 724 (!strncmp(szSendBuffer, "HTTP/1.1 200 OK\r\n", 17) || 725 !strncmp(szSendBuffer, "HTTP/1.0 200 OK\r\n", 17)) ) { 726 const char *datacheck = "Content-Type: gnss/data\r\n"; 727 const char *chunkycheck = "Transfer-Encoding: chunked\r\n"; 728 int l = strlen(datacheck)-1; 729 int j=0; 730 for(i = 0; j != l && i < nBufferBytes-l; ++i) { 731 for(j = 0; j < l && szSendBuffer[i+j] == datacheck[j]; ++j) 732 ; 674 if (stream_name) { 675 int init = 0; 676 /* set socket buffer size */ 677 setsockopt(gps_socket, SOL_SOCKET, SO_SNDBUF, (const char*) &size, sizeof(const char*)); 678 /* input from Ntrip caster*/ 679 nBufferBytes=snprintf(szSendBuffer, sizeof(szSendBuffer) - 40,/* leave some space for login */ 680 "GET %s/%s HTTP/1.1\r\n" 681 "Host: %s\r\n" 682 "%s" 683 "User-Agent: %s/%s\r\n" 684 //"%s%s%s" // nmea 685 "Connection: close%s", 686 get_extension, 687 stream_name ? stream_name : "", 688 casterinhost, 689 inputmode == NTRIP1_IN ? "" : "Ntrip-Version: Ntrip/2.0\r\n", 690 AGENTSTRING, revisionstr, 691 //args.nmea ? "Ntrip-GGA: " : "", args.nmea ? args.nmea : "", args.nmea ? "\r\n" : "", // TODO: add argument 692 (*stream_user || *stream_password) ? "\r\nAuthorization: Basic " : ""); 693 /* second check for old glibc */ 694 if (nBufferBytes > (int) sizeof(szSendBuffer) - 40 || nBufferBytes < 0) { 695 fprintf(stderr, "ERROR: Source caster request too long\n"); 696 input_init = 0; 697 reconnect_sec_max = 0; 698 break; 699 } 700 nBufferBytes += encode(szSendBuffer + nBufferBytes, sizeof(szSendBuffer) - nBufferBytes - 4, 701 stream_user, stream_password); 702 if (nBufferBytes > (int) sizeof(szSendBuffer) - 4) { 703 fprintf(stderr, "ERROR: Source caster user ID and/or password too long\n"); 704 input_init = 0; 705 reconnect_sec_max = 0; 706 break; 707 } 708 szSendBuffer[nBufferBytes++] = '\r'; 709 szSendBuffer[nBufferBytes++] = '\n'; 710 szSendBuffer[nBufferBytes++] = '\r'; 711 szSendBuffer[nBufferBytes++] = '\n'; 712 #ifndef NDEBUG 713 fprintf(stdout, "%s\n", szSendBuffer); 714 #endif 715 if ((send(gps_socket, szSendBuffer, (size_t) nBufferBytes, 0)) != nBufferBytes) { 716 fprintf(stderr, "WARNING: could not send Source caster request\n"); 717 input_init = 0; 718 break; 719 } 720 nBufferBytes = 0; 721 /* check Source caster's response */ 722 while (!init && nBufferBytes < (int) sizeof(szSendBuffer) && 723 (nBufferBytes += recv(gps_socket, szSendBuffer, sizeof(szSendBuffer) - nBufferBytes, 0)) > 0) { 724 if( nBufferBytes > 17 && !strstr(szSendBuffer, "ICY 200 OK") && /* case 'proxy & ntrip 1.0 caster' */ 725 (!strncmp(szSendBuffer, "HTTP/1.1 200 OK\r\n", 17) || 726 !strncmp(szSendBuffer, "HTTP/1.0 200 OK\r\n", 17)) ) { 727 const char *datacheck = "Content-Type: gnss/data\r\n"; 728 const char *chunkycheck = "Transfer-Encoding: chunked\r\n"; 729 int l = strlen(datacheck)-1; 730 int j=0; 731 for(i = 0; j != l && i < nBufferBytes-l; ++i) { 732 for(j = 0; j < l && szSendBuffer[i+j] == datacheck[j]; ++j) 733 ; 734 } 735 if(i == nBufferBytes-l) { 736 fprintf(stderr, "No 'Content-Type: gnss/data' found\n"); 737 input_init = 0; 738 } 739 l = strlen(chunkycheck)-1; 740 j=0; 741 for(i = 0; j != l && i < nBufferBytes-l; ++i) { 742 for(j = 0; j < l && szSendBuffer[i+j] == chunkycheck[j]; ++j) 743 ; 744 } 745 if(i < nBufferBytes-l) 746 chunkymode = 1; 747 init = 1; 733 748 } 734 if(i == nBufferBytes-l) { 735 fprintf(stderr, "No 'Content-Type: gnss/data' found\n"); 736 input_init = 0; 749 else if (strstr(szSendBuffer, "\r\n")) { 750 if (!strstr(szSendBuffer, "ICY 200 OK")) { 751 int k; 752 fprintf(stderr, "ERROR: could not get requested data from Source caster: "); 753 for (k = 0; k < nBufferBytes && szSendBuffer[k] != '\n' && szSendBuffer[k] != '\r'; ++k) { 754 fprintf(stderr, "%c", isprint(szSendBuffer[k]) ? szSendBuffer[k] : '.'); 755 } 756 fprintf(stderr, "\n"); 757 if (!strstr(szSendBuffer, "SOURCETABLE 200 OK")) { 758 reconnect_sec_max = 0; 759 } 760 input_init = 0; 761 break; 762 } 763 init = 1; 737 764 } 738 l = strlen(chunkycheck)-1; 739 j=0; 740 for(i = 0; j != l && i < nBufferBytes-l; ++i) { 741 for(j = 0; j < l && szSendBuffer[i+j] == chunkycheck[j]; ++j) 742 ; 743 } 744 if(i < nBufferBytes-l) 745 chunkymode = 1; 746 init = 1; 747 } 748 else if (strstr(szSendBuffer, "\r\n")) { 749 if (!strstr(szSendBuffer, "ICY 200 OK")) { 750 int k; 751 fprintf(stderr, "ERROR: could not get requested data from Source caster: "); 752 for (k = 0; k < nBufferBytes && szSendBuffer[k] != '\n' && szSendBuffer[k] != '\r'; ++k) { 753 fprintf(stderr, "%c", isprint(szSendBuffer[k]) ? szSendBuffer[k] : '.'); 754 } 755 fprintf(stderr, "\n"); 756 if (!strstr(szSendBuffer, "SOURCETABLE 200 OK")) { 757 reconnect_sec_max = 0; 758 } 759 input_init = 0; 760 break; 761 } 762 init = 1; 763 } 764 765 } 766 /* end input from NTRIP caster */ 765 } 766 } 767 767 768 768 if (initfile && inputmode != SISNET) {
Note:
See TracChangeset
for help on using the changeset viewer.