Re: [PATCH] - improved decoding of URL special characters
Peter Ganzhorn <[email protected]> Sat, 05 Nov 2005 13:09:53 +0100
| Newsgroups | gmane.comp.multimedia.xmms.devel |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format. --------------040302040700090606050600 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit I think your patch is pretty useful and if one of the developers will decide to merge it into CVS for the next XMMS release, I made the patch fitting for CVS from 2005-11-05 to keep everything as simple as possible. The added/removed code is 100% identical to the previous patch using Andrew's algorithm, only the numbers of the lines are matching the CVS code. See attachment ;) Peter Dustin Kirkland wrote: >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); >> >> >> > >_______________________________________________ >xmms-devel mailing list >[email protected] >http://lists.xmms.org/mailman/listinfo/xmms-devel > > > > --------------040302040700090606050600 Content-Type: text/x-patch; name="urldecode_CVS20051105.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="urldecode_CVS20051105.diff" --- xmms-20051105/xmms/playlist.c 2005-10-07 07:22:06.000000000 +0200 +++ xmms-urldecode/xmms/playlist.c 2005-11-05 11:22:29.000000000 +0100 @@ -1026,18 +1026,9 @@ if (cfg.convert_underscore) 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; } int playlist_get_current_length(void) --- xmms-20051105/xmms/playlist_list.c 2003-06-08 23:52:02.000000000 +0200 +++ xmms-urldecode/xmms/playlist_list.c 2005-11-05 11:22:27.000000000 +0100 @@ -313,20 +313,9 @@ wtext[i] = L' '; } 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; while (gdk_text_width_wc(font, wtext, len) > width && len > 4) @@ -365,16 +354,10 @@ if (cfg.convert_underscore) 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) { len--; --- xmms-20051105/xmms/urldecode.c 2004-03-17 05:04:52.000000000 +0100 +++ xmms-urldecode/xmms/urldecode.c 2005-11-05 11:57:16.000000000 +0100 @@ -60,4 +60,32 @@ g_free(tmp); 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; +} --- xmms-20051105/xmms/urldecode.h 2004-03-17 05:04:52.000000000 +0100 +++ xmms-urldecode/xmms/urldecode.h 2005-11-05 11:56:56.000000000 +0100 @@ -16,4 +16,5 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ char *xmms_urldecode_path(char *); +int urldecodestr(char *buf); --------------040302040700090606050600 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ xmms-devel mailing list [email protected] http://lists.xmms.org/mailman/listinfo/xmms-devel --------------040302040700090606050600--