Fixes for mlit to xml translation with string length of 0, suggested by Stefan Bruns

This commit is contained in:
Ron Pedde 2005-10-26 06:00:54 +00:00
parent 4c89c687a6
commit 64e1af83a4
4 changed files with 74 additions and 41 deletions

View File

@ -91,6 +91,7 @@ Mark Woehrer
Stefan Bruns Stefan Bruns
* Speedups for javascript in playlist page, konq fixes, css fixes * Speedups for javascript in playlist page, konq fixes, css fixes
* Fixes for mlit -> xml serialization when block len = 0
blech (from the forums) blech (from the forums)
* Fixes for iTunes 5 view persistence * Fixes for iTunes 5 view persistence
@ -101,4 +102,3 @@ Phil Packer
Diego Penneno Diego Penneno
* Patches for multiple PID files to facilitate gentoo init scripts * Patches for multiple PID files to facilitate gentoo init scripts

View File

@ -31,7 +31,7 @@
</table> </table>
<input type="button" onclick="javascript:pl_update();" name="submit_button" value="Submit"> <input type="button" onclick="javascript:pl_update();" name="submit_button" value="Submit">
<input type="button" value="Cancel"> <input type="button" onclick="javascript:pl_cancel();" value="Cancel">
</form> </form>
</div> </div>

View File

