sofia-sip/msg_header.h

Go to the documentation of this file.
00001 /*
00002  * This file is part of the Sofia-SIP package
00003  *
00004  * Copyright (C) 2005 Nokia Corporation.
00005  *
00006  * Contact: Pekka Pessi <pekka.pessi@nokia-email.address.hidden>
00007  *
00008  * This library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public License
00010  * as published by the Free Software Foundation; either version 2.1 of
00011  * the License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00021  * 02110-1301 USA
00022  *
00023  */
00024 
00025 #ifndef MSG_HEADER_H
00026 
00027 #define MSG_HEADER_H
00028 
00039 #include <stdarg.h>
00040 #include <string.h>
00041 
00042 #ifndef SU_TYPES_H
00043 #include <sofia-sip/su_types.h>
00044 #endif
00045 #ifndef SU_ALLOC_H
00046 #include <sofia-sip/su_alloc.h>
00047 #endif
00048 #ifndef MSG_H
00049 #include <sofia-sip/msg.h>
00050 #endif
00051 #ifndef URL_H
00052 #include <sofia-sip/url.h>
00053 #endif
00054 
00055 SOFIA_BEGIN_DECLS
00056 
00057 SOFIAPUBFUN msg_header_t *msg_header_alloc(su_home_t *,
00058                                            msg_hclass_t *hc,
00059                                            isize_t extra)
00060   __attribute__((__malloc__));
00061 
00062 SOFIAPUBFUN isize_t msg_header_size(msg_header_t const *h);
00063 
00064 SOFIAPUBFUN msg_header_t **msg_header_offset(msg_t const *,
00065                                          msg_pub_t const *,
00066                                          msg_header_t const *);
00067 SOFIAPUBFUN msg_header_t **msg_hclass_offset(msg_mclass_t const *,
00068                                              msg_pub_t const *,
00069                                              msg_hclass_t *);
00070 SOFIAPUBFUN msg_header_t *msg_header_access(msg_pub_t const *pub,
00071                                             msg_hclass_t *hc);
00072 
00073 SOFIAPUBFUN msg_header_t *msg_header_copy_as(su_home_t *home,
00074                                              msg_hclass_t *hc,
00075                                              msg_header_t const *o)
00076   __attribute__((__malloc__));
00077 SOFIAPUBFUN msg_header_t *msg_header_copy(su_home_t *home,
00078                                           msg_header_t const *o)
00079   __attribute__((__malloc__));
00080 SOFIAPUBFUN msg_header_t *msg_header_copy_one(su_home_t *home,
00081                                               msg_header_t const *o)
00082   __attribute__((__malloc__));
00083 SOFIAPUBFUN msg_header_t *msg_header_dup_as(su_home_t *home,
00084                                             msg_hclass_t *hc,
00085                                             msg_header_t const *o)
00086   __attribute__((__malloc__));
00087 SOFIAPUBFUN msg_header_t *msg_header_dup(su_home_t *home,
00088                                          msg_header_t const *h)
00089   __attribute__((__malloc__));
00090 SOFIAPUBFUN msg_header_t *msg_header_dup_one(su_home_t *home,
00091                                              msg_header_t const *h)
00092   __attribute__((__malloc__));
00093 
00094 SOFIAPUBFUN msg_header_t *msg_header_d(su_home_t *home,
00095                                        msg_t const *msg,
00096                                        char const *b);
00097 SOFIAPUBFUN issize_t msg_header_e(char b[], isize_t bsiz,
00098                                   msg_header_t const *h,
00099                                   int flags);
00100 SOFIAPUBFUN issize_t msg_object_e(char b[], isize_t size,
00101                                   msg_pub_t const *mo,
00102                                   int flags);
00103 
00104 SOFIAPUBFUN issize_t msg_header_field_e(char b[], isize_t bsiz,
00105                                         msg_header_t const *h,
00106                                         int flags);
00107 
00108 SOFIAPUBFUN int msg_header_remove(msg_t *msg,
00109                                   msg_pub_t *mo,
00110                                   msg_header_t *h);
00111 
00112 SOFIAPUBFUN int msg_header_remove_all(msg_t *msg,
00113                                       msg_pub_t *mo,
00114                                       msg_header_t *h);
00115 
00116 SOFIAPUBFUN int msg_header_insert(msg_t *msg, msg_pub_t *mo,
00117                                   msg_header_t *h);
00118 
00119 SOFIAPUBFUN int msg_header_replace(msg_t *msg, msg_pub_t *mo,
00120                                    msg_header_t *old_header,
00121                                    msg_header_t *new_header);
00122 
00123 SOFIAPUBFUN int msg_header_add_dup(msg_t *msg,
00124                                    msg_pub_t *pub,
00125                                    msg_header_t const *o);
00126 
00127 SOFIAPUBFUN int msg_header_add_str(msg_t *msg,
00128                                    msg_pub_t *pub,
00129                                    char const *str);
00130 
00131 SOFIAPUBFUN int msg_header_parse_str(msg_t *msg,
00132                                      msg_pub_t *pub,
00133                                      char *s);
00134 
00135 SOFIAPUBFUN int msg_header_add_dup_as(msg_t *msg,
00136                                       msg_pub_t *pub,
00137                                       msg_hclass_t *hc,
00138                                       msg_header_t const *o);
00139 
00140 SOFIAPUBFUN int msg_header_add_make(msg_t *msg,
00141                                     msg_pub_t *pub,
00142                                     msg_hclass_t *hc,
00143                                     char const *s);
00144 
00145 SOFIAPUBFUN int msg_header_prepend(msg_t *msg,
00146                                    msg_pub_t *pub,
00147                                    msg_header_t **hh,
00148                                    msg_header_t *h);
00149 
00150 SOFIAPUBFUN msg_header_t *msg_header_make(su_home_t *home,
00151                                           msg_hclass_t *hc,
00152                                           char const *s)
00153      __attribute__((__malloc__));
00154 
00155 SOFIAPUBFUN msg_header_t *msg_header_format(su_home_t *home,
00156                                             msg_hclass_t *hc,
00157                                             char const *fmt, ...)
00158      __attribute__ ((__malloc__, __format__ (printf, 3, 4)));
00159 
00160 SOFIAPUBFUN msg_header_t *msg_header_vformat(su_home_t *home,
00161                                              msg_hclass_t *hc,
00162                                              char const *fmt,
00163                                              va_list ap)
00164      __attribute__((__malloc__));
00165 
00166 
00167 SOFIAPUBFUN void msg_header_free(su_home_t *home,
00168                                  msg_header_t *h);
00169 
00170 SOFIAPUBFUN void msg_header_free_all(su_home_t *home,
00171                                      msg_header_t *h);
00172 
00173 SOFIAPUBFUN msg_payload_t *msg_payload_create(su_home_t *home,
00174                                               void const *data,
00175                                               usize_t len)
00176      __attribute__((__malloc__));
00177 
00178 SOFIAPUBFUN msg_separator_t *msg_separator_create(su_home_t *home)
00179   __attribute__((__malloc__));
00180 
00181 /* Chunk handling macros */
00182 
00184 #define MSG_CHUNK_BUFFER(pl) \
00185   ((char *)pl->pl_common->h_data + (pl)->pl_common->h_len)
00186 
00187 #define MSG_CHUNK_AVAIL(pl) \
00188   ((pl)->pl_len + ((pl)->pl_data - (char *)pl->pl_common->h_data) - \
00189    (pl)->pl_common->h_len)
00190 
00191 #define MSG_CHUNK_NEXT(pl) \
00192   ((pl)->pl_next)
00193 
00194 SOFIAPUBFUN issize_t msg_headers_prepare(msg_t *,
00195                                          msg_header_t *headers,
00196                                          int flags);
00197 
00198 #ifdef SU_HAVE_INLINE
00199 
00200 su_inline void msg_fragment_clear(msg_common_t *h) 
00201 {
00202   h->h_data = NULL, h->h_len = 0;
00203 }
00204 
00206 su_inline 
00207 msg_param_t **msg_header_params(msg_common_t const *h)
00208 {
00209   if (h && h->h_class->hc_params) {
00210     return (msg_param_t **)((char *)h + h->h_class->hc_params);
00211   }
00212   return NULL;
00213 }
00214 #else
00215 #define msg_fragment_clear(h) ((h)->h_data = NULL, (h)->h_len = 0)
00216 #define msg_header_params(h) \
00217  (((h) && ((msg_common_t *)h)->h_class->hc_params) ? \
00218   (msg_param_t **)((char *)(h) + ((msg_common_t *)h)->h_class->hc_params) : NULL)
00219 #endif
00220 
00221 SOFIAPUBFUN char const *msg_header_find_param(msg_common_t const *,
00222                                               char const *name);
00223 SOFIAPUBFUN int msg_header_add_param(su_home_t *, msg_common_t *h,
00224                                      char const *param);
00225 SOFIAPUBFUN int msg_header_replace_param(su_home_t *, msg_common_t *h,
00226                                          char const *param);
00227 SOFIAPUBFUN int msg_header_remove_param(msg_common_t *h, char const *name);
00228 
00229 SOFIAPUBFUN char const *msg_header_find_item(msg_common_t const *h,
00230                                              char const *item);
00231 
00232 SOFIAPUBFUN int msg_header_replace_item(su_home_t *, msg_common_t *h,
00233                                         char const *item);
00234 SOFIAPUBFUN int msg_header_remove_item(msg_common_t *h, char const *name);
00235 
00237 SOFIAPUBFUN int msg_list_append_items(su_home_t *home,
00238                                       msg_list_t *k,
00239                                       msg_param_t const items[]);
00240 
00242 SOFIAPUBFUN int msg_list_replace_items(su_home_t *home,
00243                                        msg_list_t *k,
00244                                        msg_param_t const items[]);
00245 
00246 SOFIAPUBFUN int msg_header_join_items(su_home_t *home,
00247                                       msg_common_t *dst,
00248                                       msg_common_t const *src,
00249                                       int duplicate);
00250 
00251 SOFIAPUBFUN issize_t msg_random_token(char token[], isize_t tlen,
00252                                       void const *d, isize_t dlen);
00253 
00254 SOFIAPUBFUN msg_param_t msg_params_find(msg_param_t const pp[],
00255                                         char const *name);
00256 SOFIAPUBFUN msg_param_t *msg_params_find_slot(msg_param_t [],
00257                                               char const *name);
00258 SOFIAPUBFUN int msg_params_add(su_home_t *sh,
00259                                msg_param_t **pp,
00260                                char const *param);
00261 SOFIAPUBFUN int msg_params_cmp(char const * const a[],
00262                                char const * const b[]);
00263 SOFIAPUBFUN int msg_params_replace(su_home_t *,
00264                                    char const * **inout_paramlist,
00265                                    char const *);
00266 SOFIAPUBFUN int msg_params_remove(char const **paramlist,
00267                                   char const *name);
00268 SOFIAPUBFUN size_t msg_params_length(char const * const * params);
00269 
00271 SOFIAPUBFUN char *msg_unquote_dup(su_home_t *home, char const *q)
00272      __attribute__((__malloc__));
00273 
00274 SOFIAPUBFUN char *msg_unquote(char *dst, char const *s);
00275 
00277 SOFIAPUBFUN unsigned long msg_hash_string(char const *id);
00278 
00279 /* Align pointer p for multiple of t (which must be a power of 2) */
00280 #define MSG_ALIGN(p, t) (((uintptr_t)(p) + (t) - 1) & (0 - (uintptr_t)(t)))
00281 #define MSG_STRUCT_SIZE_ALIGN(rv) ((rv) = MSG_ALIGN(rv, sizeof(void *)))
00282 #define MSG_STRUCT_ALIGN(p) ((p) = (void*)MSG_ALIGN(p, sizeof(void *)))
00283 
00284 enum {
00285  msg_n_params = 8,      /* allocation size of parameter string list */
00286 #define MSG_N_PARAMS msg_n_params
00287 };
00288 
00290 #define MSG_HEADER_INIT(h, msg_class, size)                     \
00291   ((void)memset((h), 0, (size)),                                \
00292    (void)(((msg_common_t *)(h))->h_class = (msg_class)),        \
00293    (h))
00294 
00296 #define MSG_HEADER_NONE ((msg_header_t *)-1)
00297 
00298 SOFIA_END_DECLS
00299 
00300 #ifndef MSG_PROTOS_H
00301 #include <sofia-sip/msg_protos.h>
00302 #endif
00303 
00304 #endif 

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