diff options
Diffstat (limited to 'tinySIP/src/api')
-rw-r--r-- | tinySIP/src/api/tsip_api_common.c | 134 | ||||
-rw-r--r-- | tinySIP/src/api/tsip_api_invite.c | 300 | ||||
-rw-r--r-- | tinySIP/src/api/tsip_api_message.c | 134 | ||||
-rw-r--r-- | tinySIP/src/api/tsip_api_options.c | 133 | ||||
-rw-r--r-- | tinySIP/src/api/tsip_api_publish.c | 159 | ||||
-rw-r--r-- | tinySIP/src/api/tsip_api_register.c | 166 | ||||
-rw-r--r-- | tinySIP/src/api/tsip_api_subscribe.c | 160 |
7 files changed, 1186 insertions, 0 deletions
diff --git a/tinySIP/src/api/tsip_api_common.c b/tinySIP/src/api/tsip_api_common.c new file mode 100644 index 0000000..2bd5e61 --- /dev/null +++ b/tinySIP/src/api/tsip_api_common.c @@ -0,0 +1,134 @@ +/*
+* Copyright (C) 2009-2010 Mamadou Diop.
+*
+* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
+*
+* This file is part of Open Source Doubango Framework.
+*
+* DOUBANGO 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.
+*
+* DOUBANGO 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 DOUBANGO.
+*
+*/
+
+/**@file tsip_api_common.c
+ * @brief Public common functions.
+ *
+ * @author Mamadou Diop <diopmamadou(at)doubango.org>
+ *
+ * @date Created: Sat Nov 8 16:54:58 2009 mdiop
+ */
+#include "tinysip/api/tsip_api_common.h"
+
+#include "tinysip/tsip_action.h"
+
+#include "tsk_runnable.h"
+#include "tsk_debug.h"
+
+/* Internal functions */
+extern tsip_action_t* _tsip_action_create(tsip_action_type_t type, va_list* app);
+/* Local functions */
+int _tsip_action_ANY(const tsip_ssession_handle_t *ss, tsip_action_type_t type, va_list* app);
+
+/* internal function used to execute any user action
+* can only handle session with dialogs */
+int _tsip_action_ANY(const tsip_ssession_handle_t *ss, tsip_action_type_t type, va_list* app)
+{
+ int ret = -1;
+ tsip_action_t* action;
+ const tsip_ssession_t* _ss;
+
+ /* Checks for validity */
+ if(!(_ss = ss) || !_ss->stack){
+ TSK_DEBUG_ERROR("Invalid parameter.");
+ return ret;
+ }
+
+ /* Checks if the stack has been started */
+ if(!TSK_RUNNABLE(_ss->stack)->started){
+ TSK_DEBUG_ERROR("Stack not started.");
+ return -2;
+ }
+
+ /* execute action */
+ if((action = _tsip_action_create(type, app))){
+ ret = tsip_ssession_handle(_ss, action);
+ TSK_OBJECT_SAFE_FREE(action);
+ }
+ return ret;
+}
+
+/**@ingroup tsip_action_group
+* Rejects an incoming request.
+* @param ss The SIP Session managing the dialog on which the request has been received.
+* @param ... Any TSIP_ACTION_SET_*() macros. e.g. @ref TSIP_ACTION_SET_HEADER().
+* MUST always ends with @ref TSIP_ACTION_SET_NULL().
+* @retval Zero if succeed and non-zero error code otherwise.
+*/
+int tsip_action_REJECT(const tsip_ssession_handle_t *ss, ...)
+{
+ int ret = -1;
+ va_list ap;
+
+ va_start(ap, ss);
+ if((ret = _tsip_action_ANY(ss, tsip_atype_reject, &ap))){
+ TSK_DEBUG_ERROR("Reject() failed.");
+ }
+ va_end(ap);
+
+ return ret;
+}
+
+/**@ingroup tsip_action_group
+* Hangs up a session.
+* @param ss The SIP Session to hang-up. Will send an unREGISTER or unSUBSCRIBE or unPUBLISH or
+* BYE etc depending on the type of the SIP dialog managed by the session.
+* @param ... Any TSIP_ACTION_SET_*() macros. e.g. @ref TSIP_ACTION_SET_HEADER().
+* MUST always ends with @ref TSIP_ACTION_SET_NULL().
+* @retval Zero if succeed and non-zero error code otherwise.
+*/
+int tsip_action_HANGUP(const tsip_ssession_handle_t *ss, ...)
+{
+ int ret = -1;
+ va_list ap;
+
+ va_start(ap, ss);
+ if((ret = _tsip_action_ANY(ss, tsip_atype_hangup, &ap))){
+ TSK_DEBUG_ERROR("Hang-up() failed.");
+ }
+ va_end(ap);
+
+ return ret;
+}
+
+/**@ingroup tsip_action_group
+* Accepts an incoming request.
+* @param ss The SIP Session managing the dialog on which the request has been received.
+* @param ... Any TSIP_ACTION_SET_*() macros. e.g. @ref TSIP_ACTION_SET_HEADER().
+* MUST always ends with @ref TSIP_ACTION_SET_NULL().
+* @retval Zero if succeed and non-zero error code otherwise.
+*/
+int tsip_action_ACCEPT(const tsip_ssession_handle_t *ss, ...)
+{
+ int ret = -1;
+ va_list ap;
+
+ va_start(ap, ss);
+ if((ret = _tsip_action_ANY(ss, tsip_atype_accept, &ap))){
+ TSK_DEBUG_ERROR("Accept() failed.");
+ }
+ va_end(ap);
+
+ return ret;
+}
+
+
diff --git a/tinySIP/src/api/tsip_api_invite.c b/tinySIP/src/api/tsip_api_invite.c new file mode 100644 index 0000000..831b46b --- /dev/null +++ b/tinySIP/src/api/tsip_api_invite.c @@ -0,0 +1,300 @@ +/* +* Copyright (C) 2009-2010 Mamadou Diop. +* +* Contact: Mamadou Diop <diopmamadou(at)doubango.org> +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO 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. +* +* DOUBANGO 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 DOUBANGO. +* +*/ + +/**@file tsip_api_invite.c + * @brief Public short messaging (INVITE) functions. + * + * @author Mamadou Diop <diopmamadou(at)doubango.org> + * + * @date Created: Sat Nov 8 16:54:58 2009 mdiop + */ +#include "tinysip/api/tsip_api_invite.h" + +#include "tinysip/dialogs/tsip_dialog_layer.h" +#include "tinysip/dialogs/tsip_dialog_invite.h" + +#include "tinysip/tsip_action.h" +#include "tsip.h" + +#include "tsk_runnable.h" +#include "tsk_debug.h" + +#define TSIP_INVITE_EVENT_CREATE( type) tsk_object_new(tsip_invite_event_def_t, type) + +extern tsip_action_t* _tsip_action_create(tsip_action_type_t type, va_list* app); +extern int _tsip_action_ANY(const tsip_ssession_handle_t *ss, tsip_action_type_t type, va_list* app); + +int tsip_invite_event_signal(tsip_invite_event_type_t type, tsip_ssession_handle_t* ss, short status_code, const char *phrase, const tsip_message_t* sipmessage) +{ + tsip_invite_event_t* sipevent = TSIP_INVITE_EVENT_CREATE(type); + tsip_event_init(TSIP_EVENT(sipevent), ss, status_code, phrase, sipmessage, tsip_event_invite); + + TSK_RUNNABLE_ENQUEUE_OBJECT(TSK_RUNNABLE(TSIP_SSESSION(ss)->stack), sipevent); + + return 0; +} + +int tsip_action_INVITE(const tsip_ssession_handle_t *ss, tmedia_type_t type, ...) +{ + const tsip_ssession_t* _ss; + va_list ap; + tsip_action_t* action; + tsip_dialog_t* dialog; + int ret = -1; + + if(!(_ss = ss) || !_ss->stack){ + TSK_DEBUG_ERROR("Invalid parameter."); + return ret; + } + + /* Checks if the stack has been started */ + if(!TSK_RUNNABLE(_ss->stack)->started){ + TSK_DEBUG_ERROR("Stack not started."); + return -2; + } + + va_start(ap, type); + if((action = _tsip_action_create(tsip_atype_invite, &ap))){ + /* Media type */ + action->media.type = type; + + if(!(dialog = tsip_dialog_layer_find_by_ss(_ss->stack->layer_dialog, ss))){ + dialog = tsip_dialog_layer_new(_ss->stack->layer_dialog, tsip_dialog_INVITE, ss); + } + if(!(ret = tsip_dialog_fsm_act(dialog, action->type, tsk_null, action))){ + TSIP_SSESSION(_ss)->media.type = type; // Update Session Media Type + } + + tsk_object_unref(dialog); + TSK_OBJECT_SAFE_FREE(action); + } + va_end(ap); + + return ret; +} + +int tsip_action_HOLD(const tsip_ssession_handle_t *ss, tmedia_type_t type, ...) +{ + int ret = -1; + tsip_action_t* action; + const tsip_ssession_t* _ss; + va_list ap; + + /* Checks for validity */ + if(!(_ss = ss) || !_ss->stack){ + TSK_DEBUG_ERROR("Invalid parameter."); + return ret; + } + + /* Checks if the stack has been started */ + if(!TSK_RUNNABLE(_ss->stack)->started){ + TSK_DEBUG_ERROR("Stack not started."); + return -2; + } + + va_start(ap, type); + /* execute action */ + if((action = _tsip_action_create(tsip_atype_hold, &ap))){ + /* Media type */ + action->media.type = type; + /* Perform action */ + ret = tsip_ssession_handle(_ss, action); + TSK_OBJECT_SAFE_FREE(action); + } + va_end(ap); + + return ret; +} + +int tsip_action_RESUME(const tsip_ssession_handle_t *ss, tmedia_type_t type, ...) +{ + int ret = -1; + tsip_action_t* action; + const tsip_ssession_t* _ss; + va_list ap; + + /* Checks for validity */ + if(!(_ss = ss) || !_ss->stack){ + TSK_DEBUG_ERROR("Invalid parameter."); + return ret; + } + + /* Checks if the stack has been started */ + if(!TSK_RUNNABLE(_ss->stack)->started){ + TSK_DEBUG_ERROR("Stack not started."); + return -2; + } + + va_start(ap, type); + /* execute action */ + if((action = _tsip_action_create(tsip_atype_resume, &ap))){ + /* Media type */ + action->media.type = type; + /* Perform action */ + ret = tsip_ssession_handle(_ss, action); + TSK_OBJECT_SAFE_FREE(action); + } + va_end(ap); + + return ret; +} + +int tsip_action_LARGE_MESSAGE(const tsip_ssession_handle_t *ss, ...) +{ + int ret = -1; + va_list ap; + + va_start(ap, ss); + if((ret = _tsip_action_ANY(ss, tsip_atype_lmessage, &ap))){ + TSK_DEBUG_ERROR("Failed to send MSRP message"); + } + va_end(ap); + + return ret; +} + +int tsip_action_ECT(const tsip_ssession_handle_t *ss, const char* toUri, ...) +{ + int ret = -1; + tsip_action_t* action; + const tsip_ssession_t* _ss; + va_list ap; + + /* Checks for validity */ + if(!(_ss = ss) || !_ss->stack || !toUri){ + TSK_DEBUG_ERROR("Invalid parameter."); + return ret; + } + + /* Checks if the stack has been started */ + if(!TSK_RUNNABLE(_ss->stack)->started){ + TSK_DEBUG_ERROR("Stack not started."); + return -2; + } + + va_start(ap, toUri); + /* execute action */ + if((action = _tsip_action_create(tsip_atype_ect, &ap))){ + /* Refer-To */ + action->ect.to = tsk_strdup(toUri); + /* Perform action */ + ret = tsip_ssession_handle(_ss, action); + TSK_OBJECT_SAFE_FREE(action); + } + va_end(ap); + + return ret; +} + +int tsip_action_DTMF(const tsip_ssession_handle_t *ss, int event, ...) +{ + int ret = -1; + tsip_action_t* action; + const tsip_ssession_t* _ss; + va_list ap; + + /* Checks for validity */ + if(!(_ss = ss) || !_ss->stack || (event <0 || event>15)){ + TSK_DEBUG_ERROR("Invalid parameter."); + return ret; + } + + /* Checks if the stack has been started */ + if(!TSK_RUNNABLE(_ss->stack)->started){ + TSK_DEBUG_ERROR("Stack not started."); + return -2; + } + + va_start(ap, event); + /* execute action */ + if((action = _tsip_action_create(tsip_atype_dtmf_send, &ap))){ + /* Event */ + action->dtmf.event = event; + /* Perform action */ + ret = tsip_ssession_handle(_ss, action); + TSK_OBJECT_SAFE_FREE(action); + } + va_end(ap); + + return ret; +} + +int tsip_action_BYE(const tsip_ssession_handle_t *ss, ...) +{ + int ret = -1; + va_list ap; + + va_start(ap, ss); + if((ret = _tsip_action_ANY(ss, tsip_atype_bye, &ap))){ + TSK_DEBUG_ERROR("Bye() failed."); + } + va_end(ap); + + return ret; +} + + + + + + + + + + + + + +//======================================================== +// SIP INVITE event object definition +// +static tsk_object_t* tsip_invite_event_ctor(tsk_object_t * self, va_list * app) +{ + tsip_invite_event_t *sipevent = self; + if(sipevent){ + sipevent->type = va_arg(*app, tsip_invite_event_type_t); + } + return self; +} + +static tsk_object_t* tsip_invite_event_dtor(tsk_object_t * self) +{ + tsip_invite_event_t *sipevent = self; + if(sipevent){ + tsip_event_deinit(TSIP_EVENT(sipevent)); + } + return self; +} + +static int tsip_invite_event_cmp(const tsk_object_t *obj1, const tsk_object_t *obj2) +{ + return -1; +} + +static const tsk_object_def_t tsip_invite_event_def_s = +{ + sizeof(tsip_invite_event_t), + tsip_invite_event_ctor, + tsip_invite_event_dtor, + tsip_invite_event_cmp, +}; +const tsk_object_def_t *tsip_invite_event_def_t = &tsip_invite_event_def_s; diff --git a/tinySIP/src/api/tsip_api_message.c b/tinySIP/src/api/tsip_api_message.c new file mode 100644 index 0000000..358bf8b --- /dev/null +++ b/tinySIP/src/api/tsip_api_message.c @@ -0,0 +1,134 @@ +/* +* Copyright (C) 2009-2010 Mamadou Diop. +* +* Contact: Mamadou Diop <diopmamadou(at)doubango.org> +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO 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. +* +* DOUBANGO 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 DOUBANGO. +* +*/ + +/**@file tsip_api_message.c + * @brief Public short messaging (MESSAGE) functions. + * + * @author Mamadou Diop <diopmamadou(at)doubango.org> + * + * @date Created: Sat Nov 8 16:54:58 2009 mdiop + */ +#include "tinysip/api/tsip_api_message.h" + +#include "tinysip/dialogs/tsip_dialog_layer.h" +#include "tinysip/dialogs/tsip_dialog_message.h" + +#include "tsip.h" + +#include "tsk_runnable.h" +#include "tsk_debug.h" + +#define TSIP_MESSAGE_EVENT_CREATE( type) tsk_object_new(tsip_message_event_def_t, type) + +extern tsip_action_t* _tsip_action_create(tsip_action_type_t type, va_list* app); + +int tsip_message_event_signal(tsip_message_event_type_t type, tsip_ssession_handle_t* ss, short status_code, const char *phrase, const tsip_message_t* sipmessage) +{ + tsip_message_event_t* sipevent = TSIP_MESSAGE_EVENT_CREATE(type); + tsip_event_init(TSIP_EVENT(sipevent), ss, status_code, phrase, sipmessage, tsip_event_message); + + TSK_RUNNABLE_ENQUEUE_OBJECT(TSK_RUNNABLE(TSIP_SSESSION(ss)->stack), sipevent); + + return 0; +} + +int tsip_action_MESSAGE(const tsip_ssession_handle_t *ss, ...) +{ + const tsip_ssession_t* _ss; + va_list ap; + tsip_action_t* action; + tsip_dialog_t* dialog; + int ret = -1; + + if(!(_ss = ss) || !_ss->stack){ + TSK_DEBUG_ERROR("Invalid parameter."); + return ret; + } + + /* Checks if the stack has been started */ + if(!TSK_RUNNABLE(_ss->stack)->started){ + TSK_DEBUG_ERROR("Stack not started."); + return -2; + } + + /* action */ + va_start(ap, ss); + if((action = _tsip_action_create(tsip_atype_message_send, &ap))){ + if(!(dialog = tsip_dialog_layer_find_by_ss(_ss->stack->layer_dialog, ss))){ + dialog = tsip_dialog_layer_new(_ss->stack->layer_dialog, tsip_dialog_MESSAGE, ss); + } + ret = tsip_dialog_fsm_act(dialog, action->type, tsk_null, action); + + tsk_object_unref(dialog); + TSK_OBJECT_SAFE_FREE(action); + } + va_end(ap); + + return ret; +} + + + + + + + + + + + + + +//======================================================== +// SIP MESSAGE event object definition +// +static tsk_object_t* tsip_message_event_ctor(tsk_object_t * self, va_list * app) +{ + tsip_message_event_t *sipevent = self; + if(sipevent){ + sipevent->type = va_arg(*app, tsip_message_event_type_t); + } + return self; +} + +static tsk_object_t* tsip_message_event_dtor(tsk_object_t * self) +{ + tsip_message_event_t *sipevent = self; + if(sipevent){ + tsip_event_deinit(TSIP_EVENT(sipevent)); + } + return self; +} + +static int tsip_message_event_cmp(const tsk_object_t *obj1, const tsk_object_t *obj2) +{ + return -1; +} + +static const tsk_object_def_t tsip_message_event_def_s = +{ + sizeof(tsip_message_event_t), + tsip_message_event_ctor, + tsip_message_event_dtor, + tsip_message_event_cmp, +}; +const tsk_object_def_t *tsip_message_event_def_t = &tsip_message_event_def_s; diff --git a/tinySIP/src/api/tsip_api_options.c b/tinySIP/src/api/tsip_api_options.c new file mode 100644 index 0000000..b6f7b09 --- /dev/null +++ b/tinySIP/src/api/tsip_api_options.c @@ -0,0 +1,133 @@ +/* +* Copyright (C) 2009-2010 Mamadou Diop. +* +* Contact: Mamadou Diop <diopmamadou(at)doubango.org> +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO 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. +* +* DOUBANGO 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 DOUBANGO. +* +*/ + +/**@file tsip_api_options.c + * @brief Public functions to handle OPTIONS. + * + * @author Mamadou Diop <diopmamadou(at)doubango.org> + * + * @date Created: Sat Nov 8 16:54:58 2009 mdiop + */ +#include "tinysip/api/tsip_api_options.h" + +#include "tinysip/dialogs/tsip_dialog_layer.h" +#include "tinysip/dialogs/tsip_dialog_options.h" + +#include "tsip.h" + +#include "tsk_runnable.h" +#include "tsk_debug.h" + +#define TSIP_OPTIONS_EVENT_CREATE( type) tsk_object_new(tsip_options_event_def_t, type) + +extern tsip_action_t* _tsip_action_create(tsip_action_type_t type, va_list* app); + +int tsip_options_event_signal(tsip_options_event_type_t type, tsip_ssession_handle_t* ss, short status_code, const char *phrase, const tsip_message_t* sipmessage) +{ + tsip_options_event_t* sipevent = TSIP_OPTIONS_EVENT_CREATE(type); + tsip_event_init(TSIP_EVENT(sipevent), ss, status_code, phrase, sipmessage, tsip_event_options); + + TSK_RUNNABLE_ENQUEUE_OBJECT(TSK_RUNNABLE(TSIP_SSESSION(ss)->stack), sipevent); + + return 0; +} + +int tsip_action_OPTIONS(const tsip_ssession_handle_t *ss, ...) +{ + const tsip_ssession_t* _ss; + va_list ap; + tsip_action_t* action; + tsip_dialog_t* dialog; + int ret = -1; + + if(!(_ss = ss) || !_ss->stack){ + TSK_DEBUG_ERROR("Invalid parameter."); + return ret; + } + + /* Checks if the stack has been started */ + if(!TSK_RUNNABLE(_ss->stack)->started){ + TSK_DEBUG_ERROR("Stack not started."); + return -2; + } + + va_start(ap, ss); + if((action = _tsip_action_create(tsip_atype_options_send, &ap))){ + if(!(dialog = tsip_dialog_layer_find_by_ss(_ss->stack->layer_dialog, ss))){ + dialog = tsip_dialog_layer_new(_ss->stack->layer_dialog, tsip_dialog_OPTIONS, ss); + } + ret = tsip_dialog_fsm_act(dialog, action->type, tsk_null, action); + + tsk_object_unref(dialog); + TSK_OBJECT_SAFE_FREE(action); + } + va_end(ap); + + return ret; +} + + + + + + + + + + + + + +//======================================================== +// SIP OPTIONS event object definition +// +static tsk_object_t* tsip_options_event_ctor(tsk_object_t * self, va_list * app) +{ + tsip_options_event_t *sipevent = self; + if(sipevent){ + sipevent->type = va_arg(*app, tsip_options_event_type_t); + } + return self; +} + +static tsk_object_t* tsip_options_event_dtor(tsk_object_t * self) +{ + tsip_options_event_t *sipevent = self; + if(sipevent){ + tsip_event_deinit(TSIP_EVENT(sipevent)); + } + return self; +} + +static int tsip_options_event_cmp(const tsk_object_t *obj1, const tsk_object_t *obj2) +{ + return -1; +} + +static const tsk_object_def_t tsip_options_event_def_s = +{ + sizeof(tsip_options_event_t), + tsip_options_event_ctor, + tsip_options_event_dtor, + tsip_options_event_cmp, +}; +const tsk_object_def_t *tsip_options_event_def_t = &tsip_options_event_def_s; diff --git a/tinySIP/src/api/tsip_api_publish.c b/tinySIP/src/api/tsip_api_publish.c new file mode 100644 index 0000000..adbe513 --- /dev/null +++ b/tinySIP/src/api/tsip_api_publish.c @@ -0,0 +1,159 @@ +/* +* Copyright (C) 2009-2010 Mamadou Diop. +* +* Contact: Mamadou Diop <diopmamadou(at)doubango.org> +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO 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. +* +* DOUBANGO 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 DOUBANGO. +* +*/ + +/**@file tsip_api_publish.c + * @brief Public subscription (PUBLISH) functions. + * + * @author Mamadou Diop <diopmamadou(at)doubango.org> + * + * @date Created: Sat Nov 8 16:54:58 2009 mdiop + */ +#include "tinysip/api/tsip_api_publish.h" + +#include "tinysip/dialogs/tsip_dialog_layer.h" +#include "tinysip/dialogs/tsip_dialog_publish.h" + +#include "tsip.h" + +#include "tsk_runnable.h" +#include "tsk_debug.h" + +#define TSIP_PUBLISH_EVENT_CREATE( type) tsk_object_new(tsip_publish_event_def_t, type) + +extern tsip_action_t* _tsip_action_create(tsip_action_type_t type, va_list* app); + +int tsip_publish_event_signal(tsip_publish_event_type_t type, tsip_ssession_handle_t* ss, short status_code, const char *phrase, const tsip_message_t* sipmessage) +{ + tsip_publish_event_t* sipevent = TSIP_PUBLISH_EVENT_CREATE(type); + tsip_event_init(TSIP_EVENT(sipevent), ss, status_code, phrase, sipmessage, tsip_event_publish); + + TSK_RUNNABLE_ENQUEUE_OBJECT(TSK_RUNNABLE(TSIP_SSESSION(ss)->stack), sipevent); + + return 0; +} + +int tsip_action_PUBLISH(const tsip_ssession_handle_t *ss, ...) +{ + const tsip_ssession_t* _ss; + va_list ap; + tsip_action_t* action; + tsip_dialog_t* dialog; + int ret = -1; + + if(!(_ss = ss) || !_ss->stack){ + TSK_DEBUG_ERROR("Invalid parameter."); + return ret; + } + + /* Checks if the stack has been started */ + if(!TSK_RUNNABLE(_ss->stack)->started){ + TSK_DEBUG_ERROR("Stack not started."); + return -2; + } + + va_start(ap, ss); + if((action = _tsip_action_create(tsip_atype_publish, &ap))){ + if(!(dialog = tsip_dialog_layer_find_by_ss(_ss->stack->layer_dialog, ss))){ + dialog = tsip_dialog_layer_new(_ss->stack->layer_dialog, tsip_dialog_PUBLISH, ss); + } + ret = tsip_dialog_fsm_act(dialog, action->type, tsk_null, action); + + tsk_object_unref(dialog); + TSK_OBJECT_SAFE_FREE(action); + } + va_end(ap); + + return ret; +} + +int tsip_action_UNPUBLISH(const tsip_ssession_handle_t *ss, ...) +{ + const tsip_ssession_t* _ss; + va_list ap; + tsip_action_t* action; + int ret = -1; + + if(!(_ss = ss) || !_ss->stack){ + TSK_DEBUG_ERROR("Invalid parameter."); + return ret; + } + + /* Checks if the stack is running */ + if(!TSK_RUNNABLE(_ss->stack)->running){ + TSK_DEBUG_ERROR("Stack not running."); + return -2; + } + + va_start(ap, ss); + if((action = _tsip_action_create(tsip_atype_unpublish, &ap))){ + ret = tsip_ssession_handle(ss, action); + TSK_OBJECT_SAFE_FREE(action); + } + va_end(ap); + + return 0; +} + + + + + + + + + + + +//======================================================== +// SIP PUBLISH event object definition +// +static tsk_object_t* tsip_publish_event_ctor(tsk_object_t * self, va_list * app) +{ + tsip_publish_event_t *sipevent = self; + if(sipevent){ + sipevent->type = va_arg(*app, tsip_publish_event_type_t); + } + return self; +} + +static tsk_object_t* tsip_publish_event_dtor(tsk_object_t * self) +{ + tsip_publish_event_t *sipevent = self; + if(sipevent){ + tsip_event_deinit(TSIP_EVENT(sipevent)); + } + return self; +} + +static int tsip_publish_event_cmp(const tsk_object_t *obj1, const tsk_object_t *obj2) +{ + return -1; +} + +static const tsk_object_def_t tsip_publish_event_def_s = +{ + sizeof(tsip_publish_event_t), + tsip_publish_event_ctor, + tsip_publish_event_dtor, + tsip_publish_event_cmp, +}; +const tsk_object_def_t *tsip_publish_event_def_t = &tsip_publish_event_def_s; diff --git a/tinySIP/src/api/tsip_api_register.c b/tinySIP/src/api/tsip_api_register.c new file mode 100644 index 0000000..2e2cb29 --- /dev/null +++ b/tinySIP/src/api/tsip_api_register.c @@ -0,0 +1,166 @@ +/* +* Copyright (C) 2009-2010 Mamadou Diop. +* +* Contact: Mamadou Diop <diopmamadou(at)doubango.org> +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO 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. +* +* DOUBANGO 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 DOUBANGO. +* +*/ + +/**@file tsip_api_register.c + * @brief Public registration (REGISTER) functions. + * + * @author Mamadou Diop <diopmamadou(at)doubango.org> + * + * @date Created: Sat Nov 8 16:54:58 2009 mdiop + */ +#include "tinysip/api/tsip_api_register.h" + +#include "tinysip/dialogs/tsip_dialog_layer.h" +#include "tinysip/dialogs/tsip_dialog_register.h" + +#include "tsip.h" +#include "tinysip/tsip_action.h" + +#include "tsk_runnable.h" +#include "tsk_debug.h" + +#define TSIP_REGISTER_EVENT_CREATE( type) tsk_object_new(tsip_register_event_def_t, type) + +/* Internal functions */ +extern tsip_action_t* _tsip_action_create(tsip_action_type_t type, va_list* app); +extern int _tsip_action_ANY(const tsip_ssession_handle_t *ss, tsip_action_type_t type, va_list* app); + +/* internal function used to signal evant from REGISTER dialog to user app */ +int tsip_register_event_signal(tsip_register_event_type_t type, tsip_ssession_t* ss, short status_code, const char *phrase, const tsip_message_t* sipmessage) +{ + tsip_register_event_t* sipevent = TSIP_REGISTER_EVENT_CREATE(type); + tsip_event_init(TSIP_EVENT(sipevent), ss, status_code, phrase, sipmessage, tsip_event_register); + + TSK_RUNNABLE_ENQUEUE_OBJECT(TSK_RUNNABLE(ss->stack), sipevent); + + return 0; +} + +/**@ingroup tsip_action_group +* Sends SIP REGISTER request. If the session is already established, the same dialog will +* be used (refresh). +* @param ss The SIP Session managing the REGISTER dialog. +* @param ... Any TSIP_ACTION_SET_*() macros. e.g. @ref TSIP_ACTION_SET_HEADER(). +* MUST always ends with @ref TSIP_ACTION_SET_NULL(). +* @retval Zero if succeed and non-zero error code otherwise. +* @sa @ref tsip_action_UNREGISTER +*/ +int tsip_action_REGISTER(const tsip_ssession_handle_t *ss, ...) +{ + const tsip_ssession_t* _ss; + va_list ap; + tsip_action_t* action; + tsip_dialog_t* dialog; + int ret = -1; + + if(!(_ss = ss) || !_ss->stack){ + TSK_DEBUG_ERROR("Invalid parameter."); + return ret; + } + + /* Checks if the stack has been started */ + if(!TSK_RUNNABLE(_ss->stack)->started){ + TSK_DEBUG_ERROR("Stack not started."); + return -2; + } + + /* performs action */ + va_start(ap, ss); + if((action = _tsip_action_create(tsip_atype_register, &ap))){ + if(!(dialog = tsip_dialog_layer_find_by_ss(_ss->stack->layer_dialog, _ss))){ + dialog = tsip_dialog_layer_new(_ss->stack->layer_dialog, tsip_dialog_REGISTER, _ss); + } + ret = tsip_dialog_fsm_act(dialog, action->type, tsk_null, action); + + TSK_OBJECT_SAFE_FREE(dialog); + TSK_OBJECT_SAFE_FREE(action); + } + va_end(ap); + + return ret; +} + +/**@ingroup tsip_action_group +* Sends SIP unREGISTER request (expires=0). The session should be already established. +* @param ss The SIP Session managing the REGISTER dialog. +* @param ... Any TSIP_ACTION_SET_*() macros. e.g. @ref TSIP_ACTION_SET_HEADER(). +* MUST always ends with @ref TSIP_ACTION_SET_NULL(). +* @retval Zero if succeed and non-zero error code otherwise. +* @sa @ref tsip_action_REGISTER +*/ +int tsip_action_UNREGISTER(const tsip_ssession_handle_t *ss, ...) +{ + int ret = -1; + va_list ap; + + va_start(ap, ss); + if((ret = _tsip_action_ANY(ss, tsip_atype_unregister, &ap))){ + TSK_DEBUG_ERROR("unREGISTER() failed."); + } + va_end(ap); + + return ret; +} + + + + + + + + + + +//======================================================== +// SIP REGISTER event object definition +// +static tsk_object_t* tsip_register_event_ctor(tsk_object_t * self, va_list * app) +{ + tsip_register_event_t *sipevent = self; + if(sipevent){ + sipevent->type = va_arg(*app, tsip_register_event_type_t); + } + return self; +} + +static tsk_object_t* tsip_register_event_dtor(tsk_object_t * self) +{ + tsip_register_event_t *sipevent = self; + if(sipevent){ + tsip_event_deinit(TSIP_EVENT(sipevent)); + } + return self; +} + +static int tsip_register_event_cmp(const tsk_object_t *obj1, const tsk_object_t *obj2) +{ + return -1; +} + +static const tsk_object_def_t tsip_register_event_def_s = +{ + sizeof(tsip_register_event_t), + tsip_register_event_ctor, + tsip_register_event_dtor, + tsip_register_event_cmp, +}; +const tsk_object_def_t *tsip_register_event_def_t = &tsip_register_event_def_s; diff --git a/tinySIP/src/api/tsip_api_subscribe.c b/tinySIP/src/api/tsip_api_subscribe.c new file mode 100644 index 0000000..79d9ed4 --- /dev/null +++ b/tinySIP/src/api/tsip_api_subscribe.c @@ -0,0 +1,160 @@ +/* +* Copyright (C) 2009-2010 Mamadou Diop. +* +* Contact: Mamadou Diop <diopmamadou(at)doubango.org> +* +* This file is part of Open Source Doubango Framework. +* +* DOUBANGO 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. +* +* DOUBANGO 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 DOUBANGO. +* +*/ + +/**@file tsip_api_subscribe.c + * @brief Public subscription (SUBSCRIBE) functions. + * + * @author Mamadou Diop <diopmamadou(at)doubango.org> + * + * @date Created: Sat Nov 8 16:54:58 2009 mdiop + */ +#include "tinysip/api/tsip_api_subscribe.h" + +#include "tinysip/dialogs/tsip_dialog_layer.h" +#include "tinysip/dialogs/tsip_dialog_subscribe.h" + +#include "tinysip/tsip_action.h" +#include "tsip.h" + +#include "tsk_runnable.h" +#include "tsk_debug.h" + +#define TSIP_SUBSCRIBE_EVENT_CREATE( type) tsk_object_new(tsip_subscribe_event_def_t, type) + +extern tsip_action_t* _tsip_action_create(tsip_action_type_t type, va_list* app); + +int tsip_subscribe_event_signal(tsip_subscribe_event_type_t type, tsip_ssession_t* ss, short status_code, const char *phrase, const tsip_message_t* sipmessage) +{ + tsip_subscribe_event_t* sipevent = TSIP_SUBSCRIBE_EVENT_CREATE(type); + tsip_event_init(TSIP_EVENT(sipevent), ss, status_code, phrase, sipmessage, tsip_event_subscribe); + + TSK_RUNNABLE_ENQUEUE_OBJECT(TSK_RUNNABLE(TSIP_SSESSION(ss)->stack), sipevent); + + return 0; +} + +int tsip_action_SUBSCRIBE(const tsip_ssession_handle_t *ss, ...) +{ + const tsip_ssession_t* _ss; + va_list ap; + tsip_action_t* action; + tsip_dialog_t* dialog; + int ret = -1; + + if(!(_ss = ss) || !_ss->stack){ + TSK_DEBUG_ERROR("Invalid parameter."); + return ret; + } + + /* Checks if the stack has been started */ + if(!TSK_RUNNABLE(_ss->stack)->started){ + TSK_DEBUG_ERROR("Stack not started."); + return -2; + } + + va_start(ap, ss); + if((action = _tsip_action_create(tsip_atype_subscribe, &ap))){ + if(!(dialog = tsip_dialog_layer_find_by_ss(_ss->stack->layer_dialog, ss))){ + dialog = tsip_dialog_layer_new(_ss->stack->layer_dialog, tsip_dialog_SUBSCRIBE, ss); + } + ret = tsip_dialog_fsm_act(dialog, action->type, tsk_null, action); + + tsk_object_unref(dialog); + TSK_OBJECT_SAFE_FREE(action); + } + va_end(ap); + + return ret; +} + +int tsip_action_UNSUBSCRIBE(const tsip_ssession_handle_t *ss, ...) +{ + const tsip_ssession_t* _ss; + va_list ap; + tsip_action_t* action; + int ret = -1; + + if(!(_ss = ss) || !_ss->stack){ + TSK_DEBUG_ERROR("Invalid parameter."); + return ret; + } + + /* Checks if the stack is running */ + if(!TSK_RUNNABLE(_ss->stack)->running){ + TSK_DEBUG_ERROR("Stack not running."); + return -2; + } + + va_start(ap, ss); + if((action = _tsip_action_create(tsip_atype_unsubscribe, &ap))){ + ret = tsip_ssession_handle(ss, action); + TSK_OBJECT_SAFE_FREE(action); + } + va_end(ap); + + return 0; +} + + + + + + + + + + + +//======================================================== +// SIP SUBSCRIBE event object definition +// +static tsk_object_t* tsip_subscribe_event_ctor(tsk_object_t * self, va_list * app) +{ + tsip_subscribe_event_t *sipevent = self; + if(sipevent){ + sipevent->type = va_arg(*app, tsip_subscribe_event_type_t); + } + return self; +} + +static tsk_object_t* tsip_subscribe_event_dtor(tsk_object_t * self) +{ + tsip_subscribe_event_t *sipevent = self; + if(sipevent){ + tsip_event_deinit(TSIP_EVENT(sipevent)); + } + return self; +} + +static int tsip_subscribe_event_cmp(const tsk_object_t *obj1, const tsk_object_t *obj2) +{ + return -1; +} + +static const tsk_object_def_t tsip_subscribe_event_def_s = +{ + sizeof(tsip_subscribe_event_t), + tsip_subscribe_event_ctor, + tsip_subscribe_event_dtor, + tsip_subscribe_event_cmp, +}; +const tsk_object_def_t *tsip_subscribe_event_def_t = &tsip_subscribe_event_def_s; |