Browse code

Merge d8bd9825fa401ad0a3489d246f29d05485b72831 into 658cb4965ba108079116eb60c350d39b18f7e912

Alex Hermann authored on 20/10/2020 08:17:37 • GitHub committed on 20/10/2020 08:17:37
Showing 4 changed files
... ...
@@ -300,6 +300,24 @@ xlog("L_INFO", "Size of queue is: $var(q_size)\n");
300 300
 ...
301 301
 &kamcmd; mqueue.fetch xyz
302 302
 ...
303
+</programlisting>
304
+	    </example>
305
+	</section>
306
+
307
+	<section id="mqueue.r.get_sizes">
308
+		<title>mqueue.get_sizes</title>
309
+		<para>
310
+			Get the size for all memory queues.
311
+		</para>
312
+		<para>
313
+			Parameters: none
314
+		</para>
315
+		<example>
316
+		<title><function>mqueue.get_sizes</function> usage</title>
317
+		<programlisting format="linespecific">
318
+...
319
+&kamcmd; mqueue.get_sizes
320
+...
303 321
 </programlisting>
304 322
 	    </example>
305 323
 	</section>
... ...
@@ -173,6 +173,9 @@ mq_head_t *mq_head_get(str *name)
173 173
 	mq_head_t *mh = NULL;
174 174
 
175 175
 	mh = _mq_head_list;
176
+	if (!name) {
177
+		return mh;
178
+	}
176 179
 	while(mh!=NULL)
177 180
 	{
178 181
 		if(name->len == mh->name.len
... ...
@@ -77,6 +77,7 @@ int mq_head_add(str *name, int msize);
77 77
 int mq_head_fetch(str *name);
78 78
 void mq_pv_free(str *name);
79 79
 int mq_item_add(str *qname, str *key, str *val);
80
+mq_head_t *mq_head_get(str *name);
80 81
 
81 82
 int _mq_get_csize(str *);
82 83
 int mq_set_dbmode(str *, int dbmode);
... ...
@@ -294,13 +294,13 @@ static void  mqueue_rpc_get_size(rpc_t* rpc, void* ctx)
294 294
 	int			mqueue_sz = 0;
295 295
 
296 296
 	if (rpc->scan(ctx, "S", &mqueue_name) < 1) {
297
-		rpc->fault(ctx, 500, "No queue name");
297
+		rpc->fault(ctx, 400, "No queue name");
298 298
 		return;
299 299
 	}
300 300
 
301 301
 	if(mqueue_name.len <= 0 || mqueue_name.s == NULL) {
302 302
 		LM_ERR("bad mqueue name\n");
303
-		rpc->fault(ctx, 500, "Invalid queue name");
303
+		rpc->fault(ctx, 400, "Invalid queue name");
304 304
 		return;
305 305
 	}
306 306
 
... ...
@@ -308,7 +308,7 @@ static void  mqueue_rpc_get_size(rpc_t* rpc, void* ctx)
308 308
 
309 309
 	if(mqueue_sz < 0) {
310 310
 		LM_ERR("no such mqueue\n");
311
-		rpc->fault(ctx, 500, "No such queue");
311
+		rpc->fault(ctx, 404, "No such queue");
312 312
 		return;
313 313
 	}
314 314
 
... ...
@@ -327,6 +327,34 @@ static const char* mqueue_rpc_get_size_doc[2] = {
327 327
 	0
328 328
 };
329 329
 
330
+static void mqueue_rpc_get_sizes(rpc_t* rpc, void* ctx)
331
+{
332
+	mq_head_t* mh = mq_head_get(NULL);
333
+	void* vh;
334
+	int size;
335
+
336
+	while(mh!=NULL)
337
+	{
338
+		if (rpc->add(ctx, "{", &vh) < 0) {
339
+			rpc->fault(ctx, 500, "Server error");
340
+			return;
341
+		}
342
+		lock_get(&mh->lock);
343
+		size = mh->csize;
344
+		lock_release(&mh->lock);
345
+		rpc->struct_add(vh, "Sd",
346
+				"name", &mh->name,
347
+				"size", size
348
+		);
349
+		mh = mh->next;
350
+	}
351
+}
352
+
353
+static const char* mqueue_rpc_get_sizes_doc[2] = {
354
+	"Get sizes of all mqueues.",
355
+	0
356
+};
357
+
330 358
 static void  mqueue_rpc_fetch(rpc_t* rpc, void* ctx)
331 359
 {
332 360
 	str mqueue_name;
... ...
@@ -392,6 +420,7 @@ static const char* mqueue_rpc_fetch_doc[2] = {
392 420
 
393 421
 rpc_export_t mqueue_rpc[] = {
394 422
 	{"mqueue.get_size", mqueue_rpc_get_size, mqueue_rpc_get_size_doc, 0},
423
+	{"mqueue.get_sizes", mqueue_rpc_get_sizes, mqueue_rpc_get_sizes_doc, RET_ARRAY},
395 424
 	{"mqueue.fetch", mqueue_rpc_fetch, mqueue_rpc_fetch_doc, 0},
396 425
 	{0, 0, 0, 0}
397 426
 };