security_events: Fix error caused by DTD validation error
[asterisk/asterisk.git] / funcs / func_lock.c
index 060fcb8..2102d5c 100644 (file)
@@ -59,6 +59,11 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                        Returns <literal>1</literal> if the lock was obtained or <literal>0</literal> on error.</para>
                        <note><para>To avoid the possibility of a deadlock, LOCK will only attempt to
                        obtain the lock for 3 seconds if the channel already has another lock.</para></note>
+                       <note>
+                               <para>If <literal>live_dangerously</literal> in <literal>asterisk.conf</literal>
+                               is set to <literal>no</literal>, this function can only be executed from the
+                               dialplan, and not directly from external protocols.</para>
+                       </note>
                </description>
        </function>
        <function name="TRYLOCK" language="en_US">
@@ -72,6 +77,11 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                        <para>Attempts to grab a named lock exclusively, and prevents other channels
                        from obtaining the same lock.  Returns <literal>1</literal> if the lock was 
                        available or <literal>0</literal> otherwise.</para>
+                       <note>
+                               <para>If <literal>live_dangerously</literal> in <literal>asterisk.conf</literal>
+                               is set to <literal>no</literal>, this function can only be executed from the
+                               dialplan, and not directly from external protocols.</para>
+                       </note>
                </description>
        </function>
        <function name="UNLOCK" language="en_US">
@@ -86,6 +96,11 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                        had a lock or <literal>0</literal> otherwise.</para>
                        <note><para>It is generally unnecessary to unlock in a hangup routine, as any locks 
                        held are automatically freed when the channel is destroyed.</para></note>
+                       <note>
+                               <para>If <literal>live_dangerously</literal> in <literal>asterisk.conf</literal>
+                               is set to <literal>no</literal>, this function can only be executed from the
+                               dialplan, and not directly from external protocols.</para>
+                       </note>
                </description>
        </function>
  ***/
@@ -99,7 +114,7 @@ static void lock_fixup(void *data, struct ast_channel *oldchan, struct ast_chann
 static int unloading = 0;
 static pthread_t broker_tid = AST_PTHREADT_NULL;
 
-static struct ast_datastore_info lock_info = {
+static const struct ast_datastore_info lock_info = {
        .type = "MUTEX",
        .destroy = lock_free,
        .chan_fixup = lock_fixup,
@@ -373,10 +388,15 @@ static int get_lock(struct ast_channel *chan, char *lockname, int trylock)
 
 static int unlock_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 {
-       struct ast_datastore *lock_store = ast_channel_datastore_find(chan, &lock_info, NULL);
+       struct ast_datastore *lock_store;
        struct channel_lock_frame *clframe;
        AST_LIST_HEAD(, channel_lock_frame) *list;
 
+       if (!chan) {
+               return -1;
+       }
+
+       lock_store = ast_channel_datastore_find(chan, &lock_info, NULL);
        if (!lock_store) {
                ast_log(LOG_WARNING, "No datastore for dialplan locks.  Nothing was ever locked!\n");
                ast_copy_string(buf, "0", len);
@@ -417,26 +437,24 @@ static int unlock_read(struct ast_channel *chan, const char *cmd, char *data, ch
 
 static int lock_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 {
-       if (chan)
-               ast_autoservice_start(chan);
-
+       if (!chan) {
+               return -1;
+       }
+       ast_autoservice_start(chan);
        ast_copy_string(buf, get_lock(chan, data, 0) ? "0" : "1", len);
-
-       if (chan)
-               ast_autoservice_stop(chan);
+       ast_autoservice_stop(chan);
 
        return 0;
 }
 
 static int trylock_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 {
-       if (chan)
-               ast_autoservice_start(chan);
-
+       if (!chan) {
+               return -1;
+       }
+       ast_autoservice_start(chan);
        ast_copy_string(buf, get_lock(chan, data, 1) ? "0" : "1", len);
-
-       if (chan)
-               ast_autoservice_stop(chan);
+       ast_autoservice_stop(chan);
 
        return 0;
 }
@@ -499,9 +517,9 @@ static int unload_module(void)
 
 static int load_module(void)
 {
-       int res = ast_custom_function_register(&lock_function);
-       res |= ast_custom_function_register(&trylock_function);
-       res |= ast_custom_function_register(&unlock_function);
+       int res = ast_custom_function_register_escalating(&lock_function, AST_CFE_READ);
+       res |= ast_custom_function_register_escalating(&trylock_function, AST_CFE_READ);
+       res |= ast_custom_function_register_escalating(&unlock_function, AST_CFE_READ);
 
        if (ast_pthread_create_background(&broker_tid, NULL, lock_broker, NULL)) {
                ast_log(LOG_ERROR, "Failed to start lock broker thread. Unloading func_lock module.\n");