[Player-dev] CR: Don't convert client strings to utf8, as they (usually) are

[Player-dev] CR: Don't convert client strings to utf8, as they (usually) are

Ryan Gammon rgammon at real.com
Wed Aug 25 16:54:41 PDT 2004


> Why does this g_try_malloc use buf_desired while the below version of
> this same routine use strlen(buf)? Is this OK or a problem (I can see
> how buf_desired is calculated?


In the hx_player_get_statistic version, we ask hxclientkit for the size 
of the buffer required (buf_desired) and allocate this buffer.

In the statistics observer version, hxclientkit allocates the buffer and 
passes it in as a char*. We therefore have to calculate the length of 
this buffer, and then add 1 for the extra byte required by a unicode (c) 
(0xc2a9 instead of 0xa9), as we don't have buf_desired.


> Both versions only work after the word 'copyright'. Will you never
> see a copyright symbol any other place?


A typical copyright string is: "(C) 2002 My company",  where (C) is a 
single extended ascii character.

Both versions only work if the key is "copyright". Someone could 
probably put a (C) in something like the title too, but I worry that if 
brute-force search for 0xa9 on all statistic strings, I'll end up 
corrupting valid utf-8 strings.

> Since you have 2 versions of the same code, you might want to consolidate
> them into one common function if it doesn't a headache.
>
> Rest looks good.
> --greg.
>
>
>
> >+                    g_return_val_if_fail(utf8_val != FALSE, FALSE);
> >+
> >+                    strncpy(utf8_val, str_value, len);
> >+                    utf8_val[len] = 0xc2;
> >+                    utf8_val[len + 1] = 0xa9;
> >+                    strcpy(&utf8_val[len + 2], &str_value[len + 1]);
> >+                    g_free(str_value);
> >+                    str_value = utf8_val;
> >+                }
> >+            }
> >
> >             g_value_init(value, G_TYPE_STRING);
> >-            g_value_set_string_take_ownership(value, utf8_val);
> >+            g_value_set_string_take_ownership(value, str_value);
> >             break;
> >
> >         default:
> >Index: hxstatisticsobserver.cpp
> >===================================================================
> >RCS file: /cvsroot/player/common/gtk/hxstatisticsobserver.cpp,v
> >retrieving revision 1.5
> >diff -u -r1.5 hxstatisticsobserver.cpp
> >--- hxstatisticsobserver.cpp    9 Jul 2004 18:24:08 -0000    1.5
> >+++ hxstatisticsobserver.cpp    25 Aug 2004 21:07:21 -0000
> >@@ -71,13 +71,12 @@
> > static void hx_statistics_observer_finalize   
> (GObject*                   object);
> >
> > static void
> >-make_gvalue(GValue*              value,
> >+make_gvalue(const gchar*         key,
> >+            GValue*              value,
> >             int                  valueType,
> >             const unsigned char* szBuf)
> > {
> >-    gsize in;
> >-    gsize out;
> >-    gchar *utf8_val;
> >+    gchar *utf8_val = NULL;
> >     const gchar* buf = (const gchar*)szBuf;
> >
> >     switch(valueType)
> >@@ -88,10 +87,30 @@
> >             break;
> >
> >         case kValueTypeString:
> >-            in = strlen(buf) + 1;
> >-            out = 0;
> >-            utf8_val = g_convert(buf, in - 1, "UTF-8", "ISO-8859-1", 
> &in, &out, NULL);
> >-            g_assert(utf8_val);
> >+            if(strcasecmp(key, "copyright") == 0)
> >+            {
> >+                gchar* copyright_symbol = strchr(buf, 0xa9);
> >+
> >+                if(copyright_symbol)
> >+                {
> >+                    gint len;
> >+
> >+                    len = copyright_symbol - buf;
> >+
> >+                    /* Make the copyright symbol proper utf-8 */
> >+                    utf8_val = (gchar*) g_try_malloc(strlen(buf) + 2);
> >+
> >+                    strncpy(utf8_val, buf, len);
> >+                    utf8_val[len] = 0xc2;
> >+                    utf8_val[len + 1] = 0xa9;
> >+                    strcpy(&utf8_val[len + 2], &buf[len + 1]);
> >+                }
> >+            }
> >+
> >+            if(!utf8_val)
> >+            {
> >+                utf8_val = g_strdup(buf);
> >+            }
> >
> >             g_value_init(value, G_TYPE_STRING);
> >             g_value_set_string_take_ownership(value, utf8_val);
> >@@ -112,7 +131,7 @@
> >     GValue value;
> >
> >     memset(&value, 0, sizeof(value));
> >-    make_gvalue(&value, valueType, pValue);
> >+    make_gvalue(pStatisticName, &value, valueType, pValue);
> >
> >     g_signal_emit(G_OBJECT(observerInfo), 
> signals[STATISTIC_ADDED_SIGNAL], 0,
> >                   pStatisticName, (gpointer)&value);
> >@@ -129,7 +148,7 @@
> >     GValue value;
> >
> >     memset(&value, 0, sizeof(value));
> >-    make_gvalue(&value, valueType, pValue);
> >+    make_gvalue(pStatisticName, &value, valueType, pValue);
> >
> >     g_signal_emit(G_OBJECT(observerInfo), 
> signals[STATISTIC_MODIFIED_SIGNAL], 0,
> >                   pStatisticName, (gpointer)&value);
>
>


-- 
Ryan Gammon
rgammon at real.com
Developer for Helix Player
https://player.helixcommunity.org




More information about the Player-dev mailing list
 

Site Map   |   Terms of Use   |   Privacy Policy   |   Contact Us

Copyright © 1995-2007 RealNetworks, Inc. All rights reserved. RealNetworks and Helix are trademarks of RealNetworks.
All other trademarks or registered trademarks are the property of their respective holders.