Commit 1c7708f3 authored by jehan's avatar jehan

start body access implementation

parent a3b1d2e1
......@@ -68,6 +68,8 @@ void belle_sip_message_add_header(belle_sip_message_t *msg, belle_sip_header_t*
void belle_sip_message_add_headers(belle_sip_message_t *message, const belle_sip_list_t *header_list);
char *belle_sip_message_to_string(belle_sip_message_t *msg);
char* belle_sip_get_body(belle_sip_message_t *msg,unsigned int* size);
void belle_sip_set_body(belle_sip_message_t *msg,char* bodyy,unsigned int size);
int belle_sip_response_get_status_code(const belle_sip_response_t *response);
void belle_sip_response_set_status_code(belle_sip_response_t *response,int status);
......
......@@ -537,14 +537,11 @@ GET_SET_STRING(belle_sip_header_extension,value);
if (header->opaque) {\
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%sopaque=\"%s\"",border,header->opaque);\
border=", ";\
}\
if (header->qop) {\
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%sqop=%s",border,header->qop);\
border=", ";\
}
struct _belle_sip_header_authorization {
AUTH_BASE
const char* username;
......@@ -607,8 +604,12 @@ int belle_sip_header_authorization_marshal(belle_sip_header_authorization_t* aut
border=", ";
}
if (authorization->nonce_count>0) {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%snc=\"%08i\"",border,authorization->nonce_count);
}
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%snc=%08i",border,authorization->nonce_count);
border=", ";
}
if (authorization->qop) {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%sqop=%s",border,authorization->qop);
}
return current_offset-offset;
}
BELLE_SIP_NEW_HEADER(header_authorization,parameters,"Authorization")
......@@ -671,8 +672,12 @@ int belle_sip_header_www_authenticate_marshal(belle_sip_header_www_authenticate_
border=", ";
}
if (www_authenticate->stale>=0) {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%sstale=\"%s",border,www_authenticate->stale?"true":"false");
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%sstale=%s",border,www_authenticate->stale?"true":"false");
}
if (www_authenticate->qop) {
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%sqop=\"%s\"",border,www_authenticate->qop);
border=", ";
}
return current_offset-offset;
}
BELLE_SIP_NEW_HEADER_INIT(header_www_authenticate,parameters,"WWW-Authenticate",header_www_authenticate)
......
......@@ -83,7 +83,7 @@ struct _belle_sip_object{
};
belle_sip_object_t * _belle_sip_object_new(size_t objsize, belle_sip_object_vptr_t *vptr, int initially_unowed);
int belle_sip_object_marshal(belle_sip_object_t* obj, char* buff,unsigned int offset,size_t buff_size);
#define belle_sip_object_new(_type) (_type*)_belle_sip_object_new(sizeof(_type),(belle_sip_object_vptr_t*)&BELLE_SIP_OBJECT_VPTR_NAME(_type),0)
#define belle_sip_object_new_unowed(_type,destroy)(_type*)_belle_sip_object_new(sizeof(_type),(belle_sip_object_vptr_t*)&BELLE_SIP_OBJECT_VPTR_NAME(_type),1)
......@@ -517,7 +517,9 @@ void belle_sip_client_transaction_add_response(belle_sip_client_transaction_t *t
*/
void belle_sip_response_get_return_hop(belle_sip_response_t *msg, belle_sip_hop_t *hop);
#define IS_TOKEN(token) (strcmp(#token,(const char*)(INPUT->toStringTT(INPUT,LT(1),LT(strlen(#token))))->chars) == 0)
#define IS_TOKEN(token) \
(INPUT->toStringTT(INPUT,LT(1),LT(strlen(#token)))->chars ?\
strcmp(#token,(const char*)(INPUT->toStringTT(INPUT,LT(1),LT(strlen(#token)))->chars)) == 0:0)
char* _belle_sip_str_dup_and_unquote_string(char* quoted_string);
#ifdef __cplusplus
......
......@@ -123,7 +123,7 @@ extension_method
response returns [belle_sip_response_t* ret]
scope { belle_sip_response_t* current; }
@init {$response::current = belle_sip_response_new(); $ret=$response::current; }
: status_line message_header[BELLE_SIP_MESSAGE($response::current)]+ last_crlf=CRLF {*($message_raw::message_length)=0;} /*message_body*/ ;
: status_line message_header[BELLE_SIP_MESSAGE($response::current)]+ last_crlf=CRLF {*($message_raw::message_length)=$last_crlf->user1;} /*message_body*/ ;
status_line
: sip_version
......
......@@ -39,6 +39,8 @@ static void belle_sip_headers_container_delete(headers_container_t *obj){
struct _belle_sip_message {
belle_sip_object_t base;
belle_sip_list_t* header_list;
char* body;
unsigned int body_length;
};
static void belle_sip_message_destroy(belle_sip_message_t *msg){
......@@ -118,6 +120,47 @@ const belle_sip_list_t* belle_sip_message_get_headers(belle_sip_message_t *messa
return headers_container ? headers_container->header_list:NULL;
}
/*
int belle_sip_message_named_headers_marshal(belle_sip_message_t *message, const char* header_name, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset;
belle_sip_list_t* header_list = belle_sip_message_get_headers(message,header_name);
if (!header_list) {
belle_sip_error("headers [%s] not found",header_name);
return 0;
}
for(;header_list!=NULL;header_list=header_list->next){
belle_sip_header_t *h=BELLE_SIP_HEADER(header_list->data);
current_offset+=belle_sip_object_marshal(BELLE_SIP_OBJECT(h),buff,current_offset,buff_size);
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s","\r\n");
}
return current_offset-offset;
}
#define MARSHAL_AND_CHECK_HEADER(header) \
if (current_offset == (current_offset+=(header))) {\
belle_sip_error("missing mandatory header");\
return current_offset;\
} else {\
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s","\r\n");\
}
*/
int belle_sip_headers_marshal(belle_sip_message_t *message, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset;
belle_sip_list_t* headers_list;
belle_sip_list_t* header_list;
for(headers_list=message->header_list;headers_list!=NULL;headers_list=headers_list->next){
for(header_list=((headers_container_t*)(headers_list->data))->header_list
;header_list!=NULL
;header_list=header_list->next) {
belle_sip_header_t *h=BELLE_SIP_HEADER(header_list->data);
current_offset+=belle_sip_object_marshal(BELLE_SIP_OBJECT(h),buff,current_offset,buff_size);
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s","\r\n");
}
}
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s","\r\n");
return current_offset-offset;
}
struct _belle_sip_request {
belle_sip_message_t message;
const char* method;
......@@ -132,7 +175,12 @@ static void belle_sip_request_clone(belle_sip_request_t *request, const belle_si
if (orig->method) request->method=belle_sip_strdup(orig->method);
}
int belle_sip_request_marshal(belle_sip_request_t* request, char* buff,unsigned int offset,unsigned int buff_size) {
unsigned int current_offset=offset;
current_offset+=snprintf(buff+current_offset,buff_size-current_offset,"%s ",belle_sip_request_get_method(request));
current_offset+=belle_sip_uri_marshal(belle_sip_request_get_uri(request),buff,current_offset,buff_size);
current_offset+=snprintf(buff+current_offset,buff_size-current_offset," %s","SIP/2.0\r\n");
current_offset+=belle_sip_headers_marshal(BELLE_SIP_MESSAGE(request),buff,current_offset,buff_size);
return current_offset-offset;
}
BELLE_SIP_NEW(request,message)
BELLE_SIP_PARSE(request)
......@@ -166,9 +214,14 @@ belle_sip_header_t *belle_sip_message_get_header(belle_sip_message_t *msg, const
char *belle_sip_message_to_string(belle_sip_message_t *msg){
return NULL;
return belle_sip_object_to_string(BELLE_SIP_OBJECT(msg));
}
char* belle_sip_get_body(belle_sip_message_t *msg,unsigned int* size) {
return 0;
}
void belle_sip_set_body(belle_sip_message_t *msg,char* bodyy,unsigned int size) {
}
struct _belle_sip_response{
belle_sip_message_t base;
char *sip_version;
......@@ -256,7 +309,14 @@ static void belle_sip_response_clone(belle_sip_response_t *resp, const belle_sip
if (orig->reason_phrase) resp->reason_phrase=belle_sip_strdup(orig->reason_phrase);
}
int belle_sip_response_marshal(belle_sip_response_t *resp, char* buff,unsigned int offset,unsigned int buff_size) {
return 0;
unsigned int current_offset=offset;
current_offset+=snprintf( buff+current_offset
,buff_size-current_offset
,"SIP/2.0 %i %s\r\n"
,belle_sip_response_get_status_code(resp)
,belle_sip_response_get_reason_phrase(resp));
current_offset+=belle_sip_headers_marshal(BELLE_SIP_MESSAGE(resp),buff,current_offset,buff_size);
return current_offset-offset;
}
BELLE_SIP_NEW(response,message);
BELLE_SIP_PARSE(response)
......
......@@ -70,6 +70,10 @@ static void testRegisterMessage(void) {
", uri=\"sip:linphone.net\", response=\"eed376ff7c963441255ec66594e470e7\", algorithm=MD5, cnonce=\"0a4f113b\", qop=auth, nc=00000001\r\n"\
"Content-Length: 0\r\n\r\n";
belle_sip_message_t* message = belle_sip_message_parse(raw_message);
char* encoded_message = belle_sip_object_to_string(BELLE_SIP_OBJECT(message));
belle_sip_object_unref(BELLE_SIP_OBJECT(message));
message = belle_sip_message_parse(encoded_message);
belle_sip_request_t* request = BELLE_SIP_REQUEST(message);
CU_ASSERT_STRING_EQUAL(belle_sip_request_get_method(request),"REGISTER");
CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Expires"));
......@@ -95,6 +99,9 @@ static void testInviteMessage(void) {
"User-Agent: X-Lite 4 release 4.0 stamp 58832\r\n"\
"Content-Length: 230\r\n\r\n";
belle_sip_message_t* message = belle_sip_message_parse(raw_message);
char* encoded_message = belle_sip_object_to_string(BELLE_SIP_OBJECT(message));
belle_sip_object_unref(BELLE_SIP_OBJECT(message));
message = belle_sip_message_parse(encoded_message);
belle_sip_request_t* request = BELLE_SIP_REQUEST(message);
CU_ASSERT_STRING_EQUAL(belle_sip_request_get_method(request),"INVITE");
CU_ASSERT_PTR_NOT_NULL(belle_sip_message_get_header(message,"Contact"));
......@@ -112,6 +119,9 @@ static void test401Response(void) {
"WWW-Authenticate: Digest realm=\"sip.ovh.net\",nonce=\"24212965507cde726e8bc37e04686459\",opaque=\"241b9fb347752f2\",stale=false,algorithm=MD5\r\n"
"Content-Length: 0\r\n\r\n";
belle_sip_message_t* message = belle_sip_message_parse(raw_message);
char* encoded_message = belle_sip_object_to_string(BELLE_SIP_OBJECT(message));
belle_sip_object_unref(BELLE_SIP_OBJECT(message));
message = belle_sip_message_parse(encoded_message);
belle_sip_response_t* response = BELLE_SIP_RESPONSE(message);
CU_ASSERT_EQUAL(belle_sip_response_get_status_code(response),401);
CU_ASSERT_STRING_EQUAL(belle_sip_response_get_reason_phrase(response),"Unauthorized");
......
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