Skip to content

Commit

Permalink
core: event hook for sip reply out
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed Jun 18, 2020
1 parent 7e402da commit 93ab079
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/core/events.c
Expand Up @@ -180,6 +180,15 @@ int sr_event_register_cb(int type, sr_event_cb_f f)
_sr_events_list.net_data_send = f;
else return -1;
break;
case SREV_SIP_REPLY_OUT:
for(i=0; i<SREV_CB_LIST_SIZE; i++) {
if(_sr_events_list.sip_reply_out[i]==0) {
_sr_events_list.sip_reply_out[i] = f;
break;
}
}
if(i==SREV_CB_LIST_SIZE) return -1;
break;
default:
return -1;
}
Expand Down Expand Up @@ -317,6 +326,15 @@ int sr_event_exec(int type, sr_event_param_t *evp)
ret = _sr_events_list.net_data_send(evp);
return ret;
} else return 1;
case SREV_SIP_REPLY_OUT:
if(unlikely(_sr_events_list.net_data_in[0]!=0))
{
ret = 0;
for(i=0; i<SREV_CB_LIST_SIZE
&& _sr_events_list.sip_reply_out[i]; i++) {
ret |= _sr_events_list.sip_reply_out[i](evp);
}
} else return 1;
default:
return -1;
}
Expand Down Expand Up @@ -358,6 +376,8 @@ int sr_event_enabled(int type)
return (_sr_events_list.net_data_recv!=0)?1:0;
case SREV_NET_DATA_SEND:
return (_sr_events_list.net_data_send!=0)?1:0;
case SREV_SIP_REPLY_OUT:
return (_sr_events_list.sip_reply_out[0]!=0)?1:0;
}
return 0;
}
Expand Down
6 changes: 6 additions & 0 deletions src/core/events.h
Expand Up @@ -37,13 +37,18 @@
#define SREV_TCP_CLOSED 13
#define SREV_NET_DATA_RECV 14
#define SREV_NET_DATA_SEND 15
#define SREV_SIP_REPLY_OUT 16

#define SREV_CB_LIST_SIZE 8

typedef struct sr_event_param {
void *data;
receive_info_t* rcv;
dest_info_t *dst;
sip_msg_t *req;
sip_msg_t *rpl;
int rplcode;
int mode;
} sr_event_param_t;

typedef int (*sr_event_cb_f)(sr_event_param_t *evp);
Expand All @@ -64,6 +69,7 @@ typedef struct sr_event_cb {
sr_event_cb_f tcp_closed;
sr_event_cb_f net_data_recv;
sr_event_cb_f net_data_send;
sr_event_cb_f sip_reply_out[SREV_CB_LIST_SIZE];
} sr_event_cb_t;

void sr_event_cb_init(void);
Expand Down

0 comments on commit 93ab079

Please sign in to comment.