Fix garbage characters on entity-encoding dmap strings, also fix browse results

This commit is contained in:
Ron Pedde 2005-03-04 05:16:34 +00:00
parent 72d2d7c5c8
commit ea71a2b410

View File

@ -353,12 +353,20 @@ DAAP_ITEMS *daap_lookup_tag(char *tag) {
/** /**
* xml entity encoding, stupid style * xml entity encoding, stupid style
*/ */
char *daap_xml_entity_encode(char *original) { char *daap_xml_entity_encode(char *original, int len) {
char *new; char *new;
char *s, *d; char *s, *d;
int destsize; int destsize;
int truelen;
destsize = 6*strlen(original)+1; /* this is about stupid */
if(len) {
truelen=len;
} else {
truelen=strlen(original);
}
destsize = 6*truelen+1;
new=(char *)malloc(destsize); new=(char *)malloc(destsize);
if(!new) return NULL; if(!new) return NULL;
@ -367,7 +375,7 @@ char *daap_xml_entity_encode(char *original) {
s=original; s=original;
d=new; d=new;
while(*s) { while(s < (original+truelen)) {
switch(*s) { switch(*s) {
case '>': case '>':
strcat(d,"&gt;"); strcat(d,"&gt;");
@ -420,56 +428,57 @@ int daap_serialize_xml(DAAP_BLOCK *root, int fd) {
pitem=daap_lookup_tag(root->tag); pitem=daap_lookup_tag(root->tag);
r_fdprintf(fd,"<%s>",pitem->description); r_fdprintf(fd,"<%s>",pitem->description);
if(pitem->type != 0x0c) { /* container */ switch(pitem->type) {
switch(pitem->type) { case 0x01: /* byte */
case 0x01: /* byte */ r_fdprintf(fd,"%d",*((char *)data));
r_fdprintf(fd,"%d",*((char *)data)); break;
break; case 0x02: /* unsigned byte */
case 0x02: /* unsigned byte */ r_fdprintf(fd,"%ud",*((char *)data));
r_fdprintf(fd,"%ud",*((char *)data)); break;
break; case 0x03: /* short */
case 0x03: /* short */ ivalue = data[0] << 8 | data[1];
ivalue = data[0] << 8 | data[1]; r_fdprintf(fd,"%d",ivalue);
r_fdprintf(fd,"%d",ivalue); break;
break; case 0x05: /* int */
case 0x05: /* int */ case 0x0A: /* epoch */
case 0x0A: /* epoch */ ivalue = data[0] << 24 |
ivalue = data[0] << 24 | data[1] << 16 |
data[1] << 16 | data[2] << 8 |
data[2] << 8 | data[3];
data[3]; r_fdprintf(fd,"%d",ivalue);
r_fdprintf(fd,"%d",ivalue); break;
break; case 0x07: /* long long */
case 0x07: /* long long */ ivalue = data[0] << 24 |
ivalue = data[0] << 24 | data[1] << 16 |
data[1] << 16 | data[2] << 8 |
data[2] << 8 | data[3];
data[3]; lvalue=ivalue;
lvalue=ivalue; ivalue = data[4] << 24 |
ivalue = data[4] << 24 | data[5] << 16 |
data[5] << 16 | data[6] << 8 |
data[6] << 8 | data[7];
data[7]; lvalue = (lvalue << 32) | ivalue;
lvalue = (lvalue << 32) | ivalue; r_fdprintf(fd,"%ll",ivalue);
r_fdprintf(fd,"%ll",ivalue); break;
break; case 0x09: /* string */
case 0x09: /* string */ case 0x0C: /* container, but mlit is a string in browse */
encoded_string=daap_xml_entity_encode(data); encoded_string=daap_xml_entity_encode(data,root->size);
r_fdprintf(fd,"%s",encoded_string); r_fdprintf(fd,"%s",encoded_string);
free(encoded_string); free(encoded_string);
break; break;
case 0x0B: /* version? */ case 0x0B: /* version? */
ivalue=data[0] << 8 | data[1]; ivalue=data[0] << 8 | data[1];
r_fdprintf(fd,"%d.%d.%d",ivalue,data[2],data[3]); r_fdprintf(fd,"%d.%d.%d",ivalue,data[2],data[3]);
break; break;
default: default:
DPRINTF(E_FATAL,L_DAAP,"Bad dmap type: %d, %s\n", DPRINTF(E_FATAL,L_DAAP,"Bad dmap type: %d, %s\n",
pitem->type, pitem->description); pitem->type, pitem->description);
break; break;
}
} else {
daap_serialize_xml(root->children,fd);
} }
if(root->children)
daap_serialize_xml(root->children,fd);
r_fdprintf(fd,"</%s>",pitem->description); r_fdprintf(fd,"</%s>",pitem->description);
root=root->next; root=root->next;
} }