@ -104,6 +104,38 @@ static void cli_incoming_list_totals(char* buffer, int len, struct callmaster* m
g_list_free ( list ) ;
g_list_free ( list ) ;
}
}
static void cli_incoming_list_maxsessions ( char * buffer , int len , struct callmaster * m , char * replybuffer , const char * outbufend ) {
int printlen = 0 ;
/* don't lock anything while reading the value */
printlen = snprintf ( replybuffer , ( outbufend - replybuffer ) , " Maximum sessions configured on rtpengine: %d \n " , m - > conf . max_sessions ) ;
ADJUSTLEN ( printlen , outbufend , replybuffer ) ;
return ;
}
static void cli_incoming_list_maxopenfiles ( char * buffer , int len , struct callmaster * m , char * replybuffer , const char * outbufend ) {
int printlen = 0 ;
struct rlimit rlim ;
pid_t pid = getpid ( ) ;
if ( getrlimit ( RLIMIT_NOFILE , & rlim ) = = - 1 ) {
printlen = snprintf ( replybuffer , ( outbufend - replybuffer ) , " Fail getting rtpengine configured limits; cat /proc/%u/limits \n " , pid ) ;
ADJUSTLEN ( printlen , outbufend , replybuffer ) ;
return ;
}
if ( rlim . rlim_cur = = RLIM_INFINITY ) {
printlen = snprintf ( replybuffer , ( outbufend - replybuffer ) , " Maximum open-files configured on rtpengine: infinite; cat /proc/%u/limits \n " , pid ) ;
ADJUSTLEN ( printlen , outbufend , replybuffer ) ;
} else {
printlen = snprintf ( replybuffer , ( outbufend - replybuffer ) , " Maximum open-files configured on rtpengine: %lld; cat /proc/%u/limits \n " , ( long long ) rlim . rlim_cur , pid ) ;
ADJUSTLEN ( printlen , outbufend , replybuffer ) ;
}
return ;
}
static void cli_incoming_list_callid ( char * buffer , int len , struct callmaster * m , char * replybuffer , const char * outbufend ) {
static void cli_incoming_list_callid ( char * buffer , int len , struct callmaster * m , char * replybuffer , const char * outbufend ) {
str callid ;
str callid ;
struct call * c = 0 ;
struct call * c = 0 ;
@ -212,6 +244,84 @@ static void cli_incoming_list_callid(char* buffer, int len, struct callmaster* m
obj_put ( c ) ;
obj_put ( c ) ;
}
}
static void cli_incoming_set_maxopenfiles ( char * buffer , int len , struct callmaster * m , char * replybuffer , const char * outbufend ) {
int printlen = 0 ;
unsigned int open_files_num ;
str open_files ;
pid_t pid ;
/ / limit the minimum number of open files to avoid rtpengine freeze for low open_files_num values
unsigned int min_open_files_num = ( 1 < < 16 ) ;
if ( len < = 1 ) {
printlen = snprintf ( replybuffer , ( outbufend - replybuffer ) , " %s \n " , " More parameters required. " ) ;
ADJUSTLEN ( printlen , outbufend , replybuffer ) ;
return ;
}
+ + buffer ; - - len ; / / one space
open_files . s = buffer ;
open_files . len = len ;
open_files_num = str_to_ui ( & open_files , - 1 ) ;
if ( open_files_num = = - 1 ) {
printlen = snprintf ( replybuffer , ( outbufend - replybuffer ) , " Fail setting open_files to %.*s; not an unsigned integer \n " , open_files . len , open_files . s ) ;
ADJUSTLEN ( printlen , outbufend , replybuffer ) ;
return ;
} else if ( open_files_num < min_open_files_num ) {
printlen = snprintf ( replybuffer , ( outbufend - replybuffer ) , " Fail setting open_files to %.*s; can't set it under %u \n " , open_files . len , open_files . s , min_open_files_num ) ;
ADJUSTLEN ( printlen , outbufend , replybuffer ) ;
return ;
} else if ( rlim ( RLIMIT_NOFILE , open_files_num ) = = - 1 ) {
printlen = snprintf ( replybuffer , ( outbufend - replybuffer ) , " Fail setting open_files to %.*s; errno = %d \n " , open_files . len , open_files . s , errno ) ;
ADJUSTLEN ( printlen , outbufend , replybuffer ) ;
return ;
} else {
pid = getpid ( ) ;
printlen = snprintf ( replybuffer , ( outbufend - replybuffer ) , " Success setting open_files to %.*s; cat /proc/%u/limits \n " , open_files . len , open_files . s , pid ) ;
ADJUSTLEN ( printlen , outbufend , replybuffer ) ;
}
}
static void cli_incoming_set_maxsessions ( char * buffer , int len , struct callmaster * m , char * replybuffer , const char * outbufend ) {
int printlen = 0 ;
int maxsessions_num ;
int err = 0x80000000 ;
int disabled = - 1 ;
str maxsessions ;
if ( len < = 1 ) {
printlen = snprintf ( replybuffer , ( outbufend - replybuffer ) , " %s \n " , " More parameters required. " ) ;
ADJUSTLEN ( printlen , outbufend , replybuffer ) ;
return ;
}
+ + buffer ; - - len ; / / one space
maxsessions . s = buffer ;
maxsessions . len = len ;
maxsessions_num = str_to_i ( & maxsessions , err ) ;
if ( maxsessions_num = = err ) {
printlen = snprintf ( replybuffer , ( outbufend - replybuffer ) , " Fail setting maxsessions to %.*s; not an integer \n " , maxsessions . len , maxsessions . s ) ;
ADJUSTLEN ( printlen , outbufend , replybuffer ) ;
} else if ( maxsessions_num < disabled ) {
printlen = snprintf ( replybuffer , ( outbufend - replybuffer ) , " Fail setting maxsessions to %d; either positive or -1 values allowed \n " , maxsessions_num ) ;
ADJUSTLEN ( printlen , outbufend , replybuffer ) ;
} else if ( maxsessions_num = = disabled ) {
/* don't lock anything while writing the value - only this command modifies its value */
m - > conf . max_sessions = maxsessions_num ;
printlen = snprintf ( replybuffer , ( outbufend - replybuffer ) , " Success setting maxsessions to %d; disable feature \n " , maxsessions_num ) ;
ADJUSTLEN ( printlen , outbufend , replybuffer ) ;
} else {
/* don't lock anything while writing the value - only this command modifies its value */
m - > conf . max_sessions = maxsessions_num ;
printlen = snprintf ( replybuffer , ( outbufend - replybuffer ) , " Success setting maxsessions to %d \n " , maxsessions_num ) ;
ADJUSTLEN ( printlen , outbufend , replybuffer ) ;
}
return ;
}
static void cli_incoming_list ( char * buffer , int len , struct callmaster * m , char * replybuffer , const char * outbufend ) {
static void cli_incoming_list ( char * buffer , int len , struct callmaster * m , char * replybuffer , const char * outbufend ) {
GHashTableIter iter ;
GHashTableIter iter ;
gpointer key , value ;
gpointer key , value ;
@ -223,6 +333,8 @@ static void cli_incoming_list(char* buffer, int len, struct callmaster* m, char*
static const char * LIST_SESSIONS = " sessions " ;
static const char * LIST_SESSIONS = " sessions " ;
static const char * LIST_SESSION = " session " ;
static const char * LIST_SESSION = " session " ;
static const char * LIST_TOTALS = " totals " ;
static const char * LIST_TOTALS = " totals " ;
static const char * LIST_MAX_OPEN_FILES = " maxopenfiles " ;
static const char * LIST_MAX_SESSIONS = " maxsessions " ;
if ( len < = 1 ) {
if ( len < = 1 ) {
printlen = snprintf ( replybuffer , outbufend - replybuffer , " %s \n " , " More parameters required. " ) ;
printlen = snprintf ( replybuffer , outbufend - replybuffer , " %s \n " , " More parameters required. " ) ;
@ -233,7 +345,7 @@ static void cli_incoming_list(char* buffer, int len, struct callmaster* m, char*
if ( len > = strlen ( LIST_NUMSESSIONS ) & & strncmp ( buffer , LIST_NUMSESSIONS , strlen ( LIST_NUMSESSIONS ) ) = = 0 ) {
if ( len > = strlen ( LIST_NUMSESSIONS ) & & strncmp ( buffer , LIST_NUMSESSIONS , strlen ( LIST_NUMSESSIONS ) ) = = 0 ) {
rwlock_lock_r ( & m - > hashlock ) ;
rwlock_lock_r ( & m - > hashlock ) ;
printlen = snprintf ( replybuffer , outbufend - replybuffer , " Current Sessions on rtpengine: %i \n " , g_hash_table_size ( m - > callhash ) ) ;
printlen = snprintf ( replybuffer , outbufend - replybuffer , " Current sessions running on rtpengine: %i \n " , g_hash_table_size ( m - > callhash ) ) ;
ADJUSTLEN ( printlen , outbufend , replybuffer ) ;
ADJUSTLEN ( printlen , outbufend , replybuffer ) ;
rwlock_unlock_r ( & m - > hashlock ) ;
rwlock_unlock_r ( & m - > hashlock ) ;
} else if ( len > = strlen ( LIST_SESSIONS ) & & strncmp ( buffer , LIST_SESSIONS , strlen ( LIST_SESSIONS ) ) = = 0 ) {
} else if ( len > = strlen ( LIST_SESSIONS ) & & strncmp ( buffer , LIST_SESSIONS , strlen ( LIST_SESSIONS ) ) = = 0 ) {
@ -256,12 +368,39 @@ static void cli_incoming_list(char* buffer, int len, struct callmaster* m, char*
cli_incoming_list_callid ( buffer + strlen ( LIST_SESSION ) , len - strlen ( LIST_SESSION ) , m , replybuffer , outbufend ) ;
cli_incoming_list_callid ( buffer + strlen ( LIST_SESSION ) , len - strlen ( LIST_SESSION ) , m , replybuffer , outbufend ) ;
} else if ( len > = strlen ( LIST_TOTALS ) & & strncmp ( buffer , LIST_TOTALS , strlen ( LIST_TOTALS ) ) = = 0 ) {
} else if ( len > = strlen ( LIST_TOTALS ) & & strncmp ( buffer , LIST_TOTALS , strlen ( LIST_TOTALS ) ) = = 0 ) {
cli_incoming_list_totals ( buffer + strlen ( LIST_TOTALS ) , len - strlen ( LIST_TOTALS ) , m , replybuffer , outbufend ) ;
cli_incoming_list_totals ( buffer + strlen ( LIST_TOTALS ) , len - strlen ( LIST_TOTALS ) , m , replybuffer , outbufend ) ;
} else if ( len > = strlen ( LIST_MAX_SESSIONS ) & & strncmp ( buffer , LIST_MAX_SESSIONS , strlen ( LIST_MAX_SESSIONS ) ) = = 0 ) {
cli_incoming_list_maxsessions ( buffer + strlen ( LIST_MAX_SESSIONS ) , len - strlen ( LIST_MAX_SESSIONS ) , m , replybuffer , outbufend ) ;
} else if ( len > = strlen ( LIST_MAX_OPEN_FILES ) & & strncmp ( buffer , LIST_MAX_OPEN_FILES , strlen ( LIST_MAX_OPEN_FILES ) ) = = 0 ) {
cli_incoming_list_maxopenfiles ( buffer + strlen ( LIST_MAX_OPEN_FILES ) , len - strlen ( LIST_MAX_OPEN_FILES ) , m , replybuffer , outbufend ) ;
} else {
} else {
printlen = snprintf ( replybuffer , outbufend - replybuffer , " %s:%s \n " , " Unknown 'list' command " , buffer ) ;
printlen = snprintf ( replybuffer , outbufend - replybuffer , " %s:%s \n " , " Unknown 'list' command " , buffer ) ;
ADJUSTLEN ( printlen , outbufend , replybuffer ) ;
ADJUSTLEN ( printlen , outbufend , replybuffer ) ;
}
}
}
}
static void cli_incoming_set ( char * buffer , int len , struct callmaster * m , char * replybuffer , const char * outbufend ) {
int printlen = 0 ;
static const char * SET_MAX_OPEN_FILES = " maxopenfiles " ;
static const char * SET_MAX_SESSIONS = " maxsessions " ;
if ( len < = 1 ) {
printlen = snprintf ( replybuffer , outbufend - replybuffer , " %s \n " , " More parameters required. " ) ;
ADJUSTLEN ( printlen , outbufend , replybuffer ) ;
return ;
}
+ + buffer ; - - len ; / / one space
if ( len > = strlen ( SET_MAX_OPEN_FILES ) & & strncmp ( buffer , SET_MAX_OPEN_FILES , strlen ( SET_MAX_OPEN_FILES ) ) = = 0 ) {
cli_incoming_set_maxopenfiles ( buffer + strlen ( SET_MAX_OPEN_FILES ) , len - strlen ( SET_MAX_OPEN_FILES ) , m , replybuffer , outbufend ) ;
} else if ( len > = strlen ( SET_MAX_SESSIONS ) & & strncmp ( buffer , SET_MAX_SESSIONS , strlen ( SET_MAX_SESSIONS ) ) = = 0 ) {
cli_incoming_set_maxsessions ( buffer + strlen ( SET_MAX_SESSIONS ) , len - strlen ( SET_MAX_SESSIONS ) , m , replybuffer , outbufend ) ;
} else {
printlen = snprintf ( replybuffer , outbufend - replybuffer , " %s:%s \n " , " Unknown 'set' command " , buffer ) ;
ADJUSTLEN ( printlen , outbufend , replybuffer ) ;
}
}
static void cli_incoming_terminate ( char * buffer , int len , struct callmaster * m , char * replybuffer , const char * outbufend ) {
static void cli_incoming_terminate ( char * buffer , int len , struct callmaster * m , char * replybuffer , const char * outbufend ) {
str termparam ;
str termparam ;
struct call * c = 0 ;
struct call * c = 0 ;
@ -334,9 +473,9 @@ static void cli_incoming(int fd, void *p, uintptr_t u) {
struct cli * cli = ( void * ) p ;
struct cli * cli = ( void * ) p ;
socklen_t sinl ;
socklen_t sinl ;
static const int BUFLENGTH = 4096 * 1024 ;
static const int BUFLENGTH = 4096 * 1024 ;
char replybuffer [ BUFLENGTH ] ;
char * outbuf = replybuffer ;
const char * outbufend = replybuffer + BUFLENGTH ;
char replybuffer [ BUFLENGTH ] ;
char * outbuf = replybuffer ;
const char * outbufend = replybuffer + BUFLENGTH ;
static const int MAXINPUT = 1024 ;
static const int MAXINPUT = 1024 ;
char inbuf [ MAXINPUT ] ;
char inbuf [ MAXINPUT ] ;
int inlen = 0 , readbytes = 0 ;
int inlen = 0 , readbytes = 0 ;
@ -374,12 +513,14 @@ next:
static const char * LIST = " list " ;
static const char * LIST = " list " ;
static const char * TERMINATE = " terminate " ;
static const char * TERMINATE = " terminate " ;
static const char * SET = " set " ;
if ( strncmp ( inbuf , LIST , strlen ( LIST ) ) = = 0 ) {
if ( strncmp ( inbuf , LIST , strlen ( LIST ) ) = = 0 ) {
cli_incoming_list ( inbuf + strlen ( LIST ) , inlen - strlen ( LIST ) , cli - > callmaster , outbuf , outbufend ) ;
cli_incoming_list ( inbuf + strlen ( LIST ) , inlen - strlen ( LIST ) , cli - > callmaster , outbuf , outbufend ) ;
} else if ( strncmp ( inbuf , TERMINATE , strlen ( TERMINATE ) ) = = 0 ) {
} else if ( strncmp ( inbuf , TERMINATE , strlen ( TERMINATE ) ) = = 0 ) {
cli_incoming_terminate ( inbuf + strlen ( TERMINATE ) , inlen - strlen ( TERMINATE ) , cli - > callmaster , outbuf , outbufend ) ;
cli_incoming_terminate ( inbuf + strlen ( TERMINATE ) , inlen - strlen ( TERMINATE ) , cli - > callmaster , outbuf , outbufend ) ;
} else if ( strncmp ( inbuf , SET , strlen ( SET ) ) = = 0 ) {
cli_incoming_set ( inbuf + strlen ( SET ) , inlen - strlen ( SET ) , cli - > callmaster , outbuf , outbufend ) ;
} else {
} else {
sprintf ( replybuffer , " %s:%s \n " , " Unknown or incomplete command: " , inbuf ) ;
sprintf ( replybuffer , " %s:%s \n " , " Unknown or incomplete command: " , inbuf ) ;
}
}