parse_content.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright (C) 2001-2003 FhG Fokus
  3. *
  4. * This file is part of ser, a free SIP server.
  5. *
  6. * ser 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. * ser 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. /*! \file
  21. * \brief Parser :: Content
  22. *
  23. * \ingroup parser
  24. */
  25. #ifndef _PARSE_CONTENT_H
  26. #define _PARSE_CONTENT_H
  27. #include "msg_parser.h"
  28. struct mime_type {
  29. unsigned short type;
  30. unsigned short subtype;
  31. };
  32. /*! \name MimeTypes
  33. * Mimes types/subtypes that are recognized
  34. */
  35. /*@{ */
  36. #define TYPE_TEXT 1
  37. #define TYPE_MESSAGE 2
  38. #define TYPE_APPLICATION 3
  39. #define TYPE_MULTIPART 4
  40. #define TYPE_ALL 0xfe
  41. #define TYPE_UNKNOWN 0xff
  42. #define SUBTYPE_PLAIN 1
  43. #define SUBTYPE_CPIM 2
  44. #define SUBTYPE_SDP 3
  45. #define SUBTYPE_CPLXML 4
  46. #define SUBTYPE_PIDFXML 5
  47. #define SUBTYPE_RLMIXML 6
  48. #define SUBTYPE_RELATED 7
  49. #define SUBTYPE_LPIDFXML 8
  50. #define SUBTYPE_XPIDFXML 9
  51. #define SUBTYPE_WATCHERINFOXML 10
  52. #define SUBTYPE_EXTERNAL_BODY 11
  53. #define SUBTYPE_XML_MSRTC_PIDF 12
  54. #define SUBTYPE_CPIM_PIDFXML 13
  55. #define SUBTYPE_MIXED 14
  56. #define SUBTYPE_ISUP 15
  57. #define SUBTYPE_ALL 0xfe
  58. #define SUBTYPE_UNKNOWN 0xff
  59. /*@} */
  60. /*! \brief taken from PA module - will be useful here */
  61. #define MIMETYPE(x_,y_) ((TYPE_##x_ << 16) | (SUBTYPE_##y_))
  62. /*! \brief
  63. * Maximum number of mimes allowed in Accept header
  64. */
  65. #define MAX_MIMES_NR 128
  66. /*! \brief
  67. * returns the content-length value of a sip_msg as an integer
  68. */
  69. #define get_content_length(_msg_) ((long)((_msg_)->content_length->parsed))
  70. /*! \brief
  71. * returns the content-type value of a sip_msg as an integer
  72. */
  73. #define get_content_type(_msg_) ((int)(long)((_msg_)->content_type->parsed))
  74. /*! \brief
  75. * returns the accept values of a sip_msg as an null-terminated array
  76. * of integer
  77. */
  78. #define get_accept(_msg_) ((int*)((_msg_)->accept->parsed))
  79. /*! \brief
  80. * parse the body of the Content-Type header. It's value is also converted
  81. * as int.
  82. * Returns: n (n>0) : the found type
  83. * 0 : hdr not found
  84. * -1 : error (parse error )
  85. */
  86. int parse_content_type_hdr(struct sip_msg* const msg);
  87. int parse_accept_body(struct hdr_field* const hdr);
  88. /*! \brief
  89. * parse the body of the Accept header. It's values are also converted
  90. * as an null-terminated array of ints.
  91. * Returns: 1 : OK
  92. * 0 : hdr not found
  93. * -1 : error (parse error)
  94. */
  95. int parse_accept_hdr(struct sip_msg* const msg);
  96. /*! \brief
  97. * parse the body of a Content_-Length header. Also tries to recognize the
  98. * type specified by this header (see th above defines).
  99. * Returns the first chr after the end of the header.
  100. */
  101. char* parse_content_length(char* const buffer, const char* const end, int* const length);
  102. /*! \brief
  103. * Sets the mime type from the body of a Content-Type header
  104. */
  105. char* decode_mime_type(char* const start, const char* const end, unsigned int* const mime_type);
  106. #endif