[libdmapsharing] Changes to dmap-structure.{c,h} due to pedansee



commit 6cf4986b1b38161c60f701ba16b7bcf1d4555c98
Author: W. Michael Petullo <mike flyn org>
Date:   Mon Mar 19 14:52:44 2018 -0400

    Changes to dmap-structure.{c,h} due to pedansee
    
    Signed-off-by: W. Michael Petullo <mike flyn org>

 libdmapsharing/dmap-share.c     |    6 +-
 libdmapsharing/dmap-structure.c |  167 +++++++++++++++++++++------------------
 libdmapsharing/dmap-structure.h |    4 +-
 3 files changed, 95 insertions(+), 82 deletions(-)
---
diff --git a/libdmapsharing/dmap-share.c b/libdmapsharing/dmap-share.c
index 479297e..22f62c2 100644
--- a/libdmapsharing/dmap-share.c
+++ b/libdmapsharing/dmap-share.c
@@ -1007,7 +1007,7 @@ dmap_share_content_codes (DmapShare * share,
 
        g_debug ("Path is %s.", path);
 
-       defs = dmap_content_codes (&num_defs);
+       defs = dmap_structure_content_codes (&num_defs);
 
        mccr = dmap_structure_add (NULL, DMAP_CC_MCCR);
        dmap_structure_add (mccr, DMAP_CC_MSTT, (gint32) DMAP_STATUS_OK);
@@ -1017,9 +1017,7 @@ dmap_share_content_codes (DmapShare * share,
 
                mdcl = dmap_structure_add (mccr, DMAP_CC_MDCL);
                dmap_structure_add (mdcl, DMAP_CC_MCNM,
-                                   dmap_content_code_string_as_int32 (defs
-                                                                      [i].
-                                                                      string));
+                                   dmap_structure_cc_string_as_int32 (defs[i].string));
                dmap_structure_add (mdcl, DMAP_CC_MCNA, defs[i].name);
                dmap_structure_add (mdcl, DMAP_CC_MCTY,
                                    (gint32) defs[i].type);
diff --git a/libdmapsharing/dmap-structure.c b/libdmapsharing/dmap-structure.c
index 8907100..b922204 100644
--- a/libdmapsharing/dmap-structure.c
+++ b/libdmapsharing/dmap-structure.c
@@ -33,7 +33,7 @@
     ( (gint32)(gchar)(ch2) << 16 ) | \
     ( (gint32)(gchar)(ch3) << 24 ) ))
 
