flags.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2001-2003 Fhg Fokus
  5. *
  6. * This file is part of ser, a free SIP server.
  7. *
  8. * ser 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. * For a license to use the ser software under conditions
  14. * other than those described here, or to purchase support for this
  15. * software, please contact iptel.org by e-mail at the following addresses:
  16. * [email protected]
  17. *
  18. * ser is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  26. */
  27. #include <limits.h>
  28. #include "sr_module.h"
  29. #include "dprint.h"
  30. #include "parser/msg_parser.h"
  31. #include "flags.h"
  32. #include "error.h"
  33. #include "stdlib.h"
  34. int setflag( struct sip_msg* msg, flag_t flag ) {
  35. msg->flags |= 1 << flag;
  36. return 1;
  37. }
  38. int resetflag( struct sip_msg* msg, flag_t flag ) {
  39. msg->flags &= ~ (1 << flag);
  40. return 1;
  41. }
  42. int isflagset( struct sip_msg* msg, flag_t flag ) {
  43. return (msg->flags & (1<<flag)) ? 1 : -1;
  44. }
  45. int flag_in_range( flag_t flag ) {
  46. if (flag > MAX_FLAG ) {
  47. LOG(L_ERR, "ERROR: message flag %d too high; MAX=%d\n",
  48. flag, MAX_FLAG );
  49. return 0;
  50. }
  51. if (flag<=0) {
  52. LOG(L_ERR, "ERROR: message flag (%d) must be in range %d..%d\n",
  53. flag, 1, MAX_FLAG );
  54. return 0;
  55. }
  56. return 1;
  57. }
  58. #ifdef _GET_AWAY
  59. /* wrapping functions for flag processing */
  60. static int fixup_t_flag(void** param, int param_no)
  61. {
  62. unsigned int *code;
  63. char *c;
  64. int token;
  65. DBG("DEBUG: fixing flag: %s\n", (char *) (*param));
  66. if (param_no!=1) {
  67. LOG(L_ERR, "ERROR: TM module: only parameter #1 for flags can be fixed\n");
  68. return E_BUG;
  69. };
  70. if ( !(code = malloc( sizeof( unsigned int) )) ) return E_OUT_OF_MEM;
  71. *code = 0;
  72. c = *param;
  73. while ( *c && (*c==' ' || *c=='\t')) c++; /* intial whitespaces */
  74. token=1;
  75. if (strcasecmp(c, "white")==0) *code=FL_WHITE;
  76. else if (strcasecmp(c, "yellow")==0) *code=FL_YELLOW;
  77. else if (strcasecmp(c, "green")==0) *code=FL_GREEN;
  78. else if (strcasecmp(c, "red")==0) *code=FL_RED;
  79. else if (strcasecmp(c, "blue")==0) *code=FL_BLUE;
  80. else if (strcasecmp(c, "magenta")==0) *code=FL_MAGENTA;
  81. else if (strcasecmp(c, "brown")==0) *code=FL_BROWN;
  82. else if (strcasecmp(c, "black")==0) *code=FL_BLACK;
  83. else if (strcasecmp(c, "acc")==0) *code=FL_ACC;
  84. else {
  85. token=0;
  86. while ( *c && *c>='0' && *c<='9' ) {
  87. *code = *code*10+ *c-'0';
  88. if (*code > (sizeof( flag_t ) * CHAR_BIT - 1 )) {
  89. LOG(L_ERR, "ERROR: TM module: too big flag number: %s; MAX=%d\n",
  90. (char *) (*param), sizeof( flag_t ) * CHAR_BIT - 1 );
  91. goto error;
  92. }
  93. c++;
  94. }
  95. }
  96. while ( *c && (*c==' ' || *c=='\t')) c++; /* terminating whitespaces */
  97. if ( *code == 0 ) {
  98. LOG(L_ERR, "ERROR: TM module: bad flag number: %s\n", (char *) (*param));
  99. goto error;
  100. }
  101. if (*code < FL_MAX && token==0) {
  102. LOG(L_ERR, "ERROR: TM module: too high flag number: %s (%d)\n; lower number"
  103. " bellow %d reserved\n", (char *) (*param), *code, FL_MAX );
  104. goto error;
  105. }
  106. /* free string */
  107. free( *param );
  108. /* fix now */
  109. *param = code;
  110. return 0;
  111. error:
  112. free( code );
  113. return E_CFG;
  114. }
  115. #endif