mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-02-10 18:57:45 +00:00
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3774 d0543943-73ff-0310-b7d9-9358b9ac24b2
312 lines
8.6 KiB
C
312 lines
8.6 KiB
C
/** -*- C -*-
|
||
* @file sofia-sip/http_protos.h.in
|
||
*
|
||
* Template for <http_protos.h>.
|
||
*/
|
||
|
||
/*
|
||
* This file is part of the Sofia-SIP package
|
||
*
|
||
* Copyright (C) 2005 Nokia Corporation.
|
||
*
|
||
* Contact: Pekka Pessi <pekka.pessi@nokia.com>
|
||
*
|
||
* This library is free software; you can redistribute it and/or
|
||
* modify it under the terms of the GNU Lesser General Public License
|
||
* as published by the Free Software Foundation; either version 2.1 of
|
||
* the License, or (at your option) any later version.
|
||
*
|
||
* This library is distributed in the hope that it will be useful, but
|
||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
* Lesser General Public License for more details.
|
||
*
|
||
* You should have received a copy of the GNU Lesser General Public
|
||
* License along with this library; if not, write to the Free Software
|
||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||
* 02110-1301 USA
|
||
*
|
||
*/
|
||
|
||
#ifndef HTTP_PROTOS_H
|
||
/** Defined when <sofia-sip/http_protos.h> has been included. */
|
||
#define HTTP_PROTOS_H
|
||
|
||
/**@file sofia-sip/http_protos.h
|
||
*
|
||
* Macros for each HTTP header.
|
||
*
|
||
* #AUTO#
|
||
*
|
||
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
|
||
*/
|
||
|
||
#include <sofia-sip/su_config.h>
|
||
|
||
#ifndef HTTP_HEADER_H
|
||
#include <sofia-sip/http_header.h>
|
||
#endif
|
||
#ifndef HTTP_HCLASSES_H
|
||
#include <sofia-sip/http_hclasses.h>
|
||
#endif
|
||
|
||
#define http_header_make(h, c, s) \
|
||
((http_header_t *)msg_header_make((h), (c), (s)))
|
||
#define http_header_vformat(h, c, f, a) \
|
||
((http_header_t *)msg_header_vformat((h), (c), (f), (a)))
|
||
|
||
SOFIA_BEGIN_DECLS
|
||
|
||
/* Declare internal prototypes for #xxxxxxx_xxxxxxx# */
|
||
|
||
/**@addtogroup http_#xxxxxx#*/ /** @{ */
|
||
|
||
enum {
|
||
/** Hash of #xxxxxxx_xxxxxxx#. @internal*/
|
||
http_#xxxxxx#_hash = #hash#
|
||
};
|
||
|
||
/**Header class for HTTP #xxxxxxx_xxxxxxx#.
|
||
*
|
||
* The header class http_#xxxxxx#_class defines how a HTTP
|
||
* #xxxxxxx_xxxxxxx# is parsed and printed. It also
|
||
* contains methods used by HTTP parser and other functions
|
||
* to manipulate the http_#xxxxxx#_t header structure.
|
||
*
|
||
*/
|
||
SOFIAPUBVAR msg_hclass_t http_#xxxxxx#_class[];
|
||
|
||
#ifndef HTTP_HCLASSES_ONLY
|
||
|
||
/** Decode (parse) a #xxxxxxx_xxxxxxx#. @internal */
|
||
SOFIAPUBFUN msg_parse_f http_#xxxxxx#_d;
|
||
|
||
/** Encode (print) a #xxxxxxx_xxxxxxx#. @internal */
|
||
SOFIAPUBFUN msg_print_f http_#xxxxxx#_e;
|
||
|
||
/**Initializer for structure http_#xxxxxx#_t.
|
||
*
|
||
* A static http_#xxxxxx#_t structure must be initialized
|
||
* with the HTTP_#XXXXXX#_INIT() macro. For instance,
|
||
* @code
|
||
*
|
||
* http_#xxxxxx#_t http_#xxxxxx# = HTTP_#XXXXXX#_INIT;
|
||
*
|
||
* @endcode
|
||
* @HI
|
||
*/
|
||
#define HTTP_#XXXXXX#_INIT() HTTP_HDR_INIT(#xxxxxx#)
|
||
|
||
/**Initialize a structure http_#xxxxxx#_t.
|
||
*
|
||
* An http_#xxxxxx#_t structure can be initialized with the
|
||
* http_#xxxxxx#_init() function/macro. For instance,
|
||
* @code
|
||
*
|
||
* http_#xxxxxx#_t http_#xxxxxx#;
|
||
*
|
||
* http_#xxxxxx#_init(&http_#xxxxxx#);
|
||
*
|
||
* @endcode
|
||
* @HI
|
||
*/
|
||
#if SU_HAVE_INLINE
|
||
su_inline http_#xxxxxx#_t *http_#xxxxxx#_init(http_#xxxxxx#_t x[1])
|
||
{
|
||
return HTTP_HEADER_INIT(x, http_#xxxxxx#_class, sizeof(http_#xxxxxx#_t));
|
||
}
|
||
#else
|
||
#define http_#xxxxxx#_init(x) \
|
||
HTTP_HEADER_INIT(x, http_#xxxxxx#_class, sizeof(http_#xxxxxx#_t))
|
||
#endif
|
||
|
||
/**Test if header object is instance of http_#xxxxxx#_t.
|
||
*
|
||
* The function http_is_#xxxxxx#() returns true (nonzero) if
|
||
* the header class is an instance of #xxxxxxx_xxxxxxx#
|
||
* object and false (zero) otherwise.
|
||
*
|
||
* @param header pointer to the header structure to be tested
|
||
*
|
||
* @return
|
||
* The function http_is_x#xxxxxx#() returns true (nonzero) if
|
||
* the header object is an instance of header #xxxxxx# and
|
||
* false (zero) otherwise.
|
||
*/
|
||
#if SU_HAVE_INLINE
|
||
su_inline
|
||
int http_is_#xxxxxx#(http_header_t const *header)
|
||
{
|
||
return header && header->sh_class->hc_hash == http_#xxxxxx#_hash;
|
||
}
|
||
#else
|
||
#define http_is_#xxxxxx#(h) \
|
||
((h) && ((msg_common_t *)(h))->h_class->hc_hash == http_#xxxxxx#_hash)
|
||
#endif
|
||
|
||
/**Duplicate (deep copy) @c http_#xxxxxx#_t.
|
||
*
|
||
* The function http_#xxxxxx#_dup() duplicates a header
|
||
* structure @a hdr. If the header structure @a hdr
|
||
* contains a reference (@c hdr->x_next) to a list of
|
||
* headers, all the headers in the list are duplicated, too.
|
||
*
|
||
* @param home memory home used to allocate new structure
|
||
* @param hdr header structure to be duplicated
|
||
*
|
||
* When duplicating, all parameter lists and non-constant
|
||
* strings attached to the header are copied, too. The
|
||
* function uses given memory @a home to allocate all the
|
||
* memory areas used to copy the header.
|
||
*
|
||
* @par Example
|
||
* @code
|
||
*
|
||
* #xxxxxx# = http_#xxxxxx#_dup(home, http->http_#xxxxxx#);
|
||
*
|
||
* @endcode
|
||
*
|
||
* @return
|
||
* The function http_#xxxxxx#_dup() returns a pointer to the
|
||
* newly duplicated http_#xxxxxx#_t header structure, or NULL
|
||
* upon an error.
|
||
*/
|
||
#if SU_HAVE_INLINE
|
||
su_inline
|
||
#endif
|
||
http_#xxxxxx#_t *http_#xxxxxx#_dup(su_home_t *home,
|
||
http_#xxxxxx#_t const *hdr)
|
||
__attribute__((__malloc__));
|
||
|
||
/**Copy a http_#xxxxxx#_t header structure.
|
||
*
|
||
* The function http_#xxxxxx#_copy() copies a header structure @a
|
||
* hdr. If the header structure @a hdr contains a reference (@c
|
||
* hdr->h_next) to a list of headers, all the headers in that
|
||
* list are copied, too. The function uses given memory @a home
|
||
* to allocate all the memory areas used to copy the header
|
||
* structure @a hdr.
|
||
*
|
||
* @param home memory home used to allocate new structure
|
||
* @param hdr pointer to the header structure to be duplicated
|
||
*
|
||
* When copying, only the header structure and parameter lists
|
||
* attached to it are duplicated. The new header structure
|
||
* retains all the references to the strings within the old @a
|
||
* header, including the encoding of the old header, if present.
|
||
*
|
||
* @par Example
|
||
* @code
|
||
*
|
||
* #xxxxxx# = http_#xxxxxx#_copy(home, http->http_#xxxxxx#);
|
||
*
|
||
* @endcode
|
||
*
|
||
* @return
|
||
* The function http_#xxxxxx#_copy() returns a pointer to
|
||
* newly copied header structure, or NULL upon an error.
|
||
*/
|
||
#if SU_HAVE_INLINE
|
||
su_inline
|
||
#endif
|
||
http_#xxxxxx#_t *http_#xxxxxx#_copy(su_home_t *home,
|
||
http_#xxxxxx#_t const *hdr)
|
||
__attribute__((__malloc__));
|
||
|
||
/**Make a header structure http_#xxxxxx#_t.
|
||
*
|
||
* The function http_#xxxxxx#_make() makes a new
|
||
* http_#xxxxxx#_t header structure. It allocates a new
|
||
* header structure, and decodes the string @a s as the
|
||
* value of the structure.
|
||
*
|
||
* @param home memory home used to allocate new header structure.
|
||
* @param s string to be decoded as value of the new header structure
|
||
*
|
||
* @note This function is usually implemented as a macro calling
|
||
* http_header_make().
|
||
*
|
||
* @return
|
||
* The function http_#xxxxxx#_make() returns a pointer to
|
||
* newly maked http_#xxxxxx#_t header structure, or NULL upon
|
||
* an error.
|
||
*/
|
||
#if SU_HAVE_INLINE
|
||
su_inline
|
||
#endif
|
||
http_#xxxxxx#_t *http_#xxxxxx#_make(su_home_t *home, char const *s)
|
||
__attribute__((__malloc__));
|
||
|
||
/**Make a #xxxxxxx_xxxxxxx# from formatting result.
|
||
*
|
||
* The function http_#xxxxxx#_format() makes a new
|
||
* #xxxxxxx_xxxxxxx# object using formatting result as its
|
||
* value. The function first prints the arguments according to
|
||
* the format @a fmt specified. Then it allocates a new header
|
||
* structure, and uses the formatting result as the header
|
||
* value.
|
||
*
|
||
* @param home memory home used to allocate new header structure.
|
||
* @param fmt string used as a printf()-style format
|
||
* @param ... argument list for format
|
||
*
|
||
* @note This function is usually implemented as a macro calling
|
||
* msg_header_format().
|
||
*
|
||
* @return
|
||
* The function http_#xxxxxx#_format() returns a pointer to newly
|
||
* makes header structure, or NULL upon an error.
|
||
*
|
||
* @HIDE
|
||
*/
|
||
#if SU_HAVE_INLINE
|
||
su_inline
|
||
#endif
|
||
http_#xxxxxx#_t *http_#xxxxxx#_format(su_home_t *home, char const *fmt, ...)
|
||
__attribute__((__malloc__, __format__ (printf, 2, 3)));
|
||
|
||
|
||
/* Inlined functions */
|
||
#if SU_HAVE_INLINE
|
||
su_inline
|
||
http_#xxxxxx#_t *http_#xxxxxx#_format(su_home_t *home, char const *fmt, ...)
|
||
{
|
||
http_header_t *h;
|
||
va_list ap;
|
||
|
||
va_start(ap, fmt);
|
||
h = http_header_vformat(home, http_#xxxxxx#_class, fmt, ap);
|
||
va_end(ap);
|
||
|
||
return (http_#xxxxxx#_t *)h;
|
||
}
|
||
|
||
su_inline
|
||
http_#xxxxxx#_t *http_#xxxxxx#_dup(su_home_t *home, http_#xxxxxx#_t const *o)
|
||
{
|
||
return (http_#xxxxxx#_t *)
|
||
msg_header_dup_as(home, http_#xxxxxx#_class, (msg_header_t const *)o);
|
||
}
|
||
|
||
su_inline
|
||
http_#xxxxxx#_t *http_#xxxxxx#_copy(su_home_t *home, http_#xxxxxx#_t const *o)
|
||
{
|
||
return (http_#xxxxxx#_t *)
|
||
msg_header_copy_as(home, http_#xxxxxx#_class, (msg_header_t const *)o);
|
||
}
|
||
|
||
su_inline
|
||
http_#xxxxxx#_t *http_#xxxxxx#_make(su_home_t *home, char const *s)
|
||
{
|
||
return (http_#xxxxxx#_t *)http_header_make(home, http_#xxxxxx#_class, s);
|
||
}
|
||
#endif
|
||
|
||
#endif /* !define HTTP_HCLASSES_ONLY */
|
||
|
||
/** @} */
|
||
|
||
|
||
SOFIA_END_DECLS
|
||
#endif /* !defined(HTTP_PROTOS_H) */
|