Re: [PATCH] - improved decoding of URL special characters
Dustin Kirkland <[email protected]> Thu, 3 Nov 2005 13:08:00 -0600
| Newsgroups | gmane.comp.multimedia.xmms.devel |
|---|---|
| Message-ID | <[email protected]> |
Would the maintainer(s) please comment on whether or not this patch is acceptable or interesting to the next release of XMMS? I'm happy to rework it to something more palatable if that's needed. But I'd really like to see this minor annoyance fixed. :-Dustin On 10/20/05, Dustin Kirkland <[email protected]> wrote: > On 10/20/05, Andrew Sveikauskas <[email protected]> wrote: > > Sure. Go for it. > > The following is an updated patch utilizing Andrew's more efficient > algorithm. Can this be considered for inclusion? > > :-Dustin > > > > diff -urpN xmms-1.2.10/xmms/playlist.c xmms-1.2.10-urldecodestr/xmms/playlist.c > --- xmms-1.2.10/xmms/playlist.c 2004-02-23 14:31:43.000000000 -0600 > +++ xmms-1.2.10-urldecodestr/xmms/playlist.c 2005-10-20 11:37:46.000000000 -0500 > @@ -983,16 +983,7 @@ char *playlist_get_info_text(void) > while ((tmp = strchr(text, '_')) != NULL) > *tmp = ' '; > if (cfg.convert_twenty) > - while ((tmp = strstr(text, "%20")) != NULL) > - { > - char *tmp2; > - tmp2 = tmp + 3; > - *(tmp++) = ' '; > - while (*tmp2) > - *(tmp++) = *(tmp2++); > - *tmp = '\0'; > - } > - > + urldecodestr(text); > return text; > } > > diff -urpN xmms-1.2.10/xmms/playlist_list.c > xmms-1.2.10-urldecodestr/xmms/playlist_list.c > --- xmms-1.2.10/xmms/playlist_list.c 2003-06-11 13:44:17.000000000 -0500 > +++ xmms-1.2.10-urldecodestr/xmms/playlist_list.c 2005-10-20 > 11:37:46.000000000 -0500 > @@ -314,18 +314,7 @@ void playlist_list_draw_string_wc(PlayLi > } > > if (cfg.convert_twenty && len > 2) > - { > - GdkWChar *wtmp; > - while ((wtmp = find_in_wstr(wtext, "%20")) != NULL) > - { > - GdkWChar *wtmp2 = wtmp + 3; > - *(wtmp++) = L' '; > - while (*wtmp2) > - *(wtmp++) = *(wtmp2++); > - *wtmp = L'\0'; > - len -= 2; > - } > - } > + urldecodestr(wtext); > > newlen = len + 2; > > @@ -366,14 +355,8 @@ void playlist_list_draw_string(PlayList_ > while ((tmp = strchr(text, '_')) != NULL) > *tmp = ' '; > if (cfg.convert_twenty) > - while ((tmp = strstr(text, "%20")) != NULL) > - { > - char *tmp2 = tmp + 3; > - *(tmp++) = ' '; > - while (*tmp2) > - *(tmp++) = *(tmp2++); > - *tmp = '\0'; > - } > + urldecodestr(text); > + > len = strlen(text); > while (gdk_text_width(font, text, len) > width && len > 4) > { > diff -urpN xmms-1.2.10/xmms/urldecode.c > xmms-1.2.10-urldecodestr/xmms/urldecode.c > --- xmms-1.2.10/xmms/urldecode.c 2003-05-19 16:22:08.000000000 -0500 > +++ xmms-1.2.10-urldecodestr/xmms/urldecode.c 2005-10-20 > 11:37:49.000000000 -0500 > @@ -61,3 +61,31 @@ char *xmms_urldecode_path(char *encoded_ > > return encoded_path; > } > + > + > +int urldecodestr( char *buf ) > +{ > + const char *r = buf; > + while( *r ) { > + switch( *r ) { > + case '%': > + /* Is this followed by a 2-digit hex string? */ > + if( isxdigit(r[1]) && isxdigit(r[2]) ) > + { > + char hexstr[2]; > + int i; > + hexstr[0] = *++r; > + hexstr[1] = *++r; > + ++r; > + sscanf( hexstr, "%x", &i ); > + *buf++ = i; > + break; > + } > + /* No, examine next char. */ > + default: > + *buf++ = *r++; > + } > + } > + *buf = 0; > + return 0; > +} > diff -urpN xmms-1.2.10/xmms/urldecode.h > xmms-1.2.10-urldecodestr/xmms/urldecode.h > --- xmms-1.2.10/xmms/urldecode.h 2000-05-31 21:56:20.000000000 -0500 > +++ xmms-1.2.10-urldecodestr/xmms/urldecode.h 2005-10-20 > 11:37:58.000000000 -0500 > @@ -17,3 +17,4 @@ > */ > > char *xmms_urldecode_path(char *); > +int urldecodestr(char *buf); >