1
0
mirror of https://github.com/coturn/coturn.git synced 2025-10-26 20:41:07 +01:00

auth server code cleaning

This commit is contained in:
mom040267 2014-12-20 22:21:00 +00:00
parent 6b291a8238
commit 87cd2366c7
5 changed files with 38 additions and 38 deletions

View File

@ -161,6 +161,7 @@ static Ryconninfo *RyconninfoParse(const char *userdb, char **errmsg) {
} }
redis_context_handle get_redis_async_connection(struct event_base *base, const char* connection_string, int delete_keys) { redis_context_handle get_redis_async_connection(struct event_base *base, const char* connection_string, int delete_keys) {
redis_context_handle ret = NULL; redis_context_handle ret = NULL;
char *errmsg = NULL; char *errmsg = NULL;

View File

@ -110,7 +110,6 @@ NEV_UNKNOWN,
LOW_DEFAULT_PORTS_BOUNDARY,HIGH_DEFAULT_PORTS_BOUNDARY,0,0,0,"", LOW_DEFAULT_PORTS_BOUNDARY,HIGH_DEFAULT_PORTS_BOUNDARY,0,0,0,"",
0,NULL,0,NULL,DEFAULT_GENERAL_RELAY_SERVERS_NUMBER,0, 0,NULL,0,NULL,DEFAULT_GENERAL_RELAY_SERVERS_NUMBER,0,
////////////// Auth server ///////////////////////////////////// ////////////// Auth server /////////////////////////////////////
{NULL,NULL,NULL,0,NULL},
"","",0, "","",0,
/////////////// AUX SERVERS //////////////// /////////////// AUX SERVERS ////////////////
{NULL,0,{0,NULL}},0, {NULL,0,{0,NULL}},0,
@ -1884,8 +1883,6 @@ int main(int argc, char **argv)
STRCPY(turn_params.default_users_db.persistent_users_db.userdb,DEFAULT_USERDB_FILE); STRCPY(turn_params.default_users_db.persistent_users_db.userdb,DEFAULT_USERDB_FILE);
#endif #endif
update_white_and_black_lists();
argc -= optind; argc -= optind;
argv += optind; argv += optind;

View File

@ -160,16 +160,6 @@ enum _NET_ENG_VERSION {
typedef enum _NET_ENG_VERSION NET_ENG_VERSION; typedef enum _NET_ENG_VERSION NET_ENG_VERSION;
////////////// Auth Server Types ////////////////
struct auth_server {
struct event_base* event_base;
struct bufferevent *in_buf;
struct bufferevent *out_buf;
pthread_t thr;
redis_context_handle rch;
};
/////////// PARAMS ////////////////////////////////// /////////// PARAMS //////////////////////////////////
typedef struct _turn_params_ { typedef struct _turn_params_ {
@ -275,7 +265,6 @@ typedef struct _turn_params_ {
////////////// Auth server //////////////// ////////////// Auth server ////////////////
struct auth_server authserver;
char oauth_server_name[1025]; char oauth_server_name[1025];
char domain[1025]; char domain[1025];
int oauth; int oauth;

View File

@ -37,6 +37,18 @@ static unsigned int barrier_count = 0;
static pthread_barrier_t barrier; static pthread_barrier_t barrier;
#endif #endif
////////////// Auth Server ////////////////
struct auth_server {
struct event_base* event_base;
struct bufferevent *in_buf;
struct bufferevent *out_buf;
pthread_t thr;
redis_context_handle rch;
};
static struct auth_server authserver = {NULL,NULL,NULL,0,NULL};
////////////////////////////////////////////// //////////////////////////////////////////////
#define get_real_general_relay_servers_number() (turn_params.general_relay_servers_number > 1 ? turn_params.general_relay_servers_number : 1) #define get_real_general_relay_servers_number() (turn_params.general_relay_servers_number > 1 ? turn_params.general_relay_servers_number : 1)
@ -356,7 +368,7 @@ static int handle_relay_message(relay_server_handle rs, struct message_to_relay
void send_auth_message_to_auth_server(struct auth_message *am) void send_auth_message_to_auth_server(struct auth_message *am)
{ {
struct evbuffer *output = bufferevent_get_output(turn_params.authserver.out_buf); struct evbuffer *output = bufferevent_get_output(authserver.out_buf);
if(evbuffer_add(output,am,sizeof(struct auth_message))<0) { if(evbuffer_add(output,am,sizeof(struct auth_message))<0) {
fprintf(stderr,"%s: Weird buffer error\n",__FUNCTION__); fprintf(stderr,"%s: Weird buffer error\n",__FUNCTION__);
} }
@ -1689,33 +1701,34 @@ static void* run_auth_server_thread(void *arg)
{ {
ignore_sigpipe(); ignore_sigpipe();
ns_bzero(&turn_params.authserver,sizeof(struct auth_server)); struct auth_server *as = (struct auth_server*)arg;
turn_params.authserver.event_base = turn_event_base_new(); ns_bzero(as,sizeof(struct auth_server));
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO,"IO method (auth thread): %s\n",event_base_get_method(turn_params.authserver.event_base));
as->event_base = turn_event_base_new();
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO,"IO method (auth thread): %s\n",event_base_get_method(as->event_base));
struct bufferevent *pair[2]; struct bufferevent *pair[2];
bufferevent_pair_new(turn_params.authserver.event_base, TURN_BUFFEREVENTS_OPTIONS, pair); bufferevent_pair_new(as->event_base, TURN_BUFFEREVENTS_OPTIONS, pair);
turn_params.authserver.in_buf = pair[0]; as->in_buf = pair[0];
turn_params.authserver.out_buf = pair[1]; as->out_buf = pair[1];
bufferevent_setcb(turn_params.authserver.in_buf, auth_server_receive_message, NULL, NULL, &turn_params.authserver); bufferevent_setcb(as->in_buf, auth_server_receive_message, NULL, NULL, as);
bufferevent_enable(turn_params.authserver.in_buf, EV_READ); bufferevent_enable(as->in_buf, EV_READ);
#if !defined(TURN_NO_HIREDIS) #if !defined(TURN_NO_HIREDIS)
turn_params.authserver.rch = get_redis_async_connection(turn_params.authserver.event_base, turn_params.redis_statsdb, 1); as->rch = get_redis_async_connection(as->event_base, turn_params.redis_statsdb, 1);
#endif #endif
struct auth_server *authserver = &turn_params.authserver; struct event_base *eb = as->event_base;
struct event_base *eb = authserver->event_base;
barrier_wait(); barrier_wait();
while(run_auth_server_flag) { while(run_auth_server_flag) {
reread_realms(); reread_realms();
run_events(eb,NULL);
update_white_and_black_lists(); update_white_and_black_lists();
auth_ping(authserver->rch); auth_ping(as->rch);
run_events(eb,NULL);
#if defined(DB_TEST) #if defined(DB_TEST)
run_db_test(); run_db_test();
#endif #endif
@ -1724,13 +1737,13 @@ static void* run_auth_server_thread(void *arg)
return arg; return arg;
} }
static void setup_auth_server(void) static void setup_auth_server(struct auth_server *as)
{ {
if(pthread_create(&(turn_params.authserver.thr), NULL, run_auth_server_thread, NULL)<0) { if(pthread_create(&(as->thr), NULL, run_auth_server_thread, as)<0) {
perror("Cannot create auth thread\n"); perror("Cannot create auth thread\n");
exit(-1); exit(-1);
} }
pthread_detach(turn_params.authserver.thr); pthread_detach(as->thr);
} }
static void* run_cli_server_thread(void *arg) static void* run_cli_server_thread(void *arg)
@ -1815,7 +1828,7 @@ void setup_server(void)
} }
} }
setup_auth_server(); setup_auth_server(&authserver);
if(use_cli) if(use_cli)
setup_cli_server(); setup_cli_server();

View File

@ -650,12 +650,12 @@ int get_user_pwd(u08bits *usname, st_password_t pwd)
{ {
int ret = -1; int ret = -1;
const turn_dbdriver_t * dbd = get_dbdriver(); const turn_dbdriver_t * dbd = get_dbdriver();
if (dbd && dbd->get_user_pwd) { if (dbd && dbd->get_user_pwd) {
ret = (*dbd->get_user_pwd)(usname, pwd); ret = (*dbd->get_user_pwd)(usname, pwd);
} }
return ret; return ret;
} }
u08bits *start_user_check(turnserver_id id, turn_credential_type ct, int in_oauth, int *out_oauth, u08bits *usname, u08bits *realm, get_username_resume_cb resume, ioa_net_data *in_buffer, u64bits ctxkey, int *postpone_reply) u08bits *start_user_check(turnserver_id id, turn_credential_type ct, int in_oauth, int *out_oauth, u08bits *usname, u08bits *realm, get_username_resume_cb resume, ioa_net_data *in_buffer, u64bits ctxkey, int *postpone_reply)
@ -1023,7 +1023,7 @@ void auth_ping(redis_context_handle rch)
const turn_dbdriver_t * dbd = get_dbdriver(); const turn_dbdriver_t * dbd = get_dbdriver();
if (dbd && dbd->auth_ping) { if (dbd && dbd->auth_ping) {
(*dbd->auth_ping)(rch); (*dbd->auth_ping)(rch);
} }
} }
///////////////// TEST ///////////////// ///////////////// TEST /////////////////