1 /* 2 The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 3 Copyright (C) 2001-2020 Aymeric MOIZARD amoizard@antisip.com 4 5 This library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Lesser General Public 7 License as published by the Free Software Foundation; either 8 version 2.1 of the License, or (at your option) any later version. 9 10 This library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Lesser General Public License for more details. 14 15 You should have received a copy of the GNU Lesser General Public 16 License along with this library; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 */ 19 20 #ifndef _OSIP_VIA_H_ 21 #define _OSIP_VIA_H_ 22 23 #include <osipparser2/osip_list.h> 24 25 /** 26 * @file osip_via.h 27 * @brief oSIP osip_via header definition. 28 */ 29 30 /** 31 * @defgroup oSIP_VIA oSIP via header definition. 32 * @ingroup oSIP_HEADERS 33 * @{ 34 */ 35 36 /** 37 * Structure for Via headers. 38 * @var osip_via_t 39 */ 40 typedef struct osip_via osip_via_t; 41 42 /** 43 * Definition of the Via header. 44 * @struct osip_via 45 */ 46 struct osip_via { 47 char *version; /**< SIP Version */ 48 char *protocol; /**< Protocol used by SIP Agent */ 49 char *host; /**< Host where to send answers */ 50 char *port; /**< Port where to send answers */ 51 char *comment; /**< Comments about SIP Agent */ 52 osip_list_t via_params; /**< Via parameters */ 53 }; 54 55 #ifdef __cplusplus 56 extern "C" { 57 #endif 58 59 /** 60 * Allocate a Via element. 61 * @param header The element to work on. 62 */ 63 int osip_via_init(osip_via_t **header); 64 /** 65 * Free a Via element. 66 * @param header The element to work on. 67 */ 68 void osip_via_free(osip_via_t *header); 69 /** 70 * Parse a Via element. 71 * @param header The element to work on. 72 * @param hvalue The string to parse. 73 */ 74 int osip_via_parse(osip_via_t *header, const char *hvalue); 75 /** 76 * Get a string representation of a Via element. 77 * @param header The element to work on. 78 * @param dest A pointer on the new allocated string. 79 */ 80 int osip_via_to_str(const osip_via_t *header, char **dest); 81 /** 82 * Clone a Via element. 83 * @param header The element to work on. 84 * @param dest A pointer on the copy of the element. 85 */ 86 int osip_via_clone(const osip_via_t *header, osip_via_t **dest); 87 /** 88 * Set the SIP version in the Via element. 89 * @param header The element to work on. 90 * @param value The value of the element. 91 */ 92 void via_set_version(osip_via_t *header, char *value); 93 #define osip_via_set_version via_set_version 94 /** 95 * Get the SIP version from a Via header. 96 * @param header The element to work on. 97 */ 98 char *via_get_version(osip_via_t *header); 99 #define osip_via_get_version via_get_version 100 /** 101 * Set the protocol in the Via element. 102 * @param header The element to work on. 103 * @param value The value of the element. 104 */ 105 void via_set_protocol(osip_via_t *header, char *value); 106 #define osip_via_set_protocol via_set_protocol 107 /** 108 * Get the protocol from a Via header. 109 * @param header The element to work on. 110 */ 111 char *via_get_protocol(osip_via_t *header); 112 #define osip_via_get_protocol via_get_protocol 113 /** 114 * Set the host in the Via element. 115 * @param header The element to work on. 116 * @param value The value of the element. 117 */ 118 void via_set_host(osip_via_t *header, char *value); 119 #define osip_via_set_host via_set_host 120 /** 121 * Get the host from a Via header. 122 * @param header The element to work on. 123 */ 124 char *via_get_host(osip_via_t *header); 125 #define osip_via_get_host via_get_host 126 /** 127 * Set the port in the Via element. 128 * @param header The element to work on. 129 * @param value The value of the element. 130 */ 131 void via_set_port(osip_via_t *header, char *value); 132 #define osip_via_set_port via_set_port 133 /** 134 * Get the port from a Via header. 135 * @param header The element to work on. 136 */ 137 char *via_get_port(osip_via_t *header); 138 #define osip_via_get_port via_get_port 139 /** 140 * Set the comment in the Via element. 141 * @param header The element to work on. 142 * @param value The value of the element. 143 */ 144 void via_set_comment(osip_via_t *header, char *value); 145 #define osip_via_set_comment via_set_comment 146 /** 147 * Get the comment from a Via header. 148 * @param header The element to work on. 149 */ 150 char *via_get_comment(osip_via_t *header); 151 #define osip_via_get_comment via_get_comment 152 153 /** 154 * Allocate and add a hidden parameter element in a list. 155 * @param header The element to work on. 156 */ 157 #define osip_via_set_hidden(header) osip_generic_param_add((&(header)->via_params), osip_strdup("hidden"), NULL) 158 /** 159 * Allocate and add a ttl parameter element in a list. 160 * @param header The element to work on. 161 * @param value The token value. 162 */ 163 #define osip_via_set_ttl(header, value) osip_generic_param_add((&(header)->via_params), osip_strdup("ttl"), value) 164 /** 165 * Allocate and add a maddr parameter element in a list. 166 * @param header The element to work on. 167 * @param value The token value. 168 */ 169 #define osip_via_set_maddr(header, value) osip_generic_param_add((&(header)->via_params), osip_strdup("maddr"), value) 170 /** 171 * Allocate and add a received parameter element in a list. 172 * @param header The element to work on. 173 * @param value The token value. 174 */ 175 #define osip_via_set_received(header, value) osip_generic_param_add((&(header)->via_params), osip_strdup("received"), value) 176 /** 177 * Allocate and add a branch parameter element in a list. 178 * @param header The element to work on. 179 * @param value The token value. 180 */ 181 #define osip_via_set_branch(header, value) osip_generic_param_add((&(header)->via_params), osip_strdup("branch"), value) 182 183 /** 184 * Allocate and add a generic parameter element in a list. 185 * @param header The element to work on. 186 * @param name The token name. 187 * @param value The token value. 188 */ 189 #define osip_via_param_add(header, name, value) osip_generic_param_add((&(header)->via_params), name, value) 190 /** 191 * Find a header parameter in a Via element. 192 * @param header The element to work on. 193 * @param name The token name to search. 194 * @param dest A pointer on the element found. 195 */ 196 #define osip_via_param_get_byname(header, name, dest) osip_generic_param_get_byname((&(header)->via_params), name, dest) 197 198 /** 199 * Check if the Via headers match. 200 * NOTE: THIS IS AN INTERNAL METHOD ONLY 201 * @param via1 The first Via header. 202 * @param via2 The second Via header. 203 */ 204 int osip_via_match(osip_via_t *via1, osip_via_t *via2); 205 206 #ifdef __cplusplus 207 } 208 #endif 209 210 /** @} */ 211 212 #endif 213