untabify err.c
This commit is contained in:
parent
463c7fe478
commit
4d1555ec2b
26
src/conf.c
26
src/conf.c
|
@ -627,6 +627,32 @@ int conf_get_string(char *section, char *key, char *dflt, char *out, int *size)
|
|||
return CONF_E_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* return the value from the CURRENT config tree as an allocated string
|
||||
*
|
||||
* @param section section name to search in
|
||||
* @param key key to search for
|
||||
* @param dflt default value to return if key not found
|
||||
* @returns a pointer to an allocated string containing the required
|
||||
* configuration key
|
||||
*/
|
||||
char *conf_alloc_string (char *section, char *key, char *dflt) {
|
||||
int size = -1;
|
||||
char *out;
|
||||
|
||||
conf_get_string(section, key, dflt, NULL, &size);
|
||||
out = (char *)malloc(size * sizeof(char));
|
||||
|
||||
if(!out)
|
||||
DPRINTF(E_FATAL,L_CONF,"Malloc failure\n");
|
||||
|
||||
if(conf_get_string (section, key, dflt, out, &size) != CONF_E_SUCCESS)
|
||||
return NULL;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* set (update) the config tree with a particular value.
|
||||
* this accepts an int, but it actually adds it as a string.
|
||||
|
|
|
@ -37,6 +37,7 @@ extern int conf_close(void);
|
|||
extern int conf_get_int(char *section, char *key, int dflt);
|
||||
extern int conf_get_string(char *section, char *key, char *dflt,
|
||||
char *out, int *size);
|
||||
extern char *conf_alloc_string(char *section, char *key, char *dflt);
|
||||
extern int conf_set_int(char *section, char *key, int value);
|
||||
extern int conf_set_string(char *section, char *key, char *value);
|
||||
|
||||
|
|
|
@ -317,19 +317,18 @@ void config_subst_stream(WS_CONNINFO *pwsc, int fd_src) {
|
|||
void config_handler(WS_CONNINFO *pwsc) {
|
||||
char path[PATH_MAX];
|
||||
char resolved_path[PATH_MAX];
|
||||
char web_root[PATH_MAX];
|
||||
int file_fd;
|
||||
struct stat sb;
|
||||
char *pw;
|
||||
char web_root[PATH_MAX];
|
||||
char *pw, *web_root;
|
||||
int size;
|
||||
|
||||
size = PATH_MAX;
|
||||
if(conf_get_string("general","web_root",NULL,
|
||||
web_root,&size) != CONF_E_SUCCESS) {
|
||||
DPRINTF(E_FATAL,L_CONF,"No web root!\n");
|
||||
size = sizeof(web_root);
|
||||
if(conf_get_string("general","web_root",NULL,web_root,
|
||||
&size) == CONF_E_NOTFOUND) {
|
||||
DPRINTF(E_FATAL,L_WS,"No web root!\n");
|
||||
}
|
||||
|
||||
|
||||
DPRINTF(E_DBG,L_CONF|L_WS,"Entering config_handler\n");
|
||||
|
||||
config_set_status(pwsc,0,"Serving admin pages");
|
||||
|
@ -421,21 +420,16 @@ void config_handler(WS_CONNINFO *pwsc) {
|
|||
* \param password password passed in the auth request
|
||||
*/
|
||||
int config_auth(char *user, char *password) {
|
||||
char adminpassword[80];
|
||||
int size = sizeof(adminpassword);
|
||||
char *adminpassword;
|
||||
int res;
|
||||
|
||||
if(conf_get_string("general","admin_pw","",adminpassword,
|
||||
&size) != CONF_E_SUCCESS) {
|
||||
DPRINTF(E_LOG,L_CONF,"c_g_s: not success\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
DPRINTF(E_LOG,L_CONF,"Admin pw: %s\n",adminpassword);
|
||||
|
||||
if(!password)
|
||||
if((!password) ||
|
||||
((adminpassword=conf_alloc_string("general","admin_pw",NULL))==NULL))
|
||||
return FALSE;
|
||||
|
||||
return !strcmp(password,adminpassword);
|
||||
res = !strcmp(password,adminpassword);
|
||||
free(adminpassword);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
@ -776,14 +770,14 @@ void config_emit_readonly(WS_CONNINFO *pwsc, void *value, char *arg) {
|
|||
void config_emit_include(WS_CONNINFO *pwsc, void *value, char *arg) {
|
||||
char resolved_path[PATH_MAX];
|
||||
char path[PATH_MAX];
|
||||
char web_root[PATH_MAX];
|
||||
int file_fd;
|
||||
struct stat sb;
|
||||
char web_root[PATH_MAX];
|
||||
int size;
|
||||
|
||||
size = sizeof(web_root);
|
||||
if(conf_get_string("general","web_root",NULL,web_root,
|
||||
&size) != CONF_E_SUCCESS) {
|
||||
&size) == CONF_E_NOTFOUND) {
|
||||
DPRINTF(E_FATAL,L_WS,"No web root!\n");
|
||||
}
|
||||
|
||||
|
@ -800,7 +794,7 @@ void config_emit_include(WS_CONNINFO *pwsc, void *value, char *arg) {
|
|||
/* this should really return a 302:Found */
|
||||
stat(resolved_path,&sb);
|
||||
if(sb.st_mode & S_IFDIR) {
|
||||
ws_writefd(pwsc,"<hr><i>error: cannot include director %s</i><hr>",arg);
|
||||
ws_writefd(pwsc,"<hr><i>error: cannot include dir %s</i><hr>",arg);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
102
src/dispatch.c
102
src/dispatch.c
|
@ -124,37 +124,39 @@ void dispatch_cleanup(DBQUERYINFO *pqi) {
|
|||
* not. If you apply authentication somewhere that iTunes doesn't expect
|
||||
* it, it happily disconnects.
|
||||
*
|
||||
* \param username The username passed by iTunes
|
||||
* \param password The password passed by iTunes
|
||||
* \returns 1 if auth successful, 0 otherwise
|
||||
* @param username The username passed by iTunes
|
||||
* @param password The password passed by iTunes
|
||||
* @returns 1 if auth successful, 0 otherwise
|
||||
*/
|
||||
int daap_auth(char *username, char *password) {
|
||||
char readpassword[40];
|
||||
int size;
|
||||
char *readpassword;
|
||||
|
||||
size = sizeof(readpassword);
|
||||
conf_get_string("general","password","",readpassword,&size);
|
||||
readpassword = conf_alloc_string("general","password",NULL);
|
||||
|
||||
if((password == NULL) &&
|
||||
((readpassword == NULL) || (strlen(readpassword)==0)))
|
||||
return 1;
|
||||
|
||||
if(password == NULL)
|
||||
return 0;
|
||||
|
||||
if(strcasecmp(password,readpassword)) {
|
||||
DPRINTF(E_LOG,L_DAAP | L_WS,"Bad password attempt\n");
|
||||
return 0;
|
||||
if(password == NULL) {
|
||||
if(readpassword == NULL) {
|
||||
return TRUE;
|
||||
} else {
|
||||
free(readpassword);
|
||||
return FALSE;
|
||||
}
|
||||
} else {
|
||||
if(strcasecmp(password,readpassword)) {
|
||||
free(readpassword);
|
||||
return FALSE;
|
||||
} else {
|
||||
free(readpassword);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
DPRINTF(E_DBG,L_DAAP | L_WS, "good password.\n");
|
||||
return 1;
|
||||
return TRUE; /* not used */
|
||||
}
|
||||
|
||||
/**
|
||||
* decodes the request and hands it off to the appropriate dispatcher
|
||||
*
|
||||
* \param pwsc the current web connection info
|
||||
* @param pwsc the current web connection info
|
||||
*/
|
||||
void daap_handler(WS_CONNINFO *pwsc) {
|
||||
DBQUERYINFO *pqi;
|
||||
|
@ -383,9 +385,9 @@ void daap_handler(WS_CONNINFO *pwsc) {
|
|||
* set up whatever necessary to begin streaming the output
|
||||
* to the client.
|
||||
*
|
||||
* \param pwsc pointer to the current conninfo struct
|
||||
* \param pqi pointer to the current dbquery struct
|
||||
* \param content_length content_length (assuming dmap) of the output
|
||||
* @param pwsc pointer to the current conninfo struct
|
||||
* @param pqi pointer to the current dbquery struct
|
||||
* @param content_length content_length (assuming dmap) of the output
|
||||
*/
|
||||
int dispatch_output_start(WS_CONNINFO *pwsc, DBQUERYINFO *pqi, int content_length) {
|
||||
OUTPUT_INFO *poi;
|
||||
|
@ -429,10 +431,10 @@ int dispatch_output_start(WS_CONNINFO *pwsc, DBQUERYINFO *pqi, int content_lengt
|
|||
* dmap blocks out to the client. In more complex cases, it convert
|
||||
* them to xml, or compresses them.
|
||||
*
|
||||
* \param pqi pointer to the current dbquery info struct
|
||||
* \param pwsc pointer to the current conninfo struct
|
||||
* \param pblock block of data to write
|
||||
* \param len length of block to write
|
||||
* @param pqi pointer to the current dbquery info struct
|
||||
* @param pwsc pointer to the current conninfo struct
|
||||
* @param pblock block of data to write
|
||||
* @param len length of block to write
|
||||
*/
|
||||
int dispatch_output_write(WS_CONNINFO *pwsc, DBQUERYINFO *pqi, unsigned char *block, int len) {
|
||||
OUTPUT_INFO *poi=(pqi->output_info);
|
||||
|
@ -453,10 +455,10 @@ int dispatch_output_write(WS_CONNINFO *pwsc, DBQUERYINFO *pqi, unsigned char *bl
|
|||
* this is the serializer for xml. This assumes that (with the exception of
|
||||
* containers) blocks are complete dmap blocks
|
||||
*
|
||||
* \param pqi pointer to the current dbquery info struct
|
||||
* \param pwsc pointer to the current conninfo struct
|
||||
* \param pblock block of data to write
|
||||
* \param len length of block to write
|
||||
* @param pqi pointer to the current dbquery info struct
|
||||
* @param pwsc pointer to the current conninfo struct
|
||||
* @param pblock block of data to write
|
||||
* @param len length of block to write
|
||||
*/
|
||||
int dispatch_output_xml_write(WS_CONNINFO *pwsc, DBQUERYINFO *pqi, unsigned char *block, int len) {
|
||||
OUTPUT_INFO *poi = pqi->output_info;
|
||||
|
@ -638,8 +640,8 @@ int dispatch_output_xml_write(WS_CONNINFO *pwsc, DBQUERYINFO *pqi, unsigned char
|
|||
* finish streaming output to the client, freeing any allocated
|
||||
* memory, and cleaning up
|
||||
*
|
||||
* \param pwsc current conninfo struct
|
||||
* \param pqi current dbquery struct
|
||||
* @param pwsc current conninfo struct
|
||||
* @param pqi current dbquery struct
|
||||
*/
|
||||
int dispatch_output_end(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) {
|
||||
OUTPUT_INFO *poi = pqi->output_info;
|
||||
|
@ -1427,35 +1429,34 @@ void dispatch_update(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) {
|
|||
}
|
||||
|
||||
void dispatch_dbinfo(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) {
|
||||
unsigned char dbinfo_response[255]; /* FIXME */
|
||||
unsigned char dbinfo_response[255]; /* FIXME: servername limit 255-113 */
|
||||
unsigned char *current = dbinfo_response;
|
||||
int namelen;
|
||||
int count;
|
||||
char servername[80];
|
||||
int size;
|
||||
char *servername;
|
||||
|
||||
size = sizeof(servername);
|
||||
conf_get_string("general","servername","mt-daapd",servername,&size);
|
||||
servername = conf_alloc_string("general","servername","mt-daapd");
|
||||
namelen=(int) strlen(servername);
|
||||
|
||||
current += db_dmap_add_container(current,"avdb",105 + namelen);
|
||||
current += db_dmap_add_int(current,"mstt",200); /* 12 */
|
||||
current += db_dmap_add_char(current,"muty",0); /* 9 */
|
||||
current += db_dmap_add_int(current,"mtco",1); /* 12 */
|
||||
current += db_dmap_add_int(current,"mrco",1); /* 12 */
|
||||
current += db_dmap_add_int(current,"mstt",200); /* 12 */
|
||||
current += db_dmap_add_char(current,"muty",0); /* 9 */
|
||||
current += db_dmap_add_int(current,"mtco",1); /* 12 */
|
||||
current += db_dmap_add_int(current,"mrco",1); /* 12 */
|
||||
current += db_dmap_add_container(current,"mlcl",52 + namelen);
|
||||
current += db_dmap_add_container(current,"mlit",44 + namelen);
|
||||
current += db_dmap_add_int(current,"miid",1); /* 12 */
|
||||
current += db_dmap_add_string(current,"minm",servername); /* 8 + namelen */
|
||||
current += db_dmap_add_int(current,"miid",1); /* 12 */
|
||||
current += db_dmap_add_string(current,"minm",servername); /* 8 + namelen */
|
||||
db_get_song_count(NULL,&count);
|
||||
current += db_dmap_add_int(current,"mimc",count); /* 12 */
|
||||
current += db_dmap_add_int(current,"mimc",count); /* 12 */
|
||||
db_get_playlist_count(NULL,&count);
|
||||
current += db_dmap_add_int(current,"mctc",count); /* 12 */
|
||||
current += db_dmap_add_int(current,"mctc",count); /* 12 */
|
||||
|
||||
dispatch_output_start(pwsc,pqi,113+namelen);
|
||||
dispatch_output_write(pwsc,pqi,dbinfo_response,113+namelen);
|
||||
dispatch_output_end(pwsc,pqi);
|
||||
|
||||
free(servername);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1519,17 +1520,15 @@ void dispatch_content_codes(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) {
|
|||
}
|
||||
|
||||
void dispatch_server_info(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) {
|
||||
unsigned char server_info[256]; /* FIXME: Don't make this static */
|
||||
unsigned char server_info[256];
|
||||
unsigned char *current = server_info;
|
||||
char *client_version;
|
||||
int mpro = 2 << 16;
|
||||
int apro = 3 << 16;
|
||||
char servername[80];
|
||||
int size;
|
||||
char *servername;
|
||||
int actual_length;
|
||||
|
||||
size = sizeof(servername);
|
||||
conf_get_string("general","servername","mt-daapd",servername,&size);
|
||||
servername = conf_alloc_string("general","servername","mt-daapd");
|
||||
|
||||
actual_length=130 + (int) strlen(servername);
|
||||
|
||||
|
@ -1570,6 +1569,7 @@ void dispatch_server_info(WS_CONNINFO *pwsc, DBQUERYINFO *pqi) {
|
|||
dispatch_output_write(pwsc,pqi,server_info,actual_length);
|
||||
dispatch_output_end(pwsc,pqi);
|
||||
|
||||
free(servername);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -90,20 +90,17 @@ int fcopyblock(FILE *fromfp, int tofd, size_t size);
|
|||
*/
|
||||
int da_get_image_fd(char *filename) {
|
||||
char buffer[PATH_MAX];
|
||||
char *path_end;
|
||||
char *path_end, *artfilename;
|
||||
int fd;
|
||||
char artfilename[PATH_MAX];
|
||||
int size;
|
||||
|
||||
size = sizeof(artfilename);
|
||||
if(conf_get_string("general","art_filename","_folderOpenImage.jpg",
|
||||
artfilename,&size) != CONF_E_SUCCESS) {
|
||||
if((artfilename = conf_alloc_string("general","art_filename","_folderOpenImage.jpg")) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
strncpy(buffer,filename,sizeof(buffer));
|
||||
path_end = strrchr(buffer,'/');
|
||||
strcpy(path_end+1,artfilename);
|
||||
free(artfilename);
|
||||
fd = open(buffer,O_RDONLY);
|
||||
if(fd != -1)
|
||||
DPRINTF(E_INF,L_ART,"Found image file %s (fd %d)\n",buffer,fd);
|
||||
|
@ -298,12 +295,9 @@ off_t da_aac_insert_covr_atom(off_t extra_size, int out_fd, FILE *aac_fp,
|
|||
char *cp;
|
||||
unsigned char img_type_flag = 0;
|
||||
|
||||
char artfilename[PATH_MAX];
|
||||
int size;
|
||||
char *artfilename;
|
||||
|
||||
size = sizeof(artfilename);
|
||||
if(conf_get_string("general","art_filename","_folderOpenImage.jpg",
|
||||
artfilename,&size) != CONF_E_SUCCESS) {
|
||||
if((artfilename = conf_alloc_string("general","art_filename","_folderOpenImage.jpg")) == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -322,6 +316,7 @@ off_t da_aac_insert_covr_atom(off_t extra_size, int out_fd, FILE *aac_fp,
|
|||
} else {
|
||||
DPRINTF(E_LOG, L_ART, "No file extension for image file.\n");
|
||||
}
|
||||
free(artfilename);
|
||||
|
||||
aac_fd = fileno(aac_fp);
|
||||
fstat(aac_fd, &sb);
|
||||
|
|
|
@ -189,7 +189,7 @@ extern int err_setdebugmask(char *list) {
|
|||
err_debugmask=0x80000000; /* always log L_MISC! */
|
||||
str=tmpstr=strdup(list);
|
||||
if(!str)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
while(1) {
|
||||
token=strtok_r(str,",",&last);
|
||||
|
@ -206,7 +206,7 @@ extern int err_setdebugmask(char *list) {
|
|||
|
||||
if(!err_categorylist[index]) {
|
||||
DPRINTF(E_LOG,L_MISC,"Unknown module: %s\n",token);
|
||||
free(tmpstr);
|
||||
free(tmpstr);
|
||||
return 1;
|
||||
} else {
|
||||
DPRINTF(E_DBG,L_MISC,"Adding module %s to debug list (0x%08x)\n",token,rack);
|
||||
|
|
66
src/main.c
66
src/main.c
|
@ -195,16 +195,9 @@ int main(int argc, char *argv[]) {
|
|||
int old_song_count, song_count;
|
||||
int force_non_root=0;
|
||||
int skip_initial=0;
|
||||
int size;
|
||||
int convert_conf=0;
|
||||
char logfile[PATH_MAX];
|
||||
char db_type[40];
|
||||
char db_parms[PATH_MAX];
|
||||
char mp3_dir[PATH_MAX];
|
||||
char web_root[PATH_MAX];
|
||||
char runas[40];
|
||||
char servername[PATH_MAX];
|
||||
char iface[20];
|
||||
char *logfile,*db_type,*db_parms,*mp3_dir,*web_root,*runas;
|
||||
char *servername,*iface;
|
||||
|
||||
char txtrecord[255];
|
||||
|
||||
|
@ -305,36 +298,37 @@ int main(int argc, char *argv[]) {
|
|||
DPRINTF(E_LOG,L_MAIN,"Starting with debuglevel %d\n",err_getlevel());
|
||||
|
||||
if(!config.foreground) {
|
||||
size = PATH_MAX;
|
||||
if(conf_get_string("general","logfile",NULL,logfile,&size) == CONF_E_SUCCESS) {
|
||||
if((logfile = conf_alloc_string("general","logfile",NULL)) != NULL) {
|
||||
err_setdest(logfile,LOGDEST_LOGFILE);
|
||||
free(logfile);
|
||||
} else {
|
||||
err_setdest("mt-daapd",LOGDEST_SYSLOG);
|
||||
}
|
||||
}
|
||||
|
||||
runas = conf_alloc_string("general","runas","nobody");
|
||||
|
||||
#ifndef WITHOUT_MDNS
|
||||
if(config.use_mdns) {
|
||||
DPRINTF(E_LOG,L_MAIN,"Starting rendezvous daemon\n");
|
||||
size = sizeof(runas);
|
||||
conf_get_string("general","runas","nobody",runas,&size);
|
||||
if(rend_init(runas)) {
|
||||
DPRINTF(E_FATAL,L_MAIN|L_REND,"Error in rend_init: %s\n",strerror(errno));
|
||||
DPRINTF(E_FATAL,L_MAIN|L_REND,"Error in rend_init: %s\n",
|
||||
strerror(errno));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if(!os_init(config.foreground)) {
|
||||
if(!os_init(config.foreground,runas)) {
|
||||
DPRINTF(E_LOG,L_MAIN,"Could not initialize server\n");
|
||||
os_deinit();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
free(runas);
|
||||
|
||||
/* this will require that the db be readable by the runas user */
|
||||
size = sizeof(db_type);
|
||||
conf_get_string("general","db_type","sqlite",db_type,&size);
|
||||
size = sizeof(db_parms);
|
||||
conf_get_string("general","db_parms","/var/cache/mt-daapd",db_parms,&size);
|
||||
db_type = conf_alloc_string("general","db_type","sqlite");
|
||||
db_parms = conf_alloc_string("general","db_parms","/var/cache/mt-daapd");
|
||||
err=db_open(&perr,db_type,db_parms);
|
||||
|
||||
if(err) {
|
||||
|
@ -342,14 +336,16 @@ int main(int argc, char *argv[]) {
|
|||
db_type,db_parms,perr);
|
||||
}
|
||||
|
||||
free(db_type);
|
||||
free(db_parms);
|
||||
|
||||
/* Initialize the database before starting */
|
||||
DPRINTF(E_LOG,L_MAIN|L_DB,"Initializing database\n");
|
||||
if(db_init(reload)) {
|
||||
DPRINTF(E_FATAL,L_MAIN|L_DB,"Error in db_init: %s\n",strerror(errno));
|
||||
}
|
||||
|
||||
size = sizeof(mp3_dir);
|
||||
conf_get_string("general","mp3_dir","/mnt/mp3",mp3_dir,&size);
|
||||
mp3_dir = conf_alloc_string("general","mp3_dir","/mnt/mp3");
|
||||
if(!skip_initial) {
|
||||
DPRINTF(E_LOG,L_MAIN|L_SCAN,"Starting mp3 scan of %s\n",mp3_dir);
|
||||
|
||||
|
@ -357,10 +353,10 @@ int main(int argc, char *argv[]) {
|
|||
DPRINTF(E_FATAL,L_MAIN|L_SCAN,"Error scanning MP3 files: %s\n",strerror(errno));
|
||||
}
|
||||
}
|
||||
free(mp3_dir);
|
||||
|
||||
/* start up the web server */
|
||||
size = sizeof(web_root);
|
||||
conf_get_string("general","web_root",NULL,web_root,&size);
|
||||
web_root = conf_alloc_string("general","web_root",NULL);
|
||||
ws_config.web_root=web_root;
|
||||
ws_config.port=conf_get_int("general","port",3689);
|
||||
|
||||
|
@ -383,24 +379,25 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
#ifndef WITHOUT_MDNS
|
||||
if(config.use_mdns) { /* register services */
|
||||
size = sizeof(servername);
|
||||
conf_get_string("general","servername","mt-daapd",servername,&size);
|
||||
/* FIXME: get default name from hostname (os_hostname()?) */
|
||||
servername = conf_alloc_string("general","servername","mt-daapd");
|
||||
|
||||
memset(txtrecord,0,sizeof(txtrecord));
|
||||
txt_add(txtrecord,"txtvers=1");
|
||||
txt_add(txtrecord,"Database ID=beddab1edeadbea7");
|
||||
txt_add(txtrecord,"Machine ID=f00f00f00");
|
||||
txt_add(txtrecord,"Database ID=beddab1edeadbea7"); /* FIXME: config */
|
||||
txt_add(txtrecord,"Machine ID=f00f00f00"); /* ?? */
|
||||
txt_add(txtrecord,"Machine Name=%s",servername);
|
||||
txt_add(txtrecord,"mtd-version=" VERSION);
|
||||
txt_add(txtrecord,"iTSh Version=131073");
|
||||
txt_add(txtrecord,"Version=196610");
|
||||
txt_add(txtrecord,"iTSh Version=131073"); /* iTunes 6.0.4 */
|
||||
txt_add(txtrecord,"Version=196610"); /* iTunes 6.0.4 */
|
||||
txt_add(txtrecord,"Password=%s",conf_isset("general","password") ? "true" : "false");
|
||||
|
||||
DPRINTF(E_LOG,L_MAIN|L_REND,"Registering rendezvous names\n");
|
||||
size = sizeof(iface);
|
||||
conf_get_string("general","interface","",iface,&size);
|
||||
iface = conf_alloc_string("general","interface","");
|
||||
rend_register(servername,"_daap._tcp",ws_config.port,iface,txtrecord);
|
||||
rend_register(servername,"_http._tcp",ws_config.port,iface,txtrecord);
|
||||
free(servername);
|
||||
free(iface);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -431,12 +428,13 @@ int main(int argc, char *argv[]) {
|
|||
start_time=(int) time(NULL);
|
||||
|
||||
DPRINTF(E_LOG,L_MAIN|L_DB|L_SCAN,"Rescanning database\n");
|
||||
size = PATH_MAX;
|
||||
conf_get_string("general","mp3_dir","/mnt/mp3",mp3_dir,&size);
|
||||
/* FIXME: move mp3_dir to scanner */
|
||||
mp3_dir = conf_alloc_string("general","mp3_dir","/mnt/mp3");
|
||||
if(scan_init(mp3_dir)) {
|
||||
DPRINTF(E_LOG,L_MAIN|L_DB|L_SCAN,"Error rescanning... exiting\n");
|
||||
config.stop=1;
|
||||
}
|
||||
free(mp3_dir);
|
||||
config.reload=0;
|
||||
db_get_song_count(NULL,&song_count);
|
||||
DPRINTF(E_INF,L_MAIN|L_DB|L_SCAN,"Scanned %d songs (was %d) in "
|
||||
|
@ -465,7 +463,7 @@ int main(int argc, char *argv[]) {
|
|||
DPRINTF(E_LOG,L_MAIN|L_WS,"Stopping web server\n");
|
||||
ws_stop(config.server);
|
||||
*/
|
||||
|
||||
free(web_root);
|
||||
conf_close();
|
||||
|
||||
DPRINTF(E_LOG,L_MAIN|L_DB,"Closing database\n");
|
||||
|
|
|
@ -294,17 +294,15 @@ int scan_path(char *path) {
|
|||
char mp3_path[PATH_MAX];
|
||||
struct stat sb;
|
||||
int modified_time;
|
||||
char *ext;
|
||||
char *ext,*extensions;
|
||||
MP3FILE *pmp3;
|
||||
int is_compdir;
|
||||
|
||||
char extensions[PATH_MAX];
|
||||
int size = sizeof(extensions);
|
||||
|
||||
conf_get_string("general","extensions",".mp3,.m4a,.m4p",extensions,&size);
|
||||
extensions = conf_alloc_string("general","extensions",".mp3,.m4a,.m4p");
|
||||
|
||||
if((current_dir=opendir(path)) == NULL) {
|
||||
DPRINTF(E_WARN,L_SCAN,"opendir: %s\n",strerror(errno));
|
||||
free(extensions);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -314,6 +312,7 @@ int scan_path(char *path) {
|
|||
if(config.stop) {
|
||||
DPRINTF(E_WARN,L_SCAN,"Stop req. Aborting scan of %s.\n",path);
|
||||
closedir(current_dir);
|
||||
free(extensions);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -324,6 +323,7 @@ int scan_path(char *path) {
|
|||
DPRINTF(E_DBG,L_SCAN,"Error on readdir_r: %s\n",strerror(errno));
|
||||
err=errno;
|
||||
closedir(current_dir);
|
||||
free(extensions);
|
||||
errno=err;
|
||||
return -1;
|
||||
}
|
||||
|
@ -373,6 +373,7 @@ int scan_path(char *path) {
|
|||
}
|
||||
|
||||
closedir(current_dir);
|
||||
free(extensions);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <syslog.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
|
@ -78,13 +79,9 @@ char *_os_pidfile = PIDFILE;
|
|||
* @param foreground whether to run in fg or fork to bg
|
||||
* @returns TRUE on success, FALSE otherwise
|
||||
*/
|
||||
int os_init(int foreground) {
|
||||
int os_init(int foreground, char *runas) {
|
||||
int pid_fd;
|
||||
FILE *pid_fp=NULL;
|
||||
char runas[80];
|
||||
int size = sizeof(runas);
|
||||
|
||||
conf_get_string("general","runas","nobody",runas,&size);
|
||||
|
||||
/* open the pidfile, so it can be written once we detach */
|
||||
if(!foreground) {
|
||||
|
|
|
@ -58,9 +58,10 @@ char os_config_file[_MAX_PATH];
|
|||
* signal handlers (or ctrl-c handlers), etc
|
||||
*
|
||||
* @param background whether or not to start in background (service)
|
||||
* @param runas we'll ignore this, as it's a unix thang
|
||||
* @returns TRUE on success, FALSE otherwise
|
||||
*/
|
||||
int os_init(int foreground) {
|
||||
int os_init(int foreground, char *runas) {
|
||||
int err;
|
||||
|
||||
_os_socket_startup();
|
||||
|
|
2
src/os.h
2
src/os.h
|
@ -24,7 +24,7 @@
|
|||
|
||||
|
||||
/* backgrounding, signal handling, etc */
|
||||
extern int os_init(int foreground);
|
||||
extern int os_init(int foreground, char *runas);
|
||||
extern void os_deinit(void);
|
||||
|
||||
/* system native logging functions */
|
||||
|
|
|
@ -70,8 +70,6 @@ static sw_result rend_howl_reply(sw_discovery discovery,
|
|||
* Initialize howl and start runloop
|
||||
*/
|
||||
int rend_private_init(char *user) {
|
||||
sw_result result;
|
||||
|
||||
DPRINTF(E_DBG,L_REND,"Starting rendezvous services\n");
|
||||
signal(SIGHUP, SIG_IGN); // SIGHUP might happen from a request to reload the daap server
|
||||
|
||||
|
@ -106,7 +104,6 @@ int rend_private_init(char *user) {
|
|||
*/
|
||||
void *rend_pipe_monitor(void* arg) {
|
||||
fd_set rset;
|
||||
struct timeval tv;
|
||||
int result;
|
||||
|
||||
while(1) {
|
||||
|
@ -157,7 +154,7 @@ void rend_callback(void) {
|
|||
NULL, /* domain */
|
||||
NULL, /* host */
|
||||
msg.port,
|
||||
msg.txt,
|
||||
(sw_octets) msg.txt,
|
||||
strlen(msg.txt),
|
||||
rend_howl_reply,
|
||||
NULL,
|
||||
|
|
|
@ -30,6 +30,10 @@
|
|||
# include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#ifndef WIN32
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
#include "err.h"
|
||||
#include "mp3-scanner.h"
|
||||
#include "scan-aac.h"
|
||||
|
|
|
@ -30,6 +30,10 @@
|
|||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#ifndef WIN32
|
||||
#include <netinet/in.h>
|
||||
#endif
|
||||
|
||||
#include "err.h"
|
||||
#include "mp3-scanner.h"
|
||||
#include "scan-aac.h"
|
||||
|
|
20
src/ssc.c
20
src/ssc.c
|
@ -61,24 +61,25 @@
|
|||
* @returns 1 if should be converted. 0 if not
|
||||
*/
|
||||
int server_side_convert(char *codectype) {
|
||||
char ssc_codectypes[PATH_MAX];
|
||||
int size;
|
||||
char *ssc_codectypes;
|
||||
|
||||
size = sizeof(ssc_codectypes);
|
||||
conf_get_string("general","ssc_codectypes","ogg,flac,wma,alac",
|
||||
ssc_codectypes,&size);
|
||||
ssc_codectypes = conf_alloc_string("general","ssc_codectypes",
|
||||
"ogg,flac,wma,alac");
|
||||
|
||||
if ((!conf_isset("general","ssc_codectypes")) ||
|
||||
(!conf_isset("general","ssc_prog")) ||
|
||||
(!codectype)) {
|
||||
DPRINTF(E_DBG,L_SCAN,"Nope\n");
|
||||
free(ssc_codectypes);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(strcasestr(ssc_codectypes, codectype)) {
|
||||
free(ssc_codectypes);
|
||||
return 1;
|
||||
}
|
||||
|
||||
free(ssc_codectypes);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -95,14 +96,12 @@ FILE *server_side_convert_open(char *path, off_t offset, unsigned long len_ms, c
|
|||
char *newpath;
|
||||
char *metachars = "\"\\!(){}#*?$&<>`"; /* More?? */
|
||||
char metacount = 0;
|
||||
char *src,*dst;
|
||||
char ssc_prog[PATH_MAX];
|
||||
int size;
|
||||
char *src,*dst,*ssc_prog;
|
||||
|
||||
size = sizeof(ssc_prog);
|
||||
conf_get_string("general","ssc_prog","",ssc_prog,&size);
|
||||
ssc_prog = conf_alloc_string("general","ssc_prog","");
|
||||
|
||||
if(ssc_prog[0] == '\0') { /* can't happen */
|
||||
free(ssc_prog);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -148,6 +147,7 @@ FILE *server_side_convert_open(char *path, off_t offset, unsigned long len_ms, c
|
|||
f = popen(cmd, "r");
|
||||
free(newpath);
|
||||
free(cmd); /* should really have in-place expanded the path */
|
||||
free(ssc_prog);
|
||||
return f;
|
||||
}
|
||||
|
||||
|
|
|
@ -370,4 +370,4 @@ char *strptime(char *buf, char *fmt, struct tm *tm) {
|
|||
return buf;
|
||||
}
|
||||
|
||||
#endif /* ndef HAVE_STRPTIME */
|
||||
#endif /* ndef HAVE_STRPTIME */
|
||||
|
|
Loading…
Reference in New Issue