-static const DmapContentCodeDefinition cc_defs[] = {
+static const DmapContentCodeDefinition _cc_defs[] = {
        {DMAP_RAW, 0, "", "", DMAP_TYPE_STRING},
        {DMAP_CC_MDCL, MAKE_CONTENT_CODE ('m', 'd', 'c', 'l'),
         "dmap.dictionary", "mdcl", DMAP_TYPE_CONTAINER},
@@ -348,19 +348,19 @@ static const DmapContentCodeDefinition cc_defs[] = {
 
 };
 
-const gchar *
-dmap_content_code_name (DmapContentCode code)
+static const gchar *
+_cc_name (DmapContentCode code)
 {
-       return cc_defs[code - 1].name;
+       return _cc_defs[code - 1].name;
 }
 
-DmapType
-dmap_content_code_dmap_type (DmapContentCode code)
+static DmapType
+_cc_dmap_type (DmapContentCode code)
 {
        DmapType type = DMAP_TYPE_INVALID;
 
-       if (code < sizeof cc_defs / sizeof(DmapContentCodeDefinition)) {
-               type = cc_defs[code - 1].type;
+       if (code < sizeof _cc_defs / sizeof(DmapContentCodeDefinition)) {
+               type = _cc_defs[code - 1].type;
        } else {
                g_warning("Invalid content code: %d\n", code);
        }
@@ -368,40 +368,51 @@ dmap_content_code_dmap_type (DmapContentCode code)
        return type;
 }
 
-const gchar *
-dmap_content_code_string (DmapContentCode code)
+static const gchar *
+_cc_string (DmapContentCode code)
 {
-       return cc_defs[code - 1].string;
+       return _cc_defs[code - 1].string;
 }
 
 static GType
-dmap_content_code_gtype (DmapContentCode code)
+_cc_gtype (DmapContentCode code)
 {
-       switch (dmap_content_code_dmap_type (code)) {
+       GType type = G_TYPE_NONE;
+
+       switch (_cc_dmap_type (code)) {
        case DMAP_TYPE_BYTE:
        case DMAP_TYPE_SIGNED_INT:
-               return G_TYPE_CHAR;
+               type = G_TYPE_CHAR;
+               break;
        case DMAP_TYPE_SHORT:
        case DMAP_TYPE_INT:
        case DMAP_TYPE_DATE:
-               return G_TYPE_INT;
+               type = G_TYPE_INT;
+               break;
        case DMAP_TYPE_INT64:
-               return G_TYPE_INT64;
+               type = G_TYPE_INT64;
+               break;
        case DMAP_TYPE_VERSION:
-               return G_TYPE_DOUBLE;
+               type = G_TYPE_DOUBLE;
+               break;
        case DMAP_TYPE_STRING:
-               return G_TYPE_STRING;
+               type = G_TYPE_STRING;
+               break;
        case DMAP_TYPE_POINTER:
-               return G_TYPE_POINTER;
+               type = G_TYPE_POINTER;
+               break;
        case DMAP_TYPE_CONTAINER:
        case DMAP_TYPE_INVALID:
        default:
-               return G_TYPE_NONE;
+               type = G_TYPE_NONE;
+               break;
        }
+
+       return type;
 }
 
 static gboolean
-dmap_structure_node_serialize (GNode * node, GByteArray * array)
+_node_serialize (GNode * node, GByteArray * array)
 {
        DmapStructureItem *item = node->data;
        DmapType dmap_type;
@@ -410,13 +421,13 @@ dmap_structure_node_serialize (GNode * node, GByteArray * array)
        if (item->content_code != DMAP_RAW) {
                g_byte_array_append (array,
                                     (const guint8 *)
-                                    dmap_content_code_string (item->
+                                    _cc_string (item->
                                                               content_code),
                                     4);
                g_byte_array_append (array, (const guint8 *) &size, 4);
        }
 
-       dmap_type = dmap_content_code_dmap_type (item->content_code);
+       dmap_type = _cc_dmap_type (item->content_code);
 
        switch (dmap_type) {
        case DMAP_TYPE_BYTE:
@@ -510,7 +521,7 @@ dmap_structure_serialize (GNode * structure, guint * length)
        if (structure) {
                g_node_traverse (structure, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
                                 (GNodeTraverseFunc)
-                                dmap_structure_node_serialize, array);
+                                _node_serialize, array);
        }
 
        data = (gchar *) array->data;
@@ -521,35 +532,42 @@ dmap_structure_serialize (GNode * structure, guint * length)
 }
 
 DmapContentCode
-dmap_content_code_read_from_buffer (const gchar * buf)
+dmap_structure_cc_read_from_buffer (const gchar * buf)
 {
+       DmapContentCode cc = DMAP_CC_INVALID;
+
        gint32 c = MAKE_CONTENT_CODE (buf[0], buf[1], buf[2], buf[3]);
        guint i;
 
-       for (i = 0; i < G_N_ELEMENTS (cc_defs); i++) {
-               if (cc_defs[i].int_code == c) {
-                       return cc_defs[i].code;
+       for (i = 0; i < G_N_ELEMENTS (_cc_defs); i++) {
+               if (_cc_defs[i].int_code == c) {
+                       cc = _cc_defs[i].code;
+                       goto done;
                }
        }
 
        g_warning ("Content code %4s is invalid.", buf);
 
-       return DMAP_CC_INVALID;
+done:
+       return cc;
 }
 
 static gchar *
-dmap_buffer_read_string (const guint8 * buf, gsize size)
+_read_string (const guint8 * buf, gsize size)
 {
+       gchar *str;
+
        if (g_utf8_validate ((char *) buf, size, NULL) == TRUE) {
-               return g_strndup ((char *) buf, size);
+               str = g_strndup ((char *) buf, size);
        } else {
-               return g_strdup ("");
+               str = g_strdup ("");
        }
+
+       return str;
 }
 
 static void
-dmap_structure_parse_container_buffer (GNode * parent,
-                                      const guint8 * buf, gsize buf_length)
+_parse_container_buffer (GNode * parent, const guint8 * buf, gsize buf_length)
 {
        gint l = 0;
 
@@ -571,7 +589,7 @@ dmap_structure_parse_container_buffer (GNode * parent,
                        item->content_code = DMAP_RAW;
                        node = g_node_new (item);
                        g_node_append (parent, node);
-                       gchar *s = dmap_buffer_read_string (buf, buf_length);
+                       gchar *s = _read_string (buf, buf_length);
                        item->size = strlen (s);
                        g_value_init (&(item->content), G_TYPE_STRING);
                        g_value_take_string (&(item->content), s);
@@ -588,10 +606,10 @@ dmap_structure_parse_container_buffer (GNode * parent,
                        goto done;
                }
 
-               cc = dmap_content_code_read_from_buffer ((const gchar *)
-                                                        &(buf[l]));
+               cc = dmap_structure_cc_read_from_buffer ((const gchar *)
+                                                       &(buf[l]));
                if (cc == DMAP_CC_INVALID) {
-                       return;
+                       goto done;
                }
                l += 4;
 
@@ -604,7 +622,7 @@ dmap_structure_parse_container_buffer (GNode * parent,
                 */
                if (codesize > buf_length - l - 4 || codesize < 0) {
                        g_debug ("Invalid codesize %d received in buf_length %zd\n", codesize, buf_length);
-                       return;
+                       goto done;
                }
                l += 4;
 
@@ -613,13 +631,13 @@ dmap_structure_parse_container_buffer (GNode * parent,
                node = g_node_new (item);
                g_node_append (parent, node);
 
-               gtype = dmap_content_code_gtype (item->content_code);
+               gtype = _cc_gtype (item->content_code);
 
                if (gtype != G_TYPE_NONE) {
                        g_value_init (&(item->content), gtype);
                }
 // FIXME USE THE G_TYPE CONVERTOR FUNCTION dmap_type_to_gtype
-               switch (dmap_content_code_dmap_type (item->content_code)) {
+               switch (_cc_dmap_type (item->content_code)) {
                case DMAP_TYPE_SIGNED_INT:
                case DMAP_TYPE_BYTE:{
                                gchar c = 0;
@@ -669,9 +687,7 @@ dmap_structure_parse_container_buffer (GNode * parent,
                                break;
                        }
                case DMAP_TYPE_STRING:{
-                               gchar *s =
-                                       dmap_buffer_read_string (&(buf[l]),
-                                                                codesize);
+                               gchar *s = _read_string (&(buf[l]), codesize);
 
                                item->size = strlen (s);
                                g_value_take_string (&(item->content), s);
@@ -712,17 +728,14 @@ dmap_structure_parse_container_buffer (GNode * parent,
                                break;
                        }
                case DMAP_TYPE_CONTAINER:{
-                               dmap_structure_parse_container_buffer (node,
-                                                                      &(buf
-                                                                        [l]),
-                                                                      codesize);
+                               _parse_container_buffer (node, &(buf[l]), codesize);
                                break;
                        }
                case DMAP_TYPE_INVALID:
                default:
                        /*
                         * Bad type should have been caught as bad content code
-                        * by dmap_content_code_read_from_buffer()
+                        * by dmap_structure_cc_read_from_buffer()
                         */
                        g_assert_not_reached();
                }
@@ -742,8 +755,7 @@ dmap_structure_parse (const guint8 * buf, gsize buf_length)
 
        root = g_node_new (NULL);
 
-       dmap_structure_parse_container_buffer (root, (guchar *) buf,
-                                              buf_length);
+       _parse_container_buffer (root, (guchar *) buf, buf_length);
 
        child = root->children;
        if (child) {
@@ -761,31 +773,33 @@ struct NodeFinder
 };
 
 static gboolean
-gnode_find_node (GNode * node, gpointer data)
+_gnode_find_node (GNode * node, gpointer data)
 {
+       gboolean found = FALSE;
+
        struct NodeFinder *finder = (struct NodeFinder *) data;
        DmapStructureItem *item = node->data;
 
        if (item->content_code == finder->code) {
                finder->node = node;
-               return TRUE;
+               found = TRUE;
        }
 
-       return FALSE;
+       return found;
 }
 
 DmapStructureItem *
 dmap_structure_find_item (GNode * structure, DmapContentCode code)
 {
+       DmapStructureItem *item = NULL;
        GNode *node = NULL;
 
        node = dmap_structure_find_node (structure, code);
-
        if (node) {
-               return node->data;
+               item = node->data;
        }
 
-       return NULL;
+       return item;
 }
 
 GNode *
@@ -800,8 +814,8 @@ dmap_structure_add (GNode * parent, DmapContentCode cc, ...)
 
        va_start (list, cc);
 
-       dmap_type = dmap_content_code_dmap_type (cc);
-       gtype = dmap_content_code_gtype (cc);
+       dmap_type = _cc_dmap_type (cc);
+       gtype = _cc_gtype (cc);
 
        item = g_new0 (DmapStructureItem, 1);
        item->content_code = cc;
@@ -871,10 +885,11 @@ dmap_structure_add (GNode * parent, DmapContentCode cc, ...)
                while (parent) {
                        DmapStructureItem *parent_item = parent->data;
 
-                       if (cc == DMAP_RAW)
+                       if (cc == DMAP_RAW) {
                                parent_item->size += item->size;
-                       else
+                       } else {
                                parent_item->size += (4 + 4 + item->size);
+                       }
 
                        parent = parent->parent;
                }
@@ -894,7 +909,7 @@ dmap_structure_find_node (GNode * structure, DmapContentCode code)
        finder->code = code;
 
        g_node_traverse (structure, G_IN_ORDER, G_TRAVERSE_ALL, -1,
-                        gnode_find_node, finder);
+                        _gnode_find_node, finder);
 
        node = finder->node;
        g_free (finder);
@@ -904,9 +919,9 @@ dmap_structure_find_node (GNode * structure, DmapContentCode code)
 }
 
 static void
-dmap_item_free (DmapStructureItem * item)
+_dmap_item_free (DmapStructureItem * item)
 {
-       DmapType type = dmap_content_code_dmap_type (item->content_code);
+       DmapType type = _cc_dmap_type (item->content_code);
 
        if (DMAP_TYPE_INVALID != type && DMAP_TYPE_CONTAINER != type) {
                g_value_unset (&(item->content));
@@ -916,9 +931,9 @@ dmap_item_free (DmapStructureItem * item)
 }
 
 static gboolean
-gnode_free_dmap_item (GNode * node, gpointer data)
+_gnode_free_dmap_item (GNode * node, gpointer data)
 {
-       dmap_item_free ((DmapStructureItem *) node->data);
+       _dmap_item_free ((DmapStructureItem *) node->data);
 
        return FALSE;
 }
@@ -928,7 +943,7 @@ dmap_structure_destroy (GNode * structure)
 {
        if (structure) {
                g_node_traverse (structure, G_IN_ORDER, G_TRAVERSE_ALL, -1,
-                                gnode_free_dmap_item, NULL);
+                                _gnode_free_dmap_item, NULL);
 
                g_node_destroy (structure);
 
@@ -937,15 +952,15 @@ dmap_structure_destroy (GNode * structure)
 }
 
 const DmapContentCodeDefinition *
-dmap_content_codes (guint * number)
+dmap_structure_content_codes (guint * number)
 {
-       *number = G_N_ELEMENTS (cc_defs);
+       *number = G_N_ELEMENTS (_cc_defs);
 
-       return cc_defs;
+       return _cc_defs;
 }
 
 gint32
-dmap_content_code_string_as_int32 (const gchar * str)
+dmap_structure_cc_string_as_int32 (const gchar * str)
 {
        union
        {
@@ -959,7 +974,7 @@ dmap_content_code_string_as_int32 (const gchar * str)
 }
 
 static gboolean
-print_dmap_item (GNode * node, gpointer data)
+_print_dmap_item (GNode * node, gpointer data)
 {
        DmapStructureItem *item;
        const gchar *name;
@@ -972,7 +987,7 @@ print_dmap_item (GNode * node, gpointer data)
 
        item = node->data;
 
-       name = dmap_content_code_name (item->content_code);
+       name = _cc_name (item->content_code);
 
        if (G_IS_VALUE (&(item->content))) {
                value = g_strdup_value_contents (&(item->content));
@@ -992,7 +1007,7 @@ dmap_structure_print (GNode * structure)
 {
        if (structure) {
                g_node_traverse (structure, G_PRE_ORDER, G_TRAVERSE_ALL, -1,
-                                (GNodeTraverseFunc) print_dmap_item, NULL);
+                                (GNodeTraverseFunc) _print_dmap_item, NULL);
        }
 }
 
@@ -1001,10 +1016,10 @@ dmap_structure_get_size (GNode * structure)
 {
        DmapStructureItem *item = (DmapStructureItem *) structure->data;
 
-       g_assert (strlen(cc_defs[item->content_code].string) == 4);
+       g_assert (strlen(_cc_defs[item->content_code].string) == 4);
        g_assert (sizeof(item->size) == 4);
 
-       return item->size + strlen(cc_defs[item->content_code].string) + sizeof(item->size);
+       return item->size + strlen(_cc_defs[item->content_code].string) + sizeof(item->size);
 }
 
 void
diff --git a/libdmapsharing/dmap-structure.h b/libdmapsharing/dmap-structure.h
index a840513..87bb1ce 100644
--- a/libdmapsharing/dmap-structure.h
+++ b/libdmapsharing/dmap-structure.h
@@ -73,8 +73,8 @@ struct _DmapContentCodeDefinition
        DmapType type;
 };
 
-const DmapContentCodeDefinition * dmap_content_codes (guint * number);
-gint32 dmap_content_code_string_as_int32 (const gchar * str);
+const DmapContentCodeDefinition * dmap_structure_content_codes (guint * number);
+gint32 dmap_structure_cc_string_as_int32 (const gchar * str);
 const gchar *dmap_content_code_name (DmapContentCode code);
 DmapType dmap_content_code_dmap_type (DmapContentCode code);
 const gchar *dmap_content_code_string (DmapContentCode code);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]