flags.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /**
  2. * $Id$
  3. *
  4. * Copyright (C) 2009
  5. *
  6. * This file is part of SIP-Router.org, a free SIP server.
  7. *
  8. * SIP-Router is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version
  12. *
  13. * Kamailio is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include <stdlib.h>
  25. #include "../../dprint.h"
  26. #include "../../flags.h"
  27. #include "../../dset.h"
  28. #include "../../mod_fix.h"
  29. #include "flags.h"
  30. int w_issflagset(struct sip_msg *msg, char *flag, str *s2)
  31. {
  32. int fval=0;
  33. if(fixup_get_ivalue(msg, (gparam_p)flag, &fval)!=0)
  34. {
  35. LM_ERR("no flag value\n");
  36. return -1;
  37. }
  38. if(fval<0 || fval>31)
  39. return -1;
  40. return issflagset((flag_t)fval);
  41. }
  42. int w_resetsflag(struct sip_msg *msg, char *flag, str *s2)
  43. {
  44. int fval=0;
  45. if(fixup_get_ivalue(msg, (gparam_p)flag, &fval)!=0)
  46. {
  47. LM_ERR("no flag value\n");
  48. return -1;
  49. }
  50. if(fval<0 || fval>31)
  51. return -1;
  52. return resetsflag((flag_t)fval);
  53. }
  54. int w_setsflag(struct sip_msg *msg, char *flag, char *s2)
  55. {
  56. int fval=0;
  57. if(fixup_get_ivalue(msg, (gparam_p)flag, &fval)!=0)
  58. {
  59. LM_ERR("no flag value\n");
  60. return -1;
  61. }
  62. if(fval<0 || fval>31)
  63. return -1;
  64. return setsflag((flag_t)fval);
  65. }
  66. int w_isbflagset(struct sip_msg *msg, char *flag, str *idx)
  67. {
  68. int fval=0;
  69. int ival=0;
  70. if(fixup_get_ivalue(msg, (gparam_p)flag, &fval)!=0)
  71. {
  72. LM_ERR("no flag value\n");
  73. return -1;
  74. }
  75. if(fval<0 || fval>31)
  76. return -1;
  77. if(idx!=0)
  78. {
  79. if(fixup_get_ivalue(msg, (gparam_p)idx, &ival)!=0)
  80. {
  81. LM_ERR("no idx value\n");
  82. return -1;
  83. }
  84. if(ival<0)
  85. return -1;
  86. }
  87. return isbflagset(ival, (flag_t)fval);
  88. }
  89. int w_resetbflag(struct sip_msg *msg, char *flag, str *idx)
  90. {
  91. int fval=0;
  92. int ival=0;
  93. if(fixup_get_ivalue(msg, (gparam_p)flag, &fval)!=0)
  94. {
  95. LM_ERR("no flag value\n");
  96. return -1;
  97. }
  98. if(fval<0 || fval>31)
  99. return -1;
  100. if(idx!=0)
  101. {
  102. if(fixup_get_ivalue(msg, (gparam_p)idx, &ival)!=0)
  103. {
  104. LM_ERR("no idx value\n");
  105. return -1;
  106. }
  107. if(ival<0)
  108. return -1;
  109. }
  110. return resetbflag(ival, (flag_t)fval);
  111. }
  112. int w_setbflag(struct sip_msg *msg, char *flag, char *idx)
  113. {
  114. int fval=0;
  115. int ival=0;
  116. if(fixup_get_ivalue(msg, (gparam_p)flag, &fval)!=0)
  117. {
  118. LM_ERR("no flag value\n");
  119. return -1;
  120. }
  121. if(fval<0 || fval>31)
  122. return -1;
  123. if(idx!=0)
  124. {
  125. if(fixup_get_ivalue(msg, (gparam_p)idx, &ival)!=0)
  126. {
  127. LM_ERR("no idx value\n");
  128. return -1;
  129. }
  130. if(ival<0)
  131. return -1;
  132. }
  133. return setbflag(ival, (flag_t)fval);
  134. }