* * $Log$ * *
Definition in file station.c.
#include <cfg/os.h>
#include <cfg/clock.h>
#include <dev/board.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include <sys/version.h>
#include <sys/confnet.h>
#include <sys/atom.h>
#include <sys/heap.h>
#include <sys/thread.h>
#include <sys/timer.h>
#include <sys/event.h>
#include <sys/socket.h>
#include <hxmp3/mp3dec.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <net/route.h>
#include <pro/dhcp.h>
#include "tlv320dac.h"
#include "config.h"
#include "utils.h"
#include "player.h"
#include "shoutcast.h"
Include dependency graph for station.c:
Go to the source code of this file.
Functions | |
u_int | StationSelect (u_int idx, int dir) |
Select new radio station. | |
void | StationDisconnect (STATIONINFO *sip) |
Disconnect from a radio station. | |
STATIONINFO * | StationConnect (STATIONCONF *scp) |
Connect to a radio station. |
|
Select new radio station.
Definition at line 84 of file station.c. 00086 { 00087 u_int rc = idx; 00088 char *symbol; 00089 00090 if (station[rc].rs_port) { 00091 symbol = station[idx].rs_symbol; 00092 } 00093 else { 00094 symbol = NULL; 00095 } 00096 00097 for (;;) { 00098 if (dir < 0) { 00099 if (rc == 0) { 00100 rc = MAXNUM_STATIONS; 00101 } 00102 rc--; 00103 } 00104 else if (++rc >= MAXNUM_STATIONS) { 00105 rc = 0; 00106 } 00107 if (rc == idx) { 00108 break; 00109 } 00110 if (station[rc].rs_port) { 00111 if (symbol == NULL) { 00112 break; 00113 } 00114 if (dir) { 00115 if (station[rc].rs_symbol == NULL || strcmp(station[rc].rs_symbol, symbol)) { 00116 break; 00117 } 00118 } 00119 else { 00120 if (station[rc].rs_symbol && strcmp(station[rc].rs_symbol, symbol) == 0) { 00121 break; 00122 } 00123 } 00124 } 00125 } 00126 return rc;
|
|
Disconnect from a radio station.
Definition at line 133 of file station.c. 00135 { 00136 printf("Disconnecting\n"); 00137 if (sip) { 00138 if (sip->si_sock) { 00139 NutTcpCloseSocket(sip->si_sock); 00140 } 00141 TcpReleaseHeaderLines(sip->si_header); 00142 free(sip); 00143 }
|
|
Connect to a radio station.
Definition at line 153 of file station.c. 00155 { 00156 STATIONINFO *sip = NULL; 00157 TCPSOCKET *sock = NULL; 00158 u_short mss = MAX_TCPSEG_SIZE; 00159 u_short tcpbufsiz = MAX_TCPBUF_SIZE; 00160 u_long rx_to = MAX_TCPRCV_WAIT; 00161 int err = -1; 00162 int cr; 00163 char *line; 00164 00165 /* Create a TCP socket. */ 00166 if ((sock = NutTcpCreateSocket()) != NULL) { 00167 /* Set socket options. Failures are ignored. */ 00168 NutTcpSetSockOpt(sock, TCP_MAXSEG, &mss, sizeof(mss)); 00169 NutTcpSetSockOpt(sock, SO_RCVBUF, &tcpbufsiz, sizeof(tcpbufsiz)); 00170 NutTcpSetSockOpt(sock, SO_RCVTIMEO, &rx_to, sizeof(rx_to)); 00171 00172 /* Connect the stream server. */ 00173 printf("[CNCT %s:%u", inet_ntoa(scp->rs_ip), scp->rs_port); 00174 if (proxy.proxy_ip) { 00175 printf(" via %s:%u]", inet_ntoa(proxy.proxy_ip), proxy.proxy_port); 00176 cr = NutTcpConnect(sock, proxy.proxy_ip, proxy.proxy_port); 00177 } 00178 else { 00179 putchar(']'); 00180 cr = NutTcpConnect(sock, scp->rs_ip, scp->rs_port); 00181 } 00182 if (cr) { 00183 printf("[CERR=%d]\n", NutTcpError(sock)); 00184 } 00185 else { 00186 printf("[CNCTD]"); 00187 00188 /* Create a new station info structure. */ 00189 if ((sip = malloc(sizeof(STATIONINFO))) != NULL) { 00190 memset(sip, 0, sizeof(STATIONINFO)); 00191 sip->si_sock = sock; 00192 sip->si_scp = scp; 00193 00194 /* 00195 * Send the HTTP request. 00196 */ 00197 line = malloc(256); 00198 00199 if (proxy.proxy_ip) { 00200 /* A proxy requires an absolute URI. */ 00201 sprintf(line, "GET http://%s:%u/", inet_ntoa(scp->rs_ip), scp->rs_port); 00202 } 00203 else { 00204 strcpy(line, "GET /"); 00205 } 00206 if (scp->rs_url_path) { 00207 /* URL contains a specific path. */ 00208 strcat(line, scp->rs_url_path); 00209 } 00210 strcat(line, " HTTP/1.0\r\n"); 00211 err = TcpPutString(sock, line); 00212 00213 if (err == 0) { 00214 /* HTTP 1.1 requires this. So just in case... */ 00215 sprintf(line, "Host: %s\r\n", inet_ntoa(scp->rs_ip)); 00216 err = TcpPutString(sock, line); 00217 } 00218 00219 if (err == 0) { 00220 /* Some shoutcast servers seem to require a user-agent line. 00221 "Eat chalk" to get in. */ 00222 TcpPutString(sock, "User-Agent: WinampMPEG/2.7\r\n" /* */ 00223 "Accept: */*\r\n" /* */ 00224 "Icy-MetaData: 1\r\n" /* */ 00225 "Connection: close\r\n\r\n"); 00226 } 00227 00228 free(line); 00229 00230 /* Read the servers response. */ 00231 if (TcpGetHeaderLines(sock, &sip->si_header) <= 0) { 00232 err = -1; 00233 } 00234 } 00235 } 00236 00237 /* Release resources in case of any error. */ 00238 if (err) { 00239 if (sip) { 00240 StationDisconnect(sip); 00241 sip = NULL; 00242 } 00243 else { 00244 NutTcpCloseSocket(sock); 00245 } 00246 } 00247 } 00248 return sip;
|