|
|
|
@ -1,34 +1,34 @@
|
|
|
|
|
/***
|
|
|
|
|
* _____ _ _ _____
|
|
|
|
|
* / ____(_) | | |_ _|
|
|
|
|
|
* | (___ _ _ __ ___ _ __ | | ___ ___ | | _ __
|
|
|
|
|
* \___ \| | '_ ` _ \| '_ \| |/ _ \/ __| | | | '_ \
|
|
|
|
|
* ____) | | | | | | | |_) | | __/\__ \ _| |_| |_) | |
|
|
|
|
* |_____/|_|_| |_| |_| .__/|_|\___||___/ |_____| .__/
|
|
|
|
|
* | \/ | | | | |
|
|
|
|
|
* | \ / | __ _ _ __ |_|_ _ __ _ ___ _ __ |_|
|
|
|
|
|
* | |\/| |/ _` | '_ \ / _` |/ _` |/ _ \ '__|
|
|
|
|
|
* | | | | (_| | | | | (_| | (_| | __/ |
|
|
|
|
|
* |_| |_|\__,_|_| |_|\__,_|\__, |\___|_|
|
|
|
|
|
* __/ |
|
|
|
|
|
* |___/
|
|
|
|
|
*
|
|
|
|
|
* .----------------. .----------------. .----------------. .----------------.
|
|
|
|
|
* | .--------------. || .--------------. || .--------------. || .--------------. | |
|
|
|
|
* | | __ | || | ____ ____ | || | _____ | || | ________ | | |
|
|
|
|
* | | / \ | || ||_ \ / _|| || | |_ _| | || | |_ ___ `. | | |
|
|
|
|
* | | / /\ \ | || | | \/ | | || | | | | || | | | `. \ | | |
|
|
|
|
* | | / ____ \ | || | | |\ /| | | || | | | | || | | | | | | | |
|
|
|
|
* | | _/ / \ \_ | || | _| |_\/_| |_ | || | _| |_ | || | _| |___.' / | | |
|
|
|
|
* | ||____| |____|| || ||_____||_____|| || | |_____| | || | |________.' | | |
|
|
|
|
* | | | || | | || | | || | | | |
|
|
|
|
* | '--------------' || '--------------' || '--------------' || '--------------' | |
|
|
|
|
* '----------------' '----------------' '----------------' '----------------'
|
|
|
|
|
* |
|
|
|
|
* Copyright (C) 2022 Simples IP. |
|
|
|
|
* Author: Ródgger Bruno <rodgger.silva@simplesip.com> |
|
|
|
|
* Maintainers: Rodgger Bruno <rodgger.silva@simplesip.com> |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <main.h> |
|
|
|
|
#include <string.h> |
|
|
|
|
#include <frame/frame_asterisk.h> |
|
|
|
|
#include <frame/frame_asterisk.h> // camada de persistência |
|
|
|
|
#include <agent/agent.h> |
|
|
|
|
#include <parse_actions.h> |
|
|
|
|
#include <methods_actions.h> |
|
|
|
|
#include <string_functions.h> |
|
|
|
|
#include <stdlib.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* lida com os eventos agents |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
int parse_event_agents( EVENT *event, s_manager *smanager ){ |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@ -89,39 +89,41 @@ int parse_event_agents( EVENT *event, s_manager *smanager ){
|
|
|
|
|
status = ami_get_value( smanager->ami, event->args, "Status" ); |
|
|
|
|
if( !status ) { goto fail; } |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
{ //banco de dados
|
|
|
|
|
struct s_table_agent *table_agent = get_agents_db( Select_agents, matricula ); |
|
|
|
|
if (table_agent) { |
|
|
|
|
if( strcmp_n( table_agent->name, name ) ||
|
|
|
|
|
strcmp_n( table_agent->status, status )){ |
|
|
|
|
|
|
|
|
|
/* atualizar linha de dados da tabela agent */ |
|
|
|
|
if(update_agents_db( Update_agents, name, status, table_agent->id ) == -1){ |
|
|
|
|
goto fail; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// liberar resultado mysql
|
|
|
|
|
free_table_agent(table_agent); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
// inseri uma linha na tabela
|
|
|
|
|
if(insert_agents_db( Insert_agents, name, matricula, status) == -1){ |
|
|
|
|
goto fail; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
{ // camada de persistência
|
|
|
|
|
struct s_agents *agent = get_agents(matricula); |
|
|
|
|
|
|
|
|
|
if(agent){ |
|
|
|
|
agent->action_update = 1; |
|
|
|
|
agent->action_update = 1; // esse agente existe no asterisk
|
|
|
|
|
} |
|
|
|
|
else{ |
|
|
|
|
else{ // criar um novo agente na persistência que existe no asteriks
|
|
|
|
|
agent = create_agents(); |
|
|
|
|
newstrncpy(&agent->matricula, matricula); |
|
|
|
|
agent->action_update = 1; |
|
|
|
|
insert_agents( agent ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return 1; |
|
|
|
@ -130,30 +132,40 @@ fail:
|
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* lida com o eventos agentscomplete. |
|
|
|
|
* esse evento é recebido quando terminou a lista de eventos dos agentes, por isso o nome |
|
|
|
|
* Esse evento é usado para sincronizar agentes com o asterisk |
|
|
|
|
*/ |
|
|
|
|
int parse_event_agentscomplete(EVENT *event, s_manager *smanager){ |
|
|
|
|
|
|
|
|
|
if( strcasecmp_n( ami_get_value(smanager->ami, event->args, "Eventlist"), "Complete" ) ) { |
|
|
|
|
return -1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Excluí agentes na camada de persistêcnia que não estão no asterisk
|
|
|
|
|
agent_update(); |
|
|
|
|
|
|
|
|
|
struct s_table_agent *table_agent = get_agents_update_db(Select_agents_update); |
|
|
|
|
struct s_table_agent *root_table_agent = table_agent; |
|
|
|
|
while(table_agent){ |
|
|
|
|
struct s_agents *agent = get_agents(table_agent->matricula); |
|
|
|
|
if(agent){ |
|
|
|
|
if(agent->action_update == 0){ |
|
|
|
|
{ // Excluí agentes no banco de dados que não estão na camada de persistência
|
|
|
|
|
struct s_table_agent *table_agent = get_agents_all_db(Select_agents_update); |
|
|
|
|
struct s_table_agent *root_table_agent = table_agent; |
|
|
|
|
while(table_agent){ |
|
|
|
|
struct s_agents *agent = get_agents(table_agent->matricula); |
|
|
|
|
if(agent){ |
|
|
|
|
if(agent->action_update == 0){ |
|
|
|
|
delete_agents_db(Delete_agents, table_agent->id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
agent->action_update = 0; |
|
|
|
|
} |
|
|
|
|
else{ |
|
|
|
|
delete_agents_db(Delete_agents, table_agent->id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
agent->action_update = 0; |
|
|
|
|
} |
|
|
|
|
else{ |
|
|
|
|
delete_agents_db(Delete_agents, table_agent->id); |
|
|
|
|
table_agent = table_agent->next; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
table_agent = table_agent->next; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
free_table_agent(root_table_agent); |
|
|
|
|