pdb_server_backend.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (C) 2009 1&1 Internet AG
  3. *
  4. * This file is part of sip-router, a free SIP server.
  5. *
  6. * sip-router is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version
  10. *
  11. * sip-router is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "pdb_server_backend.h"
  21. #include "dtm.h"
  22. #include "log.h"
  23. #include <stdio.h>
  24. #include <string.h>
  25. struct dtm_node_t *mroot;
  26. int init_backend(char *filename)
  27. {
  28. mroot=dtm_load(filename);
  29. if (mroot == NULL) {
  30. LERR("cannot load '%s'.\n", filename);
  31. return -1;
  32. }
  33. return 0;
  34. }
  35. carrier_t lookup_number(char *number)
  36. {
  37. carrier_t carrierid;
  38. int nmatch=dtm_longest_match(mroot, number, strlen(number), &carrierid);
  39. if (nmatch<=0) {
  40. /* nothing found - return id 0 */
  41. carrierid=0;
  42. }
  43. LINFO("request='%s', nmatch=%ld, carrier=%ld\n", number, (long int)nmatch, (long int)carrierid);
  44. return carrierid;
  45. }