message.h 7.44 KB
Newer Older
1 2 3 4 5 6
/*
	belle-sip - SIP (RFC3261) library.
    Copyright (C) 2010  Belledonne Communications SARL

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
7
    the Free Software Foundation, either version 2 of the License, or
8 9 10 11 12 13 14 15 16 17 18 19 20
    (at your option) any later version.

    This program 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 General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef BELLE_SIP_MESSAGE_H
#define BELLE_SIP_MESSAGE_H

Simon Morlat's avatar
Simon Morlat committed
21
#include "belle-sip/headers.h"
22

23 24
#define BELLE_SIP_MESSAGE(obj)		BELLE_SIP_CAST(obj,belle_sip_message_t)
#define BELLE_SIP_REQUEST(obj)		BELLE_SIP_CAST(obj,belle_sip_request_t)
25 26
#define BELLE_SIP_RESPONSE(obj)		BELLE_SIP_CAST(obj,belle_sip_response_t)

Simon Morlat's avatar
Simon Morlat committed
27 28
BELLE_SIP_BEGIN_DECLS

29
BELLESIP_EXPORT belle_sip_message_t* belle_sip_message_parse(const char* raw);
30 31 32 33 34 35 36
/**
 * Parse sip message from a raw buffer
 * @param [in] buff buffer to be parsed
 * @param [in] buff_length size of the buffer to be parsed
 * @param [out] message_length number of bytes read
 * @return parsed message
 */
37
BELLESIP_EXPORT belle_sip_message_t* belle_sip_message_parse_raw (const char* buff, size_t buff_length,size_t* message_length );
38

39 40


41
BELLESIP_EXPORT int belle_sip_message_is_request(belle_sip_message_t *msg);
42
BELLESIP_EXPORT belle_sip_request_t* belle_sip_request_new(void);
Ghislain MARY's avatar
Ghislain MARY committed
43
BELLESIP_EXPORT belle_sip_request_t* belle_sip_request_parse(const char* raw);
jehan's avatar
jehan committed
44

45
BELLESIP_EXPORT belle_sip_request_t* belle_sip_request_create(belle_sip_uri_t *requri, const char* method,
46 47 48 49 50 51
                                         belle_sip_header_call_id_t *callid,
                                         belle_sip_header_cseq_t *cseq,
                                         belle_sip_header_from_t *from,
                                         belle_sip_header_to_t *to,
                                         belle_sip_header_via_t *via,
                                         int max_forwards);
jehan's avatar
jehan committed
52 53 54



55

jehan's avatar
jehan committed
56
BELLESIP_EXPORT belle_sip_uri_t* belle_sip_request_get_uri(const belle_sip_request_t* request);
Ghislain MARY's avatar
Ghislain MARY committed
57
BELLESIP_EXPORT void belle_sip_request_set_uri(belle_sip_request_t* request, belle_sip_uri_t* uri);
58
BELLESIP_EXPORT const char* belle_sip_request_get_method(const belle_sip_request_t* request);
Ghislain MARY's avatar
Ghislain MARY committed
59
BELLESIP_EXPORT void belle_sip_request_set_method(belle_sip_request_t* request,const char* method);
60
/**
jehan's avatar
jehan committed
61
 * Guess the origin of the received sip message from VIA header (thanks to received/rport)
jehan's avatar
jehan committed
62
 * @param req request to be analyzed
jehan's avatar
jehan committed
63
 * @ return a newly allocated uri
64
 * */
65
BELLESIP_EXPORT belle_sip_uri_t* belle_sip_request_extract_origin(const belle_sip_request_t* req);
Simon Morlat's avatar
Simon Morlat committed
66

67 68 69 70 71 72 73
/**
 * Clone all sip headers + body if any
 * @param  req message to be cloned
 * @return newly allocated request
 */
BELLESIP_EXPORT belle_sip_request_t * belle_sip_request_clone_with_body(const belle_sip_request_t *initial_req);

74 75 76 77 78 79 80 81 82 83 84 85 86
/**
 * returns an absolute uri. A header address cannot have both a sip uri and an absolute uri.
 */
BELLESIP_EXPORT belle_generic_uri_t* belle_sip_request_get_absolute_uri(const belle_sip_request_t* req);
/**
 * set an absolute uri. A header address cannot have both a sip uri and an absolute uri. This function also to uri to NULL
 */
BELLESIP_EXPORT void belle_sip_request_set_absolute_uri(belle_sip_request_t* req, belle_generic_uri_t* uri);





Ghislain MARY's avatar
Ghislain MARY committed
87
BELLESIP_EXPORT int belle_sip_message_is_response(const belle_sip_message_t *msg);
Simon Morlat's avatar
Simon Morlat committed
88

89
BELLESIP_EXPORT belle_sip_header_t *belle_sip_message_get_header(const belle_sip_message_t *msg, const char *header_name);
Simon Morlat's avatar
Simon Morlat committed
90

91
BELLESIP_EXPORT belle_sip_object_t *_belle_sip_message_get_header_by_type_id(const belle_sip_message_t *message, belle_sip_type_id_t id);
Simon Morlat's avatar
Simon Morlat committed
92 93 94 95

#define belle_sip_message_get_header_by_type(msg,header_type)\
	(header_type*)_belle_sip_message_get_header_by_type_id(BELLE_SIP_MESSAGE(msg),BELLE_SIP_TYPE_ID(header_type))

