[libdmapsharing] More adjustments to error handling and related tests



commit ecdd1d9faadfdf76e042e80d3b302e1287c0b6a9
Author: W. Michael Petullo <mike flyn org>
Date:   Sat Jul 21 21:47:39 2018 -0400

    More adjustments to error handling and related tests
    
    Signed-off-by: W. Michael Petullo <mike flyn org>

 libdmapsharing/dmap-av-share.c      | 72 ++++++++++++++++++-------------------
 libdmapsharing/dmap-connection.c    | 28 ++++++++++-----
 libdmapsharing/dmap-control-share.c | 10 +++---
 libdmapsharing/dmap-error.h         | 21 +++++++++--
 libdmapsharing/dmap-image-share.c   |  2 +-
 libdmapsharing/dmap-share.c         | 17 +++++----
 libdmapsharing/dmap-share.h         |  1 -
 libdmapsharing/dmap-structure.c     |  8 ++---
 libdmapsharing/generate-test-suites |  6 ++--
 9 files changed, 95 insertions(+), 70 deletions(-)
---
diff --git a/libdmapsharing/dmap-av-share.c b/libdmapsharing/dmap-av-share.c
index df859d7..6faab0e 100644
--- a/libdmapsharing/dmap-av-share.c
+++ b/libdmapsharing/dmap-av-share.c
@@ -171,7 +171,7 @@ dmap_av_share_server_info (DmapShare * share,
        g_object_get ((gpointer) share, "name", &nameprop, NULL);
 
        msrv = dmap_structure_add (NULL, DMAP_CC_MSRV);
-       dmap_structure_add (msrv, DMAP_CC_MSTT, (gint32) DMAP_STATUS_OK);
+       dmap_structure_add (msrv, DMAP_CC_MSTT, (gint32) SOUP_STATUS_OK);
        dmap_structure_add (msrv, DMAP_CC_MPRO, (gdouble) DAAP_VERSION);
        dmap_structure_add (msrv, DMAP_CC_APRO, (gdouble) DAAP_VERSION);
        /* 2/3 is for itunes 4.8 (at least).  its determined by the
@@ -321,7 +321,7 @@ _should_transcode (DmapAvShare *share,
 
        format2 = dmap_utils_mime_to_format (transcode_mimetype);
        if (NULL == format2) {
-               dmap_share_emit_error(DMAP_SHARE(share), DMAP_ERROR_FAILED,
+               dmap_share_emit_error(DMAP_SHARE(share), DMAP_STATUS_BAD_FORMAT,
                                     "Configured to transcode, but target format bad");
                goto done;
        }
@@ -355,7 +355,7 @@ _send_chunked_file (DmapAvShare *share, SoupServer * server, SoupMessage * messa
 
        g_object_get (record, "location", &location, "has-video", &has_video, NULL);
        if (NULL == location) {
-               dmap_share_emit_error(DMAP_SHARE(share), DMAP_ERROR_FAILED,
+               dmap_share_emit_error(DMAP_SHARE(share), DMAP_STATUS_RECORD_MISSING_FIELD,
                                     "Error getting location from record");
                goto done;
        }
@@ -368,14 +368,14 @@ _send_chunked_file (DmapAvShare *share, SoupServer * server, SoupMessage * messa
 
        stream = G_INPUT_STREAM (dmap_av_record_read (record, &error));
        if (error != NULL) {
-               dmap_share_emit_error(DMAP_SHARE(share), DMAP_ERROR_FAILED,
+               dmap_share_emit_error(DMAP_SHARE(share), DMAP_STATUS_OPEN_FAILED,
                                     "Cannot open %s", error->message);
                goto done;
        }
 
        g_object_get (record, "format", &format, NULL);
        if (NULL == format) {
-               dmap_share_emit_error(DMAP_SHARE(share), DMAP_ERROR_FAILED,
+               dmap_share_emit_error(DMAP_SHARE(share), DMAP_STATUS_RECORD_MISSING_FIELD,
                                     "Error getting format from record");
                goto done;
        }
@@ -386,7 +386,7 @@ _send_chunked_file (DmapAvShare *share, SoupServer * server, SoupMessage * messa
                cd->original_stream = stream;
                cd->stream = dmap_gst_input_stream_new (transcode_mimetype, stream);
 #else
-               dmap_share_emit_error(DMAP_SHARE(share), DMAP_ERROR_FAILED,
+               dmap_share_emit_error(DMAP_SHARE(share), DMAP_STATUS_BAD_FORMAT,
                                     "Transcode format %s not supported",
                                      transcode_mimetype);
                cd->original_stream = NULL;
@@ -399,14 +399,14 @@ _send_chunked_file (DmapAvShare *share, SoupServer * server, SoupMessage * messa
        }
 
        if (cd->stream == NULL) {
-               dmap_share_emit_error(DMAP_SHARE(share), DMAP_ERROR_FAILED,
+               dmap_share_emit_error(DMAP_SHARE(share), DMAP_STATUS_OPEN_FAILED,
                                     "Could not setup input stream");
                goto done;
        }
 
        if (offset != 0) {
                if (g_seekable_seek (G_SEEKABLE (cd->stream), offset, G_SEEK_SET, NULL, &error) == FALSE) {
-                       dmap_share_emit_error(DMAP_SHARE(share), DMAP_ERROR_FAILED,
+                       dmap_share_emit_error(DMAP_SHARE(share), DMAP_STATUS_SEEK_FAILED,
                                             "Error seeking: %s.", error->message);
                        goto done;
                }
@@ -449,21 +449,21 @@ _send_chunked_file (DmapAvShare *share, SoupServer * server, SoupMessage * messa
 
        if (0 == g_signal_connect (message, "wrote_headers",
                                   G_CALLBACK (dmap_private_utils_write_next_chunk), cd)) {
-               dmap_share_emit_error(DMAP_SHARE(share), DMAP_ERROR_FAILED,
+               dmap_share_emit_error(DMAP_SHARE(share), DMAP_STATUS_FAILED,
                                     "Error connecting to wrote_headers signal");
                goto done;
        }
 
        if (0 == g_signal_connect (message, "wrote_chunk",
                          G_CALLBACK (dmap_private_utils_write_next_chunk), cd)) {
-               dmap_share_emit_error(DMAP_SHARE(share), DMAP_ERROR_FAILED,
+               dmap_share_emit_error(DMAP_SHARE(share), DMAP_STATUS_FAILED,
                                     "Error connecting to wrote_chunk signal");
                goto done;
        }
 
        if (0 == g_signal_connect (message, "finished",
                          G_CALLBACK (dmap_private_utils_chunked_message_finished), cd)) {
-               dmap_share_emit_error(DMAP_SHARE(share), DMAP_ERROR_FAILED,
+               dmap_share_emit_error(DMAP_SHARE(share), DMAP_STATUS_FAILED,
                                     "Error connecting to finished signal");
                goto done;
        }
@@ -480,7 +480,7 @@ done:
                if (NULL != cd && NULL != cd->stream) {
                        ok = g_input_stream_close (cd->stream, NULL, &error);
                        if (!ok) {
-                               dmap_share_emit_error(DMAP_SHARE(share), DMAP_ERROR_FAILED,
+                               dmap_share_emit_error(DMAP_SHARE(share), DMAP_STATUS_CLOSE_FAILED,
                                                     "Error closing transcode stream: %s.",
                                                      error->message);
                        }
@@ -491,7 +491,7 @@ done:
                if (NULL != stream) {
                        ok = g_input_stream_close (stream, NULL, &error);
                        if (!ok) {
-                               dmap_share_emit_error(DMAP_SHARE(share), DMAP_ERROR_FAILED,
+                               dmap_share_emit_error(DMAP_SHARE(share), DMAP_STATUS_CLOSE_FAILED,
                                                     "Error closing stream: %s.",
                                                      error->message);
                        }
@@ -894,14 +894,14 @@ _databases_browse_xxx (DmapShare * share,
                                      category_items);
                category_cc = DMAP_CC_ABAL;
        } else {
-               dmap_share_emit_error(share, DMAP_ERROR_FAILED,
+               dmap_share_emit_error(share, DMAP_STATUS_BAD_BROWSE_CATEGORY,
                                     "Unsupported browse category: %s",
                                      browse_category);
                goto _bad_category;
        }
 
        abro = dmap_structure_add (NULL, DMAP_CC_ABRO);
-       dmap_structure_add (abro, DMAP_CC_MSTT, (gint32) DMAP_STATUS_OK);
+       dmap_structure_add (abro, DMAP_CC_MSTT, (gint32) SOUP_STATUS_OK);
        dmap_structure_add (abro, DMAP_CC_MUTY, 0);
 
        num_genre = g_hash_table_size (category_items);
@@ -957,7 +957,7 @@ _databases_items_xxx (DmapShare * share,
        if (NULL == record) {
                g_signal_emit_by_name(share, "error",
                        g_error_new(DMAP_ERROR,
-                                   DMAP_ERROR_FAILED,
+                                   DMAP_STATUS_DB_BAD_ID,
                                   "Bad record identifier requested"));
                soup_message_set_status (msg, SOUP_STATUS_NOT_FOUND);
                goto done;
@@ -1285,81 +1285,81 @@ START_TEST(_album_tabulator_test)
 }
 END_TEST
 
-static gboolean _error_triggered = FALSE;
+static int _status = DMAP_STATUS_OK;
 
 static void
 _error_cb(DmapShare *share, GError *error, gpointer user_data)
 {
-       _error_triggered = TRUE;
+       _status = error->code;
 }
 
 START_TEST(_should_transcode_test_no)
 {
-       _error_triggered = FALSE;
+       _status = DMAP_STATUS_OK;
        DmapAvShare *share = dmap_av_share_new("test", NULL, NULL, NULL, NULL);
        g_signal_connect(share, "error", G_CALLBACK(_error_cb), NULL);
        ck_assert_int_eq(FALSE, _should_transcode(share, "mp3", TRUE, "audio/wav"));
-       ck_assert(!_error_triggered);
+       ck_assert_int_eq(DMAP_STATUS_OK, _status);
 }
 END_TEST
 
 START_TEST(_should_transcode_test_no_trancode_mimetype)
 {
-       _error_triggered = FALSE;
+       _status = DMAP_STATUS_OK;
        DmapAvShare *share = dmap_av_share_new("test", NULL, NULL, NULL, NULL);
        g_signal_connect(share, "error", G_CALLBACK(_error_cb), NULL);
        ck_assert_int_eq(FALSE, _should_transcode(share, "foo", FALSE, NULL));
-       ck_assert(!_error_triggered);
+       ck_assert_int_eq(DMAP_STATUS_OK, _status);
 }
 END_TEST
 
 START_TEST(_should_transcode_test_no_trancode_mimetype_unknown_mimetype)
 {
-       _error_triggered = FALSE;
+       _status = DMAP_STATUS_OK;
        DmapAvShare *share = dmap_av_share_new("test", NULL, NULL, NULL, NULL);
        g_signal_connect(share, "error", G_CALLBACK(_error_cb), NULL);
        ck_assert_int_eq(FALSE, _should_transcode(share, "mp3", FALSE, "foo"));
-       ck_assert(_error_triggered);
+       ck_assert_int_eq(DMAP_STATUS_BAD_FORMAT, _status);
 }
 END_TEST
 
 START_TEST(_should_transcode_test_no_trancode_mimetype_already_good)
 {
-       _error_triggered = FALSE;
+       _status = DMAP_STATUS_OK;
        DmapAvShare *share = dmap_av_share_new("test", NULL, NULL, NULL, NULL);
        g_signal_connect(share, "error", G_CALLBACK(_error_cb), NULL);
        ck_assert_int_eq(FALSE, _should_transcode(share, "mp3", FALSE, "audio/mp3"));
-       ck_assert(!_error_triggered);
+       ck_assert_int_eq(DMAP_STATUS_OK, _status);
 }
 END_TEST
 
 START_TEST(_should_transcode_test_yes_trancode_mimetype_to_wav)
 {
-       _error_triggered = FALSE;
+       _status = DMAP_STATUS_OK;
        DmapAvShare *share = dmap_av_share_new("test", NULL, NULL, NULL, NULL);
        g_signal_connect(share, "error", G_CALLBACK(_error_cb), NULL);
        ck_assert_int_eq(TRUE, _should_transcode(share, "mp3", FALSE, "audio/wav"));
-       ck_assert(!_error_triggered);
+       ck_assert_int_eq(DMAP_STATUS_OK, _status);
 }
 END_TEST
 
 START_TEST(_should_transcode_test_yes_trancode_mimetype_to_mp3)
 {
-       _error_triggered = FALSE;
+       _status = DMAP_STATUS_OK;
        DmapAvShare *share = dmap_av_share_new("test", NULL, NULL, NULL, NULL);
        g_signal_connect(share, "error", G_CALLBACK(_error_cb), NULL);
        ck_assert_int_eq(TRUE, _should_transcode(share, "wav", FALSE, "audio/mp3"));
-       ck_assert(!_error_triggered);
+       ck_assert_int_eq(DMAP_STATUS_OK, _status);
 }
 END_TEST
 
 START_TEST(_should_transcode_test_yes_trancode_mimetype_to_mp4)
 {
-       _error_triggered = FALSE;
+       _status = DMAP_STATUS_OK;
        DmapAvShare *share = dmap_av_share_new("test", NULL, NULL, NULL, NULL);
        g_signal_connect(share, "error", G_CALLBACK(_error_cb), NULL);
        ck_assert_int_eq(TRUE, _should_transcode(share, "wav", FALSE, "video/quicktime"));
-       ck_assert(!_error_triggered);
+       ck_assert_int_eq(DMAP_STATUS_OK, _status);
 }
 END_TEST
 
@@ -1408,7 +1408,7 @@ START_TEST(dmap_av_share_server_info_test)
        root = dmap_structure_parse(data, length, NULL);
 
        item = dmap_structure_find_item(root, DMAP_CC_MSTT);
-       ck_assert_int_eq(DMAP_STATUS_OK, item->content.data->v_int);
+       ck_assert_int_eq(SOUP_STATUS_OK, item->content.data->v_int);
 
        item = dmap_structure_find_item(root, DMAP_CC_MPRO);
        ck_assert_int_eq(DAAP_VERSION, item->content.data->v_double);
@@ -1513,7 +1513,7 @@ START_TEST(_databases_browse_xxx_test)
        root = dmap_structure_parse(data, length, NULL);
 
        item = dmap_structure_find_item(root, DMAP_CC_MSTT);
-       ck_assert_int_eq(DMAP_STATUS_OK, item->content.data->v_int);
+       ck_assert_int_eq(SOUP_STATUS_OK, item->content.data->v_int);
 
        item = dmap_structure_find_item(root, DMAP_CC_MUTY);
        ck_assert_int_eq(0, item->content.data->v_int);
@@ -1737,10 +1737,10 @@ START_TEST(_databases_items_xxx_test_bad_id)
        /* IDs go from G_MAXINT down, so 0 does not exist. */
        g_snprintf(path, sizeof path, "/db/1/items/%d", 0);
 
-       _error_triggered = FALSE;
+       _status = DMAP_STATUS_OK;
        g_signal_connect(share, "error", G_CALLBACK(_error_cb), NULL);
        _databases_items_xxx(share, server, message, path, NULL, NULL);
-       ck_assert(_error_triggered);
+       ck_assert_int_eq(DMAP_STATUS_DB_BAD_ID, _status);
 
        g_object_unref(share);
 }
