debugger_act.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /**
  2. * $Id$
  3. *
  4. * Copyright (C) 2010 Daniel-Constantin Mierla (asipto.com)
  5. *
  6. * This file is part of Kamailio, a free SIP server.
  7. *
  8. * This file 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. * This file 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. */
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include <stdlib.h>
  26. #include <unistd.h>
  27. #include "../../dprint.h"
  28. #include "../../sr_module.h"
  29. #include "debugger_act.h"
  30. typedef struct _dbg_action {
  31. int type;
  32. str name;
  33. } dbg_action_t;
  34. static str _dbg_action_special[] = {
  35. str_init("unknown"), /* 0 */
  36. str_init("exit"), /* 1 */
  37. str_init("drop"), /* 2 */
  38. str_init("return"), /* 3 */
  39. {0, 0}
  40. };
  41. static dbg_action_t _dbg_action_list[] = {
  42. { FORWARD_T, str_init("forward") },
  43. { LOG_T, str_init("log") },
  44. { ERROR_T, str_init("error") },
  45. { ROUTE_T, str_init("route") },
  46. { EXEC_T, str_init("exec") },
  47. { SET_HOST_T, str_init("sethost") },
  48. { SET_HOSTPORT_T, str_init("sethostport") },
  49. { SET_USER_T, str_init("setuser") },
  50. { SET_USERPASS_T, str_init("setuserpass") },
  51. { SET_PORT_T, str_init("setport") },
  52. { SET_URI_T, str_init("seturi") },
  53. { SET_HOSTPORTTRANS_T, str_init("sethostporttrans") },
  54. { SET_HOSTALL_T, str_init("sethostall") },
  55. { SET_USERPHONE_T, str_init("setuserphone") },
  56. { IF_T, str_init("if") },
  57. { SWITCH_T, str_init("switch") },
  58. { BLOCK_T, str_init("block") },
  59. { EVAL_T, str_init("eval") },
  60. { SWITCH_JT_T, str_init("switch") },
  61. { SWITCH_COND_T, str_init("switch") },
  62. { MATCH_COND_T, str_init("case") },
  63. { WHILE_T, str_init("while") },
  64. { SETFLAG_T, str_init("setflag") },
  65. { RESETFLAG_T, str_init("resetflag") },
  66. { ISFLAGSET_T, str_init("isflagset") },
  67. { AVPFLAG_OPER_T, str_init("avpflag") },
  68. { LEN_GT_T, str_init("lengt") },
  69. { PREFIX_T, str_init("prefix") },
  70. { STRIP_T, str_init("strip") },
  71. { STRIP_TAIL_T, str_init("striptail") },
  72. { APPEND_BRANCH_T, str_init("append_branch") },
  73. { REVERT_URI_T, str_init("reverturi") },
  74. { FORWARD_TCP_T, str_init("forward_tcp") },
  75. { FORWARD_UDP_T, str_init("forward_udp") },
  76. { FORWARD_TLS_T, str_init("forward_tls") },
  77. { FORWARD_SCTP_T, str_init("forward_sctp") },
  78. { FORCE_RPORT_T, str_init("force_rport") },
  79. { ADD_LOCAL_RPORT_T, str_init("add_local_rport") },
  80. { SET_ADV_ADDR_T, str_init("set_adv_addr") },
  81. { SET_ADV_PORT_T, str_init("set_adv_port") },
  82. { FORCE_TCP_ALIAS_T, str_init("force_tcp_alias") },
  83. { LOAD_AVP_T, str_init("load_avp") },
  84. { AVP_TO_URI_T, str_init("avp_to_uri") },
  85. { FORCE_SEND_SOCKET_T, str_init("force_send_socket") },
  86. { ASSIGN_T, str_init("assign") },
  87. { ADD_T, str_init("add") },
  88. { UDP_MTU_TRY_PROTO_T, str_init("udp_mtu_try_proto") },
  89. { SET_FWD_NO_CONNECT_T, str_init("set_fwd_no_connect") },
  90. { SET_RPL_NO_CONNECT_T, str_init("set_rpl_no_connect") },
  91. { SET_FWD_CLOSE_T, str_init("set_fwd_close") },
  92. { SET_RPL_CLOSE_T, str_init("set_rpl_close") },
  93. { 0, {0, 0} }
  94. };
  95. str* dbg_get_action_name(struct action *a)
  96. {
  97. int i;
  98. static str aname;
  99. cmd_export_common_t *cmd;
  100. if(a==NULL)
  101. return &_dbg_action_special[0];
  102. switch(a->type) {
  103. case DROP_T:
  104. if(a->val[1].u.number&DROP_R_F)
  105. return &_dbg_action_special[2];
  106. if(a->val[1].u.number&RETURN_R_F)
  107. return &_dbg_action_special[3];
  108. return &_dbg_action_special[1];
  109. case MODULE0_T:
  110. case MODULE1_T:
  111. case MODULE2_T:
  112. case MODULE3_T:
  113. case MODULE4_T:
  114. case MODULE5_T:
  115. case MODULE6_T:
  116. case MODULEX_T:
  117. case MODULE1_RVE_T:
  118. case MODULE2_RVE_T:
  119. case MODULE3_RVE_T:
  120. case MODULE4_RVE_T:
  121. case MODULE5_RVE_T:
  122. case MODULE6_RVE_T:
  123. case MODULEX_RVE_T:
  124. cmd = (cmd_export_common_t*)(a->val[0].u.data);
  125. aname.s = cmd->name;
  126. aname.len = strlen(aname.s);
  127. return &aname;
  128. default:
  129. for(i=0; _dbg_action_list[i].type!=0; i++)
  130. {
  131. if(_dbg_action_list[i].type==a->type)
  132. return &_dbg_action_list[i].name;
  133. }
  134. }
  135. return &_dbg_action_special[0];
  136. }