Skip to content

Commit 69b32ad

Browse files
author
gasmibal
committed
some update, I don't have time for the moment !
1 parent af46fa5 commit 69b32ad

File tree

3 files changed

+62
-42
lines changed

3 files changed

+62
-42
lines changed

src/esip.c

+10-10
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@
2828
#include "log.h"
2929
#include "esosip.h"
3030

31+
/**
32+
* @brief
33+
*/
3134
typedef struct app_s {
32-
struct event_config * cfg;
33-
struct event_base * base;
34-
struct event * evsig;
35-
36-
/* osip stack */
37-
es_osip_t * osipCtx;
35+
struct event_config * cfg; //!< LibEvent configuration
36+
struct event_base * base; //!< LibEvent Base loop
37+
struct event * evsig; //!< LibEvent Signal
38+
es_log_t * logger; //!< Logger handler
39+
es_osip_t * osipCtx; //!< OSip stack context
3840
} app_t;
3941

4042
static void libevent_log_cb(int severity, const char * msg)
@@ -49,7 +51,6 @@ static void signal_cb(evutil_socket_t fd, short event, void * arg)
4951
(void)event_base_loopexit(ctx->base, NULL);
5052

5153
/* TODO: free all allocated mem */
52-
//free(ctx);
5354
}
5455

5556
int main(const int argc, const char * argv[])
@@ -61,8 +62,6 @@ int main(const int argc, const char * argv[])
6162

6263
event_set_log_callback(libevent_log_cb);
6364

64-
//event_enable_debug_logging(0xffffffffu);
65-
6665
ctx.cfg = event_config_new();
6766
if (event_config_avoid_method(ctx.cfg, "select") != 0) {
6867
ESIP_TRACE(ESIP_LOG_ERROR, "Can not avoid select methode");
@@ -116,6 +115,7 @@ int main(const int argc, const char * argv[])
116115
event_free(ctx.evsig);
117116
event_base_free(ctx.base);
118117

119-
//libevent_global_shutdown();
120118
return ret;
121119
}
120+
121+
// vim: noai:ts=2:sw=2

src/inc/estypes.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ extern "C" {
4040
#define ES_MIN(_a, _b) (((_a) < (_b) ? (_a) : (_b)))
4141
#define ES_MAX(_a, _b) (((_a) > (_b) ? (_a) : (_b)))
4242

43-
#define ES_UNSED_ARG(_arg) (void)(_arg);
43+
#ifdef __GNUC__
44+
# define UNUSED(d) d __attribute__ ((unused))
45+
#else
46+
# define UNUSED(d) d
47+
#endif
4448

4549
#define IN
4650
#define OUT

src/sip/esosip.c

+47-31
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@
3737
#include "estransport.h"
3838
#include "esosip.h"
3939

40+
#define ES_OSIP_MAGIC 0X20140607
41+
4042
struct es_osip_s {
43+
/* Magic */
44+
uint32_t magic;
4145
/* OSip */
4246
osip_t * osip;
4347
/* Transport Layer */
@@ -58,28 +62,28 @@ struct es_osip_s {
5862
* @note Internal use
5963
*/
6064
static void _es_transport_event_cb(
61-
IN es_transport_t * transp,
62-
IN int event,
63-
IN int error,
64-
IN void * data);
65+
es_transport_t * transp,
66+
int event,
67+
int error,
68+
void * data);
6569

6670
/**
6771
* @brief Transport layer new msg callback
6872
* @return void
6973
* @note Internal use
7074
*/
7175
static void _es_transport_msg_cb(
72-
IN es_transport_t * transp,
73-
IN const char const * msg,
74-
IN const unsigned int size,
75-
OUT void * data);
76+
es_transport_t * transp,
77+
const char const * msg,
78+
const unsigned int size,
79+
void * data);
7680

7781
/**
7882
* @brief Set OSip stack callbacks to internal ones
7983
* @return ES_OK on success
8084
*/
8185
static es_status _es_osip_set_internal_callbacks(
82-
IN struct es_osip_s * _ctx);
86+
struct es_osip_s * _ctx);
8387

8488
/**
8589
* @brief ESip Event sender
@@ -88,14 +92,14 @@ static es_status _es_osip_set_internal_callbacks(
8892
*
8993
* @return ES_OK on success
9094
*/
91-
static es_status _es_send_event(
92-
IN struct es_osip_s * ctx);
95+
static es_status _es_osip_wakeup(
96+
struct es_osip_s * ctx);
9397

9498
/*******************************************************************************
9599
Public functions implementation
96100
******************************************************************************/
97101

98-
es_status es_osip_init(OUT es_osip_t ** _ctx, IN struct event_base * base)
102+
es_status es_osip_init(es_osip_t ** _ctx, struct event_base * base)
99103
{
100104
es_status ret = ES_OK;
101105
struct es_osip_s * ctx = (struct es_osip_s *) malloc(sizeof(struct es_osip_s));
@@ -105,7 +109,7 @@ es_status es_osip_init(OUT es_osip_t ** _ctx, IN struct event_base * base)
105109
}
106110

107111
/* Set Magic */
108-
/* TODO */
112+
ctx->magic = ES_OSIP_MAGIC;
109113

