message.h 5.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
	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
    the Free Software Foundation, either version 3 of the License, or
    (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

22

23 24 25 26
#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)
#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

jehan's avatar
jehan committed
29
belle_sip_message_t* belle_sip_message_parse(const char* raw);
30 31 32 33 34 35 36 37
/**
 * 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
 */
belle_sip_message_t* belle_sip_message_parse_raw (const char* buff, size_t buff_length,size_t* message_length );
38

Simon Morlat's avatar
wip  
Simon Morlat committed
39
int belle_sip_message_is_request(belle_sip_message_t *msg);
jehan's avatar
jehan committed
40 41 42
belle_sip_request_t* belle_sip_request_new();
belle_sip_request_t* belle_sip_request_parse(const char* raw);

43 44 45 46 47 48 49
belle_sip_request_t* belle_sip_request_create(belle_sip_uri_t *requri, const char* method,
                                         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
50 51 52



jehan's avatar
jehan committed
53

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

65
int belle_sip_message_is_response(const belle_sip_message_t *msg);
Simon Morlat's avatar
wip  
Simon Morlat committed
66

67
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
68

Simon Morlat's avatar
Simon Morlat committed
69 70 71 72 73
belle_sip_object_t *_belle_sip_message_get_header_by_type_id(const belle_sip_message_t *message, belle_sip_type_id_t id);

#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))

74
const belle_sip_list_t* belle_sip_message_get_headers(const belle_sip_message_t *message,const char* header_name);
Simon Morlat's avatar
Simon Morlat committed
75

jehan's avatar
jehan committed
76 77 78 79 80
/**
 * add an header to this message
 * @param msg
 * @param header to add, must be one of header type
 */
81
void belle_sip_message_add_header(belle_sip_message_t *msg, belle_sip_header_t* header);
Simon Morlat's avatar
wip  
Simon Morlat committed
82

Simon Morlat's avatar
Simon Morlat committed
83 84
void belle_sip_message_add_headers(belle_sip_message_t *message, const belle_sip_list_t *header_list);

85 86
void belle_sip_message_set_header(belle_sip_message_t *msg, belle_sip_header_t* header);

87 88 89 90 91 92
void belle_sip_message_remove_first(belle_sip_message_t *msg, const char *header_name);

void belle_sip_message_remove_last(belle_sip_message_t *msg, const char *header_name);

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

93
char *belle_sip_message_to_string(belle_sip_message_t *msg);
jehan's avatar
jehan committed
94
const char* belle_sip_message_get_body(belle_sip_message_t *msg);
jehan's avatar
jehan committed
95
void belle_sip_message_set_body(belle_sip_message_t *msg,const char* body,unsigned int size);
jehan's avatar
jehan committed
96 97
/*message keep ownership of the null terminated body buffer
void belle_sip_message_assign_body(belle_sip_message_t *msg,char* body);*/
98

Simon Morlat's avatar
Simon Morlat committed
99
int belle_sip_response_get_status_code(const belle_sip_response_t *response);
100 101 102 103 104
void belle_sip_response_set_status_code(belle_sip_response_t *response,int status);

const char* belle_sip_response_get_reason_phrase(const belle_sip_response_t *response);
void belle_sip_response_set_reason_phrase(belle_sip_response_t *response,const char* reason_phrase);

Simon Morlat's avatar
Simon Morlat committed
105

Simon Morlat's avatar
Simon Morlat committed
106
belle_sip_response_t *belle_sip_response_new(void);
Simon Morlat's avatar
Simon Morlat committed
107

108
belle_sip_response_t *belle_sip_response_create_from_request(belle_sip_request_t *req, int status_code);
jehan's avatar
jehan committed
109 110 111 112 113 114 115
/**
 * This method takes the received rport value of the reponse and update the contact IP/port accordingly
 * @param response use to extract received/rport from top most via.
 * @param contact contact to be updated
 * @returns 0 if no error
 * */
int belle_sip_response_fix_contact(const belle_sip_response_t* response,belle_sip_header_contact_t* contact);
jehan's avatar
jehan committed
116

jehan's avatar
jehan committed
117

Simon Morlat's avatar
Simon Morlat committed
118 119
BELLE_SIP_END_DECLS

120 121
#endif