common.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. #ifndef _COMMON_H_
  21. #define _COMMON_H_
  22. #include <stdint.h>
  23. /*
  24. 0 no carrier id defined.
  25. 1..999 are regular carrier ids.
  26. 1000 is used as fake carrier id when merging carriers we are not interested in.
  27. -1000..-1 used in dtm to indicate a carrier id and that no more nodes will follow (leaf node compression).
  28. -1001 used in dtm to mark a pointer to a child node as NULL.
  29. */
  30. #define MIN_PDB_CARRIERID 1
  31. #define MAX_PDB_CARRIERID 999
  32. #define OTHER_CARRIERID 1000
  33. #define MAX_CARRIERID 1000
  34. #define NULL_CARRIERID -1001
  35. #define PAYLOADSIZE 256
  36. #define IS_VALID_PDB_CARRIERID(id) ((id>=MIN_PDB_CARRIERID) && (id<=MAX_PDB_CARRIERID))
  37. #define IS_VALID_CARRIERID(id) ((id>=MIN_PDB_CARRIERID) && (id<=MAX_CARRIERID))
  38. #define PDB_VERSION 1
  39. typedef int16_t carrier_t;
  40. enum __attribute__((packed)) pdb_versions {
  41. PDB_VERSION_1 = 1,
  42. PDB_VERSION_MAX
  43. };
  44. enum __attribute__((packed)) pdb_types {
  45. PDB_TYPE_REQUEST_ID = 0, /* request pdb type */
  46. PDB_TYPE_REPLY_ID, /* reply pdb type */
  47. PDB_TYPE_MAX
  48. };
  49. enum __attribute__((packed)) pdb_codes {
  50. PDB_CODE_DEFAULT = 0, /* for request */
  51. PDB_CODE_OK, /* for response - OK */
  52. PDB_CODE_NOT_NUMBER, /* for response - letters found in the number */
  53. PDB_CODE_NOT_FOUND, /* for response - no pdb_id found for the number */
  54. PDB_CODE_MAX
  55. };
  56. struct __attribute__((packed)) pdb_hdr {
  57. uint8_t version;
  58. uint8_t type;
  59. uint8_t code;
  60. uint8_t length;
  61. uint16_t id;
  62. };
  63. struct __attribute__((packed)) pdb_bdy {
  64. char payload[PAYLOADSIZE];
  65. };
  66. struct __attribute__((packed)) pdb_msg {
  67. struct pdb_hdr hdr;
  68. struct pdb_bdy bdy;
  69. };
  70. void pdb_msg_dbg (struct pdb_msg msg);
  71. int pdb_msg_format_send(struct pdb_msg *msg,
  72. uint8_t version, uint8_t type,
  73. uint8_t code, uint16_t id,
  74. char *payload, uint16_t payload_len);
  75. #endif