From 3d2c60572ddf17f3e212d3591dd647268a52f5e9 Mon Sep 17 00:00:00 2001 From: Ron Pedde Date: Wed, 28 Apr 2004 18:45:56 +0000 Subject: [PATCH] Updates for iTunes 4.5. Some problems with seeking on mac, though --- src/daap.c | 21 ++++++++++++++++----- src/daap.h | 2 +- src/main.c | 25 ++++++++++++++----------- src/webserver.c | 20 ++++++++++++++++++-- 4 files changed, 49 insertions(+), 19 deletions(-) diff --git a/src/daap.c b/src/daap.c index 1ea97c64..96c6a61d 100644 --- a/src/daap.c +++ b/src/daap.c @@ -195,7 +195,7 @@ DAAP_BLOCK *daap_response_content_codes(void) { DAAP_BLOCK *daap_response_login(char *hostname) { DAAP_BLOCK *root; int g=1; - int session; + int session=0; DPRINTF(ERR_DEBUG,"Preparing to send login response\n"); @@ -557,18 +557,29 @@ DAAP_BLOCK *daap_response_dbinfo(char *name) { * * handle the daap block for the /server-info URI */ -DAAP_BLOCK *daap_response_server_info(char *name) { +DAAP_BLOCK *daap_response_server_info(char *name, char *client_version) { DAAP_BLOCK *root; int g=1; - DPRINTF(ERR_DEBUG,"Preparing to send server info\n"); + DPRINTF(ERR_DEBUG,"Preparing to send server info for client version %s\n",client_version); root=daap_add_empty(NULL,"msrv"); if(root) { g = (int)daap_add_int(root,"mstt",200); /* result */ - g = g && daap_add_int(root,"mpro",2 << 16); /* dmap proto ? */ - g = g && daap_add_int(root,"apro",2 << 16); /* daap protocol */ + if((!client_version)||(!strcmp(client_version,"3.0"))) { + g = g && daap_add_int(root,"mpro",2 << 16); /* dmap proto ? */ + g = g && daap_add_int(root,"apro",3 << 16); /* daap protocol */ + } else { + if(!strcmp(client_version,"1.0")) { + g = g && daap_add_int(root,"mpro",1 << 16); /* dmap proto ? */ + g = g && daap_add_int(root,"apro",1 << 16); /* daap protocol */ + } else if(!strcmp(client_version,"2.0")) { + g = g && daap_add_int(root,"mpro",1 << 16); /* dmap proto ? */ + g = g && daap_add_int(root,"apro",2 << 16); /* daap protocol */ + } + } + g = g && daap_add_string(root,"minm",name); /* server name */ g = g && daap_add_char(root,"mslr",config.readpassword != NULL); /* logon required */ g = g && daap_add_int(root,"mstm",1800); /* timeout - iTunes=1800 */ diff --git a/src/daap.h b/src/daap.h index a9877614..b72be82d 100644 --- a/src/daap.h +++ b/src/daap.h @@ -23,7 +23,7 @@ #include "daap-proto.h" -DAAP_BLOCK *daap_response_server_info(char *name); +DAAP_BLOCK *daap_response_server_info(char *name, char *client_version); DAAP_BLOCK *daap_response_content_codes(void); DAAP_BLOCK *daap_response_login(char *hostname); DAAP_BLOCK *daap_response_update(int fd, int clientver); diff --git a/src/main.c b/src/main.c index abc90680..fde97d9f 100644 --- a/src/main.c +++ b/src/main.c @@ -108,8 +108,8 @@ void daap_handler(WS_CONNINFO *pwsc) { int img_fd; - off_t offset=0; - off_t file_len; + long offset=0; + long file_len; close=pwsc->close; pwsc->close=1; /* in case we have any errors */ @@ -125,7 +125,8 @@ void daap_handler(WS_CONNINFO *pwsc) { if(!strcasecmp(pwsc->uri,"/server-info")) { config_set_status(pwsc,session_id,"Sending server info"); - root=daap_response_server_info(config.servername); + root=daap_response_server_info(config.servername, + ws_getrequestheader(pwsc,"Client-DAAP-Version")); } else if (!strcasecmp(pwsc->uri,"/content-codes")) { config_set_status(pwsc,session_id,"Sending content codes"); root=daap_response_content_codes(); @@ -248,8 +249,8 @@ void daap_handler(WS_CONNINFO *pwsc) { pwsc->close=1; if(ws_getrequestheader(pwsc,"range")) { - offset=atol(ws_getrequestheader(pwsc,"range") + 6); - DPRINTF(ERR_DEBUG,"Thread %d: Skipping to byte %ld\n",pwsc->threadno,offset); + offset=(long)atol(ws_getrequestheader(pwsc,"range") + 6); + DPRINTF(ERR_DEBUG,"Offset is %ld\n",offset); } pmp3=db_find(item); @@ -266,7 +267,10 @@ void daap_handler(WS_CONNINFO *pwsc) { config_set_status(pwsc,session_id,NULL); } else { - file_len=lseek(file_fd,0,SEEK_END); + file_len=(long)lseek(file_fd,0,SEEK_END); + DPRINTF(ERR_DEBUG,"Thread %d: length of file is %ld\n", + pwsc->threadno,(long)file_len); + lseek(file_fd,0,SEEK_SET); file_len -= offset; @@ -285,15 +289,15 @@ void daap_handler(WS_CONNINFO *pwsc) { if(!offset) config.stats.songs_served++; /* FIXME: remove stat races */ - if((config.artfilename) && - ((img_fd=da_get_image_fd(pmp3->path)) != -1) && (!offset) && - (strncasecmp(pmp3->type,".mp3",4) ==0)) { + if((config.artfilename) && + (!offset) && (strncasecmp(pmp3->type,".mp3",4) ==0) && + ((img_fd=da_get_image_fd(pmp3->path)) != -1)) { DPRINTF(ERR_INFO,"Dynamically attaching artwork to %s (fd %d)\n", pmp3->fname, img_fd); da_attach_image(img_fd, pwsc->fd, file_fd, offset); } else if(offset) { DPRINTF(ERR_INFO,"Seeking to offset %d\n",offset); - lseek(file_fd,offset,SEEK_SET); + lseek(file_fd,(fpos_t)offset,SEEK_SET); } if(copyfile(file_fd,pwsc->fd)) { @@ -438,7 +442,6 @@ int drop_privs(char *user) { * This thread merely spins waiting for signals */ void *signal_handler(void *arg) { - int error; sigset_t intmask; int sig; diff --git a/src/webserver.c b/src/webserver.c index 0e9dce90..1c6fa06b 100644 --- a/src/webserver.c +++ b/src/webserver.c @@ -688,6 +688,19 @@ void *ws_dispatcher(void *arg) { first=ws_urldecode(pwsc->uri); free(pwsc->uri); pwsc->uri=first; + + /* Strip out the proxy stuff - iTunes 4.5 */ + first=strstr(pwsc->uri,"://"); + if(first) { + first += 3; + first=strchr(first,'/'); + if(first) { + first=strdup(first); + free(pwsc->uri); + pwsc->uri=first; + } + } + DPRINTF(ERR_DEBUG,"Thread %d: Translated URI: %s\n",pwsc->threadno, pwsc->uri); @@ -945,11 +958,12 @@ int ws_testarg(ARGLIST *root, char *key, char *value) { char *ws_getarg(ARGLIST *root, char *key) { ARGLIST *pcurrent=root->next; - while((pcurrent)&&(strcasecmp(pcurrent->key,key))) + while((pcurrent)&&(strcasecmp(pcurrent->key,key))) pcurrent=pcurrent->next; if(pcurrent) return pcurrent->value; + return NULL; } @@ -1132,6 +1146,8 @@ int ws_findhandler(WS_PRIVATE *pwsp, WS_CONNINFO *pwsc, ws_lock_unsafe(); + *preq=NULL; + DPRINTF(ERR_DEBUG,"Thread %d: Preparing to find handler\n", pwsc->threadno); @@ -1287,7 +1303,7 @@ int ws_addresponseheader(WS_CONNINFO *pwsc, char *header, char *fmt, ...) { * Simple wrapper around the CONNINFO request vars */ char *ws_getvar(WS_CONNINFO *pwsc, char *var) { - return ws_getarg(&pwsc->request_vars,var); + return ws_getarg(&(pwsc->request_vars),var); } char *ws_getrequestheader(WS_CONNINFO *pwsc, char *header) {