110114
/* Init Transport Layer */
111115
ret = es_transport_init(&ctx->transportCtx, base);
@@ -182,7 +186,10 @@ es_status es_osip_parse_msg(IN es_osip_t * _ctx, IN const char * buf, IN unsigne
182186
}
183187

184188
/* Check Context magic */
185-
/* TODO */
189+
if (ctx->magic != ES_OSIP_MAGIC) {
190+
ESIP_TRACE(ESIP_LOG_ERROR, "SIP ctx is not valid");
191+
return ES_ERROR_NULLPTR;
192+
}
186193

187194
/* Parse buffer and check if it's really a SIP Message */
188195
evt = osip_parse(buf, size);
@@ -232,7 +239,7 @@ es_status es_osip_parse_msg(IN es_osip_t * _ctx, IN const char * buf, IN unsigne
232239
/* Set context reference into Transaction struct */
233240
osip_transaction_set_your_instance(tr, (void *)ctx);
234241

235-
/* add a new OSip event into Fifo list */
242+
/* add a new OSip event into FiFo list */
236243
if (osip_transaction_add_event(tr, evt)) {
237244
ESIP_TRACE(ESIP_LOG_ERROR, "adding event failed");
238245
free(evt);
@@ -241,7 +248,7 @@ es_status es_osip_parse_msg(IN es_osip_t * _ctx, IN const char * buf, IN unsigne
241248
}
242249

243250
/* Send notification using event for the transaction */
244-
if (_es_send_event(ctx) != ES_OK) {
251+
if (_es_osip_wakeup(ctx) != ES_OK) {
245252
ESIP_TRACE(ESIP_LOG_ERROR, "sending event failed");
246253
free(evt);
247254
return ES_ERROR_UNKNOWN;
@@ -257,19 +264,19 @@ es_status es_osip_parse_msg(IN es_osip_t * _ctx, IN const char * buf, IN unsigne
257264
******************************************************************************/
258265

259266
static void _es_transport_event_cb(
260-
IN es_transport_t * transp,
261-
IN int event,
262-
IN int error,
263-
IN void * data)
267+
es_transport_t * transp,
268+
int event,
269+
int error,
270+
void * data)
264271
{
265272
ESIP_TRACE(ESIP_LOG_DEBUG, "Event: %d", event);
266273
}
267274

268275
static void _es_transport_msg_cb(
269-
IN es_transport_t * transp,
270-
IN const char const * msg,
271-
IN const unsigned int size,
272-
OUT void * data)
276+
es_transport_t * transp,
277+
const char const * msg,
278+
const unsigned int size,
279+
void * data)
273280
{
274281
struct es_osip_s * ctx = (struct es_osip_s *)data;
275282

@@ -349,7 +356,7 @@ static void _es_osip_loop(evutil_socket_t fd, short event, void * arg)
349356
}
350357
}
351358

352-
static es_status _es_send_event(struct es_osip_s * ctx)
359+
static es_status _es_osip_wakeup(struct es_osip_s * ctx)
353360
{
354361
struct event * evsip = NULL;
355362

@@ -390,9 +397,9 @@ static es_status _es_send_event(struct es_osip_s * ctx)
390397
}
391398

392399
static es_status _es_tools_build_response(
393-
IN osip_message_t * req,
394-
IN const unsigned int code,
395-
OUT osip_message_t ** resp)
400+
osip_message_t * req,
401+
const unsigned int code,
402+
osip_message_t ** resp)
396403
{
397404
osip_message_t * msg = NULL;
398405
unsigned int random_tag = 0;
@@ -480,7 +487,11 @@ static int _es_internal_send_msg_cb(
480487
return -1;
481488
}
482489

483-
/* TODO: Check magic */
490+
/* Check magic */
491+
if (ctx->magic != ES_OSIP_MAGIC) {
492+
ESIP_TRACE(ESIP_LOG_ERROR, "Reference is invalid");
493+
return -1;
494+
}
484495

485496
osip_message_to_str(msg, &buf, &buf_len);
486497

@@ -526,7 +537,11 @@ static void _es_internal_message_cb(int type, osip_transaction_t * tr, osip_mess
526537
return;
527538
}
528539

529-
/* TODO: Check magic */
540+
/* Check magic */
541+
if (ctx->magic != ES_OSIP_MAGIC) {
542+
ESIP_TRACE(ESIP_LOG_ERROR, "Reference is invalid");
543+
return;
544+
}
530545

531546
if (_es_tools_build_response(msg, 0, &response) != ES_OK) {
532547
ESIP_TRACE(ESIP_LOG_ERROR, "Creating Response failed");
@@ -561,7 +576,7 @@ static void _es_internal_message_cb(int type, osip_transaction_t * tr, osip_mess
561576
osip_transaction_add_event(tr, evt);
562577

563578
/* Send notification using event for the transaction */
564-
if (_es_send_event(ctx) != ES_OK) {
579+
if (_es_osip_wakeup(ctx) != ES_OK) {
565580
ESIP_TRACE(ESIP_LOG_ERROR, "sending event failed");
566581
free(evt);
567582
return;
@@ -608,3 +623,4 @@ static es_status _es_osip_set_internal_callbacks(struct es_osip_s * ctx)
608623
return ES_OK;
609624
}
610625

626+
// vim: ts=2:sw=2

0 commit comments

Comments
 (0)