Ghislain MARY's avatar
Ghislain MARY committed
96
BELLESIP_EXPORT const belle_sip_list_t* belle_sip_message_get_headers(const belle_sip_message_t *message,const char* header_name);
97
/**
jehan's avatar
jehan committed
98 99 100 101
 * Get list of all headers present in the message.
 * @param message
 * @return a newly allocated list of belle_sip_header_t
 * */
Ghislain MARY's avatar
Ghislain MARY committed
102
BELLESIP_EXPORT belle_sip_list_t* belle_sip_message_get_all_headers(const belle_sip_message_t *message);
103 104 105

BELLESIP_EXPORT void belle_sip_message_add_first(belle_sip_message_t *msg, belle_sip_header_t* header);

106 107 108 109 110
/**
 * add an header to this message
 * @param msg
 * @param header to add, must be one of header type
 */
111
BELLESIP_EXPORT void belle_sip_message_add_header(belle_sip_message_t *msg, belle_sip_header_t* header);
Simon Morlat's avatar
Simon Morlat committed
112

Ghislain MARY's avatar
Ghislain MARY committed
113
BELLESIP_EXPORT void belle_sip_message_add_headers(belle_sip_message_t *message, const belle_sip_list_t *header_list);
Simon Morlat's avatar
Simon Morlat committed
114

Ghislain MARY's avatar
Ghislain MARY committed
115
BELLESIP_EXPORT void belle_sip_message_set_header(belle_sip_message_t *msg, belle_sip_header_t* header);
116

Ghislain MARY's avatar
Ghislain MARY committed
117
BELLESIP_EXPORT void belle_sip_message_remove_first(belle_sip_message_t *msg, const char *header_name);
118

Ghislain MARY's avatar
Ghislain MARY committed
119
BELLESIP_EXPORT void belle_sip_message_remove_last(belle_sip_message_t *msg, const char *header_name);
120

121
BELLESIP_EXPORT void belle_sip_message_remove_header(belle_sip_message_t *msg, const char *header_name);
122

123 124 125
BELLESIP_EXPORT void belle_sip_message_remove_header_from_ptr(belle_sip_message_t *msg, belle_sip_header_t* header);


Ghislain MARY's avatar
Ghislain MARY committed
126
BELLESIP_EXPORT char *belle_sip_message_to_string(belle_sip_message_t *msg);
127 128 129 130 131

BELLESIP_EXPORT belle_sip_body_handler_t *belle_sip_message_get_body_handler(const belle_sip_message_t *msg);

BELLESIP_EXPORT void belle_sip_message_set_body_handler(belle_sip_message_t *msg, belle_sip_body_handler_t *body_handler);

Sylvain Berfini's avatar
Sylvain Berfini committed
132
BELLESIP_EXPORT const char* belle_sip_message_get_body(belle_sip_message_t *msg);
133

134
BELLESIP_EXPORT size_t belle_sip_message_get_body_size(const belle_sip_message_t *msg);
Simon Morlat's avatar
Simon Morlat committed
135

136
BELLESIP_EXPORT void belle_sip_message_set_body(belle_sip_message_t *msg,const char* body,size_t size);
137

138
BELLESIP_EXPORT void belle_sip_message_assign_body(belle_sip_message_t *msg, char* body, size_t size);
139

140
BELLESIP_EXPORT int belle_sip_response_get_status_code(const belle_sip_response_t *response);
Ghislain MARY's avatar
Ghislain MARY committed
141
BELLESIP_EXPORT void belle_sip_response_set_status_code(belle_sip_response_t *response,int status);
142

143
BELLESIP_EXPORT const char* belle_sip_response_get_reason_phrase(const belle_sip_response_t *response);
Ghislain MARY's avatar
Ghislain MARY committed
144
BELLESIP_EXPORT void belle_sip_response_set_reason_phrase(belle_sip_response_t *response,const char* reason_phrase);
145

Simon Morlat's avatar
Simon Morlat committed
146

147
BELLESIP_EXPORT belle_sip_response_t *belle_sip_response_new(void);
Simon Morlat's avatar
Simon Morlat committed
148

149
BELLESIP_EXPORT belle_sip_response_t *belle_sip_response_create_from_request(belle_sip_request_t *req, int status_code);
jehan's avatar
jehan committed
150
/**
151 152
 * This method takes  received/rport/via value of the reponse and update the contact IP/port accordingly
 * @param response use to extract via/received/rport from top most via.
jehan's avatar
jehan committed
153 154 155
 * @param contact contact to be updated
 * @returns 0 if no error
 * */
Ghislain MARY's avatar
Ghislain MARY committed
156
BELLESIP_EXPORT int belle_sip_response_fix_contact(const belle_sip_response_t* response,belle_sip_header_contact_t* contact);
157

158 159 160 161 162
/**
 * Check for mandatory headers and parameters.
 * If message does not satisfy minimum requirements return FALSE, otherwise return TRUE.
**/
BELLESIP_EXPORT int belle_sip_message_check_headers(const belle_sip_message_t* message);
jehan's avatar
jehan committed
163

jehan's avatar
jehan committed
164 165 166 167 168 169 170
/**
 * check uri components of headers and req uri.
 * return 0 if not compliant
 * */
BELLESIP_EXPORT int belle_sip_request_check_uris_components(const belle_sip_request_t* request);


Simon Morlat's avatar
Simon Morlat committed
171 172
BELLE_SIP_END_DECLS

173 174
#endif