diff --git a/libdmapsharing/dmap-connection.c b/libdmapsharing/dmap-connection.c
index ad7a6bf..c3c767a 100644
--- a/libdmapsharing/dmap-connection.c
+++ b/libdmapsharing/dmap-connection.c
@@ -764,7 +764,7 @@ _actual_http_response_handler (DmapResponseData * data)
                }
                structure = dmap_structure_parse (response, response_length, &error);
                if (structure == NULL) {
-                       dmap_connection_emit_error(data->connection, DMAP_ERROR_FAILED,
+                       dmap_connection_emit_error(data->connection, error->code,
                                                  "Error parsing %s response: %s\n", message_path,
                                                   error->message);
                        data->status = SOUP_STATUS_MALFORMED;
@@ -1851,22 +1851,22 @@ dmap_connection_emit_error(DmapConnection *connection, gint code,
 #include <check.h>
 #include <libdmapsharing/dmap-av-connection.h>
 
-static gboolean _error_triggered = FALSE;
+static int _status = DMAP_STATUS_OK;
 
 static void
 _error_cb(DmapConnection *share, GError *error, gpointer user_data)
 {
-       _error_triggered = TRUE;
+       _status = error->code;
 }
 
-#define _ACTUAL_HTTP_RESPONSE_HANDLER_TEST(bytes, size, ok) \
+#define _ACTUAL_HTTP_RESPONSE_HANDLER_TEST(bytes, size, __status) \
 { \
        SoupMessage      *message; \
        DmapConnection   *connection; \
        char              body[] = bytes; \
        DmapResponseData *data; \
        \
-       _error_triggered = FALSE; \
+       _status = DMAP_STATUS_OK; \
        \
        message = soup_message_new(SOUP_METHOD_GET, "http://test/";); \
        soup_message_set_response(message, \
@@ -1886,20 +1886,30 @@ _error_cb(DmapConnection *share, GError *error, gpointer user_data)
        \
        _actual_http_response_handler(data); \
        \
-       ck_assert(_error_triggered != ok); \
+       ck_assert(_status == __status); \
 } \
 
 START_TEST(_actual_http_response_handler_test) \
-_ACTUAL_HTTP_RESPONSE_HANDLER_TEST("minm\x00\x00\x00\x0dHello, world!", sizeof bytes, TRUE);
+_ACTUAL_HTTP_RESPONSE_HANDLER_TEST("minm\x00\x00\x00\x0dHello, world!",
+                                    sizeof bytes, DMAP_STATUS_OK);
+END_TEST
+
+/* Length < 8 only allowed for DMAP_RAW. */
+START_TEST(_actual_http_response_handler_too_short_test) \
+_ACTUAL_HTTP_RESPONSE_HANDLER_TEST("xxxx", sizeof bytes,
+                                    DMAP_STATUS_RESPONSE_TOO_SHORT);
 END_TEST
 
 START_TEST(_actual_http_response_handler_bad_cc_test) \
-_ACTUAL_HTTP_RESPONSE_HANDLER_TEST("xxxx", sizeof bytes, FALSE);
+_ACTUAL_HTTP_RESPONSE_HANDLER_TEST("xxxx\x00\x00\x00\x00", sizeof bytes,
+                                    DMAP_STATUS_INVALID_CONTENT_CODE);
 END_TEST
 
 /* Length of 99 is larger than sizeof containing array. */
 START_TEST(_actual_http_response_handler_bad_len_test) \
-_ACTUAL_HTTP_RESPONSE_HANDLER_TEST("minm\x00\x00\x00\x99Hello, world!", sizeof bytes, FALSE);
+_ACTUAL_HTTP_RESPONSE_HANDLER_TEST("minm\x00\x00\x00\x99Hello, world!",
+                                    sizeof bytes,
+                                    DMAP_STATUS_INVALID_CONTENT_CODE_SIZE);
 END_TEST
 
 #include "dmap-connection-suite.c"
diff --git a/libdmapsharing/dmap-control-share.c b/libdmapsharing/dmap-control-share.c
index c4bc238..950c942 100644
--- a/libdmapsharing/dmap-control-share.c
+++ b/libdmapsharing/dmap-control-share.c
@@ -521,7 +521,7 @@ _fill_playstatusupdate (DmapControlShare * share, SoupMessage * message)
        record = dmap_control_player_now_playing_record (share->priv->player);
 
        cmst = dmap_structure_add (NULL, DMAP_CC_CMST);
-       dmap_structure_add (cmst, DMAP_CC_MSTT, (gint32) DMAP_STATUS_OK);
+       dmap_structure_add (cmst, DMAP_CC_MSTT, (gint32) SOUP_STATUS_OK);
        dmap_structure_add (cmst, DMAP_CC_CMSR,
                            share->priv->current_revision);
        dmap_structure_add (cmst, DMAP_CC_CAVC, 1);
@@ -702,7 +702,7 @@ dmap_control_share_ctrl_int (DmapShare * share,
                caci = dmap_structure_add (NULL, DMAP_CC_CACI);
                // dmap.status
                dmap_structure_add (caci, DMAP_CC_MSTT,
-                                   (gint32) DMAP_STATUS_OK);
+                                   (gint32) SOUP_STATUS_OK);
                // dmap.updatetype
                dmap_structure_add (caci, DMAP_CC_MUTY, 0);
                // dmap.specifiedtotalcount
@@ -748,7 +748,7 @@ dmap_control_share_ctrl_int (DmapShare * share,
                }
 
                cmgt = dmap_structure_add (NULL, DMAP_CC_CMGT);
-               dmap_structure_add (cmgt, DMAP_CC_MSTT, DMAP_STATUS_OK);
+               dmap_structure_add (cmgt, DMAP_CC_MSTT, SOUP_STATUS_OK);
 
                properties = g_strsplit (properties_query, ",", -1);
                for (property = properties; *property; property++) {
@@ -786,7 +786,7 @@ dmap_control_share_ctrl_int (DmapShare * share,
 
                casp = dmap_structure_add (NULL, DMAP_CC_CASP);
                dmap_structure_add (casp, DMAP_CC_MSTT,
-                                   (gint32) DMAP_STATUS_OK);
+                                   (gint32) SOUP_STATUS_OK);
                dmap_structure_add (casp, DMAP_CC_MDCL);
 
                dmap_structure_add (casp, DMAP_CC_CAIA, TRUE);
@@ -945,7 +945,7 @@ dmap_control_share_ctrl_int (DmapShare * share,
 
                        cacr = dmap_structure_add (NULL, DMAP_CC_CACR);
                        dmap_structure_add (cacr, DMAP_CC_MSTT,
-                                           DMAP_STATUS_OK);
+                                           SOUP_STATUS_OK);
                        dmap_structure_add (cacr, DMAP_CC_MIID, index);
 
                        dmap_share_message_set_from_dmap_structure (share,
diff --git a/libdmapsharing/dmap-error.h b/libdmapsharing/dmap-error.h
index 48af4e6..b083928 100644
--- a/libdmapsharing/dmap-error.h
+++ b/libdmapsharing/dmap-error.h
@@ -46,8 +46,25 @@ GQuark dmap_error_quark ();
  */
 typedef enum
 {
-       DMAP_ERROR_FAILED = 1,
-       DMAP_ERROR_NUM_ERRORS,
+       DMAP_STATUS_OK = 0,
+       DMAP_STATUS_FAILED,
+
+       DMAP_STATUS_INVALID_CONTENT_CODE,
+       DMAP_STATUS_INVALID_CONTENT_CODE_SIZE,
+       DMAP_STATUS_RESPONSE_TOO_SHORT,
+
+       DMAP_STATUS_BAD_FORMAT,
+       DMAP_STATUS_BAD_BROWSE_CATEGORY,
+
+       DMAP_STATUS_RECORD_MISSING_FIELD,
+
+       DMAP_STATUS_DB_BAD_ID,
+
+       DMAP_STATUS_OPEN_FAILED,
+       DMAP_STATUS_CLOSE_FAILED,
+       DMAP_STATUS_SEEK_FAILED,
+
+       DMAP_STATUS_NUM_ERRORS,
 } DmapError;
 
 G_END_DECLS
diff --git a/libdmapsharing/dmap-image-share.c b/libdmapsharing/dmap-image-share.c
index b188e70..00be757 100644
--- a/libdmapsharing/dmap-image-share.c
+++ b/libdmapsharing/dmap-image-share.c
@@ -566,7 +566,7 @@ dmap_image_share_server_info (DmapShare * share,
        g_object_get ((gpointer) share, "name", &nameprop, NULL);
 
        msrv = dmap_structure_add (NULL, DMAP_CC_MSRV);
-       dmap_structure_add (msrv, DMAP_CC_MSTT, (gint32) DMAP_STATUS_OK);
+       dmap_structure_add (msrv, DMAP_CC_MSTT, (gint32) SOUP_STATUS_OK);
        dmap_structure_add (msrv, DMAP_CC_MPRO, (gdouble) DMAP_VERSION);
        dmap_structure_add (msrv, DMAP_CC_PPRO, (gdouble) DPAP_VERSION);
        dmap_structure_add (msrv, DMAP_CC_MINM, nameprop);
diff --git a/libdmapsharing/dmap-share.c b/libdmapsharing/dmap-share.c
index c3c7eb0..39acc9e 100644
--- a/libdmapsharing/dmap-share.c
+++ b/libdmapsharing/dmap-share.c
@@ -39,7 +39,6 @@
 #define DMAP_VERSION 2.0
 #define DAAP_VERSION 3.0
 #define DMAP_TIMEOUT 1800
-#define DMAP_STATUS_OK 200
 
 enum
 {
@@ -1021,7 +1020,7 @@ dmap_share_content_codes (DmapShare * share,
        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);
+       dmap_structure_add (mccr, DMAP_CC_MSTT, (gint32) SOUP_STATUS_OK);
 
        for (i = 0; i < num_defs; i++) {
                GNode *mdcl;
@@ -1057,7 +1056,7 @@ dmap_share_login (DmapShare * share,
        session_id = dmap_share_session_id_create (share, context);
 
        mlog = dmap_structure_add (NULL, DMAP_CC_MLOG);
-       dmap_structure_add (mlog, DMAP_CC_MSTT, (gint32) DMAP_STATUS_OK);
+       dmap_structure_add (mlog, DMAP_CC_MSTT, (gint32) SOUP_STATUS_OK);
        dmap_structure_add (mlog, DMAP_CC_MLID, session_id);
 
        dmap_share_message_set_from_dmap_structure (share, message, mlog);
@@ -1112,7 +1111,7 @@ dmap_share_update (DmapShare * share,
 
                mupd = dmap_structure_add (NULL, DMAP_CC_MUPD);
                dmap_structure_add (mupd, DMAP_CC_MSTT,
-                                   (gint32) DMAP_STATUS_OK);
+                                   (gint32) SOUP_STATUS_OK);
                dmap_structure_add (mupd, DMAP_CC_MUSR,
                                    (gint32)
                                    dmap_share_get_revision_number (share));
@@ -1674,7 +1673,7 @@ dmap_share_databases (DmapShare * share,
 
                avdb = dmap_structure_add (NULL, DMAP_CC_AVDB);
                dmap_structure_add (avdb, DMAP_CC_MSTT,
-                                   (gint32) DMAP_STATUS_OK);
+                                   (gint32) SOUP_STATUS_OK);
                dmap_structure_add (avdb, DMAP_CC_MUTY, 0);
                dmap_structure_add (avdb, DMAP_CC_MTCO, (gint32) 1);
                dmap_structure_add (avdb, DMAP_CC_MRCO, (gint32) 1);
@@ -1737,7 +1736,7 @@ dmap_share_databases (DmapShare * share,
 
                agal = dmap_structure_add (NULL, DMAP_CC_AGAL);
                dmap_structure_add (agal, DMAP_CC_MSTT,
-                                   (gint32) DMAP_STATUS_OK);
+                                   (gint32) SOUP_STATUS_OK);
                dmap_structure_add (agal, DMAP_CC_MUTY, 0);
 
                num = g_hash_table_size (groups);
@@ -1866,7 +1865,7 @@ dmap_share_databases (DmapShare * share,
                /* 2: */
                adbs = dmap_structure_add (NULL, DMAP_CC_ADBS);
                dmap_structure_add (adbs, DMAP_CC_MSTT,
-                                   (gint32) DMAP_STATUS_OK);
+                                   (gint32) SOUP_STATUS_OK);
                dmap_structure_add (adbs, DMAP_CC_MUTY, 0);
                dmap_structure_add (adbs, DMAP_CC_MTCO, (gint32) num_songs);
                dmap_structure_add (adbs, DMAP_CC_MRCO, (gint32) num_songs);
@@ -1932,7 +1931,7 @@ dmap_share_databases (DmapShare * share,
 
                aply = dmap_structure_add (NULL, DMAP_CC_APLY);
                dmap_structure_add (aply, DMAP_CC_MSTT,
-                                   (gint32) DMAP_STATUS_OK);
+                                   (gint32) SOUP_STATUS_OK);
                dmap_structure_add (aply, DMAP_CC_MUTY, 0);
                dmap_structure_add (aply, DMAP_CC_MTCO,
                                    (gint32) dmap_container_db_count (share->
@@ -1999,7 +1998,7 @@ dmap_share_databases (DmapShare * share,
 
                apso = dmap_structure_add (NULL, DMAP_CC_APSO);
                dmap_structure_add (apso, DMAP_CC_MSTT,
-                                   (gint32) DMAP_STATUS_OK);
+                                   (gint32) SOUP_STATUS_OK);
                dmap_structure_add (apso, DMAP_CC_MUTY, 0);
 
                if (g_ascii_strcasecmp ("/1/items", rest_of_path + 13) == 0) {
diff --git a/libdmapsharing/dmap-share.h b/libdmapsharing/dmap-share.h
index f108279..33b65c4 100644
--- a/libdmapsharing/dmap-share.h
+++ b/libdmapsharing/dmap-share.h
@@ -87,7 +87,6 @@ G_BEGIN_DECLS
  */
 #define DMAP_SHARE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), \
                                 DMAP_TYPE_SHARE, DmapShareClass))
-#define DMAP_STATUS_OK 200
 typedef struct DmapSharePrivate DmapSharePrivate;
 
 typedef struct {
diff --git a/libdmapsharing/dmap-structure.c b/libdmapsharing/dmap-structure.c
index 3b64ecf..04cddd4 100644
--- a/libdmapsharing/dmap-structure.c
+++ b/libdmapsharing/dmap-structure.c
@@ -363,7 +363,7 @@ _cc_dmap_type (DmapContentCode code, GError **error)
        if (code < sizeof _cc_defs / sizeof(DmapContentCodeDefinition)) {
                type = _cc_defs[code - 1].type;
        } else {
-               g_set_error(error, DMAP_ERROR, DMAP_ERROR_FAILED,
+               g_set_error(error, DMAP_ERROR, DMAP_STATUS_INVALID_CONTENT_CODE,
                           "Invalid content code: %d", code);
        }
 
@@ -548,7 +548,7 @@ _cc_read_from_buffer (const gchar * buf, GError **error)
                }
        }
 
-       g_set_error(error, DMAP_ERROR, DMAP_ERROR_FAILED,
+       g_set_error(error, DMAP_ERROR, DMAP_STATUS_INVALID_CONTENT_CODE,
                   "Invalid content code: %4s", buf);
 
 done:
@@ -606,7 +606,7 @@ _parse_container_buffer (GNode * parent, const guint8 * buf,
                 * content_code and 4 of size) is odd.
                 */
                if (buf_length - l < 8) {
-                       g_set_error(error, DMAP_ERROR, DMAP_ERROR_FAILED,
+                       g_set_error(error, DMAP_ERROR, DMAP_STATUS_RESPONSE_TOO_SHORT,
                                   "Malformed response received");
                        goto done;
                }
@@ -625,7 +625,7 @@ _parse_container_buffer (GNode * parent, const guint8 * buf,
                 * then get out before we start processing it
                 */
                if (codesize > buf_length - l - 4 || codesize < 0) {
-                       g_set_error(error, DMAP_ERROR, DMAP_ERROR_FAILED,
+                       g_set_error(error, DMAP_ERROR, DMAP_STATUS_INVALID_CONTENT_CODE_SIZE,
                                   "Invalid codesize %d received in buffer of length %zd",
                                    codesize, buf_length);
                        goto done;
diff --git a/libdmapsharing/generate-test-suites b/libdmapsharing/generate-test-suites
index 0c42f3d..465ff2a 100755
--- a/libdmapsharing/generate-test-suites
+++ b/libdmapsharing/generate-test-suites
@@ -2,7 +2,7 @@
 
 # Generate test suite for each source file containing "^START_TEST":
 for f in *.c; do
-       tests=$(grep ^START_TEST $f | cut -c 12- | sed 's/.$//')
+       tests=$(grep ^START_TEST $f | cut -c 12- | sed 's/).*//')
        suitefn=$(echo ${f%.*} | sed 's/-/_/g')
 
        # Continue if no tests.
@@ -47,7 +47,7 @@ EOF
 
 for f in *.c; do
         # Get list of tests in given source file.
-        tests=$(grep ^START_TEST $f | cut -c 12- | sed 's/.$//')
+        tests=$(grep ^START_TEST $f | cut -c 12- | sed 's/).*//')
        suitefn=$(echo ${f%.*} | sed 's/-/_/g')
 
         # Continue if no tests.
@@ -91,7 +91,7 @@ EOF
 
 for f in *.c; do
         # Get list of tests in given source file.
-        tests=$(grep ^START_TEST $f | cut -c 12- | sed 's/.$//')
+        tests=$(grep ^START_TEST $f | cut -c 12- | sed 's/).*//')
        suitefn=$(echo ${f%.*} | sed 's/-/_/g')
 
         # Continue if no tests.


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