Commit 0b4385d1 authored by Simon Morlat's avatar Simon Morlat

add a casting mechanism, start implementation of transactions

parent 5669d5d6
......@@ -4,6 +4,8 @@ bellesip_HEADERS=\
uri.h \
list.h \
mainloop.h \
transaction.h \
message.h \
belle-sip.h
EXTRA_DIST=$(bellesip_HEADERS)
......@@ -18,10 +18,36 @@
#ifndef BELLE_SIP_H
#define BELLE_SIP_H
#include <stdlib.h>
#define BELLE_SIP_MAGIC(_type) _type##_magic
typedef enum belle_sip_magic{
belle_sip_magic_first=0x32445191,
BELLE_SIP_MAGIC(belle_sip_transaction_t),
BELLE_SIP_MAGIC(belle_sip_server_transaction_t),
BELLE_SIP_MAGIC(belle_sip_client_transaction_t),
belle_sip_magic_end
}belle_sip_magic_t;
#define BELLE_SIP_IMPLEMENT_CAST(_type) \
_type *_type##_cast(void *obj, const char *file, int line){ \
if (((_type*)obj)->magic==BELLE_SIP_MAGIC(_type)) return (_type*)obj; \
belle_sip_fatal("Bad cast to "#_type " at %s:%i", file, line);\
return NULL; \
}
#define BELLE_SIP_DECLARE_CAST(_type)\
_type *_type##_cast(void *obj, const char *file, int line);
#define BELLE_SIP_CAST(obj,_type) _type##_cast(obj, __FILE__, __LINE__)
#include "belle-sip/list.h"
#include "belle-sip/mainloop.h"
#include "belle-sip/uri.h"
#include "belle-sip/message.h"
#include "belle-sip/transaction.h"
#undef TRUE
#define TRUE 1
......
/*
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
typedef struct belle_sip_message bellesip_message_t;
typedef struct belle_sip_request belle_sip_request_t;
typedef struct belle_sip_response belle_sip_response_t;
#endif
/*
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_TRANSACTION_H
#define BELLE_SIP_TRANSACTION_H
typedef struct belle_sip_transaction belle_sip_transaction_t;
typedef struct belle_sip_server_transaction belle_sip_server_transaction_t;
typedef struct belle_sip_client_transaction belle_sip_client_transaction_t;
typedef enum belle_sip_transaction_state{
BELLE_SIP_TRANSACTION_CALLING,
BELLE_SIP_TRANSACTION_COMPLETED,
BELLE_SIP_TRANSACTION_CONFIRMED,
BELLE_SIP_TRANSACTION_PROCEEDING,
BELLE_SIP_TRANSACTION_TRYING,
BELLE_SIP_TRANSACTION_TERMINATED
}belle_sip_transaction_state_t;
void *belle_sip_transaction_get_application_data(const belle_sip_transaction_t *t);
void belle_sip_transaction_set_application_data(belle_sip_transaction_t *t, void *data);
const char *belle_sip_transaction_get_branch_id(const belle_sip_transaction_t *t);
belle_sip_transaction_state_t belle_sip_transaction_get_state(const belle_sip_transaction_t *t);
void belle_sip_transaction_terminate(belle_sip_transaction_t *t);
belle_sip_request_t *belle_sip_transaction_get_request(belle_sip_transaction_t *t);
void belle_sip_server_transaction_send_response(belle_sip_server_transaction_t *t);
belle_sip_request_t * belle_sip_client_transaction_create_cancel(belle_sip_client_transaction_t *t);
void belle_sip_client_transaction_send_request(belle_sip_client_transaction_t *t);
BELLE_SIP_DECLARE_CAST(belle_sip_transaction_t);
BELLE_SIP_DECLARE_CAST(belle_sip_client_transaction_t);
BELLE_SIP_DECLARE_CAST(belle_sip_server_transaction_t);
#define BELLE_SIP_TRANSACTION(t) BELLE_SIP_CAST(t,belle_sip_transaction_t)
#define BELLE_SIP_SERVER_TRANSACTION(t) BELLE_SIP_CAST(t,belle_sip_server_transaction_t)
#define BELLE_SIP_CLIENT_TRANSACTION(t) BELLE_SIP_CAST(t,belle_sip_client_transaction_t)
/*to be moved out when belle_sip_provider_t is implemented:*/
belle_sip_client_transaction_t * belle_sip_client_transaction_new(belle_sip_request_t *req);
belle_sip_server_transaction_t * belle_sip_server_transaction_new(belle_sip_request_t *req);
#endif
......@@ -24,7 +24,8 @@ lib_LTLIBRARIES=libbellesip.la
libbellesip_la_SOURCES=belle_sip_uri_impl.c \
belle_sip_utils.c belle_sip_internal.h \
belle_sip_loop.c \
belle_sip_resolver.c belle_sip_resolver.h
belle_sip_resolver.c belle_sip_resolver.h \
transaction.c
libbellesip_la_CFLAGS=$(STRICT_OPTIONS)
......
/*
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/>.
*/
#include "belle_sip_internal.h"
struct belle_sip_transaction{
belle_sip_magic_t magic;
char *branch_id;
belle_sip_transaction_state_t state;
void *appdata;
belle_sip_request_t *request;
};
struct belle_sip_server_transaction{
belle_sip_transaction_t base;
belle_sip_magic_t magic;
};
struct belle_sip_client_transaction{
belle_sip_transaction_t base;
belle_sip_magic_t magic;
};
BELLE_SIP_IMPLEMENT_CAST(belle_sip_transaction_t);
BELLE_SIP_IMPLEMENT_CAST(belle_sip_server_transaction_t);
BELLE_SIP_IMPLEMENT_CAST(belle_sip_client_transaction_t);
void *belle_sip_transaction_get_application_data(const belle_sip_transaction_t *t){
return t->appdata;
}
void belle_sip_transaction_set_application_data(belle_sip_transaction_t *t, void *data){
t->appdata=data;
}
const char *belle_sip_transaction_get_branch_id(const belle_sip_transaction_t *t){
return t->branch_id;
}
belle_sip_transaction_state_t belle_sip_transaction_get_state(const belle_sip_transaction_t *t){
return t->state;
}
void belle_sip_transaction_terminate(belle_sip_transaction_t *t){
}
belle_sip_request_t *belle_sip_transaction_get_request(belle_sip_transaction_t *t){
return t->request;
}
void belle_sip_server_transaction_send_response(belle_sip_server_transaction_t *t){
}
belle_sip_request_t * belle_sip_client_transaction_create_cancel(belle_sip_client_transaction_t *t){
return NULL;
}
void belle_sip_client_transaction_send_request(belle_sip_client_transaction_t *t){
}
static void belle_sip_transaction_init(belle_sip_transaction_t *t, belle_sip_request_t *req){
t->magic=BELLE_SIP_MAGIC(belle_sip_transaction_t);
t->request=req;
}
belle_sip_client_transaction_t * belle_sip_client_transaction_new(belle_sip_request_t *req){
belle_sip_client_transaction_t *t=belle_sip_new0(belle_sip_client_transaction_t);
belle_sip_transaction_init((belle_sip_transaction_t*)t,req);
t->magic=BELLE_SIP_MAGIC(belle_sip_client_transaction_t);
return t;
}
belle_sip_server_transaction_t * belle_sip_server_transaction_new(belle_sip_request_t *req){
belle_sip_server_transaction_t *t=belle_sip_new0(belle_sip_server_transaction_t);
belle_sip_transaction_init((belle_sip_transaction_t*)t,req);
t->magic=BELLE_SIP_MAGIC(belle_sip_server_transaction_t);
return t;
}
if BUILD_TESTS
noinst_PROGRAMS=belle_sip_uri_tester
noinst_PROGRAMS=belle_sip_uri_tester cast_test
belle_sip_uri_tester_SOURCES=belle_sip_uri_tester.c
cast_test_SOURCES=cast_test.c
INCLUDES=-I$(top_srcdir)/include
LDADD=$(top_builddir)/src/libbellesip.la -lcunit
AM_CFLAGS=$(STRICT_OPTIONS)
endif
/*
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/>.
*/
#include <stdio.h>
#include "belle-sip/belle-sip.h"
int main(int argc, char *argv[]){
belle_sip_server_transaction_t *st=belle_sip_server_transaction_new(NULL);
belle_sip_client_transaction_t *ct=belle_sip_client_transaction_new(NULL);
belle_sip_transaction_t *t;
printf("Casting belle_sip_server_transaction_t to belle_sip_transaction_t\n");
t=BELLE_SIP_TRANSACTION(st);
printf("Ok.\n");
printf("Casting belle_sip_client_transaction_t to belle_sip_transaction_t\n");
t=BELLE_SIP_TRANSACTION(ct);
printf("Ok.\n");
printf("Casting belle_sip_server_transaction_t to belle_sip_client_transaction_t\n");
ct=BELLE_SIP_CLIENT_TRANSACTION(st);
printf("Ooops we should have aborted before.\n");
return 0;
}
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