can parse inputStream_http can parse mime type

git-svn-id: https://svn.musicpd.org/mpd/trunk@1056 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
Warren Dukes 2004-05-18 09:34:22 +00:00
parent 45f8d47384
commit d4c7d6df6d
3 changed files with 51 additions and 15 deletions

View File

@ -34,6 +34,8 @@ struct _InputStream {
int error; int error;
long offset; long offset;
size_t size; size_t size;
char * mime;
int seekable;
/* don't touc this stuff */ /* don't touc this stuff */
InputStreamSeekFunc seekFunc; InputStreamSeekFunc seekFunc;

View File

@ -33,6 +33,8 @@ int inputStream_fileOpen(InputStream * inStream, char * filename) {
} }
inStream->offset = 0; inStream->offset = 0;
inStream->seekable = 1;
inStream->mime = NULL;
fseek(fp,0,SEEK_END); fseek(fp,0,SEEK_END);
inStream->size = ftell(fp); inStream->size = ftell(fp);

View File

@ -51,9 +51,9 @@ typedef struct _InputStreemHTTPData {
int connState; int connState;
char buffer[HTTP_BUFFER_SIZE]; char buffer[HTTP_BUFFER_SIZE];
int buflen; int buflen;
int canSeek;
int timesRedirected; int timesRedirected;
int icyMetaint; int icyMetaint;
char * icyName;
} InputStreamHTTPData; } InputStreamHTTPData;
static InputStreamHTTPData * newInputStreamHTTPData() { static InputStreamHTTPData * newInputStreamHTTPData() {
@ -63,8 +63,9 @@ static InputStreamHTTPData * newInputStreamHTTPData() {
ret->path = NULL; ret->path = NULL;
ret->port = 80; ret->port = 80;
ret->connState = HTTP_CONN_STATE_CLOSED; ret->connState = HTTP_CONN_STATE_CLOSED;
ret->canSeek = 0;
ret->timesRedirected = 0; ret->timesRedirected = 0;
ret->icyName = NULL;
ret->icyMetaint = 0;
return ret; return ret;
} }
@ -72,6 +73,7 @@ static InputStreamHTTPData * newInputStreamHTTPData() {
static void freeInputStreamHTTPData(InputStreamHTTPData * data) { static void freeInputStreamHTTPData(InputStreamHTTPData * data) {
if(data->host) free(data->host); if(data->host) free(data->host);
if(data->path) free(data->path); if(data->path) free(data->path);
if(data->icyName) free(data->icyName);
free(data); free(data);
} }
@ -296,15 +298,15 @@ static int getHTTPHello(InputStream * inStream) {
if(!needle) return 0; if(!needle) return 0;
if(0 == strncmp(cur, "HTTP/1.0 ", 9)) { if(0 == strncmp(cur, "HTTP/1.0 ", 9)) {
data->canSeek = 0; inStream->seekable = 0;
rc = atoi(cur+9); rc = atoi(cur+9);
} }
else if(0 == strncmp(cur, "HTTP/1.1 ", 9)) { else if(0 == strncmp(cur, "HTTP/1.1 ", 9)) {
data->canSeek = 1; inStream->seekable = 1;
rc = atoi(cur+9); rc = atoi(cur+9);
} }
else if(0 == strncmp(cur, "ICY 200 OK", 10)) { else if(0 == strncmp(cur, "ICY 200 OK", 10)) {
data->canSeek = 0; inStream->seekable = 0;
rc = 200; rc = 200;
} }
else if(0 == strncmp(cur, "ICY 400 Server Full", 19)) rc = 400; else if(0 == strncmp(cur, "ICY 400 Server Full", 19)) rc = 400;
@ -354,21 +356,48 @@ static int getHTTPHello(InputStream * inStream) {
return -1; return -1;
} }
cur = strstr(data->buffer, "\r\nContent-Length: "); cur = strstr(data->buffer,"\r\n");
if(cur) { while(cur && cur!=needle) {
if(!inStream->size) inStream->size = atol(cur+18); if(0 == strncmp(cur,"\r\nContent-Length: ",18)) {
} if(!inStream->size) inStream->size = atol(cur+18);
else data->canSeek = 0; }
else if(0 == strncmp(cur, "\r\nicy-metaint:", 14)) {
data->icyMetaint = atoi(cur+14);
}
else if(0 == strncmp(cur, "\r\nicy-name:", 11)) {
char * temp = strstr(cur+11,"\r\n");
if(!temp) break;
*temp = '\0';
if(data->icyName) free(data->icyName);
data->icyName = strdup(cur+11);
*temp = '\r';
}
else if(0 == strncmp(cur, "\r\nx-audiocast-name:", 19)) {
char * temp = strstr(cur+19,"\r\n");
if(!temp) break;
*temp = '\0';
if(data->icyName) free(data->icyName);
data->icyName = strdup(cur+19);
*temp = '\r';
}
else if(0 == strncmp(cur, "\r\nContent-Type:", 15)) {
char * temp = strstr(cur+15,"\r\n");
if(!temp) break;
*temp = '\0';
if(inStream->mime) free(inStream->mime);
inStream->mime = strdup(cur+15);
*temp = '\r';
}
cur = strstr(data->buffer, "\r\nicy-metaint:"); cur = strstr(cur+2,"\r\n");
if(cur) {
data->icyMetaint = atoi(cur+14);
} }
else data->icyMetaint = 0;
if(inStream->size <= 0) inStream->seekable = 0;
needle += 4; /* 4 == strlen("\r\n\r\n") */ needle += 4; /* 4 == strlen("\r\n\r\n") */
memmove(data->buffer, needle, data->buffer+data->buflen-needle);
data->buflen -= data->buffer+data->buflen-needle; data->buflen -= data->buffer+data->buflen-needle;
/*fwrite(data->buffer, 1, data->buflen, stdout);*/
memmove(data->buffer, needle, data->buflen);
data->connState = HTTP_CONN_STATE_OPEN; data->connState = HTTP_CONN_STATE_OPEN;
@ -398,6 +427,8 @@ int inputStream_httpOpen(InputStream * inStream, char * url) {
inStream->offset = 0; inStream->offset = 0;
inStream->size = 0; inStream->size = 0;
inStream->error = 0; inStream->error = 0;
inStream->mime = NULL;
inStream->seekable = 0;
return 0; return 0;
} }
@ -492,6 +523,7 @@ int inputStream_httpClose(InputStream * inStream) {
close(data->sock); close(data->sock);
} }
if(inStream->mime) free(inStream->mime);
freeInputStreamHTTPData(data); freeInputStreamHTTPData(data);
return 0; return 0;