mirror of
				https://github.com/owntone/owntone-server.git
				synced 2025-10-29 15:55:02 -04:00 
			
		
		
		
	modularize debugging statements
This commit is contained in:
		
							parent
							
								
									45fe1b5c81
								
							
						
					
					
						commit
						31aa0d8575
					
				| @ -241,7 +241,7 @@ int config_read(char *file) { | ||||
|     err=0; | ||||
|     while((pce->config_element != -1)) { | ||||
| 	if(pce->required && pce->config_element && !pce->changed) { | ||||
| 	    DPRINTF(ERR_LOG,"Required config entry '%s' not specified\n",pce->name); | ||||
| 	    DPRINTF(E_LOG,L_CONF,"Required config entry '%s' not specified\n",pce->name); | ||||
| 	    err=-1; | ||||
| 	} | ||||
| 
 | ||||
| @ -249,10 +249,10 @@ int config_read(char *file) { | ||||
| 	if((pce->config_element) && (pce->changed)) { | ||||
| 	    switch(pce->type) { | ||||
| 	    case CONFIG_TYPE_STRING: | ||||
| 		DPRINTF(ERR_INFO,"%s: %s\n",pce->name,*((char**)pce->var)); | ||||
| 		DPRINTF(E_INF,"%s: %s\n",pce->name,*((char**)pce->var)); | ||||
| 		break; | ||||
| 	    case CONFIG_TYPE_INT: | ||||
| 		DPRINTF(ERR_INFO,"%s: %d\n",pce->name,*((int*)pce->var)); | ||||
| 		DPRINTF(E_INF,"%s: %d\n",pce->name,*((int*)pce->var)); | ||||
| 		break; | ||||
| 	    } | ||||
| 	} | ||||
| @ -351,7 +351,7 @@ void config_subst_stream(WS_CONNINFO *pwsc, int fd_src) { | ||||
| 	    if((next == '@') && (strlen(argbuffer) > 0)) { | ||||
| 		in_arg=0; | ||||
| 
 | ||||
| 		DPRINTF(ERR_DEBUG,"Got directive %s\n",argbuffer); | ||||
| 		DPRINTF(E_DBG,L_CONF,"Got directive %s\n",argbuffer); | ||||
| 
 | ||||
| 		/* see if there are args */ | ||||
| 		first=last=argbuffer; | ||||
| @ -401,7 +401,7 @@ void config_handler(WS_CONNINFO *pwsc) { | ||||
|     struct stat sb; | ||||
|     char *pw; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Entering config_handler\n"); | ||||
|     DPRINTF(E_DBG,L_CONF|L_WS,"Entering config_handler\n"); | ||||
| 
 | ||||
|     config_set_status(pwsc,0,"Serving admin pages"); | ||||
|      | ||||
| @ -411,7 +411,7 @@ void config_handler(WS_CONNINFO *pwsc) { | ||||
|     snprintf(path,PATH_MAX,"%s/%s",config.web_root,pwsc->uri); | ||||
|     if(!realpath(path,resolved_path)) { | ||||
| 	pwsc->error=errno; | ||||
| 	DPRINTF(ERR_WARN,"Cannot resolve %s\n",path); | ||||
| 	DPRINTF(E_WARN,L_CONF|L_WS,"Cannot resolve %s\n",path); | ||||
| 	ws_returnerror(pwsc,404,"Not found"); | ||||
| 	config_set_status(pwsc,0,NULL); | ||||
| 	return; | ||||
| @ -422,13 +422,13 @@ void config_handler(WS_CONNINFO *pwsc) { | ||||
|     if(sb.st_mode & S_IFDIR) | ||||
| 	strcat(resolved_path,"/index.html"); | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Thread %d: Preparing to serve %s\n", | ||||
|     DPRINTF(E_DBG,L_CONF|L_WS,"Thread %d: Preparing to serve %s\n", | ||||
| 	    pwsc->threadno, resolved_path); | ||||
| 
 | ||||
|     if(strncmp(resolved_path,config.web_root, | ||||
| 	       strlen(config.web_root))) { | ||||
| 	pwsc->error=EINVAL; | ||||
| 	DPRINTF(ERR_WARN,"Thread %d: Requested file %s out of root\n", | ||||
| 	DPRINTF(E_WARN,L_CONF|L_WS,"Thread %d: Requested file %s out of root\n", | ||||
| 		pwsc->threadno,resolved_path); | ||||
| 	ws_returnerror(pwsc,403,"Forbidden"); | ||||
| 	config_set_status(pwsc,0,NULL); | ||||
| @ -438,7 +438,7 @@ void config_handler(WS_CONNINFO *pwsc) { | ||||
|     file_fd=r_open2(resolved_path,O_RDONLY); | ||||
|     if(file_fd == -1) { | ||||
| 	pwsc->error=errno; | ||||
| 	DPRINTF(ERR_WARN,"Thread %d: Error opening %s: %s\n", | ||||
| 	DPRINTF(E_WARN,L_CONF|L_WS,"Thread %d: Error opening %s: %s\n", | ||||
| 		pwsc->threadno,resolved_path,strerror(errno)); | ||||
| 	ws_returnerror(pwsc,404,"Not found"); | ||||
| 	config_set_status(pwsc,0,NULL); | ||||
| @ -480,7 +480,7 @@ void config_handler(WS_CONNINFO *pwsc) { | ||||
| 	    } | ||||
| 
 | ||||
| 	    if(!config_file_is_readonly()) { | ||||
| 		DPRINTF(ERR_INFO,"Updating config file\n"); | ||||
| 		DPRINTF(E_INF,L_CONF|L_WS,"Updating config file\n"); | ||||
| 		config_write(pwsc); | ||||
| 	    } | ||||
| 	} | ||||
| @ -496,7 +496,7 @@ void config_handler(WS_CONNINFO *pwsc) { | ||||
|     } | ||||
| 
 | ||||
|     r_close(file_fd); | ||||
|     DPRINTF(ERR_DEBUG,"Thread %d: Served successfully\n",pwsc->threadno); | ||||
|     DPRINTF(E_DBG,L_CONF|L_WS,"Thread %d: Served successfully\n",pwsc->threadno); | ||||
|     config_set_status(pwsc,0,NULL); | ||||
|     return; | ||||
| } | ||||
| @ -734,7 +734,7 @@ void config_emit_ispage(WS_CONNINFO *pwsc, void *value, char *arg) { | ||||
| 
 | ||||
|     char *page, *true, *false; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Splitting arg %s\n",arg); | ||||
|     DPRINTF(E_DBG,L_CONF|L_WS,"Splitting arg %s\n",arg); | ||||
| 
 | ||||
|     first=last=arg; | ||||
|     strsep(&last,":"); | ||||
| @ -761,7 +761,7 @@ void config_emit_ispage(WS_CONNINFO *pwsc, void *value, char *arg) { | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"page: %s, uri: %s\n",page,pwsc->uri); | ||||
|     DPRINTF(E_DBG,L_CONF|L_WS,"page: %s, uri: %s\n",page,pwsc->uri); | ||||
| 
 | ||||
|     if((strlen(page) > strlen(pwsc->uri)) || | ||||
|        (strcasecmp(page,(char*)&pwsc->uri[strlen(pwsc->uri) - strlen(page)]) != 0)) { | ||||
| @ -831,12 +831,12 @@ void config_emit_include(WS_CONNINFO *pwsc, void *value, char *arg) { | ||||
|     int file_fd; | ||||
|     struct stat sb; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Preparing to include %s\n",arg); | ||||
|     DPRINTF(E_DBG,L_CONF|L_WS,"Preparing to include %s\n",arg); | ||||
|      | ||||
|     snprintf(path,PATH_MAX,"%s/%s",config.web_root,arg); | ||||
|     if(!realpath(path,resolved_path)) { | ||||
| 	pwsc->error=errno; | ||||
| 	DPRINTF(ERR_WARN,"Cannot resolve %s\n",path); | ||||
| 	DPRINTF(E_WARN,L_CONF|L_WS,"Cannot resolve %s\n",path); | ||||
| 	ws_writefd(pwsc,"<hr><i>error: cannot find %s</i><hr>",arg); | ||||
| 	return; | ||||
|     } | ||||
| @ -849,13 +849,13 @@ void config_emit_include(WS_CONNINFO *pwsc, void *value, char *arg) { | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Thread %d: Preparing to serve %s\n", | ||||
|     DPRINTF(E_DBG,L_CONF|L_WS,"Thread %d: Preparing to serve %s\n", | ||||
| 	    pwsc->threadno, resolved_path); | ||||
| 
 | ||||
|     if(strncmp(resolved_path,config.web_root, | ||||
| 	       strlen(config.web_root))) { | ||||
| 	pwsc->error=EINVAL; | ||||
| 	DPRINTF(ERR_WARN,"Thread %d: Requested file %s out of root\n", | ||||
| 	DPRINTF(E_LOG,L_CONF|L_WS,"Thread %d: Requested file %s out of root\n", | ||||
| 		pwsc->threadno,resolved_path); | ||||
| 	ws_writefd(pwsc,"<hr><i>error: %s out of web root</i><hr>",arg); | ||||
| 	return; | ||||
| @ -864,7 +864,7 @@ void config_emit_include(WS_CONNINFO *pwsc, void *value, char *arg) { | ||||
|     file_fd=r_open2(resolved_path,O_RDONLY); | ||||
|     if(file_fd == -1) { | ||||
| 	pwsc->error=errno; | ||||
| 	DPRINTF(ERR_WARN,"Thread %d: Error opening %s: %s\n", | ||||
| 	DPRINTF(E_LOG,L_CONF|L_WS,"Thread %d: Error opening %s: %s\n", | ||||
| 		pwsc->threadno,resolved_path,strerror(errno)); | ||||
| 	ws_writefd(pwsc,"<hr><i>error: cannot open %s: %s</i><hr>",arg,strerror(errno)); | ||||
| 	return; | ||||
| @ -873,7 +873,7 @@ void config_emit_include(WS_CONNINFO *pwsc, void *value, char *arg) { | ||||
|     config_subst_stream(pwsc, file_fd); | ||||
| 
 | ||||
|     r_close(file_fd); | ||||
|     DPRINTF(ERR_DEBUG,"Thread %d: included successfully\n",pwsc->threadno); | ||||
|     DPRINTF(E_DBG,L_CONF|L_WS,"Thread %d: included successfully\n",pwsc->threadno); | ||||
|     return; | ||||
| } | ||||
| 
 | ||||
| @ -887,11 +887,11 @@ void config_set_status(WS_CONNINFO *pwsc, int session, char *fmt, ...) { | ||||
|     va_list ap; | ||||
|     SCAN_STATUS *pfirst, *plast; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Entering config_set_status\n"); | ||||
|     DPRINTF(E_DBG,L_CONF,"Entering config_set_status\n"); | ||||
| 
 | ||||
|     if(config_mutex_lock()) { | ||||
| 	/* we should really shutdown the app here... */ | ||||
| 	DPRINTF(ERR_FATAL,"Error acquiring config mutex\n"); | ||||
| 	DPRINTF(E_FATAL,L_CONF,"Error acquiring config mutex\n"); | ||||
|     } | ||||
| 
 | ||||
|     pfirst=plast=scan_status.next; | ||||
| @ -923,7 +923,7 @@ void config_set_status(WS_CONNINFO *pwsc, int session, char *fmt, ...) { | ||||
|     } else { | ||||
| 	if(!pfirst) { | ||||
| 	    config_mutex_unlock(); | ||||
| 	    DPRINTF(ERR_DEBUG,"Exiting config_set_status\n"); | ||||
| 	    DPRINTF(E_DBG,L_CONF,"Exiting config_set_status\n"); | ||||
| 	    return; | ||||
| 	} | ||||
| 
 | ||||
| @ -941,7 +941,7 @@ void config_set_status(WS_CONNINFO *pwsc, int session, char *fmt, ...) { | ||||
|     } | ||||
| 
 | ||||
|     config_mutex_unlock(); | ||||
|     DPRINTF(ERR_DEBUG,"Exiting config_set_status\n"); | ||||
|     DPRINTF(E_DBG,L_CONF,"Exiting config_set_status\n"); | ||||
| } | ||||
| 
 | ||||
| /*
 | ||||
| @ -1022,4 +1022,8 @@ void config_emit_flags(WS_CONNINFO *pwsc, void *value, char *arg) { | ||||
| #ifdef WITH_HOWL | ||||
|     ws_writefd(pwsc,"%s ","--enable-howl"); | ||||
| #endif | ||||
| 
 | ||||
| #ifdef NSLU2 | ||||
|     ws_writefd(pwsc,"%s ","--enable-nslu2"); | ||||
| #endif | ||||
| } | ||||
|  | ||||
| @ -47,7 +47,7 @@ DAAP_BLOCK *daap_get_new(void) { | ||||
| 
 | ||||
|     pnew=(DAAP_BLOCK*)malloc(sizeof(DAAP_BLOCK)); | ||||
|     if(!pnew) { | ||||
| 	DPRINTF(ERR_WARN,"Error mallocing a daap block\n"); | ||||
| 	DPRINTF(E_WARN,L_DAAP,"Error mallocing a daap block\n"); | ||||
| 	return NULL; | ||||
|     } | ||||
| 
 | ||||
| @ -73,7 +73,7 @@ DAAP_BLOCK *daap_add_formatted(DAAP_BLOCK *parent, char *tag, | ||||
|     DAAP_BLOCK *current,*last; | ||||
|     DAAP_BLOCK *pnew; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Adding daap tag %s\n",tag); | ||||
|     DPRINTF(E_DBG,L_DAAP,"Adding daap tag %s\n",tag); | ||||
|     pnew = daap_get_new(); | ||||
|     if(!pnew) | ||||
| 	return NULL; | ||||
| @ -322,7 +322,7 @@ void daap_free(DAAP_BLOCK *root) { | ||||
|     DAAP_BLOCK *pnext; | ||||
| 
 | ||||
|     while(root) { | ||||
| 	DPRINTF(ERR_DEBUG,"Freeing %c%c%c%c\n",root->tag[0],root->tag[1], | ||||
| 	DPRINTF(E_DBG,L_DAAP,"Freeing %c%c%c%c\n",root->tag[0],root->tag[1], | ||||
| 		root->tag[2],root->tag[3]); | ||||
| 
 | ||||
| 	if((root->size) && (root->free)) | ||||
|  | ||||
							
								
								
									
										74
									
								
								src/daap.c
									
									
									
									
									
								
							
							
						
						
									
										74
									
								
								src/daap.c
									
									
									
									
									
								
							| @ -198,7 +198,7 @@ DAAP_BLOCK *daap_response_content_codes(void) { | ||||
|     DAAP_ITEMS *current=taglist; | ||||
|     int g=1; | ||||
|      | ||||
|     DPRINTF(ERR_DEBUG,"Preparing to get content codes\n"); | ||||
|     DPRINTF(E_DBG,L_DAAP,"Preparing to get content codes\n"); | ||||
| 
 | ||||
|     root=daap_add_empty(NULL,"mccr"); | ||||
|     if(root) { | ||||
| @ -231,7 +231,7 @@ DAAP_BLOCK *daap_response_login(char *hostname) { | ||||
|     int g=1; | ||||
|     int session=0; | ||||
|      | ||||
|     DPRINTF(ERR_DEBUG,"Preparing to send login response\n"); | ||||
|     DPRINTF(E_DBG,L_DAAP,"Preparing to send login response\n"); | ||||
| 
 | ||||
|     root=daap_add_empty(NULL,"mlog"); | ||||
|     if(root) { | ||||
| @ -245,7 +245,7 @@ DAAP_BLOCK *daap_response_login(char *hostname) { | ||||
| 	return NULL; | ||||
|     } | ||||
| 
 | ||||
|     DPRINTF(ERR_LOG,"%s logging in as session %d\n",hostname,session); | ||||
|     DPRINTF(E_LOG,L_DAAP,"%s logging in as session %d\n",hostname,session); | ||||
| 
 | ||||
|     return root; | ||||
| } | ||||
| @ -385,10 +385,10 @@ MetaField_t encodeMetaRequest(char* meta, MetaDataMap* map) | ||||
| 	if(m->tag) | ||||
| 	    bits |= (((MetaField_t) 1) << m->bit); | ||||
| 	else | ||||
| 	    DPRINTF(ERR_WARN, "Unknown meta code: %.*s\n", len, start); | ||||
| 	    DPRINTF(E_WARN,L_DAAP,"Unknown meta code: %.*s\n", len, start); | ||||
|     } | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG, "meta codes: %llu\n", bits); | ||||
|     DPRINTF(E_DBG, L_DAAP, "meta codes: %llu\n", bits); | ||||
| 
 | ||||
|     return bits; | ||||
| } | ||||
| @ -410,7 +410,7 @@ DAAP_BLOCK *daap_response_songlist(char* metaStr, char* query) { | ||||
|     query_node_t*	filter = 0; | ||||
|     int			songs = 0; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"enter daap_response_songlist\n"); | ||||
|     DPRINTF(E_DBG,L_DAAP,"enter daap_response_songlist\n"); | ||||
| 
 | ||||
|     // if the meta tag is specified, encode it, if it's not specified
 | ||||
|     // we're given the latitude to select our own subset, for
 | ||||
| @ -422,16 +422,16 @@ DAAP_BLOCK *daap_response_songlist(char* metaStr, char* query) { | ||||
| 
 | ||||
|     if(0 != query) { | ||||
| 	filter = query_build(query, song_fields); | ||||
| 	DPRINTF(ERR_INFO,"query: %s\n", query); | ||||
| 	if(err_debuglevel >= ERR_INFO) /* this is broken */ | ||||
| 	DPRINTF(E_INF,L_DAAP|L_QRY,"query: %s\n", query); | ||||
| 	if(err_debuglevel >= E_INF) /* this is broken */ | ||||
| 	    query_dump(stderr,filter, 0); | ||||
|     } | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Preparing to send db items\n"); | ||||
|     DPRINTF(E_DBG,L_DAAP|L_DB,"Preparing to send db items\n"); | ||||
| 
 | ||||
|     henum=db_enum_begin(); | ||||
|     if((!henum) && (db_get_song_count())) { | ||||
| 	DPRINTF(ERR_DEBUG,"Can't get enum handle - exiting daap_response_songlist\n"); | ||||
| 	DPRINTF(E_DBG,L_DAAP|L_DB,"Can't get enum handle - exiting daap_response_songlist\n"); | ||||
| 	return NULL; | ||||
|     } | ||||
| 
 | ||||
| @ -448,7 +448,7 @@ DAAP_BLOCK *daap_response_songlist(char* metaStr, char* query) { | ||||
| 	    while(g && (current=db_enum(&henum))) { | ||||
| 		if(filter == 0 || query_test(filter, current)) | ||||
| 		{ | ||||
| 		    DPRINTF(ERR_DEBUG,"Got entry for %s\n",current->fname); | ||||
| 		    DPRINTF(E_DBG,L_DAAP|L_DB,"Got entry for %s\n",current->fname); | ||||
| 		    // song entry generation extracted for usage with
 | ||||
| 		    // playlists as well
 | ||||
| 		    g = 0 != daap_add_song_entry(mlcl, current, meta); | ||||
| @ -464,17 +464,17 @@ DAAP_BLOCK *daap_response_songlist(char* metaStr, char* query) { | ||||
| 	query_free(filter); | ||||
| 
 | ||||
|     if(!g) { | ||||
| 	DPRINTF(ERR_DEBUG,"Error enumerating database - exiting daap_response_songlist\n"); | ||||
| 	DPRINTF(E_DBG,L_DAAP|L_DB,"Error enumerating db - exiting daap_response_songlist\n"); | ||||
| 	daap_free(root); | ||||
| 	return NULL; | ||||
|     } | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Successfully enumerated database - %d items\n",songs); | ||||
|     DPRINTF(E_DBG,L_DAAP|L_DB,"Successfully enumerated database - %d items\n",songs); | ||||
| 
 | ||||
|     daap_set_int(root, "mtco", songs); | ||||
|     daap_set_int(root, "mrco", songs); | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Exiting daap_response_songlist\n"); | ||||
|     DPRINTF(E_DBG,L_DAAP,"Exiting daap_response_songlist\n"); | ||||
|     return root; | ||||
| } | ||||
| 
 | ||||
| @ -610,7 +610,7 @@ DAAP_BLOCK *daap_response_update(int fd, int clientver) { | ||||
|     struct timeval tv; | ||||
|     int result; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Preparing to send update response\n"); | ||||
|     DPRINTF(E_DBG,L_DAAP,"Preparing to send update response\n"); | ||||
| 
 | ||||
|     while(clientver == db_version()) { | ||||
| 	FD_ZERO(&rset); | ||||
| @ -622,7 +622,7 @@ DAAP_BLOCK *daap_response_update(int fd, int clientver) { | ||||
| 	result=select(fd+1,&rset,NULL,NULL,&tv); | ||||
| 	if(FD_ISSET(fd,&rset)) { | ||||
| 	    /* can't be ready for read, must be error */ | ||||
| 	    DPRINTF(ERR_DEBUG,"Socket closed?\n"); | ||||
| 	    DPRINTF(E_DBG,L_DAAP,"Socket closed?\n"); | ||||
| 	     | ||||
| 	    return NULL; | ||||
| 	} | ||||
| @ -657,7 +657,7 @@ DAAP_BLOCK *daap_response_playlists(char *name) { | ||||
|     int playlistid; | ||||
|     ENUMHANDLE henum; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Preparing to send playlists\n"); | ||||
|     DPRINTF(E_DBG,L_DAAP,"Preparing to send playlists\n"); | ||||
|      | ||||
|     root=daap_add_empty(NULL,"aply"); | ||||
|     if(root) { | ||||
| @ -681,10 +681,10 @@ DAAP_BLOCK *daap_response_playlists(char *name) { | ||||
| 	    henum=db_playlist_enum_begin(); | ||||
| 	    while(henum) { | ||||
| 		playlistid=db_playlist_enum(&henum); | ||||
| 		DPRINTF(ERR_DEBUG,"Returning playlist %d\n",playlistid); | ||||
| 		DPRINTF(ERR_DEBUG,"  -- Songs: %d\n", | ||||
| 		DPRINTF(E_DBG,L_DAAP|L_PL,"Returning playlist %d\n",playlistid); | ||||
| 		DPRINTF(E_DBG,L_DAAP|L_PL,"  -- Songs: %d\n", | ||||
| 			db_get_playlist_entry_count(playlistid)); | ||||
| 		DPRINTF(ERR_DEBUG,"  -- Smart: %s\n", | ||||
| 		DPRINTF(E_DBG,L_DAAP|L_PL,"  -- Smart: %s\n", | ||||
| 			db_get_playlist_is_smart(playlistid) ? | ||||
| 			"Yes" : "No"); | ||||
| 		mlit=daap_add_empty(mlcl,"mlit"); | ||||
| @ -707,7 +707,7 @@ DAAP_BLOCK *daap_response_playlists(char *name) { | ||||
|     g = g && mlcl; | ||||
| 
 | ||||
|     if(!g) { | ||||
| 	DPRINTF(ERR_INFO,"Memory problem.  Bailing\n"); | ||||
| 	DPRINTF(E_INF,L_DAAP,"Memory problem.  Bailing\n"); | ||||
| 	daap_free(root); | ||||
| 	return NULL; | ||||
|     } | ||||
| @ -727,7 +727,7 @@ DAAP_BLOCK *daap_response_dbinfo(char *name) { | ||||
|     DAAP_BLOCK *mlit=NULL; | ||||
|     int g=1; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Preparing to send db info\n"); | ||||
|     DPRINTF(E_DBG,L_DAAP|L_DB,"Preparing to send db info\n"); | ||||
|      | ||||
|     root=daap_add_empty(NULL,"avdb"); | ||||
|     if(root) { | ||||
| @ -751,12 +751,12 @@ DAAP_BLOCK *daap_response_dbinfo(char *name) { | ||||
|     g = g && mlcl && mlit; | ||||
| 
 | ||||
|     if(!g) { | ||||
| 	DPRINTF(ERR_INFO,"Memory problem.  Bailing\n"); | ||||
| 	DPRINTF(E_INF,L_DAAP,"Memory problem.  Bailing\n"); | ||||
| 	daap_free(root); | ||||
| 	return NULL; | ||||
|     } | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Sent db info... %d songs, %d playlists\n",db_get_song_count(), | ||||
|     DPRINTF(E_DBG,L_DAAP|L_DB,"Sent db info... %d songs, %d playlists\n",db_get_song_count(), | ||||
| 	    db_get_playlist_count()); | ||||
| 
 | ||||
|     return root; | ||||
| @ -771,7 +771,7 @@ 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 for client version %s\n",client_version); | ||||
|     DPRINTF(E_DBG,L_DAAP,"Preparing to send server-info for client ver %s\n",client_version); | ||||
| 
 | ||||
|     root=daap_add_empty(NULL,"msrv"); | ||||
| 
 | ||||
| @ -867,12 +867,12 @@ DAAP_BLOCK *daap_response_playlist_items(unsigned int playlist, char* metaStr, c | ||||
| 
 | ||||
|     if(0 != query) { | ||||
| 	filter = query_build(query, song_fields); | ||||
| 	DPRINTF(ERR_INFO,"query: %s\n",query); | ||||
| 	if(err_debuglevel >= ERR_INFO) /* this is broken */ | ||||
| 	DPRINTF(E_INF,L_DAAP|L_QRY,"query: %s\n",query); | ||||
| 	if(err_debuglevel >= E_INF) /* this is broken */ | ||||
| 	    query_dump(stderr,filter, 0); | ||||
|     } | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Preparing to send playlist items for pl #%d\n",playlist); | ||||
|     DPRINTF(E_DBG,L_DAAP|L_PL,"Preparing to send playlist items for pl #%d\n",playlist); | ||||
|      | ||||
|     if(playlist == 1) { | ||||
| 	henum=db_enum_begin(); | ||||
| @ -914,7 +914,7 @@ DAAP_BLOCK *daap_response_playlist_items(unsigned int playlist, char* metaStr, c | ||||
| 			if(0 == filter || query_test(filter, current)) | ||||
| 			{ | ||||
| 			    songs++; | ||||
| 			    DPRINTF(ERR_DEBUG,"Adding itemid %d\n",itemid); | ||||
| 			    DPRINTF(E_DBG,L_DAAP|L_PL,"Adding itemid %d\n",itemid); | ||||
| 			    mlit=daap_add_song_entry(mlcl,current,meta); | ||||
| 			    if(0 != mlit) { | ||||
| 				if(wantsMeta(meta, metaContainerItemId)) // current->id?
 | ||||
| @ -940,7 +940,7 @@ DAAP_BLOCK *daap_response_playlist_items(unsigned int playlist, char* metaStr, c | ||||
| 	return NULL; | ||||
|     } | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Sucessfully enumerated %d items\n",songs); | ||||
|     DPRINTF(E_DBG,L_DAAP|L_PL,"Sucessfully enumerated %d items\n",songs); | ||||
| 
 | ||||
|     daap_set_int(root, "mtco", songs); | ||||
|     daap_set_int(root, "mrco", songs); | ||||
| @ -1046,13 +1046,13 @@ void daap_handle_index(DAAP_BLOCK* block, const char* index) | ||||
|     // should have already be created
 | ||||
|     daap_set_int(block, "mrco", count); | ||||
| 
 | ||||
|     DPRINTF(ERR_INFO, "index:%s first:%d count:%d\n", index, first, count); | ||||
|     DPRINTF(E_INF,L_DAAP|L_IND, "index:%s first:%d count:%d\n", index, first, count); | ||||
| 
 | ||||
|     // remove the first first entries
 | ||||
|     for(back = &list->children ; *back && first ; ) | ||||
| 	if(!strncmp((**back).tag, "mlit", 4)) | ||||
| 	{ | ||||
| 	    DPRINTF(ERR_DEBUG, "first:%d removing\n", first); | ||||
| 	    DPRINTF(E_DBG,L_DAAP|L_IND, "first:%d removing\n", first); | ||||
| 	    daap_remove(*back); | ||||
| 	    first--; | ||||
| 	} | ||||
| @ -1063,7 +1063,7 @@ void daap_handle_index(DAAP_BLOCK* block, const char* index) | ||||
|     for( ; *back && count ; back = &(**back).next) | ||||
| 	if(!strncmp((**back).tag, "mlit", 4)) | ||||
| 	{ | ||||
| 	    DPRINTF(ERR_DEBUG, "count:%d keeping\n", count); | ||||
| 	    DPRINTF(E_DBG,L_DAAP|L_IND,"count:%d keeping\n", count); | ||||
| 	    count--; | ||||
| 	} | ||||
| 
 | ||||
| @ -1072,7 +1072,7 @@ void daap_handle_index(DAAP_BLOCK* block, const char* index) | ||||
|     { | ||||
| 	if(!strncmp((**back).tag, "mlit", 4)) | ||||
| 	{ | ||||
| 	    DPRINTF(ERR_DEBUG, "removing spare\n"); | ||||
| 	    DPRINTF(E_DBG,L_DAAP|L_IND,"removing spare\n"); | ||||
| 	    daap_remove(*back); | ||||
| 	} | ||||
| 	else | ||||
| @ -1173,7 +1173,7 @@ DAAP_BLOCK* daap_response_browse(const char* name, const char* filter) | ||||
|     } | ||||
|     else | ||||
|     { | ||||
| 	DPRINTF(ERR_WARN,"Invalid browse request: %s\n", name); | ||||
| 	DPRINTF(E_WARN,L_DAAP|L_BROW,"Invalid browse request: %s\n", name); | ||||
| 	return NULL; | ||||
|     } | ||||
| 
 | ||||
| @ -1182,8 +1182,8 @@ DAAP_BLOCK* daap_response_browse(const char* name, const char* filter) | ||||
| 	return NULL; | ||||
| 
 | ||||
|     if(query) { | ||||
| 	DPRINTF(ERR_INFO,"query: %s\n",filter); | ||||
| 	if(err_debuglevel >= ERR_INFO) /* this is broken */ | ||||
| 	DPRINTF(E_INF,L_DAAP|L_BROW|L_QRY,"query: %s\n",filter); | ||||
| 	if(err_debuglevel >= E_INF) /* this is broken */ | ||||
| 	    query_dump(stderr,query, 0); | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -185,7 +185,7 @@ void db_readlock(void) { | ||||
|     int err; | ||||
| 
 | ||||
|     if((err=pthread_rwlock_rdlock(&db_rwlock))) { | ||||
| 	DPRINTF(ERR_FATAL,"cannot lock rdlock: %s\n",strerror(err)); | ||||
| 	DPRINTF(E_FATAL,L_DB,"cannot lock rdlock: %s\n",strerror(err)); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| @ -198,7 +198,7 @@ void db_writelock(void) { | ||||
|     int err; | ||||
| 
 | ||||
|     if((err=pthread_rwlock_wrlock(&db_rwlock))) { | ||||
| 	DPRINTF(ERR_FATAL,"cannot lock rwlock: %s\n",strerror(err)); | ||||
| 	DPRINTF(E_FATAL,L_DB,"cannot lock rwlock: %s\n",strerror(err)); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| @ -251,7 +251,7 @@ int db_open(char *parameters, int reload) { | ||||
|     db_songs=gdbm_open(db_path, 0, reload | GDBM_SYNC | GDBM_NOLOCK, | ||||
| 		       0600,NULL); | ||||
|     if(!db_songs) { | ||||
| 	DPRINTF(ERR_FATAL,"Could not open songs database (%s)\n", | ||||
| 	DPRINTF(E_FATAL,L_DB,"Could not open songs database (%s)\n", | ||||
| 		db_path); | ||||
| 	return -1; | ||||
|     } | ||||
| @ -275,7 +275,7 @@ int db_init(void) { | ||||
|     db_version_no=1; | ||||
|     db_song_count=0; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Building playlists\n"); | ||||
|     DPRINTF(E_DBG,L_DB|L_PL,"Building playlists\n"); | ||||
| 
 | ||||
|     /* count the actual songs and build the playlists */ | ||||
|     tmp_key=gdbm_firstkey(db_songs); | ||||
| @ -302,7 +302,7 @@ int db_init(void) { | ||||
| 	db_song_count++; | ||||
|     } | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Loaded database... found %d songs\n",db_song_count); | ||||
|     DPRINTF(E_DBG,L_DB,"Loaded database... found %d songs\n",db_song_count); | ||||
| 
 | ||||
|     /* and the playlists */ | ||||
|     return 0; | ||||
| @ -410,13 +410,13 @@ int db_end_initial_update(void) { | ||||
| 
 | ||||
|     db_update_mode=0; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Initial update over.  Removing stale items\n"); | ||||
|     DPRINTF(E_DBG,L_DB|L_SCAN,"Initial update over.  Removing stale items\n"); | ||||
|     for(val=rblookup(RB_LUFIRST,NULL,db_removed); val != NULL;  | ||||
| 	val=rblookup(RB_LUNEXT,val,db_removed)) { | ||||
| 	db_delete(*((int*)val)); | ||||
|     } | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Done removing stale items\n"); | ||||
|     DPRINTF(E_DBG,L_DB|L_SCAN,"Done removing stale items\n"); | ||||
| 
 | ||||
|     rbdestroy(db_removed); | ||||
| 
 | ||||
| @ -465,14 +465,14 @@ int db_add_playlist(unsigned int playlistid, char *name, int is_smart) { | ||||
| 	return -1; | ||||
|     } | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Adding new playlist %s\n",name); | ||||
|     DPRINTF(E_DBG,L_DB|L_PL,"Adding new playlist %s\n",name); | ||||
| 
 | ||||
|     pnew->next=db_playlists.next; | ||||
|     db_playlists.next=pnew; | ||||
| 
 | ||||
|     db_version_no++; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Added playlist\n"); | ||||
|     DPRINTF(E_DBG,L_DB|L_PL,"Added playlist\n"); | ||||
|     return 0; | ||||
| } | ||||
| 
 | ||||
| @ -496,14 +496,14 @@ int db_add_playlist_song(unsigned int playlistid, unsigned int itemid) { | ||||
|     pnew->id=itemid; | ||||
|     pnew->next=NULL; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Adding item %d to %d\n",itemid,playlistid);  | ||||
|     DPRINTF(E_DBG,L_DB|L_PL,"Adding item %d to %d\n",itemid,playlistid);  | ||||
| 
 | ||||
|     current=db_playlists.next; | ||||
|     while(current && (current->id != playlistid)) | ||||
| 	current=current->next; | ||||
| 
 | ||||
|     if(!current) { | ||||
| 	DPRINTF(ERR_WARN,"Could not find playlist attempting to add to\n"); | ||||
| 	DPRINTF(E_WARN,L_DB|L_PL,"Could not find playlist attempting to add to\n"); | ||||
| 	if(!db_update_mode) | ||||
| 	    db_unlock(); | ||||
| 	db_unlock(); | ||||
| @ -515,13 +515,13 @@ int db_add_playlist_song(unsigned int playlistid, unsigned int itemid) { | ||||
| 	db_playlist_count++; | ||||
| 
 | ||||
|     current->songs++; | ||||
|     DPRINTF(ERR_DEBUG,"Playlist now has %d entries\n",current->songs); | ||||
|     DPRINTF(E_DBG,L_DB|L_PL,"Playlist now has %d entries\n",current->songs); | ||||
|     pnew->next = current->nodes; | ||||
|     current->nodes = pnew; | ||||
| 
 | ||||
|     db_version_no++; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Added playlist item\n"); | ||||
|     DPRINTF(E_DBG,L_DB|L_PL,"Added playlist item\n"); | ||||
|     return 0; | ||||
| } | ||||
| 
 | ||||
| @ -677,7 +677,7 @@ int db_unpackrecord(datum *pdatum, MP3FILE *pmp3) { | ||||
|     ppacked=(MP3PACKED*)pdatum->dptr; | ||||
| 
 | ||||
|     if(ppacked->version != DB_VERSION)  | ||||
| 	DPRINTF(ERR_FATAL,"ON-DISK DATABASE VERSION HAS CHANGED\n" | ||||
| 	DPRINTF(E_FATAL,L_DB,"ON-DISK DATABASE VERSION HAS CHANGED\n" | ||||
| 		"Delete your songs.gdb and restart.\n"); | ||||
| 
 | ||||
|     pmp3->bitrate=ppacked->bitrate; | ||||
| @ -772,7 +772,7 @@ int db_add(MP3FILE *pmp3) { | ||||
|     MP3PACKED *ppacked; | ||||
|     unsigned int id; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Adding %s\n",pmp3->path); | ||||
|     DPRINTF(E_DBG,L_DB,"Adding %s\n",pmp3->path); | ||||
| 
 | ||||
|     if(!(pnew=db_packrecord(pmp3))) { | ||||
| 	errno=ENOMEM; | ||||
| @ -791,16 +791,16 @@ int db_add(MP3FILE *pmp3) { | ||||
|     ppacked->time_played=0; /* do we want to keep track of this? */ | ||||
| 
 | ||||
|     if(gdbm_store(db_songs,dkey,*pnew,GDBM_REPLACE)) { | ||||
| 	DPRINTF(ERR_FATAL,"Error inserting file %s in database\n",pmp3->fname); | ||||
| 	DPRINTF(E_FATAL,L_DB,"Error inserting file %s in database\n",pmp3->fname); | ||||
|     } | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Testing for %d\n",pmp3->id); | ||||
|     DPRINTF(E_DBG,L_DB,"Testing for %d\n",pmp3->id); | ||||
|     id=pmp3->id; | ||||
|     dkey.dptr=(void*)&id; | ||||
|     dkey.dsize=sizeof(unsigned int); | ||||
| 
 | ||||
|     if(!gdbm_exists(db_songs,dkey)) { | ||||
| 	DPRINTF(ERR_FATAL,"Error.. could not find just added file\n"); | ||||
| 	DPRINTF(E_FATAL,L_DB,"Error.. could not find just added file\n"); | ||||
|     } | ||||
| 
 | ||||
|     free(pnew->dptr); | ||||
| @ -810,7 +810,7 @@ int db_add(MP3FILE *pmp3) { | ||||
| 
 | ||||
|     db_song_count++; | ||||
|      | ||||
|     DPRINTF(ERR_DEBUG,"Added file\n"); | ||||
|     DPRINTF(E_DBG,L_DB,"Added file\n"); | ||||
|     return 0; | ||||
| } | ||||
| 
 | ||||
| @ -903,10 +903,10 @@ ENUMHANDLE db_enum_begin(void) { | ||||
| 
 | ||||
| 	data = gdbm_fetch(db_songs, key); | ||||
| 	if(!data.dptr) | ||||
| 	    DPRINTF(ERR_FATAL, "Cannot find item... corrupt database?\n"); | ||||
| 	    DPRINTF(E_FATAL,L_DB, "Cannot find item... corrupt database?\n"); | ||||
| 
 | ||||
| 	if(db_unpackrecord(&data, &entry->mp3file)) | ||||
| 	    DPRINTF(ERR_FATAL, "Cannot unpack item... corrupt database?\n"); | ||||
| 	    DPRINTF(E_FATAL,L_DB, "Cannot unpack item... corrupt database?\n"); | ||||
| 
 | ||||
| 	for(root = &helper->root ; *root ; root = &(**root).next) | ||||
| 	{ | ||||
| @ -998,10 +998,10 @@ MP3FILE *db_enum(ENUMHANDLE *current) { | ||||
|     if(pkey->dptr) { | ||||
| 	data=gdbm_fetch(db_songs,*pkey); | ||||
| 	if(!data.dptr) | ||||
| 	    DPRINTF(ERR_FATAL, "Cannot find item.... corrupt database?\n"); | ||||
| 	    DPRINTF(E_FATAL,L_DB, "Cannot find item.... corrupt database?\n"); | ||||
| 
 | ||||
| 	if(db_unpackrecord(&data,&mp3)) | ||||
| 	    DPRINTF(ERR_FATAL,"Cannot unpack item... corrupt database?\n"); | ||||
| 	    DPRINTF(E_FATAL,L_DB,"Cannot unpack item... corrupt database?\n"); | ||||
| 
 | ||||
| 	free(data.dptr); | ||||
| 
 | ||||
| @ -1274,14 +1274,14 @@ int db_exists(int id) { | ||||
|     MP3FILE *pmp3; | ||||
|     datum key,content; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Checking if node %d in db\n",id); | ||||
|     DPRINTF(E_DBG,L_DB,"Checking if node %d in db\n",id); | ||||
|     key.dptr=(char*)&id; | ||||
|     key.dsize=sizeof(int); | ||||
| 
 | ||||
|     content=gdbm_fetch(db_songs,key); | ||||
|     MEMNOTIFY(content.dptr); | ||||
|     if(!content.dptr) { | ||||
| 	DPRINTF(ERR_DEBUG,"Nope!  Not in DB\n"); | ||||
| 	DPRINTF(E_DBG,L_DB,"Nope!  Not in DB\n"); | ||||
| 	return 0; | ||||
|     } | ||||
| 
 | ||||
| @ -1289,13 +1289,13 @@ int db_exists(int id) { | ||||
| 	/* knock it off the maybe list */ | ||||
| 	node = (int*)rbdelete((void*)&id,db_removed); | ||||
| 	if(node) { | ||||
| 	    DPRINTF(ERR_DEBUG,"Knocked node %d from the list\n",*node); | ||||
| 	    DPRINTF(E_DBG,L_DB,"Knocked node %d from the list\n",*node); | ||||
| 	    free(node); | ||||
| 	} | ||||
|     } | ||||
| 
 | ||||
|     free(content.dptr); | ||||
|     DPRINTF(ERR_DEBUG,"Yup, in database\n"); | ||||
|     DPRINTF(E_DBG,L_DB,"Yup, in database\n"); | ||||
|     return 1; | ||||
| } | ||||
| 
 | ||||
| @ -1337,7 +1337,7 @@ int db_delete(int id) { | ||||
|     DB_PLAYLIST *pcurrent; | ||||
|     DB_PLAYLISTENTRY *phead, *ptail; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Removing item %d\n",id); | ||||
|     DPRINTF(E_DBG,L_DB,"Removing item %d\n",id); | ||||
| 
 | ||||
|     if(db_exists(id)) { | ||||
| 	key.dptr=(void*)&id; | ||||
| @ -1356,7 +1356,7 @@ int db_delete(int id) { | ||||
| 	    } | ||||
| 
 | ||||
| 	    if(phead) { /* found it */ | ||||
| 		DPRINTF(ERR_DEBUG,"Removing from playlist %d\n", | ||||
| 		DPRINTF(E_DBG,L_DB|L_PL,"Removing from playlist %d\n", | ||||
| 			pcurrent->id); | ||||
| 		if(phead == pcurrent->nodes) { | ||||
| 		    pcurrent->nodes=phead->next; | ||||
| @ -1366,7 +1366,7 @@ int db_delete(int id) { | ||||
| 		free(phead); | ||||
| 
 | ||||
| 		if(pcurrent->nodes == NULL) { | ||||
| 		    DPRINTF(ERR_DEBUG,"Empty Playlist!\n"); | ||||
| 		    DPRINTF(E_DBG,L_DB|L_PL,"Empty Playlist!\n"); | ||||
| 		    db_playlist_count--; | ||||
| 		} | ||||
| 	    } | ||||
|  | ||||
| @ -252,10 +252,10 @@ int db_add_playlist(unsigned int playlistid, char *name, int is_smart) { | ||||
| 	return -1; | ||||
|     } | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Adding new playlist %s\n",name); | ||||
|     DPRINTF(E_DBG,L_DB,"Adding new playlist %s\n",name); | ||||
| 
 | ||||
|     if((err=pthread_rwlock_wrlock(&db_rwlock))) { | ||||
| 	DPRINTF(ERR_WARN,"cannot lock wrlock in db_add\n"); | ||||
| 	DPRINTF(E_WARN,L_DB,"cannot lock wrlock in db_add\n"); | ||||
| 	free(pnew->name); | ||||
| 	free(pnew); | ||||
| 	errno=err; | ||||
| @ -272,7 +272,7 @@ int db_add_playlist(unsigned int playlistid, char *name, int is_smart) { | ||||
|     } | ||||
| 
 | ||||
|     pthread_rwlock_unlock(&db_rwlock); | ||||
|     DPRINTF(ERR_DEBUG,"Added playlist\n"); | ||||
|     DPRINTF(E_DBG,L_DB,"Added playlist\n"); | ||||
|     return 0; | ||||
| } | ||||
| 
 | ||||
| @ -293,10 +293,10 @@ int db_add_playlist_song(unsigned int playlistid, unsigned int itemid) { | ||||
|     pnew->id=itemid; | ||||
|     pnew->next=NULL; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Adding new playlist item\n");  | ||||
|     DPRINTF(E_DBG,L_DB,"Adding new playlist item\n");  | ||||
| 
 | ||||
|     if((err=pthread_rwlock_wrlock(&db_rwlock))) { | ||||
| 	DPRINTF(ERR_WARN,"cannot lock wrlock in db_add\n"); | ||||
| 	DPRINTF(E_WARN,L_DB,"cannot lock wrlock in db_add\n"); | ||||
| 	free(pnew); | ||||
| 	errno=err; | ||||
| 	return -1; | ||||
| @ -307,7 +307,7 @@ int db_add_playlist_song(unsigned int playlistid, unsigned int itemid) { | ||||
| 	current=current->next; | ||||
| 
 | ||||
|     if(!current) { | ||||
| 	DPRINTF(ERR_WARN,"Could not find playlist attempting to add to\n"); | ||||
| 	DPRINTF(E_WARN,L_DB,"Could not find playlist attempting to add to\n"); | ||||
| 	pthread_rwlock_unlock(&db_rwlock); | ||||
| 	free(pnew); | ||||
| 	return -1; | ||||
| @ -325,7 +325,7 @@ int db_add_playlist_song(unsigned int playlistid, unsigned int itemid) { | ||||
|     } | ||||
| 
 | ||||
|     pthread_rwlock_unlock(&db_rwlock); | ||||
|     DPRINTF(ERR_DEBUG,"Added playlist item\n"); | ||||
|     DPRINTF(E_DBG,L_DB,"Added playlist item\n"); | ||||
|     return 0; | ||||
| } | ||||
| 
 | ||||
| @ -340,7 +340,7 @@ int db_add(MP3FILE *mp3file) { | ||||
|     int g; | ||||
|     MP3RECORD *pnew; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Adding %s\n",mp3file->path); | ||||
|     DPRINTF(E_DBG,L_DB,"Adding %s\n",mp3file->path); | ||||
| 
 | ||||
|     if((pnew=(MP3RECORD*)malloc(sizeof(MP3RECORD))) == NULL) { | ||||
| 	free(pnew); | ||||
| @ -386,14 +386,14 @@ int db_add(MP3FILE *mp3file) { | ||||
| 	g = g && (pnew->mp3file.grouping=strdup(mp3file->grouping)); | ||||
| 
 | ||||
|     if(!g) { | ||||
| 	DPRINTF(ERR_WARN,"Malloc error in db_add\n"); | ||||
| 	DPRINTF(E_WARN,L_DB,"Malloc error in db_add\n"); | ||||
| 	db_freerecord(pnew); | ||||
| 	errno=ENOMEM; | ||||
| 	return -1; | ||||
|     } | ||||
| 
 | ||||
|     if((err=pthread_rwlock_wrlock(&db_rwlock))) { | ||||
| 	DPRINTF(ERR_WARN,"cannot lock wrlock in db_add\n"); | ||||
| 	DPRINTF(E_WARN,L_DB,"cannot lock wrlock in db_add\n"); | ||||
| 	db_freerecord(pnew); | ||||
| 	errno=err; | ||||
| 	return -1; | ||||
| @ -411,7 +411,7 @@ int db_add(MP3FILE *mp3file) { | ||||
|     db_song_count++; | ||||
|      | ||||
|     pthread_rwlock_unlock(&db_rwlock); | ||||
|     DPRINTF(ERR_DEBUG,"Added file\n"); | ||||
|     DPRINTF(E_DBG,L_DB,"Added file\n"); | ||||
|     return 0; | ||||
| } | ||||
| 
 | ||||
| @ -450,7 +450,7 @@ MP3RECORD *db_enum_begin(void) { | ||||
|     int err; | ||||
| 
 | ||||
|     if((err=pthread_rwlock_rdlock(&db_rwlock))) { | ||||
| 	DPRINTF(ERR_FATAL,"Cannot lock rwlock\n"); | ||||
| 	DPRINTF(E_FATAL,L_DB,"Cannot lock rwlock\n"); | ||||
| 	errno=err; | ||||
| 	return NULL; | ||||
|     } | ||||
| @ -468,7 +468,7 @@ DB_PLAYLIST *db_playlist_enum_begin(void) { | ||||
|     DB_PLAYLIST *current; | ||||
| 
 | ||||
|     if((err=pthread_rwlock_rdlock(&db_rwlock))) { | ||||
| 	DPRINTF(ERR_FATAL,"Cannot lock rwlock\n"); | ||||
| 	DPRINTF(E_FATAL,L_DB,"Cannot lock rwlock\n"); | ||||
| 	errno=err; | ||||
| 	return NULL; | ||||
|     } | ||||
| @ -491,7 +491,7 @@ DB_PLAYLISTENTRY *db_playlist_items_enum_begin(int playlistid) { | ||||
|     int err; | ||||
| 
 | ||||
|     if((err=pthread_rwlock_rdlock(&db_rwlock))) { | ||||
| 	DPRINTF(ERR_FATAL,"Cannot lock rwlock\n"); | ||||
| 	DPRINTF(E_FATAL,L_DB,"Cannot lock rwlock\n"); | ||||
| 	errno=err; | ||||
| 	return NULL; | ||||
|     } | ||||
| @ -636,7 +636,7 @@ int db_get_playlist_is_smart(int playlistid) { | ||||
|     int result; | ||||
| 
 | ||||
|     if((err=pthread_rwlock_rdlock(&db_rwlock))) { | ||||
| 	DPRINTF(ERR_FATAL,"Cannot lock rwlock\n"); | ||||
| 	DPRINTF(E_FATAL,L_DB,"Cannot lock rwlock\n"); | ||||
| 	errno=err; | ||||
| 	return -1;	 | ||||
|     } | ||||
| @ -667,7 +667,7 @@ int db_get_playlist_entry_count(int playlistid) { | ||||
|     int err; | ||||
| 
 | ||||
|     if((err=pthread_rwlock_rdlock(&db_rwlock))) { | ||||
| 	DPRINTF(ERR_FATAL,"Cannot lock rwlock\n"); | ||||
| 	DPRINTF(E_FATAL,L_DB,"Cannot lock rwlock\n"); | ||||
| 	errno=err; | ||||
| 	return -1;	 | ||||
|     } | ||||
| @ -699,7 +699,7 @@ char *db_get_playlist_name(int playlistid) { | ||||
|     int err; | ||||
| 
 | ||||
|     if((err=pthread_rwlock_rdlock(&db_rwlock))) { | ||||
| 	DPRINTF(ERR_FATAL,"Cannot lock rwlock\n"); | ||||
| 	DPRINTF(E_FATAL,L_DB,"Cannot lock rwlock\n"); | ||||
| 	errno=err; | ||||
| 	return NULL; | ||||
|     } | ||||
|  | ||||
| @ -86,7 +86,7 @@ int da_get_image_fd(char *filename) { | ||||
|     strcpy(path_end+1,config.artfilename); | ||||
|     fd = open(buffer,O_RDONLY); | ||||
|     if(fd != -1)  | ||||
| 	DPRINTF(ERR_INFO,"Found image file %s (fd %d)\n",buffer,fd); | ||||
| 	DPRINTF(E_INF,L_ART,"Found image file %s (fd %d)\n",buffer,fd); | ||||
| 
 | ||||
|     return fd; | ||||
| } | ||||
| @ -137,7 +137,7 @@ int da_attach_image(int img_fd, int out_fd, int mp3_fd, int offset) | ||||
|     fstat(img_fd,&sb); | ||||
|     img_size=sb.st_size; | ||||
| 
 | ||||
|     DPRINTF(ERR_INFO,"Image appears to be %ld bytes\n",img_size); | ||||
|     DPRINTF(E_INF,L_ART,"Image appears to be %ld bytes\n",img_size); | ||||
|     if(img_size < 1) { | ||||
| 	r_close(img_fd); | ||||
| 	return 0; | ||||
| @ -152,7 +152,7 @@ int da_attach_image(int img_fd, int out_fd, int mp3_fd, int offset) | ||||
|     tag_info = da_get_current_tag_info(mp3_fd); | ||||
|     tag_size = tag_info[1]; | ||||
| 
 | ||||
|     DPRINTF(ERR_INFO,"Current tag size is %d bytes\n",tag_size); | ||||
|     DPRINTF(E_INF,L_ART,"Current tag size is %d bytes\n",tag_size); | ||||
| 
 | ||||
|     if (tag_info[0] == 3) { | ||||
| 	r_write(out_fd,"ID3\x03\0\0",6); | ||||
| @ -187,7 +187,7 @@ int da_attach_image(int img_fd, int out_fd, int mp3_fd, int offset) | ||||
|     } | ||||
|     lseek(img_fd,0,SEEK_SET); | ||||
|     copyfile(img_fd,out_fd); | ||||
|     DPRINTF(ERR_INFO,"Done copying IMG %ld\n",img_size); | ||||
|     DPRINTF(E_INF,L_ART,"Done copying IMG %ld\n",img_size); | ||||
|     r_close(img_fd); | ||||
|     free(tag_info); | ||||
|     return 0; | ||||
| @ -202,63 +202,63 @@ int da_attach_image(int img_fd, int out_fd, int mp3_fd, int offset) | ||||
| off_t da_aac_rewrite_stco_atom(off_t extra_size, int out_fd, FILE *aac_fp, | ||||
|                                off_t last_pos) | ||||
| { | ||||
|   int           aac_fd; | ||||
|   struct stat   sb; | ||||
|   unsigned char buffer[4]; | ||||
|   off_t         file_size; | ||||
|   int           atom_offset; | ||||
|   int           atom_length; | ||||
|   off_t         cur_pos; | ||||
|   off_t         old_pos; | ||||
|   int           i; | ||||
|   unsigned int  num_entries; | ||||
|   unsigned int  offset_entry; | ||||
|     int           aac_fd; | ||||
|     struct stat   sb; | ||||
|     unsigned char buffer[4]; | ||||
|     off_t         file_size; | ||||
|     int           atom_offset; | ||||
|     int           atom_length; | ||||
|     off_t         cur_pos; | ||||
|     off_t         old_pos; | ||||
|     int           i; | ||||
|     unsigned int  num_entries; | ||||
|     unsigned int  offset_entry; | ||||
| 
 | ||||
|   aac_fd = fileno(aac_fp); | ||||
|     aac_fd = fileno(aac_fp); | ||||
| 
 | ||||
|   fstat(aac_fd, &sb); | ||||
|   file_size = sb.st_size; | ||||
|     fstat(aac_fd, &sb); | ||||
|     file_size = sb.st_size; | ||||
| 
 | ||||
|   /* Drill down to the 'stco' atom which contains offsets to chunks in
 | ||||
|      the 'mdat' section. These offsets need to be readjusted. */ | ||||
|   atom_offset = aac_drilltoatom(aac_fp, "moov:trak:mdia:minf:stbl:stco", | ||||
|                                 &atom_length); | ||||
|   if (atom_offset != -1) { | ||||
|     /* Skip flags */ | ||||
|     fseek(aac_fp, 4, SEEK_CUR); | ||||
|     /* Drill down to the 'stco' atom which contains offsets to chunks in
 | ||||
|        the 'mdat' section. These offsets need to be readjusted. */ | ||||
|     atom_offset = aac_drilltoatom(aac_fp, "moov:trak:mdia:minf:stbl:stco", | ||||
| 				  &atom_length); | ||||
|     if (atom_offset != -1) { | ||||
| 	/* Skip flags */ | ||||
| 	fseek(aac_fp, 4, SEEK_CUR); | ||||
| 
 | ||||
|     old_pos = last_pos; | ||||
|     cur_pos = ftell(aac_fp); | ||||
| 	old_pos = last_pos; | ||||
| 	cur_pos = ftell(aac_fp); | ||||
| 
 | ||||
|     /* Copy from last point to this point. */ | ||||
|     fseek(aac_fp, old_pos, SEEK_SET); | ||||
|     fcopyblock(aac_fp, out_fd, cur_pos - old_pos); | ||||
| 	/* Copy from last point to this point. */ | ||||
| 	fseek(aac_fp, old_pos, SEEK_SET); | ||||
| 	fcopyblock(aac_fp, out_fd, cur_pos - old_pos); | ||||
| 
 | ||||
|     /* Read number of entries */ | ||||
|     fread(buffer, 1, 4, aac_fp); | ||||
|     r_write(out_fd, buffer, 4); | ||||
| 	/* Read number of entries */ | ||||
| 	fread(buffer, 1, 4, aac_fp); | ||||
| 	r_write(out_fd, buffer, 4); | ||||
| 
 | ||||
|     num_entries = (buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8) | buffer[3]; | ||||
| 	num_entries = (buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8) | buffer[3]; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG, "Readjusting %d 'stco' table offsets.\n", num_entries); | ||||
|     /* PENDING: Error check on num_entries? */ | ||||
|     for (i = 0; i < num_entries; i++) { | ||||
|         fread(buffer, 1, 4, aac_fp); | ||||
|         offset_entry = (buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8) | buffer[3]; | ||||
|         /* Adjust chunk offset. */ | ||||
|         offset_entry += extra_size; | ||||
|         buffer[3] = offset_entry & 0xFF; | ||||
|         buffer[2] = (offset_entry >> 8) & 0xFF; | ||||
|         buffer[1] = (offset_entry >> 16) & 0xFF; | ||||
|         buffer[0] = (offset_entry >> 24) & 0xFF; | ||||
|         r_write(out_fd, buffer, 4); | ||||
|         offset_entry = 0; | ||||
| 	DPRINTF(E_DBG, L_ART,"Readjusting %d 'stco' table offsets.\n", num_entries); | ||||
| 	/* PENDING: Error check on num_entries? */ | ||||
| 	for (i = 0; i < num_entries; i++) { | ||||
| 	    fread(buffer, 1, 4, aac_fp); | ||||
| 	    offset_entry = (buffer[0] << 24) | (buffer[1] << 16) | (buffer[2] << 8) | buffer[3]; | ||||
| 	    /* Adjust chunk offset. */ | ||||
| 	    offset_entry += extra_size; | ||||
| 	    buffer[3] = offset_entry & 0xFF; | ||||
| 	    buffer[2] = (offset_entry >> 8) & 0xFF; | ||||
| 	    buffer[1] = (offset_entry >> 16) & 0xFF; | ||||
| 	    buffer[0] = (offset_entry >> 24) & 0xFF; | ||||
| 	    r_write(out_fd, buffer, 4); | ||||
| 	    offset_entry = 0; | ||||
| 	} | ||||
| 	return ftell(aac_fp); | ||||
|     } else { | ||||
| 	DPRINTF(E_LOG, L_ART,"No 'stco' atom found.\n"); | ||||
|     } | ||||
|     return ftell(aac_fp); | ||||
|   } else { | ||||
|       DPRINTF(ERR_LOG, "No 'stco' atom found.\n"); | ||||
|   } | ||||
|   return last_pos; | ||||
|     return last_pos; | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
| @ -268,159 +268,159 @@ off_t da_aac_rewrite_stco_atom(off_t extra_size, int out_fd, FILE *aac_fp, | ||||
| off_t da_aac_insert_covr_atom(off_t extra_size, int out_fd, FILE *aac_fp, | ||||
|                               off_t last_pos, off_t file_size, int img_fd) | ||||
| { | ||||
|   int           aac_fd; | ||||
|   struct stat   sb; | ||||
|   off_t         old_pos; | ||||
|   unsigned char buffer[4]; | ||||
|   int           atom_offset; | ||||
|   int           atom_length; | ||||
|   off_t         cur_pos; | ||||
|   char          *cp; | ||||
|   unsigned char img_type_flag = 0; | ||||
|     int           aac_fd; | ||||
|     struct stat   sb; | ||||
|     off_t         old_pos; | ||||
|     unsigned char buffer[4]; | ||||
|     int           atom_offset; | ||||
|     int           atom_length; | ||||
|     off_t         cur_pos; | ||||
|     char          *cp; | ||||
|     unsigned char img_type_flag = 0; | ||||
| 
 | ||||
|   /* Figure out image file type since this needs to be encoded in the atom. */ | ||||
|   cp = strrchr(config.artfilename, '.'); | ||||
|   if (cp) { | ||||
|     if (!strcasecmp(cp, ".jpeg") || !strcasecmp(cp, ".jpg")) { | ||||
|       img_type_flag = 0x0d; | ||||
|     } | ||||
|     else if (!strcasecmp(cp, ".png")) { | ||||
|       img_type_flag = 0x0e; | ||||
|     /* Figure out image file type since this needs to be encoded in the atom. */ | ||||
|     cp = strrchr(config.artfilename, '.'); | ||||
|     if (cp) { | ||||
| 	if (!strcasecmp(cp, ".jpeg") || !strcasecmp(cp, ".jpg")) { | ||||
| 	    img_type_flag = 0x0d; | ||||
| 	} | ||||
| 	else if (!strcasecmp(cp, ".png")) { | ||||
| 	    img_type_flag = 0x0e; | ||||
| 	} else { | ||||
| 	    DPRINTF(E_LOG,L_ART, "Image type '%s' not supported.\n", cp); | ||||
| 	    return 0; | ||||
| 	} | ||||
|     } else { | ||||
|       DPRINTF(ERR_LOG, "Image type '%s' not supported.\n", cp); | ||||
|       return 0; | ||||
| 	DPRINTF(E_LOG, L_ART, "No file extension for image file.\n"); | ||||
|     } | ||||
|   } else { | ||||
|     DPRINTF(ERR_LOG, "No file extension for image file.\n"); | ||||
|   } | ||||
| 
 | ||||
|   aac_fd = fileno(aac_fp); | ||||
|   fstat(aac_fd, &sb); | ||||
|   file_size = sb.st_size; | ||||
|   rewind(aac_fp); | ||||
|     aac_fd = fileno(aac_fp); | ||||
|     fstat(aac_fd, &sb); | ||||
|     file_size = sb.st_size; | ||||
|     rewind(aac_fp); | ||||
| 
 | ||||
|   atom_offset = scan_aac_findatom(aac_fp, file_size, "moov", &atom_length); | ||||
|   if (atom_offset != -1) { | ||||
|     atom_offset = scan_aac_findatom(aac_fp, atom_length - 8, "udta", &atom_length); | ||||
|     atom_offset = scan_aac_findatom(aac_fp, file_size, "moov", &atom_length); | ||||
|     if (atom_offset != -1) { | ||||
|       old_pos = last_pos; | ||||
|       cur_pos = ftell(aac_fp) - 8; | ||||
|       DPRINTF(ERR_INFO,"Found udta atom at %ld.\n", cur_pos); | ||||
|       fseek(aac_fp, old_pos, SEEK_SET); | ||||
|       fcopyblock(aac_fp, out_fd, cur_pos - old_pos); | ||||
| 	atom_offset = scan_aac_findatom(aac_fp, atom_length - 8, "udta", &atom_length); | ||||
| 	if (atom_offset != -1) { | ||||
| 	    old_pos = last_pos; | ||||
| 	    cur_pos = ftell(aac_fp) - 8; | ||||
| 	    DPRINTF(E_INF,L_ART,"Found udta atom at %ld.\n", cur_pos); | ||||
| 	    fseek(aac_fp, old_pos, SEEK_SET); | ||||
| 	    fcopyblock(aac_fp, out_fd, cur_pos - old_pos); | ||||
| 
 | ||||
|       /* Write out new length */ | ||||
|       atom_length += extra_size; | ||||
|       buffer[3] = atom_length & 0xFF; | ||||
|       buffer[2] = ( atom_length >> 8 ) & 0xFF; | ||||
|       buffer[1] = ( atom_length >> 16 ) & 0xFF; | ||||
|       buffer[0] = ( atom_length >> 24 ) & 0xFF; | ||||
|       r_write(out_fd, buffer, 4); | ||||
| 	    /* Write out new length */ | ||||
| 	    atom_length += extra_size; | ||||
| 	    buffer[3] = atom_length & 0xFF; | ||||
| 	    buffer[2] = ( atom_length >> 8 ) & 0xFF; | ||||
| 	    buffer[1] = ( atom_length >> 16 ) & 0xFF; | ||||
| 	    buffer[0] = ( atom_length >> 24 ) & 0xFF; | ||||
| 	    r_write(out_fd, buffer, 4); | ||||
| 
 | ||||
|       cur_pos += 4; | ||||
|       fseek(aac_fp, 8, SEEK_CUR); | ||||
| 	    cur_pos += 4; | ||||
| 	    fseek(aac_fp, 8, SEEK_CUR); | ||||
| 
 | ||||
|       atom_offset = scan_aac_findatom(aac_fp, atom_length - 8, "meta", &atom_length); | ||||
|       if (atom_offset != -1) { | ||||
|         old_pos = cur_pos; | ||||
|         cur_pos = ftell(aac_fp) - 8; | ||||
|         DPRINTF(ERR_INFO,"Found meta atom at %ld.\n", cur_pos); | ||||
|         fseek(aac_fp, old_pos, SEEK_SET); | ||||
|         fcopyblock(aac_fp, out_fd, cur_pos - old_pos); | ||||
| 	    atom_offset = scan_aac_findatom(aac_fp, atom_length - 8, "meta", &atom_length); | ||||
| 	    if (atom_offset != -1) { | ||||
| 		old_pos = cur_pos; | ||||
| 		cur_pos = ftell(aac_fp) - 8; | ||||
| 		DPRINTF(E_INF,L_ART,"Found meta atom at %ld.\n", cur_pos); | ||||
| 		fseek(aac_fp, old_pos, SEEK_SET); | ||||
| 		fcopyblock(aac_fp, out_fd, cur_pos - old_pos); | ||||
| 
 | ||||
|         /* Write out new length */ | ||||
|         atom_length += extra_size; | ||||
|         buffer[3] = atom_length & 0xFF; | ||||
|         buffer[2] = ( atom_length >> 8 ) & 0xFF; | ||||
|         buffer[1] = ( atom_length >> 16 ) & 0xFF; | ||||
|         buffer[0] = ( atom_length >> 24 ) & 0xFF; | ||||
|         r_write(out_fd, buffer, 4); | ||||
| 		/* Write out new length */ | ||||
| 		atom_length += extra_size; | ||||
| 		buffer[3] = atom_length & 0xFF; | ||||
| 		buffer[2] = ( atom_length >> 8 ) & 0xFF; | ||||
| 		buffer[1] = ( atom_length >> 16 ) & 0xFF; | ||||
| 		buffer[0] = ( atom_length >> 24 ) & 0xFF; | ||||
| 		r_write(out_fd, buffer, 4); | ||||
| 
 | ||||
|         cur_pos += 4; | ||||
|         fseek(aac_fp, 12, SEEK_CUR); /* "meta" atom hack. */ | ||||
| 		cur_pos += 4; | ||||
| 		fseek(aac_fp, 12, SEEK_CUR); /* "meta" atom hack. */ | ||||
| 
 | ||||
|         atom_offset = scan_aac_findatom(aac_fp, atom_length - 8, "ilst", &atom_length); | ||||
|         if (atom_offset != -1) { | ||||
|           old_pos = cur_pos; | ||||
|           cur_pos = ftell(aac_fp) - 8; | ||||
|           DPRINTF(ERR_INFO,"Found ilst atom at %ld.\n", cur_pos); | ||||
|           fseek(aac_fp, old_pos, SEEK_SET); | ||||
|           fcopyblock(aac_fp, out_fd, cur_pos - old_pos); | ||||
| 		atom_offset = scan_aac_findatom(aac_fp, atom_length - 8, "ilst", &atom_length); | ||||
| 		if (atom_offset != -1) { | ||||
| 		    old_pos = cur_pos; | ||||
| 		    cur_pos = ftell(aac_fp) - 8; | ||||
| 		    DPRINTF(E_INF,L_ART,"Found ilst atom at %ld.\n", cur_pos); | ||||
| 		    fseek(aac_fp, old_pos, SEEK_SET); | ||||
| 		    fcopyblock(aac_fp, out_fd, cur_pos - old_pos); | ||||
| 
 | ||||
|           old_pos = cur_pos + 4; | ||||
|           cur_pos += atom_length; | ||||
| 		    old_pos = cur_pos + 4; | ||||
| 		    cur_pos += atom_length; | ||||
| 
 | ||||
|           /* Write out new length */ | ||||
|           atom_length += extra_size; | ||||
|           buffer[3] = atom_length & 0xFF; | ||||
|           buffer[2] = ( atom_length >> 8 ) & 0xFF; | ||||
|           buffer[1] = ( atom_length >> 16 ) & 0xFF; | ||||
|           buffer[0] = ( atom_length >> 24 ) & 0xFF; | ||||
|           r_write(out_fd, buffer, 4); | ||||
| 		    /* Write out new length */ | ||||
| 		    atom_length += extra_size; | ||||
| 		    buffer[3] = atom_length & 0xFF; | ||||
| 		    buffer[2] = ( atom_length >> 8 ) & 0xFF; | ||||
| 		    buffer[1] = ( atom_length >> 16 ) & 0xFF; | ||||
| 		    buffer[0] = ( atom_length >> 24 ) & 0xFF; | ||||
| 		    r_write(out_fd, buffer, 4); | ||||
| 
 | ||||
|           /* Copy all 'ilst' children (all the MP4 'tags'). We will append
 | ||||
|              at the end. */ | ||||
|           fseek(aac_fp, old_pos, SEEK_SET); | ||||
|           fcopyblock(aac_fp, out_fd, cur_pos - old_pos); | ||||
|           cur_pos = ftell(aac_fp); | ||||
| 		    /* Copy all 'ilst' children (all the MP4 'tags'). We will append
 | ||||
| 		       at the end. */ | ||||
| 		    fseek(aac_fp, old_pos, SEEK_SET); | ||||
| 		    fcopyblock(aac_fp, out_fd, cur_pos - old_pos); | ||||
| 		    cur_pos = ftell(aac_fp); | ||||
| 
 | ||||
|           /* Write out 'covr' atom */ | ||||
|           atom_length = extra_size; | ||||
|           buffer[3] = atom_length & 0xFF; | ||||
|           buffer[2] = ( atom_length >> 8 ) & 0xFF; | ||||
|           buffer[1] = ( atom_length >> 16 ) & 0xFF; | ||||
|           buffer[0] = ( atom_length >> 24 ) & 0xFF; | ||||
|           r_write(out_fd, buffer, 4); | ||||
| 		    /* Write out 'covr' atom */ | ||||
| 		    atom_length = extra_size; | ||||
| 		    buffer[3] = atom_length & 0xFF; | ||||
| 		    buffer[2] = ( atom_length >> 8 ) & 0xFF; | ||||
| 		    buffer[1] = ( atom_length >> 16 ) & 0xFF; | ||||
| 		    buffer[0] = ( atom_length >> 24 ) & 0xFF; | ||||
| 		    r_write(out_fd, buffer, 4); | ||||
|              | ||||
|           r_write(out_fd, "covr", 4); | ||||
| 		    r_write(out_fd, "covr", 4); | ||||
| 
 | ||||
|           /* Write out 'data' atom */ | ||||
|           atom_length = extra_size - 8; | ||||
|           buffer[3] = atom_length & 0xFF; | ||||
|           buffer[2] = ( atom_length >> 8 ) & 0xFF; | ||||
|           buffer[1] = ( atom_length >> 16 ) & 0xFF; | ||||
|           buffer[0] = ( atom_length >> 24 ) & 0xFF; | ||||
|           r_write(out_fd, buffer, 4); | ||||
| 		    /* Write out 'data' atom */ | ||||
| 		    atom_length = extra_size - 8; | ||||
| 		    buffer[3] = atom_length & 0xFF; | ||||
| 		    buffer[2] = ( atom_length >> 8 ) & 0xFF; | ||||
| 		    buffer[1] = ( atom_length >> 16 ) & 0xFF; | ||||
| 		    buffer[0] = ( atom_length >> 24 ) & 0xFF; | ||||
| 		    r_write(out_fd, buffer, 4); | ||||
| 
 | ||||
|           r_write(out_fd, "data", 4); | ||||
| 		    r_write(out_fd, "data", 4); | ||||
| 
 | ||||
|           /* Write out 'data' flags */ | ||||
|           buffer[3] = img_type_flag; | ||||
|           buffer[2] = 0; | ||||
|           buffer[1] = 0; | ||||
|           buffer[0] = 0; | ||||
|           r_write(out_fd, buffer, 4); | ||||
| 		    /* Write out 'data' flags */ | ||||
| 		    buffer[3] = img_type_flag; | ||||
| 		    buffer[2] = 0; | ||||
| 		    buffer[1] = 0; | ||||
| 		    buffer[0] = 0; | ||||
| 		    r_write(out_fd, buffer, 4); | ||||
| 
 | ||||
|           /* Reserved? Zero in any case. */ | ||||
|           buffer[3] = 0; | ||||
|           buffer[2] = 0; | ||||
|           buffer[1] = 0; | ||||
|           buffer[0] = 0; | ||||
| 		    /* Reserved? Zero in any case. */ | ||||
| 		    buffer[3] = 0; | ||||
| 		    buffer[2] = 0; | ||||
| 		    buffer[1] = 0; | ||||
| 		    buffer[0] = 0; | ||||
| 
 | ||||
|           r_write(out_fd, buffer, 4); | ||||
| 		    r_write(out_fd, buffer, 4); | ||||
| 
 | ||||
|           /* Now ready for the image stream. Copy it over. */ | ||||
|           lseek(img_fd,0,SEEK_SET); | ||||
|           copyfile(img_fd,out_fd); | ||||
|           last_pos = cur_pos; | ||||
|         } else { | ||||
|           DPRINTF(ERR_LOG, "No 'ilst' atom found.\n"); | ||||
|         } | ||||
|      } else { | ||||
|         DPRINTF(ERR_LOG, "No 'meta' atom found.\n"); | ||||
|      } | ||||
| 		    /* Now ready for the image stream. Copy it over. */ | ||||
| 		    lseek(img_fd,0,SEEK_SET); | ||||
| 		    copyfile(img_fd,out_fd); | ||||
| 		    last_pos = cur_pos; | ||||
| 		} else { | ||||
| 		    DPRINTF(E_LOG, L_ART,"No 'ilst' atom found.\n"); | ||||
| 		} | ||||
| 	    } else { | ||||
| 		DPRINTF(E_LOG,L_ART, "No 'meta' atom found.\n"); | ||||
| 	    } | ||||
| 	} else { | ||||
| 	    DPRINTF(E_LOG,L_ART, "No 'udta' atom found.\n"); | ||||
| 	} | ||||
|     } else { | ||||
|       DPRINTF(ERR_LOG, "No 'udta' atom found.\n"); | ||||
| 	DPRINTF(E_LOG,L_ART, "No 'moov' atom found.\n"); | ||||
|     } | ||||
|   } else { | ||||
|     DPRINTF(ERR_LOG, "No 'moov' atom found.\n"); | ||||
|   } | ||||
| 
 | ||||
|   /* Seek to position right after 'udta' atom. Let main() stream out the
 | ||||
|      rest. */ | ||||
|   lseek(aac_fd, last_pos, SEEK_SET); | ||||
|     /* Seek to position right after 'udta' atom. Let main() stream out the
 | ||||
|        rest. */ | ||||
|     lseek(aac_fd, last_pos, SEEK_SET); | ||||
| 
 | ||||
|   return last_pos; | ||||
|     return last_pos; | ||||
| } | ||||
| 
 | ||||
| /*
 | ||||
| @ -433,147 +433,147 @@ off_t da_aac_insert_covr_atom(off_t extra_size, int out_fd, FILE *aac_fp, | ||||
|  */ | ||||
| off_t da_aac_attach_image(int img_fd, int out_fd, int aac_fd, int offset) | ||||
| { | ||||
|   off_t         img_size; | ||||
|   int           atom_length; | ||||
|   unsigned int  extra_size; | ||||
|   off_t         file_size; | ||||
|   unsigned char buffer[4]; | ||||
|   struct stat   sb; | ||||
|   FILE          *aac_fp; | ||||
|   off_t         stco_atom_pos; | ||||
|   off_t         ilst_atom_pos; | ||||
|   off_t         last_pos; | ||||
|     off_t         img_size; | ||||
|     int           atom_length; | ||||
|     unsigned int  extra_size; | ||||
|     off_t         file_size; | ||||
|     unsigned char buffer[4]; | ||||
|     struct stat   sb; | ||||
|     FILE          *aac_fp; | ||||
|     off_t         stco_atom_pos; | ||||
|     off_t         ilst_atom_pos; | ||||
|     off_t         last_pos; | ||||
| 
 | ||||
|   fstat(img_fd, &sb); | ||||
|   img_size = sb.st_size; | ||||
|     fstat(img_fd, &sb); | ||||
|     img_size = sb.st_size; | ||||
| 
 | ||||
|   DPRINTF(ERR_INFO,"Image size (in bytes): %ld.\n", img_size); | ||||
|     DPRINTF(E_INF,L_ART,"Image size (in bytes): %ld.\n", img_size); | ||||
| 
 | ||||
|   /* PENDING: We can be stricter here by checking the shortest header between
 | ||||
|      PNG and JPG and using that length. */ | ||||
|   if (img_size < 1) { | ||||
|     r_close(img_fd); | ||||
|     return 0; | ||||
|   } | ||||
| 
 | ||||
|   /* Include extra bytes for 'covr' atom length (4) and type (4) and its
 | ||||
|      'data' item length (4) and type (4) plus 4 bytes for the 'data' atom's | ||||
|      flags and 4 reserved(?) bytes. */ | ||||
|   extra_size = img_size + 24; | ||||
| 
 | ||||
|   fstat(aac_fd, &sb); | ||||
|   file_size = sb.st_size; | ||||
| 
 | ||||
|   aac_fp = fdopen(dup(aac_fd), "r"); | ||||
| 
 | ||||
|   stco_atom_pos = aac_drilltoatom(aac_fp, "moov:trak:mdia:minf:stbl:stco", | ||||
|                                   &atom_length); | ||||
|   ilst_atom_pos = aac_drilltoatom(aac_fp, "moov:udta:meta:ilst", | ||||
|                                   &atom_length); | ||||
|   last_pos = aac_drilltoatom(aac_fp, "mdat", &atom_length); | ||||
| 
 | ||||
|   if (last_pos != -1) { | ||||
|     if (offset >= last_pos) { | ||||
|       /* Offset is in the actual music data so don't bother processing 
 | ||||
|          meta data. */ | ||||
|       return 0; | ||||
|     /* PENDING: We can be stricter here by checking the shortest header between
 | ||||
|        PNG and JPG and using that length. */ | ||||
|     if (img_size < 1) { | ||||
| 	r_close(img_fd); | ||||
| 	return 0; | ||||
|     } | ||||
|   } else { | ||||
|     DPRINTF(ERR_LOG, "No 'mdat' atom.\n"); | ||||
|     return 0; | ||||
|   } | ||||
| 
 | ||||
|   rewind(aac_fp); | ||||
|     /* Include extra bytes for 'covr' atom length (4) and type (4) and its
 | ||||
|        'data' item length (4) and type (4) plus 4 bytes for the 'data' atom's | ||||
|        flags and 4 reserved(?) bytes. */ | ||||
|     extra_size = img_size + 24; | ||||
| 
 | ||||
|     fstat(aac_fd, &sb); | ||||
|     file_size = sb.st_size; | ||||
| 
 | ||||
|     aac_fp = fdopen(dup(aac_fd), "r"); | ||||
| 
 | ||||
|     stco_atom_pos = aac_drilltoatom(aac_fp, "moov:trak:mdia:minf:stbl:stco", | ||||
| 				    &atom_length); | ||||
|     ilst_atom_pos = aac_drilltoatom(aac_fp, "moov:udta:meta:ilst", | ||||
| 				    &atom_length); | ||||
|     last_pos = aac_drilltoatom(aac_fp, "mdat", &atom_length); | ||||
| 
 | ||||
|     if (last_pos != -1) { | ||||
| 	if (offset >= last_pos) { | ||||
| 	    /* Offset is in the actual music data so don't bother processing 
 | ||||
| 	       meta data. */ | ||||
| 	    return 0; | ||||
| 	} | ||||
|     } else { | ||||
| 	DPRINTF(E_LOG,L_ART, "No 'mdat' atom.\n"); | ||||
| 	return 0; | ||||
|     } | ||||
| 
 | ||||
|   /* Re-adjust length of 'moov' atom. */ | ||||
|   last_pos = scan_aac_findatom(aac_fp, file_size, "moov", &atom_length); | ||||
|   if (last_pos != -1) { | ||||
|     /* Copy everything from up to this atom */ | ||||
|     rewind(aac_fp); | ||||
|     fcopyblock(aac_fp, out_fd, last_pos); | ||||
| 
 | ||||
|     /* Write out new length. */ | ||||
|     atom_length += extra_size; | ||||
|     buffer[3] = atom_length & 0xFF; | ||||
|     buffer[2] = ( atom_length >> 8 ) & 0xFF; | ||||
|     buffer[1] = ( atom_length >> 16 ) & 0xFF; | ||||
|     buffer[0] = ( atom_length >> 24 ) & 0xFF; | ||||
|     r_write(out_fd, buffer, 4); | ||||
|     /* Re-adjust length of 'moov' atom. */ | ||||
|     last_pos = scan_aac_findatom(aac_fp, file_size, "moov", &atom_length); | ||||
|     if (last_pos != -1) { | ||||
| 	/* Copy everything from up to this atom */ | ||||
| 	rewind(aac_fp); | ||||
| 	fcopyblock(aac_fp, out_fd, last_pos); | ||||
| 
 | ||||
|     last_pos += 4; | ||||
|   } else { | ||||
|     DPRINTF(ERR_LOG, "Could not find 'moov' atom.\n"); | ||||
|     return 0; | ||||
|   } | ||||
| 	/* Write out new length. */ | ||||
| 	atom_length += extra_size; | ||||
| 	buffer[3] = atom_length & 0xFF; | ||||
| 	buffer[2] = ( atom_length >> 8 ) & 0xFF; | ||||
| 	buffer[1] = ( atom_length >> 16 ) & 0xFF; | ||||
| 	buffer[0] = ( atom_length >> 24 ) & 0xFF; | ||||
| 	r_write(out_fd, buffer, 4); | ||||
| 
 | ||||
|   if (stco_atom_pos < ilst_atom_pos) { | ||||
|     last_pos = da_aac_rewrite_stco_atom(extra_size, out_fd, aac_fp, last_pos); | ||||
|     last_pos = da_aac_insert_covr_atom(extra_size, out_fd, aac_fp, last_pos, | ||||
|                                        file_size, img_fd); | ||||
|   } else { | ||||
|     last_pos = da_aac_insert_covr_atom(extra_size, out_fd, aac_fp, last_pos, | ||||
|                                        file_size, img_fd); | ||||
|     last_pos = da_aac_rewrite_stco_atom(extra_size, out_fd, aac_fp, last_pos); | ||||
|   } | ||||
| 	last_pos += 4; | ||||
|     } else { | ||||
| 	DPRINTF(E_LOG,L_ART, "Could not find 'moov' atom.\n"); | ||||
| 	return 0; | ||||
|     } | ||||
| 
 | ||||
|   /* Seek to position right after last atom. Let main() stream out the rest. */ | ||||
|   lseek(aac_fd, last_pos, SEEK_SET); | ||||
|     if (stco_atom_pos < ilst_atom_pos) { | ||||
| 	last_pos = da_aac_rewrite_stco_atom(extra_size, out_fd, aac_fp, last_pos); | ||||
| 	last_pos = da_aac_insert_covr_atom(extra_size, out_fd, aac_fp, last_pos, | ||||
| 					   file_size, img_fd); | ||||
|     } else { | ||||
| 	last_pos = da_aac_insert_covr_atom(extra_size, out_fd, aac_fp, last_pos, | ||||
| 					   file_size, img_fd); | ||||
| 	last_pos = da_aac_rewrite_stco_atom(extra_size, out_fd, aac_fp, last_pos); | ||||
|     } | ||||
| 
 | ||||
|   r_close(img_fd); | ||||
|   fclose(aac_fp); | ||||
|     /* Seek to position right after last atom. Let main() stream out the rest. */ | ||||
|     lseek(aac_fd, last_pos, SEEK_SET); | ||||
| 
 | ||||
|   return last_pos; | ||||
|     r_close(img_fd); | ||||
|     fclose(aac_fp); | ||||
| 
 | ||||
|     return last_pos; | ||||
| } | ||||
| 
 | ||||
| int copyblock(int fromfd, int tofd, size_t size) { | ||||
|   char buf[BLKSIZE]; | ||||
|   int  bytesread; | ||||
|   int  totalbytes = 0; | ||||
|   int  blocksize = BLKSIZE; | ||||
|   int  bytesleft; | ||||
|     char buf[BLKSIZE]; | ||||
|     int  bytesread; | ||||
|     int  totalbytes = 0; | ||||
|     int  blocksize = BLKSIZE; | ||||
|     int  bytesleft; | ||||
| 
 | ||||
|   while (totalbytes < size) { | ||||
|     bytesleft = size - totalbytes; | ||||
|     if (bytesleft < BLKSIZE) { | ||||
|       blocksize = bytesleft; | ||||
|     } else { | ||||
|       blocksize = BLKSIZE; | ||||
|     while (totalbytes < size) { | ||||
| 	bytesleft = size - totalbytes; | ||||
| 	if (bytesleft < BLKSIZE) { | ||||
| 	    blocksize = bytesleft; | ||||
| 	} else { | ||||
| 	    blocksize = BLKSIZE; | ||||
| 	} | ||||
| 	if ((bytesread = r_read(fromfd, buf, blocksize)) < 0) | ||||
| 	    return -1; | ||||
| 	if (bytesread == 0) | ||||
| 	    return totalbytes; | ||||
| 	if (r_write(tofd, buf, bytesread) < 0) | ||||
| 	    return -1; | ||||
| 	totalbytes += bytesread; | ||||
|     } | ||||
|     if ((bytesread = r_read(fromfd, buf, blocksize)) < 0) | ||||
|       return -1; | ||||
|     if (bytesread == 0) | ||||
|       return totalbytes; | ||||
|     if (r_write(tofd, buf, bytesread) < 0) | ||||
|       return -1; | ||||
|     totalbytes += bytesread; | ||||
|   } | ||||
|   return totalbytes; | ||||
|     return totalbytes; | ||||
| } | ||||
| 
 | ||||
| int fcopyblock(FILE *fromfp, int tofd, size_t size) { | ||||
|   char buf[BLKSIZE]; | ||||
|   int  bytesread; | ||||
|   int  totalbytes = 0; | ||||
|   int  blocksize = BLKSIZE; | ||||
|   int  bytesleft; | ||||
|     char buf[BLKSIZE]; | ||||
|     int  bytesread; | ||||
|     int  totalbytes = 0; | ||||
|     int  blocksize = BLKSIZE; | ||||
|     int  bytesleft; | ||||
| 
 | ||||
|   while (totalbytes < size) { | ||||
|     bytesleft = size - totalbytes; | ||||
|     if (bytesleft < BLKSIZE) { | ||||
|       blocksize = bytesleft; | ||||
|     } else { | ||||
|       blocksize = BLKSIZE; | ||||
|     } | ||||
|     if ((bytesread = fread(buf, 1, blocksize, fromfp)) < blocksize) { | ||||
|       if (ferror(fromfp)) | ||||
|         return -1; | ||||
|     } | ||||
|     if (r_write(tofd, buf, bytesread) < 0) | ||||
|       return -1; | ||||
|     while (totalbytes < size) { | ||||
| 	bytesleft = size - totalbytes; | ||||
| 	if (bytesleft < BLKSIZE) { | ||||
| 	    blocksize = bytesleft; | ||||
| 	} else { | ||||
| 	    blocksize = BLKSIZE; | ||||
| 	} | ||||
| 	if ((bytesread = fread(buf, 1, blocksize, fromfp)) < blocksize) { | ||||
| 	    if (ferror(fromfp)) | ||||
| 		return -1; | ||||
| 	} | ||||
| 	if (r_write(tofd, buf, bytesread) < 0) | ||||
| 	    return -1; | ||||
| 
 | ||||
|     if (feof(fromfp)) | ||||
|       return 0; | ||||
|     totalbytes += bytesread; | ||||
|   } | ||||
|   return totalbytes; | ||||
| 	if (feof(fromfp)) | ||||
| 	    return 0; | ||||
| 	totalbytes += bytesread; | ||||
|     } | ||||
|     return totalbytes; | ||||
| } | ||||
|  | ||||
							
								
								
									
										31
									
								
								src/err.c
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								src/err.c
									
									
									
									
									
								
							| @ -54,12 +54,12 @@ int err_debuglevel=0; /**< current debuglevel, set from command line with -d */ | ||||
| static int err_logdestination=LOGDEST_STDERR; /**< current log destination */ | ||||
| static FILE *err_file=NULL; /**< if logging to file, the handle of that file */ | ||||
| static pthread_mutex_t err_mutex=PTHREAD_MUTEX_INITIALIZER; /**< for serializing log messages */ | ||||
| 
 | ||||
| static unsigned int err_debugmask=0xFFFF; /**< what modules to debug, see \ref log_categories */ | ||||
| #ifdef DEBUG_MEMORY | ||||
| 
 | ||||
| /**
 | ||||
|  * Nodes for a linked list of in-use memory.  Any malloc/strdup/etc | ||||
|  * calls get a new node of this type added to the ::err_leak list. | ||||
|  * calls get a new node of this type added to the #err_leak list. | ||||
|  */ | ||||
| typedef struct tag_err_leak { | ||||
|     void *ptr; | ||||
| @ -89,7 +89,7 @@ static int err_unlock_mutex(void); | ||||
|  * \param level Level at which to log \ref log_levels | ||||
|  * \param fmt printf-style  | ||||
|  */ | ||||
| void log_err(int level, char *fmt, ...) | ||||
| void log_err(int level, unsigned int cat, char *fmt, ...) | ||||
| { | ||||
|     va_list ap; | ||||
|     char timebuf[256]; | ||||
| @ -97,8 +97,13 @@ void log_err(int level, char *fmt, ...) | ||||
|     struct tm tm_now; | ||||
|     time_t tt_now; | ||||
| 
 | ||||
|     if(level > err_debuglevel) | ||||
| 	return; | ||||
|     if(level) { | ||||
| 	if(level > err_debuglevel) | ||||
| 	    return; | ||||
| 
 | ||||
| 	if(!(cat && err_debugmask)) | ||||
| 	    return; | ||||
|     } /* we'll *always* process a log level 0 */ | ||||
| 
 | ||||
|     va_start(ap, fmt); | ||||
|     vsnprintf(errbuf, sizeof(errbuf), fmt, ap); | ||||
| @ -222,10 +227,10 @@ void err_notify(char *file, int line, void *ptr) { | ||||
| 
 | ||||
|     pnew=(ERR_LEAK*)malloc(sizeof(ERR_LEAK)); | ||||
|     if(!pnew)  | ||||
| 	log_err(1,"Error: cannot allocate leak struct\n"); | ||||
| 	DPRINTF(E_FATAL,L_MISC,"Error: cannot allocate leak struct\n"); | ||||
| 
 | ||||
|     if(err_lock_mutex())  | ||||
| 	log_err(1,"Error: cannot lock error mutex\n"); | ||||
| 	DPRINTF(E_FATAL,L_MISC,"Error: cannot lock error mutex\n"); | ||||
| 	 | ||||
|     pnew->file=file; | ||||
|     pnew->line=line; | ||||
| @ -251,10 +256,10 @@ void *err_malloc(char *file, int line, size_t size) { | ||||
| 
 | ||||
|     pnew=(ERR_LEAK*)malloc(sizeof(ERR_LEAK)); | ||||
|     if(!pnew)  | ||||
| 	log_err(1,"Error: cannot allocate leak struct\n"); | ||||
| 	DPRINTF(E_FATAL,L_MISC,"Error: cannot allocate leak struct\n"); | ||||
| 
 | ||||
|     if(err_lock_mutex())  | ||||
| 	log_err(1,"Error: cannot lock error mutex\n"); | ||||
| 	DPRINTF(E_FATAL,L_MISC,"Error: cannot lock error mutex\n"); | ||||
| 	 | ||||
|     pnew->file=file; | ||||
|     pnew->line=line; | ||||
| @ -283,7 +288,7 @@ char *err_strdup(char *file, int line, const char *str) { | ||||
| 
 | ||||
|     pnew=err_malloc(file,line,strlen(str) + 1); | ||||
|     if(!pnew)  | ||||
| 	log_err(1,"Cannot malloc enough space for strdup\n"); | ||||
| 	DPRINTF(E_FATAL,L_MISC,"Cannot malloc enough space for strdup\n"); | ||||
| 
 | ||||
|     memcpy(pnew,str,strlen(str)+1); | ||||
|     return pnew; | ||||
| @ -301,7 +306,7 @@ void err_free(char *file, int line, void *ptr) { | ||||
|     ERR_LEAK *current,*last; | ||||
| 
 | ||||
|     if(err_lock_mutex())  | ||||
| 	log_err(1,"Error: cannot lock error mutex\n"); | ||||
|         DPRINTF(E_FATAL,L_MISC,"Error: cannot lock error mutex\n"); | ||||
| 
 | ||||
|     last=&err_leak; | ||||
|     current=last->next; | ||||
| @ -312,7 +317,7 @@ void err_free(char *file, int line, void *ptr) { | ||||
|     } | ||||
| 
 | ||||
|     if(!current) { | ||||
| 	log_err(1,"Attempt to free unallocated memory: %s, %d\n",file,line); | ||||
| 	DPRINTF(E_FATAL,L_MISC,"Attempt to free unallocated memory: %s, %d\n",file,line); | ||||
|     } else { | ||||
| 	free(current->ptr); | ||||
| 	last->next=current->next; | ||||
| @ -331,7 +336,7 @@ void err_leakcheck(void) { | ||||
|     ERR_LEAK *current; | ||||
| 
 | ||||
|     if(err_lock_mutex())  | ||||
| 	log_err(1,"Error: cannot lock error mutex\n"); | ||||
| 	DPRINTF(E_FATAL,L_MISC,"Error: cannot lock error mutex\n"); | ||||
| 
 | ||||
|     current=err_leak.next; | ||||
|     while(current) { | ||||
|  | ||||
							
								
								
									
										43
									
								
								src/err.h
									
									
									
									
									
								
							
							
						
						
									
										43
									
								
								src/err.h
									
									
									
									
									
								
							| @ -34,38 +34,43 @@ | ||||
| #define LOGDEST_LOGFILE      2  /**< Log to logfile */ | ||||
| 
 | ||||
| /** @anchor log_levels */ | ||||
| #define ERR_EXCESSIVE        10  /**< Logorrhea! */ | ||||
| #define ERR_DEBUG            9   /**< Way too verbose */ | ||||
| #define ERR_INFO             5   /**< Good info, not too much spam */ | ||||
| #define ERR_WARN             2   /**< Reasonably important, but not enough to log */ | ||||
| #define ERR_LOG              1   /**< Something that should go in a log file */ | ||||
| #define ERR_FATAL            0   /**< Log and force an exit */ | ||||
| #define E_SPAM         10   /**< Logorrhea! */ | ||||
| #define E_DBG           9   /**< Way too verbose */ | ||||
| #define E_INF           5   /**< Good info, not too much spam */ | ||||
| #define E_WARN          2   /**< Reasonably important, but not enough to log */ | ||||
| #define E_LOG           1   /**< Something that should go in a log file */ | ||||
| #define E_FATAL         0   /**< Log and force an exit */ | ||||
| 
 | ||||
| /** @anchor log_categories */ | ||||
| #define LOG_CONFIG           0x0001 /**< configfile.c */ | ||||
| #define LOG_WEBSERVER        0x0002 /**< webserver.c */ | ||||
| #define LOG_DATABASE         0x0004 /**< db-* */ | ||||
| #define LOG_SCAN             0x0008 /**< mp3-scanner.c */ | ||||
| #define LOG_QUERY            0x0010 /**< query.c */ | ||||
| #define LOG_INDEX            0x0020 /**< daap.c */ | ||||
| #define LOG_BROWSE           0x0040 /**< daap.c, query.c */ | ||||
| #define LOG_PLAYLIST         0x0080 /**< playlist.c, lexer.l, parser.y */ | ||||
| #define L_CONF    0x00000001 /**< configuration - configfile.c */ | ||||
| #define L_WS      0x00000002 /**< webserver - webserver.c */ | ||||
| #define L_DB      0x00000004 /**< database - db-gdbm.c, db-memory.c */ | ||||
| #define L_SCAN    0x00000008 /**< scanner - mp3-scanner.c */ | ||||
| #define L_QRY     0x00000010 /**< query - query.c */ | ||||
| #define L_IND     0x00000020 /**< index - daap.c */ | ||||
| #define L_BROW    0x00000040 /**< browse - daap.c, query.c */ | ||||
| #define L_PL      0x00000080 /**< playlists - playlist.c, lexer.l, parser.y */ | ||||
| #define L_ART     0x00000100 /**< cover art - dynamic-art.c */ | ||||
| #define L_DAAP    0x00000200 /**< Generally daap related - main.c, daap.c, query.c */ | ||||
| #define L_MAIN    0x00000400 /**< setup, teardown, signals - main.c */ | ||||
| #define L_REND    0x00000800 /**< rendezvous -- rend-unix.c, rend-posix.c, etc */ | ||||
| 
 | ||||
| #define L_MISC    0x80000000 /**< anything else */ | ||||
| 
 | ||||
| extern int err_debuglevel; | ||||
| 
 | ||||
| extern void log_err(int quit, char *fmt, ...); | ||||
| extern void log_err(int level, unsigned int cat, char *fmt, ...); | ||||
| extern void log_setdest(char *app, int destination); | ||||
| 
 | ||||
| /**
 | ||||
|  * Print a debugging or log message | ||||
|  */ | ||||
| #ifdef DEBUG | ||||
| # define DPRINTF(level, fmt, arg...) \ | ||||
|     { log_err(level,"%s, %d: ",__FILE__,__LINE__); log_err(level,fmt,##arg); } | ||||
| # define DPRINTF(level, cat, fmt, arg...)				\ | ||||
|     { log_err(level,cat,"%s, %d: ",__FILE__,__LINE__); log_err(level,cat,fmt,##arg); } | ||||
| #else | ||||
| # define DPRINTF(level, fmt, arg...) \ | ||||
|     { log_err(level,fmt,##arg); } | ||||
| # define DPRINTF(level, cat, fmt, arg...)	\ | ||||
|     { log_err(level,cat,fmt,##arg); } | ||||
| #endif | ||||
| 
 | ||||
| #ifdef DEBUG_MEMORY | ||||
|  | ||||
| @ -120,7 +120,7 @@ time_t l_convertyyyymmdd(char *date) { | ||||
|     strncpy(month,date+5,2); | ||||
|     strncpy(day,date+8,2); | ||||
| 
 | ||||
|     DPRINTF(ERR_INFO,"Converting %d-%d-%d\n",atoi(year),atoi(month),atoi(day)); | ||||
|     DPRINTF(E_INF,L_PL,"Converting %d-%d-%d\n",atoi(year),atoi(month),atoi(day)); | ||||
|     return l_converttime(atoi(day), atoi(month), atoi(year)); | ||||
| } | ||||
| 
 | ||||
| @ -141,7 +141,7 @@ int yywrap(void) { | ||||
| 
 | ||||
| void yyerror(char *msg) { | ||||
|     pl_error=1; | ||||
|     DPRINTF(ERR_LOG,"Playlist error, line %d: %s\n",yylineno, msg); | ||||
|     DPRINTF(E_LOG,L_PL,"Playlist error, line %d: %s\n",yylineno, msg); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
|  | ||||
| @ -36,6 +36,9 @@ | ||||
| 	Change History (most recent first): | ||||
| 
 | ||||
| $Log$ | ||||
| Revision 1.3  2004/11/13 07:14:26  rpedde | ||||
| modularize debugging statements | ||||
| 
 | ||||
| Revision 1.2  2004/10/25 04:51:54  rpedde | ||||
| tune down some of the logging | ||||
| 
 | ||||
| @ -189,7 +192,7 @@ mDNSexport void debugf_(const char *format, ...) | ||||
| 	buffer[mDNS_vsnprintf((char *)buffer, sizeof(buffer), format, ptr)] = 0; | ||||
| 	va_end(ptr); | ||||
| 
 | ||||
| 	DPRINTF(ERR_DEBUG-1,"%s\n",buffer); | ||||
| 	DPRINTF(E_INF,L_REND,"%s\n",buffer); | ||||
| 	} | ||||
| 
 | ||||
| mDNSexport void verbosedebugf_(const char *format, ...) | ||||
| @ -199,7 +202,7 @@ mDNSexport void verbosedebugf_(const char *format, ...) | ||||
| 	va_start(ptr,format); | ||||
| 	buffer[mDNS_vsnprintf((char *)buffer, sizeof(buffer), format, ptr)] = 0; | ||||
| 	va_end(ptr); | ||||
| 	DPRINTF(ERR_DEBUG,"%s\n",buffer); | ||||
| 	DPRINTF(E_DBG,L_REND,"%s\n",buffer); | ||||
| 	} | ||||
| 
 | ||||
| mDNSexport void LogMsg(const char *format, ...) | ||||
| @ -209,7 +212,7 @@ mDNSexport void LogMsg(const char *format, ...) | ||||
| 	va_start(ptr,format); | ||||
| 	buffer[mDNS_vsnprintf((char *)buffer, sizeof(buffer), format, ptr)] = 0; | ||||
| 	va_end(ptr); | ||||
| 	DPRINTF(ERR_WARN,"%s\n",buffer); | ||||
| 	DPRINTF(E_WARN,L_REND,"%s\n",buffer); | ||||
| 	} | ||||
| 
 | ||||
| #define PosixErrorToStatus(errNum) ((errNum) == 0 ? mStatus_NoError : mStatus_UnknownErr) | ||||
| @ -379,7 +382,7 @@ static void SocketDataReady(mDNS *const m, PosixNetworkInterface *intf, int skt) | ||||
| 			num_pkts_rejected++; | ||||
| 			if (num_pkts_rejected > (num_pkts_accepted + 1) * (num_registered_interfaces + 1) * 2) | ||||
| 				{ | ||||
| 				    DPRINTF(ERR_LOG, | ||||
| 				    DPRINTF(E_LOG,L_REND, | ||||
| 					"*** WARNING: Received %d packets; Accepted %d packets; Rejected %d packets because of interface mismatch\n", | ||||
| 					num_pkts_accepted + num_pkts_rejected, num_pkts_accepted, num_pkts_rejected); | ||||
| 				num_pkts_accepted = 0; | ||||
| @ -462,7 +465,7 @@ static void ClearInterfaceList(mDNS *const m) | ||||
| 		{ | ||||
| 		PosixNetworkInterface *intf = (PosixNetworkInterface*)(m->HostInterfaces); | ||||
| 		mDNS_DeregisterInterface(m, &intf->coreIntf); | ||||
| 		if (gMDNSPlatformPosixVerboseLevel > 0) DPRINTF(ERR_LOG, "Deregistered interface %s\n", intf->intfName); | ||||
| 		if (gMDNSPlatformPosixVerboseLevel > 0) DPRINTF(E_LOG,L_REND, "Deregistered interface %s\n", intf->intfName); | ||||
| 		FreePosixNetworkInterface(intf); | ||||
| 		} | ||||
| 	num_registered_interfaces = 0; | ||||
| @ -575,7 +578,7 @@ static int SetupSocket(struct sockaddr *intfAddr, mDNSIPPort port, int interface | ||||
| 			err = bind(*sktPtr, (struct sockaddr *) &bindAddr, sizeof(bindAddr)); | ||||
| 			if (err < 0) {  | ||||
| 			    err = errno;  | ||||
| 			    DPRINTF(ERR_LOG,"bind: %s\n",strerror(errno)); | ||||
| 			    DPRINTF(E_LOG,L_REND,"bind: %s\n",strerror(errno)); | ||||
| 			} | ||||
| 			} | ||||
| 		} // endif (intfAddr->sa_family == AF_INET)
 | ||||
| @ -739,7 +742,7 @@ static int SetupOneInterface(mDNS *const m, struct sockaddr *intfAddr, const cha | ||||
| 		num_registered_interfaces++; | ||||
| 		debugf("SetupOneInterface: %s %#a Registered", intf->intfName, &intf->coreIntf.ip); | ||||
| 		if (gMDNSPlatformPosixVerboseLevel > 0) | ||||
| 			DPRINTF(ERR_LOG, "Registered interface %s\n", intf->intfName); | ||||
| 		    DPRINTF(E_LOG,L_REND, "Registered interface %s\n", intf->intfName); | ||||
| 		} | ||||
| 	else | ||||
| 		{ | ||||
|  | ||||
							
								
								
									
										106
									
								
								src/main.c
									
									
									
									
									
								
							
							
						
						
									
										106
									
								
								src/main.c
									
									
									
									
									
								
							| @ -216,7 +216,7 @@ void daap_handler(WS_CONNINFO *pwsc) { | ||||
| 	} | ||||
| 	root=daap_response_update(pwsc->fd,clientrev); | ||||
| 	if((ws_getvar(pwsc,"delta")) && (root==NULL)) { | ||||
| 	    DPRINTF(ERR_LOG,"Client %s disconnected\n",pwsc->hostname); | ||||
| 	    DPRINTF(E_LOG,L_WS,"Client %s disconnected\n",pwsc->hostname); | ||||
| 	    config_set_status(pwsc,session_id,NULL); | ||||
| 	    pwsc->close=1; | ||||
| 	    return; | ||||
| @ -312,7 +312,7 @@ void daap_handler(WS_CONNINFO *pwsc) { | ||||
|     } | ||||
| 
 | ||||
|     if((!root)&&(!streaming)) { | ||||
| 	DPRINTF(ERR_DEBUG,"Bad request -- root=%x, streaming=%d\n",root,streaming); | ||||
| 	DPRINTF(E_DBG,L_WS|L_DAAP,"Bad request -- root=%x, streaming=%d\n",root,streaming); | ||||
| 	ws_returnerror(pwsc,400,"Invalid Request"); | ||||
| 	config_set_status(pwsc,session_id,NULL); | ||||
| 	return; | ||||
| @ -321,11 +321,11 @@ void daap_handler(WS_CONNINFO *pwsc) { | ||||
|     pwsc->close=close; | ||||
| 
 | ||||
|     if(!streaming) { | ||||
| 	DPRINTF(ERR_DEBUG,"Satisfying request\n"); | ||||
| 	DPRINTF(E_DBG,L_WS,"Satisfying request\n"); | ||||
| 	ws_addresponseheader(pwsc,"Content-Length","%d",root->reported_size + 8); | ||||
| 	ws_writefd(pwsc,"HTTP/1.1 200 OK\r\n"); | ||||
| 
 | ||||
| 	DPRINTF(ERR_DEBUG,"Emitting headers\n"); | ||||
| 	DPRINTF(E_DBG,L_WS,"Emitting headers\n"); | ||||
| 	ws_emitheaders(pwsc); | ||||
| 
 | ||||
| 	/*
 | ||||
| @ -335,9 +335,9 @@ void daap_handler(WS_CONNINFO *pwsc) { | ||||
| 	  } | ||||
| 	*/ | ||||
| 
 | ||||
| 	DPRINTF(ERR_DEBUG,"Serializing\n"); | ||||
| 	DPRINTF(E_DBG,L_WS|L_DAAP,"Serializing\n"); | ||||
| 	daap_serialize(root,pwsc->fd,0); | ||||
| 	DPRINTF(ERR_DEBUG,"Done, freeing\n"); | ||||
| 	DPRINTF(E_DBG,L_WS|L_DAAP,"Done, freeing\n"); | ||||
| 	daap_free(root); | ||||
|     } else { | ||||
| 	/* stream out the song */ | ||||
| @ -355,7 +355,7 @@ void daap_handler(WS_CONNINFO *pwsc) { | ||||
| 	    file_fd=r_open2(pmp3->path,O_RDONLY); | ||||
| 	    if(file_fd == -1) { | ||||
| 		pwsc->error=errno; | ||||
| 		DPRINTF(ERR_WARN,"Thread %d: Error opening %s: %s\n", | ||||
| 		DPRINTF(E_WARN,L_WS,"Thread %d: Error opening %s: %s\n", | ||||
| 			pwsc->threadno,pmp3->path,strerror(errno)); | ||||
| 		ws_returnerror(pwsc,404,"Not found"); | ||||
| 		config_set_status(pwsc,session_id,NULL); | ||||
| @ -383,7 +383,7 @@ void daap_handler(WS_CONNINFO *pwsc) { | ||||
| 
 | ||||
| 		file_len = real_len - offset; | ||||
| 
 | ||||
| 		DPRINTF(ERR_DEBUG,"Thread %d: Length of file (remaining) is %ld\n", | ||||
| 		DPRINTF(E_DBG,L_WS,"Thread %d: Length of file (remaining) is %ld\n", | ||||
| 			pwsc->threadno,(long)file_len); | ||||
| 		 | ||||
| 		// DWB:  fix content-type to correctly reflect data
 | ||||
| @ -408,7 +408,7 @@ void daap_handler(WS_CONNINFO *pwsc) { | ||||
| 		ws_emitheaders(pwsc); | ||||
| 
 | ||||
| 		config_set_status(pwsc,session_id,"Streaming file '%s'",pmp3->fname); | ||||
| 		DPRINTF(ERR_LOG,"Session %d: Streaming file '%s' to %s (offset %d)\n", | ||||
| 		DPRINTF(E_LOG,L_WS,"Session %d: Streaming file '%s' to %s (offset %d)\n", | ||||
| 			session_id,pmp3->fname, pwsc->hostname,(long)offset); | ||||
| 		 | ||||
| 		if(!offset) | ||||
| @ -417,21 +417,22 @@ void daap_handler(WS_CONNINFO *pwsc) { | ||||
| 		if((config.artfilename) && | ||||
| 		   (!offset) && | ||||
| 		   ((img_fd=da_get_image_fd(pmp3->path)) != -1)) { | ||||
|                   if (strncasecmp(pmp3->type,"mp3",4) ==0) { | ||||
| 		    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 (strncasecmp(pmp3->type, "m4a", 4) == 0) { | ||||
| 		    DPRINTF(ERR_INFO,"Dynamically attaching artwork to %s (fd %d)\n", pmp3->fname, img_fd); | ||||
|                     da_aac_attach_image(img_fd, pwsc->fd, file_fd, offset); | ||||
|                   } | ||||
| 		    if (strncasecmp(pmp3->type,"mp3",4) ==0) { | ||||
| 			DPRINTF(E_INF,L_WS|L_ART,"Dynamic add artwork to %s (fd %d)\n", | ||||
| 				pmp3->fname, img_fd); | ||||
| 			da_attach_image(img_fd, pwsc->fd, file_fd, offset); | ||||
| 		    } else if (strncasecmp(pmp3->type, "m4a", 4) == 0) { | ||||
| 			DPRINTF(E_INF,L_WS|L_ART,"Dynamic add artwork to %s (fd %d)\n",  | ||||
| 				pmp3->fname, img_fd); | ||||
| 			da_aac_attach_image(img_fd, pwsc->fd, file_fd, offset); | ||||
| 		    } | ||||
| 		} else if(offset) { | ||||
| 		    DPRINTF(ERR_INFO,"Seeking to offset %ld\n",(long)offset); | ||||
| 		    DPRINTF(E_INF,L_WS,"Seeking to offset %ld\n",(long)offset); | ||||
| 		    lseek(file_fd,offset,SEEK_SET); | ||||
| 		} | ||||
| 		 | ||||
| 		if(copyfile(file_fd,pwsc->fd)) { | ||||
| 		    DPRINTF(ERR_INFO,"Error copying file to remote... %s\n", | ||||
| 		    DPRINTF(E_INF,L_WS,"Error copying file to remote... %s\n", | ||||
| 			    strerror(errno)); | ||||
| 		} | ||||
| 		config_set_status(pwsc,session_id,NULL); | ||||
| @ -440,7 +441,7 @@ void daap_handler(WS_CONNINFO *pwsc) { | ||||
| 	} | ||||
|     } | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Finished serving DAAP response\n"); | ||||
|     DPRINTF(E_DBG,L_WS|L_DAAP,"Finished serving DAAP response\n"); | ||||
| 
 | ||||
|     return; | ||||
| } | ||||
| @ -571,7 +572,7 @@ void *signal_handler(void *arg) { | ||||
|     config.stop=0; | ||||
|     config.reload=0; | ||||
| 
 | ||||
|     DPRINTF(ERR_WARN,"Signal handler started\n"); | ||||
|     DPRINTF(E_WARN,L_MAIN,"Signal handler started\n"); | ||||
| 
 | ||||
|     while(!config.stop) { | ||||
| 	if((sigemptyset(&intmask) == -1) || | ||||
| @ -579,26 +580,26 @@ void *signal_handler(void *arg) { | ||||
| 	   (sigaddset(&intmask, SIGINT) == -1) || | ||||
| 	   (sigaddset(&intmask, SIGHUP) == -1) || | ||||
| 	   (sigwait(&intmask, &sig) == -1)) { | ||||
| 	    DPRINTF(ERR_FATAL,"Error waiting for signals.  Aborting\n"); | ||||
| 	    DPRINTF(E_FATAL,L_MAIN,"Error waiting for signals.  Aborting\n"); | ||||
| 	} else { | ||||
| 	    /* process the signal */ | ||||
| 	    switch(sig) { | ||||
| 	    case SIGCLD: | ||||
| 		DPRINTF(ERR_LOG,"Got CLD signal.  Reaping\n"); | ||||
| 		DPRINTF(E_LOG,L_MAIN,"Got CLD signal.  Reaping\n"); | ||||
| 		while (wait(&status)) { | ||||
| 		}; | ||||
| 		break; | ||||
| 	    case SIGINT: | ||||
| 		DPRINTF(ERR_LOG,"Got INT signal. Notifying daap server.\n"); | ||||
| 		DPRINTF(E_LOG,L_MAIN,"Got INT signal. Notifying daap server.\n"); | ||||
| 		config.stop=1; | ||||
| 		return NULL; | ||||
| 		break; | ||||
| 	    case SIGHUP: | ||||
| 		DPRINTF(ERR_LOG,"Got HUP signal. Notifying daap server.\n"); | ||||
| 		DPRINTF(E_LOG,L_MAIN,"Got HUP signal. Notifying daap server.\n"); | ||||
| 		config.reload=1; | ||||
| 		break; | ||||
| 	    default: | ||||
| 		DPRINTF(ERR_LOG,"What am I doing here?\n"); | ||||
| 		DPRINTF(E_LOG,L_MAIN,"What am I doing here?\n"); | ||||
| 		break; | ||||
| 	    } | ||||
| 	} | ||||
| @ -624,13 +625,13 @@ int start_signal_handler(void) { | ||||
|        (sigaddset(&set,SIGHUP) == -1) || | ||||
|        (sigaddset(&set,SIGCLD) == -1) || | ||||
|        (sigprocmask(SIG_BLOCK, &set, NULL) == -1)) { | ||||
| 	DPRINTF(ERR_LOG,"Error setting signal set\n"); | ||||
| 	DPRINTF(E_LOG,L_MAIN,"Error setting signal set\n"); | ||||
| 	return -1; | ||||
|     } | ||||
| 
 | ||||
|     if(error=pthread_create(&handler_tid, NULL, signal_handler, NULL)) { | ||||
| 	errno=error; | ||||
| 	DPRINTF(ERR_LOG,"Error creating signal_handler thread\n"); | ||||
| 	DPRINTF(E_LOG,L_MAIN,"Error creating signal_handler thread\n"); | ||||
| 	return -1; | ||||
|     } | ||||
| 
 | ||||
| @ -726,9 +727,9 @@ int main(int argc, char *argv[]) { | ||||
| 
 | ||||
| #ifndef WITHOUT_MDNS | ||||
|     if((config.use_mdns) && (!parseonly)) { | ||||
| 	DPRINTF(ERR_LOG,"Starting rendezvous daemon\n"); | ||||
| 	DPRINTF(E_LOG,L_MAIN,"Starting rendezvous daemon\n"); | ||||
| 	if(rend_init(config.runas)) { | ||||
| 	    DPRINTF(ERR_FATAL,"Error in rend_init: %s\n",strerror(errno)); | ||||
| 	    DPRINTF(E_FATAL,L_MAIN|L_REND,"Error in rend_init: %s\n",strerror(errno)); | ||||
| 	} | ||||
|     } | ||||
| #endif | ||||
| @ -745,21 +746,21 @@ int main(int argc, char *argv[]) { | ||||
| 
 | ||||
|     /* DWB: shouldn't this be done after dropping privs? */ | ||||
|     if(db_open(config.dbdir, reload)) { | ||||
| 	DPRINTF(ERR_FATAL,"Error in db_open: %s\n",strerror(errno)); | ||||
| 	DPRINTF(E_FATAL,L_MAIN|L_DB,"Error in db_open: %s\n",strerror(errno)); | ||||
|     } | ||||
| 
 | ||||
|     // Drop privs here
 | ||||
|     if(drop_privs(config.runas)) { | ||||
| 	DPRINTF(ERR_FATAL,"Error in drop_privs: %s\n",strerror(errno)); | ||||
| 	DPRINTF(E_FATAL,L_MAIN,"Error in drop_privs: %s\n",strerror(errno)); | ||||
|     } | ||||
| 
 | ||||
|     /* block signals and set up the signal handling thread */ | ||||
|     DPRINTF(ERR_LOG,"Starting signal handler\n"); | ||||
|     DPRINTF(E_LOG,L_MAIN,"Starting signal handler\n"); | ||||
|     if(start_signal_handler()) { | ||||
| 	DPRINTF(ERR_FATAL,"Error starting signal handler %s\n",strerror(errno)); | ||||
| 	DPRINTF(E_FATAL,L_MAIN,"Error starting signal handler %s\n",strerror(errno)); | ||||
|     } | ||||
| 
 | ||||
|     DPRINTF(ERR_LOG,"Loading playlists\n"); | ||||
|     DPRINTF(E_LOG,L_MAIN|L_PL,"Loading playlists\n"); | ||||
| 
 | ||||
|     if(config.playlist) | ||||
| 	pl_load(config.playlist); | ||||
| @ -773,26 +774,26 @@ int main(int argc, char *argv[]) { | ||||
|     } | ||||
| 
 | ||||
|     /* Initialize the database before starting */ | ||||
|     DPRINTF(ERR_LOG,"Initializing database\n"); | ||||
|     DPRINTF(E_LOG,L_MAIN|L_DB,"Initializing database\n"); | ||||
|     if(db_init()) { | ||||
| 	DPRINTF(ERR_FATAL,"Error in db_init: %s\n",strerror(errno)); | ||||
| 	DPRINTF(E_FATAL,L_MAIN|L_DB,"Error in db_init: %s\n",strerror(errno)); | ||||
|     } | ||||
| 
 | ||||
|     DPRINTF(ERR_LOG,"Starting mp3 scan\n"); | ||||
|     DPRINTF(E_LOG,L_MAIN|L_SCAN,"Starting mp3 scan\n"); | ||||
|     if(scan_init(config.mp3dir)) { | ||||
| 	DPRINTF(ERR_FATAL,"Error scanning MP3 files: %s\n",strerror(errno)); | ||||
| 	DPRINTF(E_FATAL,L_MAIN|L_SCAN,"Error scanning MP3 files: %s\n",strerror(errno)); | ||||
|     } | ||||
| 
 | ||||
|     /* start up the web server */ | ||||
|     ws_config.web_root=config.web_root; | ||||
|     ws_config.port=config.port; | ||||
| 
 | ||||
|     DPRINTF(ERR_LOG,"Starting web server from %s on port %d\n", | ||||
|     DPRINTF(E_LOG,L_MAIN|L_WS,"Starting web server from %s on port %d\n", | ||||
| 	    config.web_root, config.port); | ||||
| 
 | ||||
|     server=ws_start(&ws_config); | ||||
|     if(!server) { | ||||
| 	DPRINTF(ERR_FATAL,"Error staring web server: %s\n",strerror(errno)); | ||||
| 	DPRINTF(E_FATAL,L_MAIN|L_WS,"Error staring web server: %s\n",strerror(errno)); | ||||
|     } | ||||
| 
 | ||||
|     ws_registerhandler(server, "^.*$",config_handler,config_auth,1); | ||||
| @ -806,7 +807,7 @@ int main(int argc, char *argv[]) { | ||||
| 
 | ||||
| #ifndef WITHOUT_MDNS | ||||
|     if(config.use_mdns) { /* register services */ | ||||
| 	DPRINTF(ERR_LOG,"Registering rendezvous names\n"); | ||||
| 	DPRINTF(E_LOG,L_MAIN|L_REND,"Registering rendezvous names\n"); | ||||
| 	rend_register(config.servername,"_daap._tcp",config.port); | ||||
| 	rend_register(config.servername,"_http._tcp",config.port); | ||||
|     } | ||||
| @ -814,7 +815,7 @@ int main(int argc, char *argv[]) { | ||||
| 
 | ||||
|     end_time=time(NULL); | ||||
| 
 | ||||
|     DPRINTF(ERR_LOG,"Scanned %d songs in  %d seconds\n",db_get_song_count(), | ||||
|     DPRINTF(E_LOG,L_MAIN,"Scanned %d songs in  %d seconds\n",db_get_song_count(), | ||||
| 	    end_time-start_time); | ||||
| 
 | ||||
|     config.stop=0; | ||||
| @ -824,7 +825,7 @@ int main(int argc, char *argv[]) { | ||||
| 	    if((config.always_scan) || (config_get_session_count())) { | ||||
| 		config.reload=1; | ||||
| 	    } else { | ||||
| 		DPRINTF(ERR_DEBUG,"Skipping background scan... no connected users\n"); | ||||
| 		DPRINTF(E_DBG,L_MAIN|L_SCAN|L_DB,"Skipped bground scan... no users\n"); | ||||
| 	    } | ||||
| 	    rescan_counter=0; | ||||
| 	} | ||||
| @ -833,34 +834,35 @@ int main(int argc, char *argv[]) { | ||||
| 	    old_song_count = db_get_song_count(); | ||||
| 	    start_time=time(NULL); | ||||
| 
 | ||||
| 	    DPRINTF(ERR_LOG,"Rescanning database\n"); | ||||
| 	    DPRINTF(E_LOG,L_MAIN|L_DB|L_SCAN,"Rescanning database\n"); | ||||
| 	    if(scan_init(config.mp3dir)) { | ||||
| 		DPRINTF(ERR_LOG,"Error rescanning... exiting\n"); | ||||
| 		DPRINTF(E_LOG,L_MAIN|L_DB|L_SCAN,"Error rescanning... exiting\n"); | ||||
| 		config.stop=1; | ||||
| 	    } | ||||
| 	    config.reload=0; | ||||
| 	    DPRINTF(ERR_INFO,"Background scanned %d songs (previously %d) in %d seconds\n",db_get_song_count(),old_song_count,time(NULL)-start_time); | ||||
| 	    DPRINTF(E_INF,L_MAIN|L_DB|L_SCAN,"Scanned %d songs (was %d) in %d seconds\n", | ||||
| 		    db_get_song_count(),old_song_count,time(NULL)-start_time); | ||||
| 	} | ||||
| 
 | ||||
| 	sleep(MAIN_SLEEP_INTERVAL); | ||||
| 	rescan_counter += MAIN_SLEEP_INTERVAL; | ||||
|     } | ||||
| 
 | ||||
|     DPRINTF(ERR_LOG,"Stopping gracefully\n"); | ||||
|     DPRINTF(E_LOG,L_MAIN,"Stopping gracefully\n"); | ||||
| 
 | ||||
| #ifndef WITHOUT_MDNS | ||||
|     if(config.use_mdns) { | ||||
| 	DPRINTF(ERR_LOG,"Stopping rendezvous daemon\n"); | ||||
| 	DPRINTF(E_LOG,L_MAIN|L_REND,"Stopping rendezvous daemon\n"); | ||||
| 	rend_stop(); | ||||
|     } | ||||
| #endif | ||||
| 
 | ||||
|     DPRINTF(ERR_LOG,"Stopping web server\n"); | ||||
|     DPRINTF(E_LOG,L_MAIN|L_WS,"Stopping web server\n"); | ||||
|     ws_stop(server); | ||||
| 
 | ||||
|     config_close(); | ||||
| 
 | ||||
|     DPRINTF(ERR_LOG,"Closing database\n"); | ||||
|     DPRINTF(E_LOG,L_MAIN|L_DB,"Closing database\n"); | ||||
|     db_deinit(); | ||||
| 
 | ||||
| #ifdef DEBUG_MEMORY | ||||
| @ -868,7 +870,7 @@ int main(int argc, char *argv[]) { | ||||
|     err_leakcheck(); | ||||
| #endif | ||||
| 
 | ||||
|     DPRINTF(ERR_LOG,"Done!\n"); | ||||
|     DPRINTF(E_LOG,L_MAIN,"Done!\n"); | ||||
| 
 | ||||
|     log_setdest(NULL,LOGDEST_STDERR); | ||||
| 
 | ||||
|  | ||||
| @ -305,7 +305,7 @@ int scan_init(char *path) { | ||||
|     if(db_start_initial_update())  | ||||
| 	return -1; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"%s scanning for MP3s in %s\n", | ||||
|     DPRINTF(E_DBG,L_SCAN,"%s scanning for MP3s in %s\n", | ||||
| 	    scan_mode_foreground ? "Foreground" : "Background", | ||||
| 	    path); | ||||
| 
 | ||||
| @ -339,7 +339,7 @@ int scan_path(char *path) { | ||||
| 
 | ||||
|     while(1) { | ||||
| 	if(config.stop) { | ||||
| 	    DPRINTF(ERR_WARN,"Stop detected.  Aborting scan of %s.\n",path); | ||||
| 	    DPRINTF(E_WARN,L_SCAN,"Stop detected.  Aborting scan of %s.\n",path); | ||||
| 	    return 0; | ||||
| 	} | ||||
| 
 | ||||
| @ -347,7 +347,7 @@ int scan_path(char *path) { | ||||
| 
 | ||||
| 	err=readdir_r(current_dir,(struct dirent *)de,&pde); | ||||
| 	if(err == -1) { | ||||
| 	    DPRINTF(ERR_DEBUG,"Error on readdir_r: %s\n",strerror(errno)); | ||||
| 	    DPRINTF(E_DBG,L_SCAN,"Error on readdir_r: %s\n",strerror(errno)); | ||||
| 	    err=errno; | ||||
| 	    closedir(current_dir); | ||||
| 	    errno=err; | ||||
| @ -361,12 +361,12 @@ int scan_path(char *path) { | ||||
| 	    continue; | ||||
| 
 | ||||
| 	snprintf(mp3_path,PATH_MAX,"%s/%s",path,pde->d_name); | ||||
| 	DPRINTF(ERR_DEBUG,"Found %s\n",mp3_path); | ||||
| 	DPRINTF(E_DBG,L_SCAN,"Found %s\n",mp3_path); | ||||
| 	if(stat(mp3_path,&sb)) { | ||||
| 	    DPRINTF(ERR_WARN,"Error statting: %s\n",strerror(errno)); | ||||
| 	    DPRINTF(E_WARN,L_SCAN,"Error statting: %s\n",strerror(errno)); | ||||
| 	} else { | ||||
| 	    if(sb.st_mode & S_IFDIR) { /* dir -- recurse */ | ||||
| 		DPRINTF(ERR_DEBUG,"Found dir %s... recursing\n",pde->d_name); | ||||
| 		DPRINTF(E_DBG,L_SCAN,"Found dir %s... recursing\n",pde->d_name); | ||||
| 		scan_path(mp3_path); | ||||
| 	    } else { | ||||
| 		/* process the file */ | ||||
| @ -380,14 +380,14 @@ int scan_path(char *path) { | ||||
| 			 | ||||
| 			/* only scan if it's been changed, or empty db */ | ||||
| 			modified_time=sb.st_mtime; | ||||
| 			DPRINTF(ERR_DEBUG,"FS Modified time: %d\n",modified_time); | ||||
| 			DPRINTF(ERR_DEBUG,"DB Modified time: %d\n",db_last_modified(sb.st_ino)); | ||||
| 			DPRINTF(E_DBG,L_SCAN,"FS Mod time: %d\n",modified_time); | ||||
| 			DPRINTF(E_DBG,L_SCAN,"DB Mod time: %d\n",db_last_modified(sb.st_ino)); | ||||
| 			if((scan_mode_foreground) ||  | ||||
| 			   !db_exists(sb.st_ino) || | ||||
| 			   db_last_modified(sb.st_ino) < modified_time) { | ||||
| 			    scan_music_file(path,pde,&sb); | ||||
| 			} else { | ||||
| 			    DPRINTF(ERR_DEBUG,"Skipping file... not modified\n"); | ||||
| 			    DPRINTF(E_DBG,L_SCAN,"Skipping file... not modified\n"); | ||||
| 			} | ||||
| 		    } | ||||
| 		} | ||||
| @ -412,7 +412,7 @@ void scan_static_playlist(char *path, struct dirent *pde, struct stat *psb) { | ||||
|     int playlistid; | ||||
|     struct stat sb; | ||||
| 
 | ||||
|     DPRINTF(ERR_WARN,"Processing static playlist: %s\n",pde->d_name); | ||||
|     DPRINTF(E_WARN,L_SCAN|L_PL,"Processing static playlist: %s\n",pde->d_name); | ||||
|     strcpy(m3u_path,pde->d_name); | ||||
|     snprintf(playlist_path,sizeof(playlist_path),"%s/%s",path,pde->d_name); | ||||
|     m3u_path[strlen(pde->d_name) - 4] = '\0'; | ||||
| @ -420,7 +420,7 @@ void scan_static_playlist(char *path, struct dirent *pde, struct stat *psb) { | ||||
|     fd=open(playlist_path,O_RDONLY); | ||||
|     if(fd != -1) { | ||||
| 	db_add_playlist(playlistid,m3u_path,0); | ||||
| 	DPRINTF(ERR_INFO,"Added playlist as id %d\n",playlistid); | ||||
| 	DPRINTF(E_INF,L_SCAN|L_PL,"Added playlist as id %d\n",playlistid); | ||||
| 
 | ||||
| 	memset(linebuffer,0x00,sizeof(linebuffer)); | ||||
| 	while(readline(fd,linebuffer,sizeof(linebuffer)) > 0) { | ||||
| @ -440,21 +440,21 @@ void scan_static_playlist(char *path, struct dirent *pde, struct stat *psb) { | ||||
| 		snprintf(m3u_path,sizeof(m3u_path),"%s/%s",path,linebuffer); | ||||
| 	    } | ||||
| 
 | ||||
| 	    DPRINTF(ERR_DEBUG,"Checking %s\n",m3u_path); | ||||
| 	    DPRINTF(E_DBG,L_SCAN|L_PL,"Checking %s\n",m3u_path); | ||||
| 
 | ||||
| 	    /* might be valid, might not... */ | ||||
| 	    if(!stat(m3u_path,&sb)) { | ||||
| 		/* FIXME: check to see if valid inode! */ | ||||
| 		db_add_playlist_song(playlistid,sb.st_ino); | ||||
| 	    } else { | ||||
| 		DPRINTF(ERR_WARN,"Playlist entry %s bad: %s\n", | ||||
| 		DPRINTF(E_WARN,L_SCAN|L_PL,"Playlist entry %s bad: %s\n", | ||||
| 			m3u_path,strerror(errno)); | ||||
| 	    } | ||||
| 	} | ||||
| 	close(fd); | ||||
|     } | ||||
| 
 | ||||
|     DPRINTF(ERR_WARN,"Done processing playlist\n"); | ||||
|     DPRINTF(E_WARN,L_SCAN|L_PL,"Done processing playlist\n"); | ||||
| } | ||||
| 
 | ||||
| /*
 | ||||
| @ -469,7 +469,7 @@ void scan_music_file(char *path, struct dirent *pde, struct stat *psb) { | ||||
|     snprintf(mp3_path,sizeof(mp3_path),"%s/%s",path,pde->d_name); | ||||
| 
 | ||||
|     /* we found an mp3 file */ | ||||
|     DPRINTF(ERR_INFO,"Found music file: %s\n",pde->d_name); | ||||
|     DPRINTF(E_INF,L_SCAN,"Found music file: %s\n",pde->d_name); | ||||
|      | ||||
|     memset((void*)&mp3file,0,sizeof(mp3file)); | ||||
|     mp3file.path=mp3_path; | ||||
| @ -496,12 +496,12 @@ void scan_music_file(char *path, struct dirent *pde, struct stat *psb) { | ||||
| 	    mp3file.time_added=psb->st_ctime; | ||||
| 	mp3file.time_modified=time(NULL); | ||||
| 
 | ||||
| 	DPRINTF(ERR_DEBUG," Date Added: %d\n",mp3file.time_added); | ||||
| 	DPRINTF(E_DBG,L_SCAN," Date Added: %d\n",mp3file.time_added); | ||||
| 
 | ||||
| 	db_add(&mp3file); | ||||
| 	pl_eval(&mp3file); /* FIXME: move to db_add? */ | ||||
|     } else { | ||||
| 	DPRINTF(ERR_WARN,"Skipping %s - scan_gettags failed\n",pde->d_name); | ||||
| 	DPRINTF(E_WARN,L_SCAN,"Skipping %s - scan_gettags failed\n",pde->d_name); | ||||
|     } | ||||
|      | ||||
|     scan_freetags(&mp3file); | ||||
| @ -560,7 +560,7 @@ int scan_get_aactags(char *file, MP3FILE *pmp3) { | ||||
|     int len; | ||||
| 
 | ||||
|     if(!(fin=fopen(file,"rb"))) { | ||||
| 	DPRINTF(ERR_INFO,"Cannot open file %s for reading\n",file); | ||||
| 	DPRINTF(E_INF,L_SCAN,"Cannot open file %s for reading\n",file); | ||||
| 	return -1; | ||||
|     } | ||||
| 
 | ||||
| @ -700,7 +700,7 @@ int scan_get_mp3tags(char *file, MP3FILE *pmp3) { | ||||
| 
 | ||||
|     pid3file=id3_file_open(file,ID3_FILE_MODE_READONLY); | ||||
|     if(!pid3file) { | ||||
| 	DPRINTF(ERR_WARN,"Cannot open %s\n",file); | ||||
| 	DPRINTF(E_WARN,L_SCAN,"Cannot open %s\n",file); | ||||
| 	return -1; | ||||
|     } | ||||
| 
 | ||||
| @ -710,7 +710,7 @@ int scan_get_mp3tags(char *file, MP3FILE *pmp3) { | ||||
| 	err=errno; | ||||
| 	id3_file_close(pid3file); | ||||
| 	errno=err; | ||||
| 	DPRINTF(ERR_WARN,"Cannot get ID3 tag for %s\n",file); | ||||
| 	DPRINTF(E_WARN,L_SCAN,"Cannot get ID3 tag for %s\n",file); | ||||
| 	return -1; | ||||
|     } | ||||
| 
 | ||||
| @ -724,7 +724,7 @@ int scan_get_mp3tags(char *file, MP3FILE *pmp3) { | ||||
| 
 | ||||
| 	if(!strcmp(pid3frame->id,"YTCP")) { /* for id3v2.2 */ | ||||
| 	    pmp3->compilation = 1; | ||||
| 	    DPRINTF(ERR_DEBUG, "Compilation: %d\n", pmp3->compilation); | ||||
| 	    DPRINTF(E_DBG,L_SCAN,"Compilation: %d\n", pmp3->compilation); | ||||
| 	} | ||||
| 
 | ||||
| 	if(((pid3frame->id[0] == 'T')||(strcmp(pid3frame->id,"COMM")==0)) && | ||||
| @ -742,36 +742,36 @@ int scan_get_mp3tags(char *file, MP3FILE *pmp3) { | ||||
| 		if(!strcmp(pid3frame->id,"TIT2")) { /* Title */ | ||||
| 		    used=1; | ||||
| 		    pmp3->title = utf8_text; | ||||
| 		    DPRINTF(ERR_DEBUG," Title: %s\n",utf8_text); | ||||
| 		    DPRINTF(E_DBG,L_SCAN," Title: %s\n",utf8_text); | ||||
| 		} else if(!strcmp(pid3frame->id,"TPE1")) { | ||||
| 		    used=1; | ||||
| 		    pmp3->artist = utf8_text; | ||||
| 		    DPRINTF(ERR_DEBUG," Artist: %s\n",utf8_text); | ||||
| 		    DPRINTF(E_DBG,L_SCAN," Artist: %s\n",utf8_text); | ||||
| 		} else if(!strcmp(pid3frame->id,"TALB")) { | ||||
| 		    used=1; | ||||
| 		    pmp3->album = utf8_text; | ||||
| 		    DPRINTF(ERR_DEBUG," Album: %s\n",utf8_text); | ||||
| 		    DPRINTF(E_DBG,L_SCAN," Album: %s\n",utf8_text); | ||||
| 		} else if(!strcmp(pid3frame->id,"TCOM")) { | ||||
| 		    used=1; | ||||
| 		    pmp3->composer = utf8_text; | ||||
| 		    DPRINTF(ERR_DEBUG," Composer: %s\n",utf8_text); | ||||
| 		    DPRINTF(E_DBG,L_SCAN," Composer: %s\n",utf8_text); | ||||
| 		} else if(!strcmp(pid3frame->id,"TIT1")) { | ||||
| 		    used=1; | ||||
| 		    pmp3->grouping = utf8_text; | ||||
| 		    DPRINTF(ERR_DEBUG," Grouping: %s\n",utf8_text); | ||||
| 		    DPRINTF(E_DBG,L_SCAN," Grouping: %s\n",utf8_text); | ||||
| 		} else if(!strcmp(pid3frame->id,"TPE2")) { | ||||
| 		    used=1; | ||||
| 		    pmp3->orchestra = utf8_text; | ||||
| 		    DPRINTF(ERR_DEBUG," Orchestra: %s\n",utf8_text); | ||||
| 		    DPRINTF(E_DBG,L_SCAN," Orchestra: %s\n",utf8_text); | ||||
| 		} else if(!strcmp(pid3frame->id,"TPE3")) { | ||||
| 		    used=1; | ||||
| 		    pmp3->conductor = utf8_text; | ||||
| 		    DPRINTF(ERR_DEBUG," Conductor: %s\n",utf8_text); | ||||
| 		    DPRINTF(E_DBG,L_SCAN," Conductor: %s\n",utf8_text); | ||||
| 		} else if(!strcmp(pid3frame->id,"TCON")) { | ||||
| 		    used=1; | ||||
| 		    pmp3->genre = utf8_text; | ||||
| 		    got_numeric_genre=0; | ||||
| 		    DPRINTF(ERR_DEBUG," Genre: %s\n",utf8_text); | ||||
| 		    DPRINTF(E_DBG,L_SCAN," Genre: %s\n",utf8_text); | ||||
| 		    if(pmp3->genre) { | ||||
| 			if(!strlen(pmp3->genre)) { | ||||
| 			    genre=WINAMP_GENRE_UNKNOWN; | ||||
| @ -794,7 +794,7 @@ int scan_get_mp3tags(char *file, MP3FILE *pmp3) { | ||||
| 		} else if(!strcmp(pid3frame->id,"COMM")) { | ||||
| 		    used=1; | ||||
| 		    pmp3->comment = utf8_text; | ||||
| 		    DPRINTF(ERR_DEBUG," Comment: %s\n",pmp3->comment); | ||||
| 		    DPRINTF(E_DBG,L_SCAN," Comment: %s\n",pmp3->comment); | ||||
| 		} else if(!strcmp(pid3frame->id,"TPOS")) { | ||||
| 		    tmp=(char*)utf8_text; | ||||
| 		    strsep(&tmp,"/"); | ||||
| @ -802,7 +802,7 @@ int scan_get_mp3tags(char *file, MP3FILE *pmp3) { | ||||
| 			pmp3->total_discs=atoi(tmp); | ||||
| 		    } | ||||
| 		    pmp3->disc=atoi((char*)utf8_text); | ||||
| 		    DPRINTF(ERR_DEBUG," Disc %d of %d\n",pmp3->disc,pmp3->total_discs); | ||||
| 		    DPRINTF(E_DBG,L_SCAN," Disc %d of %d\n",pmp3->disc,pmp3->total_discs); | ||||
| 		} else if(!strcmp(pid3frame->id,"TRCK")) { | ||||
| 		    tmp=(char*)utf8_text; | ||||
| 		    strsep(&tmp,"/"); | ||||
| @ -810,19 +810,19 @@ int scan_get_mp3tags(char *file, MP3FILE *pmp3) { | ||||
| 			pmp3->total_tracks=atoi(tmp); | ||||
| 		    } | ||||
| 		    pmp3->track=atoi((char*)utf8_text); | ||||
| 		    DPRINTF(ERR_DEBUG," Track %d of %d\n",pmp3->track,pmp3->total_tracks); | ||||
| 		    DPRINTF(E_DBG,L_SCAN," Track %d of %d\n",pmp3->track,pmp3->total_tracks); | ||||
| 		} else if(!strcmp(pid3frame->id,"TDRC")) { | ||||
| 		    pmp3->year = atoi(utf8_text); | ||||
| 		    DPRINTF(ERR_DEBUG," Year: %d\n",pmp3->year); | ||||
| 		    DPRINTF(E_DBG,L_SCAN," Year: %d\n",pmp3->year); | ||||
| 		} else if(!strcmp(pid3frame->id,"TLEN")) { | ||||
| 		    pmp3->song_length = atoi(utf8_text) / 1000; | ||||
| 		    DPRINTF(ERR_DEBUG, " Length: %d\n", pmp3->song_length); | ||||
| 		    DPRINTF(E_DBG,L_SCAN," Length: %d\n", pmp3->song_length); | ||||
| 		} else if(!strcmp(pid3frame->id,"TBPM")) { | ||||
| 		    pmp3->bpm = atoi(utf8_text); | ||||
| 		    DPRINTF(ERR_DEBUG, "BPM: %d\n", pmp3->bpm); | ||||
| 		    DPRINTF(E_DBG,L_SCAN,"BPM: %d\n", pmp3->bpm); | ||||
| 		} else if(!strcmp(pid3frame->id,"TCMP")) { /* for id3v2.3 */ | ||||
|                     pmp3->compilation = (char)atoi(utf8_text); | ||||
|                     DPRINTF(ERR_DEBUG, "Compilation: %d\n", pmp3->compilation); | ||||
|                     DPRINTF(E_DBG,L_SCAN,"Compilation: %d\n", pmp3->compilation); | ||||
|                 } | ||||
| 	    } | ||||
| 	} | ||||
| @ -835,7 +835,7 @@ int scan_get_mp3tags(char *file, MP3FILE *pmp3) { | ||||
|     } | ||||
| 
 | ||||
|     id3_file_close(pid3file); | ||||
|     DPRINTF(ERR_DEBUG,"Got id3 tag successfully\n"); | ||||
|     DPRINTF(E_DBG,L_SCAN,"Got id3 tag successfully\n"); | ||||
|     return 0; | ||||
| } | ||||
| 
 | ||||
| @ -882,7 +882,7 @@ int scan_get_fileinfo(char *file, MP3FILE *pmp3) { | ||||
| 
 | ||||
|     /* a file we don't know anything about... ogg or aiff maybe */ | ||||
|     if(!(infile=fopen(file,"rb"))) { | ||||
| 	DPRINTF(ERR_WARN,"Could not open %s for reading\n",file); | ||||
| 	DPRINTF(E_WARN,L_SCAN,"Could not open %s for reading\n",file); | ||||
| 	return -1; | ||||
|     } | ||||
| 
 | ||||
| @ -936,7 +936,7 @@ off_t aac_drilltoatom(FILE *aac_fp, char *atom_path, unsigned int *atom_length) | ||||
| 		{ | ||||
| 		    return -1; | ||||
| 		} | ||||
| 	    DPRINTF(ERR_DEBUG, "Found %s atom at offset %ld.\n", atom_name, ftell(aac_fp) - 8); | ||||
| 	    DPRINTF(E_DBG,L_SCAN,"Found %s atom at off %ld.\n", atom_name, ftell(aac_fp) - 8); | ||||
| 	    cur_p = strchr(cur_p, ':'); | ||||
| 	    if (cur_p != NULL) | ||||
| 		{ | ||||
| @ -968,10 +968,10 @@ int scan_get_urlfileinfo(char *file, MP3FILE *pmp3) { | ||||
|     char *head, *tail; | ||||
|     char linebuffer[256]; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Getting URL file info\n"); | ||||
|     DPRINTF(E_DBG,L_SCAN,"Getting URL file info\n"); | ||||
| 
 | ||||
|     if(!(infile=fopen(file,"rb"))) { | ||||
| 	DPRINTF(ERR_WARN,"Could not open %s for reading\n",file); | ||||
| 	DPRINTF(E_WARN,L_SCAN,"Could not open %s for reading\n",file); | ||||
| 	return -1; | ||||
|     } | ||||
| 
 | ||||
| @ -984,7 +984,7 @@ int scan_get_urlfileinfo(char *file, MP3FILE *pmp3) { | ||||
|     head=linebuffer; | ||||
|     tail=strchr(head,','); | ||||
|     if(!tail) { | ||||
| 	DPRINTF(ERR_LOG,"Badly formatted .url file - must be bitrate,descr,url\n"); | ||||
| 	DPRINTF(E_LOG,L_SCAN,"Badly formatted .url file - must be bitrate,descr,url\n"); | ||||
| 	fclose(infile); | ||||
| 	return -1; | ||||
|     } | ||||
| @ -993,7 +993,7 @@ int scan_get_urlfileinfo(char *file, MP3FILE *pmp3) { | ||||
|     head=++tail; | ||||
|     tail=strchr(head,','); | ||||
|     if(!tail) { | ||||
| 	DPRINTF(ERR_LOG,"Badly formatted .url file - must be bitrate,descr,url\n"); | ||||
| 	DPRINTF(E_LOG,L_SCAN,"Badly formatted .url file - must be bitrate,descr,url\n"); | ||||
| 	fclose(infile); | ||||
| 	return -1; | ||||
|     } | ||||
| @ -1004,9 +1004,9 @@ int scan_get_urlfileinfo(char *file, MP3FILE *pmp3) { | ||||
|     pmp3->url=strdup(tail); | ||||
|     fclose(infile); | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"  Title:    %s\n",pmp3->title); | ||||
|     DPRINTF(ERR_DEBUG,"  Bitrate:  %d\n",pmp3->bitrate); | ||||
|     DPRINTF(ERR_DEBUG,"  URL:      %s\n",pmp3->url); | ||||
|     DPRINTF(E_DBG,L_SCAN,"  Title:    %s\n",pmp3->title); | ||||
|     DPRINTF(E_DBG,L_SCAN,"  Bitrate:  %d\n",pmp3->bitrate); | ||||
|     DPRINTF(E_DBG,L_SCAN,"  URL:      %s\n",pmp3->url); | ||||
| 
 | ||||
|     return 0; | ||||
| } | ||||
| @ -1027,10 +1027,10 @@ int scan_get_aacfileinfo(char *file, MP3FILE *pmp3) { | ||||
|     int ms; | ||||
|     unsigned char buffer[2]; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Getting AAC file info\n"); | ||||
|     DPRINTF(E_DBG,L_SCAN,"Getting AAC file info\n"); | ||||
| 
 | ||||
|     if(!(infile=fopen(file,"rb"))) { | ||||
| 	DPRINTF(ERR_WARN,"Could not open %s for reading\n",file); | ||||
| 	DPRINTF(E_WARN,L_SCAN,"Could not open %s for reading\n",file); | ||||
| 	return -1; | ||||
|     } | ||||
| 
 | ||||
| @ -1060,7 +1060,7 @@ int scan_get_aacfileinfo(char *file, MP3FILE *pmp3) { | ||||
| 	/* DWB: use ms time instead of sec */ | ||||
| 	pmp3->song_length=(int)((samples * ms) / sample_size); | ||||
| 
 | ||||
| 	DPRINTF(ERR_DEBUG,"Song length: %d seconds\n", pmp3->song_length / 1000); | ||||
| 	DPRINTF(E_DBG,L_SCAN,"Song length: %d seconds\n", pmp3->song_length / 1000); | ||||
|     } | ||||
| 
 | ||||
|     pmp3->bitrate = 0; | ||||
| @ -1093,17 +1093,17 @@ int scan_get_aacfileinfo(char *file, MP3FILE *pmp3) { | ||||
| 
 | ||||
| 	    pmp3->bitrate = ntohl(bit_rate) / 1000; | ||||
| 	} else { | ||||
| 	    DPRINTF(ERR_DEBUG, "Could not find 'esds' atom to determine bit rate.\n"); | ||||
| 	    DPRINTF(E_DBG,L_SCAN, "Could not find 'esds' atom to determine bit rate.\n"); | ||||
| 	} | ||||
|        | ||||
|     } else { | ||||
| 	DPRINTF(ERR_DEBUG, "Could not find 'mp4a' atom to determine sample rate.\n"); | ||||
| 	DPRINTF(E_DBG,L_SCAN, "Could not find 'mp4a' atom to determine sample rate.\n"); | ||||
|     } | ||||
| 
 | ||||
|     /* Fallback if we can't find the info in the atoms. */ | ||||
|     if (pmp3->bitrate == 0) { | ||||
| 	/* calculate bitrate from song length... Kinda cheesy */ | ||||
| 	DPRINTF(ERR_DEBUG, "Could not find 'esds' atom. Calculating bit rate.\n"); | ||||
| 	DPRINTF(E_DBG,L_SCAN, "Could not find 'esds' atom. Calculating bit rate.\n"); | ||||
| 
 | ||||
| 	atom_offset=aac_drilltoatom(infile,"mdat",&atom_length); | ||||
| 
 | ||||
| @ -1141,7 +1141,7 @@ int scan_get_mp3fileinfo(char *file, MP3FILE *pmp3) { | ||||
|     int stereo=0; | ||||
| 
 | ||||
|     if(!(infile=fopen(file,"rb"))) { | ||||
| 	DPRINTF(ERR_WARN,"Could not open %s for reading\n",file); | ||||
| 	DPRINTF(E_WARN,L_SCAN,"Could not open %s for reading\n",file); | ||||
| 	return -1; | ||||
|     } | ||||
| 
 | ||||
| @ -1153,9 +1153,9 @@ int scan_get_mp3fileinfo(char *file, MP3FILE *pmp3) { | ||||
| 
 | ||||
|     if(fread(buffer,1,sizeof(buffer),infile) != sizeof(buffer)) { | ||||
| 	if(ferror(infile)) { | ||||
| 	    DPRINTF(ERR_LOG,"Error reading: %s\n",strerror(errno)); | ||||
| 	    DPRINTF(E_LOG,L_SCAN,"Error reading: %s\n",strerror(errno)); | ||||
| 	} else { | ||||
| 	    DPRINTF(ERR_LOG,"Short file: %s\n",file); | ||||
| 	    DPRINTF(E_LOG,L_SCAN,"Short file: %s\n",file); | ||||
| 	} | ||||
| 	return -1; | ||||
|     } | ||||
| @ -1164,18 +1164,18 @@ int scan_get_mp3fileinfo(char *file, MP3FILE *pmp3) { | ||||
|      | ||||
|     if(strncmp(pid3->id,"ID3",3)==0) { | ||||
| 	/* found an ID3 header... */ | ||||
| 	DPRINTF(ERR_DEBUG,"Found ID3 header\n"); | ||||
| 	DPRINTF(E_DBG,L_SCAN,"Found ID3 header\n"); | ||||
| 	size = (pid3->size[0] << 21 | pid3->size[1] << 14 |  | ||||
| 		pid3->size[2] << 7 | pid3->size[3]); | ||||
| 	fp_size=size + sizeof(SCAN_ID3HEADER); | ||||
| 	DPRINTF(ERR_DEBUG,"Header length: %d\n",size); | ||||
| 	DPRINTF(E_DBG,L_SCAN,"Header length: %d\n",size); | ||||
|     } | ||||
| 
 | ||||
|     file_size -= fp_size; | ||||
| 
 | ||||
|     fseek(infile,fp_size,SEEK_SET); | ||||
|     if(fread(buffer,1,sizeof(buffer),infile) < sizeof(buffer)) { | ||||
| 	DPRINTF(ERR_LOG,"Short file: %s\n",file); | ||||
| 	DPRINTF(E_LOG,L_SCAN,"Short file: %s\n",file); | ||||
| 	return -1; | ||||
|     } | ||||
| 
 | ||||
| @ -1186,7 +1186,7 @@ int scan_get_mp3fileinfo(char *file, MP3FILE *pmp3) { | ||||
|     } | ||||
| 
 | ||||
|     if(index) { | ||||
| 	DPRINTF(ERR_DEBUG,"Scanned forward %d bytes to find frame header\n",index); | ||||
| 	DPRINTF(E_DBG,L_SCAN,"Scanned forward %d bytes to find frame header\n",index); | ||||
|     } | ||||
| 
 | ||||
|     if((buffer[index] == 0xFF)&&(buffer[index+1] >= 224)) { | ||||
| @ -1223,12 +1223,12 @@ int scan_get_mp3fileinfo(char *file, MP3FILE *pmp3) { | ||||
| 	} | ||||
| 
 | ||||
| 	if((layer_index < 0) || (layer_index > 4)) { | ||||
| 	    DPRINTF(ERR_LOG,"Bad mp3 header in %s: bad layer_index\n",file); | ||||
| 	    DPRINTF(E_LOG,L_SCAN,"Bad mp3 header in %s: bad layer_index\n",file); | ||||
| 	    return -1; | ||||
| 	} | ||||
| 
 | ||||
| 	if((sample_index < 0) || (sample_index > 2)) { | ||||
| 	    DPRINTF(ERR_LOG,"Bad mp3 header in %s: bad sample_index\n",file); | ||||
| 	    DPRINTF(E_LOG,L_SCAN,"Bad mp3 header in %s: bad sample_index\n",file); | ||||
| 	    return -1; | ||||
| 	} | ||||
| 
 | ||||
| @ -1243,10 +1243,10 @@ int scan_get_mp3fileinfo(char *file, MP3FILE *pmp3) { | ||||
| 	    stereo=0; | ||||
| 	else | ||||
| 	    stereo=1; | ||||
| 	DPRINTF(ERR_DEBUG," MPEG Version: %s\n",ver == 3 ? "1" : (ver == 2 ? "2" : "2.5")); | ||||
| 	DPRINTF(ERR_DEBUG," Layer: %d\n",4-layer); | ||||
| 	DPRINTF(ERR_DEBUG," Sample Rate: %d\n",samplerate); | ||||
| 	DPRINTF(ERR_DEBUG," Bit Rate: %d\n",bitrate); | ||||
| 	DPRINTF(E_DBG,L_SCAN," MPEG Version: %s\n",ver == 3 ? "1" : (ver == 2 ? "2" : "2.5")); | ||||
| 	DPRINTF(E_DBG,L_SCAN," Layer: %d\n",4-layer); | ||||
| 	DPRINTF(E_DBG,L_SCAN," Sample Rate: %d\n",samplerate); | ||||
| 	DPRINTF(E_DBG,L_SCAN," Bit Rate: %d\n",bitrate); | ||||
| 
 | ||||
| 	/* guesstimate the file length */ | ||||
| 	if(!pmp3->song_length) /* could have gotten it from the tag */ | ||||
| @ -1263,7 +1263,7 @@ int scan_get_mp3fileinfo(char *file, MP3FILE *pmp3) { | ||||
|     } else { | ||||
| 	/* FIXME: should really scan forward to next sync frame */ | ||||
| 	fclose(infile); | ||||
| 	DPRINTF(ERR_DEBUG,"Could not find sync frame\n"); | ||||
| 	DPRINTF(E_DBG,L_SCAN,"Could not find sync frame\n"); | ||||
| 	return 0; | ||||
|     } | ||||
|      | ||||
|  | ||||
| @ -226,10 +226,10 @@ void pl_register(void) { | ||||
|     SMART_PLAYLIST *pcurrent; | ||||
| 
 | ||||
|     /* register the playlists */ | ||||
|     DPRINTF(ERR_INFO,"Finished loading smart playlists\n"); | ||||
|     DPRINTF(E_INF,L_PL,"Finished loading smart playlists\n"); | ||||
|     pcurrent=pl_smart.next; | ||||
|     while(pcurrent) { | ||||
| 	DPRINTF(ERR_INFO,"Adding smart playlist %s as %d\n",pcurrent->name,pcurrent->id) | ||||
| 	DPRINTF(E_INF,L_PL,"Adding smart playlist %s as %d\n",pcurrent->name,pcurrent->id) | ||||
| 	    db_add_playlist(pcurrent->id, pcurrent->name,1); | ||||
| 	pcurrent=pcurrent->next; | ||||
|     } | ||||
| @ -246,7 +246,7 @@ void pl_eval(MP3FILE *pmp3) { | ||||
|     pcurrent=pl_smart.next; | ||||
|     while(pcurrent) { | ||||
| 	if(pl_eval_node(pmp3,pcurrent->root)) { | ||||
| 	    DPRINTF(ERR_DEBUG,"Matched song to playlist %s (%d)\n",pcurrent->name,pcurrent->id); | ||||
| 	    DPRINTF(E_DBG,L_PL,"Match song to playlist %s (%d)\n",pcurrent->name,pcurrent->id); | ||||
| 	    db_add_playlist_song(pcurrent->id, pmp3->id); | ||||
| 	} | ||||
| 
 | ||||
| @ -326,7 +326,7 @@ int pl_eval_node(MP3FILE *pmp3, PL_NODE *pnode) { | ||||
| 	ival=pmp3->time_added; | ||||
| 	break; | ||||
|     default: | ||||
| 	DPRINTF(ERR_FATAL,"Unknown token in playlist.  This can't happen!\n\n"); | ||||
| 	DPRINTF(E_FATAL,L_PL,"Unknown token in playlist.  This can't happen!\n\n"); | ||||
| 	break; | ||||
|     } | ||||
| 
 | ||||
| @ -338,7 +338,7 @@ int pl_eval_node(MP3FILE *pmp3, PL_NODE *pnode) { | ||||
| 	if(!cval)  | ||||
| 	    cval = ""; | ||||
| 
 | ||||
| 	DPRINTF(ERR_DEBUG,"Matching %s to %s\n",cval,pnode->arg2.cval); | ||||
| 	DPRINTF(E_DBG,L_PL,"Matching %s to %s\n",cval,pnode->arg2.cval); | ||||
| 
 | ||||
| 	switch(boolarg) { | ||||
| 	case IS: | ||||
| @ -353,7 +353,7 @@ int pl_eval_node(MP3FILE *pmp3, PL_NODE *pnode) { | ||||
|     } | ||||
| 
 | ||||
|     if(pnode->type==T_DATE) { | ||||
| 	DPRINTF(ERR_DEBUG,"Comparing (datewise) %d to %d\n",ival,pnode->arg2.ival); | ||||
| 	DPRINTF(E_DBG,L_PL,"Comparing (datewise) %d to %d\n",ival,pnode->arg2.ival); | ||||
| 	switch(boolarg) { | ||||
| 	case BEFORE: | ||||
| 	    r_arg=(ival < pnode->arg2.ival); | ||||
| @ -366,7 +366,7 @@ int pl_eval_node(MP3FILE *pmp3, PL_NODE *pnode) { | ||||
|     } | ||||
| 
 | ||||
|     if(pnode->type==T_INT) { | ||||
| 	DPRINTF(ERR_DEBUG,"Comparing %d to %d\n",ival,pnode->arg2.ival); | ||||
| 	DPRINTF(E_DBG,L_PL,"Comparing %d to %d\n",ival,pnode->arg2.ival); | ||||
| 
 | ||||
| 	switch(boolarg) { | ||||
| 	case EQUALS: | ||||
| @ -388,7 +388,7 @@ int pl_eval_node(MP3FILE *pmp3, PL_NODE *pnode) { | ||||
| 	retval = not? !r_arg : r_arg; | ||||
|     } | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Returning %d\n",retval); | ||||
|     DPRINTF(E_DBG,L_PL,"Returning %d\n",retval); | ||||
|     return retval; | ||||
| } | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										40
									
								
								src/query.c
									
									
									
									
									
								
							
							
						
						
									
										40
									
								
								src/query.c
									
									
									
									
									
								
							| @ -62,7 +62,7 @@ query_node_t* query_build(const char* query, const query_field_t* fields) | ||||
| 	case ' ':	join = qot_and;		break; | ||||
| 	case ',':	join = qot_or;		break; | ||||
| 	default: | ||||
| 	    DPRINTF(ERR_LOG, "Illegal character '%c' (0%o) at index %d: %s\n", | ||||
| 	    DPRINTF(E_LOG,L_QRY, "Illegal character '%c' (0%o) at index %d: %s\n", | ||||
| 		    *cursor, *cursor, cursor - raw, raw); | ||||
| 	    goto error; | ||||
| 	} | ||||
| @ -104,7 +104,7 @@ static query_node_t*	match_specifier(const char* query, | ||||
|     case '(':		return group_match(query, cursor, fields); | ||||
|     } | ||||
| 
 | ||||
|     DPRINTF(ERR_LOG, "Illegal character '%c' (0%o) at index %d: %s\n", | ||||
|     DPRINTF(E_LOG,L_QRY,"Illegal character '%c' (0%o) at index %d: %s\n", | ||||
| 	    **cursor, **cursor, *cursor - query, query); | ||||
|     return NULL; | ||||
| } | ||||
| @ -137,7 +137,7 @@ static query_node_t*	group_match(const char* query, | ||||
| 	break; | ||||
| 
 | ||||
|     default: | ||||
| 	DPRINTF(ERR_LOG, "Illegal character '%c' (0%o) at index %d: %s\n", | ||||
| 	DPRINTF(E_LOG,L_QRY,"Illegal character '%c' (0%o) at index %d: %s\n", | ||||
| 		*cursor, *cursor, cursor - query, query); | ||||
| 	goto error; | ||||
|     } | ||||
| @ -147,7 +147,7 @@ static query_node_t*	group_match(const char* query, | ||||
| 
 | ||||
|     if(*cursor != ')') | ||||
|     { | ||||
| 	DPRINTF(ERR_LOG, "Illegal character '%c' (0%o) at index %d: %s\n", | ||||
| 	DPRINTF(E_LOG,L_QRY,"Illegal character '%c' (0%o) at index %d: %s\n", | ||||
| 		*cursor, *cursor, cursor - query, query); | ||||
| 	goto error; | ||||
|     } | ||||
| @ -200,14 +200,14 @@ static query_node_t*	single_match(const char* query, | ||||
|     } | ||||
|     else | ||||
|     { | ||||
| 	DPRINTF(ERR_LOG, "Illegal Operator: %c (0%o) at index %d: %s\n", | ||||
| 	DPRINTF(E_LOG,L_QRY,"Illegal Operator: %c (0%o) at index %d: %s\n", | ||||
| 		**pcursor, **pcursor, *pcursor - query, query); | ||||
| 	return NULL; | ||||
|     } | ||||
| 
 | ||||
|     if(0 == (field = find_field(fname, fields))) | ||||
|     { | ||||
| 	DPRINTF(ERR_LOG, "Unknown field: %s\n", fname); | ||||
| 	DPRINTF(E_LOG,L_QRY,"Unknown field: %s\n", fname); | ||||
| 	return NULL; | ||||
|     } | ||||
| 
 | ||||
| @ -223,13 +223,13 @@ static query_node_t*	single_match(const char* query, | ||||
| 	break; | ||||
| 
 | ||||
|     default: | ||||
| 	DPRINTF(ERR_LOG, "Invalid field type: %d\n", field->type); | ||||
| 	DPRINTF(E_LOG,L_QRY,"Invalid field type: %d\n", field->type); | ||||
| 	break; | ||||
|     } | ||||
| 
 | ||||
|     if(**pcursor != '\'') | ||||
|     { | ||||
| 	DPRINTF(ERR_LOG, "Illegal Character: %c (0%o) index %d: %s\n", | ||||
| 	DPRINTF(E_LOG,L_QRY,"Illegal Character: %c (0%o) index %d: %s\n", | ||||
| 		**pcursor, **pcursor, *pcursor - query, query); | ||||
| 	query_free(node); | ||||
| 	node = 0; | ||||
| @ -254,7 +254,7 @@ static int		get_field_name(const char** pcursor, | ||||
|     { | ||||
| 	if(--len <= 0) | ||||
| 	{ | ||||
| 	    DPRINTF(ERR_LOG, "token length exceeded at offset %d: %s\n", | ||||
| 	    DPRINTF(E_LOG,L_QRY,"token length exceeded at offset %d: %s\n", | ||||
| 		    cursor - query, query); | ||||
| 	    return 0; | ||||
| 	} | ||||
| @ -304,7 +304,7 @@ static query_node_t*	match_number(const query_field_t* field, | ||||
| 
 | ||||
|     if(**pcursor != '\'') | ||||
|     { | ||||
| 	DPRINTF(ERR_LOG, "Illegal char in number '%c' (0%o) at index %d: %s\n", | ||||
| 	DPRINTF(E_LOG,L_QRY,"Illegal char in number '%c' (0%o) at index %d: %s\n", | ||||
| 		**pcursor, **pcursor, *pcursor - query, query); | ||||
| 	free(node); | ||||
| 	return 0; | ||||
| @ -327,7 +327,7 @@ static query_node_t*	match_string(const query_field_t* field, | ||||
| 
 | ||||
|     if(opcode != ':') | ||||
|     { | ||||
| 	DPRINTF(ERR_LOG, "Illegal operation on string: %c at index %d: %s\n", | ||||
| 	DPRINTF(E_LOG,L_QRY,"Illegal operation on string: %c at index %d: %s\n", | ||||
| 		opcode, cursor - query - 1); | ||||
| 	return NULL; | ||||
|     } | ||||
| @ -342,7 +342,7 @@ static query_node_t*	match_string(const query_field_t* field, | ||||
|     { | ||||
| 	if(--left == 0) | ||||
| 	{ | ||||
| 	    DPRINTF(ERR_LOG, "string too long at index %d: %s\n", | ||||
| 	    DPRINTF(E_LOG,L_QRY,"string too long at index %d: %s\n", | ||||
| 		    cursor - query, query); | ||||
| 	    return NULL; | ||||
| 	} | ||||
| @ -357,7 +357,7 @@ static query_node_t*	match_string(const query_field_t* field, | ||||
| 		*dst++ = *cursor++; | ||||
| 		break; | ||||
| 	    default: | ||||
| 		DPRINTF(ERR_LOG, "Illegal escape: %c (0%o) at index %d: %s\n", | ||||
| 		DPRINTF(E_LOG,L_QRY,"Illegal escape: %c (0%o) at index %d: %s\n", | ||||
| 			*cursor, *cursor, cursor - query, query); | ||||
| 		return NULL; | ||||
| 	    } | ||||
| @ -464,7 +464,7 @@ void query_free(query_node_t* query) | ||||
| 	    break; | ||||
| 	     | ||||
| 	default: | ||||
| 	    DPRINTF(ERR_LOG, "Illegal query type: %d\n", query->type); | ||||
| 	    DPRINTF(E_LOG,L_QRY,"Illegal query type: %d\n", query->type); | ||||
| 	    break; | ||||
| 	} | ||||
| 
 | ||||
| @ -479,7 +479,7 @@ static const query_field_t* find_field(const char* name, const query_field_t* fi | ||||
| 
 | ||||
|     if(fields->name == 0) | ||||
|     { | ||||
| 	DPRINTF(ERR_LOG, "Illegal query field: %s\n", name); | ||||
| 	DPRINTF(E_LOG,L_QRY,"Illegal query field: %s\n", name); | ||||
| 	return NULL; | ||||
|     } | ||||
| 
 | ||||
| @ -507,7 +507,7 @@ static int arith_query(query_node_t* query, void* target) | ||||
| 	    case qot_ge:	return tv >= 0; | ||||
| 	    case qot_gt:	return tv > 0; | ||||
| 	    default: | ||||
| 		DPRINTF(ERR_LOG, "illegal query type: %d\n", query->type); | ||||
| 		DPRINTF(E_LOG,L_QRY,"illegal query type: %d\n", query->type); | ||||
| 		break; | ||||
| 	    } | ||||
| 	} | ||||
| @ -528,14 +528,14 @@ static int arith_query(query_node_t* query, void* target) | ||||
| 	    case qot_ge:	return tv >= 0; | ||||
| 	    case qot_gt:	return tv > 0; | ||||
| 	    default: | ||||
| 		DPRINTF(ERR_LOG, "illegal query type: %d\n", query->type); | ||||
| 		DPRINTF(E_LOG,L_QRY,"illegal query type: %d\n", query->type); | ||||
| 		break; | ||||
| 	    } | ||||
| 	} | ||||
| 	break; | ||||
| 
 | ||||
|     default: | ||||
| 	DPRINTF(ERR_LOG, "illegal field type: %d\n", field->type); | ||||
| 	DPRINTF(E_LOG,L_QRY,"illegal field type: %d\n", field->type); | ||||
| 	break; | ||||
|     } | ||||
|      | ||||
| @ -549,7 +549,7 @@ static int string_query(query_node_t* query, void* target) | ||||
| 
 | ||||
|     if(field->type != qft_string) | ||||
|     { | ||||
| 	DPRINTF(ERR_LOG, "illegal field type: %d\n", field->type); | ||||
| 	DPRINTF(E_LOG,L_QRY,"illegal field type: %d\n", field->type); | ||||
| 	return 0; | ||||
|     } | ||||
| 
 | ||||
| @ -580,7 +580,7 @@ static int string_query(query_node_t* query, void* target) | ||||
| 	return (int) strcasestr(ts, query->right.str); /* returns null if not found */ | ||||
| 
 | ||||
|     default: | ||||
| 	DPRINTF(ERR_LOG, "Illegal query type: %d\n", query->type); | ||||
| 	DPRINTF(E_LOG,L_QRY,"Illegal query type: %d\n", query->type); | ||||
| 	break; | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -60,7 +60,7 @@ static sw_result rend_howl_reply(sw_rendezvous_publish_handler handler, | ||||
| 	"invalid" | ||||
|     }; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Publish reply: %s\n",status_text[status]); | ||||
|     DPRINTF(E_DBG,L_REND,"Publish reply: %s\n",status_text[status]); | ||||
|     return SW_OKAY; | ||||
| } | ||||
| 
 | ||||
| @ -73,11 +73,11 @@ static sw_result rend_howl_reply(sw_rendezvous_publish_handler handler, | ||||
| int rend_private_init(char *user) { | ||||
|     sw_result result; | ||||
|      | ||||
|     DPRINTF(ERR_DEBUG,"Starting rendezvous services\n"); | ||||
|     DPRINTF(E_DBG,L_REND,"Starting rendezvous services\n"); | ||||
|     signal(SIGHUP,  SIG_IGN);           // SIGHUP might happen from a request to reload the daap server
 | ||||
| 
 | ||||
|     if(sw_rendezvous_init(&rend_handle) != SW_OKAY) { | ||||
| 	DPRINTF(ERR_WARN,"Error initializing rendezvous\n"); | ||||
| 	DPRINTF(E_WARN,L_REND,"Error initializing rendezvous\n"); | ||||
| 	errno=EINVAL; | ||||
| 	return -1; | ||||
|     } | ||||
| @ -85,19 +85,19 @@ int rend_private_init(char *user) { | ||||
|     if(drop_privs(user))  | ||||
| 	return -1; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Starting polling thread\n"); | ||||
|     DPRINTF(E_DBG,L_REND,"Starting polling thread\n"); | ||||
|      | ||||
|     if(pthread_create(&rend_tid,NULL,rend_pipe_monitor,NULL)) { | ||||
| 	DPRINTF(ERR_FATAL,"Could not start thread.  Terminating\n"); | ||||
| 	DPRINTF(E_FATAL,L_REND,"Could not start thread.  Terminating\n"); | ||||
| 	/* should kill parent, too */ | ||||
| 	exit(EXIT_FAILURE); | ||||
|     } | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Entering runloop\n"); | ||||
|     DPRINTF(E_DBG,L_REND,"Entering runloop\n"); | ||||
| 
 | ||||
|     sw_rendezvous_run(rend_handle); | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Exiting runloop\n"); | ||||
|     DPRINTF(E_DBG,L_REND,"Exiting runloop\n"); | ||||
| 
 | ||||
|     return 0; | ||||
| } | ||||
| @ -111,7 +111,7 @@ void *rend_pipe_monitor(void* arg) { | ||||
|     int result; | ||||
| 
 | ||||
|     while(1) { | ||||
| 	DPRINTF(ERR_DEBUG,"Waiting for data\n"); | ||||
| 	DPRINTF(E_DBG,L_REND,"Waiting for data\n"); | ||||
| 	FD_ZERO(&rset); | ||||
| 	FD_SET(rend_pipe_to[RD_SIDE],&rset); | ||||
| 
 | ||||
| @ -119,12 +119,12 @@ void *rend_pipe_monitor(void* arg) { | ||||
| 	while(((result=select(rend_pipe_to[RD_SIDE] + 1,&rset,NULL,NULL,NULL)) != -1) && | ||||
| 	    errno != EINTR) { | ||||
| 	    if(FD_ISSET(rend_pipe_to[RD_SIDE],&rset)) { | ||||
| 		DPRINTF(ERR_DEBUG,"Received a message from daap server\n"); | ||||
| 		DPRINTF(E_DBG,L_REND,"Received a message from daap server\n"); | ||||
| 		rend_callback(); | ||||
| 	    } | ||||
| 	} | ||||
| 
 | ||||
| 	DPRINTF(ERR_DEBUG,"Select error!\n"); | ||||
| 	DPRINTF(E_DBG,L_REND,"Select error!\n"); | ||||
| 	/* should really bail here */ | ||||
|     } | ||||
| } | ||||
| @ -144,33 +144,33 @@ void rend_callback(void) { | ||||
|     /* here, we've seen the message, now we have to process it */ | ||||
| 
 | ||||
|     if(rend_read_message(&msg) != sizeof(msg)) { | ||||
| 	DPRINTF(ERR_FATAL,"Error reading rendezvous message\n"); | ||||
| 	DPRINTF(E_FATAL,L_REND,"Error reading rendezvous message\n"); | ||||
| 	exit(EXIT_FAILURE); | ||||
|     } | ||||
| 
 | ||||
|     switch(msg.cmd) { | ||||
|     case REND_MSG_TYPE_REGISTER: | ||||
| 	DPRINTF(ERR_DEBUG,"Registering %s.%s (%d)\n",msg.type,msg.name,msg.port); | ||||
| 	DPRINTF(E_DBG,L_REND,"Registering %s.%s (%d)\n",msg.type,msg.name,msg.port); | ||||
| 	if((result=sw_rendezvous_publish(rend_handle,msg.name,msg.type,NULL,NULL,msg.port,NULL,0, | ||||
| 					 NULL,rend_howl_reply,NULL,&rend_id)) != SW_OKAY) { | ||||
| 	    DPRINTF(ERR_WARN,"Error registering name\n"); | ||||
| 	    DPRINTF(E_WARN,L_REND,"Error registering name\n"); | ||||
| 	    rend_send_response(-1); | ||||
| 	} else { | ||||
| 	    rend_send_response(0); /* success */ | ||||
| 	} | ||||
| 	break; | ||||
|     case REND_MSG_TYPE_UNREGISTER: | ||||
| 	DPRINTF(ERR_WARN,"Unsupported function: UNREGISTER\n"); | ||||
| 	DPRINTF(E_WARN,L_REND,"Unsupported function: UNREGISTER\n"); | ||||
| 	rend_send_response(-1); /* error */ | ||||
| 	break; | ||||
|     case REND_MSG_TYPE_STOP: | ||||
| 	DPRINTF(ERR_DEBUG,"Stopping mDNS\n"); | ||||
| 	DPRINTF(E_DBG,L_REND,"Stopping mDNS\n"); | ||||
| 	rend_send_response(0); | ||||
| 	//sw_rendezvous_stop_publish(rend_handle);
 | ||||
| 	sw_rendezvous_fina(rend_handle); | ||||
| 	break; | ||||
|     case REND_MSG_TYPE_STATUS: | ||||
| 	DPRINTF(ERR_DEBUG,"Status inquiry -- returning 0\n"); | ||||
| 	DPRINTF(E_DBG,L_REND,"Status inquiry -- returning 0\n"); | ||||
| 	rend_send_response(0); /* success */ | ||||
| 	break; | ||||
|     default: | ||||
|  | ||||
| @ -55,7 +55,7 @@ static void rend_stoprunloop(void) { | ||||
|  * rend_sigint | ||||
|  */ | ||||
| static void rend_sigint(int sigraised) { | ||||
|     DPRINTF(ERR_INFO,"SIGINT\n"); | ||||
|     DPRINTF(E_INF,L_REND,"SIGINT\n"); | ||||
|     rend_stoprunloop(); | ||||
| } | ||||
| 
 | ||||
| @ -95,13 +95,13 @@ static int rend_addtorunloop(dns_service_discovery_ref client) { | ||||
| static void rend_reply(DNSServiceRegistrationReplyErrorType errorCode, void *context) { | ||||
|     switch(errorCode) { | ||||
|     case kDNSServiceDiscoveryNoError: | ||||
| 	DPRINTF(ERR_DEBUG,"Registered successfully\n"); | ||||
| 	DPRINTF(E_DBG,L_REND,"Registered successfully\n"); | ||||
| 	break; | ||||
|     case kDNSServiceDiscoveryNameConflict: | ||||
| 	DPRINTF(ERR_WARN,"Error - name in use\n"); | ||||
| 	DPRINTF(E_WARN,L_REND,"Error - name in use\n"); | ||||
| 	break; | ||||
|     default: | ||||
| 	DPRINTF(ERR_WARN,"Error %d\n",errorCode); | ||||
| 	DPRINTF(E_WARN,L_REND,"Error %d\n",errorCode); | ||||
| 	break; | ||||
|     } | ||||
| } | ||||
| @ -115,7 +115,7 @@ void *rend_pipe_monitor(void* arg) { | ||||
| 
 | ||||
| 
 | ||||
|     while(1) { | ||||
| 	DPRINTF(ERR_DEBUG,"Waiting for data\n"); | ||||
| 	DPRINTF(E_DBG,L_REND,"Waiting for data\n"); | ||||
| 	FD_ZERO(&rset); | ||||
| 	FD_SET(rend_pipe_to[RD_SIDE],&rset); | ||||
| 
 | ||||
| @ -123,14 +123,14 @@ void *rend_pipe_monitor(void* arg) { | ||||
| 	while(((result=select(rend_pipe_to[RD_SIDE] + 1,&rset,NULL,NULL,NULL)) != -1) && | ||||
| 	    errno != EINTR) { | ||||
| 	    if(FD_ISSET(rend_pipe_to[RD_SIDE],&rset)) { | ||||
| 		DPRINTF(ERR_DEBUG,"Received a message from daap server\n"); | ||||
| 		DPRINTF(E_DBG,L_REND,"Received a message from daap server\n"); | ||||
| 		CFRunLoopSourceSignal(rend_rls); | ||||
| 		CFRunLoopWakeUp(rend_runloop); | ||||
| 		sleep(1);  /* force a reschedule, hopefully */ | ||||
| 	    } | ||||
| 	} | ||||
| 
 | ||||
| 	DPRINTF(ERR_DEBUG,"Select error!\n"); | ||||
| 	DPRINTF(E_DBG,L_REND,"Select error!\n"); | ||||
| 	/* should really bail here */ | ||||
|     } | ||||
| } | ||||
| @ -150,33 +150,33 @@ void rend_callback(void *info) { | ||||
|     /* here, we've seen the message, now we have to process it */ | ||||
| 
 | ||||
|     if(rend_read_message(&msg) != sizeof(msg)) { | ||||
| 	DPRINTF(ERR_FATAL,"Error reading rendezvous message\n"); | ||||
| 	DPRINTF(E_FATAL,L_REND,"Error reading rendezvous message\n"); | ||||
| 	exit(EXIT_FAILURE); | ||||
|     } | ||||
| 
 | ||||
|     switch(msg.cmd) { | ||||
|     case REND_MSG_TYPE_REGISTER: | ||||
| 	DPRINTF(ERR_DEBUG,"Registering %s.%s (%d)\n",msg.type,msg.name,msg.port); | ||||
| 	DPRINTF(E_DBG,L_REND,"Registering %s.%s (%d)\n",msg.type,msg.name,msg.port); | ||||
| 	usPort=msg.port; | ||||
| 	dns_ref=DNSServiceRegistrationCreate(msg.name,msg.type,"",usPort,"",rend_reply,nil); | ||||
| 	if(rend_addtorunloop(dns_ref)) { | ||||
| 	    DPRINTF(ERR_WARN,"Add to runloop failed\n"); | ||||
| 	    DPRINTF(E_WARN,L_REND,"Add to runloop failed\n"); | ||||
| 	    rend_send_response(-1); | ||||
| 	} else { | ||||
| 	    rend_send_response(0); /* success */ | ||||
| 	} | ||||
| 	break; | ||||
|     case REND_MSG_TYPE_UNREGISTER: | ||||
| 	DPRINTF(ERR_WARN,"Unsupported function: UNREGISTER\n"); | ||||
| 	DPRINTF(E_WARN,L_REND,"Unsupported function: UNREGISTER\n"); | ||||
| 	rend_send_response(-1); /* error */ | ||||
| 	break; | ||||
|     case REND_MSG_TYPE_STOP: | ||||
| 	DPRINTF(ERR_DEBUG,"Stopping mDNS\n"); | ||||
| 	DPRINTF(E_DBG,L_REND,"Stopping mDNS\n"); | ||||
| 	rend_send_response(0); | ||||
| 	rend_stoprunloop(); | ||||
| 	break; | ||||
|     case REND_MSG_TYPE_STATUS: | ||||
| 	DPRINTF(ERR_DEBUG,"Status inquiry -- returning 0\n"); | ||||
| 	DPRINTF(E_DBG,L_REND,"Status inquiry -- returning 0\n"); | ||||
| 	rend_send_response(0); /* success */ | ||||
| 	break; | ||||
|     default: | ||||
| @ -196,7 +196,7 @@ int rend_private_init(char *user) { | ||||
| 	return -1; | ||||
| 
 | ||||
|     /* need a sigint handler */ | ||||
|     DPRINTF(ERR_DEBUG,"Starting rendezvous services\n"); | ||||
|     DPRINTF(E_DBG,L_REND,"Starting rendezvous services\n"); | ||||
| 
 | ||||
|     memset((void*)&context,0,sizeof(context)); | ||||
|     context.perform = rend_callback; | ||||
| @ -205,19 +205,19 @@ int rend_private_init(char *user) { | ||||
|     rend_rls = CFRunLoopSourceCreate(NULL,0,&context); | ||||
|     CFRunLoopAddSource(CFRunLoopGetCurrent(),rend_rls,kCFRunLoopDefaultMode); | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Starting polling thread\n"); | ||||
|     DPRINTF(E_DBG,L_REND,"Starting polling thread\n"); | ||||
|      | ||||
|     if(pthread_create(&rend_tid,NULL,rend_pipe_monitor,NULL)) { | ||||
| 	DPRINTF(ERR_FATAL,"Could not start thread.  Terminating\n"); | ||||
| 	DPRINTF(E_FATAL,L_REND,"Could not start thread.  Terminating\n"); | ||||
| 	/* should kill parent, too */ | ||||
| 	exit(EXIT_FAILURE); | ||||
|     } | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Starting runloop\n"); | ||||
|     DPRINTF(E_DBG,L_REND,"Starting runloop\n"); | ||||
| 
 | ||||
|     CFRunLoopRun(); | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Exiting runloop\n"); | ||||
|     DPRINTF(E_DBG,L_REND,"Exiting runloop\n"); | ||||
| 
 | ||||
|     CFRelease(rend_rls); | ||||
|     pthread_cancel(rend_tid); | ||||
|  | ||||
| @ -89,6 +89,9 @@ | ||||
|   Change History (most recent first): | ||||
| 
 | ||||
|   $Log$ | ||||
|   Revision 1.19  2004/11/13 07:14:26  rpedde | ||||
|   modularize debugging statements | ||||
| 
 | ||||
|   Revision 1.18  2004/04/19 06:19:46  rpedde | ||||
|   Starting to fix signal stuff | ||||
| 
 | ||||
| @ -203,7 +206,7 @@ static void HandleSigInt(int sigraised) | ||||
| { | ||||
|     assert(sigraised == SIGINT); | ||||
| 
 | ||||
|     DPRINTF(ERR_INFO,"SIGINT\n"); | ||||
|     DPRINTF(E_INF,L_REND,"SIGINT\n"); | ||||
|     gStopNow = mDNStrue; | ||||
| } | ||||
| 
 | ||||
| @ -216,7 +219,7 @@ static void HandleSigQuit(int sigraised) | ||||
| { | ||||
|     assert(sigraised == SIGQUIT); | ||||
| 
 | ||||
|     DPRINTF(ERR_INFO,"SIGQUIT\n"); | ||||
|     DPRINTF(E_INF,L_REND,"SIGQUIT\n"); | ||||
| 
 | ||||
|     mDNS_Close(&mDNSStorage); | ||||
|     exit(0); | ||||
| @ -249,13 +252,13 @@ static void RegistrationCallback(mDNS *const m, ServiceRecordSet *const thisRegi | ||||
|     switch (status) { | ||||
| 
 | ||||
|     case mStatus_NoError:       | ||||
| 	DPRINTF(ERR_DEBUG,"Callback: Name Registered\n"); | ||||
| 	DPRINTF(E_DBG,L_REND,"Callback: Name Registered\n"); | ||||
| 	// Do nothing; our name was successfully registered.  We may 
 | ||||
| 	// get more call backs in the future.
 | ||||
| 	break; | ||||
| 
 | ||||
|     case mStatus_NameConflict:  | ||||
| 	DPRINTF(ERR_WARN,"Callback: Name Conflict\n"); | ||||
| 	DPRINTF(E_WARN,L_REND,"Callback: Name Conflict\n"); | ||||
| 
 | ||||
| 	// In the event of a conflict, this sample RegistrationCallback 
 | ||||
| 	// just calls mDNS_RenameAndReregisterService to automatically 
 | ||||
| @ -273,7 +276,7 @@ static void RegistrationCallback(mDNS *const m, ServiceRecordSet *const thisRegi | ||||
| 	break; | ||||
| 
 | ||||
|     case mStatus_MemFree:       | ||||
| 	DPRINTF(ERR_WARN,"Callback: Memory Free\n"); | ||||
| 	DPRINTF(E_WARN,L_REND,"Callback: Memory Free\n"); | ||||
|              | ||||
| 	// When debugging is enabled, make sure that thisRegistration 
 | ||||
| 	// is not on our gServiceList.
 | ||||
| @ -293,7 +296,7 @@ static void RegistrationCallback(mDNS *const m, ServiceRecordSet *const thisRegi | ||||
| 	break; | ||||
| 
 | ||||
|     default:                    | ||||
| 	DPRINTF(ERR_WARN,"Callback: Unknown Status %d\n",status);  | ||||
| 	DPRINTF(E_WARN,L_REND,"Callback: Unknown Status %d\n",status);  | ||||
| 	break; | ||||
|     } | ||||
| } | ||||
| @ -342,7 +345,7 @@ static mStatus RegisterOneService(const char *  richTextHostName, | ||||
|         thisServ->next = gServiceList; | ||||
|         gServiceList = thisServ; | ||||
| 
 | ||||
| 	DPRINTF(ERR_DEBUG, | ||||
| 	DPRINTF(E_DBG,L_REND, | ||||
| 		"Registered service %d, name '%s', type '%s', domain '%s', port %ld\n",  | ||||
| 		thisServ->serviceID,  | ||||
| 		richTextHostName, | ||||
| @ -370,7 +373,7 @@ static void DeregisterOurServices(void) | ||||
|          | ||||
|         mDNS_DeregisterService(&mDNSStorage, &thisServ->coreServ); | ||||
| 
 | ||||
| 	DPRINTF(ERR_DEBUG,"Deregistered service %d\n", | ||||
| 	DPRINTF(E_DBG,L_REND,"Deregistered service %d\n", | ||||
| 		thisServ->serviceID); | ||||
|     } | ||||
| } | ||||
| @ -385,21 +388,21 @@ void rend_callback(void) { | ||||
|     int result; | ||||
|     int err; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Processing rendezvous message\n"); | ||||
|     DPRINTF(E_DBG,L_REND,"Processing rendezvous message\n"); | ||||
| 
 | ||||
|     /* here, we've seen the message, now we have to process it */ | ||||
| 
 | ||||
|     if((result=rend_read_message(&msg)) != sizeof(msg)) { | ||||
| 	err=errno; | ||||
| 	DPRINTF(ERR_DEBUG,"Expected %d, got %d\n",sizeof(msg),result); | ||||
| 	DPRINTF(ERR_FATAL,"Rendezvous pipe closed... Exiting\n"); | ||||
| 	DPRINTF(E_DBG,L_REND,"Expected %d, got %d\n",sizeof(msg),result); | ||||
| 	DPRINTF(E_FATAL,L_REND,"Rendezvous pipe closed... Exiting\n"); | ||||
| 	gStopNow=mDNStrue; | ||||
| 	return; | ||||
|     } | ||||
| 
 | ||||
|     switch(msg.cmd) { | ||||
|     case REND_MSG_TYPE_REGISTER: | ||||
| 	DPRINTF(ERR_DEBUG,"Registering %s.%s (%d)\n",msg.name,msg.type,msg.port); | ||||
| 	DPRINTF(E_DBG,L_REND,"Registering %s.%s (%d)\n",msg.name,msg.type,msg.port); | ||||
| 	RegisterOneService(msg.name,msg.type,"local.",NULL,0,msg.port); | ||||
| 	rend_send_response(0); /* success */ | ||||
| 	break; | ||||
| @ -407,7 +410,7 @@ void rend_callback(void) { | ||||
| 	rend_send_response(1); /* error */ | ||||
| 	break; | ||||
|     case REND_MSG_TYPE_STOP: | ||||
| 	DPRINTF(ERR_INFO,"Stopping mDNS\n"); | ||||
| 	DPRINTF(E_INF,L_REND,"Stopping mDNS\n"); | ||||
| 	gStopNow = mDNStrue; | ||||
| 	rend_send_response(0); | ||||
| 	break; | ||||
| @ -431,7 +434,7 @@ int rend_private_init(char *user) { | ||||
| 		       mDNS_Init_NoInitCallback, mDNS_Init_NoInitCallbackContext); | ||||
|      | ||||
|     if (status != mStatus_NoError) { | ||||
| 	DPRINTF(ERR_FATAL,"mDNS Error %d\n",status); | ||||
| 	DPRINTF(E_FATAL,L_REND,"mDNS Error %d\n",status); | ||||
| 	return(-1); | ||||
|     } | ||||
| 
 | ||||
| @ -464,13 +467,13 @@ int rend_private_init(char *user) { | ||||
| 	mDNSPosixGetFDSet(&mDNSStorage, &nfds, &readfds, &timeout); | ||||
| 	 | ||||
| 	// 4. Call select as normal
 | ||||
| 	DPRINTF(ERR_DEBUG,"select(%d, %d.%06d)\n", nfds,  | ||||
| 	DPRINTF(E_DBG,L_REND,"select(%d, %d.%06d)\n", nfds,  | ||||
| 		timeout.tv_sec, timeout.tv_usec); | ||||
| 	 | ||||
| 	result = select(nfds, &readfds, NULL, NULL, &timeout); | ||||
| 	 | ||||
| 	if (result < 0) { | ||||
| 	    DPRINTF(ERR_WARN,"select() returned %d errno %d\n", result, errno); | ||||
| 	    DPRINTF(E_WARN,L_REND,"select() returned %d errno %d\n", result, errno); | ||||
| 	    if (errno != EINTR) gStopNow = mDNStrue; | ||||
| 	} else { | ||||
| 	    // 5. Call mDNSPosixProcessFDSet to let the mDNSPosix layer do its work
 | ||||
| @ -485,7 +488,7 @@ int rend_private_init(char *user) { | ||||
| 	} | ||||
|     } | ||||
|      | ||||
|     DPRINTF(ERR_DEBUG,"Exiting\n"); | ||||
|     DPRINTF(E_DBG,L_REND,"Exiting\n"); | ||||
|      | ||||
|     DeregisterOurServices(); | ||||
|     mDNS_Close(&mDNSStorage); | ||||
| @ -495,7 +498,7 @@ int rend_private_init(char *user) { | ||||
|     } else { | ||||
|         result = 2; | ||||
|     } | ||||
|     DPRINTF(ERR_DEBUG, "Finished with status %ld, result %d\n",  | ||||
|     DPRINTF(E_DBG,L_REND, "Finished with status %ld, result %d\n",  | ||||
| 	    status, result); | ||||
| 
 | ||||
|     exit(result); | ||||
|  | ||||
| @ -97,11 +97,11 @@ int rend_running(void) { | ||||
|     REND_MESSAGE msg; | ||||
|     int result; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Status inquiry\n"); | ||||
|     DPRINTF(E_DBG,L_REND,"Status inquiry\n"); | ||||
|     memset((void*)&msg,0x00,sizeof(msg)); | ||||
|     msg.cmd=REND_MSG_TYPE_STATUS; | ||||
|     result=rend_send_message(&msg); | ||||
|     DPRINTF(ERR_DEBUG,"Returning status %d\n",result); | ||||
|     DPRINTF(E_DBG,L_REND,"Returning status %d\n",result); | ||||
|     return result; | ||||
| } | ||||
| 
 | ||||
| @ -126,7 +126,7 @@ int rend_register(char *name, char *type, int port) { | ||||
|     REND_MESSAGE msg; | ||||
| 
 | ||||
|     if((strlen(name)+1 > MAX_NAME_LEN) || (strlen(type)+1 > MAX_NAME_LEN)) { | ||||
| 	DPRINTF(ERR_FATAL,"Registration failed: name or type too long\n"); | ||||
| 	DPRINTF(E_FATAL,L_REND,"Registration failed: name or type too long\n"); | ||||
| 	return -1; | ||||
|     } | ||||
| 
 | ||||
|  | ||||
							
								
								
									
										134
									
								
								src/webserver.c
									
									
									
									
									
								
							
							
						
						
									
										134
									
								
								src/webserver.c
									
									
									
									
									
								
							| @ -200,18 +200,18 @@ WSHANDLE ws_start(WSCONFIG *config) { | ||||
| 	return NULL; | ||||
|     } | ||||
| 
 | ||||
|     DPRINTF(ERR_INFO,"Preparing to listen on port %d\n",pwsp->wsconfig.port); | ||||
|     DPRINTF(E_INF,L_WS,"Preparing to listen on port %d\n",pwsp->wsconfig.port); | ||||
| 
 | ||||
|     if((pwsp->server_fd = u_open(pwsp->wsconfig.port)) == -1) { | ||||
| 	err=errno; | ||||
| 	DPRINTF(ERR_WARN,"Could not open port: %s\n",strerror(errno)); | ||||
| 	DPRINTF(E_WARN,L_WS,"Could not open port: %s\n",strerror(errno)); | ||||
| 	errno=err; | ||||
| 	return NULL; | ||||
|     } | ||||
| 
 | ||||
|     DPRINTF(ERR_INFO,"Starting server thread\n"); | ||||
|     DPRINTF(E_INF,L_WS,"Starting server thread\n"); | ||||
|     if((err=pthread_create(&pwsp->server_tid,NULL,ws_mainthread,(void*)pwsp))) { | ||||
| 	DPRINTF(ERR_WARN,"Could not spawn thread: %s\n",strerror(err)); | ||||
| 	DPRINTF(E_WARN,L_WS,"Could not spawn thread: %s\n",strerror(err)); | ||||
| 	r_close(pwsp->server_fd); | ||||
| 	errno=err; | ||||
| 	return NULL; | ||||
| @ -233,7 +233,7 @@ void ws_remove_dispatch_thread(WS_PRIVATE *pwsp, WS_CONNINFO *pwsc) { | ||||
|     WS_CONNLIST *pHead, *pTail; | ||||
| 
 | ||||
|     if(pthread_mutex_lock(&pwsp->exit_mutex)) | ||||
| 	DPRINTF(ERR_FATAL,"Cannot lock condition mutex\n"); | ||||
| 	DPRINTF(E_FATAL,L_WS,"Cannot lock condition mutex\n"); | ||||
| 
 | ||||
|     pTail=&(pwsp->connlist); | ||||
|     pHead=pwsp->connlist.next; | ||||
| @ -245,7 +245,7 @@ void ws_remove_dispatch_thread(WS_PRIVATE *pwsp, WS_CONNINFO *pwsc) { | ||||
| 
 | ||||
|     if(pHead) { | ||||
| 	pwsp->dispatch_threads--; | ||||
| 	DPRINTF(ERR_DEBUG,"With thread %d exiting, %d are still running\n", | ||||
| 	DPRINTF(E_DBG,L_WS,"With thread %d exiting, %d are still running\n", | ||||
| 		pwsc->threadno,pwsp->dispatch_threads); | ||||
| 
 | ||||
| 	pTail->next = pHead->next; | ||||
| @ -276,10 +276,10 @@ void ws_add_dispatch_thread(WS_PRIVATE *pwsp, WS_CONNINFO *pwsc) { | ||||
|     pNew->status=strdup("Initializing"); | ||||
| 
 | ||||
|     if(!pNew) | ||||
| 	DPRINTF(ERR_FATAL,"Malloc: %s\n",strerror(errno)); | ||||
| 	DPRINTF(E_FATAL,L_WS,"Malloc: %s\n",strerror(errno)); | ||||
|      | ||||
|     if(pthread_mutex_lock(&pwsp->exit_mutex)) | ||||
| 	DPRINTF(ERR_FATAL,"Cannot lock condition mutex\n"); | ||||
| 	DPRINTF(E_FATAL,L_WS,"Cannot lock condition mutex\n"); | ||||
| 
 | ||||
|     /* list is locked... */ | ||||
|     pwsp->dispatch_threads++; | ||||
| @ -300,7 +300,7 @@ extern int ws_stop(WSHANDLE ws) { | ||||
|     WS_CONNLIST *pcl; | ||||
|     void *result; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"ws_stop: %d threads\n",pwsp->dispatch_threads); | ||||
|     DPRINTF(E_DBG,L_WS,"ws_stop: %d threads\n",pwsp->dispatch_threads); | ||||
| 
 | ||||
|     /* free the ws_handlers */ | ||||
|     while(pwsp->handlers.next) { | ||||
| @ -313,7 +313,7 @@ extern int ws_stop(WSHANDLE ws) { | ||||
|     pwsp->stop=1; | ||||
|     pwsp->running=0; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"ws_stop: closing the server fd\n"); | ||||
|     DPRINTF(E_DBG,L_WS,"ws_stop: closing the server fd\n"); | ||||
|     shutdown(pwsp->server_fd,SHUT_RDWR); | ||||
|     r_close(pwsp->server_fd); /* this should tick off the listener */ | ||||
|      | ||||
| @ -322,7 +322,7 @@ extern int ws_stop(WSHANDLE ws) { | ||||
| 
 | ||||
|     /* Give the threads an extra push */ | ||||
|     if(pthread_mutex_lock(&pwsp->exit_mutex)) | ||||
| 	DPRINTF(ERR_FATAL,"Cannot lock condition mutex\n"); | ||||
| 	DPRINTF(E_FATAL,L_WS,"Cannot lock condition mutex\n"); | ||||
| 
 | ||||
|     pcl=pwsp->connlist.next; | ||||
| 
 | ||||
| @ -339,7 +339,7 @@ extern int ws_stop(WSHANDLE ws) { | ||||
| 
 | ||||
|     /* wait for the threads to be done */ | ||||
|     while(pwsp->dispatch_threads) { | ||||
| 	DPRINTF(ERR_DEBUG,"ws_stop: I still see %d threads\n",pwsp->dispatch_threads); | ||||
| 	DPRINTF(E_DBG,L_WS,"ws_stop: I still see %d threads\n",pwsp->dispatch_threads); | ||||
| 	pthread_cond_wait(&pwsp->exit_cond, &pwsp->exit_mutex); | ||||
|     } | ||||
| 
 | ||||
| @ -374,7 +374,7 @@ void *ws_mainthread(void *arg) { | ||||
| 	pwsc=(WS_CONNINFO*)malloc(sizeof(WS_CONNINFO)); | ||||
| 	if(!pwsc) { | ||||
| 	    /* can't very well service any more threads! */ | ||||
| 	    DPRINTF(ERR_FATAL,"Error: %s\n",strerror(errno)); | ||||
| 	    DPRINTF(E_FATAL,L_WS,"Error: %s\n",strerror(errno)); | ||||
| 	    pwsp->running=0; | ||||
| 	    return NULL; | ||||
| 	} | ||||
| @ -382,13 +382,13 @@ void *ws_mainthread(void *arg) { | ||||
| 	memset(pwsc,0,sizeof(WS_CONNINFO)); | ||||
| 
 | ||||
| 	if((fd=u_accept(pwsp->server_fd,hostname,MAX_HOSTNAME)) == -1) { | ||||
| 	    DPRINTF(ERR_DEBUG,"Dispatcher: accept failed: %s\n",strerror(errno)); | ||||
| 	    DPRINTF(E_DBG,L_WS,"Dispatcher: accept failed: %s\n",strerror(errno)); | ||||
| 	    shutdown(pwsp->server_fd,SHUT_RDWR); | ||||
| 	    r_close(pwsp->server_fd); | ||||
| 	    pwsp->running=0; | ||||
| 	    free(pwsc); | ||||
| 
 | ||||
| 	    DPRINTF(ERR_DEBUG,"Dispatcher: Aborting\n"); | ||||
| 	    DPRINTF(E_DBG,L_WS,"Dispatcher: Aborting\n"); | ||||
| 	    return NULL; | ||||
| 	} | ||||
| 
 | ||||
| @ -409,7 +409,7 @@ void *ws_mainthread(void *arg) { | ||||
| 	/* now, throw off a dispatch thread */ | ||||
| 	if((err=pthread_create(&tid,NULL,ws_dispatcher,(void*)pwsc))) { | ||||
| 	    pwsc->error=err; | ||||
| 	    DPRINTF(ERR_WARN,"Could not spawn thread: %s\n",strerror(err)); | ||||
| 	    DPRINTF(E_WARN,L_WS,"Could not spawn thread: %s\n",strerror(err)); | ||||
| 	    ws_close(pwsc); | ||||
| 	} else { | ||||
| 	    ws_add_dispatch_thread(pwsp,pwsc); | ||||
| @ -437,12 +437,12 @@ void ws_close(WS_CONNINFO *pwsc) { | ||||
|        relevant entries  */ | ||||
|     config_set_status(pwsc, 0, NULL); | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Thread %d: Terminating\n",pwsc->threadno); | ||||
|     DPRINTF(ERR_DEBUG,"Thread %d: Freeing request headers\n",pwsc->threadno); | ||||
|     DPRINTF(E_DBG,L_WS,"Thread %d: Terminating\n",pwsc->threadno); | ||||
|     DPRINTF(E_DBG,L_WS,"Thread %d: Freeing request headers\n",pwsc->threadno); | ||||
|     ws_freearglist(&pwsc->request_headers); | ||||
|     DPRINTF(ERR_DEBUG,"Thread %d: Freeing response headers\n",pwsc->threadno); | ||||
|     DPRINTF(E_DBG,L_WS,"Thread %d: Freeing response headers\n",pwsc->threadno); | ||||
|     ws_freearglist(&pwsc->response_headers); | ||||
|     DPRINTF(ERR_DEBUG,"Thread %d: Freeing request vars\n",pwsc->threadno); | ||||
|     DPRINTF(E_DBG,L_WS,"Thread %d: Freeing request vars\n",pwsc->threadno); | ||||
|     ws_freearglist(&pwsc->request_vars); | ||||
|     if(pwsc->uri) { | ||||
| 	free(pwsc->uri); | ||||
| @ -450,7 +450,7 @@ void ws_close(WS_CONNINFO *pwsc) { | ||||
|     } | ||||
|      | ||||
|     if((pwsc->close)||(pwsc->error)) { | ||||
| 	DPRINTF(ERR_DEBUG,"Thread %d: Closing fd\n",pwsc->threadno); | ||||
| 	DPRINTF(E_DBG,L_WS,"Thread %d: Closing fd\n",pwsc->threadno); | ||||
| 	shutdown(pwsc->fd,SHUT_RDWR); | ||||
| 	r_close(pwsc->fd); | ||||
| 	free(pwsc->hostname); | ||||
| @ -485,7 +485,7 @@ void ws_emitheaders(WS_CONNINFO *pwsc) { | ||||
|     ARGLIST *pcurrent=pwsc->response_headers.next; | ||||
| 
 | ||||
|     while(pcurrent) { | ||||
| 	DPRINTF(ERR_DEBUG,"Emitting reponse header %s: %s\n",pcurrent->key, | ||||
| 	DPRINTF(E_DBG,L_WS,"Emitting reponse header %s: %s\n",pcurrent->key, | ||||
| 		pcurrent->value); | ||||
| 	ws_writefd(pwsc,"%s: %s\r\n",pcurrent->key,pcurrent->value); | ||||
| 	pcurrent=pcurrent->next; | ||||
| @ -513,14 +513,14 @@ int ws_getpostvars(WS_CONNINFO *pwsc) { | ||||
|     } | ||||
| 
 | ||||
|     length=atoi(content_length); | ||||
|     DPRINTF(ERR_DEBUG,"Thread %d: Post var length: %d\n", | ||||
|     DPRINTF(E_DBG,L_WS,"Thread %d: Post var length: %d\n", | ||||
| 	    pwsc->threadno,length); | ||||
| 
 | ||||
|     buffer=(char*)malloc(length+1); | ||||
| 
 | ||||
|     if(!buffer) { | ||||
| 	pwsc->error = errno; | ||||
| 	DPRINTF(ERR_INFO,"Thread %d: Could not malloc %d bytes\n", | ||||
| 	DPRINTF(E_INF,L_WS,"Thread %d: Could not malloc %d bytes\n", | ||||
| 		pwsc->threadno, length); | ||||
| 	return -1; | ||||
|     } | ||||
| @ -528,13 +528,13 @@ int ws_getpostvars(WS_CONNINFO *pwsc) { | ||||
|     // make the read time out 30 minutes like we said in the
 | ||||
|     // /server-info response
 | ||||
|     if((readtimed(pwsc->fd, buffer, length, 1800.0)) == -1) { | ||||
| 	DPRINTF(ERR_INFO,"Thread %d: Timeout reading post vars\n", | ||||
| 	DPRINTF(E_INF,L_WS,"Thread %d: Timeout reading post vars\n", | ||||
| 		pwsc->threadno); | ||||
| 	pwsc->error=errno; | ||||
| 	return -1; | ||||
|     } | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Thread %d: Read post vars: %s\n",pwsc->threadno,buffer); | ||||
|     DPRINTF(E_DBG,L_WS,"Thread %d: Read post vars: %s\n",pwsc->threadno,buffer); | ||||
| 
 | ||||
|     pwsc->error=ws_getgetvars(pwsc,buffer); | ||||
|      | ||||
| @ -559,11 +559,11 @@ int ws_getheaders(WS_CONNINFO *pwsc) { | ||||
|     while(!done) { | ||||
| 	if(readline(pwsc->fd,buffer,sizeof(buffer)) == -1) { | ||||
| 	    pwsc->error=errno; | ||||
| 	    DPRINTF(ERR_INFO,"Thread %d: Unexpected close\n",pwsc->threadno); | ||||
| 	    DPRINTF(E_INF,L_WS,"Thread %d: Unexpected close\n",pwsc->threadno); | ||||
| 	    return -1; | ||||
| 	} | ||||
| 	 | ||||
| 	DPRINTF(ERR_DEBUG,"Thread %d: Read: %s",pwsc->threadno,buffer); | ||||
| 	DPRINTF(E_DBG,L_WS,"Thread %d: Read: %s",pwsc->threadno,buffer); | ||||
| 
 | ||||
| 	first=buffer; | ||||
| 	if(buffer[0] == '\r') | ||||
| @ -574,7 +574,7 @@ int ws_getheaders(WS_CONNINFO *pwsc) { | ||||
| 	    first[strlen(first)-1] = '\0'; | ||||
| 
 | ||||
| 	if(strlen(first) == 0) { | ||||
| 	    DPRINTF(ERR_DEBUG,"Thread %d: Headers parsed!\n",pwsc->threadno); | ||||
| 	    DPRINTF(E_DBG,L_WS,"Thread %d: Headers parsed!\n",pwsc->threadno); | ||||
| 	    done=1; | ||||
| 	} else { | ||||
| 	    /* we have a header! */ | ||||
| @ -582,7 +582,7 @@ int ws_getheaders(WS_CONNINFO *pwsc) { | ||||
| 	    strsep(&last,":"); | ||||
| 
 | ||||
| 	    if(last==first) { | ||||
| 		DPRINTF(ERR_WARN,"Thread %d: Invalid header: %s\n", | ||||
| 		DPRINTF(E_WARN,L_WS,"Thread %d: Invalid header: %s\n", | ||||
| 			pwsc->threadno,first); | ||||
| 	    } else { | ||||
| 		while(*last==' ') | ||||
| @ -591,11 +591,11 @@ int ws_getheaders(WS_CONNINFO *pwsc) { | ||||
| 		while(last[strlen(last)-1] == '\r') | ||||
| 		    last[strlen(last)-1] = '\0'; | ||||
| 
 | ||||
| 		DPRINTF(ERR_DEBUG,"Thread %d: Adding header *%s=%s*\n", | ||||
| 		DPRINTF(E_DBG,L_WS,"Thread %d: Adding header *%s=%s*\n", | ||||
| 			pwsc->threadno,first,last); | ||||
| 
 | ||||
| 		if(ws_addarg(&pwsc->request_headers,first,"%s",last)) { | ||||
| 		    DPRINTF(ERR_FATAL,"Thread %d: Out of memory\n", | ||||
| 		    DPRINTF(E_FATAL,L_WS,"Thread %d: Out of memory\n", | ||||
| 			    pwsc->threadno); | ||||
| 		    pwsc->error=ENOMEM; | ||||
| 		    return -1; | ||||
| @ -619,10 +619,10 @@ int ws_getgetvars(WS_CONNINFO *pwsc, char *string) { | ||||
|     char *key, *value; | ||||
|     int done; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Thread %d: Original string: %s\n", | ||||
|     DPRINTF(E_DBG,L_WS,"Thread %d: Original string: %s\n", | ||||
| 	    pwsc->threadno,string); | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Thread %d: Processing GET/POSTs from %s\n", | ||||
|     DPRINTF(E_DBG,L_WS,"Thread %d: Processing GET/POSTs from %s\n", | ||||
| 	    pwsc->threadno,string); | ||||
| 
 | ||||
|     done=0; | ||||
| @ -635,13 +635,13 @@ int ws_getgetvars(WS_CONNINFO *pwsc, char *string) { | ||||
| 	strsep(&middle,"="); | ||||
| 	 | ||||
| 	if(!middle) { | ||||
| 	    DPRINTF(ERR_WARN,"Thread %d: Bad arg: %s\n", | ||||
| 	    DPRINTF(E_WARN,L_WS,"Thread %d: Bad arg: %s\n", | ||||
| 		    pwsc->threadno,first); | ||||
| 	} else { | ||||
| 	    key=ws_urldecode(first); | ||||
| 	    value=ws_urldecode(middle); | ||||
| 	     | ||||
| 	    DPRINTF(ERR_DEBUG,"Thread %d: Adding arg %s = %s\n", | ||||
| 	    DPRINTF(E_DBG,L_WS,"Thread %d: Adding arg %s = %s\n", | ||||
| 		    pwsc->threadno,key,value); | ||||
| 	    ws_addarg(&pwsc->request_vars,key,"%s",value); | ||||
| 
 | ||||
| @ -650,7 +650,7 @@ int ws_getgetvars(WS_CONNINFO *pwsc, char *string) { | ||||
| 	} | ||||
| 	 | ||||
| 	if(!last) { | ||||
| 	    DPRINTF(ERR_DEBUG,"Thread %d: Done parsing GET/POST args!\n", | ||||
| 	    DPRINTF(E_DBG,L_WS,"Thread %d: Done parsing GET/POST args!\n", | ||||
| 		    pwsc->threadno); | ||||
| 	    done=1; | ||||
| 	} else { | ||||
| @ -683,7 +683,7 @@ void *ws_dispatcher(void *arg) { | ||||
|     void (*req_handler)(WS_CONNINFO*); | ||||
|     int(*auth_handler)(char *, char *); | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Thread %d: Connection from %s\n",pwsc->threadno, | ||||
|     DPRINTF(E_DBG,L_WS,"Thread %d: Connection from %s\n",pwsc->threadno, | ||||
| 	    pwsc->hostname); | ||||
| 	 | ||||
|     while(!connection_done) { | ||||
| @ -696,14 +696,14 @@ void *ws_dispatcher(void *arg) { | ||||
| 	if((readlinetimed(pwsc->fd,buffer,sizeof(buffer),1800.0)) < 1) { | ||||
| 	    pwsc->error=errno; | ||||
| 	    pwsc->close=1; | ||||
| 	    DPRINTF(ERR_WARN,"Thread %d:  could not read: %s\n", | ||||
| 	    DPRINTF(E_WARN,L_WS,"Thread %d:  could not read: %s\n", | ||||
| 		    pwsc->threadno,strerror(errno)); | ||||
| 	    ws_close(pwsc); | ||||
| 	    return NULL; | ||||
| 	} | ||||
| 
 | ||||
| 	DPRINTF(ERR_DEBUG,"Thread %d: got request\n",pwsc->threadno); | ||||
| 	DPRINTF(ERR_DEBUG - 1, "Request: %s", buffer); | ||||
| 	DPRINTF(E_DBG,L_WS,"Thread %d: got request\n",pwsc->threadno); | ||||
| 	DPRINTF(E_DBG - 1,L_WS, "Request: %s", buffer); | ||||
| 
 | ||||
| 	first=last=buffer; | ||||
| 	strsep(&last," "); | ||||
| @ -734,7 +734,7 @@ void *ws_dispatcher(void *arg) { | ||||
| 	/* Get headers */ | ||||
| 	if((ws_getheaders(pwsc)) || (!last)) { /* didn't provide a HTTP/1.x */ | ||||
| 	    /* error already set */ | ||||
| 	    DPRINTF(ERR_FATAL,"Thread %d: Couldn't parse headers - aborting\n", | ||||
| 	    DPRINTF(E_FATAL,L_WS,"Thread %d: Couldn't parse headers - aborting\n", | ||||
| 		    pwsc->threadno); | ||||
| 	    pwsc->close=1; | ||||
| 	    ws_close(pwsc); | ||||
| @ -750,7 +750,7 @@ void *ws_dispatcher(void *arg) { | ||||
| 	} else { /* default to persistant for HTTP/1.1 and above */ | ||||
| 	    pwsc->close=ws_testarg(&pwsc->request_headers,"connection","close"); | ||||
| 	} | ||||
| 	DPRINTF(ERR_DEBUG,"Thread %d: Connection type %s: Connection: %s\n", | ||||
| 	DPRINTF(E_DBG,L_WS,"Thread %d: Connection type %s: Connection: %s\n", | ||||
| 		pwsc->threadno, last, pwsc->close ? "non-persist" : "persist"); | ||||
| 
 | ||||
| 	if(!pwsc->uri) { | ||||
| @ -758,7 +758,7 @@ void *ws_dispatcher(void *arg) { | ||||
| 	     * as well bail */ | ||||
| 	    pwsc->error=ENOMEM; | ||||
| 	    pwsc->close=1; /* force a full close */ | ||||
| 	    DPRINTF(ERR_FATAL,"Thread %d: Error allocation URI\n", | ||||
| 	    DPRINTF(E_FATAL,L_WS,"Thread %d: Error allocation URI\n", | ||||
| 		    pwsc->threadno); | ||||
| 	    ws_returnerror(pwsc,500,"Internal server error"); | ||||
| 	    ws_close(pwsc); | ||||
| @ -770,13 +770,13 @@ void *ws_dispatcher(void *arg) { | ||||
| 	strsep(&first,"?"); | ||||
| 	 | ||||
| 	if(first) { /* got some GET args */ | ||||
| 	    DPRINTF(ERR_DEBUG,"Thread %d: parsing GET args\n",pwsc->threadno); | ||||
| 	    DPRINTF(E_DBG,L_WS,"Thread %d: parsing GET args\n",pwsc->threadno); | ||||
| 	    ws_getgetvars(pwsc,first); | ||||
| 	} | ||||
| 
 | ||||
| 	/* fix the URI by un urldecoding it */ | ||||
| 	 | ||||
| 	DPRINTF(ERR_DEBUG,"Thread %d: Original URI: %s\n", | ||||
| 	DPRINTF(E_DBG,L_WS,"Thread %d: Original URI: %s\n", | ||||
| 		pwsc->threadno,pwsc->uri); | ||||
| 	 | ||||
| 	first=ws_urldecode(pwsc->uri); | ||||
| @ -796,7 +796,7 @@ void *ws_dispatcher(void *arg) { | ||||
| 	} | ||||
| 	 | ||||
| 	 | ||||
| 	DPRINTF(ERR_DEBUG,"Thread %d: Translated URI: %s\n",pwsc->threadno, | ||||
| 	DPRINTF(E_DBG,L_WS,"Thread %d: Translated URI: %s\n",pwsc->threadno, | ||||
| 		pwsc->uri); | ||||
| 
 | ||||
| 	/* now, parse POST args */ | ||||
| @ -808,10 +808,10 @@ void *ws_dispatcher(void *arg) { | ||||
| 	handler=ws_findhandler(pwsp,pwsc,&req_handler,&auth_handler,&hdrs); | ||||
| 
 | ||||
| 	time(&now); | ||||
| 	DPRINTF(ERR_DEBUG,"Thread %d: Time is %d seconds after epoch\n", | ||||
| 	DPRINTF(E_DBG,L_WS,"Thread %d: Time is %d seconds after epoch\n", | ||||
| 		pwsc->threadno,now); | ||||
| 	gmtime_r(&now,&now_tm); | ||||
| 	DPRINTF(ERR_DEBUG,"Thread %d: Setting time header\n",pwsc->threadno); | ||||
| 	DPRINTF(E_DBG,L_WS,"Thread %d: Setting time header\n",pwsc->threadno); | ||||
| 	ws_addarg(&pwsc->response_headers,"Date",  | ||||
| 		  "%s, %d %s %d %02d:%02d:%02d GMT", | ||||
| 		  ws_dow[now_tm.tm_wday],now_tm.tm_mday, | ||||
| @ -831,11 +831,11 @@ void *ws_dispatcher(void *arg) { | ||||
| 
 | ||||
| 	/* Find the appropriate handler and dispatch it */ | ||||
| 	if(handler == -1) { | ||||
| 	    DPRINTF(ERR_DEBUG,"Thread %d: Using default handler.\n", | ||||
| 	    DPRINTF(E_DBG,L_WS,"Thread %d: Using default handler.\n", | ||||
| 		    pwsc->threadno); | ||||
| 	    ws_defaulthandler(pwsp,pwsc); | ||||
| 	} else { | ||||
| 	    DPRINTF(ERR_DEBUG,"Thread %d: Using non-default handler\n", | ||||
| 	    DPRINTF(E_DBG,L_WS,"Thread %d: Using non-default handler\n", | ||||
| 		    pwsc->threadno); | ||||
| 
 | ||||
| 	    can_dispatch=0; | ||||
| @ -914,7 +914,7 @@ int ws_writefd(WS_CONNINFO *pwsc, char *fmt, ...) { | ||||
| int ws_returnerror(WS_CONNINFO *pwsc,int error, char *description) { | ||||
|     char *useragent; | ||||
| 
 | ||||
|     DPRINTF(ERR_WARN,"Thread %d: Pushing a %d: %s\n", | ||||
|     DPRINTF(E_WARN,L_WS,"Thread %d: Pushing a %d: %s\n", | ||||
| 	    pwsc->threadno,error,description); | ||||
|     ws_writefd(pwsc,"HTTP/1.1 %d %s\r\n",error,description); | ||||
|      | ||||
| @ -956,19 +956,19 @@ void ws_defaulthandler(WS_PRIVATE *pwsp, WS_CONNINFO *pwsc) { | ||||
|     snprintf(path,MAXPATHLEN,"%s/%s",pwsp->wsconfig.web_root,pwsc->uri); | ||||
|     if(!realpath(path,resolved_path)) { | ||||
| 	pwsc->error=errno; | ||||
| 	DPRINTF(ERR_WARN,"Cannot resolve %s\n",path); | ||||
| 	DPRINTF(E_WARN,L_WS,"Cannot resolve %s\n",path); | ||||
| 	ws_returnerror(pwsc,404,"Not found"); | ||||
| 	ws_close(pwsc); | ||||
| 	return; | ||||
|     } | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Thread %d: Preparing to serve %s\n", | ||||
|     DPRINTF(E_DBG,L_WS,"Thread %d: Preparing to serve %s\n", | ||||
| 	    pwsc->threadno, resolved_path); | ||||
| 
 | ||||
|     if(strncmp(resolved_path,pwsp->wsconfig.web_root, | ||||
| 	       strlen(pwsp->wsconfig.web_root))) { | ||||
| 	pwsc->error=EINVAL; | ||||
| 	DPRINTF(ERR_WARN,"Thread %d: Requested file %s out of root\n", | ||||
| 	DPRINTF(E_WARN,L_WS,"Thread %d: Requested file %s out of root\n", | ||||
| 		pwsc->threadno,resolved_path); | ||||
| 	ws_returnerror(pwsc,403,"Forbidden"); | ||||
| 	ws_close(pwsc); | ||||
| @ -978,7 +978,7 @@ void ws_defaulthandler(WS_PRIVATE *pwsp, WS_CONNINFO *pwsc) { | ||||
|     file_fd=open(resolved_path,O_RDONLY); | ||||
|     if(file_fd == -1) { | ||||
| 	pwsc->error=errno; | ||||
| 	DPRINTF(ERR_WARN,"Thread %d: Error opening %s: %s\n", | ||||
| 	DPRINTF(E_WARN,L_WS,"Thread %d: Error opening %s: %s\n", | ||||
| 		pwsc->threadno,resolved_path,strerror(errno)); | ||||
| 	ws_returnerror(pwsc,404,"Not found"); | ||||
| 	ws_close(pwsc); | ||||
| @ -991,7 +991,7 @@ void ws_defaulthandler(WS_PRIVATE *pwsp, WS_CONNINFO *pwsc) { | ||||
|     /* FIXME: assumes off_t == long */ | ||||
|     if(len != -1) { | ||||
| 	/* we have a real length */ | ||||
| 	DPRINTF(ERR_DEBUG,"Length of file is %ld\n",(long)len); | ||||
| 	DPRINTF(E_DBG,L_WS,"Length of file is %ld\n",(long)len); | ||||
| 	ws_addarg(&pwsc->response_headers,"Content-Length","%ld",(long)len); | ||||
| 	lseek(file_fd,0,SEEK_SET); | ||||
|     } | ||||
| @ -1004,7 +1004,7 @@ void ws_defaulthandler(WS_PRIVATE *pwsp, WS_CONNINFO *pwsc) { | ||||
|     copyfile(file_fd,pwsc->fd); | ||||
| 
 | ||||
|     r_close(file_fd); | ||||
|     DPRINTF(ERR_DEBUG,"Thread %d: Served successfully\n",pwsc->threadno); | ||||
|     DPRINTF(E_DBG,L_WS,"Thread %d: Served successfully\n",pwsc->threadno); | ||||
|     return; | ||||
| } | ||||
| 
 | ||||
| @ -1034,7 +1034,7 @@ int ws_testrequestheader(WS_CONNINFO *pwsc, char *header, char *value) { | ||||
| int ws_testarg(ARGLIST *root, char *key, char *value) { | ||||
|     char *retval; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Checking to see if %s matches %s\n",key,value); | ||||
|     DPRINTF(E_DBG,L_WS,"Checking to see if %s matches %s\n",key,value); | ||||
| 
 | ||||
|     retval=ws_getarg(root,key); | ||||
|     if(!retval) | ||||
| @ -1113,7 +1113,7 @@ int ws_addarg(ARGLIST *root, char *key, char *fmt, ...) { | ||||
|     while(current) { | ||||
| 	if(!strcmp(current->key,key)) { | ||||
| 	    /* got a match! */ | ||||
| 	    DPRINTF(ERR_DEBUG,"Updating %s from %s to %s\n", | ||||
| 	    DPRINTF(E_DBG,L_WS,"Updating %s from %s to %s\n", | ||||
| 		    key,current->value,value); | ||||
| 	    free(current->value); | ||||
| 	    current->value = newvalue; | ||||
| @ -1126,7 +1126,7 @@ int ws_addarg(ARGLIST *root, char *key, char *fmt, ...) { | ||||
| 
 | ||||
| 
 | ||||
|     pnew->next=root->next; | ||||
|     DPRINTF(ERR_DEBUG,"Added *%s=%s*\n",newkey,newvalue); | ||||
|     DPRINTF(E_DBG,L_WS,"Added *%s=%s*\n",newkey,newvalue); | ||||
|     root->next=pnew; | ||||
| 
 | ||||
|     return 0; | ||||
| @ -1252,13 +1252,13 @@ int ws_findhandler(WS_PRIVATE *pwsp, WS_CONNINFO *pwsc, | ||||
| 
 | ||||
|     *preq=NULL; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Thread %d: Preparing to find handler\n", | ||||
|     DPRINTF(E_DBG,L_WS,"Thread %d: Preparing to find handler\n", | ||||
| 	    pwsc->threadno); | ||||
| 
 | ||||
|     while(phandler) { | ||||
| 	if(!regexec(&phandler->regex,pwsc->uri,0,NULL,0)) { | ||||
| 	    /* that's a match */ | ||||
| 	    DPRINTF(ERR_DEBUG,"Thread %d: URI Match!\n",pwsc->threadno); | ||||
| 	    DPRINTF(E_DBG,L_WS,"Thread %d: URI Match!\n",pwsc->threadno); | ||||
| 	    *preq=phandler->req_handler; | ||||
| 	    *pauth=phandler->auth_handler; | ||||
| 	    *addheaders=phandler->addheaders; | ||||
| @ -1324,7 +1324,7 @@ int ws_decodepassword(char *header, char **username, char **password) { | ||||
|     if(!decodebuffer) | ||||
| 	return -1; | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Preparing to decode %s\n",header); | ||||
|     DPRINTF(E_DBG,L_WS,"Preparing to decode %s\n",header); | ||||
| 
 | ||||
|     memset(decodebuffer,0,strlen(header)); | ||||
|     len=0; | ||||
| @ -1336,7 +1336,7 @@ int ws_decodepassword(char *header, char **username, char **password) { | ||||
| 	if(pin[rack] != '=') { | ||||
| 	    lookup=ws_xlat[pin[rack]]; | ||||
| 	    if(lookup == 0xFF) { | ||||
| 		DPRINTF(ERR_WARN,"Got garbage Authenticate header\n"); | ||||
| 		DPRINTF(E_WARN,L_WS,"Got garbage Authenticate header\n"); | ||||
| 		return -1; | ||||
| 	    } | ||||
| 
 | ||||
| @ -1374,14 +1374,14 @@ int ws_decodepassword(char *header, char **username, char **password) { | ||||
|     } | ||||
| 
 | ||||
|     /* we now have the decoded string */ | ||||
|     DPRINTF(ERR_DEBUG,"Decoded %s\n",decodebuffer); | ||||
|     DPRINTF(E_DBG,L_WS,"Decoded %s\n",decodebuffer); | ||||
| 
 | ||||
|     *username = decodebuffer; | ||||
|     *password = *username; | ||||
| 
 | ||||
|     strsep(password,":"); | ||||
| 
 | ||||
|     DPRINTF(ERR_DEBUG,"Decoded user=%s, pw=%s\n",*username,*password); | ||||
|     DPRINTF(E_DBG,L_WS,"Decoded user=%s, pw=%s\n",*username,*password); | ||||
|     return 0; | ||||
| } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user