@ -1,14 +1,34 @@
var req; var req;
var playlist_info={}; var playlist_info={};
function pl_editor_state(state) {
var pleditor = document.getElementById("pl_editor");
if(!pleditor)
return;
if(state) {
pleditor.style.display="block";
} else {
pleditor.style.display="none";
}
return;
}
function pl_errormsg(msg) { function pl_errormsg(msg) {
var msgdiv = document.getElementById("pl_warning"); var msgdiv = document.getElementById("pl_warning");
if(!msgdiv) if(!msgdiv)
return; return;
msgdiv.innerHTML = msg + "\n"; msgdiv.innerHTML = msg + "\n";
msgdiv.style.display="block";
if(msg == "") {
msgdiv.style.display="none";
} else {
msgdiv.style.display="block";
}
} }
function pl_displayresults(xmldoc) { function pl_displayresults(xmldoc) {
@ -17,7 +37,6 @@ function pl_displayresults(xmldoc) {
function pl_update() { function pl_update() {
/* this is either update or create, depending... */ /* this is either update or create, depending... */
var id, name, spec; var id, name, spec;
var pleditor=document.getElementById("pl_editor");
id = document.forms['pl_form']['playlist_id'].value; id = document.forms['pl_form']['playlist_id'].value;
name = encodeURIComponent(document.forms['pl_form']['playlist_name'].value); name = encodeURIComponent(document.forms['pl_form']['playlist_name'].value);
@ -32,24 +51,26 @@ function pl_update() {
} }
init(); init();
pleditor.style.display="none"; pl_editor_state(false);
}
function pl_cancel() {
pl_errormsg("Cancelled");
pl_editor_state(false);
} }
function pl_new() { function pl_new() {
var msgdiv = document.getElementById("pl_warning"); var msgdiv = document.getElementById("pl_warning");
var pleditor=document.getElementById("pl_editor"); var pleditor=document.getElementById("pl_editor");
if((!msgdiv)||(!pleditor)) pl_errormsg("");
return;
msgdiv.style.display="none";
document.forms['pl_form']['playlist_id'].value='0'; document.forms['pl_form']['playlist_id'].value='0';
document.forms['pl_form']['playlist_name'].value = 'New Playlist'; document.forms['pl_form']['playlist_name'].value = 'New Playlist';
document.forms['pl_form']['playlist_spec'].value = ''; document.forms['pl_form']['playlist_spec'].value = '';
document.forms['pl_form']['submit_button'].value = 'Create'; document.forms['pl_form']['submit_button'].value = 'Create';
pleditor.style.display="block"; pl_editor_state(true);
} }
function pl_delete(pl_id) { function pl_delete(pl_id) {
@ -101,13 +122,20 @@ function pl_process() {
while(pl_table.childNodes.length > 0) { while(pl_table.childNodes.length > 0) {
pl_table.removeChild(pl_table.lastChild); pl_table.removeChild(pl_table.lastChild);
} }
for(var x=0; x < playlists.length; x++) { for(var x=0; x < playlists.length; x++) {
var pl_id=playlists[x].getElementsByTagName("dmap.itemid")[0].firstChild.nodeValue; var pl_id;
var pl_name=playlists[x].getElementsByTagName("dmap.itemname")[0].firstChild.nodeValue; var pl_name;
var pl_type=playlists[x].getElementsByTagName("org.mt-daapd.playlist-type")[0].firstChild.nodeValue; var pl_type;
pl_id=playlists[x].getElementsByTagName("dmap.itemid")[0].firstChild.nodeValue;
if(playlists[x].getElementsByTagName("dmap.itemname")[0].firstChild) {
pl_name=playlists[x].getElementsByTagName("dmap.itemname")[0].firstChild.nodeValue;
} else {
pl_name = "";
}
pl_type=playlists[x].getElementsByTagName("org.mt-daapd.playlist-type")[0].firstChild.nodeValue;
playlist_info[String(pl_id)] = { 'name': pl_name, 'type': pl_type }; playlist_info[String(pl_id)] = { 'name': pl_name, 'type': pl_type };
if(pl_type == 1) { if(pl_type == 1) {
var pl_spec=playlists[x].getElementsByTagName("org.mt-daapd.smart-playlist-spec")[0].firstChild.nodeValue; var pl_spec=playlists[x].getElementsByTagName("org.mt-daapd.smart-playlist-spec")[0].firstChild.nodeValue;
@ -129,26 +157,27 @@ function pl_process() {
break; break;
} }
if(playlist_info[pl_id]['type'] == 1) {
var row = document.createElement("tr"); var row = document.createElement("tr");
var td1 = document.createElement("td"); var td1 = document.createElement("td");
var td2 = document.createElement("td"); var td2 = document.createElement("td");
var td3 = document.createElement("td"); var td3 = document.createElement("td");
var td4 = document.createElement("td"); var td4 = document.createElement("td");
td1.innerHTML=pl_id + '\n'; td1.innerHTML=pl_id + '\n';
td2.innerHTML=pl_name + '\n'; td2.innerHTML=pl_name + '\n';
td3.innerHTML=pl_type + '\n'; td3.innerHTML=pl_type + '\n';
if((pl_id != 1) && (playlist_info[pl_id]['type'] == 1)) {
td4.innerHTML='<a href="javascript:pl_edit(' + pl_id + ')">Edit</a>'; td4.innerHTML='<a href="javascript:pl_edit(' + pl_id + ')">Edit</a>';
if(pl_id != 1) { td4.innerHTML = td4.innerHTML + '&nbsp;<a href="javascript:pl_delete(' + pl_id + ')">Delete</a>';
td4.innerHTML = td4.innerHTML + '&nbsp;<a href="javascript:pl_delete(' + pl_id + ')">Delete</a>'; } else {
} td4.innerHTML="&nbsp;";
row.appendChild(td1);
row.appendChild(td2);
row.appendChild(td3);
row.appendChild(td4);
pl_table.appendChild(row);
} }
row.appendChild(td1);
row.appendChild(td2);
row.appendChild(td3);
row.appendChild(td4);
pl_table.appendChild(row);
} }
} }

View File

@ -414,9 +414,11 @@ int dispatch_output_xml_write(WS_CONNINFO *pwsc, DBQUERYINFO *pqi, unsigned char
r_fdprintf(pwsc->fd,"%ll",ivalue); r_fdprintf(pwsc->fd,"%ll",ivalue);
break; break;
case 0x09: /* string */ case 0x09: /* string */
encoded_string=dispatch_xml_encode((char*)data,block_len); if(block_len) {
r_fdprintf(pwsc->fd,"%s",encoded_string); encoded_string=dispatch_xml_encode((char*)data,block_len);
free(encoded_string); r_fdprintf(pwsc->fd,"%s",encoded_string);
free(encoded_string);
}
break; break;
case 0x0B: /* version? */ case 0x0B: /* version? */
if(block_len != 4) { if(block_len != 4) {
@ -429,9 +431,11 @@ int dispatch_output_xml_write(WS_CONNINFO *pwsc, DBQUERYINFO *pqi, unsigned char
case 0x0C: case 0x0C:
if((poi->browse_response)&&(strcmp(block_tag,"mlit") ==0)) { if((poi->browse_response)&&(strcmp(block_tag,"mlit") ==0)) {
encoded_string=dispatch_xml_encode((char*)data,block_len); if(block_len) {
r_fdprintf(pwsc->fd,"%s",encoded_string); encoded_string=dispatch_xml_encode((char*)data,block_len);
free(encoded_string); r_fdprintf(pwsc->fd,"%s",encoded_string);
free(encoded_string);
}
} else { } else {
/* we'll need to stack this up and try and remember where we /* we'll need to stack this up and try and remember where we
* came from. Make it an extra 8 so that it gets fixed to * came from. Make it an extra 8 so that it gets fixed to
@ -545,7 +549,7 @@ char *dispatch_xml_encode(char *original, int len) {
} else { } else {
truelen=strlen(original); truelen=strlen(original);
} }
destsize = 6*truelen+1; destsize = 6*truelen+1;
new=(char *)malloc(destsize); new=(char *)malloc(destsize);
if(!new) return NULL; if(!new) return NULL;