ds_rpc.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /**
  2. * $Id$
  3. *
  4. * dispatcher module -- stateless load balancing
  5. *
  6. * Copyright (C) 2004-2006 FhG Fokus
  7. * Copyright (C) 2005-2008 Hendrik Scholz <[email protected]>
  8. *
  9. * This file is part of ser, a free SIP server.
  10. *
  11. * ser is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version
  15. *
  16. * For a license to use the ser software under conditions
  17. * other than those described here, or to purchase support for this
  18. * software, please contact iptel.org by e-mail at the following addresses:
  19. * [email protected]
  20. *
  21. * ser is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  29. */
  30. #include <stdio.h>
  31. #include <string.h>
  32. #include <stdlib.h>
  33. #include <sys/types.h>
  34. #include <unistd.h>
  35. #include "../../sr_module.h"
  36. #include "dispatcher.h"
  37. #include "ds_rpc.h"
  38. /******************************************************************************
  39. *
  40. * dispatcher_dump()
  41. *
  42. * fifo command handler for 'dispatcher_dump' command
  43. * dumps the active dispatcher config to the pipe
  44. *
  45. *****************************************************************************/
  46. void rpc_dump(rpc_t *rpc, void *c) {
  47. extern int *ds_activelist;
  48. extern char ***ds_setp_a, ***ds_setp_b;
  49. extern int **ds_setlen_a, **ds_setlen_b;
  50. int set, node;
  51. if (rpc->printf(c,
  52. "flags: DS_MAX_SETS: %d DS_MAX_NODES: %d DS_MAX_URILEN: %d",
  53. DS_MAX_SETS, DS_MAX_NODES, DS_MAX_URILEN) < 0) return;
  54. if (rpc->printf(c,
  55. "Active dispatcher list: %d", *ds_activelist) < 0) return;
  56. if (*ds_activelist == 0) {
  57. for (set = 0; set < DS_MAX_SETS; set++) {
  58. if (ds_setlen_a[set] == 0) {
  59. if (rpc->printf(c, "Set %2d is empty", set) < 0) return;
  60. } else {
  61. if (rpc->printf(c, "Set %2d:", set) < 0) return;
  62. for (node = 0; node < (long int) ds_setlen_a[set]; node++) {
  63. if (rpc->printf(c, " node %3d %s",
  64. node, ds_setp_a[set][node]) < 0) return;
  65. }
  66. }
  67. }
  68. } else {
  69. for (set = 0; set < DS_MAX_SETS; set++) {
  70. if (ds_setlen_b[set] == 0) {
  71. if (rpc->printf(c, "Set %2d is empty", set) < 0) return;
  72. } else {
  73. if (rpc->printf(c, "Set %2d:", set) < 0) return;
  74. for (node = 0; node < (long int) ds_setlen_b[set]; node++) {
  75. if (rpc->printf(c, " node %3d %s",
  76. node, ds_setp_b[set][node]) < 0) return;
  77. }
  78. }
  79. }
  80. }
  81. rpc->printf(c, "End of dispatcher list");
  82. return;
  83. }
  84. /******************************************************************************
  85. *
  86. * dispatcher_reload()
  87. *
  88. * reload a dispatcher list and activate if successful
  89. *
  90. *****************************************************************************/
  91. void rpc_reload(rpc_t *rpc, void *c) {
  92. extern char *dslistfile;
  93. extern int *ds_activelist;
  94. LOG(L_ERR, "DISPATCHER module reloading\n");
  95. if (ds_load_list(dslistfile) == 0) {
  96. DS_SWITCH_ACTIVE_LIST
  97. rpc->printf(c, "dispatcher list %d activated", *ds_activelist);
  98. } else {
  99. rpc->printf(c, "dispatcher list reload failed");
  100. }
  101. return ;
  102. }
  103. /* rpc function titles */
  104. static const char *rpc_dump_doc[2] = {
  105. "Dump dispatcher set configuration",
  106. 0
  107. };
  108. static const char *rpc_reload_doc[2] = {
  109. "Reload dispatcher list from file",
  110. 0
  111. };
  112. rpc_export_t rpc_methods[] = {
  113. {"dispatcher.dump", rpc_dump, rpc_dump_doc, 0},
  114. {"dispatcher.reload", rpc_reload, rpc_reload_doc, 0},
  115. {0, 0, 0, 0}
  116. };