37
37
#include "estransport.h"
38
38
#include "esosip.h"
39
39
40
+ #define ES_OSIP_MAGIC 0X20140607
41
+
40
42
struct es_osip_s {
43
+ /* Magic */
44
+ uint32_t magic ;
41
45
/* OSip */
42
46
osip_t * osip ;
43
47
/* Transport Layer */
@@ -58,28 +62,28 @@ struct es_osip_s {
58
62
* @note Internal use
59
63
*/
60
64
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 );
65
69
66
70
/**
67
71
* @brief Transport layer new msg callback
68
72
* @return void
69
73
* @note Internal use
70
74
*/
71
75
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 );
76
80
77
81
/**
78
82
* @brief Set OSip stack callbacks to internal ones
79
83
* @return ES_OK on success
80
84
*/
81
85
static es_status _es_osip_set_internal_callbacks (
82
- IN struct es_osip_s * _ctx );
86
+ struct es_osip_s * _ctx );
83
87
84
88
/**
85
89
* @brief ESip Event sender
@@ -88,14 +92,14 @@ static es_status _es_osip_set_internal_callbacks(
88
92
*
89
93
* @return ES_OK on success
90
94
*/
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 );
93
97
94
98
/*******************************************************************************
95
99
Public functions implementation
96
100
******************************************************************************/
97
101
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 )
99
103
{
100
104
es_status ret = ES_OK ;
101
105
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)
105
109
}
106
110
107
111
/* Set Magic */
108
- /* TODO */
112
+ ctx -> magic = ES_OSIP_MAGIC ;
109
113
110
114
/* Init Transport Layer */
111
115
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
182
186
}
183
187
184
188
/* 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
+ }
186
193
187
194
/* Parse buffer and check if it's really a SIP Message */
188
195
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
232
239
/* Set context reference into Transaction struct */
233
240
osip_transaction_set_your_instance (tr , (void * )ctx );
234
241
235
- /* add a new OSip event into Fifo list */
242
+ /* add a new OSip event into FiFo list */
236
243
if (osip_transaction_add_event (tr , evt )) {
237
244
ESIP_TRACE (ESIP_LOG_ERROR , "adding event failed" );
238
245
free (evt );
@@ -241,7 +248,7 @@ es_status es_osip_parse_msg(IN es_osip_t * _ctx, IN const char * buf, IN unsigne
241
248
}
242
249
243
250
/* Send notification using event for the transaction */
244
- if (_es_send_event (ctx ) != ES_OK ) {
251
+ if (_es_osip_wakeup (ctx ) != ES_OK ) {
245
252
ESIP_TRACE (ESIP_LOG_ERROR , "sending event failed" );
246
253
free (evt );
247
254
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
257
264
******************************************************************************/
258
265
259
266
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 )
264
271
{
265
272
ESIP_TRACE (ESIP_LOG_DEBUG , "Event: %d" , event );
266
273
}
267
274
268
275
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 )
273
280
{
274
281
struct es_osip_s * ctx = (struct es_osip_s * )data ;
275
282
@@ -349,7 +356,7 @@ static void _es_osip_loop(evutil_socket_t fd, short event, void * arg)
349
356
}
350
357
}
351
358
352
- static es_status _es_send_event (struct es_osip_s * ctx )
359
+ static es_status _es_osip_wakeup (struct es_osip_s * ctx )
353
360
{
354
361
struct event * evsip = NULL ;
355
362
@@ -390,9 +397,9 @@ static es_status _es_send_event(struct es_osip_s * ctx)
390
397
}
391
398
392
399
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 )
396
403
{
397
404
osip_message_t * msg = NULL ;
398
405
unsigned int random_tag = 0 ;
@@ -480,7 +487,11 @@ static int _es_internal_send_msg_cb(
480
487
return -1 ;
481
488
}
482
489
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
+ }
484
495
485
496
osip_message_to_str (msg , & buf , & buf_len );
486
497
@@ -526,7 +537,11 @@ static void _es_internal_message_cb(int type, osip_transaction_t * tr, osip_mess
526
537
return ;
527
538
}
528
539
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
+ }
530
545
531
546
if (_es_tools_build_response (msg , 0 , & response ) != ES_OK ) {
532
547
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
561
576
osip_transaction_add_event (tr , evt );
562
577
563
578
/* Send notification using event for the transaction */
564
- if (_es_send_event (ctx ) != ES_OK ) {
579
+ if (_es_osip_wakeup (ctx ) != ES_OK ) {
565
580
ESIP_TRACE (ESIP_LOG_ERROR , "sending event failed" );
566
581
free (evt );
567
582
return ;
@@ -608,3 +623,4 @@ static es_status _es_osip_set_internal_callbacks(struct es_osip_s * ctx)
608
623
return ES_OK ;
609
624
}
610
625
626
+ // vim: ts=2:sw=2
0 commit comments