提交 a5cd2df8 authored 作者: Mathieu Parent's avatar Mathieu Parent

Skinny: Handle network-address-change trap event

- add auto-restart param to each profile (if true, ip is automaticaly changed)
- some cleaning (unused args in flush_listener, better logs)
上级 ca481842
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
<param name="date-format" value="D/M/Y"/> <param name="date-format" value="D/M/Y"/>
<param name="odbc-dsn" value=""/> <param name="odbc-dsn" value=""/>
<param name="debug" value="4"/> <param name="debug" value="4"/>
<param name="auto-restart" value="true"/>
</settings> </settings>
<device-types> <device-types>
<device-type id="Cisco ATA 186"> <device-type id="Cisco ATA 186">
......
...@@ -52,11 +52,18 @@ struct skinny_globals { ...@@ -52,11 +52,18 @@ struct skinny_globals {
switch_event_node_t *heartbeat_node; switch_event_node_t *heartbeat_node;
switch_event_node_t *call_state_node; switch_event_node_t *call_state_node;
switch_event_node_t *message_waiting_node; switch_event_node_t *message_waiting_node;
switch_event_node_t *trap_node;
int auto_restart;
}; };
typedef struct skinny_globals skinny_globals_t; typedef struct skinny_globals skinny_globals_t;
extern skinny_globals_t globals; extern skinny_globals_t globals;
typedef enum {
PFLAG_LISTENER_READY = (1 << 0),
PFLAG_RESPAWN = (1 << 1),
} profile_flag_t;
struct skinny_profile { struct skinny_profile {
/* prefs */ /* prefs */
char *name; char *name;
...@@ -70,6 +77,7 @@ struct skinny_profile { ...@@ -70,6 +77,7 @@ struct skinny_profile {
uint32_t keep_alive; uint32_t keep_alive;
char date_format[6]; char date_format[6];
int debug; int debug;
int auto_restart;
switch_hash_t *device_type_params_hash; switch_hash_t *device_type_params_hash;
/* db */ /* db */
char *dbname; char *dbname;
...@@ -89,7 +97,8 @@ struct skinny_profile { ...@@ -89,7 +97,8 @@ struct skinny_profile {
switch_socket_t *sock; switch_socket_t *sock;
switch_mutex_t *sock_mutex; switch_mutex_t *sock_mutex;
struct listener *listeners; struct listener *listeners;
uint8_t listener_ready; int flags;
switch_mutex_t *flag_mutex;
/* call id */ /* call id */
uint32_t next_call_id; uint32_t next_call_id;
/* others */ /* others */
...@@ -114,7 +123,7 @@ typedef enum { ...@@ -114,7 +123,7 @@ typedef enum {
typedef enum { typedef enum {
LFLAG_RUNNING = (1 << 0), LFLAG_RUNNING = (1 << 0),
} event_flag_t; } listener_flag_t;
#define SKINNY_MAX_LINES 42 #define SKINNY_MAX_LINES 42
struct listener { struct listener {
......
...@@ -230,6 +230,7 @@ static switch_status_t skinny_api_list_settings(const char *line, const char *cu ...@@ -230,6 +230,7 @@ static switch_status_t skinny_api_list_settings(const char *line, const char *cu
switch_console_push_match(&my_matches, "date-format"); switch_console_push_match(&my_matches, "date-format");
switch_console_push_match(&my_matches, "odbc-dsn"); switch_console_push_match(&my_matches, "odbc-dsn");
switch_console_push_match(&my_matches, "debug"); switch_console_push_match(&my_matches, "debug");
switch_console_push_match(&my_matches, "auto-restart");
if (my_matches) { if (my_matches) {
*matches = my_matches; *matches = my_matches;
......
...@@ -119,7 +119,7 @@ switch_status_t skinny_read_packet(listener_t *listener, skinny_message_t **req) ...@@ -119,7 +119,7 @@ switch_status_t skinny_read_packet(listener_t *listener, skinny_message_t **req)
} }
if (!listener_is_ready(listener)) { if (!listener_is_ready(listener)) {
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_BREAK;
} }
ptr = mbuf; ptr = mbuf;
...@@ -136,7 +136,10 @@ switch_status_t skinny_read_packet(listener_t *listener, skinny_message_t **req) ...@@ -136,7 +136,10 @@ switch_status_t skinny_read_packet(listener_t *listener, skinny_message_t **req)
status = switch_socket_recv(listener->sock, ptr, &mlen); status = switch_socket_recv(listener->sock, ptr, &mlen);
if (!listener_is_ready(listener) || (!SWITCH_STATUS_IS_BREAK(status) && status != SWITCH_STATUS_SUCCESS)) { if (!listener_is_ready(listener)) {
return SWITCH_STATUS_BREAK;
}
if (!SWITCH_STATUS_IS_BREAK(status) && status != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Socket break.\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Socket break.\n");
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
...@@ -167,20 +170,13 @@ switch_status_t skinny_read_packet(listener_t *listener, skinny_message_t **req) ...@@ -167,20 +170,13 @@ switch_status_t skinny_read_packet(listener_t *listener, skinny_message_t **req)
} }
if(bytes >= request->length + 2*SKINNY_MESSAGE_FIELD_SIZE) { if(bytes >= request->length + 2*SKINNY_MESSAGE_FIELD_SIZE) {
/* Message body */ /* Message body */
#ifdef SKINNY_MEGA_DEBUG
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
"Got complete request: length=%d,reserved=%x,type=%x,data=%d\n",
request->length,request->reserved,request->type,request->data.as_char);
#endif
*req = request; *req = request;
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
} }
} }
if (listener->expire_time && listener->expire_time < switch_epoch_time_now(NULL)) { if (listener->expire_time && listener->expire_time < switch_epoch_time_now(NULL)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Listener timed out.\n"); return SWITCH_STATUS_TIMEOUT;
switch_clear_flag_locked(listener, LFLAG_RUNNING);
return SWITCH_STATUS_FALSE;
} }
if (do_sleep) { if (do_sleep) {
switch_cond_next(); switch_cond_next();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论