Browse code

imc(k): return code classes per command

- for each imc command a range of negative numbers is reserved to signal
errors to config file
- example enhanced to replect the need of sending replies from config
file

Daniel-Constantin Mierla authored on 10/09/2009 12:51:08
Showing 3 changed files
... ...
@@ -234,21 +234,28 @@ modparam("imc", "extra_hdrs", "P-Flags: 3\r\n")
234 234
 
235 235
    4.1. imc_manager()
236 236
 
237
-4.1.  imc_manager()
237
+4.1. imc_manager()
238 238
 
239 239
    Handles Message method.It detects if the body of the message is a
240 240
    conference command.If so it executes it, otherwise it sends the message
241 241
    to all the members in the room.
242 242
 
243
-   This function can be used from REQUEST_ROUTE.
243
+   This function can be used from REQUEST_ROUTE. See command description
244
+   for error codes returned by this function.
244 245
 
245 246
    Example 1.8. Usage of imc_manager() function
246 247
 ...
247 248
 # the rooms will be named chat-xyz to avoid overlapping
248 249
 # with usernames
249 250
 if(is_method("MESSAGE)
250
-        && (uri=~ "sip:chat-[0-9]+@" || (uri=~ "sip:chat-manager@")
251
-    imc_manager();
251
+    && (uri=~ "sip:chat-[0-9]+@" || (uri=~ "sip:chat-manager@"))
252
+{
253
+    if(imc_manager())
254
+        sl_send_reply("200", "ok");
255
+    else
256
+        sl_send_reply("500", "command error");
257
+    exit;
258
+}
252 259
 ...
253 260
 
254 261
 5. Exported MI Functions
... ...
@@ -256,7 +263,7 @@ if(is_method("MESSAGE)
256 256
    5.1. imc_list_rooms
257 257
    5.2. imc_list_members
258 258
 
259
-5.1.  imc_list_rooms
259
+5.1. imc_list_rooms
260 260
 
261 261
    Lists of the IM Conferencing rooms.
262 262
 
... ...
@@ -268,7 +275,7 @@ if(is_method("MESSAGE)
268 268
                 :imc_list_rooms:_reply_fifo_file_
269 269
                 _empty_line_
270 270
 
271
-5.2.  imc_list_members
271
+5.2. imc_list_members
272 272
 
273 273
    Listing of the members in IM Conferencing rooms.
274 274
 
... ...
@@ -286,7 +293,7 @@ if(is_method("MESSAGE)
286 286
 
287 287
    6.1. active_rooms
288 288
 
289
-6.1.  active_rooms
289
+6.1. active_rooms
290 290
 
291 291
    Number of active IM Conferencing rooms.
292 292
 
... ...
@@ -309,6 +316,7 @@ if(is_method("MESSAGE)
309 309
            and new members can be added only though invitations
310 310
   -the user is added as the first member and owner of the room
311 311
   -eg:  #create chat-000 private
312
+  -error case: return codes: -30 -- -39
312 313
 
313 314
 2.join
314 315
   -makes the user member of a room
... ...
@@ -318,6 +326,7 @@ if(is_method("MESSAGE)
318 318
   -if the room does not exist the command is treated as create
319 319
   -eg:join sip:chat-000@kamailio.org,
320 320
       or just, #join, sent to sip:chat-000@kamailio.org
321
+  -error case: return codes: -40 -- -49
321 322
 
322 323
 3.invite
323 324
   -invites a user to become a member of a room
... ...
@@ -329,6 +338,7 @@ if(is_method("MESSAGE)
329 329
     and the administrators
330 330
   -eg: #invite sip:john@kamailio.org sip:chat-000@kamailio.org
331 331
     or  #invite john@kamailio.org sent to sip:chat-000@kamailio.org
332
+  -error case: return codes: -50 -- -59
332 333
 
333 334
 4.accept
334 335
   -accepting an invitation
... ...
@@ -336,10 +346,12 @@ if(is_method("MESSAGE)
336 336
     present it will be considered to be the address in the To header
337 337
     of the message
338 338
   -eg: #accept sip:john@kamailio.org
339
+  -error case: return codes: -60 -- -69
339 340
 
340 341
 5.deny
341 342
   -rejects an invitation
342 343
   -the parameter is the same as for accept
344
+  -error case: return codes: -70 -- -79
343 345
 
344 346
 6.remove
345 347
   -deletes a member from a room
... ...
@@ -349,6 +361,7 @@ if(is_method("MESSAGE)
349 349
           to be the address in the To header of the message
350 350
   -only certain members have the right to remove other members
351 351
   -eg: #remove sip:john@kamailio.org, sent to sip:chat-000@kamailio.org
352
+  -error case: return codes: -80 -- -89
352 353
 
353 354
 7.exit
354 355
   -leaving a room
... ...
@@ -356,14 +369,17 @@ if(is_method("MESSAGE)
356 356
     present it will be considered to be the address in the To header
357 357
     of the message
358 358
   -if the user is the owner of the room, the room will be destroyed
359
+  -error case: return codes: -90 -- -99
359 360
 
360 361
 8.destroy
361 362
   -removing a room
362 363
   -the parameter is the same as for exit
363 364
   -only the owner of a room has the right to destroy it
365
+  -error case: return codes: -110 -- -119
364 366
 
365 367
 9.list
366 368
   -list members in a room
369
+  -error case: return codes: -100 -- -109
367 370
 
368 371
 ...
369 372
 
... ...
@@ -225,7 +225,8 @@ modparam("imc", "extra_hdrs", "P-Flags: 3\r\n")
225 225
 		message to all the members in the room. 
226 226
 		</para>
227 227
 		<para>
228
-		This function can be used from REQUEST_ROUTE.
228
+		This function can be used from REQUEST_ROUTE. See command description
229
+		for error codes returned by this function.
229 230
 		</para>
230 231
 		<example>
231 232
 		<title>Usage of <varname>imc_manager()</varname> function</title>
... ...
@@ -234,8 +235,14 @@ modparam("imc", "extra_hdrs", "P-Flags: 3\r\n")
234 234
 # the rooms will be named chat-xyz to avoid overlapping
235 235
 # with usernames
236 236
 if(is_method("MESSAGE)
237
-        &amp;&amp; (uri=~ "sip:chat-[0-9]+@" || (uri=~ "sip:chat-manager@")
238
-    imc_manager();
237
+    &amp;&amp; (uri=~ "sip:chat-[0-9]+@" || (uri=~ "sip:chat-manager@"))
238
+{
239
+    if(imc_manager())
240
+        sl_send_reply("200", "ok");
241
+    else
242
+        sl_send_reply("500", "command error");
243
+    exit;
244
+}
239 245
 ...
240 246
 </programlisting>
241 247
 		</example>
... ...
@@ -330,6 +337,7 @@ if(is_method("MESSAGE)
330 330
 	   and new members can be added only though invitations
331 331
   -the user is added as the first member and owner of the room
332 332
   -eg:  #create chat-000 private
333
+  -error case: return codes: -30 -- -39
333 334
 
334 335
 2.join
335 336
   -makes the user member of a room
... ...
@@ -339,6 +347,7 @@ if(is_method("MESSAGE)
339 339
   -if the room does not exist the command is treated as create
340 340
   -eg:join sip:chat-000@kamailio.org,
341 341
       or just, #join, sent to sip:chat-000@kamailio.org
342
+  -error case: return codes: -40 -- -49
342 343
 
343 344
 3.invite
344 345
   -invites a user to become a member of a room
... ...
@@ -350,6 +359,7 @@ if(is_method("MESSAGE)
350 350
     and the administrators
351 351
   -eg: #invite sip:john@kamailio.org sip:chat-000@kamailio.org
352 352
     or  #invite john@kamailio.org sent to sip:chat-000@kamailio.org
353
+  -error case: return codes: -50 -- -59
353 354
 
354 355
 4.accept
355 356
   -accepting an invitation
... ...
@@ -357,10 +367,12 @@ if(is_method("MESSAGE)
357 357
     present it will be considered to be the address in the To header
358 358
     of the message
359 359
   -eg: #accept sip:john@kamailio.org
360
+  -error case: return codes: -60 -- -69
360 361
 
361 362
 5.deny
362 363
   -rejects an invitation
363 364
   -the parameter is the same as for accept
365
+  -error case: return codes: -70 -- -79
364 366
 
365 367
 6.remove
366 368
   -deletes a member from a room
... ...
@@ -370,6 +382,7 @@ if(is_method("MESSAGE)
370 370
 	  to be the address in the To header of the message
371 371
   -only certain members have the right to remove other members
372 372
   -eg: #remove sip:john@kamailio.org, sent to sip:chat-000@kamailio.org
373
+  -error case: return codes: -80 -- -89
373 374
 
374 375
 7.exit
375 376
   -leaving a room
... ...
@@ -377,14 +390,17 @@ if(is_method("MESSAGE)
377 377
     present it will be considered to be the address in the To header
378 378
     of the message
379 379
   -if the user is the owner of the room, the room will be destroyed
380
+  -error case: return codes: -90 -- -99
380 381
 
381 382
 8.destroy
382 383
   -removing a room
383 384
   -the parameter is the same as for exit
384 385
   -only the owner of a room has the right to destroy it
386
+  -error case: return codes: -110 -- -119
385 387
 
386 388
 9.list
387 389
   -list members in a room
390
+  -error case: return codes: -100 -- -109
388 391
 
389 392
 ...
390 393
 </programlisting>
... ...
@@ -477,6 +477,7 @@ static int imc_manager(struct sip_msg* msg, char *str1, char *str2)
477 477
 	str body;
478 478
 	struct sip_uri from_uri, *pto_uri=NULL, *pfrom_uri=NULL;
479 479
 	struct to_body *pfrom;
480
+	int ret = -1;
480 481
 
481 482
 	body.s = get_body( msg );
482 483
 	if (body.s==0) 
... ...
@@ -525,6 +526,7 @@ static int imc_manager(struct sip_msg* msg, char *str1, char *str2)
525 525
 		if(imc_parse_cmd(body.s, body.len, &cmd)<0)
526 526
 		{
527 527
 			LM_ERR("failed to parse imc cmd!\n");
528
+			ret = -20;
528 529
 			goto error;
529 530
 		}
530 531
 
... ...
@@ -534,6 +536,7 @@ static int imc_manager(struct sip_msg* msg, char *str1, char *str2)
534 534
 			if(imc_handle_create(msg, &cmd, pfrom_uri, pto_uri)<0)
535 535
 			{
536 536
 				LM_ERR("failed to handle 'create'\n");
537
+				ret = -30;
537 538
 				goto error;
538 539
 			}
539 540
 		break;
... ...
@@ -541,6 +544,7 @@ static int imc_manager(struct sip_msg* msg, char *str1, char *str2)
541 541
 			if(imc_handle_join(msg, &cmd, pfrom_uri, pto_uri)<0)
542 542
 			{
543 543
 				LM_ERR("failed to handle 'join'\n");
544
+				ret = -40;
544 545
 				goto error;
545 546
 			}
546 547
 		break;
... ...
@@ -548,6 +552,7 @@ static int imc_manager(struct sip_msg* msg, char *str1, char *str2)
548 548
 			if(imc_handle_invite(msg, &cmd, pfrom_uri, pto_uri)<0)
549 549
 			{
550 550
 				LM_ERR("failed to handle 'invite'\n");
551
+				ret = -50;
551 552
 				goto error;
552 553
 			}
553 554
 		break;
... ...
@@ -555,6 +560,7 @@ static int imc_manager(struct sip_msg* msg, char *str1, char *str2)
555 555
 			if(imc_handle_accept(msg, &cmd, pfrom_uri, pto_uri)<0)
556 556
 			{
557 557
 				LM_ERR("failed to handle 'accept'\n");
558
+				ret = -60;
558 559
 				goto error;
559 560
 			}
560 561
 		break;
... ...
@@ -562,6 +568,7 @@ static int imc_manager(struct sip_msg* msg, char *str1, char *str2)
562 562
 			if(imc_handle_deny(msg, &cmd, pfrom_uri, pto_uri)<0)
563 563
 			{
564 564
 				LM_ERR("failed to handle 'deny'\n");
565
+				ret = -70;
565 566
 				goto error;
566 567
 			}
567 568
 		break;
... ...
@@ -569,6 +576,7 @@ static int imc_manager(struct sip_msg* msg, char *str1, char *str2)
569 569
 			if(imc_handle_remove(msg, &cmd, pfrom_uri, pto_uri)<0)
570 570
 			{
571 571
 				LM_ERR("failed to handle 'remove'\n");
572
+				ret = -80;
572 573
 				goto error;
573 574
 			}
574 575
 		break;
... ...
@@ -576,6 +584,7 @@ static int imc_manager(struct sip_msg* msg, char *str1, char *str2)
576 576
 			if(imc_handle_exit(msg, &cmd, pfrom_uri, pto_uri)<0)
577 577
 			{
578 578
 				LM_ERR("failed to handle 'exit'\n");
579
+				ret = -90;
579 580
 				goto error;
580 581
 			}
581 582
 		break;
... ...
@@ -583,6 +592,7 @@ static int imc_manager(struct sip_msg* msg, char *str1, char *str2)
583 583
 			if(imc_handle_list(msg, &cmd, pfrom_uri, pto_uri)<0)
584 584
 			{
585 585
 				LM_ERR("failed to handle 'list'\n");
586
+				ret = -100;
586 587
 				goto error;
587 588
 			}
588 589
 		break;
... ...
@@ -590,6 +600,7 @@ static int imc_manager(struct sip_msg* msg, char *str1, char *str2)
590 590
 			if(imc_handle_destroy(msg, &cmd, pfrom_uri, pto_uri)<0)
591 591
 			{
592 592
 				LM_ERR("failed to handle 'destroy'\n");
593
+				ret = -110;
593 594
 				goto error;
594 595
 			}
595 596
 		break;
... ...
@@ -598,6 +609,7 @@ static int imc_manager(struct sip_msg* msg, char *str1, char *str2)
598 598
 			(msg->new_uri.s)?&msg->new_uri:&msg->first_line.u.request.uri)<0)
599 599
 			{
600 600
 				LM_ERR("failed to handle 'help'\n");
601
+				ret = -120;
601 602
 				goto error;
602 603
 			}
603 604
 		break;
... ...
@@ -606,6 +618,7 @@ static int imc_manager(struct sip_msg* msg, char *str1, char *str2)
606 606
 			(msg->new_uri.s)?&msg->new_uri:&msg->first_line.u.request.uri)<0)
607 607
 			{
608 608
 				LM_ERR("failed to handle 'unknown'\n");
609
+				ret = -130;
609 610
 				goto error;
610 611
 			}
611 612
 		}
... ...
@@ -616,6 +629,7 @@ static int imc_manager(struct sip_msg* msg, char *str1, char *str2)
616 616
 	if(imc_handle_message(msg, &body, pfrom_uri, pto_uri)<0)
617 617
 	{
618 618
 		LM_ERR("failed to handle 'message'\n");
619
+		ret = -200;
619 620
 		goto error;
620 621
 	}
621 622
 
... ...
@@ -623,8 +637,7 @@ done:
623 623
 	return 1;
624 624
 
625 625
 error:
626
-
627
-	return -1;	
626
+	return ret;
628 627
 }
629 628
 
630 629
 /**