Changeset 2114:c0e084678926 in roaraudio
- Timestamp:
- 07/22/09 16:02:30 (15 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
roarclients/roarradio.c
r1511 r2114 24 24 25 25 #include <roaraudio.h> 26 27 #define P_UNKNOWN 0 28 #define P_HTTP 1 29 #define P_GOPHER 2 26 30 27 31 void usage (void) { … … 51 55 char * file = NULL; 52 56 char * host; 53 int port = 80;57 int port; 54 58 FILE * http; 55 59 struct roar_connection con[1]; 56 60 struct roar_stream stream[1]; 57 61 char buf0[80], buf1[80]; 62 int proto = P_UNKNOWN; 58 63 59 64 for (i = 1; i < argc; i++) { … … 86 91 in = ROAR_STDIN; 87 92 } else { 88 if ( strncmp(file, "http://", 7) != 0 ) { 89 if ( (in = open(file, O_RDONLY, 0644)) == -1 ) { 90 ROAR_ERR("can not open file: %s: %s", file, strerror(errno)); 91 return 1; 92 } 93 } else { 94 host = file+7; 95 93 if ( strncmp(file, "http://", 7) == 0 ) { 94 proto = P_HTTP; 95 host = file+7; 96 port = 80; 97 } else if ( strncmp(file, "gopher://", 9) == 0 ) { 98 proto = P_GOPHER; 99 host = file+9; 100 port = 70; 101 } 102 103 if ( proto == P_HTTP || proto == P_GOPHER ) { 96 104 for (i = 0; host[i] != 0; i++) { 97 105 if ( host[i] == ':' ) { … … 122 130 } 123 131 124 if ( (http = fdopen(in, "r+")) == NULL ) { 125 ROAR_ERR("can not create FILE* object: %s", strerror(errno)); 126 return 0; 127 } 128 129 fprintf(http, "GET %s HTTP/1.1\r\n", file); 130 fprintf(http, "Host: %s\r\n", host); 131 fprintf(http, "User-Agent: roarradio $Revision$\r\n"); 132 fprintf(http, "Connection: close\r\n"); 133 fprintf(http, "\r\n"); 134 fflush(http); 135 136 if ( fscanf(http, "%79s %i %79s\n", buf0, &port, buf1) != 3 ) { 137 ROAR_ERR("HTTP protocoll error!, no initial HTTP/1.x-line!"); 132 switch (proto) { 133 case P_HTTP: 134 if ( (http = fdopen(in, "r+")) == NULL ) { 135 ROAR_ERR("can not create FILE* object: %s", strerror(errno)); 136 return 0; 137 } 138 139 fprintf(http, "GET %s HTTP/1.1\r\n", file); 140 fprintf(http, "Host: %s\r\n", host); 141 fprintf(http, "User-Agent: roarradio $Revision$\r\n"); 142 fprintf(http, "Connection: close\r\n"); 143 fprintf(http, "\r\n"); 144 fflush(http); 145 146 if ( fscanf(http, "%79s %i %79s\n", buf0, &port, buf1) != 3 ) { 147 ROAR_ERR("HTTP protocoll error!, no initial HTTP/1.x-line!"); 148 return 1; 149 } 150 if ( port != 200 ) { // 200 = HTTP OK 151 ROAR_ERR("HTTP Error: %i - %s", port, buf1); 152 return 1; 153 } 154 155 *buf0 = 0; 156 157 while (*buf0 != '\r' && *buf0 != '\n') { 158 fgets(buf0, 80, http); 159 } 160 161 fflush(http); 162 break; 163 case P_GOPHER: 164 if ( file[0] == 0 ) { 165 file[0] = '/'; 166 file[1] = 0; 167 } else if ( file[0] == '/' && file[1] != 0 && file[2] == '/' ) { // strip the type prefix 168 file += 2; 169 } 170 // TODO: do some error checks here 171 write(in, file, strlen(file)); 172 write(in, "\r\n", 2); 173 ROAR_SHUTDOWN(in, SHUT_WR); 174 break; 175 } 176 } else { 177 if ( (in = open(file, O_RDONLY, 0644)) == -1 ) { 178 ROAR_ERR("can not open file: %s: %s", file, strerror(errno)); 138 179 return 1; 139 180 } 140 if ( port != 200 ) { // 200 = HTTP OK141 ROAR_ERR("HTTP Error: %i - %s", port, buf1);142 return 1;143 }144 145 *buf0 = 0;146 147 while (*buf0 != '\r' && *buf0 != '\n') {148 fgets(buf0, 80, http);149 }150 151 fflush(http);152 181 } 153 182 }
Note: See TracChangeset
for help on using the changeset viewer.