]> code.delx.au - pulseaudio/blobdiff - src/pulse/ext-stream-restore.c
Remove pa_bool_t and replace it with bool.
[pulseaudio] / src / pulse / ext-stream-restore.c
index 703179c53f51656c50b75dd2bf1a2e39c13e8eb5..3362a5f515462c5139724a9e95278843c7a50487 100644 (file)
@@ -5,7 +5,7 @@
 
   PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published
-  by the Free Software Foundation; either version 2 of the License,
+  by the Free Software Foundation; either version 2.1 of the License,
   or (at your option) any later version.
 
   PulseAudio is distributed in the hope that it will be useful, but
 #endif
 
 #include <pulse/context.h>
-#include <pulse/gccmacro.h>
+#include <pulse/fork-detect.h>
+#include <pulse/operation.h>
 
 #include <pulsecore/macro.h>
 #include <pulsecore/pstream-util.h>
 
 #include "internal.h"
-
 #include "ext-stream-restore.h"
 
 enum {
@@ -54,7 +54,7 @@ static void ext_stream_restore_test_cb(pa_pdispatch *pd, uint32_t command, uint3
         goto finish;
 
     if (command != PA_COMMAND_REPLY) {
-        if (pa_context_handle_error(o->context, command, t, FALSE) < 0)
+        if (pa_context_handle_error(o->context, command, t, false) < 0)
             goto finish;
 
     } else if (pa_tagstruct_getu32(t, &version) < 0 ||
@@ -86,6 +86,7 @@ pa_operation *pa_ext_stream_restore_test(
     pa_assert(c);
     pa_assert(PA_REFCNT_VALUE(c) >= 1);
 
+    PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
     PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
     PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 14, PA_ERR_NOTSUPPORTED);
 
@@ -113,7 +114,7 @@ static void ext_stream_restore_read_cb(pa_pdispatch *pd, uint32_t command, uint3
         goto finish;
 
     if (command != PA_COMMAND_REPLY) {
-        if (pa_context_handle_error(o->context, command, t, FALSE) < 0)
+        if (pa_context_handle_error(o->context, command, t, false) < 0)
             goto finish;
 
         eol = -1;
@@ -121,7 +122,7 @@ static void ext_stream_restore_read_cb(pa_pdispatch *pd, uint32_t command, uint3
 
         while (!pa_tagstruct_eof(t)) {
             pa_ext_stream_restore_info i;
-            pa_bool_t mute = FALSE;
+            bool mute = false;
 
             memset(&i, 0, sizeof(i));
 
@@ -166,6 +167,7 @@ pa_operation *pa_ext_stream_restore_read(
     pa_assert(c);
     pa_assert(PA_REFCNT_VALUE(c) >= 1);
 
+    PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
     PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
     PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 14, PA_ERR_NOTSUPPORTED);
 
@@ -191,14 +193,15 @@ pa_operation *pa_ext_stream_restore_write(
         void *userdata) {
 
     uint32_t tag;
-    pa_operation *o;
-    pa_tagstruct *t;
+    pa_operation *o = NULL;
+    pa_tagstruct *t = NULL;
 
     pa_assert(c);
     pa_assert(PA_REFCNT_VALUE(c) >= 1);
     pa_assert(mode == PA_UPDATE_MERGE || mode == PA_UPDATE_REPLACE || mode == PA_UPDATE_SET);
     pa_assert(data);
 
+    PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
     PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
     PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 14, PA_ERR_NOTSUPPORTED);
 
@@ -213,7 +216,15 @@ pa_operation *pa_ext_stream_restore_write(
     pa_tagstruct_put_boolean(t, apply_immediately);
 
     for (; n > 0; n--, data++) {
+        if (!data->name || !*data->name)
+            goto fail;
+
         pa_tagstruct_puts(t, data->name);
+
+        if (data->volume.channels > 0 &&
+            !pa_cvolume_compatible_with_channel_map(&data->volume, &data->channel_map))
+            goto fail;
+
         pa_tagstruct_put_channel_map(t, &data->channel_map);
         pa_tagstruct_put_cvolume(t, &data->volume);
         pa_tagstruct_puts(t, data->device);
@@ -224,6 +235,15 @@ pa_operation *pa_ext_stream_restore_write(
     pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_context_simple_ack_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref);
 
     return o;
+
+fail:
+    pa_operation_cancel(o);
+    pa_operation_unref(o);
+
+    pa_tagstruct_free(t);
+
+    pa_context_set_error(c, PA_ERR_INVALID);
+    return NULL;
 }
 
 pa_operation *pa_ext_stream_restore_delete(
@@ -233,14 +253,15 @@ pa_operation *pa_ext_stream_restore_delete(
         void *userdata) {
 
     uint32_t tag;
-    pa_operation *o;
-    pa_tagstruct *t;
+    pa_operation *o = NULL;
+    pa_tagstruct *t = NULL;
     const char *const *k;
 
     pa_assert(c);
     pa_assert(PA_REFCNT_VALUE(c) >= 1);
     pa_assert(s);
 
+    PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
     PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
     PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 14, PA_ERR_NOTSUPPORTED);
 
@@ -251,13 +272,26 @@ pa_operation *pa_ext_stream_restore_delete(
     pa_tagstruct_puts(t, "module-stream-restore");
     pa_tagstruct_putu32(t, SUBCOMMAND_DELETE);
 
-    for (k = s; *k; k++)
+    for (k = s; *k; k++) {
+        if (!*k || !**k)
+            goto fail;
+
         pa_tagstruct_puts(t, *k);
+    }
 
     pa_pstream_send_tagstruct(c->pstream, t);
     pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_context_simple_ack_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref);
 
     return o;
+
+fail:
+    pa_operation_cancel(o);
+    pa_operation_unref(o);
+
+    pa_tagstruct_free(t);
+
+    pa_context_set_error(c, PA_ERR_INVALID);
+    return NULL;
 }
 
 pa_operation *pa_ext_stream_restore_subscribe(
@@ -273,6 +307,7 @@ pa_operation *pa_ext_stream_restore_subscribe(
     pa_assert(c);
     pa_assert(PA_REFCNT_VALUE(c) >= 1);
 
+    PA_CHECK_VALIDITY_RETURN_NULL(c, !pa_detect_fork(), PA_ERR_FORKED);
     PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
     PA_CHECK_VALIDITY_RETURN_NULL(c, c->version >= 14, PA_ERR_NOTSUPPORTED);
 
@@ -297,6 +332,9 @@ void pa_ext_stream_restore_set_subscribe_cb(
     pa_assert(c);
     pa_assert(PA_REFCNT_VALUE(c) >= 1);
 
+    if (pa_detect_fork())
+        return;
+
     c->ext_stream_restore.callback = cb;
     c->ext_stream_restore.userdata = userdata;
 }
@@ -322,5 +360,4 @@ void pa_ext_stream_restore_command(pa_context *c, uint32_t tag, pa_tagstruct *t)
 
     if (c->ext_stream_restore.callback)
         c->ext_stream_restore.callback(c, c->ext_stream_restore.userdata);
-
 }