Commit b460e53c authored by Pekka Pessi's avatar Pekka Pessi
Browse files

stab 2 at soa

Added more functionality to soa. Stab at asynchronous API, too.

darcs-hash:20050908002300-65a35-d3cf6bfd21d7cb5ab7603d530056581164a4ece9.gz
parent aff03339
...@@ -26,7 +26,8 @@ BUILT_SOURCES = soa_tag_ref.c ...@@ -26,7 +26,8 @@ BUILT_SOURCES = soa_tag_ref.c
include_HEADERS = soa.h soa_session.h soa_add.h include_HEADERS = soa.h soa_session.h soa_add.h
libsoa_a_SOURCES = soa.c soa_static.c soa_tag.c soa_tag_ref.c libsoa_a_SOURCES = soa.c soa_static.c soa_asynch.c \
soa_tag.c soa_tag_ref.c
soa_objs_o_SOURCES = $(libsoa_a_SOURCES) soa_objs_o_SOURCES = $(libsoa_a_SOURCES)
soa_objs_o_LDADD = soa_objs_o_LDADD =
......
This diff is collapsed.
...@@ -49,9 +49,9 @@ typedef SOA_MAGIC_T soa_magic_t; ...@@ -49,9 +49,9 @@ typedef SOA_MAGIC_T soa_magic_t;
typedef int soa_callback_f(soa_magic_t *arg, soa_session_t *session); typedef int soa_callback_f(soa_magic_t *arg, soa_session_t *session);
soa_session_t *soa_create(su_root_t *, char const *name); soa_session_t *soa_create(char const *name, su_root_t *, soa_magic_t *);
soa_session_t *soa_clone(soa_session_t *, su_root_t *); soa_session_t *soa_clone(soa_session_t *, su_root_t *, soa_magic_t *);
void soa_destroy(soa_session_t *); void soa_destroy(soa_session_t *);
...@@ -67,6 +67,7 @@ int soa_error_as_sip_response(soa_session_t *soa, ...@@ -67,6 +67,7 @@ int soa_error_as_sip_response(soa_session_t *soa,
char const *soa_error_as_sip_reason(soa_session_t *soa); char const *soa_error_as_sip_reason(soa_session_t *soa);
int soa_parse_sdp(soa_session_t *ss, int soa_parse_sdp(soa_session_t *ss,
int live,
char const *sdp, char const *sdp,
int len); int len);
...@@ -122,11 +123,29 @@ int soa_is_remote_video_active(soa_session_t const *ss); ...@@ -122,11 +123,29 @@ int soa_is_remote_video_active(soa_session_t const *ss);
int soa_is_remote_image_active(soa_session_t const *ss); int soa_is_remote_image_active(soa_session_t const *ss);
int soa_is_remote_chat_active(soa_session_t const *ss); int soa_is_remote_chat_active(soa_session_t const *ss);
/* SOA engine and media parameters /*
* set by soa_set_params(), get by soa_get_params() * SOA engine and media parameters set by soa_set_params(), get by
* or soa_get_paramlist() * soa_get_params() or soa_get_paramlist()
*/ */
#define SOATAG_CAPS_SDP_STR(x) soatag_caps_sdp_str, tag_str_v(x)
extern tag_typedef_t soatag_caps_sdp_str;
#define SOATAG_CAPS_SDP_STR_REF(x) \
soatag_caps_sdp_str_ref, tag_str_vr(&(x))
extern tag_typedef_t soatag_caps_sdp_str_ref;
#define SOATAG_LOCAL_SDP_STR(x) soatag_local_sdp_str, tag_str_v(x)
extern tag_typedef_t soatag_local_sdp_str;
#define SOATAG_LOCAL_SDP_STR_REF(x) \
soatag_local_sdp_str_ref, tag_str_vr(&(x))
extern tag_typedef_t soatag_local_sdp_str_ref;
#define SOATAG_REMOTE_SDP_STR(x) soatag_remote_sdp_str, tag_str_v(x)
extern tag_typedef_t soatag_remote_sdp_str;
#define SOATAG_REMOTE_SDP_STR_REF(x) \
soatag_remote_sdp_str_ref, tag_str_vr(&(x))
extern tag_typedef_t soatag_remote_sdp_str_ref;
#define SOATAG_AF(x) soatag_af, tag_uint_v((x)) #define SOATAG_AF(x) soatag_af, tag_uint_v((x))
extern tag_typedef_t soatag_af; extern tag_typedef_t soatag_af;
......
...@@ -34,9 +34,12 @@ ...@@ -34,9 +34,12 @@
struct soa_session_actions; struct soa_session_actions;
extern struct soa_session_actions const soa_default_actions;
extern struct soa_session_actions const soa_static_actions;
extern struct soa_session_actions const soa_asynch_actions;
int soa_add(char const *name, struct soa_session_actions const *handler); int soa_add(char const *name, struct soa_session_actions const *handler);
struct soa_session_actions const *soa_find(char const *name);
extern struct soa_session_actions const soa_default_actions; struct soa_session_actions const *soa_find(char const *name);
#endif /* SOA_ADD_H */ #endif /* SOA_ADD_H */
...@@ -54,30 +54,42 @@ struct soa_session_actions ...@@ -54,30 +54,42 @@ struct soa_session_actions
char **(*soa_media_features)(soa_session_t *, int live, su_home_t *); char **(*soa_media_features)(soa_session_t *, int live, su_home_t *);
char const * const *(*soa_sip_required)(soa_session_t const *ss); char const * const *(*soa_sip_required)(soa_session_t const *ss);
char const * const *(*soa_sip_support)(soa_session_t const *ss); char const * const *(*soa_sip_support)(soa_session_t const *ss);
int (*soa_remote_sip_features)(soa_session_t *ss, int (*soa_remote_sip_features)(soa_session_t *ss,
char const * const * support, char const * const * support,
char const * const * required); char const * const * required);
int (*soa_config_sdp)(soa_session_t *ss, sdp_session_t *sdp,
char const *sdp_str, int strlen);
int (*soa_generate_offer)(soa_session_t *ss, soa_callback_f *completed); int (*soa_generate_offer)(soa_session_t *ss, soa_callback_f *completed);
int (*soa_generate_answer)(soa_session_t *ss, soa_callback_f *completed); int (*soa_generate_answer)(soa_session_t *ss, soa_callback_f *completed);
void (*soa_activate_session)(soa_session_t *ss, char const *option); void (*soa_activate_session)(soa_session_t *ss, char const *option);
void (*soa_terminate_session)(soa_session_t *ss, char const *option); void (*soa_terminate_session)(soa_session_t *ss, char const *option);
}; };
int soa_default_init(char const *name, soa_session_t *, soa_session_t *parent); soa_session_t *soa_session_ref(soa_session_t *ss);
void soa_default_deinit(soa_session_t *ss); void soa_session_unref(soa_session_t *ss);
int soa_default_set_params(soa_session_t *ss, tagi_t const *tags);
int soa_default_get_params(soa_session_t const *ss, tagi_t *tags); int soa_base_init(char const *name, soa_session_t *, soa_session_t *parent);
tagi_t *soa_default_get_paramlist(soa_session_t const *ss); void soa_base_deinit(soa_session_t *ss);
char **soa_default_media_features(soa_session_t *, int live, su_home_t *); int soa_base_set_params(soa_session_t *ss, tagi_t const *tags);
char const * const * soa_default_sip_required(soa_session_t const *ss); int soa_base_get_params(soa_session_t const *ss, tagi_t *tags);
char const * const * soa_default_sip_support(soa_session_t const *ss); tagi_t *soa_base_get_paramlist(soa_session_t const *ss);
int soa_default_remote_sip_features(soa_session_t *ss, char **soa_base_media_features(soa_session_t *, int live, su_home_t *);
char const * const * soa_base_sip_required(soa_session_t const *ss);
char const * const * soa_base_sip_support(soa_session_t const *ss);
int soa_base_remote_sip_features(soa_session_t *ss,
char const * const * support, char const * const * support,
char const * const * required); char const * const * required);
int soa_default_generate_offer(soa_session_t *ss, soa_callback_f *completed); int soa_base_config_sdp(soa_session_t *ss, sdp_session_t *sdp,
int soa_default_generate_answer(soa_session_t *ss, soa_callback_f *completed); char const *sdp0, int sdp0_len);
void soa_default_activate_session(soa_session_t *ss, char const *option); int soa_base_generate_offer(soa_session_t *ss, soa_callback_f *completed);
void soa_default_terminate_session(soa_session_t *ss, char const *option); int soa_base_generate_answer(soa_session_t *ss, soa_callback_f *completed);
void soa_base_activate(soa_session_t *ss, char const *option);
void soa_base_terminate(soa_session_t *ss, char const *option);
int soa_default_generate_offer(soa_session_t *ss,
soa_callback_f *completed);
int soa_default_generate_answer(soa_session_t *ss,
soa_callback_f *completed);
struct soa_session struct soa_session
{ {
...@@ -86,10 +98,14 @@ struct soa_session ...@@ -86,10 +98,14 @@ struct soa_session
struct soa_session_actions const *ss_actions; struct soa_session_actions const *ss_actions;
su_root_t *ss_root; su_root_t *ss_root;
soa_magic_t *ss_magic; /**< Application data */
unsigned ss_active:1; /**< Session has been activated */ soa_callback_f *ss_in_progress;/**< Operation in progress */
/** Incremented once each time session is terminated */
unsigned ss_terminated;
unsigned ss_in_progress:1; /**< Operation in progress */ unsigned ss_active:1; /**< Session has been activated */
/* Current Offer-Answer status */ /* Current Offer-Answer status */
...@@ -102,7 +118,7 @@ struct soa_session ...@@ -102,7 +118,7 @@ struct soa_session
unsigned ss_answer_sent:2; /**< We have answered (reliably, if >1) */ unsigned ss_answer_sent:2; /**< We have answered (reliably, if >1) */
unsigned :0; /* Pad */ unsigned :0; /* Pad */
unsigned ss_oa_rounds; /**< Number of O/A rounds completed */ unsigned ss_oa_rounds; /**< Number of O/A rounds completed */
struct soa_media_activity struct soa_media_activity
{ {
...@@ -112,12 +128,18 @@ struct soa_session ...@@ -112,12 +128,18 @@ struct soa_session
int ma_chat:3; /**< Chat activity (send/recv) */ int ma_chat:3; /**< Chat activity (send/recv) */
} ss_local_activity[1], ss_remote_activity[1]; } ss_local_activity[1], ss_remote_activity[1];
/** Capabilities as specified by application */
char const *ss_caps_str0;
char const *ss_caps_str; /**< Session capabilities as string */
sdp_session_t *ss_caps; /**< Session capabilities */ sdp_session_t *ss_caps; /**< Session capabilities */
/** Session description specified by application */
char const *ss_local_str0;
char const *ss_local_str; /**< Local session description as string */
sdp_session_t *ss_local; /**< Local session description */ sdp_session_t *ss_local; /**< Local session description */
sdp_session_t *ss_remote; /**< Remote session description */
sdp_origin_t *ss_o_remote;
sdp_parser_t *ss_parser; /**< SDP from incoming request */ sdp_parser_t *ss_parser; /**< SDP from incoming request */
sdp_session_t *ss_remote; /**< Remote session description */
/** SIP features required */ /** SIP features required */
char const * const *ss_local_required; char const * const *ss_local_required;
...@@ -152,11 +174,16 @@ struct soa_session ...@@ -152,11 +174,16 @@ struct soa_session
su_strlst_t *ss_events; su_strlst_t *ss_events;
unsigned ss_srtp_enable:1, unsigned ss_srtp_enable:1,
ss_srtp_confidentiality:1, ss_srtp_confidentiality:1,
ss_srtp_integrity:1; ss_srtp_integrity:1;
}; };
/* ====================================================================== */
int soa_set_status(soa_session_t *ss, int status, char const *phrase);
void soa_set_activity(soa_session_t *ss, sdp_media_t const *m, int remote);
/* ====================================================================== */ /* ====================================================================== */
/* Debug log settings */ /* Debug log settings */
......
...@@ -43,6 +43,11 @@ const char soa_static_c_id[] = ...@@ -43,6 +43,11 @@ const char soa_static_c_id[] =
#include <assert.h> #include <assert.h>
struct soa_static_complete;
#define SU_MSG_ARG_T struct soa_static_completed
#include <su_wait.h>
#include <su_tag_class.h> #include <su_tag_class.h>
#include <su_tag_class.h> #include <su_tag_class.h>
#include <su_tagarg.h> #include <su_tagarg.h>
...@@ -55,24 +60,25 @@ const char soa_static_c_id[] = ...@@ -55,24 +60,25 @@ const char soa_static_c_id[] =
#define NONE ((void *)-1) #define NONE ((void *)-1)
#define XXX assert(!"implemented") #define XXX assert(!"implemented")
struct soa_static_session typedef struct soa_static_session
{ {
soa_session_t session[1]; soa_session_t sss_session[1];
}; }
soa_static_session_t;
static int soa_static_init(char const *, soa_session_t *, soa_session_t *); static int soa_static_init(char const *, soa_session_t *, soa_session_t *);
static void soa_static_deinit(soa_session_t *); static void soa_static_deinit(soa_session_t *);
static int soa_static_set_params(soa_session_t *ss, tagi_t const *tags); static int soa_static_set_params(soa_session_t *ss, tagi_t const *tags);
static int soa_static_get_params(soa_session_t const *ss, tagi_t *tags); static int soa_static_get_params(soa_session_t const *ss, tagi_t *tags);
static tagi_t *soa_static_get_paramlist(soa_session_t const *ss); static tagi_t *soa_static_get_paramlist(soa_session_t const *ss);
static int soa_static_generate_offer(soa_session_t *ss, static int soa_static_generate_offer(soa_session_t *ss,
soa_callback_f *completed); soa_callback_f *completed);
static int soa_static_generate_answer(soa_session_t *ss, static int soa_static_generate_answer(soa_session_t *ss,
soa_callback_f *completed); soa_callback_f *completed);
static void soa_static_activate_session(soa_session_t *ss, char const *option); static void soa_static_activate(soa_session_t *ss, char const *option);
static void soa_static_terminate_session(soa_session_t *ss, char const *option); static void soa_static_terminate(soa_session_t *ss, char const *option);
struct soa_session_actions const soa_static_actions = struct soa_session_actions const soa_static_actions =
{ {
(sizeof soa_static_actions), (sizeof soa_static_actions),
sizeof (struct soa_static_session), sizeof (struct soa_static_session),
...@@ -81,62 +87,115 @@ struct soa_session_actions const soa_static_actions = ...@@ -81,62 +87,115 @@ struct soa_session_actions const soa_static_actions =
soa_static_set_params, soa_static_set_params,
soa_static_get_params, soa_static_get_params,
soa_static_get_paramlist, soa_static_get_paramlist,
soa_default_media_features, soa_base_media_features,
soa_default_sip_required, soa_base_sip_required,
soa_default_sip_support, soa_base_sip_support,
soa_default_remote_sip_features, soa_base_remote_sip_features,
soa_base_config_sdp,
soa_static_generate_offer, soa_static_generate_offer,
soa_static_generate_answer, soa_static_generate_answer,
soa_static_activate_session, soa_static_activate,
soa_static_terminate_session soa_static_terminate
}; };
/* Initialize session */ /* Initialize session */
static int soa_static_init(char const *name, static int soa_static_init(char const *name,
soa_session_t *ss, soa_session_t *ss,
soa_session_t *parent) soa_session_t *parent)
{ {
return soa_default_init(name, ss, parent); soa_static_session_t *myss = (void *)ss;
return soa_base_init(name, ss, parent);
} }
static void soa_static_deinit(soa_session_t *ss) static void soa_static_deinit(soa_session_t *ss)
{ {
soa_default_deinit(ss); soa_base_deinit(ss);
} }
static int soa_static_set_params(soa_session_t *ss, tagi_t const *tags) static int soa_static_set_params(soa_session_t *ss, tagi_t const *tags)
{ {
return soa_default_set_params(ss, tags); return soa_base_set_params(ss, tags);
} }
static int soa_static_get_params(soa_session_t const *ss, tagi_t *tags) static int soa_static_get_params(soa_session_t const *ss, tagi_t *tags)
{ {
return soa_default_get_params(ss, tags); return soa_base_get_params(ss, tags);
} }
static tagi_t *soa_static_get_paramlist(soa_session_t const *ss) static tagi_t *soa_static_get_paramlist(soa_session_t const *ss)
{ {
return soa_default_get_paramlist(ss); return soa_base_get_paramlist(ss);
} }
static int soa_static_generate_offer(soa_session_t *ss, static int soa_static_generate_offer(soa_session_t *ss,
soa_callback_f *completed) soa_callback_f *completed)
{ {
return soa_default_generate_offer(ss, completed); sdp_media_t *m;
uint16_t port = 5004;
su_msg_r msg;
if (ss->ss_local == NULL) {
if (ss->ss_caps == NULL)
return soa_set_status(ss, 500, "No local session available");
}
if (ss->ss_local)
return 0; /* We are done */
/* Generate a dummy offer based on our capabilities */
ss->ss_local = sdp_session_dup(ss->ss_home, ss->ss_caps);
if (!ss->ss_local) {
return soa_set_status(ss, 500, "Internal error");
}
for (m = ss->ss_local->sdp_media; m; m = m->m_next)
if (m->m_port == 0)
m->m_port = port, port += 2;
soa_set_activity(ss, ss->ss_local->sdp_media, 0);
return 0;
} }
static int soa_static_generate_answer(soa_session_t *ss, static int soa_static_generate_answer(soa_session_t *ss,
soa_callback_f *completed) soa_callback_f *completed)
{ {
return soa_default_generate_answer(ss, completed); sdp_media_t *m;
uint16_t port = 5004;
su_msg_r msg;
if (ss->ss_local == NULL) {
if (ss->ss_caps == NULL)
return soa_set_status(ss, 500, "No local session available");
}
if (ss->ss_local)
return 0; /* We are done */
/* Generate a dummy answer based on our capabilities */
ss->ss_local = sdp_session_dup(ss->ss_home, ss->ss_caps);
if (!ss->ss_local) {
return soa_set_status(ss, 500, "Internal error");
}
for (m = ss->ss_local->sdp_media; m; m = m->m_next)
if (m->m_port == 0)
m->m_port = port, port += 2;
soa_set_activity(ss, ss->ss_local->sdp_media, 0);
return 0;
} }
static void soa_static_activate_session(soa_session_t *ss, char const *option) static void soa_static_activate(soa_session_t *ss, char const *option)
{ {
return soa_default_activate_session(ss, option); soa_base_activate(ss, option);
} }
static void soa_static_terminate_session(soa_session_t *ss, char const *option) static void soa_static_terminate(soa_session_t *ss, char const *option)
{ {
return soa_default_terminate_session(ss, option); if (ss->ss_local)
su_free(ss->ss_home, ss->ss_local), ss->ss_local = NULL;
soa_base_terminate(ss, option);
} }
...@@ -42,6 +42,70 @@ const char soa_tag_c_id[] = ...@@ -42,6 +42,70 @@ const char soa_tag_c_id[] =
#include <soa.h> #include <soa.h>
#include <su_tag_class.h> #include <su_tag_class.h>
/**@def SOATAG_CAPS_SDP_STR(x)
* Pass media description file name to the NUA stack.
*
* Pass name of media description file that contains media templates
* (normally mss.sdp) to the NUA stack.
*
* @par Used with
* nua_set_params() \n
* nua_get_params() \n
* nua_create()
*
* @par Parameter type
* char const *
*
* @par Values
* NULL terminated character string
*
* Corresponding tag taking reference parameter is SOATAG_CAPS_SDP_STR_REF()
*/
tag_typedef_t soatag_caps_sdp_str = STRTAG_TYPEDEF(caps_sdp_str);
/**@def SOATAG_LOCAL_SDP_STR(x)
* Pass media description file name to the NUA stack.
*
* Pass name of media description file that contains media templates
* (normally mss.sdp) to the NUA stack.
*
* @par Used with
* nua_set_params() \n
* nua_get_params() \n
* nua_create()
*
* @par Parameter type
* char const *
*
* @par Values
* NULL terminated character string
*
* Corresponding tag taking reference parameter is SOATAG_LOCAL_SDP_STR_REF()
*/
tag_typedef_t soatag_local_sdp_str = STRTAG_TYPEDEF(local_sdp_str);
/**@def SOATAG_REMOTE_SDP_STR(x)
* Pass media description file name to the NUA stack.
*
* Pass name of media description file that contains media templates
* (normally mss.sdp) to the NUA stack.
*
* @par Used with
* nua_set_params() \n
* nua_get_params() \n
* nua_create()
*
* @par Parameter type
* char const *
*
* @par Values
* NULL terminated character string
*
* Corresponding tag taking reference parameter is SOATAG_REMOTE_SDP_STR_REF()
*/
tag_typedef_t soatag_remote_sdp_str = STRTAG_TYPEDEF(remote_sdp_str);
/**@def SOATAG_AF(x) /**@def SOATAG_AF(x)
* *
......
...@@ -51,6 +51,7 @@ struct context; ...@@ -51,6 +51,7 @@ struct context;
#define SOA_MAGIC_T struct context #define SOA_MAGIC_T struct context
#include "soa.h" #include "soa.h"
#include "soa_add.h"
#include <su_log.h> #include <su_log.h>
...@@ -69,9 +70,19 @@ int tstflags = 0; ...@@ -69,9 +70,19 @@ int tstflags = 0;
#define __func__ name #define __func__ name
#endif #endif
#define NONE ((void*)-1)
struct context struct context
{ {
su_home_t home[1]; su_home_t home[1];
su_root_t *root;
struct {
soa_session_t *a;
soa_session_t *b;
} synch, asynch;
soa_session_t *completed;
}; };
int test_api_completed(struct context *arg, soa_session_t *session) int test_api_completed(struct context *arg, soa_session_t *session)
...@@ -87,8 +98,8 @@ int test_api_errors(struct context *ctx) ...@@ -87,8 +98,8 @@ int test_api_errors(struct context *ctx)
char const *null = NULL; char const *null = NULL;
char const * const *featurelist; char const * const *featurelist;
TEST_1(!soa_create(NULL, "default"));