|
libosip 3.6.0
|
00001 /* 00002 The oSIP library implements the Session Initiation Protocol (SIP -rfc3261-) 00003 Copyright (C) 2001,2002,2003,2004,2005,2006,2007 Aymeric MOIZARD jack@atosc.org 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2.1 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 */ 00019 00020 00021 #ifndef _OSIP_MESSAGE_H_ 00022 #define _OSIP_MESSAGE_H_ 00023 00024 #include <osipparser2/osip_const.h> 00025 #include <osipparser2/osip_headers.h> 00026 #include <osipparser2/osip_body.h> 00027 00041 #ifdef __cplusplus 00042 extern "C" { 00043 #endif 00044 00049 typedef struct osip_message osip_message_t; 00050 00055 struct osip_message { 00056 char *sip_version; 00057 osip_uri_t *req_uri; 00058 char *sip_method; 00060 int status_code; 00061 char *reason_phrase; 00063 #ifndef MINISIZE 00064 osip_list_t accepts; 00065 osip_list_t accept_encodings; 00066 osip_list_t accept_languages; 00067 osip_list_t alert_infos; 00068 osip_list_t allows; 00069 osip_list_t authentication_infos; 00071 #endif 00072 osip_list_t authorizations; 00073 osip_call_id_t *call_id; 00074 #ifndef MINISIZE 00075 osip_list_t call_infos; 00076 #endif 00077 osip_list_t contacts; 00078 #ifndef MINISIZE 00079 osip_list_t content_encodings; 00081 #endif 00082 osip_content_length_t *content_length; 00084 osip_content_type_t *content_type; 00085 osip_cseq_t *cseq; 00086 #ifndef MINISIZE 00087 osip_list_t error_infos; 00088 #endif 00089 osip_from_t *from; 00090 osip_mime_version_t *mime_version; 00092 osip_list_t proxy_authenticates; 00094 #ifndef MINISIZE 00095 osip_list_t proxy_authentication_infos; 00097 #endif 00098 osip_list_t proxy_authorizations; 00100 osip_list_t record_routes; 00101 osip_list_t routes; 00102 osip_to_t *to; 00103 osip_list_t vias; 00104 osip_list_t www_authenticates; 00107 osip_list_t headers; 00109 osip_list_t bodies; 00111 /* 00112 1: structure and buffer "message" are identical. 00113 2: buffer "message" is not up to date with the structure info (call osip_message_to_str to update it). 00114 */ 00115 int message_property; 00116 char *message; 00117 size_t message_length; 00119 void *application_data; 00120 }; 00121 00122 #ifndef SIP_MESSAGE_MAX_LENGTH 00123 00126 #define SIP_MESSAGE_MAX_LENGTH 4000 00127 #endif 00128 00129 #ifndef BODY_MESSAGE_MAX_SIZE 00130 00133 #define BODY_MESSAGE_MAX_SIZE 4000 00134 #endif 00135 00140 int osip_message_init(osip_message_t ** sip); 00145 void osip_message_free(osip_message_t * sip); 00152 int osip_message_parse(osip_message_t * sip, const char *buf, size_t length); 00159 int osip_message_parse_sipfrag(osip_message_t * sip, const char *buf, 00160 size_t length); 00167 int osip_message_to_str(osip_message_t * sip, char **dest, 00168 size_t * message_length); 00176 int osip_message_to_str_sipfrag(osip_message_t * sip, char **dest, 00177 size_t * message_length); 00183 int osip_message_clone(const osip_message_t * sip, osip_message_t ** dest); 00184 00190 void osip_message_set_reason_phrase(osip_message_t * sip, char *reason); 00195 char *osip_message_get_reason_phrase(const osip_message_t * sip); 00201 void osip_message_set_status_code(osip_message_t * sip, int statuscode); 00206 int osip_message_get_status_code(const osip_message_t * sip); 00212 void osip_message_set_method(osip_message_t * sip, char *method); 00217 char *osip_message_get_method(const osip_message_t * sip); 00223 void osip_message_set_version(osip_message_t * sip, char *version); 00228 char *osip_message_get_version(const osip_message_t * sip); 00234 void osip_message_set_uri(osip_message_t * sip, osip_uri_t * uri); 00239 osip_uri_t *osip_message_get_uri(const osip_message_t * sip); 00240 00241 00242 /* 00243 * These are helpfull MACROs to test messages type. 00244 */ 00249 #define MSG_IS_RESPONSE(msg) ((msg)->status_code!=0) 00250 00254 #define MSG_IS_REQUEST(msg) ((msg)->status_code==0) 00255 00260 #define MSG_IS_INVITE(msg) (MSG_IS_REQUEST(msg) && \ 00261 0==strcmp((msg)->sip_method,"INVITE")) 00262 00266 #define MSG_IS_ACK(msg) (MSG_IS_REQUEST(msg) && \ 00267 0==strcmp((msg)->sip_method,"ACK")) 00268 00272 #define MSG_IS_REGISTER(msg) (MSG_IS_REQUEST(msg) && \ 00273 0==strcmp((msg)->sip_method,"REGISTER")) 00274 00278 #define MSG_IS_BYE(msg) (MSG_IS_REQUEST(msg) && \ 00279 0==strcmp((msg)->sip_method,"BYE")) 00280 00284 #define MSG_IS_OPTIONS(msg) (MSG_IS_REQUEST(msg) && \ 00285 0==strcmp((msg)->sip_method,"OPTIONS")) 00286 00290 #define MSG_IS_INFO(msg) (MSG_IS_REQUEST(msg) && \ 00291 0==strcmp((msg)->sip_method,"INFO")) 00292 00296 #define MSG_IS_CANCEL(msg) (MSG_IS_REQUEST(msg) && \ 00297 0==strcmp((msg)->sip_method,"CANCEL")) 00298 00302 #define MSG_IS_REFER(msg) (MSG_IS_REQUEST(msg) && \ 00303 0==strcmp((msg)->sip_method,"REFER")) 00304 00308 #define MSG_IS_NOTIFY(msg) (MSG_IS_REQUEST(msg) && \ 00309 0==strcmp((msg)->sip_method,"NOTIFY")) 00310 00315 #define MSG_IS_SUBSCRIBE(msg) (MSG_IS_REQUEST(msg) && \ 00316 0==strcmp((msg)->sip_method,"SUBSCRIBE")) 00317 00321 #define MSG_IS_MESSAGE(msg) (MSG_IS_REQUEST(msg) && \ 00322 0==strcmp((msg)->sip_method,"MESSAGE")) 00323 00327 #define MSG_IS_PRACK(msg) (MSG_IS_REQUEST(msg) && \ 00328 0==strcmp((msg)->sip_method,"PRACK")) 00329 00330 00335 #define MSG_IS_UPDATE(msg) (MSG_IS_REQUEST(msg) && \ 00336 0==strcmp((msg)->sip_method,"UPDATE")) 00337 00342 #define MSG_IS_PUBLISH(msg) (MSG_IS_REQUEST(msg) && \ 00343 0==strcmp((msg)->sip_method,"PUBLISH")) 00344 00345 00350 #define MSG_IS_STATUS_1XX(msg) ((msg)->status_code >= 100 && \ 00351 (msg)->status_code < 200) 00352 00356 #define MSG_IS_STATUS_2XX(msg) ((msg)->status_code >= 200 && \ 00357 (msg)->status_code < 300) 00358 00362 #define MSG_IS_STATUS_3XX(msg) ((msg)->status_code >= 300 && \ 00363 (msg)->status_code < 400) 00364 00368 #define MSG_IS_STATUS_4XX(msg) ((msg)->status_code >= 400 && \ 00369 (msg)->status_code < 500) 00370 00374 #define MSG_IS_STATUS_5XX(msg) ((msg)->status_code >= 500 && \ 00375 (msg)->status_code < 600) 00376 00380 #define MSG_IS_STATUS_6XX(msg) ((msg)->status_code >= 600 && \ 00381 (msg)->status_code < 700) 00382 00387 #define MSG_TEST_CODE(msg,code) (MSG_IS_RESPONSE(msg) && \ 00388 (code)==(msg)->status_code) 00389 00394 #define MSG_IS_RESPONSE_FOR(msg,requestname) (MSG_IS_RESPONSE(msg) && \ 00395 0==strcmp((msg)->cseq->method,(requestname))) 00396 00397 00402 #define osip_generic_param_init(GP) osip_uri_param_init(GP) 00403 00407 #define osip_generic_param_free(GP) osip_uri_param_free(GP) 00408 00414 #define osip_generic_param_set(GP, NAME, VALUE) osip_uri_param_set(GP, NAME, VALUE) 00415 00420 #define osip_generic_param_clone osip_uri_param_clone 00421 #ifndef DOXYGEN 00422 /* 00423 * Free a list of a generic parameter element. 00424 * @param LIST The list of generic parameter element to free. 00425 */ 00426 #define osip_generic_param_freelist(LIST) osip_uri_param_freelist(LIST) 00427 #endif 00428 00434 #define osip_generic_param_add(LIST,NAME,VALUE) osip_uri_param_add(LIST,NAME,VALUE) 00435 00441 #define osip_generic_param_get_byname(LIST,NAME,DEST) osip_uri_param_get_byname(LIST,NAME,DEST) 00442 00448 void osip_generic_param_set_name(osip_generic_param_t * generic_param, 00449 char *name); 00454 char *osip_generic_param_get_name(const osip_generic_param_t * generic_param); 00460 void osip_generic_param_set_value(osip_generic_param_t * generic_param, 00461 char *value); 00466 char *osip_generic_param_get_value(const osip_generic_param_t * generic_param); 00467 00468 00475 int osip_message_get_knownheaderlist(osip_list_t * header_list, 00476 int pos, void **dest); 00477 00481 #ifdef __cplusplus 00482 } 00483 #endif 00484 #endif
1.7.3