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