http  1.12.11devel
http_header.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Sofia-SIP package
3  *
4  * Copyright (C) 2005 Nokia Corporation.
5  *
6  * Contact: Pekka Pessi <pekka.pessi@nokia-email.address.hidden>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; either version 2.1 of
11  * the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  *
23  */
24 
25 #ifndef HTTP_HEADER_H
26 
27 #define HTTP_HEADER_H
28 
38 #ifndef SU_ALLOC_H
39 #include <sofia-sip/su_alloc.h>
40 #endif
41 
42 #ifndef SU_TAG_H
43 #include <sofia-sip/su_tag.h>
44 #endif
45 
46 #ifndef HTTP_H
47 #include <sofia-sip/http.h>
48 #endif
49 
50 #ifndef MSG_HEADER_H
51 #include <sofia-sip/msg_header.h>
52 #endif
53 
54 SOFIA_BEGIN_DECLS
55 
56 /* ----------------------------------------------------------------------
57  * 1) Macros
58  */
59 
61 #define HTTP_HEADER_INIT(h, http_class, size) \
62  ((void)memset((h), 0, (size)), \
63  (void)(((msg_common_t *)(h))->h_class = (http_class)), \
64  (h))
65 
66 #define HTTP_METHOD_NAME(method, name) \
67  ((method) == http_method_unknown ? (name) : http_method_name(method, name))
68 
69 /* ----------------------------------------------------------------------
70  * 2) Variables
71  */
72 
73 SOFIAPUBVAR char const http_method_name_get[];
74 SOFIAPUBVAR char const http_method_name_post[];
75 SOFIAPUBVAR char const http_method_name_head[];
76 SOFIAPUBVAR char const http_method_name_options[];
77 SOFIAPUBVAR char const http_method_name_put[];
78 SOFIAPUBVAR char const http_method_name_delete[];
79 SOFIAPUBVAR char const http_method_name_trace[];
80 SOFIAPUBVAR char const http_method_name_connect[];
81 
83 SOFIAPUBVAR char const http_version_0_9[];
84 
86 SOFIAPUBVAR char const http_version_1_0[];
87 
89 SOFIAPUBVAR char const http_version_1_1[];
90 
91 #define HTTP_VERSION_CURRENT http_version_1_1
92 
93 /* ----------------------------------------------------------------------
94  * 3) Prototypes
95  */
96 
99 
102 
105 
108 
110 SOFIAPUBFUN int http_add_make(msg_t *msg, http_t *http,
111  msg_hclass_t *hc, char const *s);
112 
115  char const *fmt, ...);
116 
118 SOFIAPUBFUN int http_add_tl(msg_t *msg, http_t *http,
119  tag_type_t tag, tag_value_t value, ...);
120 
123 
126  int status, char const *phrase,
127  http_t const *request);
128 
130 SOFIAPUBFUN char const *http_method_name(http_method_t method,
131  char const *name);
132 
134 SOFIAPUBFUN http_method_t http_method_code(char const *name);
135 
136 #if !SU_HAVE_INLINE
140 SOFIAPUBFUN char const *http_header_name(http_header_t const *h, int compact);
142 SOFIAPUBFUN http_content_length_t *http_content_length_create(su_home_t *home,
143  uint32_t n);
144 SOFIAPUBFUN http_payload_t *http_payload_create(su_home_t *home,
145  void const *data, usize_t len);
146 SOFIAPUBFUN http_separator_t *http_separator_create(su_home_t *home);
147 #endif
148 
149 SOFIAPUBFUN http_header_t *http_header_format(su_home_t *home, msg_hclass_t *,
150  char const *fmt, ...);
151 
152 
155  http_method_t method,
156  const char *name,
157  url_string_t const *url,
158  char const *version);
159 
162  unsigned status,
163  char const *phrase,
164  char const *version);
165 
168  char const *host,
169  char const *port);
170 
173 
176  http_time_t delta);
177 
179 SOFIAPUBFUN int http_url_cmp(url_t const *a, url_t const *b);
180 
182 SOFIAPUBFUN issize_t http_query_parse(char *query,
183  /* char const *key, char **return_value, */
184  ...);
185 
186 /* ----------------------------------------------------------------------
187  * 4) Inlined functions
188  */
189 
190 #if SU_HAVE_INLINE
191 
192 su_inline
194 {
195  return (http_t *)msg_public(msg, HTTP_PROTOCOL_TAG);
196 }
197 
216 su_inline
218 {
219  return msg_header_insert(msg, (msg_pub_t *)http, (msg_header_t *)h);
220 }
221 
223 su_inline
225 {
226  return msg_header_remove(msg, (msg_pub_t *)http, (msg_header_t *)h);
227 }
228 
230 su_inline
231 char const *http_header_name(http_header_t const *h, int compact)
232 {
233  if (compact && h->sh_class->hc_short[0])
234  return h->sh_class->hc_short;
235  else
236  return h->sh_class->hc_name;
237 }
238 
240 su_inline
242 {
243  return h && h != HTTP_NONE ? h->sh_class->hc_size + (char *)h : NULL;
244 }
245 
246 su_inline
247 http_content_length_t *http_content_length_create(su_home_t *home, uint32_t n)
248 {
249  return msg_content_length_create(home, n);
250 }
251 
252 su_inline
253 http_payload_t *http_payload_create(su_home_t *home, void const *data, isize_t len)
254 {
255  return msg_payload_create(home, data, len);
256 }
257 
258 su_inline
259 http_separator_t *http_separator_create(su_home_t *home)
260 {
261  return msg_separator_create(home);
262 }
263 #endif
264 
265 SOFIA_END_DECLS
266 
267 #ifndef HTTP_PROTOS_H
268 #include <sofia-sip/http_protos.h>
269 #endif
270 
271 #endif /* !defined(HTTP_HEADER_H) */
http_expires_create
http_expires_t * http_expires_create(su_home_t *home, http_time_t delta)
Create an Expires header object.
su_home_t
SU_HOME_T su_home_t
http_host_create
http_host_t * http_host_create(su_home_t *home, char const *host, char const *port)
Create an Host header object.
Definition: http_basic.c:733
http_message_complete
int http_message_complete(msg_t *msg, http_t *http)
Complete a HTTP message.
Definition: http_header.c:120
http_complete_response
int http_complete_response(msg_t *msg, int status, char const *phrase, http_t const *request)
Add required headers to the response message.
Definition: http_header.c:151
http_request_complete
int http_request_complete(msg_t *msg)
Complete a HTTP request.
Definition: http_header.c:62
uint32_t
SU_U32_T uint32_t
msg_pub_t
MSG_PUB_T msg_pub_t
msg_payload_s
tag_type_t
struct tag_type_s const * tag_type_t
http_date_s
Date, Expires, If-Modified-Since, If-Unmodified-Since, Last-Modified.
Definition: http.h:219
su_tag.h
http_add_make
int http_add_make(msg_t *msg, http_t *http, msg_hclass_t *hc, char const *s)
Add a header to the HTTP message.
Definition: http_header.c:244
http_version_1_1
const char http_version_1_1[]
HTTP 1.1 version.
Definition: http_parser.c:58
su_inline
#define su_inline
http_header_data
void * http_header_data(http_header_t *h)
Return data after header structure.
Definition: http_header.h:241
msg_header_remove
int msg_header_remove(msg_t *msg, msg_pub_t *mo, msg_header_t *h)
url_t
http_header_remove
int http_header_remove(msg_t *msg, http_t *http, http_header_t *h)
Remove a header from a HTTP message.
Definition: http_header.h:224
http_method_name
const char * http_method_name(http_method_t method, char const *name)
Return string corresponding to the method.
Definition: http_parser.c:416
http_request_create
http_request_t * http_request_create(su_home_t *home, http_method_t method, const char *name, url_string_t const *url, char const *version)
Create a request line object.
Definition: http_basic.c:145
http_add_format
int http_add_format(msg_t *msg, http_t *http, msg_hclass_t *hc, char const *fmt,...)
Add a header to the HTTP message.
Definition: http_header.c:258
http_time_t
unsigned long http_time_t
Time in seconds since 01-Jan-1900.
Definition: http.h:169
tag_value_t
intptr_t tag_value_t
http_host_s
Host.
Definition: http.h:226
msg_separator_s
http_s
HTTP message object.
Definition: http.h:323
msg_header.h
http_method_code
http_method_t http_method_code(char const *name)
Return enum corresponding to the method name.
Definition: http_parser.c:500
url_string_t
msg_payload_create
msg_payload_t * msg_payload_create(su_home_t *home, void const *data, usize_t len))
msg_mclass_s
http_header_insert
int http_header_insert(msg_t *msg, http_t *http, http_header_t *h)
Insert a (list of) header(s) to the header structure and fragment chain.
Definition: http_header.h:217
http_add_tl
int http_add_tl(msg_t *msg, http_t *http, tag_type_t tag, tag_value_t value,...)
Add tagged headers to the HTTP message.
Definition: http_tag_class.c:159
http_status_create
http_status_t * http_status_create(su_home_t *home, unsigned status, char const *phrase, char const *version)
Create a status line object.
Definition: http_basic.c:262
http_strip_hostport
int http_strip_hostport(url_t *url)
Remove schema, host, and port from URL.
Definition: http_header.c:99
http_header_name
const char * http_header_name(http_header_t const *h, int compact)
Return name of the header.
Definition: http_header.h:231
http_default_mclass
const msg_mclass_t * http_default_mclass(void)
HTTP parser description.
Definition: http_parser.c:64
msg_public
msg_pub_t * msg_public(msg_t const *msg, void *tag)
SOFIAPUBVAR
#define SOFIAPUBVAR
http_request_s
HTTP request line.
Definition: http.h:179
msg_header_t
MSG_HDR_T msg_header_t
msg_s
msg_header_insert
int msg_header_insert(msg_t *msg, msg_pub_t *mo, msg_header_t *h)
msg_content_length_create
msg_content_length_t * msg_content_length_create(su_home_t *home, uint32_t n)
SOFIAPUBFUN
#define SOFIAPUBFUN
msg_hclass_t
struct msg_hclass_s const msg_hclass_t
su_alloc.h
http_date_create
http_date_t * http_date_create(su_home_t *home, http_time_t t)
Create an Date header object.
Definition: http_basic.c:584
HTTP_PROTOCOL_TAG
#define HTTP_PROTOCOL_TAG
HTTP protocol identifier.
Definition: http.h:61
http_url_cmp
int http_url_cmp(url_t const *a, url_t const *b)
Compare two HTTP URLs.
Definition: http_header.c:281
http_protos.h
http_status_s
HTTP status line.
Definition: http.h:189
http_add_dup
int http_add_dup(msg_t *, http_t *, http_header_t const *)
Add a duplicate of header object to a HTTP message.
Definition: http_header.c:231
http_query_parse
issize_t http_query_parse(char *query,...)
Parse query part in HTTP URL.
Definition: http_parser.c:520
http_object
http_t * http_object(msg_t *msg)
Get HTTP structure from msg.
Definition: http_header.h:193
http_header_u
Union representing any HTTP header.
Definition: http.h:403
http_method_t
http_method_t
IDs for well-known HTTP methods.
Definition: http.h:69
http_version_0_9
const char http_version_0_9[]
HTTP 0.9.
Definition: http_parser.c:62
msg_content_length_s
http.h
http_version_1_0
const char http_version_1_0[]
HTTP 1.0.
Definition: http_parser.c:60

Sofia-SIP 1.12.11devel - Copyright (C) 2006 Nokia Corporation. All rights reserved. Licensed under the terms of the GNU Lesser General Public License.