Module: sip-router
Branch: 3.1
Commit: 203e6d078015e47ecf25a160653ace1d3745807c
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=203e6d0…
Author: Elena-Ramona Modroiu <ramona(a)asipto.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Mon Oct 11 12:20:24 2010 +0200
mqueue: return false if queue is empty
- return code -2
- reported by Alex Balashov
(cherry picked from commit e6fa8ae004f5d487e1c64471bf282931e4b9e901)
---
modules/mqueue/README | 11 +++++++----
modules/mqueue/doc/mqueue_admin.xml | 8 ++++++--
modules/mqueue/mqueue_api.c | 22 +++++++++++++---------
modules/mqueue/mqueue_mod.c | 7 +++++--
4 files changed, 31 insertions(+), 17 deletions(-)
diff --git a/modules/mqueue/README b/modules/mqueue/README
index 4c439a4..f876b2a 100644
--- a/modules/mqueue/README
+++ b/modules/mqueue/README
@@ -10,7 +10,7 @@ Elena-Ramona Modroiu
<ramona(a)asipto.com>
- Copyright � 2010 Elena-Ramona Modroiu (
asipto.com)
+ Copyright © 2010 Elena-Ramona Modroiu (
asipto.com)
__________________________________________________________________
Table of Contents
@@ -94,7 +94,7 @@ Chapter 1. Admin Guide
Definition of memory queue
- Default value is "none".
+ Default value is “none”.
Value must be a list of parameters: attr=value;... The attribute 'name'
is mandatory, defining the name of the queue. Optional attribute 'size'
@@ -128,8 +128,11 @@ mq_add("myq", "$rU", "call from $fU");
4.2. mq_fetch(queue)
- Take oldest item from que and fill $mqk(queue) and $mqv(queue) pseudo
- variables. Return true on success.
+ Take oldest item from queue and fill $mqk(queue) and $mqv(queue) pseudo
+ variables.
+
+ Return: true on success (1); false on failure (-1) or no item fetched
+ (-2).
Example 1.3. mq_fetch usage
...
diff --git a/modules/mqueue/doc/mqueue_admin.xml b/modules/mqueue/doc/mqueue_admin.xml
index e02ca38..d1b924a 100644
--- a/modules/mqueue/doc/mqueue_admin.xml
+++ b/modules/mqueue/doc/mqueue_admin.xml
@@ -118,8 +118,12 @@ mq_add("myq", "$rU", "call from $fU");
<function moreinfo="none">mq_fetch(queue)</function>
</title>
<para>
- Take oldest item from que and fill $mqk(queue) and $mqv(queue) pseudo
- variables. Return true on success.
+ Take oldest item from queue and fill $mqk(queue) and
+ $mqv(queue) pseudo variables.
+ </para>
+ <para>
+ Return: true on success (1); false on failure (-1) or
+ no item fetched (-2).
</para>
<example>
<title><function>mq_fetch</function> usage</title>
diff --git a/modules/mqueue/mqueue_api.c b/modules/mqueue/mqueue_api.c
index f75f23a..6007ef0 100644
--- a/modules/mqueue/mqueue_api.c
+++ b/modules/mqueue/mqueue_api.c
@@ -254,17 +254,21 @@ int mq_head_fetch(str *name)
return -1;
lock_get(&mh->lock);
- if(mh->ifirst!=NULL)
+ if(mh->ifirst==NULL)
{
- mp->item = mh->ifirst;
- mh->ifirst = mh->ifirst->next;
- if(mh->ifirst==NULL) {
- mh->ilast = NULL;
- } else {
- mh->ifirst->prev = NULL;
- }
- mh->csize--;
+ /* empty queue */
+ lock_release(&mh->lock);
+ return -2;
+ }
+
+ mp->item = mh->ifirst;
+ mh->ifirst = mh->ifirst->next;
+ if(mh->ifirst==NULL) {
+ mh->ilast = NULL;
+ } else {
+ mh->ifirst->prev = NULL;
}
+ mh->csize--;
lock_release(&mh->lock);
return 0;
diff --git a/modules/mqueue/mqueue_mod.c b/modules/mqueue/mqueue_mod.c
index 922f02e..5a74f58 100644
--- a/modules/mqueue/mqueue_mod.c
+++ b/modules/mqueue/mqueue_mod.c
@@ -109,8 +109,11 @@ static void mod_destroy(void)
static int w_mq_fetch(struct sip_msg* msg, char* mq, char* str2)
{
- if(mq_head_fetch((str*)mq)<0)
- return -1;
+ int ret;
+
+ ret = mq_head_fetch((str*)mq);
+ if(ret<0)
+ return ret;
return 1;
}