Commit af550943 authored by jehan's avatar jehan
Browse files

add header management at message level

parent d25b05a2
......@@ -63,6 +63,7 @@ typedef enum belle_sip_type_id{
BELLE_SIP_TYPE_ID(belle_sip_header_route_t),
BELLE_SIP_TYPE_ID(belle_sip_header_record_route_t),
BELLE_SIP_TYPE_ID(belle_sip_header_content_length_t),
BELLE_SIP_TYPE_ID(belle_sip_header_t),
belle_sip_type_id_end
}belle_sip_type_id_t;
......
......@@ -26,6 +26,7 @@ typedef struct _belle_sip_response belle_sip_response_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)
belle_sip_message_t* belle_sip_message_parse(const char* raw);
int belle_sip_message_is_request(belle_sip_message_t *msg);
belle_sip_request_t* belle_sip_request_new();
belle_sip_request_t* belle_sip_request_parse(const char* raw);
......@@ -34,6 +35,7 @@ belle_sip_request_t* belle_sip_request_parse(const char* raw);
belle_sip_uri_t* belle_sip_request_get_uri(belle_sip_request_t* request);
void belle_sip_request_set_uri(belle_sip_request_t* request,belle_sip_uri_t* uri);
const char* belle_sip_request_get_method(belle_sip_request_t* request);
......@@ -42,6 +44,12 @@ void belle_sip_request_set_method(belle_sip_request_t* request,const char* metho
int belle_sip_message_is_response(belle_sip_message_t *msg);
belle_sip_header_t *belle_sip_message_get_header_last(belle_sip_message_t *msg, const char *header_name);
/**
* add an header to this message
* @param msg
* @param header to add, must be one of header type
*/
void belle_sip_message_add_header(belle_sip_message_t *msg, belle_sip_object_t* header);
char *belle_sip_message_to_string(belle_sip_message_t *msg);
......
......@@ -27,6 +27,21 @@
#include "belle_sip_messageLexer.h"
#include "belle_sip_internal.h"
/************************
* header
***********************/
struct _belle_sip_header {
belle_sip_object_t base;
const char* name;
};
GET_SET_STRING(belle_sip_header,name);
void belle_sip_header_init(belle_sip_header_t *header) {
belle_sip_object_init_type(header,belle_sip_header_t);
belle_sip_object_init((belle_sip_object_t*)header); /*super*/
}
static void belle_sip_header_destroy(belle_sip_header_t *header){
if (header->name) belle_sip_free((void*)header->name);
}
/************************
* header_address
......
......@@ -30,12 +30,13 @@ options {
message
: request /*| response*/ ;
message returns [belle_sip_message_t* ret]
: request {$ret = BELLE_SIP_MESSAGE($request.ret);}
/*| response*/ ;
request returns [belle_sip_request_t* ret]
scope { belle_sip_request_t* current; }
@init {$request::current = belle_sip_request_new(); $ret=$request::current; }
: request_line message_header+ CRLF message_body ? ;
: request_line message_header[BELLE_SIP_MESSAGE($request::current)]+ CRLF message_body ? ;
request_line
: method {belle_sip_request_set_method($request::current,(const char*)($method.text->chars));}
......@@ -48,27 +49,28 @@ request_line
sip_version
: 'SIP/' DIGIT '.' DIGIT;
message_header
: (/*accept
message_header [belle_sip_message_t* message]
: (/*accept
| accept_encoding
| accept_language
| alert_info
| allow
| authentication_info
| authorization
|*/ header_call_id/*
|*/ header_call_id {belle_sip_message_header_add(message,BELLE_SIP_OBJECT($header_call_id.ret));}/*
| call_info
| contact
| content_disposition
| content_encoding
| content_language*/
| header_content_length
| header_content_type
| header_cseq/*
| header_content_length {belle_sip_message_header_add(message,BELLE_SIP_OBJECT($header_content_length.ret));}
| header_content_type {belle_sip_message_header_add(message,BELLE_SIP_OBJECT($header_content_type.ret));}
| header_cseq {belle_sip_message_header_add(message,BELLE_SIP_OBJECT($header_cseq.ret));}/*
| date
| error_info
| expires*/
| header_from /*
| header_from {belle_sip_message_header_add(message,BELLE_SIP_OBJECT($header_from.ret));}/*
| in_reply_to
| max_forwards
| mime_version
......@@ -78,22 +80,24 @@ message_header
| proxy_authenticate
| proxy_authorization
| proxy_require*/
| header_record_route /*
| header_record_route {belle_sip_message_header_add(message,BELLE_SIP_OBJECT($header_record_route.ret));}/*
| reply_to
| require
| retry_after*/
| header_route /*
| header_route {belle_sip_message_header_add(message,BELLE_SIP_OBJECT($header_route.ret));}/*
| server
| subject
| supported
| timestamp*/
| header_to/*
| header_to {belle_sip_message_header_add(message,BELLE_SIP_OBJECT($header_to.ret));}/*
| unsupported
| user_agent*/
| header_via /*
| header_via {belle_sip_message_header_add(message,BELLE_SIP_OBJECT($header_via.ret));}/*
| warning
| www_authenticate*/
| header_extension_header) CRLF;
| header_extension_header
) CRLF
;
/*
invitem
: 'INVITE' ; //INVITE in caps
......
......@@ -26,6 +26,7 @@ typedef struct _headers_container {
static headers_container_t* belle_sip_message_headers_container_new(const char* name) {
headers_container_t* headers_container = belle_sip_new0(headers_container_t);
headers_container->name= belle_sip_strdup(name);
return NULL; /*FIXME*/
}
struct _belle_sip_message {
......@@ -34,6 +35,8 @@ struct _belle_sip_message {
belle_sip_list_t* headernames_list;
};
BELLE_SIP_PARSE(message)
static int belle_sip_headers_container_comp_func(const headers_container_t *a, const char*b) {
return strcmp(a->name,b);
}
......@@ -47,9 +50,20 @@ headers_container_t* belle_sip_headers_container_get(belle_sip_message_t* messag
, header_name);
return result?(headers_container_t*)(result->data):NULL;
}
void belle_sip_message_add_header(belle_sip_message_t *message,belle_sip_header_t* header) {
void belle_sip_message_header_add(belle_sip_message_t *message,belle_sip_object_t* header) {
// first check if already exist
headers_container_t* headers_container = belle_sip_headers_container_get(message,belle_sip_object_get_name(header));
if (headers_container == NULL) {
headers_container = belle_sip_message_headers_container_new(belle_sip_object_get_name(header));
belle_sip_list_append(message->header_list,headers_container);
}
belle_sip_list_append(headers_container->header_list,header);
}
const belle_sip_list_t* belle_sip_message_get_headers(belle_sip_message_t *message,const char* header_name) {
headers_container_t* headers_container = belle_sip_headers_container_get(message,header_name);
return headers_container ? headers_container->header_list:NULL;
}
struct _belle_sip_request {
belle_sip_message_t message;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment