diff --git a/src/conf.c b/src/conf.c index 1c70ea89..c413cb4c 100644 --- a/src/conf.c +++ b/src/conf.c @@ -614,7 +614,7 @@ int conf_read(char *file) { DPRINTF(E_FATAL,L_CONF,"Malloc eror in io_new()\n"); DPRINTF(E_DBG,L_CONF,"Loading config file %s\n",conf_file); - if(!io_open(hconfig,"file://%U",conf_file)) { + if(!io_open(hconfig,"file://%U?ascii=1",conf_file)) { DPRINTF(E_LOG,L_MISC,"Error opening config file: %s\n",io_errstr(hconfig)); io_dispose(hconfig); return CONF_E_FOPEN; @@ -1255,7 +1255,7 @@ int conf_write(void) { if(!outfile) DPRINTF(E_FATAL,L_CONF,"io_new failed in conf_write\n"); - if(io_open(outfile,"file://%U?mode=w",conf_main_file)) { + if(io_open(outfile,"file://%U?mode=w&ascii=1",conf_main_file)) { retval = _conf_write(outfile,conf_main,0,NULL); io_close(outfile); io_dispose(outfile); diff --git a/src/err.c b/src/err.c index 894daad2..8a51fe71 100644 --- a/src/err.c +++ b/src/err.c @@ -111,7 +111,7 @@ void err_reopen(void) { return; io_close(err_file); - if(!io_open("file://%U?mode=a",err_filename)) { + if(!io_open("file://%U?mode=a&ascii=1",err_filename)) { /* what to do when you lose your logging mechanism? Keep * going? */ diff --git a/src/io.c b/src/io.c index f496925c..7a05619f 100644 --- a/src/io.c +++ b/src/io.c @@ -898,22 +898,28 @@ int io_readline_timed(IO_PRIVHANDLE *phandle, unsigned char *buf, uint32_t *len, uint32_t *ms) { uint32_t numread = 0; uint32_t to_read; - + int ascii = 0; + + if(io_option_get(phandle,"ascii",NULL)) + ascii = 1; + io_err_printf(IO_LOG_SPAM,"entering readline_timed\n"); while(numread < (*len - 1)) { to_read = 1; if(io_read_timeout(phandle, buf + numread, &to_read, ms)) { - numread += to_read; - if(buf[numread-1] == '\n') { - buf[numread-1] = '\0'; - *len = numread; - return TRUE; - } - if(!to_read) { /* EOF */ - *len = numread; - buf[numread] = '\0'; - return TRUE; + if((!ascii) || (to_read != '\r')) { + numread += to_read; + if(buf[numread-1] == '\n') { + buf[numread-1] = '\0'; + *len = numread; + return TRUE; + } + if(!to_read) { /* EOF */ + *len = numread; + buf[numread] = '\0'; + return TRUE; + } } } } @@ -955,13 +961,21 @@ int io_readline(IO_PRIVHANDLE *phandle, unsigned char *buf, */ int io_write(IO_PRIVHANDLE *phandle, unsigned char *buf, uint32_t *len) { int result; + int ascii=0; + int must_free=FALSE; + unsigned char *real_buffer; + unsigned char *dst; + uint32_t ascii_len; + uint32_t index; + uint32_t real_len; + ASSERT(io_initialized); /* call io_init first */ ASSERT(phandle); ASSERT(phandle->open); ASSERT(phandle->fnptr); ASSERT(phandle->fnptr->fn_write); - + if((!phandle) || (!phandle->open) || (!phandle->fnptr)) { io_err(phandle,IO_E_NOTINIT); *len = 0; @@ -974,10 +988,50 @@ int io_write(IO_PRIVHANDLE *phandle, unsigned char *buf, uint32_t *len) { return FALSE; } - result = phandle->fnptr->fn_write(phandle,buf,len); + +#ifdef WIN32 + // We won't do ascii mode on non-windows platforms + if(io_option_get(phandle,"ascii",NULL)) + ascii = 1; +#endif + + if(ascii) { + ascii_len = *len; + for(index = 0; index < *len; index++) { + if(buf[index] == '\n') + ascii_len++; + } + real_buffer = (unsigned char *)malloc(ascii_len); + if(!real_buffer) { + io_err_printf(IO_LOG_FATAL,"Could not alloc buffer in io_printf\n"); + exit(-1); + } + + must_free = TRUE; + dst = real_buffer; + for(index = 0; index < *len; index++) { + *dst++ = buf[index]; + if(buf[index] == '\n') + *dst++ = '\r'; + } + real_len = ascii_len; + } else { + real_buffer = buf; /* just write what was passed */ + real_len = *len; + } + + result = phandle->fnptr->fn_write(phandle,real_buffer,&real_len); + if(!result) io_err(phandle,IO_E_OTHER); + if(must_free) { + if(real_len == ascii_len) /* lie about how much we wrote */ + real_len = *len; + free(real_buffer); + } + + *len = real_len; return result; } diff --git a/src/rxml.c b/src/rxml.c index d577a4ae..fc3520e4 100644 --- a/src/rxml.c +++ b/src/rxml.c @@ -148,7 +148,7 @@ int rxml_open(RXMLHANDLE *vp, char *file, if(!pnew->hfile) RXML_ERROR(pnew,E_RXML_MALLOC); - if(!io_open(pnew->hfile, "file://%U", file)) { + if(!io_open(pnew->hfile, "file://%U?ascii=1", file)) { io_dispose(pnew->hfile); pnew->hfile = NULL; RXML_ERROR(pnew,E_RXML_OPEN); diff --git a/src/scan-url.c b/src/scan-url.c index 80f4cf2c..e36a61f8 100644 --- a/src/scan-url.c +++ b/src/scan-url.c @@ -56,7 +56,7 @@ int scan_get_urlinfo(char *filename, MP3FILE *pmp3) { return FALSE; } - if(!io_open(hfile,"file://%U",filename)) { + if(!io_open(hfile,"file://%U?ascii=1",filename)) { DPRINTF(E_WARN,L_SCAN,"Could not open %s for reading: %s\n",filename, io_errstr(hfile)); io_dispose(hfile);